/* Spillsiden: shared look for the menu and every game. Colours are tokens, light and dark. */
:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #ece8df;
  --line: #d9d3c7;
  --text: #1f1d1a;
  --muted: #6b665d;
  --accent: #2f6fdb;
  --accent-text: #ffffff;
  --good: #3f9a54;
  --warn: #c9a227;
  --bad: #d0473b;
  --tile: #e4dfd4;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 4px 14px rgba(0, 0, 0, .06);
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161514;
    --surface: #211f1d;
    --surface-2: #2b2926;
    --line: #3a3733;
    --text: #ece8e1;
    --muted: #a39d93;
    --accent: #6c9cf0;
    --accent-text: #0f1420;
    --good: #58b26c;
    --warn: #d4b13e;
    --bad: #e2675c;
    --tile: #34312d;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 14px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #161514; --surface: #211f1d; --surface-2: #2b2926; --line: #3a3733; --text: #ece8e1;
  --muted: #a39d93; --accent: #6c9cf0; --accent-text: #0f1420; --good: #58b26c; --warn: #d4b13e;
  --bad: #e2675c; --tile: #34312d; --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 14px rgba(0, 0, 0, .3);
  color-scheme: dark;
}

* { box-sizing: border-box; }
/* hidden means hidden, also where a game's own rule sets display */
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 var(--font);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); }

/* The bar on top of every game: back to the menu, the title, the game's own buttons. */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar .back { text-decoration: none; color: var(--muted); font-weight: 600; white-space: nowrap; }
.topbar .back:hover { color: var(--text); }
/* The title keeps its full text; the tools wrap when the bar is full. */
.topbar h1 { font-size: 18px; margin: 0; flex: 1 0 auto; white-space: nowrap; }
.topbar .tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }

.btn {
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  padding: 7px 14px; border-radius: 9px; cursor: pointer; font-weight: 600; font-size: 14px;
  box-shadow: var(--shadow);
}
.btn:hover { border-color: var(--muted); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn:disabled { opacity: .5; cursor: default; }
.btn:focus-visible, .seg button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* A small segmented switch: Norsk | English, levels. */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: transparent; padding: 6px 11px; cursor: pointer; font-size: 14px; font-weight: 600; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); }

.stat { font-size: 14px; color: var(--muted); white-space: nowrap; }
.stat b { color: var(--text); font-variant-numeric: tabular-nums; }

/* The game area. */
main.game {
  max-width: 980px; margin: 0 auto; padding: 20px 16px 40px;
  display: flex; flex-direction: column; align-items: center; gap: 16px;
}
.help { color: var(--muted); font-size: 14px; max-width: 640px; text-align: center; margin: 0; }
.help kbd, kbd {
  font: 12px var(--mono); padding: 1px 5px; border: 1px solid var(--line); border-bottom-width: 2px;
  border-radius: 5px; background: var(--surface);
}

/* Dialog for a win, a loss or the stats. */
.overlay {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center;
  background: rgba(0, 0, 0, .35); padding: 16px;
}
.dialog {
  background: var(--surface); color: var(--text); border-radius: 16px; box-shadow: var(--shadow);
  padding: 22px 24px; max-width: 420px; width: 100%; text-align: center;
}
.dialog h2 { margin: 0 0 6px; font-size: 22px; }
.dialog p { margin: 6px 0 14px; color: var(--muted); }
.dialog .row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

.toast {
  position: fixed; left: 50%; top: 70px; transform: translateX(-50%); z-index: 60;
  background: var(--text); color: var(--bg); padding: 8px 14px; border-radius: 9px; font-weight: 600;
  box-shadow: var(--shadow); pointer-events: none; transition: opacity .3s;
}

/* The menu. */
.menu { max-width: 1100px; margin: 0 auto; padding: 28px 16px 48px; }
.menu header h1 { margin: 0; font-size: 30px; }
.menu header p { margin: 4px 0 0; color: var(--muted); }
.menu h2 { font-size: 15px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 28px 0 10px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.card {
  display: flex; flex-direction: column; gap: 4px; text-decoration: none; color: var(--text);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow); transition: transform .12s, border-color .12s;
}
.card:hover, .card:focus-visible { transform: translateY(-2px); border-color: var(--accent); outline: none; }
.card .icon { font-size: 26px; line-height: 1; }
.card .name { font-weight: 700; font-size: 17px; }
.card .what { color: var(--muted); font-size: 13px; }
.card .best { color: var(--muted); font-size: 12px; margin-top: auto; padding-top: 6px; }

@media (max-width: 560px) {
  .topbar { flex-wrap: wrap; }
  .topbar h1 { flex-basis: 50%; }
}

/* «Vis løsning» keeps its width when it says «Skjul løsning». */
.btn.peek { min-width: 8.6em; }

