:root {
  --ink: #120c0a;
  --surface: #1b1310;
  --surface-2: #261b16;
  --line: #3a2b23;
  --paper: #f2e8dc;
  --muted: #b9a594;
  --wood: #d29a5c;
  --groen: #4fae62;
  --oranje: #ef8a2a;
  --rood: #c0342c;
  --font: "Archivo", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  -webkit-font-smoothing: antialiased;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

[hidden] { display: none !important; }

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.text-btn {
  color: var(--muted);
  font-weight: 600;
  padding: 8px 0;
}
.text-btn:hover { color: var(--paper); }

.primary {
  background: var(--wood);
  color: var(--ink);
  font-weight: 700;
  font-size: 17px;
  padding: 14px 28px;
  border-radius: 4px;
}
.primary:hover { background: #e0ab6f; }

.secondary {
  color: var(--paper);
  font-weight: 700;
  font-size: 17px;
  padding: 13px 24px;
  border-radius: 4px;
  border: 1px solid var(--line);
}
.secondary:hover { background: var(--surface-2); }

.muted { color: var(--muted); margin: 0 0 20px; }

/* ---------- Opzet: zijpaneel op desktop, onderblad op telefoon ---------- */

.sheet {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  width: min(420px, 100%);
  padding: 48px 40px 32px;
  background: var(--surface);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  animation: slide-in 0.28s ease-out;
}

@keyframes slide-in {
  from { transform: translateX(-24px); opacity: 0.6; }
  to { transform: none; opacity: 1; }
}

.wordmark {
  font-size: 44px;
  font-weight: 900;
  font-stretch: 70%;
  letter-spacing: 0.01em;
  text-transform: uppercase;
  line-height: 1;
  margin: 0 0 18px;
}
.lede { color: var(--paper); opacity: 0.86; margin: 0 0 28px; text-wrap: pretty; max-width: 34ch; }
.step-title { font-size: 30px; font-weight: 800; font-stretch: 80%; margin: 0 0 8px; line-height: 1.1; }

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 0 0 14px;
}
.brand .wordmark { margin: 0; }
.swing { color: var(--wood); }
.brand-mark {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 30px;
  flex: none;
}
.bm-ends { display: flex; gap: 2px; height: 8px; }
.bm-ends i { flex: 1; border-radius: 1.5px; }
.bm-side {
  height: 8px;
  border-radius: 1.5px;
  background: linear-gradient(#e6c398, #c69764);
}
.bm-ends i.g, .legend i.g { background: var(--groen); }
.bm-ends i.o, .legend i.o { background: var(--oranje); }
.bm-ends i.r, .legend i.r { background: var(--rood); }

.legend {
  list-style: none;
  margin: 0 0 32px;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  font-size: 14px;
}
.legend li { display: flex; align-items: center; gap: 7px; }
.legend i { width: 14px; height: 10px; border-radius: 2px; }
.legend strong { font-weight: 700; }
.legend span { color: var(--muted); }

.section-label {
  margin: 0 0 4px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.choices { display: flex; flex-direction: column; border-top: 1px solid var(--line); }
.choice {
  position: relative;
  display: flex;
  align-items: center;
  gap: 18px;
  text-align: left;
  padding: 20px 8px 20px 4px;
  border-bottom: 1px solid var(--line);
  transition: background-color 0.15s ease-out;
}
.choice:hover, .choice:focus-visible { background: var(--surface-2); outline: none; }
.choice:active { background: #2f221c; }
.choice-num {
  font-size: 46px;
  font-weight: 900;
  font-stretch: 62%;
  color: var(--wood);
  line-height: 1;
  width: 26px;
  align-self: flex-start;
}
.choice-body { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.choice-body strong { font-size: 20px; font-weight: 700; line-height: 1.25; }
.choice-body > span:not(.people) { color: var(--muted); font-size: 15px; line-height: 1.4; text-wrap: pretty; }

/* Spelers als stipjes: stellen staan bij elkaar */
.people { display: flex; align-items: center; gap: 3px; margin-top: 10px; }
.people i { width: 7px; height: 7px; border-radius: 50%; background: var(--paper); opacity: 0.55; }
.people b { width: 5px; }
.people em { font-style: normal; font-size: 13px; font-weight: 700; color: var(--muted); margin-left: 3px; line-height: 7px; }

.choice-arrow {
  width: 10px;
  height: 10px;
  border-top: 2px solid var(--muted);
  border-right: 2px solid var(--muted);
  transform: rotate(45deg);
  margin-right: 6px;
  transition: transform 0.15s ease-out, border-color 0.15s;
}
.choice:hover .choice-arrow { transform: translateX(3px) rotate(45deg); border-color: var(--paper); }

.back { margin-bottom: 16px; }
.back::before { content: "\2190\00a0"; }

.name-list { list-style: none; margin: 0 0 4px; padding: 0; counter-reset: speler; }
.name-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  counter-increment: speler;
}
.name-list li::before {
  content: counter(speler);
  color: var(--muted);
  font-stretch: 70%;
  font-weight: 700;
  width: 18px;
}
.name-list input {
  flex: 1;
  font: inherit;
  font-size: 18px;
  color: var(--paper);
  background: none;
  border: 0;
  padding: 12px 0;
  outline: none;
  -webkit-user-select: text;
  user-select: text;
}
.name-list input::placeholder { color: #6e5c50; }
.name-list .remove { color: var(--muted); font-size: 22px; padding: 4px 8px; line-height: 1; }
.name-list .remove:hover { color: var(--paper); }
.add::before { content: "+\00a0"; }

.actions { display: flex; align-items: center; gap: 24px; margin-top: 28px; }

/* ---------- Laadscherm: een toren die zichzelf opbouwt ---------- */

.splash {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(ellipse 70% 55% at 50% 45%, #2b1c15 0%, var(--ink) 75%);
  transition: opacity 0.45s ease-out;
}
.splash.done { opacity: 0; pointer-events: none; }

.loader {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}
.loader-tower {
  display: flex;
  flex-direction: column-reverse;
  gap: 3px;
  width: 108px;
  height: calc(6 * 18px + 5 * 3px);
  margin-bottom: 36px;
  animation: tower-cycle 3.2s infinite;
}
.loader .layer {
  display: flex;
  gap: 3px;
  height: 18px;
  opacity: 0;
  animation: 3.2s infinite both cubic-bezier(0.45, 0, 0.9, 0.6);
}
.loader .layer.side {
  border-radius: 3px;
  background:
    repeating-linear-gradient(177deg, rgba(110, 70, 35, 0.22) 0 1px, transparent 1px 5px),
    linear-gradient(#e6c398, #c69764);
  box-shadow: inset 0 -2px 0 rgba(80, 45, 20, 0.25);
}
.loader .layer i {
  flex: 1;
  border-radius: 3px;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.18);
}
.loader .layer i.g { background: var(--groen); }
.loader .layer i.o { background: var(--oranje); }
.loader .layer i.r { background: var(--rood); }

/* Elke laag valt op een eigen moment, de hele toren verdwijnt samen. */
.loader .layer:nth-child(1) { animation-name: drop-1; }
.loader .layer:nth-child(2) { animation-name: drop-2; }
.loader .layer:nth-child(3) { animation-name: drop-3; }
.loader .layer:nth-child(4) { animation-name: drop-4; }
.loader .layer:nth-child(5) { animation-name: drop-5; }
.loader .layer:nth-child(6) { animation-name: drop-6; }

@keyframes drop-1 { 0%, 4% { opacity: 0; transform: translateY(-56px); } 11% { opacity: 1; transform: none; } 13% { transform: translateY(-3px); } 15%, 100% { opacity: 1; transform: none; } }
@keyframes drop-2 { 0%, 14% { opacity: 0; transform: translateY(-56px); } 21% { opacity: 1; transform: none; } 23% { transform: translateY(-3px); } 25%, 100% { opacity: 1; transform: none; } }
@keyframes drop-3 { 0%, 24% { opacity: 0; transform: translateY(-56px); } 31% { opacity: 1; transform: none; } 33% { transform: translateY(-3px); } 35%, 100% { opacity: 1; transform: none; } }
@keyframes drop-4 { 0%, 34% { opacity: 0; transform: translateY(-56px); } 41% { opacity: 1; transform: none; } 43% { transform: translateY(-3px); } 45%, 100% { opacity: 1; transform: none; } }
@keyframes drop-5 { 0%, 44% { opacity: 0; transform: translateY(-56px); } 51% { opacity: 1; transform: none; } 53% { transform: translateY(-3px); } 55%, 100% { opacity: 1; transform: none; } }
@keyframes drop-6 { 0%, 54% { opacity: 0; transform: translateY(-56px); } 61% { opacity: 1; transform: none; } 63% { transform: translateY(-3px); } 65%, 100% { opacity: 1; transform: none; } }

/* Staat even, kantelt en valt weg: de toren is om, opnieuw. */
@keyframes tower-cycle {
  0%, 74% { opacity: 1; transform: none; transform-origin: 0 100%; }
  80% { transform: rotate(-3deg); transform-origin: 0 100%; }
  90% { opacity: 0; transform: translateX(-14px) rotate(-14deg); transform-origin: 0 100%; }
  100% { opacity: 0; transform: none; }
}

.splash-name {
  margin: 0 0 6px;
  font-size: 30px;
  font-weight: 900;
  font-stretch: 70%;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  line-height: 1;
}
.loader-text {
  margin: 0;
  color: var(--muted);
  font-size: 15px;
  font-weight: 500;
}
.loader-text::after {
  content: "";
  display: inline-block;
  width: 1.2em;
  text-align: left;
  animation: dots 1.1s steps(4) infinite;
}
@keyframes dots {
  0% { content: ""; }
  25% { content: "."; }
  50% { content: ".."; }
  75% { content: "..."; }
}
/* Tekst blijft op dezelfde plek staan terwijl de puntjes groeien */
.loader-text { padding-left: 1.2em; }

.loader.failed .loader-tower { display: none; }
.loader.failed .loader-text { color: var(--paper); max-width: 30ch; padding-left: 0; }
.loader.failed .loader-text::after { display: none; }

@media (prefers-reduced-motion: reduce) {
  .loader-tower, .loader .layer { animation: none; opacity: 1; }
  .loader-text::after { animation: none; content: "..."; }
}

/* ---------- Spelbalk ---------- */

#hud {
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  left: 20px;
  right: 20px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  pointer-events: none;
  text-shadow: 0 1px 12px rgba(0, 0, 0, 0.8);
}
#hud > * { pointer-events: auto; }
.turn { display: flex; flex-direction: column; }
.turn-name { font-size: 28px; font-weight: 800; font-stretch: 80%; line-height: 1.1; }
.turn-sub { color: var(--muted); font-size: 14px; }

.menu-wrap { position: relative; }
.menu {
  position: absolute;
  right: 0;
  top: 40px;
  min-width: 220px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 4px;
  display: flex;
  flex-direction: column;
  text-shadow: none;
}
.menu button, .menu a { text-align: left; padding: 12px 16px; font-weight: 600; color: inherit; text-decoration: none; }
.menu > * + * { border-top: 1px solid var(--line); }
.menu button:hover, .menu a:hover { background: var(--surface-2); }

#hint {
  position: fixed;
  left: 20px;
  right: 20px;
  bottom: max(18px, env(safe-area-inset-bottom));
  margin: 0;
  text-align: center;
  font-size: 14px;
  color: var(--muted);
  pointer-events: none;
  text-shadow: 0 1px 8px #000;
}

#toast {
  position: fixed;
  left: 50%;
  bottom: max(56px, calc(env(safe-area-inset-bottom) + 40px));
  transform: translateX(-50%);
  margin: 0;
  padding: 10px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 4px;
  font-weight: 600;
  white-space: nowrap;
  pointer-events: none;
}

/* ---------- Opdrachtkaart ---------- */

.card-layer {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(8, 5, 4, 0.35);
}
.playcard {
  --c: var(--groen);
  --t: var(--ink);
  width: min(340px, 100%);
  min-height: 440px;
  display: flex;
  flex-direction: column;
  padding: 22px 24px 20px;
  background: var(--c);
  color: var(--t);
  border-radius: 14px;
  outline: 1.5px solid color-mix(in srgb, var(--t) 22%, transparent);
  outline-offset: -10px;
  transform: rotate(-1.5deg);
  animation: deal 0.24s ease-out;
}
.playcard.oranje { --c: var(--oranje); }
.playcard.rood { --c: var(--rood); --t: var(--paper); }

@keyframes deal {
  from { transform: translateY(28px) rotate(-4deg); opacity: 0; }
  to { transform: rotate(-1.5deg); opacity: 1; }
}

.playcard-head {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 6px 4px 0;
}
.playcard-text {
  flex: 1;
  display: flex;
  align-items: center;
  margin: 24px 4px;
  font-size: 30px;
  font-weight: 800;
  font-stretch: 85%;
  line-height: 1.15;
  text-wrap: balance;
}
.playcard-foot { padding: 0 4px; }
.playcard-note { font-size: 13px; margin: 0 0 12px; opacity: 0.8; }
.done {
  width: 100%;
  background: var(--t);
  color: var(--c);
  font-weight: 800;
  font-size: 18px;
  padding: 14px;
  border-radius: 6px;
}
.playcard-up { font-size: 13px; margin: 10px 0 0; text-align: center; opacity: 0.8; min-height: 1em; }

/* ---------- Toren om ---------- */

.fallen .wordmark { font-size: 64px; margin-bottom: 12px; }
.fallen .lede { margin-bottom: 28px; }

/* Het beeldmerk valt om: drie lagen kantelen en glijden weg */
.tumble {
  position: relative;
  width: 64px;
  height: 52px;
  margin: 0 0 22px;
}
.tb {
  position: absolute;
  left: 0;
  display: flex;
  gap: 3px;
  width: 64px;
  height: 14px;
  transform-origin: 100% 100%;
}
.tb i { flex: 1; border-radius: 2px; box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.18); }
.tb i.g { background: var(--groen); }
.tb i.o { background: var(--oranje); }
.tb i.r { background: var(--rood); }
.tb.side { border-radius: 2px; background: linear-gradient(#e6c398, #c69764); }
.tb-3 { top: 38px; }
.tb-2 { top: 21px; animation: tip-2 0.7s 0.15s cubic-bezier(0.5, 0, 0.75, 0.4) both; }
.tb-1 { top: 4px; animation: tip-1 0.8s 0.05s cubic-bezier(0.5, 0, 0.75, 0.4) both; }
@keyframes tip-1 { to { transform: translate(34px, 30px) rotate(78deg); } }
@keyframes tip-2 { to { transform: translate(16px, 10px) rotate(24deg); } }

.tally {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.tally li { display: flex; flex-direction: column; padding: 14px 0 12px; }
.tally li + li { padding-left: 14px; border-left: 1px solid var(--line); }
.tally strong { font-size: 30px; font-weight: 800; font-stretch: 75%; line-height: 1; }
.tally span { color: var(--muted); font-size: 13px; margin-top: 4px; }
.tally li.g strong { color: var(--groen); }
.tally li.o strong { color: var(--oranje); }
.tally li.r strong { color: #e0574d; }
.fallen .actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.fallen .actions button { padding: 14px 10px; font-size: 16px; text-align: center; }

/* Boetekaart: dezelfde speelkaart als de opdracht, maar in het paneel */
.playcard.boete-card {
  width: 100%;
  min-height: 0;
  margin: 0 0 28px;
  padding: 18px 20px 16px;
  transform: rotate(-1deg);
  animation: deal-boete 0.24s ease-out;
}
.boete-card .playcard-text { margin: 22px 4px; font-size: 26px; }
.boete-card .done { font-size: 16px; padding: 12px; }
@keyframes deal-boete {
  from { transform: translateY(20px) rotate(-3deg); opacity: 0; }
  to { transform: rotate(-1deg); opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .tb-1, .tb-2 { animation-duration: 0.01s; animation-delay: 0s; }
}

/* ---------- Alle opdrachten ---------- */

/* Twee tegels onder de set-keuze: opdrachten bekijken en terug naar alle spellen */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 22px; }
.tile {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  padding: 14px 14px 12px;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--paper);
  text-align: left;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.12s ease-out, background-color 0.15s;
}
.tile:hover { background: #2f221c; }
.tile:active { transform: translateY(1px); }
.tile svg { width: 22px; height: 22px; fill: var(--wood); }
.tile span { display: flex; flex-direction: column; }
.tile strong { font-size: 16px; font-weight: 700; line-height: 1.2; }
.tile small { font-size: 13px; color: var(--muted); line-height: 1.3; margin-top: 2px; }

.deck-tabs {
  display: flex;
  gap: 4px;
  margin: 16px 0 8px;
  padding: 4px;
  border-radius: 6px;
  background: var(--ink);
}
.deck-tabs button {
  flex: 1;
  padding: 9px 8px;
  border-radius: 4px;
  font-weight: 700;
  color: var(--muted);
}
.deck-tabs button[aria-selected="true"] { background: var(--surface-2); color: var(--paper); }

.deck-color {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 26px 0 8px;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.deck-color i { width: 14px; height: 10px; border-radius: 2px; }
.deck-color span { margin-left: auto; color: var(--muted); font-weight: 600; letter-spacing: 0; }
.deck-color.groen i { background: var(--groen); }
.deck-color.oranje i { background: var(--oranje); }
.deck-color.rood i { background: var(--rood); }

.deck-section {
  margin: 40px 0 0;
  padding-top: 22px;
  border-top: 1px solid var(--line);
  font-size: 26px;
  font-weight: 800;
  font-stretch: 80%;
  line-height: 1.1;
}
.deck-section span { display: block; margin-top: 6px; font-size: 14px; font-weight: 500; font-stretch: normal; color: var(--muted); line-height: 1.4; }

.deck-cards { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.deck-cards li {
  position: relative;
  padding: 11px 14px 11px 20px;
  border-radius: 4px;
  background: var(--surface-2);
  font-weight: 600;
  line-height: 1.3;
  text-wrap: pretty;
}
.deck-cards li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 6px;
  border-radius: 4px 0 0 4px;
  background: var(--c);
}
.deck-cards.groen { --c: var(--groen); }
.deck-cards.oranje { --c: var(--oranje); }
.deck-cards.rood { --c: var(--rood); }

/* ---------- Telefoon ---------- */

@media (max-width: 640px) {
  .sheet {
    top: auto;
    width: 100%;
    max-height: 82vh;
    padding: 28px 20px max(24px, env(safe-area-inset-bottom));
    border-right: 0;
    border-top: 1px solid var(--line);
    border-radius: 12px 12px 0 0;
    animation-name: rise;
  }
  .wordmark { font-size: 38px; }
  .sheet::before {
    content: "";
    display: block;
    width: 36px;
    height: 4px;
    margin: -14px auto 18px;
    border-radius: 2px;
    background: var(--line);
  }
  .legend { margin-bottom: 26px; }
  .deck { max-height: 88vh; }
  .turn-name { font-size: 24px; }
  .playcard { min-height: 400px; }
  .playcard-text { font-size: 27px; }
}

/* cupertino-pane zet na het sluiten display: none op het paneel; zichtbaar is zichtbaar */
.sheet:not([hidden]) { display: block !important; }

/* In een cupertino-pane (telefoon): de pane is het blad, de sectie alleen de inhoud */
.sheet-pane {
  --cupertino-pane-background: var(--surface);
  --cupertino-pane-color: var(--paper);
  --cupertino-pane-move-background: var(--line);
  --cupertino-pane-border-radius: 14px;
  --cupertino-pane-shadow: inset 0 1px 0 rgba(255, 220, 180, 0.12), 0 -1px 2px rgba(0, 0, 0, 0.3), 0 -10px 30px rgba(0, 0, 0, 0.22);
}
.sheet.in-pane {
  position: static;
  width: auto;
  max-height: none;
  padding: 10px 20px max(24px, env(safe-area-inset-bottom));
  background: none;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  animation: none;
  /* Hoger dan het paneel mag worden: dan scrolt de inhoud binnen het paneel (88% min de greep) */
  max-height: calc(88vh - 34px);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.sheet.in-pane::before { display: none; }

@keyframes rise {
  from { transform: translateY(24px); opacity: 0.6; }
  to { transform: none; opacity: 1; }
}
