/* Poengblokka. Themes are custom properties on <html data-theme>; everything
   else reads only the variables. Hytte (cabin) is the default. */

@font-face {
  font-family: "Fredoka";
  font-weight: 300 700;
  font-display: swap;
  src: url(/fonts/fredoka-latin-ext.woff2) format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Fredoka";
  font-weight: 300 700;
  font-display: swap;
  src: url(/fonts/fredoka-latin.woff2) format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* --- Themes ------------------------------------------------------------------ */

:root,
[data-theme="hytte"] {
  color-scheme: light;
  /* Dark pine boards behind a cream score pad, wool red and pine green. */
  --bg: #3a2416;
  --bg-image:
    repeating-linear-gradient(90deg, rgb(0 0 0 / .18) 0 2px, transparent 2px 92px),
    repeating-linear-gradient(90deg, rgb(255 255 255 / .025) 0 1px, transparent 1px 7px, rgb(0 0 0 / .03) 7px 9px, transparent 9px 23px),
    linear-gradient(180deg, #4a2e1c, #2f1d12);
  --bar: #3b2417;
  --bar-ink: #f8ecd4;
  --paper: #fbf3e2;
  --paper-head: #f3e4c4;
  --paper-alt: #f6ead2;
  --ink: #3a2618;
  --muted: #6f5641;
  --line: #e2cfa8;
  --margin: #d98b7f;
  --accent: #a8322a;
  --accent-ink: #fff6ea;
  --accent-2: #2f5a45;
  --accent-2-ink: #ffffff;
  --warn: #f2b84b;
  --gold: #e9a53a;
  --lead: #fde6b2;
  --hit: #2f7a4f;
  --miss: #b0483c;
  --chip: #efe1c3;
  --chip-ink: #3a2618;
  --shadow: 0 2px 0 rgb(0 0 0 / .08), 0 10px 24px rgb(20 8 0 / .28);
  --on-bg: #f8ecd4;
  --on-bg-muted: #d7bf9c;
  --knit-a: #a8322a;
  --knit-b: #f8ecd4;
  --knit-c: #2f5a45;
}

[data-theme="lys"] {
  color-scheme: light;
  --bg: #eef1f4;
  --bg-image: none;
  --bar: #ffffff;
  --bar-ink: #1d2733;
  --paper: #ffffff;
  --paper-head: #f4f6f9;
  --paper-alt: #f8f9fb;
  --ink: #1d2733;
  --muted: #6b7684;
  --line: #e1e6ec;
  --margin: #e1e6ec;
  --accent: #2563eb;
  --accent-ink: #ffffff;
  --accent-2: #0f766e;
  --accent-2-ink: #ffffff;
  --warn: #b45309;
  --gold: #f2b01e;
  --lead: #fff4d1;
  --hit: #15803d;
  --miss: #c2410c;
  --chip: #eef1f5;
  --chip-ink: #1d2733;
  --shadow: 0 1px 2px rgb(15 23 42 / .06), 0 6px 18px rgb(15 23 42 / .08);
  --on-bg: #1d2733;
  --on-bg-muted: #4f5a67;
  --knit-a: #2563eb;
  --knit-b: #ffffff;
  --knit-c: #93b4f5;
}

[data-theme="mork"] {
  color-scheme: dark;
  --bg: #121417;
  --bg-image: none;
  --bar: #1a1d21;
  --bar-ink: #ece8e1;
  --paper: #1e2226;
  --paper-head: #262b30;
  --paper-alt: #22262b;
  --ink: #ece8e1;
  --muted: #9aa1a9;
  --line: #31373e;
  --margin: #4a3a36;
  --accent: #e0675a;
  --accent-ink: #1a0d0a;
  --accent-2: #6cbf95;
  --accent-2-ink: #0d2318;
  --warn: #f0b64f;
  --gold: #f0b64f;
  --lead: #3b3220;
  --hit: #6cbf95;
  --miss: #ef8a7d;
  --chip: #2b3036;
  --chip-ink: #ece8e1;
  --shadow: 0 8px 24px rgb(0 0 0 / .45);
  --on-bg: #ece8e1;
  --on-bg-muted: #9aa1a9;
  --knit-a: #e0675a;
  --knit-b: #2b3036;
  --knit-c: #6cbf95;
}

[data-theme="cozy"] {
  color-scheme: light;
  /* Kos: a snowy evening in, hot chocolate, heart waffles with jam, skis by
     the door. Cocoa night with falling snow, whipped-cream paper, a golden
     waffle grid, lingonberry red and ski blue. */
  --bg: #2a1812;
  --bg-image:
    radial-gradient(circle at 20% 30%, rgb(255 244 230 / .55) 0 1.6px, transparent 2.2px) 0 0 / 90px 90px,
    radial-gradient(circle at 70% 65%, rgb(255 244 230 / .35) 0 1.1px, transparent 1.6px) 0 0 / 57px 57px,
    radial-gradient(circle at 40% 85%, rgb(255 244 230 / .25) 0 2.2px, transparent 2.8px) 0 0 / 133px 133px,
    linear-gradient(180deg, #43271c, #24140f);
  --bar: #3d2319;
  --bar-ink: #fff4e6;
  --paper: #fffaf3;
  --paper-head: #f6dfae;
  --paper-alt: #fdf1df;
  --ink: #3b2219;
  --muted: #6b4a3a;
  --line: #ecd3a8;
  --margin: #d77f73;
  --accent: #b3263a;
  --accent-ink: #fff8f0;
  --accent-2: #1f4e8c;
  --accent-2-ink: #ffffff;
  --warn: #f4c25b;
  --gold: #e9a83a;
  --lead: #fde4b0;
  --hit: #2f7a4f;
  --miss: #b3263a;
  --chip: #f3e3c7;
  --chip-ink: #3b2219;
  --shadow: 0 2px 0 rgb(0 0 0 / .06), 0 12px 28px rgb(20 6 0 / .35);
  --on-bg: #fff4e6;
  --on-bg-muted: #e6cfb2;
  --knit-a: #e9b44c;
  --knit-b: #b9802a;
  --knit-c: #b3263a;
  --waffle:
    linear-gradient(90deg, rgb(185 128 42 / .32) 2px, transparent 2px) 0 0 / 12px 12px,
    linear-gradient(rgb(185 128 42 / .32) 2px, transparent 2px) 0 0 / 12px 12px;
}

[data-theme="kontrast"] {
  color-scheme: dark;
  --bg: #000;
  --bg-image: none;
  --bar: #000;
  --bar-ink: #fff;
  --paper: #000;
  --paper-head: #000;
  --paper-alt: #111;
  --ink: #fff;
  --muted: #e0e0e0;
  --line: #fff;
  --margin: #fff;
  --accent: #ffe600;
  --accent-ink: #000;
  --accent-2: #00e5ff;
  --accent-2-ink: #000000;
  --warn: #ffe600;
  --gold: #ffe600;
  --lead: #2a2600;
  --hit: #5dff8f;
  --miss: #ff8c8c;
  --chip: #000;
  --chip-ink: #fff;
  --shadow: none;
  --on-bg: #fff;
  --on-bg-muted: #e0e0e0;
  --knit-a: #ffe600;
  --knit-b: #000;
  --knit-c: #fff;
}
[data-theme="kontrast"] .card,
[data-theme="kontrast"] .btn,
[data-theme="kontrast"] .chip,
[data-theme="kontrast"] .nchip,
[data-theme="kontrast"] .pchip,
[data-theme="kontrast"] .dlg,
[data-theme="kontrast"] .sheet { outline: 2px solid #fff; outline-offset: -2px; }

/* --- Base --------------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  font-family: "Fredoka", ui-rounded, system-ui, sans-serif;
  font-size: 17px;
  line-height: 1.4;
  color: var(--on-bg);
  background: var(--bg-image), var(--bg);
  background-attachment: fixed;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3, h4 { margin: 0; font-weight: 600; line-height: 1.2; }
h2 { font-size: 1.05rem; margin-bottom: .5rem; color: var(--on-bg); }
a { color: inherit; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; justify-content: center; }
.icon { width: 1.25em; height: 1.25em; flex: none; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; box-shadow: 0 0 0 5px var(--gold); }

.page { max-width: 640px; margin: 0 auto; padding: 1rem 1rem calc(6rem + env(safe-area-inset-bottom)); }
.page section > h2 .muted { color: var(--on-bg-muted); font-weight: 400; }
.stack { display: flex; flex-direction: column; gap: 1.25rem; }
.stack.tight { gap: .6rem; }
.row { display: flex; gap: .6rem; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; }

/* --- Bars ------------------------------------------------------------------------- */

.bar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: .4rem;
  padding: calc(.4rem + env(safe-area-inset-top)) .5rem .4rem;
  background: var(--bar); color: var(--bar-ink);
  box-shadow: 0 1px 0 rgb(0 0 0 / .15);
}
.bar h1 { flex: 1; font-size: 1.15rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* Knitted band under the bar: the cabin's sweater pattern. */
[data-theme="hytte"] .bar::after, [data-theme="hytte"] .hero::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -8px; height: 8px;
  background:
    linear-gradient(135deg, var(--knit-a) 25%, transparent 25%) -4px 0 / 8px 8px,
    linear-gradient(225deg, var(--knit-a) 25%, transparent 25%) -4px 0 / 8px 8px,
    var(--knit-b);
  pointer-events: none;
}

.icon-btn {
  display: inline-grid; place-items: center;
  width: 2.75rem; height: 2.75rem; flex: none;
  border: 0; border-radius: 50%; background: transparent; color: inherit;
  text-decoration: none;
}
.icon-btn:hover { background: rgb(127 127 127 / .14); }
.icon-btn.small { width: 2.75rem; height: 2.75rem; }
.icon-btn:disabled { opacity: .25; cursor: default; background: none; }

.status-chip, .conn-dot {
  display: inline-flex; align-items: center; gap: .4rem;
  border: 0; border-radius: 99px; padding: .3rem .7rem;
  background: rgb(127 127 127 / .18); color: inherit;
  font-size: .85rem; font-weight: 600; letter-spacing: .08em;
}
.conn-dot { letter-spacing: 0; font-weight: 500; }
.dot, .conn-dot::before { content: ""; width: .6rem; height: .6rem; border-radius: 50%; background: #9a9a9a; flex: none; }
.conn-dot .dot { display: none; }
.status-online .dot, .status-online.conn-dot::before { background: #3fbf6f; box-shadow: 0 0 0 3px rgb(63 191 111 / .25); }
.status-connecting .dot, .status-connecting.conn-dot::before { background: var(--gold); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .3; } }

/* --- Home ------------------------------------------------------------------------- */

.hero {
  position: relative;
  padding: calc(.5rem + env(safe-area-inset-top)) 1rem 2rem;
  background: var(--bar); color: var(--bar-ink);
  text-align: center;
}
.hero-top { display: flex; justify-content: space-between; }
.hero h1 { font-size: clamp(2.2rem, 9vw, 3.2rem); font-weight: 700; letter-spacing: .01em; margin-top: .25rem; }
.hero p { opacity: .8; }
[data-theme="hytte"] .hero h1 { text-shadow: 0 0 24px rgb(233 165 58 / .45); }

/* --- Cards, buttons, chips -------------------------------------------------------------- */

.card {
  display: block;
  background: var(--paper); color: var(--ink);
  border-radius: 18px; padding: 1rem 1.1rem;
  box-shadow: var(--shadow);
  text-decoration: none;
}
.card h2 { color: var(--ink); }
a.card:active { transform: scale(.99); }
.session-card { display: flex; flex-direction: column; gap: .2rem; }
.session-date { font-weight: 600; font-size: 1.1rem; }
.session-meta { color: var(--muted); }
.badge { display: inline-block; font-size: .72rem; font-weight: 600; padding: .1rem .5rem; border-radius: 99px; background: var(--accent-2); color: var(--accent-2-ink); vertical-align: middle; letter-spacing: .03em; }
.game-card { display: grid; gap: .15rem; }
.game-card-top { display: flex; justify-content: space-between; gap: .5rem; }
.game-card-players { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.game-card.done { opacity: .85; }
.join .hint { margin-top: .5rem; color: var(--muted); font-size: .9rem; }
.code-input {
  flex: 1; min-width: 0;
  font-size: 1.4rem; font-weight: 600; letter-spacing: .3em; text-transform: uppercase; text-align: center;
  padding: .55rem .5rem; border-radius: 14px; border: 2px solid var(--line); background: var(--paper-alt); color: var(--ink);
}
.empty { text-align: center; color: var(--on-bg-muted); padding: 2rem 1rem; }
.notice { background: var(--lead); color: var(--ink); padding: .8rem 1rem; border-radius: 14px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  min-height: 2.9rem; padding: .55rem 1.15rem;
  border: 0; border-radius: 99px;
  background: var(--chip); color: var(--chip-ink);
  font-weight: 600; text-decoration: none; white-space: nowrap;
  box-shadow: 0 2px 0 rgb(0 0 0 / .12);
  transition: transform .12s, filter .12s;
}
.btn:active { transform: translateY(1px) scale(.98); }
.btn:hover { filter: brightness(1.04); }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.big { min-height: 3.4rem; font-size: 1.1rem; padding-inline: 1.5rem; }
.btn.danger { color: var(--miss); }
.btn:disabled, .btn.is-disabled {
  background: transparent; color: var(--muted); box-shadow: inset 0 0 0 2px var(--line);
  cursor: default; transform: none; filter: none;
}
.action-bar .btn:disabled { color: var(--on-bg-muted); box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--on-bg-muted) 50%, transparent); }
.link { background: none; border: 0; padding: .5rem; text-decoration: underline; color: var(--on-bg-muted); }
.link.danger { color: var(--on-bg-muted); }
.link.code { color: inherit; font-weight: 600; letter-spacing: .12em; padding: 0; }

.chips { display: flex; flex-wrap: wrap; gap: .45rem; margin-top: .7rem; }
.chip {
  border: 0; border-radius: 99px; padding: .45rem .85rem;
  background: var(--chip); color: var(--chip-ink); font-weight: 500;
  display: inline-flex; align-items: center; gap: .3rem;
}
.page .chip { background: color-mix(in srgb, var(--paper) 88%, transparent); }
.chip.removable .icon { width: .9em; height: .9em; opacity: .6; }

.segmented { display: inline-flex; flex-wrap: wrap; background: var(--chip); border-radius: 99px; padding: 3px; gap: 2px; }
.segmented button { border: 0; background: none; border-radius: 99px; padding: .4rem .85rem; min-height: 2.75rem; color: var(--chip-ink); font-weight: 500; }
.segmented button.on { background: var(--accent); color: var(--accent-ink); }

.switch {
  appearance: none; width: 3rem; height: 1.75rem; border-radius: 99px; flex: none;
  background: var(--line); position: relative; cursor: pointer; transition: background .2s; margin: 0;
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: calc(1.75rem - 6px); aspect-ratio: 1;
  border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgb(0 0 0 / .3); transition: transform .2s;
}
.switch:checked { background: var(--accent-2); }
.switch:checked::after { transform: translateX(1.25rem); }
.switch-row, .field-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; min-height: 2.75rem; }
.field-row .num { width: 5.5rem; }
.num {
  padding: .45rem .6rem; border-radius: 12px; border: 2px solid var(--line);
  background: var(--paper-alt); color: var(--ink); text-align: center; font-size: 1.1rem; font-weight: 600;
}

/* --- New game -------------------------------------------------------------------------- */

.text-input {
  width: 100%; padding: .7rem 1rem; border-radius: 99px; border: 2px solid var(--line);
  background: var(--paper); color: var(--ink); font-size: 1.1rem; font-weight: 600;
}
.text-input::placeholder { color: var(--muted); font-weight: 400; font-style: italic; opacity: .75; }
.presets { display: flex; flex-wrap: wrap; gap: .45rem; margin-bottom: .7rem; }
.preset {
  border: 0; border-radius: 99px; padding: .55rem 1.1rem;
  background: color-mix(in srgb, var(--paper) 88%, transparent); color: var(--ink); font-weight: 600;
}
.preset.on { background: var(--accent); color: var(--accent-ink); }
.preset.own { cursor: default; }
.rules-card { display: grid; gap: .6rem; }
.rules-summary { margin: 0; padding-left: 1.2rem; display: grid; gap: .2rem; }
.dlg .rules-summary { color: var(--ink); }
.rules-editor summary { cursor: pointer; font-weight: 600; color: var(--accent); padding: .3rem 0; }
.rule-group { display: grid; gap: .25rem; padding: .7rem 0; border-top: 1px dashed var(--line); }
.rule-group:first-of-type { border-top: 0; }
.field-col { display: grid; gap: .35rem; padding: .2rem 0; }
.switch-row span small, .field-row span small { display: block; font-size: .8rem; }

.seats { list-style: none; margin: 0 0 .6rem; padding: 0; display: grid; gap: .4rem; }
.seats li {
  display: flex; align-items: center; gap: .3rem;
  background: var(--paper); color: var(--ink); border-radius: 14px; padding: .25rem .25rem .25rem .7rem;
  box-shadow: var(--shadow);
}
.seat-no { width: 1.4rem; color: var(--muted); font-size: .9rem; }
.seat-name { flex: 1; font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dealer-btn {
  border: 0; background: none; color: var(--muted); border-radius: 99px; padding: 0 .7rem; font-size: .8rem; font-weight: 600;
  min-height: 2.75rem; display: inline-flex; align-items: center;
  box-shadow: inset 0 0 0 2px var(--line);
}
.dealer-btn.on { background: var(--gold); color: #3a2618; box-shadow: none; }
.add-player { display: flex; gap: .5rem; }
.combo { position: relative; flex: 1; }
.combo input {
  width: 100%; padding: .7rem 1rem; border-radius: 99px; border: 2px solid var(--line);
  background: var(--paper); color: var(--ink); font-size: 1.05rem;
}
.suggest {
  position: absolute; z-index: 20; left: 0; right: 0; top: calc(100% + 4px);
  list-style: none; margin: 0; padding: .3rem; border-radius: 16px;
  background: var(--paper); color: var(--ink); box-shadow: var(--shadow);
}
.suggest li { padding: .6rem .8rem; border-radius: 12px; cursor: pointer; }
.suggest li.active, .suggest li:hover { background: var(--chip); }
.hint { color: var(--on-bg-muted); }
.hint.warn { margin-top: .6rem; color: var(--warn); font-weight: 500; }
.seat-hint { font-size: .9rem; margin: -.2rem 0 .6rem; }

.action-bar {
  position: sticky; bottom: 0; z-index: 10;
  display: flex; gap: 1rem; align-items: center;
  padding: .7rem 1rem calc(.7rem + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bar) 92%, transparent);
  backdrop-filter: blur(8px);
}
body[data-view="new"] .action-bar { position: fixed; left: 0; right: 0; }
body[data-view="new"] .action-bar .btn { flex: 1; max-width: 608px; margin: 0 auto; }

/* --- Game table --------------------------------------------------------------------------- */

body[data-view="game"] #view { height: 100dvh; display: flex; flex-direction: column; }
body[data-view="game"] .bar::after { display: none; }
.game-info {
  padding: .5rem 1rem; background: var(--bar); color: var(--bar-ink); font-size: .95rem;
  border-top: 1px solid rgb(255 255 255 / .06);
}
.game-info strong { font-weight: 600; }
[data-theme="hytte"] .game-info {
  padding-bottom: calc(.5rem + 6px);
  background:
    linear-gradient(135deg, var(--knit-a) 25%, transparent 25%) -4px 100% / 8px 6px repeat-x,
    linear-gradient(225deg, var(--knit-a) 25%, transparent 25%) -4px 100% / 8px 6px repeat-x,
    linear-gradient(var(--knit-b), var(--knit-b)) 0 100% / 100% 6px no-repeat,
    var(--bar);
}
.info-line.sub { opacity: .9; font-size: .9em; }
.bal.over { color: #ffb4a8; }
.bal.under { color: #b7e4c7; }
.bal.even { color: var(--gold); }
[data-theme="lys"] .bal.over { color: var(--miss); }
[data-theme="lys"] .bal.under { color: var(--hit); }
.winner { font-size: 1.1rem; font-weight: 600; }

/* The scroller is the only scrolling box in the game view, so sticky
   header/footer/first column stick to it in both directions. */
.table-wrap { position: relative; flex: 1; min-height: 0; display: flex; }
.table-scroll {
  flex: 1; min-height: 0; overflow: auto; overscroll-behavior: contain;
  background: var(--paper);
}
.table-wrap::after {
  content: ""; position: absolute; top: 0; bottom: 0; right: 0; width: 1.5rem; pointer-events: none;
  background: linear-gradient(90deg, transparent, rgb(0 0 0 / .18)); opacity: 0; transition: opacity .2s;
}
.table-wrap.more-right::after { opacity: 1; }
table.score {
  border-collapse: separate; border-spacing: 0;
  min-width: 100%; min-height: 100%; font-size: 1rem; color: var(--ink); background: var(--paper);
  font-variant-numeric: tabular-nums;
}
.score th, .score td {
  padding: .35em .4em; text-align: center; white-space: nowrap;
  border-bottom: 1px solid var(--line);
  min-width: 4.4em;
}
.score thead th {
  position: sticky; top: 0; z-index: 2;
  background: var(--paper-head); font-weight: 600; padding-block: .55em;
  max-width: 8em; border-bottom: 2px solid var(--line);
}
.score .pn { display: block; overflow: hidden; text-overflow: ellipsis; }
.score thead th.lead { box-shadow: inset 0 -4px 0 var(--gold); }
.score tfoot th, .score tfoot td {
  position: sticky; bottom: 0; z-index: 2;
  background: var(--paper-head); border-top: 2px solid var(--line); border-bottom: 0;
  padding-block: .5em;
}
.score .rn, .score .corner {
  position: sticky; left: 0; z-index: 1;
  min-width: 2.6em; width: 2.6em;
  background: var(--paper-head); color: var(--muted); font-weight: 500;
  border-right: 2px solid var(--margin); /* the red margin line of a pad */
}
.score thead .corner, .score tfoot .corner { z-index: 3; }
.score tbody tr:nth-child(even) td { background: var(--paper-alt); }
.score tbody tr[data-rid] { cursor: pointer; }
.score tbody tr[data-rid]:hover td { background: var(--lead); }
.score td .v { display: block; font-size: 1.2em; font-weight: 600; line-height: 1.15; }
.score td .sub { display: block; font-size: .8em; color: var(--muted); line-height: 1.15; font-weight: 500; }
.score td.hit .sub { color: var(--hit); font-weight: 600; }
.score td.miss .sub { color: var(--miss); font-weight: 600; }
.score td.neg .v { color: var(--miss); }
.score .pending-row td { font-style: italic; }
.score .pending-row td .sub { font-size: .9em; color: var(--accent-2); font-weight: 600; }
.score .role { font-weight: 600; color: var(--accent-2); }
.score tfoot td .v { font-size: 1.35em; font-weight: 700; display: inline; }
.score tfoot td.lead { background: var(--lead); }
.score .empty-row td { padding: 2em 1em; color: var(--muted); font-style: italic; }
.rank {
  display: inline-grid; place-items: center; width: 1.3em; height: 1.3em; margin-left: .25em;
  border-radius: 50%; font-size: .72em; font-weight: 700; vertical-align: .2em;
  background: var(--chip); color: var(--muted);
}
.rank.r1 { background: var(--gold); color: #3a2618; box-shadow: 0 0 10px rgb(233 165 58 / .7); }
.score tbody tr.filler td { height: 100%; padding: 0; border: 0; background: var(--paper) !important; }
.score tbody tr.filler:hover td { background: var(--paper); }
@media (max-width: 400px) {
  .score th, .score td { min-width: 3.6em; padding-inline: .25em; }
}
.deal-mark { display: inline-flex; vertical-align: -.15em; color: var(--accent); }
.deal-mark .icon { width: 1em; height: 1em; }
.score thead th.dealer .pn { display: inline-block; max-width: 6rem; vertical-align: bottom; }

/* --- Dialogs ------------------------------------------------------------------------------------ */

dialog { border: 0; padding: 0; color: var(--ink); background: var(--paper); }
dialog::backdrop { background: rgb(15 8 4 / .55); backdrop-filter: blur(2px); }
.dlg {
  width: min(440px, calc(100% - 1.5rem)); max-height: calc(100dvh - 2rem);
  border-radius: 22px; box-shadow: var(--shadow);
}
.dlg-inner { padding: 1rem 1.2rem 1.4rem; display: flex; flex-direction: column; gap: 1rem; }
.dlg-head { display: flex; align-items: center; justify-content: space-between; margin-right: -.5rem; }
.dlg-head h2 { margin: 0; color: var(--ink); font-size: 1.25rem; }
.dlg h3 { font-size: .95rem; color: var(--muted); font-weight: 500; margin-bottom: .45rem; }
.dlg h4 { font-size: .95rem; margin: .7rem 0 .3rem; }
.dlg section { display: flex; flex-direction: column; }
.dlg .segmented { align-self: flex-start; }
.dlg .chip { background: var(--chip); }
.menu { display: grid; }
.menu-item {
  display: flex; align-items: center; gap: .8rem; padding: .8rem .5rem;
  border: 0; background: none; text-align: left; border-radius: 12px; font-weight: 500;
}
.menu-item:hover { background: var(--chip); }
.menu-item.danger { color: var(--miss); }
.themes { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: .25rem; }
.theme-swatch {
  border: 2px solid transparent; background: none; border-radius: 14px; padding: .35rem .2rem;
  display: flex; flex-direction: column; align-items: center; gap: .3rem; font-size: .78rem; text-align: center; line-height: 1.15; min-height: 2.75rem;
}
.theme-swatch.on { border-color: var(--accent); }
.sw { width: 2.4rem; height: 2.4rem; border-radius: 50%; box-shadow: inset 0 0 0 2px rgb(0 0 0 / .15); }
.sw-hytte { background: linear-gradient(135deg, #4a2e1c 0 45%, #fbf3e2 45% 70%, #a8322a 70%); }
.sw-lys { background: linear-gradient(135deg, #eef1f4 0 45%, #fff 45% 70%, #2563eb 70%); }
.sw-mork { background: linear-gradient(135deg, #121417 0 45%, #1e2226 45% 70%, #e0675a 70%); }
.sw-kontrast { background: linear-gradient(135deg, #000 0 55%, #ffe600 55%); }
.devices { list-style: none; padding: 0; margin: 0; display: grid; gap: .35rem; }
.devices li { display: flex; align-items: center; gap: .5rem; }
.devices li > span:first-of-type { flex: 1; }
.conn-status { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; margin-bottom: .5rem; }
.share { align-items: stretch; }
.share .qr { width: min(100%, 300px); margin: 0 auto; border-radius: 12px; box-shadow: 0 0 0 1px var(--line); }
.big-code { text-align: center; font-size: 2.2rem; font-weight: 700; letter-spacing: .25em; padding-left: .25em; }

/* Round entry: a bottom sheet on phones, a centered card on wide screens. */
.sheet {
  width: 100%; max-width: 560px; max-height: 92dvh;
  margin: auto auto 0; border-radius: 22px 22px 0 0;
  box-shadow: 0 -10px 40px rgb(0 0 0 / .35);
}
.sheet[open] { animation: rise .22s ease-out; }
@keyframes rise { from { transform: translateY(30px); opacity: .5; } }
@media (min-width: 700px) and (min-height: 600px) {
  .sheet { margin: auto; border-radius: 22px; }
}
.sheet-inner { display: flex; flex-direction: column; max-height: 92dvh; }
.sheet-head { display: flex; justify-content: space-between; align-items: flex-start; padding: 1rem 1rem .5rem 1.2rem; }
.sheet-head h2 { color: var(--ink); font-size: 1.35rem; margin: 0; }
.sheet-body { overflow: auto; padding: 0 1.2rem 1rem; flex: 1; min-height: 0; overscroll-behavior: contain; }
.sheet-body h3 { font-size: .95rem; color: var(--muted); font-weight: 500; margin: .8rem 0 .4rem; }
.sheet-foot {
  padding: .7rem 1.2rem calc(.9rem + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line); display: grid; gap: .55rem;
}
.summary { font-size: .95rem; min-height: 1.3em; }
.summary .warn { color: var(--miss); font-weight: 500; }
.summary .bal.over { color: var(--miss); }
.summary .bal.under { color: var(--hit); }
.summary .bal.even { color: var(--accent-2); font-weight: 600; }
.contract-line { font-weight: 600; margin-top: .3rem; }
.entry-list { display: grid; gap: .35rem; }
.entry { display: flex; align-items: center; justify-content: space-between; gap: .6rem; padding: .3rem 0; border-bottom: 1px dashed var(--line); }
.entry.col { flex-direction: column; align-items: stretch; gap: .35rem; }
.entry:last-child { border-bottom: 0; }
.pl { font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview { font-weight: 600; margin-left: .3rem; }
.preview.pos { color: var(--hit); }
.preview.neg { color: var(--miss); }
.nchips { display: grid; grid-template-columns: repeat(var(--cols, 7), minmax(0, 1fr)); gap: .3rem; padding: 2px; }
.entry:not(.col) .nchips { grid-template-columns: repeat(var(--cols), 2.75rem); }
.nchip {
  min-width: 0; height: 2.75rem; border-radius: 99px;
  border: 0; background: var(--chip); color: var(--chip-ink); font-weight: 600; font-size: 1.1rem;
  transition: transform .1s;
}
.nchip.on { background: var(--accent); color: var(--accent-ink); transform: scale(1.06); }
/* Pre-filled from the bid, not yet confirmed by a tap. */
.nchip.on.pre { background: var(--chip); color: var(--accent); box-shadow: inset 0 0 0 3px var(--accent); transform: none; }
.entry { scroll-margin: 4rem; border-radius: 12px; }
.entry.next { box-shadow: inset 4px 0 0 var(--accent-2); padding-left: .6rem; }
.entry.missing { box-shadow: inset 4px 0 0 var(--miss); background: color-mix(in srgb, var(--miss) 8%, transparent); padding-left: .6rem; }
.pl { display: flex; align-items: baseline; gap: .35rem; flex-wrap: wrap; }
.pl-name { overflow: hidden; text-overflow: ellipsis; }
.tot { font-size: .8rem; font-weight: 500; color: var(--muted); }
.bidref { font-weight: 500; }
.tabs { display: flex; margin-bottom: .6rem; }
.tabs button { flex: 1; }
.okline { color: var(--hit); font-weight: 600; }
.link.inline { padding: 0 .2rem; color: var(--accent); font-weight: 600; }
#both-at-once { margin-top: .5rem; color: var(--accent); }
.num.invalid { border-color: var(--miss); background: color-mix(in srgb, var(--miss) 10%, var(--paper-alt)); }
.pchips { display: flex; flex-wrap: wrap; gap: .4rem; }
.pchip { border: 0; border-radius: 99px; padding: .55rem 1rem; min-height: 2.75rem; background: var(--chip); color: var(--chip-ink); font-weight: 600; }
.pchip.on { background: var(--accent); color: var(--accent-ink); }
.stepper { display: flex; align-items: center; gap: .3rem; flex: none; }
.stepper .num { width: 4.6rem; }
.step { width: 2.75rem; height: 2.75rem; border-radius: 50%; border: 0; background: var(--chip); color: var(--chip-ink); font-size: 1.2rem; font-weight: 600; }

.toast {
  position: fixed; left: 50%; bottom: calc(5.5rem + env(safe-area-inset-bottom)); transform: translateX(-50%);
  z-index: 100; display: flex; gap: 1rem; align-items: center;
  padding: .4rem .5rem .4rem 1.1rem; border-radius: 99px; width: max-content; max-width: calc(100% - 2rem);
  background: #1f1a17; color: #fff; box-shadow: 0 8px 24px rgb(0 0 0 / .35);
}
.toast button { border: 0; background: rgb(255 255 255 / .1); color: var(--gold); font-weight: 700; min-height: 2.75rem; padding: 0 1rem; border-radius: 99px; }
.toast span { padding-block: .4rem; }

/* --- Dashboard ------------------------------------------------------------------------------------ */

body[data-view="dash"] { overflow: hidden; }
.dash {
  height: 100dvh; display: flex; flex-direction: column; gap: 1rem;
  padding: calc(1rem + env(safe-area-inset-top)) clamp(1rem, 3vw, 2.5rem) 1rem;
  font-size: clamp(16px, 1.6vw, 28px);
}
.dash-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; color: var(--on-bg); }
.dash-head h1 { font-size: 2em; font-weight: 700; }
[data-theme="hytte"] .dash-head h1 { text-shadow: 0 0 30px rgb(233 165 58 / .5); }
.dash-info { color: var(--on-bg-muted); font-size: 1.05em; }
.dash-info strong { color: var(--on-bg); }
.dash .exit { opacity: .35; color: var(--on-bg); }
.dash .exit:hover { opacity: 1; }
.dash-body { flex: 1; min-height: 0; display: grid; gap: 1.2rem; grid-template-columns: minmax(0, 1fr); }
.dash-table { display: none; border-radius: 18px; box-shadow: var(--shadow); }
@media (min-width: 900px) and (orientation: landscape) {
  .dash-body { grid-template-columns: minmax(0, 5fr) minmax(0, 4fr); }
  .dash-table { display: block; }
}
.board { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .5em; overflow: auto; }
.board li {
  display: grid; grid-template-columns: 1.6em minmax(0, 1fr) auto auto; align-items: center; gap: .6em;
  padding: .45em .9em; border-radius: 18px;
  background:
    linear-gradient(90deg, color-mix(in srgb, var(--gold) 22%, transparent) calc(var(--w, 0) * 100%), transparent 0),
    var(--paper);
  color: var(--ink); box-shadow: var(--shadow);
  font-size: 1.35em;
}
.board li.lead { outline: 3px solid var(--gold); box-shadow: var(--shadow), 0 0 28px rgb(233 165 58 / .45); }
.d-rank { color: var(--muted); font-weight: 600; text-align: center; }
.board li.lead .d-rank { color: var(--accent); }
.d-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.d-name .pill { font-size: .55em; vertical-align: middle; padding: .2em .7em; border-radius: 99px; background: var(--accent-2); color: var(--accent-2-ink); font-weight: 600; }
.d-delta { font-size: .65em; color: var(--muted); font-variant-numeric: tabular-nums; }
.d-total { font-size: 1.5em; font-weight: 700; font-variant-numeric: tabular-nums; min-width: 2.5ch; text-align: right; }
.board li.bump { animation: bump .6s ease-out; }
@keyframes bump { 30% { transform: scale(1.03); } }
.dash-side { display: flex; flex-direction: column; gap: .6em; min-height: 0; }
.dash-side .board { flex: 1; min-height: 0; }
.board-legend { text-align: right; color: var(--on-bg-muted); font-size: .85em; padding-right: 4.2em; }
.dash .score { font-size: .8em; }
.dash-qr {
  align-self: flex-start; flex: none;
  display: flex; flex-direction: column; align-items: center; gap: .2em;
  padding: .5em; background: #fff; color: #1b1410; border-radius: 16px; box-shadow: var(--shadow);
  font-weight: 700; letter-spacing: .2em; font-size: .9em;
}
.dash-qr .qr { width: clamp(72px, 8vw, 160px); display: block; }
.dash-head .dash-qr { font-size: .75em; }
.dash-empty { flex: 1; display: grid; place-items: center; }
.dash-empty .dash-qr { align-self: center; font-size: 1.4em; }
.dash-empty .dash-qr .qr { width: min(60vmin, 360px); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
.field-col .segmented { border-radius: 20px; align-self: flex-start; }
.field-col .segmented button { border-radius: 16px; }

/* --- Review additions ----------------------------------------------------------- */

.field-error { margin-top: .5rem; color: var(--miss); font-weight: 600; }
.session-game { font-weight: 500; }
.tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .6rem; }
.btn.tile { flex-direction: column; gap: .25rem; min-height: 4.2rem; padding: .5rem; font-size: .92rem; white-space: normal; text-align: center; line-height: 1.15; border-radius: 18px; }
.rules-compact { font-weight: 600; }
.rules-editor[open] > summary { margin-bottom: .4rem; }
.rules-editor .rules-summary { margin-bottom: .6rem; }

/* Landscape phone: give the rows the room. */
@media (max-height: 500px) {
  .bar { padding-top: calc(.1rem + env(safe-area-inset-top)); padding-bottom: .1rem; }
  .bar .icon-btn { width: 2.5rem; height: 2.5rem; }
  .game-info { padding-block: .2rem; font-size: .85rem; display: flex; gap: .8rem; flex-wrap: wrap; }
  [data-theme="hytte"] .game-info { padding-bottom: calc(.2rem + 6px); }
  .action-bar { padding-block: .3rem calc(.3rem + env(safe-area-inset-bottom)); }
  .btn { min-height: 2.5rem; }
  .btn.big { min-height: 2.6rem; font-size: 1rem; }
}

/* --- Kos (cozy) --------------------------------------------------------------- */

.hero-art { display: none; }
[data-theme="cozy"] .hero-art {
  display: block; height: clamp(96px, 28vw, 140px); margin: .25rem auto -.25rem; max-width: 360px;
  background: url(/themes/cozy.svg) center / contain no-repeat;
}
[data-theme="cozy"] .hero h1 { text-shadow: 0 0 22px rgb(233 168 58 / .5); }
/* A waffle-iron band under bars instead of the knit. */
[data-theme="cozy"] .bar::after, [data-theme="cozy"] .hero::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -8px; height: 8px; pointer-events: none;
  background: var(--waffle), #e9b44c;
}
[data-theme="cozy"] .game-info {
  padding-bottom: calc(.5rem + 6px);
  background: var(--waffle), linear-gradient(#e9b44c, #e9b44c) 0 100% / 100% 6px no-repeat, var(--bar);
  background-size: 12px 12px, 12px 12px, 100% 6px, auto;
  background-position: 0 100%, 0 100%, 0 100%, 0 0;
  background-repeat: repeat-x, repeat-x, no-repeat, repeat;
}
@media (max-height: 500px) { [data-theme="cozy"] .game-info { padding-bottom: calc(.2rem + 6px); } }
/* Waffle texture on the sticky header and totals of the score table. */
[data-theme="cozy"] .score thead th,
[data-theme="cozy"] .score tfoot th,
[data-theme="cozy"] .score tfoot td,
[data-theme="cozy"] .score .rn {
  background: var(--waffle), var(--paper-head);
}
[data-theme="cozy"] .score tfoot td.lead { background: var(--waffle), var(--lead); }
[data-theme="cozy"] .btn.primary:not(:disabled):not(.is-disabled) {
  background: linear-gradient(180deg, #c53246, #a11f33);
  box-shadow: 0 2px 0 #7d1626, inset 0 1px 0 rgb(255 255 255 / .2);
}
[data-theme="cozy"] .card, [data-theme="cozy"] .preset { border-radius: 22px; }
[data-theme="cozy"] .rank.r1 { box-shadow: 0 0 12px rgb(233 168 58 / .8); }
/* Steaming mug in the corner of the big screen. */
[data-theme="cozy"] .dash::before {
  content: ""; position: fixed; left: 0; bottom: 0; width: min(36vw, 420px); aspect-ratio: 360 / 140;
  background: url(/themes/cozy.svg) left bottom / contain no-repeat; opacity: .22; pointer-events: none;
}
[data-theme="cozy"] .dash > * { position: relative; }
.sw-cozy {
  background:
    radial-gradient(circle at 70% 30%, #fff4e6 0 2px, transparent 2.5px),
    linear-gradient(135deg, #3d2319 0 42%, #e9b44c 42% 68%, #b3263a 68%);
}

/* --- Results ------------------------------------------------------------------ */

.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.btn.icon-only { padding: 0; width: 2.9rem; flex: none; }
.end-link { display: inline-flex; align-items: center; gap: .4rem; margin: 1.2rem auto; color: var(--muted); font-size: .95rem; }
.score tbody tr.filler td { vertical-align: top; text-align: center; }
.table-wrap.is-results::after { display: none; }

.results { padding: 1.4rem 1rem 1.6rem; max-width: 34rem; margin: 0 auto; color: var(--ink); }
.results h2 { text-align: center; font-size: 1.5em; color: var(--ink); margin-bottom: 1em; }
.podium {
  list-style: none; margin: 0 0 1.4em; padding: 0;
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: end; gap: .5em;
}
/* 2nd left, 1st centre, 3rd right (DOM stays in rank order for screen readers). */
.place.pos1 { order: 2; }
.place.pos2 { order: 1; }
.place.pos3 { order: 3; }
.place { display: flex; flex-direction: column; align-items: center; text-align: center; min-width: 0; animation: podium-rise .6s cubic-bezier(.2, .9, .3, 1.2) both; }
.place.pos2 { animation-delay: .15s; }
.place.pos3 { animation-delay: .3s; }
.place.pos1 { animation-delay: .45s; }
@keyframes podium-rise { from { transform: translateY(30%); opacity: 0; } }
.medal { font-size: 2.2em; line-height: 1.1; }
.place.rank1 .medal { font-size: 2.8em; }
.place-name { font-weight: 700; font-size: 1.05em; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.place-score { font-weight: 700; font-size: 1.5em; font-variant-numeric: tabular-nums; margin-bottom: .25em; }
.place-step {
  width: 100%; display: grid; place-items: center;
  border-radius: 14px 14px 4px 4px; font-weight: 700; font-size: 1.6em;
  background: var(--chip); color: var(--muted); box-shadow: var(--shadow);
}
.place.rank1 .place-step { height: 5.2em; background: var(--gold); color: #3a2618; box-shadow: var(--shadow), 0 0 26px rgb(233 168 58 / .55); }
.place.rank2 .place-step { height: 3.8em; background: #d9dde3; color: #3b4048; }
.place.rank3 .place-step { height: 2.8em; background: #e2b48a; color: #4a2c16; }
[data-theme="cozy"] .place.rank1 .place-step { background: var(--waffle), var(--gold); }
[data-theme="hytte"] .place.rank1 .place-step,
[data-theme="cozy"] .place.rank1 .place-step { box-shadow: var(--shadow), 0 0 30px rgb(233 168 58 / .7); }
.rest { list-style: none; margin: 0 0 1em; padding: 0; display: grid; gap: .4em; }
.rest li {
  display: grid; grid-template-columns: 2em minmax(0, 1fr) auto; align-items: center; gap: .6em;
  padding: .55em .9em; border-radius: 14px; background: var(--paper-alt); box-shadow: inset 0 0 0 1px var(--line);
}
.rest-rank { color: var(--muted); font-weight: 700; text-align: center; }
.rest-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rest-score { font-weight: 700; font-variant-numeric: tabular-nums; }

/* Big screen: the podium in the left column, scaled up. */
.dash-side .results { max-width: none; width: 100%; background: var(--paper); border-radius: 22px; box-shadow: var(--shadow); font-size: 1.15em; overflow: auto; }
.game-info .muted, .dash-info .muted { color: inherit; opacity: .75; }
.dash-side .results { font-size: 1em; padding-block: 1em; }
.dash-side .results h2 { margin-bottom: .5em; }
.dash-side .podium { margin-bottom: .8em; }
.dash-side .place.rank1 .place-step { height: 3.6em; }
.dash-side .place.rank2 .place-step { height: 2.7em; }
.dash-side .place.rank3 .place-step { height: 2em; }

/* Tap-to-rename in the seat list. */
.seat-name { border: 0; background: none; text-align: left; padding: .4rem .2rem; min-height: 2.75rem; display: inline-flex; align-items: center; gap: .35rem; color: inherit; font: inherit; font-weight: 600; }
.seat-name .icon { width: .95em; height: .95em; opacity: .35; flex: none; }
.seat-name:hover .icon { opacity: .7; }
.seat-input { flex: 1; min-width: 0; font: inherit; font-weight: 600; padding: .45rem .7rem; border-radius: 12px; border: 2px solid var(--accent); background: var(--paper-alt); color: var(--ink); }
