:root {
  --bg: #f6f3ee; --panel: #fff; --ink: #2b2620; --muted: #7a7166; --line: #e3ddd3;
  --desk: #fdc681; --desk-line: #9a7a4a; --chair: #8f7a5a; --chair2: #b0946e;
  --bad: #dc2626; --bad-bg: #fde8e8; --ok: #15803d; --ok-bg: #e2f5e8; --warn-bg: #fff4d6; --accent: #2563eb;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #1c1a17; --panel: #262320; --ink: #eee8df; --muted: #a59d92; --line: #3a3530;
    --bad-bg: #4a1f1f; --ok-bg: #1d3a26; --warn-bg: #403618; color-scheme: dark; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif; }
a { color: inherit; }
.muted { color: var(--muted); }
#toast { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 8px 14px; border-radius: 8px; opacity: 0; transition: opacity .2s; pointer-events: none; }
#toast.show { opacity: 1; }

/* start screen */
.start { max-width: 720px; margin: 0 auto; padding: 48px 16px; text-align: center; }
.start h1 { font-size: 36px; margin: 0 0 32px; }
.start h2 { font-size: 16px; color: var(--muted); font-weight: 500; margin: 28px 0 12px; }
.players { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.player { font: inherit; font-size: 16px; padding: 12px 20px; border-radius: 12px; border: 2px solid var(--c); background: var(--panel); color: var(--ink); cursor: pointer; min-width: 130px; }
.player.on { background: var(--c); color: #fff; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.card { display: flex; flex-direction: column; gap: 4px; padding: 20px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); text-decoration: none; text-align: left; }
.card b { font-size: 18px; }
.card span { color: var(--muted); }
.card:not(.soon):not(.disabled):hover { border-color: var(--accent); }
.card.disabled, .card.soon { opacity: .5; pointer-events: none; }

/* top bar */
.top { display: flex; align-items: center; gap: 12px; padding: 8px 16px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; position: sticky; top: 0; z-index: 5; }
.back { text-decoration: none; font-size: 20px; }
.title { font-size: 16px; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tab { padding: 6px 12px; border-radius: 8px; text-decoration: none; border: 1px solid var(--line); display: inline-flex; align-items: center; gap: 4px; }
.tab.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.spacer { flex: 1; }
.btn { font: inherit; padding: 5px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); cursor: pointer; margin-left: 6px; }
.btn:hover { border-color: var(--ink); }
.ro { color: var(--muted); font-style: italic; }
.me { padding: 4px 10px; border-radius: 999px; background: var(--c); color: #fff; font-weight: 600; }

/* fuzzy logic layout */
.fl { display: grid; grid-template-columns: 170px minmax(0, 1fr) minmax(300px, 420px); gap: 16px; padding: 16px; align-items: start; }
@media (max-width: 1100px) { .fl { grid-template-columns: 150px minmax(0, 1fr); } .rules { grid-column: 1 / -1; } }
@media (max-width: 640px) { .fl { grid-template-columns: 1fr; padding: 12px; } .pal { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 4px; } .pal h3, .pal .hint { grid-column: 1 / -1; } .pal { position: static; } }
.pal, .rules { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.pal { position: sticky; top: 64px; }
.pal h3 { margin: 0 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.stud { display: flex; align-items: center; gap: 8px; padding: 4px 6px; border-radius: 8px; cursor: pointer; user-select: none; }
.stud b { width: 24px; height: 24px; border-radius: 6px; background: var(--desk); color: #3a2a12; display: grid; place-items: center; }
.stud span { flex: 1; }
.stud small { color: var(--muted); }
.stud:hover { background: var(--bg); }
.stud.on { background: var(--accent); color: #fff; }
.stud.on small { color: #dbe6ff; }
.stud.locked { cursor: default; opacity: .7; }
.stud.used span { text-decoration: line-through; opacity: .5; }
.readonly .stud { cursor: default; }
.hint { color: var(--muted); font-size: 12px; margin: 10px 0 0; }

.rooms { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
@media (max-width: 640px) { .rooms { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; } }
.room { background: var(--panel); border: 2px solid var(--line); border-radius: 12px; padding: 8px 10px 10px; }
.room.full { border-color: #c9bfae; }
.room.bad { border-color: var(--bad); background: var(--bad-bg); }
.room.hl { outline: 3px solid var(--accent); outline-offset: 2px; }
.rt { font-weight: 600; font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; }
.front { text-align: center; font-size: 10px; color: var(--muted); letter-spacing: .2em; text-transform: uppercase; border-bottom: 2px dashed var(--line); margin-bottom: 6px; }
.seats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px 10px; }
.seat { cursor: pointer; display: flex; flex-direction: column; align-items: center; border-radius: 8px; padding: 2px; }
.desk { width: 100%; aspect-ratio: 4 / 3; background: var(--desk); border: 1px solid var(--desk-line); border-radius: 5px; display: grid; place-items: center; font-weight: 700; font-size: clamp(14px, 2.2vw, 26px); color: #3a2a12; }
.chair { width: 62%; height: 12px; background: var(--chair); border-radius: 0 0 6px 6px; position: relative; }
.chair::after { content: ""; position: absolute; left: -10%; right: -10%; top: 9px; height: 9px; background: var(--chair2); border-radius: 0 0 50% 50%; }
.seat { padding-bottom: 8px; }
.seat:hover .desk { filter: brightness(1.05); box-shadow: 0 0 0 2px var(--desk-line); }
.seat.fixed .desk { background: #e9d3b0; color: #6b5636; }
.seat.fixed { cursor: default; }
.seat.same .desk { box-shadow: 0 0 0 2px var(--accent); }
.seat.sel .desk { box-shadow: 0 0 0 3px var(--accent); background: #dbe6ff; }
.seat.bad .desk { box-shadow: 0 0 0 3px var(--bad); background: #fecaca; color: #7f1d1d; }
.seat.hl .desk { box-shadow: 0 0 0 4px var(--accent); }
.readonly .seat { cursor: default; }

/* rules */
.rules { max-height: calc(100vh - 90px); overflow: auto; position: sticky; top: 64px; }
@media (max-width: 1100px) { .rules { max-height: none; position: static; } }
.status { padding: 8px 10px; border-radius: 8px; background: var(--bg); margin-bottom: 8px; }
.status.broken { background: var(--bad-bg); color: var(--bad); }
.status.solved { background: var(--ok-bg); color: var(--ok); font-weight: 700; }
.words summary { cursor: pointer; color: var(--muted); font-size: 12px; padding: 4px 0; }
.wgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 6px; margin-top: 6px; }
.wgrid label { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); }
.wgrid input { font: inherit; padding: 4px 6px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--ink); }
.rlist { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.rule { display: flex; gap: 8px; padding: 8px; border-radius: 8px; border: 1px solid var(--line); }
.rule:hover { border-color: var(--accent); }
.rule p { margin: 0; }
.rule .num { flex: none; width: 24px; height: 24px; border-radius: 50%; background: var(--bg); display: grid; place-items: center; font-size: 12px; font-weight: 700; }
.rule.broken { background: var(--bad-bg); border-color: var(--bad); }
.rule.broken .num { background: var(--bad); color: #fff; }
.fw { font-style: normal; font-weight: 600; text-decoration: underline dotted; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.chip { font-size: 11px; padding: 2px 6px; border-radius: 6px; background: var(--bg); border: 1px solid var(--line); }
.chip i { font-style: normal; font-weight: 600; }
.chip.match { background: var(--ok-bg); border-color: var(--ok); }
.chip.off { background: var(--warn-bg); }
.chip.bad { background: var(--bad); color: #fff; border-color: var(--bad); }

/* new game plus (metro word map) */
.ngp { --land: #d3d3d3; --water: #cdeafc; --tag: #1b1f27; --tag-ink: #fff; --sel: #f59e0b; --warn: #b45309; --disp: "Barlow Condensed", "Arial Narrow", "Roboto Condensed", Arial, sans-serif; padding: 16px; }
@media (prefers-color-scheme: dark) { .ngp { --land: #3a3f48; --water: #1d3442; --tag: #f1f3f6; --tag-ink: #12151b; --sel: #fbbf24; --warn: #fbbf24; } }
.ngp-hint { color: var(--muted); margin: 0 0 14px; max-width: 75ch; }
.ngp-wrap { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 16px; align-items: start; }
@media (max-width: 1100px) { .ngp-wrap { grid-template-columns: minmax(0, 1fr); } }
.ngp-map { position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow-x: auto; min-width: 0; }
.ngp-map svg { display: block; width: 100%; min-width: 860px; height: auto; }
.ngp-map svg text { font-family: var(--disp); }
.ngp-map .water { fill: var(--water); }
.ngp-map .land { fill: var(--land); }
.ngp-pop { position: absolute; z-index: 5; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px; box-shadow: 0 6px 24px rgba(0,0,0,.18); display: flex; flex-direction: column; gap: 4px; min-width: 190px; }
.ngp-pop .ttl { font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); padding: 2px 4px; }
.ngp-pop button { display: flex; align-items: center; gap: 8px; text-align: left; font: inherit; background: transparent; color: var(--ink); border: 1px solid transparent; border-radius: 5px; padding: 5px 6px; cursor: pointer; }
.ngp-pop button:hover { background: var(--bg); border-color: var(--line); }
.ngp-pop .cur { margin-left: auto; color: var(--muted); }
.ldot { width: 14px; height: 6px; border-radius: 2px; flex: none; }
.ngp-side { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.ngp-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.ngp-card h3 { margin: 0 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.ngp-card h3 small { text-transform: none; letter-spacing: 0; font-weight: 400; }
.ngp-status { font-variant-numeric: tabular-nums; }
.ngp-status .msg { color: var(--warn); }
.ngp-bank { display: flex; flex-wrap: wrap; gap: 6px; }
.wchip { font-family: var(--disp); font-weight: 600; font-size: 16px; letter-spacing: .03em; border: 1.5px solid var(--line); background: var(--bg); border-radius: 6px; padding: 4px 9px; cursor: pointer; display: inline-flex; align-items: center; gap: 4px; }
.wchip:hover { border-color: var(--accent); }
.wchip.selected { background: var(--accent); color: #fff; border-color: var(--accent); }
.wchip.unk { border-style: dashed; }
.wchip input { font: inherit; border: 0; border-bottom: 1px solid currentColor; background: transparent; color: inherit; padding: 0 2px; text-transform: uppercase; }
.wchip .len { font-size: 12px; opacity: .7; }
.ngp .empty { color: var(--muted); font-style: italic; }
.ngp-layers { display: flex; flex-direction: column; gap: 8px; }
.ngp-layers label { display: flex; gap: 8px; align-items: flex-start; cursor: pointer; }
.ngp-layers input { margin-top: 3px; accent-color: var(--accent); }
.ngp-layers small { display: block; color: var(--muted); font-size: 12px; }
.ngp-lines { display: flex; flex-direction: column; gap: 6px; }
.lr { display: grid; grid-template-columns: 22px minmax(0, 1fr); gap: 8px; align-items: start; padding: 4px; border-radius: 6px; cursor: pointer; }
.lr:hover, .lr.on { background: var(--bg); }
.lr .sw { width: 22px; height: 8px; border-radius: 2px; margin-top: 6px; }
.lr .ph { font-family: var(--disp); font-size: 16px; letter-spacing: .03em; overflow-wrap: anywhere; }
.lr .ph .gap { color: var(--muted); }
.lr .nt { font-size: 12px; color: var(--muted); }
.ngp .st { cursor: pointer; outline: none; }
.ngp .st circle.ring { fill: #fff; stroke: #000; stroke-width: 5; }
.ngp .st:hover circle.ring, .ngp .st:focus-visible circle.ring { stroke: var(--accent); }
.ngp .st.target circle.ring { stroke: var(--sel); stroke-width: 7; }
.ngp .st .num { font-size: 13px; fill: #000; font-weight: 700; pointer-events: none; }
.ngp .tagg { cursor: pointer; }
.ngp .tagg rect.bg { fill: var(--tag); }
.ngp .tagg text { fill: var(--tag-ink); font-size: 19px; font-weight: 600; letter-spacing: .03em; }
.ngp .tagg:hover rect.bg { fill: #b91c1c; }
.ngp .geo text { paint-order: stroke; stroke: #fff; stroke-width: 5px; stroke-linejoin: round; pointer-events: none; }
.ngp .geo .land { fill: #4a4f57; font-weight: 700; letter-spacing: .06em; }
.ngp .geo .water { fill: #0b5aa6; font-style: italic; font-weight: 600; letter-spacing: .05em; }
.ngp .cand { pointer-events: none; }
.ngp .cand text { paint-order: stroke; stroke: #fff; stroke-width: 5px; stroke-linejoin: round; fill: #c40000; font-weight: 700; font-size: 18px; }
.ngp .cand text.q { fill: #a15c00; }
.ngp .ln { transition: opacity .15s; }
.ngp svg.focus .ln { opacity: .15; }
.ngp svg.focus .ln.hl { opacity: 1; }
.ngp.readonly .st, .ngp.readonly .tagg, .ngp.readonly .wchip { cursor: default; }
@media (prefers-reduced-motion: reduce) { .ngp .ln { transition: none; } }

/* fuzzy logic: attendance limits + rules related to the selected student */
.stud small { display: inline-flex; align-items: center; gap: 1px; }
.stud small.over { color: var(--bad); font-weight: 700; }
.rule.related { background: #fff3b0; border-color: #e0b400; color: #3a2f00; }
.rule.related .num { background: #e0b400; color: #fff; }
.rule.related.broken .num { background: var(--bad); }
.rule.related .chip:not(.match):not(.bad) { background: #fffbe0; color: #3a2f00; }
.stud { position: relative; }
.stud small.cnt.edit { cursor: pointer; padding: 0 3px; border-radius: 4px; border-bottom: 1px dotted currentColor; }
.stud small.cnt.edit:hover { background: var(--panel); color: var(--ink); }
.maxpop { position: absolute; z-index: 20; right: 0; top: calc(100% + 2px); width: 170px; background: var(--panel); color: var(--ink); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.25); padding: 8px; cursor: default; }
.maxpop label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.maxpop input { font: inherit; width: 100%; padding: 4px 6px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--ink); }
.maxpop .row { display: flex; gap: 4px; margin-top: 6px; }
.maxpop button { font: inherit; font-size: 12px; padding: 3px 8px; border-radius: 6px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); cursor: pointer; }
.maxpop button[data-act="save"] { background: var(--accent); border-color: var(--accent); color: #fff; }
/* related rules: unmistakable yellow frame */
.rule.related { border: 3px solid #f5c400; box-shadow: inset 4px 0 0 #f5c400; }
.rule.related.broken { border: 3px solid #f5c400; box-shadow: inset 4px 0 0 var(--bad); background: var(--bad-bg); color: var(--ink); }
