:root {
  --bg: #ece2cc; --paper: #fbf6ea; --paper2: #f4ecd9; --ink: #2b2118; --muted: #7a6450; --line: #d8c9ab;
  --accent: #b3261e; --accent-ink: #fff; --blue: #1f4e79; --ok: #2e7d32; --err: #b3261e;
  --shadow: 0 1px 0 rgba(43,33,24,.06), 0 10px 30px rgba(43,33,24,.10);
  --serif: Georgia, "Times New Roman", serif; --mono: "Courier New", ui-monospace, Menlo, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #15110c; --paper: #221b14; --paper2: #2b2219; --ink: #f2e7d1; --muted: #b9a68b; --line: #3c3127;
  --accent: #e2533e; --blue: #8cb8e8; --ok: #81c784; --err: #ff8a7a; --shadow: 0 10px 30px rgba(0,0,0,.45); color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15110c; --paper: #221b14; --paper2: #2b2219; --ink: #f2e7d1; --muted: #b9a68b; --line: #3c3127;
    --accent: #e2533e; --blue: #8cb8e8; --ok: #81c784; --err: #ff8a7a; --shadow: 0 10px 30px rgba(0,0,0,.45); color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--sans); color: var(--ink); background: var(--bg);
  background-image: radial-gradient(rgba(120,90,50,.07) 1px, transparent 1px); background-size: 18px 18px;
  min-height: 100vh; line-height: 1.45; -webkit-tap-highlight-color: transparent;
}
body.modal-open { overflow: hidden; }
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { opacity: .45; cursor: default; }
[hidden] { display: none !important; }

