:root {
  --bg: #f6f5f1; --fg: #1d1d1f; --muted: #7a7a80; --card: #fff; --line: #d2d0c8; --thick: #2b2b30;
  --accent: #3b6df0; --given: #1d1d1f; --user: #2f5fd8; --bad: #d63a3a;
  --t0: #dfe9fb; --t1: #dff3e3; --t2: #fbf1c9; --t3: #fbe0cc; --t4: #ebdffb; --t5: #fbd9d9;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16171a; --fg: #ececf0; --muted: #8b8b94; --card: #232428; --line: #4a4b52; --thick: #d7d7de;
    --accent: #6f93ff; --given: #ececf0; --user: #8fb0ff; --bad: #ff6b6b;
    --t0: #28344f; --t1: #26402e; --t2: #473f22; --t3: #4a3526; --t4: #3a2e50; --t5: #4a2828;
  }
}
:root[data-theme="dark"] {
  --bg: #16171a; --fg: #ececf0; --muted: #8b8b94; --card: #232428; --line: #4a4b52; --thick: #d7d7de;
  --accent: #6f93ff; --given: #ececf0; --user: #8fb0ff; --bad: #ff6b6b;
  --t0: #28344f; --t1: #26402e; --t2: #473f22; --t3: #4a3526; --t4: #3a2e50; --t5: #4a2828;
}
:root { --sel: rgba(255,107,87,.40); --peer: rgba(255,107,87,.12); --same: rgba(255,107,87,.24); --tint: rgba(255,107,87,.16); }
/* the real values are computed from the theme's accent colour in app.js (applyPalette) */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--fg);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
main { max-width: 520px; margin: 0 auto; padding: 8px 12px max(16px, env(safe-area-inset-bottom));
  height: 100vh; height: 100dvh; display: flex; flex-direction: column; }
header { display: flex; align-items: center; justify-content: space-between; }
h1 { margin: 4px 0; font-size: 26px; letter-spacing: .5px; }
button { font: inherit; color: inherit; background: var(--card); border: 1px solid var(--line);
  border-radius: 10px; padding: 9px 12px; cursor: pointer; touch-action: manipulation; }
button:active { transform: scale(.97); }
.hdr-right { display: flex; align-items: center; gap: 10px; }
.switch { position: relative; width: 52px; height: 28px; padding: 0; border-radius: 14px; background: var(--line); border: 0; }
.switch::before { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%;
  background: var(--card); transition: transform .2s; }
