/*
 * Read & Map — the student player (read-map-player.js), the map it draws, and
 * the teacher editor. Tokens live on :root (not on a page shell) because
 * _PortalLayout moves every .modal to <body>, where shell-scoped tokens stop
 * resolving. The Digital Work page (Views/Work/Index.cshtml) re-points the
 * base tokens at its own, which follow the site's light/dark choice.
 */
:root {
    --rm-ink: #111827;
    --rm-muted: #4b5563;
    --rm-surface: #ffffff;
    --rm-surface-2: #f8fafc;
    --rm-border: rgba(15, 23, 42, 0.14);
    --rm-strong-border: rgba(15, 23, 42, 0.38);
    --rm-accent: #2563eb;
    --rm-accent-soft: rgba(37, 99, 235, 0.09);
    --rm-anchor-bg: #eef2ff;
    --rm-anchor-border: #4338ca;
    --rm-given: #f1f5f9;
    --rm-key: #1d4ed8;
    --rm-line-color: #64748b;
    --rm-right: #dcfce7;
    --rm-right-ink: #166534;
    --rm-wrong: #fee2e2;
    --rm-wrong-ink: #991b1b;
    --rm-warn-bg: #fffbeb;
    --rm-warn-border: #f59e0b;
}

[data-theme="dark"] {
    --rm-ink: #e8e8e8;
    --rm-muted: #a5a5a5;
    --rm-surface: #1b1b1b;
    --rm-surface-2: #141414;
    --rm-border: rgba(255, 255, 255, 0.12);
    --rm-strong-border: rgba(255, 255, 255, 0.34);
    --rm-accent: #6b93ff;
    --rm-accent-soft: rgba(107, 147, 255, 0.14);
    --rm-anchor-bg: #1e2547;
    --rm-anchor-border: #818cf8;
    --rm-given: #272727;
    --rm-key: #93c5fd;
    --rm-line-color: #a5a5a5;
    --rm-right: #14532d;
    --rm-right-ink: #bbf7d0;
    --rm-wrong: #7f1d1d;
    --rm-wrong-ink: #fecaca;
    --rm-warn-bg: rgba(245, 158, 11, 0.12);
    --rm-warn-border: #f59e0b;
}

/* ── Player shell ──────────────────────────────────────────────────── */
.rm-player, .rm-edit { color: var(--rm-ink); }
.rm-player *, .rm-player *::before, .rm-player *::after,
.rm-edit *, .rm-edit *::before, .rm-edit *::after { box-sizing: border-box; }

.rm-card {
    background: var(--rm-surface);
    border: 1px solid var(--rm-border);
    border-radius: 12px;
    padding: 18px 20px;
    margin-bottom: 16px;
}

.rm-brief p { margin: 0 0 6px; }
.rm-brief p:last-child { margin-bottom: 0; }

.rm-reading summary { cursor: pointer; font-weight: 700; }
.rm-para { display: flex; gap: 10px; margin: 10px 0 0; line-height: 1.6; }
.rm-para-num {
    flex: 0 0 auto;
    min-width: 1.6em;
    height: 1.6em;
    border-radius: 999px;
    background: var(--rm-accent-soft);
    color: var(--rm-accent);
    font-size: 0.78rem;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-top: 2px;
}

.rm-toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.rm-link { border: 0; background: none; padding: 0; color: var(--rm-accent); font: inherit; font-weight: 600; cursor: pointer; }
.rm-link:hover { text-decoration: underline; }
.rm-sound {
    padding: 5px 12px;
    border: 1px solid var(--rm-border);
    border-radius: 999px;
    background: var(--rm-surface);
    color: var(--rm-muted);
    font: inherit;
    font-size: 0.85rem;
    cursor: pointer;
}