.top {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between;
  padding: 8px max(12px, env(safe-area-inset-left)); background: #2b2118; color: #f6ecd8;
  box-shadow: 0 2px 10px rgba(0,0,0,.25);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo { width: 34px; height: 34px; flex: none; }
.brand-txt { display: flex; flex-direction: column; min-width: 0; }
.brand-name { font-family: var(--serif); font-size: 1.35rem; font-weight: 700; letter-spacing: .5px; line-height: 1.1; }
.brand-name em { color: #e2533e; font-style: normal; }
#tagline { font-size: .72rem; opacity: .75; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; gap: 2px; }
.icon-btn { background: none; border: 0; padding: 8px; border-radius: 10px; display: grid; place-items: center; }
.icon-btn:hover { background: rgba(255,255,255,.1); }
.icon-btn.small { padding: 4px; }

.banner {
  max-width: 1080px; margin: 10px auto 0; padding: 8px 12px; border-radius: 12px; background: #fff3c4; color: #5a4300;
  display: flex; align-items: center; justify-content: center; gap: 8px; flex-wrap: wrap; font-size: .9rem; border: 1px solid #e6cf7a;
}
main { max-width: 1080px; margin: 0 auto; padding: 10px 12px 24px; display: grid; gap: 12px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 900px) {
  main { grid-template-columns: minmax(0, 560px) minmax(0, 1fr); grid-template-areas: "head head" "board side" "legend side" "dock side" "tools side" ". side"; align-items: start; }
  .case-head { grid-area: head; } .board-area { grid-area: board; } #rooms { grid-area: legend; } .dock { grid-area: dock; }
  .tools { grid-area: tools; } .side { grid-area: side; position: sticky; top: 70px; }
}
.case-head { text-align: center; }
.case-meta { font-family: var(--mono); font-size: .8rem; color: var(--muted); display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; text-transform: uppercase; letter-spacing: .5px; }
.case-head h1 { font-family: var(--serif); font-size: clamp(1.25rem, 5vw, 1.8rem); margin: 2px 0 6px; line-height: 1.15; }
.case-sub { display: flex; align-items: center; justify-content: center; gap: 12px; flex-wrap: wrap; }
.diff { font-size: .85rem; color: var(--accent); font-weight: 600; letter-spacing: .5px; }
.timer-wrap { display: inline-flex; align-items: center; gap: 4px; background: var(--paper); border: 1px solid var(--line); border-radius: 999px; padding: 2px 4px 2px 12px; }
#timer { font-family: var(--mono); font-weight: 700; font-size: 1.05rem; min-width: 3.4em; text-align: right; }
#bPause { color: var(--ink); }

.board-area { position: relative; background: var(--paper); border-radius: 16px; padding: 8px; box-shadow: var(--shadow); }
.board svg { display: block; width: 100%; height: auto; touch-action: manipulation; user-select: none; -webkit-user-select: none; cursor: pointer; }
.board.hidden-board { filter: blur(9px) saturate(.6); pointer-events: none; }
.compass { position: absolute; top: 12px; right: 14px; z-index: 2; font: 700 11px var(--mono); color: var(--muted); display: none; }
.rlabel { font: 700 15px var(--sans); fill: rgba(43,33,24,.62); letter-spacing: .6px; paint-order: stroke; stroke: rgba(255,255,255,.55); stroke-width: 3px; pointer-events: none; }
.tok.sel { filter: drop-shadow(0 0 7px #ffcf33) drop-shadow(0 0 3px #ffcf33); }
.tok.bad > circle:nth-child(2) { stroke: #e53935; stroke-width: 7; }
.flash { animation: flash .6s ease-in-out 2; }
@keyframes flash { 50% { opacity: .1; } }

.overlay { position: absolute; inset: 0; display: grid; place-items: center; padding: 16px; z-index: 5; }
.ov-card {
  background: var(--paper); border-radius: 18px; padding: 20px 18px; max-width: 360px; width: 100%; text-align: center;
  box-shadow: var(--shadow); border: 1px solid var(--line);
}
.ov-card h2 { font-family: var(--serif); margin: 4px 0 8px; font-size: 1.35rem; line-height: 1.2; }
.ov-card p { margin: 6px 0; }
.ov-kicker { font: 700 .75rem var(--mono); text-transform: uppercase; letter-spacing: 1px; color: var(--accent); }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 4px solid var(--line); border-top-color: var(--accent); margin: 8px auto; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.legend { display: flex; flex-wrap: wrap; gap: 5px; justify-content: center; }
.room-chip { font-size: .75rem; padding: 2px 9px; border-radius: 999px; background: var(--rc); color: #2b2118; border: 1px solid rgba(43,33,24,.15); font-weight: 600; }

.dock { display: grid; gap: 8px; }
@media (max-width: 899px) {
  .dock { position: sticky; bottom: 0; z-index: 10; margin: 0 -12px; padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); background: var(--bg); box-shadow: 0 -6px 16px rgba(43,33,24,.12); border-top: 1px solid var(--line); }
  .dock .chip { font-size: .84rem; padding: 3px 9px 3px 3px; }
  .dock .dot { width: 25px; height: 25px; font-size: .85rem; }
  .dock .sel-info { padding: 6px 10px; font-size: .9rem; min-height: 0; }
}
.palette { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px 4px 4px; border-radius: 999px;
  background: var(--paper); border: 2px solid var(--line); font-weight: 600; font-size: .9rem; transition: transform .1s;
}
.chip:active { transform: scale(.96); }
.chip.sel { border-color: #e0a800; box-shadow: 0 0 0 3px rgba(255,200,40,.35); background: #fff7d6; color: #2b2118; }
.chip.placed:not(.sel) { opacity: .6; }
.chip.placed .dot::after { content: "✓"; position: absolute; right: -4px; bottom: -4px; background: var(--ok); color: #fff; border-radius: 50%; width: 14px; height: 14px; font-size: 9px; display: grid; place-items: center; border: 1.5px solid #fff; }
.dot {
  position: relative; width: 28px; height: 28px; border-radius: 50%; background: var(--c); color: #fff; display: inline-grid; place-items: center;
  font-weight: 800; font-size: .95rem; flex: none; border: 2px solid #fff; box-shadow: 0 1px 2px rgba(0,0,0,.3);
}
.dot.sm { width: 22px; height: 22px; font-size: .78rem; vertical-align: -5px; }
.dot.victim { background: none; border: 0; box-shadow: none; }
.dot.x { background: #7a2f20; }

.sel-info { min-height: 2.6em; background: var(--paper); border: 1px dashed var(--line); border-radius: 12px; padding: 8px 12px; font-size: .95rem; }
.sel-info p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: .8rem; }
.nm-chip { display: inline-block; background: var(--c); color: #fff; font-weight: 700; padding: 0 7px; border-radius: 999px; line-height: 1.35; white-space: nowrap; }
.nm-chip.victim { background: #2b2118; color: #fbf8f2; }

.tools { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tool {
  display: flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 6px; border-radius: 12px;
  background: var(--paper); border: 1px solid var(--line); font-weight: 600; font-size: .9rem; box-shadow: 0 1px 0 rgba(0,0,0,.05);
}
#bHint:not(:disabled) { background: #fff3c4; color: #5a4300; border-color: #e6cf7a; }

.side { display: grid; gap: 12px; }
.clues { background: var(--paper); border-radius: 16px; padding: 12px 14px; box-shadow: var(--shadow); }
.clues h2 { font-family: var(--serif); font-size: 1.15rem; margin: 0 0 8px; }
#clueList { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
#clueList li { display: flex; gap: 10px; align-items: flex-start; padding: 8px; border-radius: 10px; background: var(--paper2); cursor: pointer; border: 2px solid transparent; }
#clueList li.sel { border-color: #e0a800; }
#clueList li.placed { opacity: .62; }
#clueList .txt { padding-top: 2px; }
.victim-note { font-size: .85rem; color: var(--muted); margin: 10px 2px 0; }
.extras { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: center; }
.link-btn { display: inline-flex; align-items: center; gap: 6px; background: var(--paper); border: 1px solid var(--line); border-radius: 999px; padding: 7px 14px; font-weight: 600; font-size: .9rem; }
.next { width: 100%; text-align: center; font-size: .85rem; color: var(--muted); }
.next b { font-family: var(--mono); color: var(--ink); }

.foot { max-width: 1080px; margin: 0 auto; padding: 8px 16px 32px; text-align: center; font-size: .8rem; color: var(--muted); }
.langs button { background: none; border: 0; padding: 4px 6px; color: var(--muted); text-decoration: underline; }
.langs button.on { color: var(--ink); font-weight: 700; text-decoration: none; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; background: var(--accent); color: var(--accent-ink);
  border: 0; border-radius: 12px; padding: 10px 16px; font-weight: 700; box-shadow: 0 2px 0 rgba(0,0,0,.18);
}
.btn.big { padding: 13px 22px; font-size: 1.05rem; margin-top: 8px; }
.btn.small { padding: 5px 10px; font-size: .82rem; border-radius: 9px; }
.btn.ghost { background: var(--paper2); color: var(--ink); border: 1px solid var(--line); box-shadow: none; }
.btn.wide { width: 100%; margin-top: 8px; }
.row-btns { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin: 12px 0 4px; }
.row-btns .btn { flex: 1 1 140px; }

.modal { position: fixed; inset: 0; z-index: 50; background: rgba(20,14,8,.55); display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
@keyframes fade { from { opacity: 0; } }
.sheet {
  position: relative; background: var(--paper); width: 100%; max-width: 560px; max-height: 92vh; border-radius: 20px 20px 0 0;
  box-shadow: var(--shadow); animation: up .2s ease-out; display: flex; flex-direction: column;
}
@keyframes up { from { transform: translateY(30px); opacity: .6; } }
@media (min-width: 640px) { .modal { align-items: center; } .sheet { border-radius: 20px; max-height: 86vh; } }
#mBody { overflow: auto; padding: 18px 18px calc(22px + env(safe-area-inset-bottom)); -webkit-overflow-scrolling: touch; }
.m-title { font-family: var(--serif); margin: 0 34px 10px 0; font-size: 1.35rem; }
.close { position: absolute; top: 8px; right: 10px; background: none; border: 0; font-size: 1.8rem; line-height: 1; padding: 4px 10px; color: var(--muted); z-index: 2; }
#mBody h3 { font-family: var(--serif); margin: 16px 0 6px; font-size: 1.05rem; }
.lead { font-size: 1.05rem; }
.err { color: var(--err); font-weight: 600; }
.ok { color: var(--ok); font-weight: 700; }
.note { background: #fff3c4; color: #5a4300; border-radius: 10px; padding: 8px 10px; font-size: .85rem; }
.hint-big { display: grid; place-items: center; color: #c79a00; }
.hint-big svg { width: 48px; height: 48px; }

.stamp {
  margin: 4px auto 10px; width: max-content; font: 800 1.5rem var(--mono); color: var(--accent); border: 4px double var(--accent);
  padding: 6px 16px; border-radius: 8px; transform: rotate(-6deg); letter-spacing: 2px; text-transform: uppercase; animation: stamp .45s cubic-bezier(.2,1.6,.4,1);
}
@keyframes stamp { from { transform: rotate(-6deg) scale(2.2); opacity: 0; } }
.times { width: 100%; border-collapse: collapse; margin: 8px 0; }
.times td { padding: 6px 4px; border-bottom: 1px solid var(--line); }
.times td:last-child { text-align: right; font-family: var(--mono); font-weight: 700; }
.times tr.tot td { font-size: 1.1rem; border-bottom: 0; }
.submit-box { background: var(--paper2); border-radius: 12px; padding: 10px; margin: 10px 0; }
.name-row { display: flex; gap: 8px; }
.name-row input { flex: 1; min-width: 0; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--paper); color: var(--ink); font-size: 1rem; }
.next-line { text-align: center; color: var(--muted); font-size: .9rem; margin-top: 10px; }
.next-line b { font-family: var(--mono); color: var(--ink); }
.share-ta { width: 100%; min-height: 110px; padding: 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--paper2); color: var(--ink); font: .95rem var(--mono); }

.accuse-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; margin-top: 10px; }
.accuse-btn { display: flex; align-items: center; gap: 8px; padding: 10px; border-radius: 12px; background: var(--paper2); border: 2px solid var(--line); font-weight: 700; }
.accuse-btn:hover { border-color: var(--accent); }
.accuse-btn.nope { text-decoration: line-through; opacity: .45; border-color: var(--err); }

.tabs { display: flex; gap: 6px; margin-bottom: 10px; }
.tab { flex: 1; padding: 8px; border-radius: 10px; border: 1px solid var(--line); background: var(--paper2); font-weight: 600; }
.tab.on { background: var(--ink); color: var(--paper); }
.rank-list { list-style: none; margin: 0; padding: 0; }
.rank-list li { display: flex; align-items: center; gap: 10px; padding: 8px 6px; border-bottom: 1px solid var(--line); }
.rank-list li.me { background: #fff3c4; color: #2b2118; border-radius: 8px; }
.rank-list .pos { width: 2.2em; text-align: center; font-weight: 700; }
.rank-list .who { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.rank-list .val { font-family: var(--mono); font-weight: 700; white-space: nowrap; }
.gap { text-align: center; color: var(--muted); }

.archive-list { list-style: none; margin: 0; padding: 0; }
.archive-list li { display: grid; grid-template-columns: 3em 1fr auto auto; align-items: center; gap: 8px; padding: 7px 2px; border-bottom: 1px solid var(--line); font-size: .9rem; }
.a-num { font-family: var(--mono); color: var(--muted); }
.a-done { color: var(--ok); font-family: var(--mono); font-weight: 700; }

.stat-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; text-align: center; }
.stat { background: var(--paper2); border-radius: 10px; padding: 8px 2px; }
.stat b { display: block; font-size: 1.3rem; font-family: var(--mono); }
.stat span { font-size: .68rem; color: var(--muted); }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg-btn { padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--paper2); font-weight: 600; }
.seg-btn.on { background: var(--ink); color: var(--paper); }
.check { display: flex; align-items: center; gap: 8px; margin-top: 16px; font-weight: 600; }
.check input { width: 20px; height: 20px; }

.rules { padding-left: 1.2em; margin: 0; display: grid; gap: 6px; }
.legend-title { text-align: center; font-size: .82rem; color: var(--muted); margin: 14px 0 0; font-weight: 700; }
.legend-objs { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 6px; margin-top: 6px; }
.legend-objs .obj { display: flex; align-items: center; gap: 8px; padding: 4px 8px; border-radius: 10px; background: var(--paper2); font-size: .88rem; }
.legend-objs .obj b { margin-left: auto; }
.legend-objs .obj.yes b { color: var(--ok); } .legend-objs .obj.no b { color: var(--err); }
.legend-objs .ico { width: 40px; height: 40px; background: #f2e3c4; border-radius: 8px; flex: none; }
.mini-board { max-width: 340px; margin: 8px auto; }
.mini-board svg { width: 100%; height: auto; display: block; }
.sol-clues { padding-left: 1.2em; display: grid; gap: 4px; font-size: .92rem; }

.toast {
  position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); z-index: 60;
  background: #2b2118; color: #f6ecd8; padding: 10px 16px; border-radius: 12px; max-width: min(92vw, 460px); text-align: center;
  box-shadow: 0 8px 24px rgba(0,0,0,.3); opacity: 0; transition: opacity .25s, transform .25s; font-weight: 600; font-size: .92rem;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
body.modal-open .toast { bottom: auto; top: calc(14px + env(safe-area-inset-top)); }
@media (max-width: 380px) { .chip .nm { font-size: .8rem; } .chip { padding-right: 8px; } .tool { font-size: .8rem; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
