/* Murdoku — detective-noir PWA */
:root {
  --bg: #1a0e0a;
  --bg-2: #2a1810;
  --card: #2a1810;
  --card-2: #3a2418;
  --ink: #e8d5b7;
  --ink-soft: #b89878;
  --ink-dim: #786040;
  --gold: #d4a23e;
  --gold-2: #f0c850;
  --red: #c4452e;
  --red-2: #e85a3e;
  --green: #6fa83e;
  --blue: #3e6fa8;
  --line: #4a3020;
  --line-2: #6a4830;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  --max: 880px;
  --radius: 12px;
  --serif: 'Georgia', 'Iowan Old Style', serif;
  --sans: 'Segoe UI', system-ui, sans-serif;
  --mono: 'Consolas', 'Monaco', monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.5;
  min-height: 100vh;
  background-image: radial-gradient(ellipse at top, rgba(212,162,62,0.08), transparent 50%),
                    radial-gradient(ellipse at bottom, rgba(196,69,46,0.05), transparent 60%);
  background-attachment: fixed;
}

body.light {
  --bg: #f4ead8; --bg-2: #e8d5b7; --card: #f4ead8; --card-2: #e8d5b7;
  --ink: #1a0e0a; --ink-soft: #4a3020; --ink-dim: #6a4830;
  --line: #b89878; --line-2: #786040;
  background-image: radial-gradient(ellipse at top, rgba(196,69,46,0.06), transparent 50%);
}

#smoke, #confetti { position: fixed; inset: 0; pointer-events: none; z-index: 999; }

/* ==== Hero ==== */
.hero {
  text-align: center;
  padding: 40px 20px 32px;
  position: relative;
}
.hero-img-wrap {
  width: 140px; height: 140px; margin: 0 auto 16px;
  border: 4px solid var(--gold); border-radius: 50%;
  overflow: hidden; box-shadow: 0 8px 24px rgba(212,162,62,0.3);
  position: relative;
  background: #000;
}
.hero-img-wrap::after {
  content: ''; position: absolute; inset: 0; border-radius: 50%;
  box-shadow: inset 0 0 30px rgba(0,0,0,0.6);
}
.hero-img { width: 100%; height: 100%; object-fit: cover; }
.hero h1 {
  margin: 0 0 8px; font-size: clamp(2.4rem, 6vw, 3.6rem); font-weight: 800;
  font-family: var(--serif); letter-spacing: -0.02em; color: var(--ink);
}
.title-accent { color: var(--gold); }
.tag {
  margin: 0 0 16px; font-size: 1.1rem; color: var(--gold-2);
  font-family: var(--serif); font-style: italic; letter-spacing: 0.05em;
}
.lead {
  max-width: 600px; margin: 0 auto 20px; color: var(--ink-soft);
  font-size: 1.05rem; line-height: 1.6;
}
.lead strong { color: var(--ink); }

.actions {
  display: flex; gap: 12px; justify-content: center; flex-wrap: wrap;
}

button {
  font-family: var(--sans); font-size: 1rem;
  padding: 12px 22px; border-radius: 8px;
  border: 2px solid var(--gold); cursor: pointer;
  font-weight: 600; transition: all 0.2s;
}
button.primary {
  background: var(--gold); color: var(--bg);
}
button.primary:hover { background: var(--gold-2); transform: translateY(-2px); }
button.secondary {
  background: transparent; color: var(--gold);
}
button.secondary:hover { background: var(--gold); color: var(--bg); }
button.small { padding: 6px 12px; font-size: 0.85rem; }
button.hidden { display: none; }

/* ==== Main ==== */
main { max-width: var(--max); margin: 0 auto; padding: 16px; }

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 24px;
  box-shadow: var(--shadow);
  animation: fade-in 0.4s ease;
}
@keyframes fade-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.card h2 {
  margin: 0 0 16px; font-size: 1.5rem; color: var(--gold);
  font-family: var(--serif); border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
}

.muted { color: var(--ink-dim); font-size: 0.9rem; font-style: italic; }

