:root {
  --bg: #0E0B13;
  --bg-elev: #15111c;
  --bg-elev-2: #1d1825;
  --line: #2a2433;
  --text: #f1ebf5;
  --text-dim: #b9aec7;
  --text-muted: #7a6f87;
  --accent: #ffd54a;
  --accent-2: #5CABB3;
  --danger: #FF7171;
  --given: #2a2433;
  --victim: #3a1a1a;
  --selected: rgba(255, 213, 74, 0.18);
  --conflict: rgba(255, 113, 113, 0.25);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  min-height: 100vh;
  overscroll-behavior: none;
}

body { visibility: hidden; }
body.ready { visibility: visible; }

.app {
  max-width: 1280px;
  margin: 0 auto;
  padding: 1rem 1.2rem 3rem;
}

/* ---- Header ---- */
header.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.5rem 0 1.2rem;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 0.7rem; }
.brand img { height: 38px; width: auto; }
.tagline { color: var(--text-dim); font-size: 0.9rem; margin: 0; }

.lang-switch { display: inline-flex; gap: 0.35rem; }
.lang-btn {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text-dim);
  font-size: 0.78rem;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 600;
}
.lang-btn:hover { background: var(--bg-elev); }
.lang-btn.active { background: var(--accent); color: #000; border-color: #000; }

/* ---- Top controls ---- */
.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  padding: 1rem 0;
}
.controls label {
  font-size: 0.85rem;
  color: var(--text-dim);
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}
.controls select, .controls button {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 0.45rem 0.85rem;
  border-radius: 8px;
  font-size: 0.9rem;
  cursor: pointer;
  font-family: inherit;
}
.controls button:hover { background: var(--bg-elev-2); }
.controls button.primary {
  background: var(--accent);
  color: #000;
  border-color: var(--accent);
  font-weight: 600;
}
.controls button.primary:hover { background: #ffe17a; }
.controls button.danger { color: var(--danger); }
.controls .grow { flex: 1; }

/* ---- Layout ---- */
.layout {
  display: grid;
  gap: 1.2rem;
  grid-template-columns: minmax(0, 1fr);
}
@media (min-width: 900px) {
  .layout {
    grid-template-columns: 220px minmax(0, 1fr) 280px;
  }
}

.panel {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1rem;
}
.panel h2 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin: 0 0 0.7rem;
  font-weight: 700;
}

/* ---- Suspect roster ---- */
.suspects {
  display: grid;
  gap: 0.4rem;
}
.suspect {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.45rem 0.6rem;
  border-radius: 8px;
  background: var(--bg-elev-2);
  border: 1px solid transparent;
  cursor: pointer;
  user-select: none;
  font-size: 0.92rem;
  transition: background 0.15s, border-color 0.15s;
}
.suspect:hover { background: #251f30; }
.suspect.selected {
  background: var(--selected);
  border-color: var(--accent);
}
.suspect.placed-row,
.suspect.placed-col {
  /* visual hint suspect is fully placed could be added later */
}
.suspect-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.8rem;
  color: #000;
  flex-shrink: 0;
  border: 2px solid rgba(0,0,0,0.4);
}
.suspect-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- Grid ---- */
.board-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.8rem;
}
.board {
  display: grid;
  gap: 2px;
  background: var(--line);
  padding: 2px;
  border-radius: 10px;
  width: 100%;
  max-width: min(72vh, 100%);
  aspect-ratio: 1 / 1;
}
.cell {
  background: var(--bg-elev-2);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: pointer;
  font-size: 0.9rem;
  user-select: none;
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s;
  overflow: hidden;
}
.cell:hover:not(.given) { background: #261f33; }
.cell.given {
  background: var(--given);
  cursor: not-allowed;
}
.cell.given .cell-avatar {
  border: 2px solid var(--accent);
}
.cell.victim {
  background: var(--victim);
}
.cell.victim::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><g fill='none' stroke='%23FF7171' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round' opacity='0.55'><circle cx='50' cy='28' r='10'/><path d='M50 38 L50 62'/><path d='M50 44 L34 56'/><path d='M50 44 L66 56'/><path d='M50 62 L36 82'/><path d='M50 62 L64 82'/></g></svg>");
  background-repeat: no-repeat;
  background-size: 70% 70%;
  background-position: center;
  pointer-events: none;
  opacity: 0.55;
}
.cell.victim.has-suspect::before { opacity: 0.18; }
.cell.selected {
  outline: 2px solid var(--accent);
  outline-offset: -3px;
}
.cell.conflict {
  background: var(--conflict);
}
.cell-avatar {
  width: 70%;
  height: 70%;
  max-width: 56px;
  max-height: 56px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: #000;
  border: 2px solid rgba(0,0,0,0.45);
  font-size: clamp(0.55rem, 1.6vw, 1rem);
}

/* board scaling per size — done via JS gridTemplate */

/* ---- Clues ---- */
.clues-list {
  display: grid;
  gap: 0.45rem;
  margin: 0;
  padding: 0;
  list-style: none;
  max-height: 60vh;
  overflow-y: auto;
}
.clues-list li {
  font-size: 0.88rem;
  line-height: 1.4;
  padding: 0.5rem 0.65rem;
  background: var(--bg-elev-2);
  border-radius: 7px;
  border-left: 3px solid var(--accent-2);
  color: var(--text-dim);
}
.clues-list li.used { opacity: 0.45; text-decoration: line-through; }

/* ---- Status row ---- */
.status {
  font-size: 0.9rem;
  color: var(--text-dim);
  text-align: center;
  min-height: 1.4em;
}
.status.error { color: var(--danger); }
.status.success { color: var(--accent); font-weight: 600; }

/* ---- Modal ---- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 100;
  animation: fadeIn 0.25s ease;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1.6rem 1.6rem 1.4rem;
  max-width: 460px;
  width: 100%;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}
.modal h3 { margin: 0 0 0.5rem; font-size: 1.5rem; color: var(--accent); }
.modal p { color: var(--text-dim); font-size: 1rem; line-height: 1.5; margin: 0 0 1.2rem; }
.modal-actions { display: flex; gap: 0.6rem; justify-content: center; flex-wrap: wrap; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ---- Suspect picker (mobile-friendly popup) ---- */
.picker-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 50;
}
.picker-backdrop.open { display: flex; }
.picker {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1rem;
  width: min(420px, 100%);
  max-height: 80vh;
  overflow-y: auto;
}
.picker h3 {
  margin: 0 0 0.7rem;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: 700;
}
.picker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 0.4rem;
}
.picker-clear {
  margin-top: 0.7rem;
  width: 100%;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--danger);
  padding: 0.5rem;
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.9rem;
}
.picker-clear:hover { background: var(--bg-elev-2); }

/* ---- Footer ---- */
footer.app-footer {
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
}

/* ---- Generating spinner ---- */
.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-right: 0.4rem;
  vertical-align: -2px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Mobile tweaks ---- */
@media (max-width: 899px) {
  .layout { grid-template-columns: 1fr; }
  .panel.suspects-panel,
  .panel.clues-panel { order: 2; }
  .board-wrap { order: 0; }
  .suspects {
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  }
  .suspect-name { font-size: 0.82rem; }
}
