/* Bagvendt – mobil først. Mørk menu/lobby, lys spilskærm (som designforslaget); "Mørk overalt" kan vælges i Indstillinger. */
:root {
  --font: Inter, -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --r: 16px; --r-sm: 12px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --spring: cubic-bezier(.34, 1.56, .64, 1);
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
}
body[data-theme="dark"] {
  --bg: #0d0d0d; --fg: #f5f5f3; --muted: #9a9a96; --card: #1b1b1b; --card2: #262626; --line: #2c2c2c;
  --tile: #fafaf8; --tile-fg: #111; --tile-dark: #151515; --tile-dark-fg: #fafaf8; --tile-line: #3a3a3a;
  --btn: #fafaf8; --btn-fg: #111; --ok: #3fae5f; --ok-bg: #173324; --bad: #e0574f; --bad-bg: #3a1d1b; --pill: #262626; --accent: #ffd23f;
}
body[data-theme="light"] {
  --bg: #fafaf8; --fg: #111; --muted: #6d6d68; --card: #fff; --card2: #f1f1ee; --line: #e8e8e4;
  --tile: #fff; --tile-fg: #111; --tile-dark: #1c1c1c; --tile-dark-fg: #fff; --tile-line: #e3e3de;
  --btn: #111; --btn-fg: #fff; --ok: #3fae5f; --ok-bg: #d9eedd; --bad: #d9473f; --bad-bg: #f8dedb; --pill: #e4e4e0; --accent: #f2b705;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); background: var(--bg); color: var(--fg); overflow-x: hidden; transition: background .35s var(--ease), color .35s var(--ease); -webkit-font-smoothing: antialiased; touch-action: manipulation; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; padding: 0; }
input { font: inherit; color: inherit; }
h1, h2, h3, p { margin: 0; }
#app { min-height: 100%; max-width: 520px; margin: 0 auto; position: relative; display: flex; flex-direction: column; }
.screen { flex: 1; display: flex; flex-direction: column; padding: calc(var(--safe-t) + 14px) 18px calc(var(--safe-b) + 18px); }
.screen.enter { animation: screenIn .35s var(--ease) both; }
@keyframes screenIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.noanim *, .noanim *::before, .noanim *::after { animation-duration: 1ms !important; animation-delay: 0ms !important; transition-duration: 1ms !important; }
@media (prefers-reduced-motion: reduce) { * { animation-duration: 1ms !important; animation-delay: 0ms !important; transition-duration: 1ms !important; } }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- topbar ---------- */
.top { display: flex; align-items: center; gap: 12px; min-height: 56px; }
.top .ttl { flex: 1; min-width: 0; }
.top .ttl b { display: block; font-size: 20px; font-weight: 800; letter-spacing: -.01em; }
.top .ttl span { color: var(--muted); font-size: 14px; }
.icon-btn { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 12px; transition: background .2s; }
.icon-btn:active { background: var(--card2); }
.icon-btn svg { width: 22px; height: 22px; }
.pill { display: inline-flex; align-items: center; gap: 8px; background: var(--pill); border-radius: 999px; padding: 9px 16px 9px 12px; font-weight: 800; font-variant-numeric: tabular-nums; font-size: 18px; position: relative; overflow: hidden; }
.pill svg { width: 22px; height: 22px; }
.pill .bar { position: absolute; left: 0; bottom: 0; height: 3px; background: var(--fg); opacity: .55; width: 100%; transform-origin: left; }
.pill.urgent { background: var(--bad-bg); color: var(--bad); animation: pulse .8s ease-in-out infinite; }
.pill.urgent .bar { background: var(--bad); }
@keyframes pulse { 50% { transform: scale(1.06); } }
.mode-badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; background: var(--card2); color: var(--muted); border-radius: 999px; padding: 4px 10px; }
.mode-badge i { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }

/* ---------- knapper ---------- */
.btn { display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%; min-height: 56px; border-radius: var(--r-sm); background: var(--btn); color: var(--btn-fg); font-weight: 800; letter-spacing: .02em; font-size: 17px; transition: transform .15s var(--ease), opacity .2s; }
.btn:active { transform: scale(.98); }
.btn[disabled] { opacity: .35; pointer-events: none; }
.btn.ghost { background: var(--card2); color: var(--fg); }
.btn.small { min-height: 44px; font-size: 15px; }
.btn.danger { background: var(--bad-bg); color: var(--bad); }
.link { color: var(--muted); font-weight: 600; padding: 10px; text-align: center; width: 100%; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.spacer { flex: 1; }

/* ---------- forside ---------- */
.home { justify-content: space-between; position: relative; overflow: hidden; padding-bottom: 0; }
.logo { text-align: center; margin-top: 12vh; }
.logo .tiles { display: flex; justify-content: center; gap: 4px; }
.logo .t { width: min(11.4vw, 52px); aspect-ratio: .86; background: #fafaf8; color: #111; border-radius: 6px; display: grid; place-items: center; font-weight: 900; font-size: min(7.6vw, 34px); box-shadow: 0 2px 0 #bdbdb8, 0 8px 18px #0008; animation: dealIn .6s var(--spring) both; animation-delay: calc(var(--i) * 70ms); }
.logo .t.v { border: 2.5px solid #111; box-shadow: 0 0 0 2px #fafaf8, 0 2px 0 2px #bdbdb8, 0 8px 18px #0008; }
.logo p { margin-top: 18px; letter-spacing: .38em; font-size: 12px; color: var(--muted); font-weight: 600; }
@keyframes dealIn { from { opacity: 0; transform: translateY(-40px) rotate(calc((var(--i) - 3) * 9deg)) scale(.6); } to { opacity: 1; transform: none; } }
.menu { display: flex; flex-direction: column; gap: 12px; margin-top: 7vh; z-index: 1; }
.menu button { display: flex; align-items: center; gap: 18px; text-align: left; padding: 18px 20px; border-radius: var(--r-sm); background: var(--card); min-height: 72px; transition: transform .15s var(--ease), background .2s; }
.menu button:active { transform: scale(.98); }
.menu button.primary { background: #fafaf8; color: #111; }
.menu button svg { width: 26px; height: 26px; flex: none; }
.menu b { display: block; font-size: 17px; letter-spacing: .03em; font-weight: 800; }
.menu span { font-size: 15px; opacity: .72; }
.fan { position: relative; height: 150px; margin: 24px -18px 0; pointer-events: none; }
.fan .c { position: absolute; bottom: -70px; left: 50%; width: 96px; height: 134px; margin-left: -48px; border-radius: 10px; background: #f7f7f4; color: #111; font-weight: 900; font-size: 30px; padding: 8px 10px; box-shadow: 0 -2px 14px #0007; transform-origin: 50% 190%; transform: rotate(calc((var(--i) - 3.5) * 11deg)) translateY(0); animation: fanIn .8s var(--spring) both; animation-delay: calc(.5s + var(--i) * 60ms); }
.fan .c i { position: absolute; right: 10px; bottom: 6px; font-style: normal; font-size: 22px; transform: rotate(180deg); }
@keyframes fanIn { from { transform: rotate(0) translateY(60px); opacity: 0; } }

/* ---------- formularer ---------- */
.field { display: flex; flex-direction: column; gap: 8px; }
.field > label, .label { font-size: 12px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.input { width: 100%; min-height: 56px; border-radius: var(--r-sm); border: 2px solid var(--line); background: transparent; padding: 0 16px; font-size: 18px; outline: none; transition: border-color .2s; }
.input:focus { border-color: var(--fg); }
.input.code { text-transform: uppercase; letter-spacing: .12em; font-weight: 800; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.seg.n4 { grid-template-columns: repeat(4, 1fr); } .seg.n5 { grid-template-columns: repeat(5, 1fr); }
.opt { border: 2px solid var(--line); border-radius: var(--r-sm); padding: 12px; text-align: left; min-height: 48px; transition: all .18s var(--ease); }
.opt b { display: block; font-size: 15px; }
.opt small { color: var(--muted); font-size: 12.5px; line-height: 1.3; display: block; margin-top: 2px; }
.opt.chip { text-align: center; font-weight: 700; padding: 12px 4px; }
.opt.on { border-color: var(--fg); background: var(--fg); color: var(--bg); }
.opt.on small { color: inherit; opacity: .75; }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; border: 2px solid var(--line); border-radius: var(--r-sm); width: 100%; text-align: left; }
.switch small { display: block; color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.switch .knob { flex: none; width: 46px; height: 28px; border-radius: 99px; background: var(--card2); position: relative; transition: background .2s; }
.switch .knob::after { content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: var(--fg); transition: transform .25s var(--spring); }
.switch.on .knob { background: var(--ok); } .switch.on .knob::after { transform: translateX(18px); background: #fff; }
.ro { display: flex; flex-wrap: wrap; gap: 8px; }
.ro .chipx { background: var(--card2); border-radius: 999px; padding: 6px 12px; font-size: 13px; font-weight: 700; }
.err { color: var(--bad); font-weight: 600; min-height: 1.3em; font-size: 14px; }

/* ---------- lobby ---------- */
.roomcode { text-align: center; padding: 22px 12px; background: var(--card); border-radius: var(--r); }
.roomcode small { color: var(--muted); font-weight: 700; letter-spacing: .12em; text-transform: uppercase; font-size: 12px; }
.roomcode b { display: block; font-size: 40px; font-weight: 900; letter-spacing: .02em; margin: 6px 0 14px; word-break: break-all; }
.roomcode .row { display: flex; gap: 8px; justify-content: center; }
.roomcode .row .btn { width: auto; padding: 0 18px; white-space: nowrap; flex: none; }
.plist { display: flex; flex-direction: column; gap: 8px; }
.prow { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: var(--r-sm); background: var(--card); animation: rowIn .4s var(--spring) both; }
@keyframes rowIn { from { opacity: 0; transform: translateX(-18px); } }
.prow .nm { flex: 1; font-weight: 700; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prow .tag { font-size: 11px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.prow .st { font-size: 13px; font-weight: 800; color: var(--muted); }
.prow .st.ready { color: var(--ok); }
.prow.off { opacity: .5; }
.av { flex: none; width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; color: #111; font-size: 15px; position: relative; }
.av.sm { width: 28px; height: 28px; font-size: 12px; }
.av.on::after { content: ''; position: absolute; right: -2px; bottom: -2px; width: 11px; height: 11px; border-radius: 50%; background: var(--accent); border: 2px solid var(--bg); animation: pulse 1s ease-in-out infinite; }

/* ---------- brikker ---------- */
.tile { position: relative; background: var(--tile); color: var(--tile-fg); border-radius: 12px; border: 1px solid var(--tile-line); aspect-ratio: .78; display: grid; place-items: center; font-weight: 900; font-size: 34px; user-select: none; touch-action: none; box-shadow: 0 1px 0 var(--tile-line), 0 6px 14px #0000001a; }
.tile.v { background: var(--tile-dark); color: var(--tile-dark-fg); border-color: var(--tile-dark); }
.tile .c1, .tile .c2, .tile .c3, .tile .c4 { position: absolute; font-size: 12px; font-weight: 800; line-height: 1; }
.tile .c1 { top: 7px; left: 8px; } .tile .c2 { top: 7px; right: 8px; } .tile .c3 { bottom: 7px; left: 8px; } .tile .c4 { bottom: 7px; right: 8px; }
.tile.hidden { font-size: 40px; font-weight: 900; }
.row-tiles { display: grid; gap: 8px; }
.tile.used { opacity: .18; pointer-events: none; transform: scale(.94); }
.tile.drag-src { opacity: .25; }
.ghost-tile { position: fixed; z-index: 50; pointer-events: none; transform: scale(1.12) rotate(-3deg); box-shadow: 0 18px 30px #0004; transition: none; }
.slot { border: 2px dashed var(--tile-line); border-radius: 12px; aspect-ratio: .78; }
.tile.deal { animation: deal .55s var(--ease) both; animation-delay: calc(var(--i) * 70ms); }
@keyframes deal { from { opacity: 0; transform: translate(var(--dx, 0), -220px) rotate(calc(var(--i) * 40deg - 120deg)) scale(.5); } 60% { opacity: 1; } to { transform: none; } }
.tile.flip { animation: flip .7s var(--ease) both; }
@keyframes flip { 0% { transform: rotateY(90deg) scale(.9); } 55% { transform: rotateY(-12deg) scale(1.1); } 100% { transform: none; } }
.tile.pop { animation: pop .35s var(--spring); }
@keyframes pop { from { transform: scale(.6); opacity: 0; } }
.shake { animation: shake .4s; }
@keyframes shake { 20%, 60% { transform: translateX(-9px); } 40%, 80% { transform: translateX(9px); } }
.wordrow { min-height: 92px; padding: 12px; border-radius: var(--r); background: var(--card2); }
.hand { margin-top: 14px; }
.hint { color: var(--muted); font-size: 14px; text-align: center; line-height: 1.5; }
.hint b { color: var(--fg); }

/* ---------- gæt ---------- */
.owner { display: flex; align-items: center; gap: 10px; margin: 6px 0 14px; font-weight: 700; }
.owner small { color: var(--muted); font-weight: 600; margin-left: auto; }
.bigtiles { display: flex; justify-content: center; gap: 6px; margin: 8px 0 14px; }
.bigtiles .tile { flex: 0 1 var(--tw, 60px); width: var(--tw, 60px); font-size: var(--fs, 40px); }
.attempts { display: flex; align-items: center; justify-content: center; gap: 8px; margin: 10px 0; font-weight: 800; }
.attempts .pips { display: flex; gap: 5px; }
.attempts .pips i { width: 11px; height: 11px; border-radius: 50%; background: var(--fg); transition: all .3s var(--spring); }
.attempts .pips i.gone { background: transparent; border: 2px solid var(--line); transform: scale(.8); }
.turn { text-align: center; font-weight: 800; padding: 10px; border-radius: var(--r-sm); margin-bottom: 10px; background: var(--card2); }
.turn.me { background: var(--fg); color: var(--bg); animation: glow 1.4s ease-in-out infinite; }
@keyframes glow { 50% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--fg) 18%, transparent); } }
.queue { display: flex; justify-content: center; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.queue .q { opacity: .45; transition: all .3s; } .queue .q.act { opacity: 1; transform: scale(1.18); } .queue .q.act .av { box-shadow: 0 0 0 3px var(--fg); } .queue .q.done { opacity: .25; }
.guessbox { position: relative; }
.guessbox .input { padding-right: 52px; text-transform: uppercase; letter-spacing: .1em; font-weight: 800; background: var(--card); }
.guessbox .clear { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); width: 28px; height: 28px; border-radius: 50%; background: var(--muted); color: var(--bg); font-weight: 900; line-height: 28px; text-align: center; opacity: .7; }
.feed { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0; align-items: center; min-height: 34px; }
.gchip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 11px 5px 5px; border-radius: 999px; background: var(--card2); font-weight: 800; letter-spacing: .06em; font-size: 14px; animation: pop .4s var(--spring); }
.gchip.bad { text-decoration: line-through; text-decoration-color: var(--bad); text-decoration-thickness: 2px; }
.gchip.good { background: var(--ok-bg); color: var(--ok); }
.score-strip { display: flex; gap: 8px; justify-content: space-between; margin-top: auto; padding-top: 14px; }
.score-strip .s { flex: 1; text-align: center; background: var(--card); border-radius: var(--r-sm); padding: 8px 4px; min-width: 0; }
.score-strip .s b { display: block; font-size: 18px; font-variant-numeric: tabular-nums; }
.score-strip .s span { display: block; font-size: 11px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.score-strip .s.me { outline: 2px solid var(--fg); }
.score-strip .s.act { outline: 2px solid var(--accent); animation: glow 1.2s infinite; }
.sheet-bg { position: fixed; inset: 0; background: #000a; z-index: 30; animation: fadeIn .2s; display: flex; align-items: flex-end; justify-content: center; }
@keyframes fadeIn { from { opacity: 0; } }
.sheet { background: var(--bg); color: var(--fg); width: min(520px, 100%); max-height: 78vh; overflow: auto; border-radius: 22px 22px 0 0; padding: 18px 18px calc(var(--safe-b) + 24px); animation: sheetIn .35s var(--ease); }
@keyframes sheetIn { from { transform: translateY(100%); } }
.sheet h3 { margin-bottom: 12px; }
.hrow { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.hrow .w { flex: 1; font-weight: 800; letter-spacing: .08em; } .hrow small { color: var(--muted); }

/* ---------- resultat ---------- */
.banner { text-align: center; border-radius: var(--r); padding: 22px 16px; margin: 6px 0 18px; background: var(--ok-bg); animation: bannerIn .6s var(--spring) both; }
.banner.bad { background: var(--bad-bg); } .banner.neutral { background: var(--card2); }
.banner .chk { width: 46px; height: 46px; margin: -46px auto 8px; border-radius: 50%; background: var(--bg); display: grid; place-items: center; }
.banner h2 { font-size: 28px; font-weight: 900; letter-spacing: -.01em; }
.banner p { margin-top: 6px; font-size: 18px; }
@keyframes bannerIn { from { transform: scale(.8) translateY(20px); opacity: 0; } }
.sect { font-size: 22px; font-weight: 800; margin: 18px 0 10px; }
.rlist { background: var(--card); border-radius: var(--r); padding: 4px 12px; }
.rrow { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.rrow:last-child { border: 0; }
.rrow .nm { flex: 1; font-weight: 600; min-width: 0; }
.rrow .nm small { display: block; color: var(--muted); font-weight: 500; font-size: 13px; }
.rrow .pts { font-weight: 800; font-variant-numeric: tabular-nums; min-width: 64px; text-align: right; }
.pts.pos { color: var(--ok); } .pts.neg { color: var(--bad); }
.dot { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; color: #fff; flex: none; }
.dot.ok { background: var(--ok); } .dot.no { background: var(--bad); } .dot svg { width: 14px; height: 14px; }
.rank { width: 22px; font-weight: 800; color: var(--muted); }
.board .rrow { animation: rowIn .45s var(--ease) both; animation-delay: calc(var(--i) * 70ms); }
.board .rrow.me { font-weight: 800; }
.count { font-variant-numeric: tabular-nums; }
.winner { text-align: center; padding: 30px 10px 10px; }
.winner .crown { font-size: 64px; animation: crown 1.6s ease-in-out infinite; display: inline-block; }
@keyframes crown { 50% { transform: translateY(-8px) rotate(6deg); } }
.winner h1 { font-size: 34px; font-weight: 900; margin: 8px 0; letter-spacing: -.02em; }
.winner p { color: var(--muted); }
.cd { display: grid; place-items: center; flex: 1; }
.cd b { font-size: 140px; font-weight: 900; animation: cdPop 1s var(--ease) infinite; }
@keyframes cdPop { from { transform: scale(1.6); opacity: 0; } 30% { opacity: 1; } to { transform: scale(.9); } }
.wait { text-align: center; padding: 8px 0; }
.spin { width: 38px; height: 38px; border-radius: 50%; border: 4px solid var(--line); border-top-color: var(--fg); animation: spin 1s linear infinite; margin: 16px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.okmsg { color: var(--ok); font-weight: 800; } .badmsg { color: var(--bad); font-weight: 800; }

/* ---------- toast / fx ---------- */
#toast { position: fixed; left: 50%; bottom: calc(var(--safe-b) + 24px); transform: translate(-50%, 30px); background: #111; color: #fff; padding: 12px 18px; border-radius: 12px; font-weight: 600; opacity: 0; pointer-events: none; transition: all .3s var(--ease); z-index: 60; max-width: 90vw; text-align: center; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.err { background: var(--bad); }
#fx { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 40; }

/* små brikker (hånd og ordrække): kun det store bogstav */
.row-tiles .tile .c1, .row-tiles .tile .c2, .row-tiles .tile .c3, .row-tiles .tile .c4 { display: none; }