/* ==== Cases ==== */
.cases-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}
.case-card {
  background: var(--card-2); border: 1px solid var(--line-2);
  border-radius: var(--radius); padding: 16px;
  cursor: pointer; transition: all 0.2s;
  text-align: left;
}
.case-card:hover { transform: translateY(-4px); border-color: var(--gold); }
.case-card.solved { border-color: var(--green); opacity: 0.85; }
.case-card-img {
  width: 100%; height: 120px; object-fit: cover;
  border-radius: 8px; margin-bottom: 12px;
  border: 1px solid var(--line);
}
.case-card h3 { margin: 0 0 6px; color: var(--gold); font-family: var(--serif); }
.case-card p { margin: 0; font-size: 0.85rem; color: var(--ink-soft); }
.case-card .badge {
  display: inline-block; margin-top: 6px; padding: 2px 8px;
  background: var(--gold); color: var(--bg); border-radius: 10px;
  font-size: 0.7rem; font-weight: 700;
}
.case-card.solved .badge { background: var(--green); }
.case-card .difficulty-stars { color: var(--gold); margin-top: 6px; font-size: 0.9rem; }

/* ==== Game UI ==== */
.game {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px;
  box-shadow: var(--shadow);
}
.game-top {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 12px; padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}
.game-top h2 {
  margin: 0; flex: 1; color: var(--gold);
  font-family: var(--serif); font-size: 1.3rem;
}
.timer {
  color: var(--ink-soft); font-family: var(--mono);
  font-size: 0.95rem; padding: 4px 10px;
  background: var(--bg-2); border-radius: 6px;
}

.game-tabs {
  display: flex; gap: 4px; margin-bottom: 16px;
  background: var(--bg-2); padding: 4px;
  border-radius: 8px;
  overflow-x: auto;
}
.tab-btn {
  flex: 1; min-width: 100px; padding: 8px 12px; font-size: 0.9rem;
  background: transparent; color: var(--ink-soft);
  border: none; border-radius: 6px;
  white-space: nowrap;
}
.tab-btn:hover { color: var(--ink); background: var(--card); }
.tab-btn.active {
  background: var(--gold); color: var(--bg); font-weight: 700;
}

.tab { display: none; animation: fade-in 0.3s ease; }
.tab-active { display: block; }

