/* MBB – gamer × billard. Designtokens først. */
:root {
  --bg: #07130E;
  --surface: #0F2A1F;
  --surface-2: #143826;
  --line: #1f4a35;
  --accent: #00E5A0;
  --gold: #FFC83D;
  --silver: #C9D6D0;
  --bronze: #D98C4A;
  --danger: #FF4D6D;
  --text: #EAF7F0;
  --muted: #8FB5A3;
  --radius: 16px;
  --glow: 0 0 0 1px var(--accent), 0 0 18px rgba(0, 229, 160, .35);
  --font-display: "Rajdhani", "Orbitron", "Bahnschrift", "Segoe UI", system-ui, sans-serif;
  --font-body: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  --tab-h: 64px;
  --top-h: 56px;
}

* { box-sizing: border-box; }
html { color-scheme: dark; }
body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 50% -10%, #12402c 0%, transparent 60%),
    repeating-linear-gradient(45deg, rgba(255,255,255,.012) 0 2px, transparent 2px 4px),
    var(--bg);
  background-attachment: fixed;
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}
body::after { /* vignette */
  content: ""; position: fixed; inset: 0; pointer-events: none;
  box-shadow: inset 0 0 160px rgba(0,0,0,.55);
}
h1, h2, h3 { font-family: var(--font-display); text-transform: uppercase; letter-spacing: .06em; margin: 0 0 .5rem; }
h1 { font-size: 1.7rem; } h2 { font-size: 1.3rem; } h3 { font-size: 1.05rem; color: var(--muted); }
button, input, select { font: inherit; color: inherit; }
.num { font-family: var(--font-display); font-variant-numeric: tabular-nums; font-weight: 700; }
.muted { color: var(--muted); }
.hidden { display: none !important; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

/* ---------- Layout ---------- */
.shell { position: relative; z-index: 1; }
.topbar {
  position: sticky; top: 0; z-index: 20; height: calc(var(--top-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 14px 0; display: flex; align-items: center; gap: 12px;
  background: rgba(7, 19, 14, .85); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.logo { display: flex; align-items: center; gap: 8px; font-family: var(--font-display); font-weight: 700; letter-spacing: .12em; font-size: 1.25rem; }
.logo .ball { width: 28px; height: 28px; font-size: 12px; }
.topbar .spacer { flex: 1; }
.team-select {
  max-width: 55vw; background: var(--surface); border: 1px solid var(--line); border-radius: 999px;
  padding: 8px 14px; min-height: 40px; font-weight: 600;
}
main { padding: 16px 14px calc(var(--tab-h) + 28px + env(safe-area-inset-bottom)); max-width: 980px; margin: 0 auto; }
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; height: calc(var(--tab-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom); display: flex; background: rgba(7, 19, 14, .94);
  backdrop-filter: blur(10px); border-top: 1px solid var(--line);
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  background: none; border: 0; color: var(--muted); cursor: pointer; font-size: .72rem; letter-spacing: .04em;
  text-transform: uppercase; font-family: var(--font-display); font-weight: 700; min-height: 44px;
}
.tab svg { width: 24px; height: 24px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tab[aria-current="page"] { color: var(--accent); text-shadow: 0 0 12px rgba(0,229,160,.7); }
@media (min-width: 900px) {
  main { margin-left: 220px; max-width: 1100px; padding-bottom: 40px; }
  .tabbar { top: calc(var(--top-h) + env(safe-area-inset-top)); bottom: 0; right: auto; width: 200px; height: auto;
    flex-direction: column; justify-content: flex-start; gap: 6px; padding: 16px 10px; border-top: 0; border-right: 1px solid var(--line); }
  .tab { flex: none; flex-direction: row; justify-content: flex-start; gap: 12px; padding: 12px 14px; border-radius: 12px; font-size: .95rem; }
  .tab[aria-current="page"] { background: var(--surface); box-shadow: var(--glow); }
}

/* ---------- Komponenter ---------- */
.card {
  background: linear-gradient(180deg, var(--surface-2), var(--surface)); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px; margin-bottom: 14px; box-shadow: 0 8px 24px rgba(0,0,0,.35);
}
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 10px; }
.grid { display: grid; gap: 12px; }
@media (min-width: 700px) { .grid.cols-2 { grid-template-columns: 1fr 1fr; } }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px; padding: 0 20px;
  border-radius: 999px; border: 1px solid var(--line); background: var(--surface-2); cursor: pointer;
  font-family: var(--font-display); font-weight: 700; letter-spacing: .08em; text-transform: uppercase; font-size: 1rem;
  transition: transform .15s, box-shadow .2s, background .2s; text-decoration: none; color: var(--text);
}
.btn:hover { box-shadow: 0 0 14px rgba(0,229,160,.25); }
.btn:active { transform: scale(.97); }
.btn.primary { background: linear-gradient(180deg, #19f0b0, #00c98a); color: #04281b; border-color: transparent; box-shadow: var(--glow); }
.btn.gold { background: linear-gradient(180deg, #ffd966, #f0b100); color: #3a2a00; border-color: transparent; }
.btn.danger { border-color: var(--danger); color: var(--danger); background: transparent; }
.btn.ghost { background: transparent; }
.btn.small { min-height: 38px; padding: 0 14px; font-size: .85rem; }
.btn[disabled] { opacity: .45; pointer-events: none; }
.icon-btn { min-width: 44px; min-height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; font-size: 1.2rem; }

label.field { display: block; }
label.field > span { display: block; font-size: .8rem; color: var(--muted); margin-bottom: 4px; text-transform: uppercase; letter-spacing: .08em; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], select {
  width: 100%; min-height: 46px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line); background: #0a1f16;
}
input:focus, select:focus { border-color: var(--accent); box-shadow: var(--glow); outline: none; }
.err { color: var(--danger); font-size: .9rem; min-height: 1.2em; }

.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px; border-radius: 999px; font-size: .78rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; border: 1px solid var(--line); background: var(--surface); }
.chip.open { color: var(--accent); border-color: var(--accent); box-shadow: 0 0 12px rgba(0,229,160,.3); }
.chip.closed { color: var(--gold); border-color: var(--gold); }
.chip.admin { color: var(--gold); border-color: var(--gold); }
.chip.banned { color: var(--danger); border-color: var(--danger); }

/* Billardkugle-avatar */
.ball {
  --c: #d62828; width: 40px; height: 40px; border-radius: 50%; flex: none; position: relative; overflow: hidden; display: inline-block;
  background: radial-gradient(circle at 32% 28%, rgba(255,255,255,.55), transparent 35%), var(--c);
  box-shadow: inset -4px -6px 10px rgba(0,0,0,.45), 0 3px 8px rgba(0,0,0,.5);
}
.ball.stripe { background: radial-gradient(circle at 32% 28%, rgba(255,255,255,.55), transparent 35%), linear-gradient(180deg, #f4f4f4 0 24%, var(--c) 24% 76%, #f4f4f4 76%); }
.ball i {
  position: absolute; left: 50%; top: 50%; width: 52%; height: 52%; transform: translate(-50%, -50%); border-radius: 50%;
  background: #fff; color: #111; font-style: normal; font-weight: 800; display: grid; place-items: center; font-size: .62em; font-family: var(--font-display);
}
.ball.lg { width: 56px; height: 56px; font-size: 20px; }
.ball.sm { width: 28px; height: 28px; font-size: 12px; }

/* Spillerkort i sessionen */
.player {
  display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center; padding: 12px;
  border-radius: 14px; background: rgba(0,0,0,.22); border: 1px solid var(--line);
}
.player.off { opacity: .55; filter: grayscale(.6); }
.player .name { font-weight: 700; }
.player .sub { font-size: .8rem; color: var(--muted); }
.stepper { display: flex; align-items: center; gap: 6px; }
.stepper button { width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2); font-size: 1.4rem; cursor: pointer; }
.stepper input { width: 64px; text-align: center; font-family: var(--font-display); font-size: 1.5rem; font-weight: 700; padding: 0; }
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: .8rem; color: var(--muted); min-height: 44px; }
.switch input { appearance: none; width: 46px; height: 26px; border-radius: 999px; background: #20382e; position: relative; cursor: pointer; transition: background .2s; border: 1px solid var(--line); }
.switch input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .2s; }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(20px); }

/* Tabeller */
.table-wrap { overflow-x: auto; border-radius: 14px; border: 1px solid var(--line); }
table { width: 100%; border-collapse: collapse; font-size: .95rem; }
th { position: sticky; top: 0; background: #0b2218; font-family: var(--font-display); text-transform: uppercase; letter-spacing: .06em; font-size: .8rem; color: var(--muted); text-align: left; white-space: nowrap; }
th, td { padding: 12px 12px; border-bottom: 1px solid var(--line); }
td.n, th.n { text-align: right; font-family: var(--font-display); font-variant-numeric: tabular-nums; font-weight: 700; font-size: 1.05rem; }
tbody tr.drill { cursor: pointer; transition: background .15s; }
tbody tr.drill:hover { background: rgba(0,229,160,.08); }
tbody tr:last-child td { border-bottom: 0; }
td.best { color: var(--gold); text-shadow: 0 0 10px rgba(255,200,61,.5); }
td.first-col, th.first-col { position: sticky; left: 0; background: #0c241a; z-index: 1; }
.go { color: var(--accent); font-size: 1.2rem; }
.hint { font-size: .8rem; color: var(--muted); margin: 6px 2px 0; }

.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 12px; font-family: var(--font-display); text-transform: uppercase; letter-spacing: .06em; }
.crumbs button { background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit; text-transform: inherit; padding: 8px 4px; min-height: 40px; }
.crumbs span { color: var(--muted); }

.seg { display: flex; gap: 4px; padding: 4px; background: #0a1f16; border: 1px solid var(--line); border-radius: 999px; margin-bottom: 14px; }
.seg button { flex: 1; min-height: 40px; border: 0; border-radius: 999px; background: none; color: var(--muted); cursor: pointer; font-family: var(--font-display); font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.seg button[aria-pressed="true"] { background: var(--accent); color: #04281b; box-shadow: var(--glow); }

/* Podium */
.podium { display: flex; align-items: flex-end; justify-content: center; gap: 10px; margin: 8px 0 16px; min-height: 190px; }
.podium .slot { flex: 1; max-width: 170px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.podium .block {
  width: 100%; border-radius: 12px 12px 0 0; display: grid; place-items: start center; padding-top: 8px; font-size: 1.9rem;
  background: linear-gradient(180deg, var(--surface-2), var(--surface)); border: 1px solid var(--line); border-bottom: 0;
  transform-origin: bottom; animation: rise .7s cubic-bezier(.2,.9,.3,1.2) both;
}
.slot.p1 .block { height: 110px; border-color: var(--gold); box-shadow: 0 0 24px rgba(255,200,61,.35); color: var(--gold); }
.slot.p2 .block { height: 80px; color: var(--silver); }
.slot.p3 .block { height: 60px; color: var(--bronze); }
.slot .pname { font-weight: 700; font-size: .9rem; overflow-wrap: anywhere; }
.slot.p1 .ball { box-shadow: 0 0 22px rgba(255,200,61,.8), inset -4px -6px 10px rgba(0,0,0,.45); animation: pulse 2s infinite; }
.crown { font-size: 1.3rem; }
@keyframes rise { from { transform: scaleY(.1); opacity: 0; } }
@keyframes pulse { 50% { box-shadow: 0 0 34px rgba(255,200,61,1), inset -4px -6px 10px rgba(0,0,0,.45); } }

/* Turnering */
.match { display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; align-items: center; padding: 10px; border-radius: 14px; background: rgba(0,0,0,.22); border: 1px solid var(--line); }
.match .side { display: flex; align-items: center; gap: 8px; min-width: 0; }
.match .side.right { flex-direction: row-reverse; text-align: right; }
.match .pn { font-weight: 700; overflow: hidden; text-overflow: ellipsis; }
.match .score { display: flex; align-items: center; gap: 4px; }
.match .score input { width: 54px; text-align: center; padding: 0; font-family: var(--font-display); font-weight: 700; font-size: 1.2rem; }
.starter { font-size: .7rem; color: var(--gold); text-transform: uppercase; letter-spacing: .08em; display: block; }
.match.done { border-color: rgba(0,229,160,.5); }

/* Tomme tilstande, skeleton */
.empty { text-align: center; padding: 36px 16px; }
.empty .ball { width: 84px; height: 84px; font-size: 32px; margin-bottom: 12px; }
.skel { height: 64px; border-radius: 14px; background: linear-gradient(90deg, var(--surface) 25%, var(--surface-2) 50%, var(--surface) 75%); background-size: 200% 100%; animation: shimmer 1.4s infinite; margin-bottom: 10px; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* Auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; position: relative; z-index: 1; }
.auth .card { width: 100%; max-width: 420px; }
.auth .brand { text-align: center; margin-bottom: 14px; }
.auth .brand .ball { width: 84px; height: 84px; font-size: 32px; margin-bottom: 8px; animation: roll 1.2s cubic-bezier(.2,.8,.2,1) both; }
@keyframes roll { from { transform: translateX(-120px) rotate(-540deg); opacity: 0; } }

/* Dialog + toast */
dialog { border: 1px solid var(--accent); border-radius: 20px; background: var(--surface); color: var(--text); max-width: min(92vw, 440px); width: 100%; padding: 20px; box-shadow: var(--glow); }
dialog::backdrop { background: rgba(0,0,0,.7); backdrop-filter: blur(3px); }
dialog.danger { border-color: var(--danger); box-shadow: 0 0 20px rgba(255,77,109,.35); }
#toasts { position: fixed; left: 0; right: 0; bottom: calc(var(--tab-h) + 16px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 50; pointer-events: none; }
.toast { background: #0b2218; border: 1px solid var(--accent); border-radius: 12px; padding: 10px 16px; box-shadow: var(--glow); animation: toast .25s ease-out; max-width: 90vw; }
.toast.error { border-color: var(--danger); color: var(--danger); box-shadow: 0 0 16px rgba(255,77,109,.35); }
@keyframes toast { from { transform: translateY(12px); opacity: 0; } }

.offline-bar { background: #3a2a00; color: var(--gold); text-align: center; padding: 6px; font-size: .85rem; position: relative; z-index: 21; }
.confetti { position: fixed; top: -12px; width: 8px; height: 14px; z-index: 60; pointer-events: none; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); opacity: .9; } }
canvas.chart { width: 100%; height: 240px; display: block; }
.legend { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 8px; font-size: .8rem; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
  .confetti { display: none; }
}