/* Records (Spill.recordsDialog) and the Rekorder page. */
.records-box { display: flex; flex-direction: column; gap: 12px; align-items: center; margin: 4px 0 14px; }
.records-holder, .records-level { width: 100%; }
table.records { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
table.records th { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; text-align: left; padding: 4px 8px; }
table.records td { padding: 6px 8px; border-top: 1px solid var(--line); text-align: left; }
table.records td:first-child, table.records th:first-child { width: 2.5em; text-align: center; }
table.records tr.first td { font-weight: 700; }
.records-empty, .records-stats { color: var(--muted); margin: 8px 0 0; font-size: 14px; text-align: center; }

/* A wider dialog, for «Slik spiller du». */
.dialog.wide { max-width: 620px; text-align: left; }
.dialog.wide h2 { text-align: center; }
.dialog.wide .row { justify-content: center; }
.howto { display: flex; flex-direction: column; gap: 12px; margin: 8px 0 16px; max-height: calc(100vh - 220px); overflow-y: auto; }
.howto-intro { color: var(--text) !important; margin: 0 !important; }
.howto-example { display: flex; flex-wrap: wrap; gap: 14px; justify-content: center; align-items: flex-start;
  background: var(--surface-2); border-radius: var(--radius); padding: 14px; }
.howto-example figure { margin: 0; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.howto-example figcaption { font-size: 13px; color: var(--muted); text-align: center; max-width: 220px; }
.howto-rules { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 4px; font-size: 15px; }
.howto-keys { font-size: 13px; color: var(--muted) !important; margin: 0 !important; }

/* The menu: «Fortsett», favourites, each card's progress line and star. */
.card { position: relative; }
.card .star {
  position: absolute; top: 8px; right: 8px; border: 0; background: transparent; cursor: pointer;
  font-size: 18px; line-height: 1; padding: 4px; color: var(--muted); border-radius: 6px;
}
.card .star:hover { background: var(--surface-2); }
.card .star[aria-pressed="true"] { color: var(--warn); }
.card .progress { color: var(--muted); font-size: 12px; }
.card.resume { border-color: var(--accent); }
.card.resume .now { color: var(--accent); font-size: 13px; font-weight: 600; }

/* Numbered boards (Spill.boardButton, Spill.boardPicker): the board and its group in the top bar,
   and the picker, a tab per group and a grid of numbers. */
.level-btn { font-variant-numeric: tabular-nums; white-space: nowrap; }
.level-btn span { color: var(--muted); }
.level-btn .caret { margin-left: 6px; font-size: 11px; }
.dialog.picker {
  max-width: 1040px; text-align: left; display: flex; flex-direction: column; gap: 12px;
  max-height: calc(100vh - 32px); padding: 18px 20px;
}
.dialog.picker .picker-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.dialog.picker h2 { margin: 0; }
.dialog.picker .levels {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); gap: 6px;
  overflow-y: auto; min-height: 0; padding: 3px; margin: -3px;
}
.dialog.picker .lvl {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  height: 42px; padding: 0 2px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); cursor: pointer; font-variant-numeric: tabular-nums;
}
.dialog.picker .lvl:hover { border-color: var(--muted); }
.dialog.picker .lvl:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.dialog.picker .lvl .num { font-weight: 700; font-size: 15px; line-height: 1.1; }
.dialog.picker .lvl small { font-size: 10px; line-height: 1.1; color: var(--muted); font-weight: 600; white-space: nowrap; min-height: 11px; }
.dialog.picker .lvl.solved { background: color-mix(in srgb, var(--good) 16%, var(--surface)); border-color: color-mix(in srgb, var(--good) 45%, var(--line)); }
.dialog.picker .lvl.solved small { color: var(--good); }
.dialog.picker .lvl.started:not(.solved) small::before { content: "•••"; color: var(--accent); letter-spacing: 1px; }
.dialog.picker .lvl.current { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.dialog.picker .lvl.current .num { color: var(--accent); }
.dialog.picker .picker-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.dialog.picker .picker-foot p { margin: 0; font-size: 13px; }

/* Games for two (Spill.duel): the two names and the standing in the top bar, the names dialog. */
.duel-score { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; white-space: nowrap; }
.duel-score .p { padding: 3px 9px; border-radius: 8px; border: 1px solid transparent; color: var(--muted); font-weight: 600; max-width: 10em; overflow: hidden; text-overflow: ellipsis; }
.duel-score .p.turn { color: var(--text); border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, var(--surface)); }
.duel-score .standing { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--text); }
.duel-names { display: flex; flex-direction: column; gap: 10px; margin: 4px 0 16px; text-align: left; }
.duel-names label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.duel-names input { padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); font-size: 15px; }
.duel-names input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
/* The line under a board that says whose turn it is, or that the computer is thinking. */
.duel-turn { margin: 0; font-weight: 600; min-height: 1.4em; text-align: center; }
.duel-turn.thinking { color: var(--muted); font-weight: 500; }
/* A result dialog's line when the game made the records' top. */
.dialog p.rank-note { color: var(--accent); font-weight: 700; margin-top: -4px; }