/* The bank stays in view while the map scrolls under it. */
.rm-bank {
    position: sticky;
    top: 0;
    z-index: 5;
    max-height: 38vh;
    overflow: auto;
    background: var(--rm-surface-2);
    border: 1px solid var(--rm-border);
    border-radius: 10px;
    padding: 10px 12px;
}
.rm-bank-head { font-weight: 700; font-size: 0.92rem; margin-bottom: 6px; }
.rm-pool + .rm-pool { margin-top: 8px; }
.rm-pool-label { font-size: 0.78rem; font-weight: 700; color: var(--rm-muted); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 4px; }
.rm-tiles { display: flex; flex-wrap: wrap; gap: 8px; }
.rm-tiles.is-sentences { flex-direction: column; }

.rm-tile {
    padding: 7px 12px;
    border: 1.5px solid var(--rm-strong-border);
    border-radius: 9px;
    background: var(--rm-surface);
    color: var(--rm-ink);
    font: inherit;
    font-size: 0.93rem;
    line-height: 1.35;
    text-align: left;
    cursor: grab;
    box-shadow: 0 1px 0 rgba(15, 23, 42, 0.08);
    transition: border-color .12s, background .12s, transform .12s;
}
.rm-tile:hover { border-color: var(--rm-accent); }
.rm-tile:focus-visible, .rm-slot:focus-visible { outline: 3px solid var(--rm-accent); outline-offset: 2px; }
.rm-tile.is-selected { border-color: var(--rm-accent); background: var(--rm-accent-soft); transform: translateY(-1px); box-shadow: 0 0 0 3px var(--rm-accent-soft); }
.rm-tile:disabled { cursor: default; opacity: .6; }
.rm-tiles.is-sentences .rm-tile { width: 100%; }

.rm-status { color: var(--rm-muted); font-size: 0.88rem; margin: 10px 0 4px; min-height: 1.3em; }

/* ── The map ───────────────────────────────────────────────────────── */
.rm-map { margin-top: 8px; }
.rm-stage { position: relative; padding: 6px 2px 10px; }
.rm-stage > :not(.rm-lines) { position: relative; z-index: 1; }
.rm-lines { position: absolute; left: 0; top: 0; z-index: 0; pointer-events: none; overflow: visible; }
.rm-line { fill: none; stroke: var(--rm-line-color); stroke-width: 1.6; }
.rm-brace { stroke-width: 2; }
.rm-arrowhead { fill: var(--rm-line-color); }

.rm-anchor {
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    min-height: 52px;
    padding: 10px 14px;
    border: 2px solid var(--rm-anchor-border);
    border-radius: 12px;
    background: var(--rm-anchor-bg);
    font-weight: 700;
    font-size: 1.02rem;
    line-height: 1.3;
    overflow-wrap: anywhere;
}
.rm-anchor.is-round { border-radius: 50%; min-height: 96px; min-width: 96px; aspect-ratio: 1 / 1; padding: 12px; font-size: .95rem; }
.rm-anchor-wide { margin-bottom: 26px; }
.rm-anchor-center { max-width: 360px; margin: 0 auto 34px; }
.rm-anchor-col { min-height: 44px; margin-bottom: 14px; font-size: .95rem; }

.rm-heading { font-weight: 700; color: var(--rm-accent); font-size: .92rem; margin-bottom: 8px; }

.rm-col { display: flex; flex-direction: column; gap: 14px; }