/* install-dialog (voor iOS / browsers zonder beforeinstallprompt) */
.install-dialog {
  background: linear-gradient(135deg, #1a0e0a, #2a1810);
  color: var(--ink);
  border: 3px solid var(--gold);
  border-radius: 16px;
  padding: 28px;
  max-width: 440px;
  width: 90vw;
  font-family: var(--serif);
}
.install-dialog::backdrop { background: rgba(0,0,0,0.85); backdrop-filter: blur(4px); }
.install-dialog h3 { color: var(--gold); margin: 0 0 12px; font-size: 1.4rem; }
.install-dialog p, .install-dialog ol { color: var(--ink); line-height: 1.6; }
.install-dialog ol { padding-left: 24px; }
.install-dialog ol li { margin-bottom: 6px; }
.install-dialog ol li strong { color: var(--gold-2); }
.install-hint { color: var(--ink-soft); font-style: italic; margin-top: 12px; }

/* ==== Story tab ==== */
.story-intro {
  display: grid; grid-template-columns: 200px 1fr; gap: 20px;
  align-items: start; margin-bottom: 16px;
}
.story-img {
  width: 100%; height: auto; max-height: 250px;
  object-fit: cover; border-radius: 8px;
  border: 2px solid var(--line);
  filter: sepia(0.4) contrast(1.1);
}
.story-text {
  font-family: var(--serif); font-size: 1.05rem;
  line-height: 1.7; color: var(--ink);
}
.story-text p { margin: 0 0 12px; }

.clues {
  display: grid; gap: 8px; margin-top: 16px;
  padding-top: 16px; border-top: 1px dashed var(--line);
}
.clue {
  padding: 10px 14px; background: var(--card-2);
  border-left: 3px solid var(--gold);
  border-radius: 4px; font-size: 0.95rem;
}
.clue::before { content: '💡 '; }

/* ==== Sudoku tab ==== */
.sudoku-wrap { display: flex; flex-direction: column; align-items: center; gap: 16px; }
.sudoku-controls {
  display: flex; gap: 16px; font-size: 0.9rem;
  color: var(--ink-soft);
}
.difficulty { color: var(--gold); }
.mistakes { color: var(--red-2); }

.sudoku-grid {
  display: grid;
  grid-template-columns: repeat(9, 44px);
  grid-template-rows: repeat(9, 44px);
  border: 3px solid var(--gold);
  background: var(--bg-2);
  font-family: var(--mono);
  font-size: 1.2rem;
  font-weight: 700;
  user-select: none;
}
.sudoku-grid .cell {
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--line-2); cursor: pointer;
  background: var(--card);
  color: var(--ink);
  position: relative;
  transition: background 0.15s;
}
.sudoku-grid .cell.given { background: var(--card-2); color: var(--gold); }
.sudoku-grid .cell.selected { background: var(--line); box-shadow: inset 0 0 0 2px var(--gold); }
.sudoku-grid .cell.highlighted { background: var(--line); }
.sudoku-grid .cell.same-number { background: var(--line-2); }
.sudoku-grid .cell.error { color: var(--red-2); background: rgba(196,69,46,0.2); }
.sudoku-grid .cell.revealed { color: var(--green); }
.sudoku-grid .cell.hint { animation: hint-flash 1s ease; }
@keyframes hint-flash {
  0% { background: var(--gold); }
  100% { background: var(--card); }
}
.sudoku-grid .cell.thick-r { border-right: 2px solid var(--gold); }
.sudoku-grid .cell.thick-b { border-bottom: 2px solid var(--gold); }
.sudoku-grid .cell.thick-l { border-left: 2px solid var(--gold); }
.sudoku-grid .cell.thick-t { border-top: 2px solid var(--gold); }
.sudoku-grid .cell:last-child { border-right: 0; border-bottom: 0; }

.number-pad {
  display: grid; grid-template-columns: repeat(5, 56px);
  gap: 8px;
}
.np-btn {
  height: 48px; font-size: 1.2rem; font-weight: 700;
  background: var(--card-2); color: var(--gold);
  border: 2px solid var(--line-2);
}
.np-btn:hover { background: var(--line); border-color: var(--gold); }
.np-btn.np-clear { background: var(--red); color: white; border-color: var(--red-2); }

.sudoku-actions {
  display: flex; gap: 8px; flex-wrap: wrap; justify-content: center;
}

/* ==== Matrix tab ==== */
.matrix-wrap {
  overflow-x: auto;
  margin: 16px 0;
}
.matrix {
  display: grid;
  border-collapse: collapse;
  font-size: 0.9rem;
  min-width: 600px;
}
.matrix .mrow, .matrix .mhead {
  display: contents;
}
.matrix .mcell, .matrix .mhead-cell {
  padding: 6px 8px;
  border: 1px solid var(--line-2);
  text-align: center;
  min-width: 60px;
  cursor: pointer;
}
.matrix .mhead-cell, .matrix .mhead-name {
  background: var(--card-2);
  color: var(--gold);
  font-weight: 700;
  font-size: 0.85rem;
  cursor: default;
}
.matrix .mhead-name { text-align: left; min-width: 140px; }
.matrix .mname {
  background: var(--card-2);
  color: var(--gold);
  font-weight: 700;
  text-align: left;
  cursor: default;
}
.matrix .mcell:hover:not(.mname):not(.mhead-cell) { background: var(--line); }
.matrix .mcell.state-2 { background: var(--green); color: white; }   /* ✓ */
.matrix .mcell.state-1 { background: var(--red); color: white; }     /* ✗ */
.matrix .mcell.state-2::after { content: '✓'; }
.matrix .mcell.state-1::after { content: '✗'; }

