/* Theme tokens: dark by default, light via prefers-color-scheme or data-theme. */
:root {
  --bg: #111318; --fg: #f2f3f5; --muted: #9aa0ab; --card: #1a1d24; --line: #2a2e38;
  --input-bg: #0d0f13; --btn: #2a2f3a; --btn-hover: #353b48; --track: #2a2f3a;
  --accent: #4f8cff; --accent-hover: #3d78e6; --ok: #3ccf7a; --warn: #f5b942; --danger: #ff5c5c;
  --ok-bg: #14361f; --warn-bg: #3f3210; --danger-bg: #3d1717; --flash-bg: #2a3350;
  --body-warn: #2a2208; --body-danger: #3a1010; --end-flash: #8a1c1c;
  --c-red: #ff6b6b; --c-orange: #ffb347; --c-green: #4fd88a; --c-blue: #6aa3ff; --c-purple: #c79bff;
  --radius: 12px;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f5f6f8; --fg: #16181d; --muted: #5f6570; --card: #ffffff; --line: #d9dde5;
  --input-bg: #ffffff; --btn: #e3e6ec; --btn-hover: #d3d7df; --track: #dfe3ea;
  --accent: #2f6fe0; --accent-hover: #2358bd; --ok: #1f9d55; --warn: #c48a00; --danger: #d93838;
  --ok-bg: #d9f3e3; --warn-bg: #fff1c9; --danger-bg: #ffdcdc; --flash-bg: #dbe6ff;
  --body-warn: #fff3cc; --body-danger: #ffd9d9; --end-flash: #ff9c9c;
  --c-red: #d62828; --c-orange: #d97706; --c-green: #15803d; --c-blue: #1d4ed8; --c-purple: #7e22ce;
  color-scheme: light;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f5f6f8; --fg: #16181d; --muted: #5f6570; --card: #ffffff; --line: #d9dde5;
    --input-bg: #ffffff; --btn: #e3e6ec; --btn-hover: #d3d7df; --track: #dfe3ea;
    --accent: #2f6fe0; --accent-hover: #2358bd; --ok: #1f9d55; --warn: #c48a00; --danger: #d93838;
    --ok-bg: #d9f3e3; --warn-bg: #fff1c9; --danger-bg: #ffdcdc; --flash-bg: #dbe6ff;
    --body-warn: #fff3cc; --body-danger: #ffd9d9; --end-flash: #ff9c9c;
    --c-red: #d62828; --c-orange: #d97706; --c-green: #15803d; --c-blue: #1d4ed8; --c-purple: #7e22ce;
    color-scheme: light;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--fg);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh; display: flex; flex-direction: column;
  /* keep content clear of the iOS status bar / notch when installed (viewport-fit=cover) */
  padding-top: env(safe-area-inset-top);
  padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
a { color: var(--accent); }
h1 { font-size: 1.6rem; margin: .2em 0 .5em; }
h2 { font-size: 1.1rem; margin: .8em 0 .4em; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .9em; word-break: break-all; }
.muted { color: var(--muted); }
.lead { font-size: 1.1rem; color: var(--muted); }