.rm-slot {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    min-height: 50px;
    padding: 9px 12px;
    border: 2px dashed var(--rm-strong-border);
    border-radius: 10px;
    background: var(--rm-surface);
    color: var(--rm-ink);
    font: inherit;
    font-size: 0.93rem;
    line-height: 1.35;
    text-align: center;
    overflow-wrap: anywhere;
    cursor: pointer;
    transition: border-color .12s, background .12s;
}
button.rm-slot:hover { border-color: var(--rm-accent); }
.rm-slot.is-sentence { justify-content: flex-start; text-align: left; min-height: 64px; }
.rm-slot.is-filled { border-style: solid; border-color: var(--rm-accent); background: var(--rm-accent-soft); cursor: grab; }
.rm-slot.is-given { border-style: solid; border-color: var(--rm-border); background: var(--rm-given); cursor: default; }
.rm-slot.is-key { border-style: solid; border-color: var(--rm-border); color: var(--rm-key); font-weight: 600; cursor: default; }
.rm-slot.is-over { border-color: var(--rm-accent); background: var(--rm-accent-soft); }
.rm-col.is-round .rm-slot { border-radius: 999px; padding-left: 16px; padding-right: 16px; }
.rm-player.is-picking button.rm-slot:not(.is-filled) { border-color: var(--rm-accent); }
.rm-player.is-locked .rm-slot { cursor: default; }
.rm-slot:disabled { opacity: 1; }
.rm-slot-empty { color: var(--rm-muted); font-size: 1.15rem; font-weight: 600; }
.rm-step {
    position: absolute;
    left: 6px;
    top: 5px;
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--rm-muted);
}
.rm-slot.is-right { border-style: solid; border-color: var(--rm-right-ink); background: var(--rm-right); color: var(--rm-right-ink); }
.rm-slot.is-wrong { border-style: solid; border-color: var(--rm-wrong-ink); background: var(--rm-wrong); color: var(--rm-wrong-ink); }
.rm-slot.is-missed { border-color: var(--rm-wrong-ink); }
.rm-slot.is-checked { border-style: solid; border-color: var(--rm-strong-border); }
.rm-mark { font-weight: 800; margin-left: 4px; }

.rm-chain-result {
    display: inline-block;
    margin: 14px 0 0;
    padding: 5px 12px;
    border-radius: 999px;
    font-weight: 700;
    font-size: .88rem;
}
.rm-chain-result.is-right { background: var(--rm-right); color: var(--rm-right-ink); }
.rm-chain-result.is-partial { background: var(--rm-warn-bg); color: var(--rm-ink); border: 1px solid var(--rm-warn-border); }

/* Sequence: rows that wrap; Cycle as a list; Sequence top to bottom. */
.rm-chain-across { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 40px 34px; }
.rm-chain-down { display: flex; flex-direction: column; gap: 30px; max-width: 420px; margin: 0 auto; }
.rm-layout-list .rm-chain-down { margin-left: 0; margin-right: 52px; max-width: none; }

/* Cycle: boxes around a ring. */
.rm-ring { position: relative; width: 100%; }
.rm-ring-node { position: absolute; width: min(176px, 30%); transform: translate(-50%, -50%); }
.rm-ring-hub { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: 150px; }

/* Cause and effect: causes → event → effects. */
.rm-ce { display: grid; grid-template-columns: minmax(0, 1fr) minmax(130px, 0.8fr) minmax(0, 1fr); gap: 0 56px; align-items: center; }
.rm-ce-mid .rm-anchor { min-height: 96px; }

/* Compare: double bubble. */
.rm-bubble { display: grid; grid-template-columns: minmax(0, 1fr) 112px minmax(0, 1fr) 112px minmax(0, 1fr); gap: 0 30px; align-items: center; }
.rm-bubble-hub { display: flex; justify-content: center; }
.rm-bubble-hub .rm-anchor { width: 112px; }

/* Compare as columns; Classify as columns or a tree. */
.rm-columns { display: grid; grid-template-columns: repeat(var(--rm-cols, 3), minmax(0, 1fr)); gap: 18px; align-items: start; }
.rm-column { min-width: 0; }
.rm-tree .rm-anchor-col { margin-bottom: 22px; }

/* Whole and parts: the whole, a brace, then each part with its clue. */
.rm-parts { display: flex; flex-direction: column; gap: 12px; }
.rm-part { display: grid; grid-template-columns: minmax(150px, 1fr) minmax(0, 1.3fr); gap: 14px; align-items: center; }
.rm-clue { color: var(--rm-muted); font-size: .92rem; line-height: 1.4; }
.rm-brace-grid { display: grid; grid-template-columns: minmax(120px, 0.7fr) 44px minmax(0, 2.4fr); align-items: center; }

