/* Spelmotorn – mobil först. Stora tryckytor, hög kontrast, ljust och mörkt läge. */
:root {
  --bg: #f4f1ec; --surface: #ffffff; --surface-2: #efebe4; --text: #1d1b18; --muted: #6b655c; --line: #ddd6cb;
  --accent: #d2561c; --accent-ink: #ffffff; --accent-soft: #fbe3d6;
  --ok: #1f8a4c; --ok-soft: #d9f2e3; --bad: #c0392b; --bad-soft: #f8dcd8; --warn: #b7791f; --warn-soft: #fbefd5;
  --radius: 16px; --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.06);
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-scheme=light]) {
    --bg: #15130f; --surface: #221f1a; --surface-2: #2c2822; --text: #f3efe8; --muted: #a89f92; --line: #3a352d;
    --accent: #ff7a3d; --accent-ink: #1a0d05; --accent-soft: #3d2416;
    --ok: #4cc27f; --ok-soft: #173525; --bad: #ff6b5b; --bad-soft: #3d1c18; --warn: #f0b44c; --warn-soft: #3a2c12;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-scheme=dark] {
    --bg: #15130f; --surface: #221f1a; --surface-2: #2c2822; --text: #f3efe8; --muted: #a89f92; --line: #3a352d;
    --accent: #ff7a3d; --accent-ink: #1a0d05; --accent-soft: #3d2416;
    --ok: #4cc27f; --ok-soft: #173525; --bad: #ff6b5b; --bad-soft: #3d1c18; --warn: #f0b44c; --warn-soft: #3a2c12;
    --shadow: none; color-scheme: dark;
}
/* Spelets färgtema (sätts från designern) */
:root[data-accent] { --accent: var(--accent-l); --accent-ink: #fff; }
@media (prefers-color-scheme: dark) { :root[data-accent]:not([data-scheme=light]) { --accent: var(--accent-d); --accent-ink: #10141a; } }
:root[data-accent][data-scheme=dark] { --accent: var(--accent-d); --accent-ink: #10141a; }
:root[data-accent] { --accent-soft: color-mix(in srgb, var(--accent) 16%, var(--surface)); }
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 17px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent; overscroll-behavior-y: none;
}
.wrap { max-width: 640px; margin: 0 auto; padding: 16px 16px calc(120px + var(--safe-b)); }
h1 { font-size: 1.6rem; line-height: 1.2; margin: .2em 0 .4em; }
h2 { font-size: 1.25rem; margin: 1.2em 0 .5em; }
h3 { font-size: 1.05rem; margin: 1em 0 .4em; }
p { margin: .4em 0 .8em; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.center { text-align: center; }
.hidden { display: none !important; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap-row { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 12px; }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; }

/* Kort */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card + .card { margin-top: 12px; }
.card.soft { background: var(--surface-2); box-shadow: none; }
.card.now { border: 2px solid var(--accent); }
.card.next { background: transparent; border-style: dashed; box-shadow: none; }
.label { font-size: .75rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin-bottom: 4px; }
.card.now > .label { color: var(--accent); }
.say { font-size: 1.35rem; line-height: 1.35; font-weight: 600; white-space: pre-wrap; overflow-wrap: anywhere; }
.facit { margin-top: 12px; padding: 12px 14px; border-radius: 12px; background: var(--ok-soft); color: var(--ok); font-weight: 700; font-size: 1.15rem; overflow-wrap: anywhere; }
.facit .label { color: var(--ok); }
.note { margin-top: 10px; padding: 10px 12px; border-radius: 10px; background: var(--warn-soft); color: var(--text); font-size: .95rem; white-space: pre-wrap; }

/* Knappar */
button, .btn {
  font: inherit; font-weight: 650; border: 0; border-radius: 14px; padding: 14px 18px; min-height: 52px;
  background: var(--surface-2); color: var(--text); cursor: pointer; touch-action: manipulation; user-select: none; -webkit-user-select: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none; position: relative; overflow: hidden;
}
button:disabled { opacity: .45; cursor: default; }
button.primary, .btn.primary { background: var(--accent); color: var(--accent-ink); }
button.danger { background: var(--bad-soft); color: var(--bad); }
button.ok { background: var(--ok-soft); color: var(--ok); }
button.ghost { background: transparent; border: 1px solid var(--line); }
button.block { width: 100%; }
button.big { min-height: 68px; font-size: 1.2rem; border-radius: 18px; }
button.small { min-height: 40px; padding: 8px 12px; font-size: .9rem; border-radius: 10px; }
button.icon { min-width: 48px; padding: 10px; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
button .fill { position: absolute; inset: 0; background: rgba(255,255,255,.28); transform-origin: left; transform: scaleX(0); pointer-events: none; }
button.busy::after { content: ""; width: 18px; height: 18px; border-radius: 50%; border: 3px solid currentColor; border-right-color: transparent; animation: spin .8s linear infinite; }
button.cooldown { opacity: .55; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Fält */
label.field { display: block; margin: 12px 0; }
label.field > span { display: block; font-weight: 600; margin-bottom: 6px; }
.help { font-size: .85rem; color: var(--muted); margin-top: 4px; }
input, textarea, select {
  font: inherit; width: 100%; padding: 13px 14px; border-radius: 12px; border: 1.5px solid var(--line);
  background: var(--surface); color: var(--text); min-height: 52px;
}
textarea { min-height: 88px; resize: vertical; }
input.code { font-size: 2rem; letter-spacing: .3em; text-align: center; text-transform: uppercase; font-weight: 800; font-family: ui-monospace, Menlo, monospace; }
input[type=checkbox], input[type=radio] { width: 24px; height: 24px; min-height: 0; padding: 0; flex: none; accent-color: var(--accent); }
.check { display: flex; gap: 12px; align-items: center; min-height: 48px; font-weight: 600; }

/* Fast knapprad längst ned (tummens zon) */
.dock { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; background: linear-gradient(to top, var(--bg) 75%, transparent); padding: 18px 16px calc(12px + var(--safe-b)); }
.dock-inner { max-width: 640px; margin: 0 auto; }
.dock .hint { text-align: center; font-size: .85rem; color: var(--muted); margin-top: 6px; min-height: 1.2em; }

/* Flikar längst ned */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 25; background: var(--surface); border-top: 1px solid var(--line); display: flex; padding-bottom: var(--safe-b); }
.tabs button { flex: 1; border-radius: 0; background: transparent; min-height: 58px; flex-direction: column; gap: 2px; font-size: .78rem; color: var(--muted); padding: 6px 2px; }
.tabs button .ico { font-size: 1.3rem; line-height: 1; }
.tabs button.on { color: var(--accent); }
body.has-tabs .dock { bottom: calc(58px + var(--safe-b)); padding-bottom: 10px; }
body.has-tabs .wrap { padding-bottom: calc(210px + var(--safe-b)); }

/* Topprad */
.top { position: sticky; top: 0; z-index: 15; background: var(--bg); padding: 10px 16px; border-bottom: 1px solid var(--line); }
.top-inner { max-width: 640px; margin: 0 auto; display: flex; align-items: center; gap: 10px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 999px; background: var(--surface-2); font-size: .85rem; font-weight: 650; white-space: nowrap; }
.chip.accent { background: var(--accent-soft); color: var(--accent); }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.code-big { font: 800 2.6rem/1 ui-monospace, Menlo, monospace; letter-spacing: .18em; text-align: center; padding: 8px 0; }

/* Tidtagning */
.timer { display: flex; align-items: center; gap: 12px; margin: 10px 0; }
.timer .num { font: 800 1.9rem/1 ui-monospace, Menlo, monospace; min-width: 3.2ch; text-align: right; }
.bar { flex: 1; height: 10px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .25s linear; }
.timer.low .num { color: var(--bad); }
.timer.low .bar > i { background: var(--bad); }

/* Steg i rundan */
.steps { display: flex; gap: 4px; margin: 8px 0 2px; }
.steps i { flex: 1; height: 6px; border-radius: 3px; background: var(--line); }
.steps i.done { background: var(--muted); }
.steps i.now { background: var(--accent); }

/* Svarsalternativ */
.opts { display: grid; gap: 10px; margin-top: 14px; }
.opt { justify-content: flex-start; text-align: left; min-height: 64px; font-size: 1.1rem; background: var(--surface); border: 2px solid var(--line); }
.opt .key { flex: none; width: 36px; height: 36px; border-radius: 10px; background: var(--surface-2); display: inline-flex; align-items: center; justify-content: center; font-weight: 800; }
.opt.sel { border-color: var(--accent); background: var(--accent-soft); }
.opt.sel .key { background: var(--accent); color: var(--accent-ink); }
.opt.right { border-color: var(--ok); background: var(--ok-soft); }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); }
.onex2 { grid-template-columns: repeat(3, 1fr); }
.onex2 .opt { flex-direction: column; justify-content: center; text-align: center; min-height: 96px; gap: 4px; }
.onex2 .opt .key { width: auto; height: auto; background: none; font-size: 2rem; }
.onex2 .opt.sel .key { background: none; color: var(--accent); }
.onex2 .opt small { font-size: .82rem; font-weight: 500; color: var(--muted); overflow-wrap: anywhere; }

/* Resultat */
.result { border-radius: var(--radius); padding: 18px; text-align: center; margin-top: 14px; }
.result.correct { background: var(--ok-soft); color: var(--ok); }
.result.wrong, .result.empty { background: var(--bad-soft); color: var(--bad); }
.result .big { font-size: 1.6rem; font-weight: 800; }
.result .sub { color: var(--text); margin-top: 6px; }

/* Ledtrådar */
.ladder { display: flex; gap: 6px; margin: 10px 0; }
.ladder span { flex: 1; text-align: center; padding: 8px 0; border-radius: 10px; background: var(--surface-2); font-weight: 750; color: var(--muted); }
.ladder span.now { background: var(--accent); color: var(--accent-ink); }
.ladder span.past { opacity: .45; text-decoration: line-through; }
.clue { padding: 12px 14px; border-radius: 12px; background: var(--surface-2); margin-top: 8px; overflow-wrap: anywhere; }
.clue.latest { background: var(--surface); border: 2px solid var(--accent); font-size: 1.15rem; font-weight: 600; }
.clue b { color: var(--accent); margin-right: 6px; }

/* Poängtavla */
.board { list-style: none; padding: 0; margin: 0; }
.board li { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); margin-top: 8px; }
.board li.me { border: 2px solid var(--accent); }
.board .pl { width: 32px; height: 32px; border-radius: 50%; background: var(--surface-2); display: inline-flex; align-items: center; justify-content: center; font-weight: 800; flex: none; }
.board li:nth-child(1) .pl { background: #f4c542; color: #3b2a00; }
.board .nm { flex: 1; font-weight: 650; overflow-wrap: anywhere; }
.board .sc { font-weight: 800; font-size: 1.15rem; }

/* Listor (GM) */
.list { list-style: none; padding: 0; margin: 0; }
.list li { display: flex; align-items: center; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--line); flex: none; }
.dot.on { background: var(--ok); }
.ans-row { display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.ans-row:last-child { border-bottom: 0; }
.ans-row .who { font-weight: 700; }
.ans-row .what { grid-column: 1 / 2; overflow-wrap: anywhere; }
.ans-row .grade { grid-row: 1 / 3; grid-column: 2; display: flex; gap: 6px; }
.ans-row .grade button { min-width: 52px; min-height: 48px; padding: 6px; font-size: 1.2rem; }
.ans-row .grade button.on.ok { background: var(--ok); color: #fff; }
.ans-row .grade button.on.danger { background: var(--bad); color: #fff; }
.tag { font-size: .75rem; font-weight: 700; padding: 2px 8px; border-radius: 99px; margin-left: 6px; }
.tag.correct { background: var(--ok-soft); color: var(--ok); }
.tag.wrong, .tag.empty { background: var(--bad-soft); color: var(--bad); }
.tag.near { background: var(--warn-soft); color: var(--warn); }
.progress { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin-top: 8px; }
.progress > i { display: block; height: 100%; background: var(--ok); }

/* Banner, toast, dialog */
.banner { padding: 12px 14px; border-radius: 12px; font-weight: 650; margin-bottom: 12px; }
.banner.warn { background: var(--warn-soft); color: var(--warn); }
.banner.bad { background: var(--bad-soft); color: var(--bad); }
.banner.ok { background: var(--ok-soft); color: var(--ok); }
.toast { position: fixed; left: 50%; transform: translateX(-50%); top: calc(12px + env(safe-area-inset-top, 0px)); z-index: 100; max-width: calc(100% - 32px); padding: 12px 16px; border-radius: 12px; background: var(--text); color: var(--bg); font-weight: 650; box-shadow: 0 6px 24px rgba(0,0,0,.25); }
.toast.bad { background: var(--bad); color: #fff; }
.toast.ok { background: var(--ok); color: #fff; }
.modal-bg { position: fixed; inset: 0; z-index: 90; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; justify-content: center; padding: 16px; padding-bottom: calc(16px + var(--safe-b)); }
.modal { width: 100%; max-width: 520px; background: var(--surface); border-radius: 20px; padding: 20px; max-height: 85vh; overflow: auto; }
.modal h2 { margin-top: 0; }
.modal .row button { flex: 1; }

/* Studio */
.game-card { display: flex; width: 100%; text-align: left; justify-content: flex-start; flex-direction: column; align-items: stretch; background: var(--surface); border: 1px solid var(--line); padding: 14px 16px; }
.game-card .t { font-size: 1.1rem; font-weight: 750; }
.game-card .m { font-size: .85rem; color: var(--muted); font-weight: 500; }
.item { border: 1px solid var(--line); border-radius: 14px; background: var(--surface); margin-top: 10px; }
.item > .head { display: flex; align-items: center; gap: 8px; padding: 8px 8px 8px 14px; min-height: 56px; cursor: pointer; }
.item > .head .t { flex: 1; min-width: 0; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item > .head .n { color: var(--muted); font-size: .85rem; font-weight: 700; }
.item > .body { padding: 0 14px 14px; border-top: 1px solid var(--line); }
.item .item { background: var(--surface-2); }
.item.err { border-color: var(--bad); }
.tools { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.chips .chip button { min-height: 28px; min-width: 28px; padding: 0 6px; background: transparent; font-size: 1rem; }
.mode-card { display: flex; gap: 12px; align-items: flex-start; padding: 14px; border: 2px solid var(--line); border-radius: 14px; margin-top: 8px; cursor: pointer; background: var(--surface); }
.mode-card.on { border-color: var(--accent); background: var(--accent-soft); }
.mode-card input { margin-top: 2px; }
.mode-card b { display: block; }
.type-card { width: 100%; justify-content: flex-start; text-align: left; align-items: flex-start; flex-direction: column; gap: 2px; background: var(--surface); border: 1px solid var(--line); margin-top: 8px; }
.type-card .t { font-weight: 750; font-size: 1.05rem; }
.type-card .d { font-weight: 450; font-size: .9rem; color: var(--muted); }
.savebar { display: flex; gap: 10px; align-items: center; }
.savebar .status { flex: 1; font-size: .9rem; color: var(--muted); }
.savebar .status.dirty { color: var(--warn); font-weight: 700; }
.savebar .status.err { color: var(--bad); font-weight: 700; }
a { color: var(--accent); }
.linkbox { font: .9rem ui-monospace, Menlo, monospace; word-break: break-all; padding: 10px; background: var(--surface-2); border-radius: 10px; user-select: all; -webkit-user-select: all; }

.compact-row { display: flex; gap: 8px; align-items: center; margin-top: 8px; padding: 4px; border-radius: 14px; }
.compact-row.on { background: var(--ok-soft); }
.compact-row .mini-check { display: flex; flex-direction: column; align-items: center; gap: 0; font-size: .7rem; font-weight: 700; color: var(--muted); min-width: 44px; cursor: pointer; }
.compact-row.on .mini-check { color: var(--ok); }
button.undo { min-height: 38px; font-weight: 550; color: var(--muted); }
button.undo, button.undo * { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.opt:disabled { opacity: .75; }
.opt.right:disabled, .opt.sel:disabled, .opt.wrong:disabled { opacity: 1; }

.symbol { font-size: 3.4rem; line-height: 1; margin-bottom: 8px; }
.symbol.small-symbol { font-size: 2.2rem; float: right; }
.dots { display: flex; gap: 8px; justify-content: center; margin: 12px 0 4px; }
.dots i { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); animation: pulse 1.2s infinite ease-in-out; }
.dots i:nth-child(2) { animation-delay: .2s; } .dots i:nth-child(3) { animation-delay: .4s; }
@keyframes pulse { 0%, 80%, 100% { opacity: .25; transform: scale(.8); } 40% { opacity: 1; transform: scale(1); } }
@media (prefers-reduced-motion: reduce) { .dots i { animation: none; opacity: .6; } }

.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch { width: 48px; height: 48px; min-height: 48px; padding: 0; border-radius: 50%; color: #fff; font-size: 1.2rem; border: 3px solid transparent; }
.swatch.on { border-color: var(--text); box-shadow: 0 0 0 2px var(--bg) inset; }
.qr { width: min(220px, 62vw); margin: 8px auto 4px; border-radius: 12px; overflow: hidden; background: #fff; padding: 0; }
.qr.big { width: min(300px, 78vw); }
.qr svg { display: block; width: 100%; height: auto; }
.help-table { display: grid; gap: 6px; }
.help-table .hrow { display: grid; grid-template-columns: 7.5em 1fr; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.help-table .hrow:last-child { border-bottom: 0; }
