:root {
  --bg: #1b1c20;
  --panel: #26282e;
  --panel-2: #30333a;
  --text: #ecebe6;
  --muted: #a3a29b;
  --accent: #c0392b;
  --accent-2: #e5533f;
  --ok: #2ecc71;
  --bad: #e74c3c;
  --gold: #f1c40f;
  --radius: 12px;
  --font: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 15px; }
body { min-height: 100vh; -webkit-tap-highlight-color: transparent; user-select: none; }
button { font: inherit; color: inherit; cursor: pointer; }

.loading { min-height: 100vh; display: grid; place-content: center; text-align: center; gap: 12px; color: var(--muted); padding: 24px; }
.loading h1 { color: var(--text); margin: 0; }
.spinner { width: 36px; height: 36px; margin: 0 auto; border: 4px solid var(--panel-2); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

header { display: flex; align-items: center; justify-content: space-between; padding: 12px 20px; border-bottom: 1px solid #ffffff12; }
.title { display: flex; align-items: center; gap: 12px; }
.logo { font-size: 28px; }
h1 { margin: 0; font-size: 20px; letter-spacing: 0.2px; }
h1 small { color: var(--muted); font-weight: 600; }
header p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.icon { width: 34px; height: 34px; border-radius: 50%; border: 1px solid #ffffff22; background: var(--panel); font-weight: 700; }

main { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(280px, 0.9fr); gap: 24px; padding: 16px 20px 28px; max-width: 1200px; margin: 0 auto; }
@media (max-width: 820px) { main { grid-template-columns: 1fr; padding: 12px; gap: 16px; } header { padding: 10px 12px; } }

.hint { margin: 0 0 10px; color: var(--muted); min-height: 1.3em; }
.hint b { color: var(--text); }

/* ---- board ---- */
.board {
  display: grid;
  grid-template-columns: 22px repeat(var(--n), minmax(0, 1fr));
  gap: 0;
  width: 100%;
  max-width: min(600px, calc(100vh - 300px) + 22px);
  margin: 0 auto;
}
.axis { display: grid; place-items: center; color: var(--muted); font-weight: 700; font-size: 13px; padding: 4px 0; }
.cell {
  position: relative;
  aspect-ratio: 1;
  padding: 0;
  display: grid;
  place-items: center;
  transition: filter 0.12s;
  outline: none;
}
.cell:hover { filter: brightness(0.94); }
.cell.conflict { box-shadow: inset 0 0 0 3px #e74c3cbb; }
.cell.sel { box-shadow: inset 0 0 0 4px var(--gold); }
.cell.blocked { cursor: not-allowed; }
.room {
  position: absolute; top: 3px; left: 4px; right: 2px;
  font-size: clamp(7px, 1.1vw, 10px); font-weight: 800; letter-spacing: 0.4px;
  color: #2b2118bb; text-transform: uppercase; text-align: left;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; pointer-events: none;
}
.obj { width: 72%; height: 72%; display: grid; place-items: center; pointer-events: none; }
.obj svg { width: 100%; height: 100%; }
.obj.mini { position: absolute; left: 4%; bottom: 4%; width: 34%; height: 34%; }
.token {
  position: relative;
  width: 60%; aspect-ratio: 1; border-radius: 50%;
  display: grid; place-items: center;
  color: #fff; font-weight: 800; font-size: clamp(13px, 2.6vw, 24px);
  border: 3px solid #fff;
  box-shadow: 0 2px 6px #0006;
  animation: pop 0.18s ease-out;
  pointer-events: none;
}
.token.victim { border-color: #111; }
.token.victim::after {
  content: "†"; position: absolute; top: -18%; right: -18%;
  width: 42%; aspect-ratio: 1; border-radius: 50%;
  background: #111; color: #fff; font-size: 60%; display: grid; place-items: center;
}
.token.ok { box-shadow: 0 0 0 4px var(--ok), 0 2px 6px #0006; }
.token.bad { box-shadow: 0 0 0 4px var(--bad), 0 2px 6px #0006; }
.token.murderer { box-shadow: 0 0 0 5px #111, 0 0 0 8px var(--gold); }
@keyframes pop { from { transform: scale(0.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
/* Overlay so a cross on a rug/chair/bed never pushes the furniture or resizes the cell. */
.mark { position: absolute; inset: 0; display: grid; place-items: center; color: #2b2118aa; font-size: clamp(18px, 4vw, 34px); font-weight: 300; pointer-events: none; }

.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; justify-content: center; margin: 10px 0 4px; color: var(--muted); font-size: 13px; }
.legend span { display: inline-flex; align-items: center; gap: 4px; }
.legend i { width: 22px; height: 22px; display: inline-block; }
.legend i svg { width: 100%; height: 100%; }
.legend em { color: var(--bad); font-style: normal; font-weight: 700; }

/* ---- controls ---- */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 12px; }
.btn { border: 1px solid #ffffff22; background: var(--panel); padding: 10px 16px; border-radius: 10px; font-weight: 700; }
.btn:hover:not(:disabled) { background: var(--panel-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--accent-2); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.seg { display: inline-flex; background: var(--panel); border: 1px solid #ffffff22; border-radius: 10px; overflow: hidden; }
.seg button { border: 0; background: none; padding: 10px 14px; font-weight: 700; color: var(--muted); }
.seg button.on { background: var(--panel-2); color: var(--text); }
.warn { text-align: center; color: #f5b041; margin: 8px 0 0; font-size: 14px; }

.attempts { display: flex; flex-direction: column; align-items: center; gap: 4px; margin-top: 14px; }
.att { display: flex; gap: 4px; }
.att i { width: 18px; height: 18px; border-radius: 4px; background: var(--ok); }
.att i.bad { background: var(--bad); }
.att.empty i { background: var(--panel-2); }

/* ---- people & clues ---- */
.story { margin: 0 0 12px; color: var(--muted); line-height: 1.45; }
.story b { color: var(--text); }
.people { display: flex; flex-direction: column; gap: 8px; }
.person {
  text-align: left; background: var(--panel); border: 2px solid transparent; border-radius: var(--radius);
  padding: 10px 12px; transition: border-color 0.12s, background 0.12s;
}
.person:hover { background: var(--panel-2); }
.person.active { border-color: var(--gold); background: var(--panel-2); }
.person.culprit { border-color: var(--accent); }
.who { display: flex; align-items: center; gap: 8px; }
.dot { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 13px; border: 2px solid #fff; flex: none; }
.dot.victim { border-color: #111; }
.tag { font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.5px; background: #ffffff18; padding: 2px 6px; border-radius: 6px; color: var(--muted); }
.tag.red { background: var(--accent); color: #fff; }
.where { margin-left: auto; font-family: ui-monospace, monospace; color: var(--muted); font-weight: 700; }
.person ul { margin: 6px 0 0 34px; padding: 0; list-style: none; color: #d6d4cc; line-height: 1.45; font-size: 14px; }
.person li::before { content: "“"; color: var(--muted); margin-right: 2px; }
.person li.none::before { content: ""; }
.person li.none { color: var(--muted); font-style: italic; }

/* ---- modals & toasts ---- */
.modal { position: fixed; inset: 0; background: #000a; display: grid; place-items: center; padding: 16px; z-index: 10; animation: fade 0.15s; }
@keyframes fade { from { opacity: 0; } }
.sheet { background: var(--panel); border-radius: 16px; padding: 22px; width: min(440px, 100%); max-height: 92vh; overflow: auto; box-shadow: 0 20px 60px #0008; text-align: center; }
.sheet h2 { margin: 0 0 8px; }
.sheet p { color: #d6d4cc; line-height: 1.45; }
.sheet.help { text-align: left; }
.sheet.help ul { padding-left: 18px; line-height: 1.5; color: #d6d4cc; }
.sheet h3 { margin: 14px 0 4px; font-size: 15px; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 14px 0; }
.stats b { display: block; font-size: 24px; }
.stats span { color: var(--muted); font-size: 12px; }
.dist { display: flex; flex-direction: column; gap: 4px; margin: 6px 0 4px; }
.bar { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.bar span { width: 12px; color: var(--muted); }
.bar i { background: var(--panel-2); color: #fff; font-style: normal; font-weight: 700; padding: 2px 6px; border-radius: 4px; text-align: right; min-width: 22px; }
.bar i.me { background: #2f9e44; }
.next { color: var(--muted) !important; margin: 12px 0; }
.actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 10px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); padding: 10px 16px; border-radius: 10px; font-weight: 700; z-index: 20; box-shadow: 0 8px 24px #0008; transition: opacity 0.3s; }
.toast.error { background: var(--bad); color: #fff; }
.toast.info { background: #ecebe6; color: #1b1c20; }
.toast.out { opacity: 0; }