/* Frayer: four squares around the term. */
.rm-frayer { position: relative; display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.rm-frayer-cell { border: 1px solid var(--rm-border); border-radius: 12px; padding: 12px 14px; background: var(--rm-surface-2); min-height: 150px; }
.rm-frayer .rm-q0, .rm-frayer .rm-q1 { padding-bottom: 54px; }
.rm-frayer .rm-q2, .rm-frayer .rm-q3 { padding-top: 54px; }
.rm-frayer .rm-q1 .rm-heading, .rm-frayer .rm-q3 .rm-heading { text-align: right; }
.rm-frayer-term { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 2; width: 180px; min-height: 0; aspect-ratio: auto; border-radius: 999px; padding: 14px 18px; }
.rm-frayer.is-stacked { grid-template-columns: 1fr; }
.rm-frayer.is-stacked .rm-frayer-cell { padding: 12px 14px; min-height: 0; }
.rm-frayer.is-stacked .rm-heading { text-align: left; }
.rm-layout-stack > .rm-frayer-term { position: static; transform: none; margin: 0 auto 16px; }

/* Describe: a bubble map, the topic ringed by describing words. */
.rm-web .rm-slot { border-radius: 999px; padding-left: 16px; padding-right: 16px; }
.rm-web .rm-ring-node { width: min(170px, 28%); }
.rm-web .rm-ring-hub { width: 140px; }
.rm-web-list { max-width: 420px; margin: 0 auto; }

/* Analogy: a bridge map. Each pair is its given first term over the line and
   the box for its second; "as" bridges one pair to the next. */
.rm-bridge-rf { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 12px; align-items: center; margin-bottom: 26px; }
.rm-bridge-rf .rm-anchor { justify-content: flex-start; text-align: left; }
.rm-bridge { display: flex; align-items: center; gap: 12px; }
.rm-bridge-pair { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; }
.rm-bridge-given { padding: 8px 6px 10px; border-bottom: 3px solid var(--rm-ink); margin-bottom: 12px; text-align: center; font-weight: 700; color: var(--rm-ink); }
.rm-bridge-as { flex: 0 0 auto; font-style: italic; font-weight: 700; color: var(--rm-muted); }
.rm-bridge.is-stacked { flex-direction: column; align-items: stretch; gap: 8px; }
.rm-bridge.is-stacked .rm-bridge-pair { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1.2fr); gap: 10px; align-items: center; }
.rm-bridge.is-stacked .rm-bridge-given { border-bottom: 0; margin: 0; padding: 0; text-align: left; }
.rm-bridge-rel { color: var(--rm-muted); font-size: .9rem; font-style: italic; }
.rm-bridge.is-stacked .rm-bridge-as { text-align: center; }

/* Claim, evidence, reasoning. */
.rm-cer-row { display: grid; grid-template-columns: 110px minmax(0, 1fr); gap: 14px; align-items: start; margin-bottom: 30px; }
.rm-cer-row .rm-heading { padding-top: 14px; }

@media (max-width: 640px) {
    .rm-card { padding: 14px; }
    .rm-ce { grid-template-columns: minmax(0, 1fr); gap: 34px; }
    .rm-columns { grid-template-columns: minmax(0, 1fr); }
    .rm-chain-across { grid-template-columns: minmax(0, 1fr); gap: 30px; }
    .rm-part { grid-template-columns: minmax(0, 1fr); gap: 4px; }
    .rm-cer-row { grid-template-columns: minmax(0, 1fr); gap: 4px; margin-bottom: 24px; }
    .rm-cer-row .rm-heading { padding-top: 0; }
    .rm-bank { max-height: 32vh; }
}

