:root {
  --bg: #0a0e1a;
  --panel: #111827;
  --border: #1e2a45;
  --accent: #f0c040;
  --accent-dim: #c9993a;
  --correct: #3ecf6e;
  --wrong: #e05555;
  --text: #e2e8f0;
  --muted: #6b7280;
  --msg-detective: #1e3a5f;
  --msg-culprit: #3b1f1f;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

.wrap {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 16px;
}

.board {
  position: relative;
  width: min(94vw, calc(82vh * 4 / 5));
  aspect-ratio: 4 / 5;
  max-height: 82vh;
  border: 2px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  background: #0d1424;
}

.wrap:fullscreen,
.wrap:-webkit-full-screen {
  width: 100vw;
  height: 100vh;
  padding: 0;
  gap: 0;
}
.wrap:fullscreen .board,
.wrap:-webkit-full-screen .board {
  width: min(100vw, calc(100vh * 4 / 5));
  max-height: 100vh;
  border-radius: 0;
  border: none;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* HUD bar */
.bar {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  background: rgba(10,14,26,0.85);
  backdrop-filter: blur(4px);
  z-index: 10;
  border-bottom: 1px solid var(--border);
}

.bar h1 {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--accent);
}

.scores {
  display: flex;
  align-items: center;
  gap: 6px;
}

#back-levels {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  background: none;
  border: 1px solid var(--accent-dim);
  border-radius: 5px;
  cursor: pointer;
  padding: 2px 6px;
  line-height: 1.4;
}
#back-levels:hover { background: rgba(240,192,64,0.1); }

.icon, a.home {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 18px;
  padding: 2px 4px;
  color: var(--text);
  text-decoration: none;
  line-height: 1;
}

/* Panels */
.panel {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 44px;
  z-index: 5;
  background: rgba(10,14,26,0.96);
}

.panel.hidden { display: none; }

.panel-inner {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 14px 12px;
  overflow-y: auto;
}

/* Level picker */
.level-inner {
  gap: 10px;
  align-items: stretch;
}

.level-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--accent);
  text-align: center;
  padding-top: 4px;
}

.level-sub {
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}

.level-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  flex: 1;
}

.level-card {
  background: var(--panel);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-family: inherit;
  padding: 10px 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transition: border-color 0.15s, background 0.15s;
}
.level-card:hover { border-color: var(--accent); background: #1a2235; }

.lvl-badge {
  font-size: 18px;
  font-weight: 800;
  color: var(--accent);
}

.lvl-name {
  font-size: 11px;
  font-weight: 700;
}

.lvl-sub {
  font-size: 10px;
  color: var(--muted);
  text-align: center;
  line-height: 1.3;
}

/* Story/puzzle panel inner */
.story-text {
  font-size: 14px;
  line-height: 1.7;
  color: var(--text);
  flex: 1;
  white-space: pre-wrap;
}

.clue-text {
  font-size: 13px;
  line-height: 1.6;
  color: #b0bec5;
  white-space: pre-wrap;
}

.puzzle-inner {
  gap: 7px;
}

.scene-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--accent);
  border-bottom: 1px solid var(--border);
  padding-bottom: 6px;
  flex-shrink: 0;
}

.puzzle-q {
  font-size: 14px;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.5;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  flex-shrink: 0;
}

.choices {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
}

.choice-btn {
  background: var(--panel);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  padding: 9px 12px;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s, background 0.15s;
  touch-action: manipulation;
}
.choice-btn:hover { border-color: var(--accent); background: #1a2235; }
.choice-btn.correct { border-color: var(--correct); background: #0e2a1a; color: var(--correct); }
.choice-btn.wrong   { border-color: var(--wrong);   background: #2a0e0e; color: var(--wrong); }

.hint {
  font-size: 12px;
  color: #e09050;
  background: #2a1e0e;
  border: 1px solid #5a3a1a;
  border-radius: 6px;
  padding: 8px 10px;
  flex-shrink: 0;
}
.hint.hidden { display: none; }

.puzzle-foot {
  margin-top: auto;
  display: flex;
  justify-content: flex-end;
  flex-shrink: 0;
}

.cur-level-badge {
  font-size: 10px;
  font-weight: 700;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 6px;
}

/* Message panel */
.msg-panel {
  position: absolute;
  bottom: 64px;
  left: 10px; right: 10px;
  border-radius: 10px;
  padding: 12px 14px 10px;
  z-index: 8;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.msg-panel.hidden { display: none; }
.msg-panel.detective { background: var(--msg-detective); border: 1px solid #2a5a8f; }
.msg-panel.culprit   { background: var(--msg-culprit);   border: 1px solid #8f2a2a; }

.msg-from {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--accent);
}
.msg-body {
  font-size: 13px;
  line-height: 1.5;
  color: var(--text);
}
.msg-ok {
  align-self: flex-end;
}

/* Buttons */
.btn-primary {
  background: var(--accent);
  color: #0a0e1a;
  border: none;
  border-radius: 8px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  padding: 12px 20px;
  cursor: pointer;
  margin-top: auto;
  flex-shrink: 0;
  touch-action: manipulation;
}
.btn-primary:hover { background: var(--accent-dim); }

.btn-small {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  padding: 5px 10px;
  cursor: pointer;
  touch-action: manipulation;
}
.btn-small:hover { border-color: var(--accent); }

/* Resolution */
.res-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--accent);
  text-align: center;
  margin-bottom: 4px;
}
.res-culprit {
  font-size: 15px;
  font-weight: 700;
  color: var(--wrong);
  text-align: center;
}
.res-mistake {
  font-size: 13px;
  color: #c0c8d8;
  line-height: 1.6;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
}
.res-victim {
  font-size: 13px;
  font-style: italic;
  color: #90aab8;
  border-left: 3px solid var(--accent-dim);
  padding-left: 10px;
}
.res-detectives {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.res-detective-line {
  font-size: 13px;
  color: var(--text);
  background: var(--panel);
  border-radius: 6px;
  padding: 7px 10px;
}

footer.foot {
  font-size: 11px;
  color: var(--muted);
}
footer.foot a {
  color: var(--muted);
  text-decoration: none;
}
footer.foot a:hover {
  color: var(--accent);
}