.switch .sun, .switch .moon { position: absolute; top: 5px; font-size: 14px; line-height: 18px; }
.switch .sun { right: 7px; } .switch .moon { left: 7px; }
.switch[aria-checked="true"] { background: var(--accent); }
.switch[aria-checked="true"]::before { transform: translateX(24px); }
button.icon { width: 38px; height: 38px; padding: 0; border-radius: 50%; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center; line-height: 1; }
button.primary { background: var(--accent); color: var(--onaccent, #fff); border-color: var(--accent); }
.tabs { display: flex; gap: 6px; margin: 4px 0 8px; }
.tabs button { flex: 1; }
.tabs button.on { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.meta { display: flex; justify-content: space-between; color: var(--muted); font-size: 14px; margin-bottom: 6px; }
#boardWrap { flex: 1; display: flex; justify-content: center; align-items: center; min-height: 0; overflow: hidden; }
#board { width: 100%; height: 100%; user-select: none; touch-action: manipulation; }
#board text { font-family: inherit; text-anchor: middle; dominant-baseline: central; pointer-events: none; }
#board .g { fill: var(--given); font-weight: 600; font-size: 30px; }
#board .u { fill: var(--user); font-size: 30px; }
#board .bad { fill: var(--bad); }
#board .n { fill: var(--fg); fill-opacity: .8; font-size: 19px; font-weight: 700; }
.f0 { fill: var(--t0); } .f1 { fill: var(--t1); } .f2 { fill: var(--t2); }
.f3 { fill: var(--t3); } .f4 { fill: var(--t4); } .f5 { fill: var(--t5); }
.o-sel { fill: var(--sel); } .o-peer { fill: var(--peer); } .o-same { fill: var(--same); }
.thin { stroke: var(--line); stroke-width: 1; }
.thick { stroke: var(--thick); stroke-width: 3; stroke-linecap: round; }
.tools { display: flex; gap: 8px; margin: 12px 0 8px; }
.tools button { flex: 1; padding: 11px 6px; }
.tools button.on { background: var(--accent); color: var(--onaccent, #fff); border-color: var(--accent); }
#pad { display: grid; grid-template-columns: repeat(9, 1fr); gap: 5px; }
#pad button { padding: 12px 0; font-size: 22px; font-weight: 500; border-radius: 8px; }
#pad button.active { background: var(--accent); color: var(--onaccent, #fff); border-color: var(--accent); }
#pad button.done { color: var(--muted); background: transparent; }
.modal { position: fixed; top: 0; right: 0; bottom: 0; left: 0; background: rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal[hidden] { display: none; }
.card { background: var(--card); border-radius: 16px; padding: 20px; max-width: 380px; width: 100%; }
.card h2 { margin: 0 0 8px; }
.card pre { font: inherit; white-space: pre-wrap; margin: 0 0 14px; }
.card pre.emoji { font-size: 22px; line-height: 1.15; letter-spacing: 1px; }
.card .row { display: flex; gap: 8px; } .card .row button { flex: 1; }
[hidden] { display: none !important; }
.card h3 { margin: 0 0 8px; font-size: 14px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .6px; }
#themes { display: grid; gap: 8px; margin-bottom: 14px; }
button.theme { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; }
button.theme.on { border: 2px solid var(--accent); }
.dots { display: flex; gap: 4px; }
.dots i { width: 18px; height: 18px; border-radius: 5px; border: 1px solid var(--line); display: block; }
.levels { display: flex; gap: 6px; margin: 0 0 8px; }
.levels button { flex: 1; padding: 6px 2px; font-size: 14px; }
.levels button.on { background: var(--accent); color: var(--onaccent, #fff); border-color: var(--accent); }
.meta b { color: var(--fg); }
button.q { width: 20px; height: 20px; padding: 0; border-radius: 50%; font-size: 12px; font-weight: 700; color: var(--muted); vertical-align: 1px; }
#diffBody { margin-bottom: 14px; }
.bar { display: flex; gap: 4px; }
.bar i { flex: 1; height: 8px; border-radius: 4px; background: var(--line); display: block; }
.bar i.f0 { background: #4caf6a; } .bar i.f1 { background: #e0b020; }
.bar i.f2 { background: #ee7a2a; } .bar i.f3 { background: #d63a3a; }
.cur { margin-bottom: 14px; }
.cur > div:first-child { font-size: 18px; margin-bottom: 8px; }
.cur .bar i { height: 12px; }
.wk { display: grid; grid-template-columns: 6.5em 1fr 4.5em; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 8px; }
.wk.today { background: var(--tint); font-weight: 600; }
.wk .lv { text-align: right; color: var(--muted); }
.notice { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 0 0 8px;
  padding: 8px 12px; border-radius: 10px; background: var(--tint); font-size: 15px; }
.notice button { padding: 6px 12px; }
.card.help { max-height: 92vh; overflow-y: auto; }
#helpBody p { margin: 0 0 10px; }
#helpBody h3 { margin: 16px 0 6px; font-size: 15px; color: var(--fg); text-transform: none; letter-spacing: 0; }
.ex { display: flex; flex-wrap: wrap; gap: 14px 20px; margin: 0 0 10px; }
.ex figure { margin: 0; }
.ex figcaption { font-size: 13px; margin-top: 4px; color: var(--muted); }
.ex figcaption b { font-weight: 700; }
.ex .ok b { color: #2e9e56; }
.ex .no b { color: var(--bad); }
.mini { display: block; max-width: 100%; height: auto; }
.mini text { text-anchor: middle; dominant-baseline: central; font-size: 24px; font-weight: 600; fill: var(--fg); font-family: inherit; }
.mini text.bad { fill: var(--bad); }

/* desktop: board uses the full height on the left, controls sit in a compact side column */
@media (min-width: 820px) {
  main { max-width: 1040px; display: grid; grid-template-columns: minmax(0, 1fr) 320px;
    grid-template-rows: auto repeat(7, auto) 1fr; column-gap: 28px; align-content: stretch; padding-top: 10px; }
  header { grid-column: 1 / -1; grid-row: 1; }
  .tabs { grid-column: 2; grid-row: 2; }
  #levels { grid-column: 2; grid-row: 3; }
  #newDaily { grid-column: 2; grid-row: 4; }
  #resultBar { grid-column: 2; grid-row: 5; }
  .meta { grid-column: 2; grid-row: 6; }
  .tools { grid-column: 2; grid-row: 7; flex-wrap: wrap; margin-top: 4px; }
  #pad { grid-column: 2; grid-row: 8; grid-template-columns: repeat(3, 1fr); }
  #boardWrap { grid-column: 1; grid-row: 2 / 10; }
  h1 { font-size: 24px; }
  button { padding: 7px 10px; font-size: 15px; }
  .tools button { flex: 1 1 40%; padding: 8px 6px; }
  #pad button { padding: 10px 0; font-size: 20px; }
}
.card { max-height: 92vh; overflow-y: auto; }
#toast { position: fixed; left: 50%; top: 64px; transform: translateX(-50%); background: var(--fg); color: var(--bg);
  padding: 9px 16px; border-radius: 20px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 20; }
#toast.show { opacity: 1; }