/* ── Teacher pages ─────────────────────────────────────────────────── */
.rm-shell { max-width: 1240px; margin: 0 auto; padding: 8px 4px 90px; color: var(--rm-ink); }
.rm-page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.rm-page-head h1 { font-size: 1.5rem; font-weight: 800; margin: 0; }
.rm-page-head p { margin: 2px 0 0; color: var(--rm-muted); font-size: .92rem; }
.rm-icon {
    width: 44px; height: 44px; border-radius: 12px;
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--rm-accent-soft); color: var(--rm-accent); font-size: 1.2rem;
}
.rm-muted { color: var(--rm-muted); }
.rm-btn-accent { background: var(--rm-accent); border-color: var(--rm-accent); color: #fff; font-weight: 700; }
.rm-btn-accent:hover, .rm-btn-accent:focus { background: #1d4ed8; border-color: #1d4ed8; color: #fff; }
[data-theme="dark"] .rm-btn-accent { color: #141414; }

/* The type picker on the create form. */
.rm-types { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
.rm-type {
    position: relative;
    display: flex; flex-direction: column; gap: 2px;
    padding: 12px 14px;
    border: 1.5px solid var(--rm-border);
    border-radius: 12px;
    background: var(--rm-surface);
    cursor: pointer;
    transition: border-color .12s, background .12s;
}
.rm-type:hover { border-color: var(--rm-accent); }
.rm-type input { position: absolute; opacity: 0; pointer-events: none; }
.rm-type:has(input:checked) { border-color: var(--rm-accent); background: var(--rm-accent-soft); box-shadow: 0 0 0 2px var(--rm-accent-soft); }
.rm-type:has(input:focus-visible) { outline: 3px solid var(--rm-accent); outline-offset: 2px; }
.rm-type-name { font-weight: 700; display: flex; align-items: center; gap: 8px; }
.rm-type-name i { color: var(--rm-accent); width: 1.1em; text-align: center; }
.rm-type-blurb { font-size: .82rem; color: var(--rm-muted); }
.rm-type-badge {
    align-self: flex-start;
    margin-top: 4px;
    padding: 1px 8px;
    border-radius: 999px;
    background: var(--rm-accent);
    color: #fff;
    font-size: .7rem;
    font-weight: 700;
}
[data-theme="dark"] .rm-type-badge { color: #141414; }
.rm-suggest { margin: 8px 0 0; font-size: .88rem; color: var(--rm-muted); min-height: 1.2em; }

/* The editor. */
.rm-edit-card {
    background: var(--rm-surface);
    border: 1px solid var(--rm-border);
    border-radius: 12px;
    padding: 16px 18px;
    margin-bottom: 16px;
}
.rm-edit-card h2 { font-size: 1rem; font-weight: 700; margin: 0 0 10px; }
.rm-preview-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.rm-group-edit { border: 1px solid var(--rm-border); border-radius: 10px; padding: 12px; margin-bottom: 12px; background: var(--rm-surface-2); }
.rm-group-edit h3 { font-size: .92rem; font-weight: 700; margin: 0 0 8px; display: flex; align-items: center; gap: 8px; }
.rm-group-meta { font-size: .78rem; color: var(--rm-muted); font-weight: 500; }
.rm-tile-edit { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 8px; padding: 8px 0; border-top: 1px dashed var(--rm-border); }
.rm-tile-edit:first-of-type { border-top: 0; }
.rm-tile-fields { display: grid; gap: 6px; }
.rm-tile-row { display: grid; grid-template-columns: minmax(0, 1fr) 118px; gap: 6px; }
.rm-tile-actions { display: flex; flex-direction: column; gap: 4px; }
.rm-tile-actions .btn { padding: 2px 8px; }
.rm-note { background: var(--rm-warn-bg); border: 1px solid var(--rm-warn-border); border-radius: 10px; padding: 10px 12px; font-size: .9rem; }
.rm-savebar {
    position: sticky;
    bottom: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 14px;
    padding: 12px 4px;
    margin-top: 10px;
    background: var(--rm-surface-2);
    border-top: 1px solid var(--rm-border);
}
.rm-save-error { color: var(--rm-wrong-ink); font-weight: 600; }
.rm-lib-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 0; border-top: 1px solid var(--rm-border); }
.rm-lib-row:first-child { border-top: 0; }
.rm-lib-title { font-weight: 700; color: var(--rm-ink); text-decoration: none; }
.rm-lib-title:hover { color: var(--rm-accent); }
.rm-pill { display: inline-block; padding: 1px 9px; border-radius: 999px; background: var(--rm-accent-soft); color: var(--rm-accent); font-size: .76rem; font-weight: 700; }
