:root {
  --bg: #0d0f14;
  --bg-soft: #161922;
  --bg-card: #1c2029;
  --line: #2a2f3a;
  --ink: #e8e6e0;
  --ink-dim: #9aa0ac;
  --accent: #e0a84e; /* amber file-folder gold */
  --accent-soft: #3a2f1a;
  --danger: #d9544f;
  --ok: #5bbf73;
  --radius: 14px;
  --tabbar-h: 64px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 17px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

#app { min-height: 100%; }

h1, h2, h3 { font-family: "Iowan Old Style", Georgia, "Times New Roman", serif; letter-spacing: 0.01em; }
h2 { font-size: 1.5rem; margin: 0 0 0.6rem; }
h3 { font-size: 1.1rem; }
.muted { color: var(--ink-dim); }
.center { text-align: center; }

/* --------------------------- screens --------------------------- */
.screen { min-height: 100vh; min-height: 100dvh; }
[hidden] { display: none !important; }

/* --------------------------- inputs / buttons --------------------------- */
.text-input {
  width: 100%;
  padding: 14px 16px;
  font-size: 17px;
  color: var(--ink);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  outline: none;
  margin-bottom: 14px;
}
.text-input:focus { border-color: var(--accent); }
textarea.text-input { resize: vertical; font-family: inherit; }
.code-input { text-transform: uppercase; letter-spacing: 0.5em; text-align: center; font-size: 1.6rem; font-weight: 700; }
.field-label { display: block; font-size: 0.85rem; color: var(--ink-dim); margin: 0 0 6px 2px; }

.btn {
  width: 100%;
  padding: 16px;
  font-size: 17px;
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  color: #fff;
  transition: transform 0.06s ease, opacity 0.2s ease;
}
.btn:active { transform: scale(0.985); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-primary { background: var(--accent); color: #1a1300; }
.btn-ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn-danger { background: var(--danger); }
.btn + .btn { margin-top: 10px; }

.divider { display: flex; align-items: center; gap: 12px; color: var(--ink-dim); font-size: 0.8rem; margin: 18px 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.error-text { color: var(--danger); text-align: center; margin-top: 14px; }

/* --------------------------- home --------------------------- */
.home-wrap { max-width: 460px; margin: 0 auto; padding: calc(var(--safe-top) + 32px) 20px 40px; }
.brand { text-align: center; margin-bottom: 28px; }
.brand-badge { font-size: 2.6rem; }
.brand h1 { font-size: 2.4rem; letter-spacing: 0.18em; margin: 6px 0 8px; }
.tagline { color: var(--ink-dim); margin: 0 auto; max-width: 320px; }
.card { background: var(--bg-card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }

/* --------------------------- lobby --------------------------- */
.lobby-wrap { max-width: 460px; margin: 0 auto; padding: calc(var(--safe-top) + 32px) 20px 40px; text-align: center; }
.room-code {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 3rem; font-weight: 800; letter-spacing: 0.3em;
  color: var(--accent); background: var(--accent-soft);
  border: 1px dashed var(--accent); border-radius: var(--radius);
  padding: 14px 10px 14px 24px; margin: 10px 0; width: 100%; cursor: pointer;
}
.copied-hint { color: var(--ok); font-size: 0.9rem; margin: -4px 0 10px; }
.section-title { text-align: left; margin: 24px 0 10px; color: var(--ink-dim); text-transform: uppercase; font-size: 0.8rem; letter-spacing: 0.1em; }
.player-list { list-style: none; padding: 0; margin: 0; text-align: left; }
.player-list li {
  display: flex; align-items: center; gap: 10px;
  padding: 13px 14px; background: var(--bg-card);
  border: 1px solid var(--line); border-radius: 12px; margin-bottom: 8px;
}
.player-list .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ink-dim); flex: 0 0 auto; }
.player-list .dot.on { background: var(--ok); }
.player-list .pname { flex: 1; font-weight: 600; }
.player-list .badge { font-size: 0.72rem; padding: 2px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); }
.player-list .badge.solved { background: rgba(91,191,115,0.15); color: var(--ok); }
.player-list .qcount { font-size: 0.8rem; color: var(--ink-dim); }

/* --------------------------- center / spinner --------------------------- */
.center-screen { min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 24px; gap: 8px; }
.spinner { width: 46px; height: 46px; border: 4px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.9s linear infinite; margin-bottom: 16px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* --------------------------- game --------------------------- */
.game-screen { display: flex; flex-direction: column; height: 100dvh; }
.game-header {
  display: flex; align-items: center; gap: 12px;
  padding: calc(var(--safe-top) + 12px) 16px 12px;
  background: var(--bg-soft); border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.gh-title { flex: 1; font-weight: 700; font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gh-score { background: var(--bg-card); border: 1px solid var(--line); color: var(--ink); border-radius: 999px; padding: 7px 13px; font-size: 0.9rem; cursor: pointer; flex: 0 0 auto; }
.gh-code { background: var(--accent-soft); border: 1px solid var(--accent); color: var(--accent); border-radius: 999px; padding: 7px 12px; font-size: 0.85rem; font-weight: 700; letter-spacing: 0.08em; cursor: pointer; flex: 0 0 auto; font-family: ui-monospace, Menlo, monospace; }

/* difficulty segmented control */
.seg { display: flex; gap: 6px; background: var(--bg-soft); border: 1px solid var(--line); border-radius: 12px; padding: 5px; }
.seg-btn { flex: 1; padding: 11px 6px; border: none; background: none; color: var(--ink-dim); border-radius: 9px; font-size: 0.95rem; font-weight: 600; cursor: pointer; }
.seg-btn.active { background: var(--accent); color: #1a1300; }

.game-body { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 18px 16px 24px; }
.tab-panel { animation: fade 0.2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.case-meta { color: var(--ink-dim); margin-top: -4px; }
.info-block { background: var(--bg-card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.info-block h3 { margin: 0 0 8px; color: var(--accent); }
.info-block p { margin: 0 0 8px; }
.info-block p:last-child { margin-bottom: 0; }

/* suspects */
.suspect-card { background: var(--bg-card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.suspect-card .sc-name { font-weight: 700; font-size: 1.1rem; }
.suspect-card .sc-role { color: var(--accent); font-size: 0.85rem; margin-bottom: 8px; }
.suspect-card .sc-alibi { color: var(--ink-dim); font-size: 0.92rem; }
.suspect-card .sc-alibi b { color: var(--ink); }
.suspect-card button { margin-top: 12px; width: 100%; padding: 11px; background: var(--accent-soft); color: var(--accent); border: 1px solid var(--accent); border-radius: 10px; font-weight: 600; cursor: pointer; }

/* interrogate */
.char-chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 12px; margin-bottom: 6px; }
.char-chips button { white-space: nowrap; padding: 9px 14px; border-radius: 999px; background: var(--bg-card); border: 1px solid var(--line); color: var(--ink); font-size: 0.9rem; cursor: pointer; flex: 0 0 auto; }
.char-chips button.active { background: var(--accent); color: #1a1300; border-color: var(--accent); font-weight: 600; }
.chat-area { display: flex; flex-direction: column; gap: 10px; min-height: 120px; }
.bubble { max-width: 84%; padding: 11px 14px; border-radius: 16px; font-size: 0.96rem; }
.bubble.me { align-self: flex-end; background: var(--accent); color: #1a1300; border-bottom-right-radius: 4px; }
.bubble.them { align-self: flex-start; background: var(--bg-card); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.bubble.typing { color: var(--ink-dim); font-style: italic; }
.ask-form { display: flex; gap: 8px; align-items: flex-start; margin-top: 12px; }
.ask-form .text-input { margin-bottom: 0; }
.btn-send { width: 52px; flex: 0 0 auto; font-size: 1.3rem; padding: 14px 0; }

/* accuse */
.accuse-suspects { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.accuse-suspects label { display: flex; align-items: center; gap: 12px; padding: 14px; background: var(--bg-card); border: 1px solid var(--line); border-radius: 12px; cursor: pointer; }
.accuse-suspects input { width: 20px; height: 20px; accent-color: var(--danger); }
.accuse-suspects label.sel { border-color: var(--danger); }
.feedback { margin-top: 14px; padding: 13px 15px; border-radius: 12px; text-align: center; }
.feedback.bad { background: rgba(217,84,79,0.14); color: var(--danger); }
.feedback.warn { background: var(--accent-soft); color: var(--accent); }

/* tab bar */
.tab-bar {
  flex: 0 0 auto; display: flex;
  background: var(--bg-soft); border-top: 1px solid var(--line);
  padding-bottom: var(--safe-bottom);
}
.tab-btn {
  flex: 1; background: none; border: none; color: var(--ink-dim);
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 9px 0; font-size: 0.68rem; cursor: pointer;
}
.tab-btn span { font-size: 1.3rem; line-height: 1; }
.tab-btn.active { color: var(--accent); }

/* --------------------------- finished --------------------------- */
.finished-wrap { max-width: 460px; margin: 0 auto; padding: calc(var(--safe-top) + 32px) 20px 40px; }
.result-banner { text-align: center; font-size: 1.5rem; font-weight: 800; font-family: Georgia, serif; padding: 22px; border-radius: var(--radius); margin-bottom: 18px; }
.result-banner.win { background: rgba(91,191,115,0.14); color: var(--ok); border: 1px solid var(--ok); }
.result-banner.lose { background: var(--bg-card); color: var(--ink); border: 1px solid var(--line); }
.info-block.reveal h3 { color: var(--ok); }

/* --------------------------- overlay / toast --------------------------- */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: flex; align-items: flex-end; justify-content: center; z-index: 50; }
.overlay-card { background: var(--bg-soft); border-top-left-radius: 20px; border-top-right-radius: 20px; width: 100%; max-width: 520px; padding: 18px 18px calc(18px + var(--safe-bottom)); max-height: 80dvh; overflow-y: auto; }
.overlay-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.overlay-head h3 { margin: 0; }
.icon-btn { background: none; border: none; color: var(--ink-dim); font-size: 1.3rem; cursor: pointer; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 16px);
  transform: translateX(-50%); background: #000; color: #fff;
  padding: 12px 18px; border-radius: 999px; font-size: 0.92rem; z-index: 60;
  border: 1px solid var(--line); max-width: 90vw; text-align: center;
  animation: fade 0.2s ease;
}
