:root {
  --bg: #1a1330;
  --bg2: #2a1f4a;
  --ink: #f6f0ff;
  --muted: #b9acd8;
  --gold: #ffc94a;
  --gold-d: #d9921c;
  --card: #261c44;
  --line: rgba(255, 255, 255, .12);
  --felt1: #1f4f7a;
  --felt2: #102a47;
  --wood1: #8a5a32;
  --wood2: #5b3519;
  --tile1: #fffaf0;
  --tile2: #f1e6c8;
  --tile-edge: #cdb98a;
  --c0: #e0303f;
  --c1: #1f6fd1;
  --c2: #f08a00;
  --c3: #23262d;
  --ok: #3ddc84;
  --bad: #ff4d6d;
  --tw: 54px;
  --th: 72px;
  --rt: 46px;
  font-family: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); overflow: hidden; overscroll-behavior: none; touch-action: manipulation; }
body {
  background:
    radial-gradient(1200px 700px at 15% -10%, #4b2d86 0%, transparent 60%),
    radial-gradient(900px 600px at 110% 110%, #1b4f6e 0%, transparent 55%),
    var(--bg);
}
#app { height: 100dvh; position: relative; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
button { font: inherit; color: inherit; cursor: pointer; }
input, select {
  font: inherit; color: var(--ink); background: rgba(255,255,255,.07); border: 1px solid var(--line);
  border-radius: 12px; padding: 10px 12px; width: 100%; outline: none;
}
input:focus, select:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(255,201,74,.25); }
select option { color: #111; }

.btn {
  border: 0; border-radius: 14px; padding: 10px 16px; font-weight: 700;
  background: #3a2d63; box-shadow: 0 4px 0 #20173b, 0 6px 14px rgba(0,0,0,.25);
  transition: transform .08s, box-shadow .08s, filter .15s; white-space: nowrap;
}
.btn:hover { filter: brightness(1.1); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #20173b; }
.btn:disabled { opacity: .45; cursor: not-allowed; filter: grayscale(.4); }
.btn.gold { background: linear-gradient(180deg, #ffd96e, var(--gold)); color: #3a2300; box-shadow: 0 4px 0 var(--gold-d), 0 8px 18px rgba(255,180,40,.25); }
.btn.gold:active { box-shadow: 0 1px 0 var(--gold-d); }
.btn.big { width: 100%; padding: 14px; font-size: 18px; }
.btn.small { padding: 8px 10px; font-size: 14px; border-radius: 11px; }
.link { background: none; border: 0; color: var(--muted); text-decoration: underline; padding: 8px; }
.icon-btn {
  position: relative; width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line);
  background: rgba(255,255,255,.06); font-size: 18px; display: grid; place-items: center;
}
.icon-btn:hover { background: rgba(255,255,255,.12); }
.dot { position: absolute; top: 6px; right: 6px; width: 9px; height: 9px; border-radius: 50%; background: var(--bad); }

/* ---- Start / lobby ---- */
.screen { position: absolute; inset: 0; }
#scr-start, #scr-lobby { overflow-y: auto; display: flex; justify-content: center; align-items: flex-start; padding: max(24px, env(safe-area-inset-top)) 16px 40px; }
.start-card, .lobby-card {
  width: 100%; max-width: 440px; margin: auto 0; background: rgba(38, 28, 68, .82); backdrop-filter: blur(8px);
  border: 1px solid var(--line); border-radius: 24px; padding: 24px 20px; box-shadow: 0 20px 60px rgba(0,0,0,.4);
  display: flex; flex-direction: column; gap: 14px;
}
.logo { display: flex; justify-content: center; gap: 4px; margin: 4px 0 0; flex-wrap: nowrap; }
.logo .tile { position: relative; transform: none; --s: .8; animation: hop 2.6s ease-in-out infinite; }
.tagline { text-align: center; margin: 0; color: var(--muted); }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); font-weight: 600; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row2.tight { grid-template-columns: 1fr auto; }
#scr-lobby .row2.tight, .end-sheet .row2.tight { grid-template-columns: 1fr 1fr; }
#new-box { display: flex; flex-direction: column; gap: 12px; }
.or { text-align: center; color: var(--muted); font-size: 13px; }
#in-code { text-transform: uppercase; letter-spacing: 4px; font-weight: 800; text-align: center; }
.avatars { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.avatars button {
  font-size: 26px; height: 46px; border-radius: 12px; border: 2px solid transparent; background: rgba(255,255,255,.06);
}
.avatars button[aria-checked="true"] { border-color: var(--gold); background: rgba(255,201,74,.15); transform: scale(1.06); }
.join-box { text-align: center; background: rgba(255,201,74,.08); border: 1px dashed rgba(255,201,74,.5); border-radius: 16px; padding: 12px; }
.join-box p { margin: 4px 0 10px; }
.bigcode { font-size: 44px; font-weight: 900; letter-spacing: 8px; text-align: center; color: var(--gold); text-shadow: 0 3px 0 #6b3f00; }
.share { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.plist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.plist li {
  display: flex; align-items: center; gap: 10px; background: rgba(255,255,255,.05); border: 1px solid var(--line);
  border-radius: 14px; padding: 8px 10px; animation: pop .3s ease-out;
}
.plist .av { font-size: 26px; }
.plist .nm { flex: 1; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plist .tag { font-size: 12px; color: var(--muted); }
.plist .x { background: none; border: 0; color: var(--muted); font-size: 18px; }
.plist .empty { opacity: .45; border-style: dashed; }
.lb { --hg-accent: var(--gold); --hg-bg: rgba(255,255,255,.04); --hg-fg: var(--ink); --hg-border: var(--line); --hg-input: rgba(255,255,255,.08); }
.lb:empty { display: none; }

/* ---- Spel ---- */
#scr-game { display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 8px; padding: max(8px, env(safe-area-inset-top)) 10px 8px;
  background: linear-gradient(180deg, rgba(20,14,38,.95), rgba(20,14,38,.75)); border-bottom: 1px solid var(--line); z-index: 5;
}
.players { flex: 1; display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding: 2px; }
.players::-webkit-scrollbar { display: none; }
.pchip {
  position: relative; display: flex; align-items: center; gap: 6px; padding: 5px 10px 5px 6px; border-radius: 999px;
  background: rgba(255,255,255,.06); border: 2px solid transparent; flex-shrink: 0; transition: all .25s;
}
.pchip .av { font-size: 22px; width: 30px; height: 30px; display: grid; place-items: center; border-radius: 50%; background: rgba(0,0,0,.25); position: relative; }
.pchip .meta { display: flex; flex-direction: column; line-height: 1.1; }
.pchip .nm { font-weight: 800; font-size: 13px; max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pchip .sub { font-size: 11px; color: var(--muted); }
.pchip.active { border-color: var(--gold); background: rgba(255,201,74,.14); box-shadow: 0 0 18px rgba(255,201,74,.35); }
.pchip.off { opacity: .45; }
.pchip.me .nm::after { content: " (jij)"; color: var(--muted); font-weight: 600; }
.pchip svg.ring { position: absolute; inset: -4px; width: 38px; height: 38px; transform: rotate(-90deg); pointer-events: none; }
.pchip svg.ring circle { fill: none; stroke: var(--gold); stroke-width: 3; stroke-linecap: round; }
.pchip svg.ring.low circle { stroke: var(--bad); }
.tools { display: flex; gap: 6px; }

.board-vp {
  position: relative; flex: 1; overflow: hidden; touch-action: none; cursor: grab;
  background: radial-gradient(ellipse at center, #2d2152 0%, #150f28 80%);
}
.board-vp.panning { cursor: grabbing; }
.board {
  position: absolute; left: 0; top: 0; transform-origin: 0 0;
  border-radius: 26px; padding: 0;
  background:
    radial-gradient(circle at center, rgba(255,255,255,.07) 1.5px, transparent 2px) 0 0 / var(--tw) var(--th),
    radial-gradient(ellipse at 50% 40%, var(--felt1), var(--felt2));
  box-shadow: inset 0 0 0 14px var(--wood2), inset 0 0 0 18px var(--wood1), inset 0 0 60px rgba(0,0,0,.6), 0 30px 80px rgba(0,0,0,.6);
}
.board::before { /* houtnerf */
  content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
  background: repeating-linear-gradient(90deg, rgba(255,255,255,.03) 0 2px, transparent 2px 9px);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0); mask-composite: exclude; -webkit-mask-composite: xor; padding: 18px;
}
.board .drop-hint {
  position: absolute; width: calc(var(--tw) - 6px); height: calc(var(--th) - 6px); border-radius: 9px;
  border: 2px dashed rgba(255,201,74,.8); background: rgba(255,201,74,.12); pointer-events: none; transition: transform .06s;
}
.seg-mark { position: absolute; height: 8px; border-radius: 4px; pointer-events: none; transition: all .2s; }
.seg-mark.ok { background: var(--ok); box-shadow: 0 0 10px var(--ok); opacity: .75; }
.seg-mark.bad { background: var(--bad); box-shadow: 0 0 12px var(--bad); animation: blink 1s infinite; }
.seg-label {
  position: absolute; font-size: 12px; font-weight: 800; padding: 2px 7px; border-radius: 8px; pointer-events: none; white-space: nowrap;
  background: rgba(10,8,20,.75); color: #fff;
}

/* ---- Stenen ---- */
.tile {
  --s: 1;
  position: absolute; left: 0; top: 0; width: calc(48px * var(--s)); height: calc(66px * var(--s));
  border-radius: calc(9px * var(--s));
  background: linear-gradient(165deg, var(--tile1) 0%, var(--tile1) 45%, var(--tile2) 100%);
  box-shadow: 0 calc(4px * var(--s)) 0 var(--tile-edge), 0 calc(7px * var(--s)) calc(10px * var(--s)) rgba(0,0,0,.45),
              inset 0 1px 0 #fff, inset 0 -2px 4px rgba(0,0,0,.06);
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start;
  padding-top: calc(9px * var(--s));
  font-weight: 900; font-size: calc(30px * var(--s)); line-height: 1; letter-spacing: -1px;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: none; cursor: grab;
  transition: transform .45s cubic-bezier(.2,.9,.25,1.1), box-shadow .2s, opacity .3s;
  will-change: transform;
}
.tile .num { text-shadow: 0 1px 0 rgba(255,255,255,.8); }
.tile .pip {
  margin-top: auto; margin-bottom: calc(9px * var(--s)); width: calc(14px * var(--s)); height: calc(14px * var(--s)); border-radius: 50%;
  border: calc(3px * var(--s)) solid currentColor; opacity: .85;
}
.tile.c0 { color: var(--c0); } .tile.c1 { color: var(--c1); } .tile.c2 { color: var(--c2); } .tile.c3 { color: var(--c3); }
.tile.joker { padding-top: calc(6px * var(--s)); }
.tile.joker svg { width: 82%; height: auto; }
.tile.joker .pip { display: none; }
.tile.dragging { transition: none; z-index: 1000; cursor: grabbing; box-shadow: 0 6px 0 var(--tile-edge), 0 24px 30px rgba(0,0,0,.5); }
.tile.sel { box-shadow: 0 4px 0 var(--gold-d), 0 0 0 3px var(--gold), 0 8px 20px rgba(255,201,74,.45); }
.tile.locked { cursor: default; }
.tile.fresh::after {
  content: ""; position: absolute; inset: -4px; border-radius: 12px; border: 3px solid var(--gold);
  box-shadow: 0 0 16px var(--gold); animation: glow 1.6s ease-in-out infinite; pointer-events: none;
}
.tile.mine-new::before {
  content: ""; position: absolute; top: 4px; right: 4px; width: 7px; height: 7px; border-radius: 50%; background: var(--ok);
}
.tile.bad { animation: wobble .4s; }
.tile.flyin { transition: transform .9s cubic-bezier(.15,.85,.25,1.05), opacity .4s; }
.tile.ghost { opacity: 0; pointer-events: none; }
.board.slow .tile { transition-duration: .9s; }

/* ---- Rek ---- */
.dock {
  z-index: 6; padding: 6px 10px max(10px, env(safe-area-inset-bottom));
  background: linear-gradient(0deg, rgba(20,14,38,.98), rgba(20,14,38,.85)); border-top: 1px solid var(--line);
}
.dock-bar { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.pool { font-size: 13px; color: var(--muted); white-space: nowrap; display: flex; align-items: center; gap: 4px; }
.pool b { color: var(--ink); }
.hint { flex: 1; font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: center; }
.hint.bad { color: var(--bad); font-weight: 700; }
.hint.ok { color: var(--ok); font-weight: 700; }
.dock-actions { display: flex; gap: 6px; }
.btn.main { min-width: 120px; }
.btn.main.pulse { animation: pulse 1.4s infinite; }
.rack {
  position: relative; height: calc(var(--rt) * 1.375 * 2 + 18px); border-radius: 16px; margin: 0 auto; max-width: 1100px;
  background: linear-gradient(180deg, var(--wood1), var(--wood2)); box-shadow: inset 0 2px 0 rgba(255,255,255,.15), inset 0 -6px 12px rgba(0,0,0,.35), 0 6px 18px rgba(0,0,0,.4);
  touch-action: none;
}
.rack:not([data-rows="2"])::after { display: none; }
.rack::after { content: ""; position: absolute; left: 8px; right: 8px; top: 50%; height: 3px; background: rgba(0,0,0,.25); border-radius: 2px; }
.rack.turn { box-shadow: inset 0 2px 0 rgba(255,255,255,.15), inset 0 -6px 12px rgba(0,0,0,.35), 0 0 0 3px var(--gold), 0 0 26px rgba(255,201,74,.4); }
.rack .drop-hint { position: absolute; border-radius: 8px; border: 2px dashed rgba(255,255,255,.7); pointer-events: none; }

/* ---- Zoom & status ---- */
.zoom { position: absolute; right: 10px; bottom: 10px; display: flex; flex-direction: column; gap: 6px; z-index: 3; }
.zoom button {
  width: 42px; height: 42px; border-radius: 12px; border: 1px solid var(--line); background: rgba(20,14,38,.8);
  font-size: 22px; font-weight: 800; backdrop-filter: blur(6px);
}
.status {
  position: absolute; left: 50%; top: 12px; transform: translateX(-50%); z-index: 3; pointer-events: none;
  padding: 8px 16px; border-radius: 999px; background: rgba(20,14,38,.82); border: 1px solid var(--line);
  font-weight: 800; font-size: 15px; white-space: nowrap; backdrop-filter: blur(6px); transition: all .3s;
}
.status:empty { opacity: 0; }
.status.me { background: linear-gradient(180deg, #ffd96e, var(--gold)); color: #3a2300; border-color: transparent; box-shadow: 0 6px 24px rgba(255,201,74,.45); }
.status .count { display: inline-block; min-width: 2ch; margin-left: 6px; }
.status.hurry { animation: pulse 0.8s infinite; }

.replay-bar {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); z-index: 4;
  display: flex; align-items: center; gap: 6px; padding: 6px; border-radius: 18px;
  background: rgba(20,14,38,.92); border: 1px solid var(--gold); box-shadow: 0 10px 30px rgba(0,0,0,.5); max-width: calc(100% - 80px);
}
.replay-bar button { width: 40px; height: 40px; border-radius: 12px; border: 0; background: rgba(255,255,255,.08); font-size: 18px; flex-shrink: 0; }
.replay-bar button:disabled { opacity: .3; }
.rp-text { display: flex; flex-direction: column; padding: 0 8px; min-width: 0; }
.rp-text b { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rp-text span { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.board-vp.replaying::after {
  content: "TERUGKIJKEN"; position: absolute; left: 14px; top: 14px; font-size: 11px; font-weight: 900; letter-spacing: 2px;
  padding: 4px 8px; border-radius: 6px; background: var(--bad); color: #fff; animation: blink 1.6s infinite;
}

/* ---- Chat ---- */
.chat-panel {
  position: absolute; right: 10px; top: 64px; bottom: 170px; width: min(340px, calc(100% - 20px)); z-index: 8;
  background: rgba(26,19,48,.97); border: 1px solid var(--line); border-radius: 18px; display: flex; flex-direction: column;
  box-shadow: 0 20px 50px rgba(0,0,0,.5);
}
.chat-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 8px 8px 14px; border-bottom: 1px solid var(--line); }
.chat-box { flex: 1; min-height: 0; padding: 6px; --hg-accent: var(--gold); --hg-bg: transparent; --hg-fg: var(--ink); --hg-border: var(--line); --hg-input: rgba(255,255,255,.08); }

/* ---- Overlays ---- */
.overlay { position: absolute; inset: 0; z-index: 20; background: rgba(8,5,18,.6); backdrop-filter: blur(4px); display: grid; place-items: center; padding: 16px; animation: fade .2s; }
.sheet {
  width: 100%; max-width: 460px; max-height: 100%; overflow-y: auto; background: var(--card); border: 1px solid var(--line);
  border-radius: 22px; padding: 20px; display: flex; flex-direction: column; gap: 10px; box-shadow: 0 30px 80px rgba(0,0,0,.55);
  animation: pop .25s ease-out;
}
.sheet h2 { margin: 0; }
.sheet h3 { margin: 8px 0 0; font-size: 16px; color: var(--gold); }
.sheet ul { margin: 4px 0; padding-left: 20px; }
.sheet li { margin: 4px 0; }
.rules .ex { display: flex; gap: 3px; margin-top: 6px; }
.rules .ex .tile { position: relative; transform: none; --s: .62; }
.col { display: flex; flex-direction: column; gap: 6px; }
.end-title { font-size: 30px; font-weight: 900; text-align: center; }
.end-sheet .muted { text-align: center; }
.scores { width: 100%; border-collapse: collapse; font-size: 14px; }
.scores th { text-align: left; color: var(--muted); font-weight: 600; font-size: 12px; padding: 4px; }
.scores td { padding: 6px 4px; border-top: 1px solid var(--line); vertical-align: middle; }
.scores td.num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 800; }
.scores .pos { color: var(--ok); } .scores .neg { color: var(--bad); }
.scores tr.win td { background: rgba(255,201,74,.1); }
.mini { display: flex; flex-wrap: wrap; gap: 2px; max-width: 150px; }
.mini .tile { position: relative; transform: none; --s: .36; box-shadow: 0 2px 0 var(--tile-edge); }

.toast {
  position: absolute; left: 50%; top: 70px; transform: translate(-50%, -20px); z-index: 30; opacity: 0; pointer-events: none;
  background: #fff; color: #23162f; font-weight: 800; padding: 10px 18px; border-radius: 14px; box-shadow: 0 10px 30px rgba(0,0,0,.4);
  transition: all .25s; max-width: calc(100% - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { background: var(--bad); color: #fff; }
.confetti { position: absolute; inset: 0; pointer-events: none; z-index: 25; width: 100%; height: 100%; }

@keyframes hop { 0%, 80%, 100% { translate: 0 0; } 88% { translate: 0 -8px; } }
@keyframes pop { from { transform: scale(.92); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes fade { from { opacity: 0; } }
@keyframes glow { 50% { opacity: .35; } }
@keyframes blink { 50% { opacity: .45; } }
@keyframes pulse { 50% { filter: brightness(1.18); transform: scale(1.04); } }
@keyframes wobble { 25% { translate: -4px 0; } 75% { translate: 4px 0; } }

@media (max-width: 640px) {
  :root { --rt: 34px; }
  .pchip .meta .sub { display: none; }
  .pchip { padding: 4px 8px 4px 4px; }
  .pchip .nm { max-width: 60px; }
  .dock-bar { flex-wrap: wrap; }
  .hint { order: 3; flex-basis: 100%; text-align: left; }
  .btn.main { min-width: 100px; }
  .chat-panel { bottom: 150px; }
  .bigcode { font-size: 36px; letter-spacing: 6px; }
}
/* Telefoon liggend / lage schermen */
@media (max-height: 520px) {
  :root { --rt: 30px; }
  .topbar { padding-top: max(4px, env(safe-area-inset-top)); padding-bottom: 4px; }
  .pchip { padding: 2px 8px 2px 3px; }
  .pchip .av { width: 26px; height: 26px; font-size: 18px; }
  .pchip .meta .sub { display: none; }
  .icon-btn { width: 34px; height: 34px; font-size: 16px; }
  .dock { padding-top: 4px; padding-bottom: max(4px, env(safe-area-inset-bottom)); }
  .dock-bar { margin-bottom: 4px; flex-wrap: nowrap; }
  .hint { order: 0; flex-basis: auto; text-align: center; }
  .btn.small { padding: 6px 8px; }
  .btn.main { min-width: 96px; padding: 7px 12px; }
  .status { top: 6px; padding: 5px 12px; font-size: 13px; }
  .zoom { bottom: 6px; right: 6px; }
  .zoom button { width: 36px; height: 36px; }
  .chat-panel { top: 44px; bottom: 8px; }
}
.topbar, .dock { padding-left: max(10px, env(safe-area-inset-left)); padding-right: max(10px, env(safe-area-inset-right)); }

@media (prefers-reduced-motion: reduce) {
  .tile, .tile.flyin { transition-duration: .01s; }
  .logo .tile, .btn.main.pulse, .tile.fresh::after { animation: none; }
}
