:root {
  --bg: #14141f;
  --panel: #1d1d2e;
  --panel2: #242438;
  --line: #2f2f47;
  --text: #eceaf5;
  --muted: #9aa0b5;
  --accent: #e0b34f;
  --danger: #e0566b;
  --ok: #39b66b;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  min-height: 100vh;
}

#app { max-width: 560px; margin: 0 auto; padding: 12px 12px 24px; }
.screen.hidden, .modal.hidden, .toast.hidden { display: none !important; }

/* ——— Каталог ——— */
.catalog-header { text-align: center; padding: 18px 0 6px; }
.brand { font-size: 28px; font-weight: 800; letter-spacing: 3px; }
.brand-sub { color: var(--muted); margin-top: 4px; font-size: 14px; }

.section-title { margin: 20px 4px 10px; font-size: 14px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }

.case-card {
  display: block; width: 100%; text-align: left;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 14px 16px; margin-bottom: 10px; color: var(--text);
  font-size: 16px; cursor: pointer;
}
.case-card:active { transform: scale(0.985); }
.case-card .case-card-desc { color: var(--muted); font-size: 13px; margin-top: 4px; }
.case-card .solved-mark { float: right; }

.new-cases .case-card { border-left: 4px solid var(--line); }
.new-cases .diff-easy { border-left-color: #39b66b; }
.new-cases .diff-medium { border-left-color: #e0b34f; }
.new-cases .diff-hard { border-left-color: #e0566b; }

.rules-link { text-align: center; margin-top: 18px; }
.link-btn { background: none; border: none; color: var(--muted); text-decoration: underline; font-size: 14px; cursor: pointer; }

/* ——— Экран дела ——— */
.game-header {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 0 10px;
}
.game-title { flex: 1; min-width: 0; }
#case-title { font-weight: 700; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.case-subtitle { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.header-right { display: flex; align-items: center; gap: 8px; }
.timer { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 14px; }

.icon-btn {
  background: var(--panel); border: 1px solid var(--line); color: var(--text);
  width: 34px; height: 34px; border-radius: 10px; font-size: 17px; cursor: pointer;
}

#grid-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 8px; }
#grid { display: block; width: 100%; height: auto; touch-action: manipulation; }

/* ——— Подозреваемые ——— */
#suspects-bar { margin-top: 10px; display: grid; gap: 8px; }
.suspect-card {
  display: flex; gap: 10px; align-items: flex-start;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 9px 10px; cursor: pointer; transition: border-color .15s, background .15s;
}
.suspect-card.selected { border-color: var(--accent); background: var(--panel2); box-shadow: 0 0 0 1px var(--accent); }
.avatar {
  width: 40px; height: 40px; min-width: 40px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 17px; color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,.4);
}
.suspect-info { flex: 1; min-width: 0; }
.suspect-name { font-weight: 700; font-size: 14px; display: flex; align-items: center; gap: 6px; }
.cell-ref { color: var(--muted); font-weight: 400; font-size: 12px; }
.clue { font-size: 13px; color: var(--text); margin-top: 3px; line-height: 1.35; }
.clue::before { content: '• '; color: var(--accent); }

.victim-card { border-style: dashed; cursor: default; }
.victim-card .avatar { background: #3a3a4d !important; }
.victim-card .name-x { text-decoration: line-through; }

/* ——— Кнопки ——— */
.actions { display: flex; gap: 8px; margin-top: 10px; }
.action-btn {
  flex: 1; padding: 11px 8px; border-radius: 12px; cursor: pointer;
  background: var(--panel2); color: var(--text); border: 1px solid var(--line);
  font-size: 14px; font-weight: 600;
}
.action-btn:disabled { opacity: 0.4; }
.action-btn.primary { background: var(--accent); border-color: var(--accent); color: #17151f; }
.action-btn.danger { flex: 0 0 48px; color: var(--danger); }
.action-btn.active-mode { box-shadow: 0 0 0 2px var(--danger); }

.victim-strip {
  margin-top: 10px; padding: 10px 12px; border-radius: 12px;
  background: rgba(141, 153, 174, 0.12); border: 1px dashed #8d99ae;
  font-size: 13px; display: flex; gap: 8px; align-items: center;
}

/* ——— Модалки ——— */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px;
}
.modal-box {
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  padding: 20px; max-width: 400px; width: 100%; text-align: center;
  max-height: 85vh; overflow-y: auto;
}
.modal-title { font-size: 20px; font-weight: 800; margin-bottom: 8px; }
.modal-text { color: var(--muted); font-size: 14px; line-height: 1.45; margin-bottom: 14px; }
.accuse-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(86px, 1fr)); gap: 8px; margin-bottom: 14px; }
.accuse-item {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 6px; cursor: pointer; font-size: 13px; font-weight: 600;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.accuse-item:active { transform: scale(0.96); }

.win-badge { font-size: 44px; margin-bottom: 6px; }
.win-box { border-color: var(--accent); }
.win-actions { display: flex; gap: 8px; }
.win-actions .action-btn { flex: 1; }

.rules { text-align: left; font-size: 13.5px; line-height: 1.5; color: var(--text); }
.rules p { margin-bottom: 10px; }

/* ——— Тост ——— */
.toast {
  position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%);
  background: #2e2e44; color: var(--text); border: 1px solid var(--line);
  padding: 10px 16px; border-radius: 12px; font-size: 13.5px; z-index: 60;
  max-width: 86vw; text-align: center; box-shadow: 0 4px 16px rgba(0,0,0,.4);
}
/* Mobile case desk */
.hidden { display: none !important; }
#app { padding: max(10px, var(--safe-top, 0px)) max(10px, var(--safe-right, 0px)) max(24px, var(--safe-bottom, 0px)) max(10px, var(--safe-left, 0px)); }
button { font-family: inherit; touch-action: manipulation; color: inherit; }
button:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
button:disabled { cursor: default; }
.case-meta { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; padding: 0 3px 8px; }
#save-status { font-size: 12px; min-height: 28px; }
.board-dock { background: var(--bg); }
#grid-wrap { padding: 8px 6px 6px; border-radius: 16px; background: #1c2029; border-color: #434346; }
#person-picker { display: flex; overflow-x: auto; gap: 6px; padding: 10px 2px 7px; scrollbar-width: thin; }
.person-chip { flex: 0 0 auto; display: flex; align-items: center; gap: 5px; padding: 5px 9px 5px 5px; min-height: 44px; border: 1px solid var(--line); border-radius: 24px; background: var(--panel); font-size: 12px; }
.person-chip.selected { border-color: var(--accent); background: #383126; box-shadow: 0 0 0 1px var(--accent); }
.mini-avatar { width: 28px; height: 28px; display: grid; place-items: center; border-radius: 50%; font-size: 15px; font-weight: 800; color: white; }
#selection-help { font-size: 12px; color: var(--accent); min-height: 22px; padding: 3px 3px; }
#selected-clues { font-size: 13px; line-height: 1.4; padding: 5px 8px 8px; min-height: 46px; background: var(--panel); border-radius: 8px; }
.tools { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; margin-top: 8px; }
.tools .action-btn { font-size: 11px; min-height: 44px; padding: 8px 2px; }
.tools .active-mode { border-color: var(--accent); box-shadow: inset 0 -2px var(--accent); color: var(--accent); }
.board-options { display: flex; align-items: center; gap: 12px; padding: 8px 0; }
.board-options label { display: flex; align-items: center; gap: 5px; min-height: 44px; font-size: 12px; color: var(--muted); }
.board-options input { width: 18px; height: 18px; accent-color: var(--accent); }
.icon-btn { min-width: 44px; min-height: 44px; }
.evidence { border-top: 1px solid var(--line); margin-top: 4px; }
.evidence summary { cursor: pointer; padding: 14px 5px; font-size: 13px; color: var(--muted); }
.suspect-card { width: 100%; text-align: left; color: var(--text); }
.actions { position: sticky; bottom: max(8px, var(--safe-bottom, 0px)); padding: 8px 0; background: var(--bg); z-index: 5; }
.actions .action-btn { min-height: 46px; }
.modal { padding-top: max(20px, var(--safe-top, 0px)); padding-bottom: max(20px, var(--safe-bottom, 0px)); }
.modal-box { max-height: 82dvh; }
.accuse-item { color: var(--text); }
.toast { bottom: max(84px, calc(var(--safe-bottom, 0px) + 64px)); }
@media (min-width: 700px) { #app { padding-top: 22px; } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

#grid-wrap { overflow-x: auto; overscroll-behavior-x: contain; }
.case-meta { align-items: center; }
#btn-zoom { min-height: 44px; font-size: 12px; }

/* SVG outlines use viewBox units: a 2px outline would cover whole rooms.
   Suppress both the mobile UA focus ring and the HTML focus rule here;
   draw keyboard focus inside the cell with a stroke in grid units. */
#grid [role="button"]:focus { outline: none; }
#grid [role="button"]:focus-visible {
  outline: none;
  stroke: var(--accent);
  stroke-width: 0.045;
  stroke-linejoin: round;
}

/* A placed person remains editable; a check and coordinate indicate placement. */
.person-chip.placed { opacity: .65; border-style: dashed; }
.person-chip.placed.selected { opacity: 1; border-style: solid; }
.chip-cell { font-size: 10px; color: var(--ok); white-space: nowrap; }
.suspect-card.placed:not(.selected) { opacity: .75; }
.suspect-card.placed .cell-ref { color: var(--ok); }
.current-card { border-color: var(--accent); margin-top: 18px; }
.paused-card { border-left: 3px solid var(--muted); }
.history-card { border-left: 3px solid var(--ok); }
.history-card:disabled { opacity: .8; }
#case-history { margin-top: 18px; border-top: 1px solid var(--line); }
#case-history summary { min-height: 48px; padding: 15px 4px; cursor: pointer; color: var(--muted); font-size: 14px; }
.empty-history { color: var(--muted); font-size: 13px; padding: 8px 4px; line-height: 1.5; }

.rules-heading { position: sticky; top: -20px; background: var(--panel); padding: 8px 0; display:flex; align-items:center; gap:8px; z-index:2; }
.rules-heading .modal-title { flex:1; margin:0; text-align:left; font-size:18px; }
.legend-room { text-align:left; border-top:1px solid var(--line); margin-top:16px; padding-top:12px; }
.legend-room h3 { font-size:15px; color:var(--accent); margin-bottom:10px; }
.legend-items { display:grid; gap:10px; }
.legend-item { display:flex; align-items:center; gap:12px; font-size:13px; }
.legend-item svg { width:60px; height:68px; flex:0 0 60px; background:#1c2029; border-radius:8px; padding:4px; }
.legend-item small { display:block; font-size:11px; margin-top:4px; color:var(--muted); }
.legend-floor { font-size:12px; color:var(--muted); margin:10px 0; line-height:1.4; }
.case-conditions { font-size:12px; line-height:1.45; color:var(--muted); padding:8px 10px; margin-bottom:8px; border:1px solid var(--line); border-radius:10px; }
#grid-wrap.rectangular { max-height:70dvh; overflow:auto; }

.rules-details { text-align:left; margin-bottom:8px; }
.rules-details summary { min-height:44px; padding:12px 0; color:var(--muted); font-size:13px; cursor:pointer; }

.flight-case { border-left:4px solid var(--danger); }

.hint-explanation { font-size:12px; line-height:1.4; color:var(--muted); padding:6px 4px; }

.case-card.diff-insane { border-left: 4px solid #b68af1; }