.top { display: flex; align-items: center; gap: 1rem; padding: .8rem 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.top nav { display: flex; gap: 1rem; align-items: center; margin-left: auto; flex-wrap: wrap; }
.brand { font-weight: 700; color: var(--fg); text-decoration: none; }
.brand.small { font-size: .9rem; color: var(--muted); }
.page { max-width: 880px; width: 100%; margin: 0 auto; padding-block: 1rem 2rem; flex: 1; }
.foot { text-align: center; color: var(--muted); font-size: .85rem; padding: 1rem 0 max(1rem, env(safe-area-inset-bottom)); }
.foot a { color: var(--muted); }
.crumbs { color: var(--muted); }

input, button, select { font: inherit; }
input { background: var(--input-bg); color: var(--fg); border: 1px solid var(--line); border-radius: 8px; padding: .55em .7em; width: 100%; }
label { display: flex; flex-direction: column; gap: .3em; font-size: .95rem; }
label.check { flex-direction: row; align-items: center; gap: .5em; }
label.check input { width: auto; }
label.strong { font-weight: 600; }
button { background: var(--btn); color: var(--fg); border: 0; border-radius: 8px; padding: .55em 1em; cursor: pointer; }
button:hover { background: var(--btn-hover); }
button.primary { background: var(--accent); color: #fff; }
button.primary:hover { background: var(--accent-hover); }
button.danger { background: var(--danger); color: #fff; }
button.danger:hover { filter: brightness(.9); }
button.link { background: none; color: var(--accent); padding: 0; }
button.small { padding: .3em .7em; font-size: .85rem; }
button.icon { background: none; font-size: 1.3rem; padding: .2em .35em; line-height: 1; text-decoration: none; color: var(--fg); }
button.icon[aria-pressed="true"], .bar .icon[aria-pressed="true"] { background: var(--btn); border-radius: 8px; }
form.inline { display: inline; }
.stack { display: flex; flex-direction: column; gap: .8rem; }
.narrow { max-width: 420px; }
.row { display: flex; gap: .6rem; align-items: flex-end; }
.row.wrap { flex-wrap: wrap; }
.row > .grow { flex: 1 1 200px; }
.grow { flex: 1; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }
.card.danger { border-color: var(--danger); }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1rem; }
fieldset.ext { border: 1px solid var(--line); border-radius: 8px; padding: .6rem .9rem; margin: 0; }
fieldset.ext p { margin: .2em 0 .6em; }
.flash { padding: .6em .9em; border-radius: 8px; }
.flash.ok { background: var(--ok-bg); } .flash.err { background: var(--danger-bg); }
table.list { width: 100%; border-collapse: collapse; }
table.list th, table.list td { text-align: left; padding: .5em .4em; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list .actions a { margin-right: .6em; }
.cards { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: .5rem; }
.cards li a { display: block; background: var(--card); border: 1px solid var(--line); padding: .6em 1em; border-radius: 8px; text-decoration: none; }
.pill { padding: .1em .6em; border-radius: 999px; font-size: .8rem; background: var(--btn); }
.pill.state-running { background: var(--ok-bg); color: var(--ok); }
.pill.state-paused { background: var(--warn-bg); color: var(--warn); }
.pill.state-ended { background: var(--danger-bg); color: var(--danger); }
.badge { background: var(--danger); color: #fff; font-size: .75rem; padding: .1em .5em; border-radius: 999px; }
.qr { width: min(70vw, 360px); background: #fff; padding: 12px; border-radius: 12px; }
.qr.small { width: 160px; padding: 8px; }
.share { text-align: center; }
.share .url { font-family: ui-monospace, monospace; word-break: break-all; }
.code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-weight: 700; letter-spacing: .12em;
  font-size: clamp(1.6rem, 6vw, 2.6rem); background: var(--input-bg); border: 1px solid var(--line);
  border-radius: 10px; padding: .25em .6em; display: inline-block; user-select: all; }
.share .code { margin: .4em 0; }
.messages { list-style: none; padding: 0; }
.messages li { padding: .4em 0; border-bottom: 1px solid var(--line); display: flex; gap: .6em; justify-content: space-between; }
.groups { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: .6rem; }
.groups li { background: var(--input-bg); border: 1px solid var(--line); padding: .4em .8em; border-radius: 8px; }

/* --- timer view ----------------------------------------------------------- */
body.viewer { transition: background .6s; }
body.viewer.state-running.warn { background: var(--body-warn); }
body.viewer.state-running.danger { background: var(--body-danger); }
body.viewer.state-ended { background: var(--body-danger); }
.timer-main { flex: 1; display: flex; flex-direction: column; width: 100%; max-width: 1200px; margin: 0 auto; }
.bar { display: flex; align-items: center; gap: .6rem; padding: .6rem 0; flex-wrap: wrap; }
.bar button.small { white-space: nowrap; }
.bar .icon { background: none; font-size: 1.3rem; padding: .2em .35em; line-height: 1; text-decoration: none; color: var(--fg); }
.clock { flex: 1; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; padding: 1rem 0; }
.clock h1 { font-size: clamp(1.1rem, 3vw, 2rem); color: var(--muted); font-weight: 500; margin: 0 0 .3em; }
.time { font-variant-numeric: tabular-nums; font-weight: 700; line-height: 1; letter-spacing: .02em;
  font-size: clamp(4rem, 22vw, 18rem); }
.time.small { font-size: 3rem; }
.time.overtime { color: var(--danger); }
.status { color: var(--muted); margin-top: .6em; min-height: 1.5em; font-size: clamp(1rem, 2.5vw, 1.4rem); }
.progress { width: min(90vw, 700px); height: 8px; background: var(--track); border-radius: 4px; margin-top: 1.2rem; overflow: hidden; }
#progress-bar { height: 100%; width: 100%; background: var(--ok); transition: width .3s linear; }
body.warn #progress-bar { background: var(--warn); }
body.danger #progress-bar, body.state-ended #progress-bar { background: var(--danger); }
.hint { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: .6em .9em; margin: .5rem 0; }
.controls { display: flex; flex-wrap: wrap; gap: .5rem; justify-content: center; padding: .6rem 0; }
.controls button { min-width: 5.5em; }
.adjust-wrap { padding-top: 0; }
.adjust { display: flex; flex-direction: column; gap: .4rem; width: min(100%, 560px); }
.adjust-row { display: flex; gap: .4rem; justify-content: center; }
.adjust-row button { min-width: 0; flex: 1 1 0; padding: .45em .4em; font-size: .9rem; font-variant-numeric: tabular-nums; }
/* time's up: hold on 00:00, pulse the digits and flash the screen before overtime starts */
.time.zero { animation: zero-pulse 1s ease-in-out infinite; }
@keyframes zero-pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.06); } }
body.viewer.just-ended { animation: end-flash .5s steps(1) 6; }
body.viewer.just-ended .time { color: var(--fg); }
@keyframes end-flash { 0% { background: var(--end-flash); } 50% { background: var(--body-danger); } }
.ext-area { display: flex; flex-direction: column; gap: .8rem; padding-bottom: 1rem; }
.ext-block { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem 1rem; }
.ext-block h2 { margin: 0 0 .4em; font-size: .9rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
/* messages sit directly under the clock, big and bold */
.ext-top { width: min(92vw, 900px); margin-top: 1.2rem; }
.ext-top .ext-block { background: none; border: 0; padding: 0; }
.ext-top .ext-block h2 { display: none; }
.ext-messages .list { display: flex; flex-direction: column; gap: .3em; }
.ext-messages .msg { padding: .25em 0; font-weight: 700; font-size: clamp(1.1rem, 3vw, 1.6rem); color: var(--muted); line-height: 1.3; }
.ext-messages .msg:last-child { font-size: clamp(1.5rem, 5vw, 2.8rem); color: var(--fg); }
.color-red { color: var(--c-red); } .color-orange { color: var(--c-orange); } .color-green { color: var(--c-green); }
.color-blue { color: var(--c-blue); } .color-purple { color: var(--c-purple); }
.ext-messages .msg.color-red { color: var(--c-red); } .ext-messages .msg.color-orange { color: var(--c-orange); }
.ext-messages .msg.color-green { color: var(--c-green); } .ext-messages .msg.color-blue { color: var(--c-blue); }
.ext-messages .msg.color-purple { color: var(--c-purple); }
/* colour swatches in the send form */
.swatches { display: inline-flex; gap: .3em; align-items: center; align-self: center; }
.swatch { position: relative; width: 1.5em; height: 1.5em; cursor: pointer; }
.swatch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.swatch span { display: block; width: 100%; height: 100%; border-radius: 50%; border: 2px solid var(--line); background: var(--fg); }
.swatch.color-red span { background: var(--c-red); } .swatch.color-orange span { background: var(--c-orange); }
.swatch.color-green span { background: var(--c-green); } .swatch.color-blue span { background: var(--c-blue); }
.swatch.color-purple span { background: var(--c-purple); }
.swatch input:checked + span { border-color: var(--fg); box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--fg); }
.swatch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.ext-messages .msg.new { animation: flash 1.2s; border-radius: 8px; }
.ext-messages form { margin-top: .8rem; }
@keyframes flash { from { background: var(--flash-bg); } to { background: transparent; } }
.ext-groups .group { font-size: clamp(1.4rem, 5vw, 2.4rem); font-weight: 700; text-align: center; }
.ext-groups .group.new { animation: flash 1.2s; border-radius: 8px; }
.ext-groups .admin { display: flex; gap: .8rem; align-items: center; justify-content: center; flex-wrap: wrap; margin-top: .6rem; color: var(--muted); font-size: .9rem; }
.ext-groups .group .count { display: inline-flex; flex-direction: column; align-items: center; margin: 0 .6em; line-height: 1.1; }
.ext-groups .group .count small { font-size: .45em; font-weight: 500; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.live { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }

@media (max-width: 600px) {
  .controls button { flex: 1 1 28%; min-width: 0; }
  .adjust-row button { flex: 1 1 0; padding: .45em .2em; font-size: .8rem; }
  table.list th:nth-child(4), table.list td:nth-child(4) { display: none; }
}
@media print {
  body { background: #fff; color: #000; }
  .top, .foot, .noprint { display: none; }
  .qr { width: 70vw; }
  .code { color: #000; background: #fff; border-color: #000; }
}