.matrix-tools {
  display: flex; gap: 8px; align-items: center; margin-top: 8px;
}
.mat-btn { padding: 6px 14px; }
.mat-btn[data-state="2"] { color: var(--green); border-color: var(--green); }
.mat-btn[data-state="1"] { color: var(--red-2); border-color: var(--red-2); }
.mat-btn[data-state="0"] { color: var(--ink-soft); }

.ok { color: var(--green); font-weight: 700; }
.no { color: var(--red-2); font-weight: 700; }

/* ==== Suspects tab ==== */
.suspects-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
}
.suspect {
  background: var(--card-2);
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  padding: 14px;
  text-align: center;
  position: relative;
  transition: all 0.2s;
}
.suspect.killer {
  border-color: var(--red-2);
  background: linear-gradient(135deg, var(--card-2), rgba(196,69,46,0.2));
}
.suspect.killer::after {
  content: '🔪 MOORDENAAR';
  position: absolute; top: -8px; right: -8px;
  background: var(--red-2); color: white;
  padding: 4px 10px; border-radius: 12px;
  font-size: 0.7rem; font-weight: 700;
  transform: rotate(8deg);
  box-shadow: 0 2px 8px rgba(196,69,46,0.5);
}
.suspect-avatar {
  width: 64px; height: 64px; border-radius: 50%;
  background: var(--bg); margin: 0 auto 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.8rem; border: 2px solid var(--line-2);
}
.suspect-name { color: var(--gold); font-weight: 700; font-family: var(--serif); }
.suspect-role { color: var(--ink-soft); font-size: 0.85rem; font-style: italic; }
.suspect-trait { color: var(--ink); font-size: 0.85rem; margin-top: 8px; }

/* ==== Howto ==== */
.howto-list {
  color: var(--ink); font-size: 1rem; line-height: 1.7;
  padding-left: 24px;
}
.howto-list li { margin-bottom: 10px; }
.howto-list em { color: var(--gold); font-style: italic; }

/* ==== Stats ==== */
#stats-body { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 16px; }
.stat-card {
  background: var(--card-2); padding: 14px; border-radius: 8px;
  text-align: center; border: 1px solid var(--line-2);
}
.stat-num { font-size: 1.8rem; color: var(--gold); font-weight: 800; }
.stat-lbl { color: var(--ink-soft); font-size: 0.85rem; margin-top: 4px; }

/* ==== Reveal dialog ==== */
.reveal-dialog {
  background: linear-gradient(135deg, #1a0e0a, #2a1810);
  color: var(--ink);
  border: 3px solid var(--gold);
  border-radius: 16px;
  padding: 32px;
  max-width: 500px;
  width: 90vw;
  text-align: center;
  font-family: var(--serif);
}
.reveal-dialog::backdrop { background: rgba(0,0,0,0.85); backdrop-filter: blur(4px); }
.reveal-dialog h2 { color: var(--gold); margin: 0 0 16px; font-size: 1.8rem; }
#reveal-content p { font-size: 1.1rem; line-height: 1.6; }
#reveal-content .killer-name { color: var(--red-2); font-size: 1.5rem; font-weight: 800; }
#reveal-content .motive { color: var(--ink-soft); font-style: italic; }

/* ==== Footer ==== */
footer {
  text-align: center; padding: 24px 16px; margin-top: 32px;
  background: var(--card); border-top: 1px solid var(--line);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  font-size: 0.85rem; color: var(--ink-soft);
}
.heart { color: var(--red-2); }

/* ==== Mobile ==== */
@media (max-width: 600px) {
  .hero { padding: 24px 12px 20px; }
  .hero-img-wrap { width: 100px; height: 100px; }
  .story-intro { grid-template-columns: 1fr; }
  .story-img { max-height: 180px; }
  .sudoku-grid { grid-template-columns: repeat(9, 36px); grid-template-rows: repeat(9, 36px); font-size: 1rem; }
  .number-pad { grid-template-columns: repeat(5, 48px); }
  .np-btn { height: 40px; font-size: 1rem; }
  .game-tabs { flex-wrap: nowrap; }
  .tab-btn { min-width: 90px; font-size: 0.8rem; }
}