@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&family=IBM+Plex+Mono:wght@400;500;600&family=Playfair+Display:wght@500;600;700&display=swap');

:root {
  color-scheme: dark;
  --bg: #121516;
  --panel: #1a1e1f;
  --surface: #242829;
  --stroke: #393c37;
  --ink: #f4eee3;
  --muted: #c0c0b3;
  --gold: #dfb774;
  --green: #c0d7b3;
  --rose: #ffb0a4;
  --mono: "IBM Plex Mono", Consolas, monospace;
  --serif: "Playfair Display", Georgia, serif;
  --axis: 16px;
}

* { box-sizing: border-box; }
html, body { margin: 0; overflow: hidden; }
body {
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background: var(--bg);
  color: var(--ink);
  font: 500 14px/1.4 "DM Sans", system-ui, sans-serif;
}
button, select { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
button:disabled { cursor: default; }
:focus-visible { outline: 2px solid #ffe0a2; outline-offset: 2px; }
[hidden] { display: none !important; }
svg { width: 18px; height: 18px; display: block; fill: none; stroke: currentColor; stroke-width: 1.65; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; }
.skip { position: fixed; left: 8px; top: 8px; z-index: 3; padding: 10px; background: var(--panel); color: var(--ink); transform: translateY(-150%); }
.skip:focus { transform: none; }

.top { border-bottom: 1px solid #303435; background: #16191a; }
.top-inner { width: min(100%, 510px); margin: auto; min-height: 50px; padding: 2px 10px; display: flex; align-items: center; justify-content: space-between; }
.brand { display: flex; align-items: center; font: 700 26px/1 var(--serif); letter-spacing: -.04em; }
.brand-dot { color: var(--gold); }
.brand-mark { width: 30px; height: 30px; border: 1px solid #876b41; border-radius: 8px; display: grid; place-items: center; margin-right: 8px; color: var(--gold); background: #28241d; }
.brand-mark i { width: 12px; height: 12px; transform: translate(-1px,-1px); position: relative; border: 1.8px solid currentColor; border-radius: 50%; }
.brand-mark i::after { content: ""; position: absolute; width: 6px; height: 2px; border-radius: 2px; background: currentColor; transform: rotate(45deg); bottom: -2px; right: -4px; }
nav { display: flex; align-items: center; gap: 5px; }
.nav-archive, .icon-button, .close { display: inline-flex; justify-content: center; align-items: center; gap: 6px; min-width: 42px; min-height: 42px; border: 1px solid var(--stroke); border-radius: 8px; background: #212526; color: var(--muted); padding: 0 8px; }
.nav-archive { color: #ebcc95; border-color: #69573b; background: #2a251d; font-size: 13px; }
.icon-button:disabled { opacity: .45; }

.shell { width: min(100%, 510px); margin: 0 auto; padding: 7px; min-height: 0; display: grid; grid-template-rows: auto minmax(0, 1fr); gap: 6px; }
.hero {
  min-height: 67px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 7px;
  border: 1px solid #51483a;
  border-radius: 11px;
  padding: 7px 8px 8px 11px;
  background: linear-gradient(90deg, #1b2021 0%, #1b2021e8 42%, #171b1cc4 68%, #171b1c44 100%),
    #242829 url('manor.jpg') center 52% / cover no-repeat;
}
.hero-body { min-width: 0; }
.hero-meta { display: flex; gap: 6px; align-items: center; color: var(--gold); font: 500 10px/1.3 var(--mono); letter-spacing: .045em; }
#case-location { color: #d4d2c4; letter-spacing: 0; }
.hero-divider { height: 3px; width: 3px; flex: none; border-radius: 50%; background: #b09568; }
.hero h1 { margin: 1px 0 0; font: 600 clamp(20px, 6.5vw, 33px)/1.12 var(--serif); letter-spacing: -.035em; overflow-wrap: anywhere; }
.case-actions { display: flex; flex-direction: column; gap: 1px; align-items: flex-end; flex: none; }
.case-actions .icon-button { min-height: 31px; min-width: 39px; background: #1b1e1ed9; color: #ebcc95; border-color: #66583e; }
.case-actions .icon-button svg { width: 15px; height: 15px; }
.difficulty { color: #e6d8b1; border: 1px solid #685941; border-radius: 100px; background: #24241e; padding: 2px 6px; display: inline-flex; align-items: center; gap: 4px; font: 500 9px/1.15 var(--mono); }
.difficulty::before { content: ""; background: var(--difficulty-color, #b9ce9c); border-radius: 50%; width: 5px; height: 5px; }

.game-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  min-width: 0;
  min-height: 0;
  border-radius: 11px;
  border: 1px solid var(--stroke);
  background: var(--panel);
}
.mobile-dossier { padding: 7px 7px 0; }
.tokens { display: grid; grid-template-columns: repeat(var(--size, 8), minmax(0, 1fr)); gap: 3px; }
.token {
  height: 47px;
  min-width: 0;
  position: relative;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 3px;
  border: 1px solid var(--stroke);
  background: #222627;
  border-radius: 6px;
  padding: 0;
}
.token[aria-pressed=true] { border-color: var(--chip); background: #342d23; }
.token-name { color: #e8e1d5; font-size: clamp(8px, 2.35vw, 11px); line-height: 1; }
.token-dot { display: none; position: absolute; top: 2px; right: 2px; width: 5px; height: 5px; border-radius: 50%; background: var(--green); }
.token.placed .token-dot { display: block; }
.avatar { background: var(--chip); color: #1b1c1c; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; flex: none; font: 700 14px/1 var(--serif); }
.token .avatar { width: 22px; height: 22px; font-size: 12px; }
.active-clue { margin-top: 5px; min-height: 47px; padding: 3px 7px; border-left: 2px solid #97784c; background: #222523; border-radius: 0 5px 5px 0; color: #e5dfd3; font-size: 13px; line-height: 1.25; }
.active-clue strong { color: #f1cc8f; margin-right: 5px; }
.active-clue .coordinate { color: var(--green); margin-left: 4px; font: 500 10px/1 var(--mono); white-space: nowrap; }

.board-area { min-width: 0; min-height: 0; margin: 2px 7px 1px; container-type: size; display: grid; place-items: center; }
.floor-plan {
  --plan-size: min(100cqw, 100cqh, 450px);
  width: var(--plan-size);
  height: var(--plan-size);
  display: grid;
  grid-template-columns: var(--axis) minmax(0, 1fr);
  grid-template-rows: var(--axis) minmax(0, 1fr);
}
.column-axis, .row-axis { display: grid; color: #c6c7b9; font: 500 10px/1 var(--mono); text-align: center; }
.column-axis { grid-area: 1/2; grid-template-columns: repeat(var(--size), minmax(0, 1fr)); align-items: center; }
.row-axis { grid-area: 2/1; grid-template-rows: repeat(var(--size), minmax(0, 1fr)); align-items: center; justify-content: center; }
.grid { grid-area: 2/2; display: grid; grid-template-columns: repeat(var(--size), minmax(0, 1fr)); grid-template-rows: repeat(var(--size), minmax(0, 1fr)); border: 2px solid #aea48c; border-radius: 6px; overflow: clip; }
.cell { background: var(--room); border: 0; border-right: 1px solid #eae5d52e; border-bottom: 1px solid #eae5d52e; border-radius: 0; padding: 0; display: grid; place-items: center; min-width: 0; min-height: 0; position: relative; color: #ede5d1; font: 500 10px/1 var(--mono); }
.cell.wall-right { border-right: 2px solid #a49a81; }
.cell.wall-bottom { border-bottom: 2px solid #a49a81; }
.cell.edge-right { border-right: 0; }
.cell.edge-bottom { border-bottom: 0; }
.cell:focus-visible { outline: 2px solid #fff0ad; outline-offset: -3px; z-index: 1; }
.cell[data-object] { background-image: repeating-linear-gradient(135deg, #17181738 0 2px, transparent 2px 6px); cursor: default; }
.cell svg { width: clamp(11px, 4.4cqw, 21px); height: clamp(11px, 4.4cqw, 21px); }
.cell .avatar { width: 69%; height: auto; aspect-ratio: 1; max-width: 34px; font-size: clamp(9px, 3.2cqw, 15px); border: 1px solid #0c0c0d55; }
.cell .mark-icon { color: #f1e8d7; opacity: .7; }
.room-index { position: absolute; top: 2px; left: 2px; font-size: 8px; }
.cell.incorrect::after, .cell.hinted::after { position: absolute; content: ""; inset: 1px; border: 2px dashed var(--rose); border-radius: 3px; pointer-events: none; }
.cell.hinted::after { border-color: #ffe0a2; border-style: solid; }
.cell.selected .avatar { outline: 1px solid #f3d6a4; outline-offset: 1px; }
.board-caption { position: relative; min-width: 0; margin: 0 8px 4px; }
.plan-legend { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 3px 4px; padding: 1px 0; color: #e0ddcf; font-size: 10px; }
.room-key { display: flex; gap: 4px; align-items: center; white-space: nowrap; }
.room-swatch { background: var(--room); border: 1px solid #d3c5a17a; color: #fff3df; display: grid; place-items: center; border-radius: 3px; width: 13px; height: 13px; flex: none; font: 500 8px/1 var(--mono); }
.feedback-slot { position: absolute; inset: 0; display: grid; align-items: center; }
.board-caption:has(.message:not([hidden])) .plan-legend { visibility: hidden; }
.feedback-slot:has(.message[hidden]) { pointer-events: none; }
.message { color: #f2d6a4; border: 1px solid #826842; border-radius: 7px; background: #302720; padding: 3px 6px; margin: 0; font-size: 11px; line-height: 1.2; }
.message[data-tone=good] { background: #243026; color: #d7edcd; border-color: #617d60; }
.message[data-tone=error] { background: #362826; color: #ffc2b6; border-color: #895f54; }

.game-tools { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); padding: 5px 6px; gap: 4px; border-top: 1px solid var(--stroke); }
.tool, .secondary { background: #222627; border: 1px solid var(--stroke); border-radius: 7px; min-height: 40px; }
.tool { display: flex; gap: 4px; align-items: center; justify-content: center; font-size: clamp(10px, 2.9vw, 12px); color: #e4ded2; padding: 0 2px; }
.tool svg { width: 14px; height: 14px; }
.tool[aria-pressed=true] { border-color: var(--gold); color: #ffdfa5; background: #30291d; }
.tool:disabled { opacity: .52; }
.game-actions { display: flex; align-items: center; justify-content: space-between; gap: 7px; border-top: 1px solid var(--stroke); padding: 5px 6px; }
.progress-label { color: var(--muted); white-space: nowrap; font: 500 11px/1.2 var(--mono); }
.progress-label strong { color: var(--ink); }
.progress-dots { display: flex; gap: 3px; margin-top: 4px; }
.progress-dots span { width: 10px; height: 3px; border-radius: 3px; background: #4c4940; }
.progress-dots .filled { background: var(--gold); }
.primary { display: inline-flex; min-height: 43px; padding: 0 12px; align-items: center; justify-content: center; gap: 6px; border-radius: 8px; background: var(--gold); border: 1px solid #edc88b; color: #1f1a12; font-weight: 700; font-size: 13px; }
.primary svg { width: 17px; height: 17px; stroke-width: 2; }

dialog { width: min(calc(100% - 20px), 435px); max-height: calc(100dvh - 20px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); overflow: auto; padding: 0; border: 1px solid #59584d; border-radius: 13px; background: var(--panel); color: var(--ink); box-shadow: 0 16px 60px #000b; }
dialog::backdrop { background: #070909c9; }
.dialog-inner { padding: 12px; }
.dialog-heading { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.dialog-heading h2 { font: 600 24px/1.1 var(--serif); letter-spacing: -.025em; margin: 0; }
.dialog-heading .close { flex: none; }
.dialog-note { margin: 7px 0 11px; color: #ded9ce; font-size: 13px; }
.dialog-button { width: 100%; }
.dialog-buttons { display: flex; justify-content: end; gap: 6px; }
.secondary { padding: 0 12px; }
.case-details { font: 500 11px/1.3 var(--mono); color: var(--gold); margin: 6px 0 0; }
.rules { padding-left: 19px; margin: 8px 0 9px; color: #ddd8cb; }
.rules li { padding: 0 0 5px 2px; }
.rules strong { color: var(--ink); }
.object-key { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px; padding: 3px 0 10px; color: var(--muted); font-size: 12px; }
.object-key span { display: flex; align-items: center; gap: 4px; }
.object-key svg { width: 15px; height: 15px; color: var(--gold); }
.archive-filters { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin: 7px 0; }
.archive-filters p { margin: 0; font-size: 12px; }
select { min-height: 38px; min-width: 0; border: 1px solid #57574e; border-radius: 7px; background: var(--surface); color: var(--ink); padding: 0 4px; font-size: 12px; }
.archive-list, .accuse-list { display: grid; gap: 5px; }
.accuse-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.case-item, .accuse-item { display: flex; text-align: left; align-items: center; gap: 7px; width: 100%; min-height: 46px; border: 1px solid var(--stroke); border-radius: 7px; background: var(--surface); padding: 4px 7px; }
.case-item[aria-current=true] { border-color: #aa8b57; background: #30291f; }
.case-index { font: 500 11px/1 var(--mono); color: var(--gold); }
.case-data { display: grid; flex: 1; min-width: 0; }
.case-data small { color: var(--muted); }
.case-done { color: var(--green); font: 500 9px/1 var(--mono); }
.pagination { display: flex; justify-content: center; align-items: center; gap: 7px; margin-top: 7px; }
.pagination .previous svg { transform: rotate(180deg); }
.accuse-item:disabled { opacity: .58; }
.accuse-item.correct { opacity: 1; border-color: #839a7f; background: #263226; }
#accuse-feedback, #next-case { margin-top: 7px; }

@media (min-height: 760px) {
  .top-inner { min-height: 55px; }
  .shell { gap: 8px; padding: 8px; }
  .hero { min-height: 82px; }
  .mobile-dossier { padding-top: 9px; }
  .token { height: 51px; }
  .token .avatar { width: 24px; height: 24px; }
  .active-clue { padding-top: 5px; }
  .plan-legend { font-size: 11px; }
  .game-actions, .game-tools { padding: 7px 8px; }
  .tool, .primary { min-height: 45px; }
}
@media (max-height: 640px) and (orientation: portrait) {
  .top-inner { min-height: 44px; }
  .top-inner button { min-height: 36px; }
  .shell { padding: 5px; gap: 4px; }
  .hero { min-height: 53px; padding-block: 3px; }
  .hero h1 { font-size: clamp(19px, 6vw, 25px); }
  .case-actions .icon-button { min-height: 27px; }
  .mobile-dossier { padding-top: 4px; }
  .token { height: 40px; gap: 2px; }
  .token .avatar { width: 20px; height: 20px; }
  .active-clue { margin-top: 3px; min-height: 35px; font-size: 12px; }
  .game-tools, .game-actions { padding-block: 3px; }
  .tool { min-height: 35px; }
  .game-actions .primary { min-height: 40px; }
}
@media (max-width: 350px) {
  .tool { gap: 2px; }
  .tool svg { width: 12px; height: 12px; }
}
@media (orientation: landscape) and (max-height: 520px) {
  .top-inner, .shell { width: min(100%, 780px); }
  .top-inner { min-height: 42px; }
  .top-inner button { min-height: 34px; }
  .shell { padding: 4px; gap: 4px; grid-template: auto auto minmax(0, 1fr) auto / minmax(0, 1fr) minmax(0, 1fr); }
  .hero { grid-area: 1 / 2; min-height: 43px; padding: 3px 8px; }
  .hero h1 { font-size: 22px; }
  .case-actions { flex-direction: row; align-items: center; gap: 6px; }
  .game-panel { display: contents; }
  .board-area { grid-area: 1 / 1 / 5 / 2; }
  .board-caption { grid-area: 3 / 2; align-self: start; margin-top: 6px; }
  .mobile-dossier { grid-area: 2 / 2; padding: 4px 2px 0; }
  .game-controls { grid-area: 4 / 2; }
  .token { height: 39px; }
  .active-clue { font-size: 12px; }
  .tool, .game-actions .primary { min-height: 35px; }
  .game-tools, .game-actions { padding-block: 3px; }
  .archive-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .accuse-list { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
