/* Layout: one working column (max 960px) under a top bar; bottom tab bar on phones.
   Looks are chosen in Settings (data-skin on <html>): Plain (default, black on white), Plain dark,
   Yellow pad (bright legal pad with blue rules and a red margin) and Terminal (green on black).
   Each look is deliberate and ignores the device's dark mode; the viewer picks it instead. */
:root {
  --bg: #FFFFFF;
  --surface: #FFFFFF;
  --sunk: #F1F1F1;
  --ink: #111111;
  --muted: #5C5C5C;
  --line: #D6D6D6;
  --rule: transparent;
  --margin: transparent;
  --accent: #111111;
  --accent-ink: #FFFFFF;
  --binding: #111111;
  --binding-ink: #FFFFFF;
  --open: #157A3D;
  --warn: #A55A00;
  --over: #C62828;
  --open-bg: #E3F4E8;
  --warn-bg: #FDF0DC;
  --over-bg: #FCE4E2;
  --body: "Atkinson Hyperlegible", "Segoe UI", system-ui, sans-serif;
  --display: var(--body);
  --mono: "JetBrains Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
  --r: 8px;
  --shadow: 0 1px 2px rgb(0 0 0 / .06);
  color-scheme: light;
}
:root[data-skin="dark"] {
  --bg: #0B0B0B; --surface: #161616; --sunk: #222222; --ink: #F2F2F2; --muted: #A6A6A6; --line: #333333;
  --accent: #F2F2F2; --accent-ink: #0B0B0B; --binding: #000000; --binding-ink: #F2F2F2;
  --open: #5BD38A; --warn: #F2B544; --over: #FF6B61; --open-bg: #12301F; --warn-bg: #3A2B0E; --over-bg: #3B1614;
  --shadow: none; color-scheme: dark;
}
:root[data-skin="yellowpad"] {
  --bg: #FFF06B;          /* legal-pad yellow */
  --surface: #FFF6A3;     /* the top sheet, still yellow */
  --sunk: #FFE73D;
  --ink: #18235A;         /* blue-black pen */
  --muted: #4B5683;       /* pencil grey-blue */
  --line: #F0D63A;
  --rule: #8DB8E8;        /* blue ruling */
  --margin: #F0504C;      /* red margin line */
  --accent: #1E4FD0;      /* blue pen */
  --accent-ink: #FFFFFF;
  --binding: #18235A; --binding-ink: #FFF06B;
  --open: #12733A; --warn: #A34A00; --over: #C8221A;
  --open-bg: #D4F0A8; --warn-bg: #FFD98A; --over-bg: #FFC9BC;
  --display: "Kalam", "Segoe Print", "Comic Sans MS", cursive;
  --r: 3px;
  --shadow: 0 2px 6px rgb(24 35 90 / .08);
  color-scheme: light;
}
:root[data-skin="terminal"] {
  --bg: #050A06; --surface: #0A140C; --sunk: #102014; --ink: #46F27A; --muted: #2E9F52; --line: #1C4A2A;
  --accent: #46F27A; --accent-ink: #031006; --binding: #050A06; --binding-ink: #46F27A;
  --open: #46F27A; --warn: #FFD25A; --over: #FF5D5D; --open-bg: #0F2E18; --warn-bg: #332A0B; --over-bg: #351212;
  --body: var(--mono); --display: var(--mono);
  --r: 0; --shadow: none; color-scheme: dark;
}
/* Text font override, picked in Settings. Later rules win over the look's default. */
:root[data-font="system"] { --body: system-ui, "Segoe UI", Roboto, sans-serif; }
:root[data-font="serif"] { --body: Georgia, "Times New Roman", serif; }
:root[data-font="mono"] { --body: var(--mono); }
:root[data-font="hand"] { --body: "Kalam", "Segoe Print", cursive; }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background-color: var(--bg);
  color: var(--ink); font: 1rem/1.5 var(--body);
  padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px));
}
:root[data-skin="yellowpad"] body {
  --mx: max(5px, calc(50% - 506px));
  background-image:
    linear-gradient(to right, transparent var(--mx), var(--margin) var(--mx) calc(var(--mx) + 1.5px),
      transparent calc(var(--mx) + 1.5px) calc(var(--mx) + 5px), var(--margin) calc(var(--mx) + 5px) calc(var(--mx) + 6.5px), transparent calc(var(--mx) + 6.5px)),
    repeating-linear-gradient(to bottom, transparent 0 31px, var(--rule) 31px 32px);
  background-attachment: fixed, scroll;
}
:root[data-skin="terminal"] .clock { text-shadow: 0 0 18px color-mix(in srgb, var(--ink) 45%, transparent); }
@media (min-width: 760px) { body { padding-bottom: 32px; } }
h1, h2, h3 { font-family: var(--display); line-height: 1.15; text-wrap: balance; margin: 0; }
h1 { font-size: 1.8rem; font-weight: 700; }
h2 { font-size: 1.3rem; font-weight: 700; }
h3 { font-size: 1.05rem; font-weight: 700; }
:root[data-skin="yellowpad"] h1 { font-size: 2.1rem; }
:root[data-skin="yellowpad"] h2 { font-size: 1.5rem; }
:root[data-skin="yellowpad"] h3 { font-size: 1.2rem; }
p { margin: 0; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.label { font-size: .75rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 700; }

.wrap {
  max-width: 960px; margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 20px;
  display: flex; flex-direction: column; gap: 20px;
}

/* Top bar */
.top {
  background: var(--binding); color: var(--binding-ink); position: sticky; top: 0; z-index: 20;
  border-bottom: 1px solid var(--line);
}
:root[data-skin="yellowpad"] .top { border-bottom: 0; box-shadow: 0 3px 0 var(--margin), 0 6px 10px rgb(24 35 90 / .15); }
.top-inner {
  max-width: 960px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-top: env(safe-area-inset-top, 0px); min-height: 52px;
}
.brand { font-family: var(--display); font-weight: 700; font-size: 1.25rem; color: inherit; text-decoration: none; }
:root[data-skin="yellowpad"] .brand { font-size: 1.5rem; padding-top: 4px; }
.top-right { display: flex; align-items: center; gap: 10px; }
.account {
  background: none; color: inherit; border: 1px solid color-mix(in srgb, var(--binding-ink) 40%, transparent);
  padding: 6px 12px; font-size: .875rem; border-radius: 999px; white-space: nowrap;
}
.account:hover { border-color: var(--binding-ink); }
.acct-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--binding-ink); opacity: .6; }
.acct-dot.open { background: var(--open); opacity: 1; }
.acct-dot.warn { background: var(--warn); opacity: 1; }
.acct-dot.over { background: var(--over); opacity: 1; }
@media (max-width: 420px) { .acct-text { display: none; } }

/* Corner timer: stays top-right while you're writing notes */
.mini {
  position: fixed; z-index: 25; display: flex; align-items: stretch;
  top: calc(env(safe-area-inset-top, 0px) + 62px); right: max(12px, env(safe-area-inset-right, 0px));
  background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 999px;
  box-shadow: 0 4px 14px rgb(0 0 0 / .18); overflow: hidden;
}
.mini[data-phase="open"] { background: var(--open-bg); border-color: var(--open); }
.mini[data-phase="warn"] { background: var(--warn-bg); border-color: var(--warn); }
.mini[data-phase="over"] { background: var(--over-bg); border-color: var(--over); }
.mini button { border: 0; border-radius: 0; background: none; color: inherit; }
.mini-time { gap: 8px; padding: 8px 12px 8px 14px; font-size: 1.25rem; font-weight: 700; }
.mini-label { font: 700 .7rem var(--body); letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.mini-btn { padding: 8px 14px; border-left: 1px solid var(--line) !important; font-size: .9rem; }
.subnav { align-self: flex-start; }

/* Mini timer: the whole window is the clock */
:root[data-compact] body > *:not(#compact):not(#toast) { display: none !important; }
:root[data-compact] body { padding: 0; }
.compact {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  height: 100vh; padding: 8px 10px; background: var(--bg); color: var(--ink); text-align: center;
  transition: background-color .3s;
}
.compact[data-phase="open"] { background: var(--open-bg); }
.compact[data-phase="warn"] { background: var(--warn-bg); }
.compact[data-phase="over"] { background: var(--over-bg); }
.c-time { font: 700 clamp(2.4rem, 24vw, 5rem)/1 var(--mono); font-variant-numeric: tabular-nums; letter-spacing: -.03em; }
.c-sub { font-size: .8rem; color: var(--muted); font-weight: 700; display: flex; align-items: center; gap: 6px; }
.c-btns { display: flex; gap: 6px; }
.c-btns button { padding: 5px 12px; font-size: .85rem; }

/* Bulk motion import */
.modal.wide { max-width: 760px; }
.imp-list { display: flex; flex-direction: column; max-height: 48vh; overflow: auto; border: 1px solid var(--line); border-radius: var(--r); }
.imp-item { padding: 10px 12px; border-top: 1px solid var(--line); }
.imp-item:first-child { border-top: 0; }
.imp-item > span { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.imp-motion { font-weight: 700; }

.tabs { display: flex; gap: 4px; }
.tabs button {
  background: none; border: 0; color: inherit; opacity: .7; font: 600 .95rem var(--body);
  padding: 8px 12px; border-radius: 8px; cursor: pointer;
}
.tabs button:hover { opacity: 1; }
.tabs button[aria-current="page"] { opacity: 1; background: color-mix(in srgb, var(--binding-ink) 18%, transparent); }
@media (max-width: 759px) {
  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0; background: var(--surface); color: var(--ink);
    border-top: 1px solid var(--line); justify-content: space-around; z-index: 30;
    padding: 6px max(8px, env(safe-area-inset-right, 0px)) calc(6px + env(safe-area-inset-bottom, 0px)) max(8px, env(safe-area-inset-left, 0px));
  }
  .tabs button { flex: 1; padding: 10px 4px; font-size: .8rem; }
  .tabs button[aria-current="page"] { background: var(--sunk); color: var(--accent); }
}

/* Generic pieces */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 16px;
  display: flex; flex-direction: column; gap: 12px; min-width: 0;
  box-shadow: var(--shadow);
}
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.row > * { min-width: 0; }
.spread { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }

button, .btn {
  font: 700 .95rem var(--body); border-radius: 8px; border: 1px solid var(--line); background: var(--surface);
  color: var(--ink); padding: 9px 14px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; justify-content: center;
}
button:hover { border-color: var(--muted); }
button:disabled { opacity: .45; cursor: not-allowed; }
.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.primary:hover { border-color: var(--accent); filter: brightness(1.08); }
.danger { color: var(--over); }
.ghost { background: none; border-color: transparent; }
.big { padding: 14px 22px; font-size: 1.05rem; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

label.field { display: flex; flex-direction: column; gap: 4px; font-size: .875rem; color: var(--muted); font-weight: 700; min-width: 0; }
input, select, textarea {
  font: 1rem var(--body); color: var(--ink); background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; padding: 9px 10px; width: 100%; min-width: 0;
}
textarea { resize: vertical; min-height: 96px; line-height: 1.6; }
/* On the yellow pad, notes are written on ruled lines that scroll with the text. */
:root[data-skin="yellowpad"] textarea {
  line-height: 28px; padding: 4px 10px 0 18px;
  background-color: var(--surface);
  background-image:
    linear-gradient(to right, transparent 9px, color-mix(in srgb, var(--margin) 70%, transparent) 9px 10.5px, transparent 10.5px),
    linear-gradient(to bottom, transparent 27px, var(--rule) 27px);
  background-size: 100% 100%, 100% 28px;
  background-position: 0 0, 0 4px;
  background-attachment: local;
}
input[type="checkbox"], input[type="radio"] { width: 18px; height: 18px; accent-color: var(--accent); flex: none; margin: 2px 0 0; }
.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 400; color: var(--ink); font-size: .95rem; cursor: pointer; }

.seg { display: inline-flex; background: var(--sunk); border-radius: 9px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: none; padding: 7px 12px; font-size: .875rem; }
.seg button[aria-pressed="true"] { background: var(--surface); box-shadow: 0 1px 2px rgb(0 0 0 / .12); }

.pill { display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; padding: 3px 10px; font-size: .8rem; font-weight: 700; background: var(--sunk); color: var(--muted); }
.pill.open { background: var(--open-bg); color: var(--open); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.over { background: var(--over-bg); color: var(--over); }
.pill.accent { background: color-mix(in srgb, var(--accent) 15%, transparent); color: var(--accent); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.rec-dot { animation: blink 1.2s infinite; }
@keyframes blink { 50% { opacity: .25; } }

.notice { border-radius: var(--r); padding: 12px 14px; background: var(--warn-bg); color: var(--ink); border: 1px solid color-mix(in srgb, var(--warn) 40%, transparent); font-size: .925rem; }
.notice.stop { background: var(--over-bg); border-color: color-mix(in srgb, var(--over) 45%, transparent); }
.notice strong { color: var(--ink); }

.empty { text-align: center; padding: 32px 16px; color: var(--muted); display: flex; flex-direction: column; gap: 12px; align-items: center; }

/* Timer */
.timer-card { padding: 20px; gap: 16px; transition: background-color .3s; }
.timer-card[data-phase="open"] { background: color-mix(in srgb, var(--open-bg) 55%, var(--surface)); }
.timer-card[data-phase="warn"] { background: color-mix(in srgb, var(--warn-bg) 60%, var(--surface)); }
.timer-card[data-phase="over"] { background: var(--over-bg); }
.clock {
  font-family: var(--mono); font-weight: 700; font-variant-numeric: tabular-nums;
  font-size: clamp(4.5rem, 22vw, 9.5rem); line-height: 1; letter-spacing: -.04em; text-align: center;
}
.clock-sub { text-align: center; font-family: var(--mono); color: var(--muted); font-size: .95rem; }
.track { position: relative; height: 14px; background: var(--sunk); border-radius: 7px; overflow: visible; margin: 8px 0 22px; }
.track-fill { position: absolute; inset: 0 auto 0 0; width: 0; border-radius: 7px; background: var(--ink); opacity: .85; }
.track[data-phase="open"] .track-fill { background: var(--open); }
.track[data-phase="warn"] .track-fill { background: var(--warn); }
.track[data-phase="over"] .track-fill { background: var(--over); }
.tick { position: absolute; top: -4px; bottom: -4px; width: 2px; background: var(--muted); }
.tick span { position: absolute; top: 22px; left: 50%; transform: translateX(-50%); font: 500 .7rem var(--mono); color: var(--muted); white-space: nowrap; }
.controls { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.live-tx { background: var(--sunk); border-radius: 8px; padding: 10px 12px; font-size: .9rem; max-height: 140px; overflow: auto; }
.live-tx .interim { color: var(--muted); font-style: italic; }

/* Lists */
.list { display: flex; flex-direction: column; gap: 8px; }
.item { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; cursor: pointer; text-align: left; width: 100%; font-weight: 400; }
.item:hover { border-color: var(--muted); }
.item .main { flex: 1 1 260px; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.item .meta { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.motion-text { font-family: var(--display); font-weight: 700; font-size: 1.1rem; line-height: 1.35; }
:root[data-skin="yellowpad"] .motion-text { font-weight: 400; font-size: 1.25rem; }

/* Look picker in Settings */
.skins { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.skin { flex-direction: column; align-items: stretch; gap: 8px; padding: 10px; text-align: left; font-weight: 700; }
.skin[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 2px var(--accent); }
.skin .swatch { height: 56px; border-radius: 4px; border: 1px solid rgb(0 0 0 / .12); display: flex; align-items: flex-end; padding: 6px 8px; font-size: .8rem; }

/* Round speech grid */
.speech-card { gap: 8px; }
.speech-card.mine { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.speech-card textarea { min-height: 116px; }

/* Transcript */
.subs { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.sub { display: grid; grid-template-columns: auto 1fr auto; gap: 4px 12px; padding: 10px 12px; border-top: 1px solid var(--line); background: var(--surface); align-items: start; }
.sub:first-child { border-top: 0; }
.sub.playing { background: color-mix(in srgb, var(--accent) 10%, var(--surface)); }
.sub .idx { font: 500 .75rem var(--mono); color: var(--muted); padding-top: 3px; }
.sub .ts { font: 500 .8rem var(--mono); color: var(--accent); background: none; border: 0; padding: 0; cursor: pointer; justify-content: flex-start; }
.sub .txt { grid-column: 2 / 4; outline: none; border-radius: 4px; }
.sub .txt:focus { background: var(--sunk); }
.sub select { width: auto; padding: 3px 6px; font-size: .8rem; }
.sub .sec-start { grid-column: 1 / -1; font: 700 .72rem var(--body); letter-spacing: .08em; text-transform: uppercase; }

.timeline { display: flex; height: 26px; border-radius: 6px; overflow: hidden; background: var(--sunk); }
.timeline div { min-width: 2px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: .85rem; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

table { border-collapse: collapse; width: 100%; font-size: .925rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: .75rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
td.num, th.num { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }
tr.flag td { background: var(--warn-bg); }

.stat { display: flex; flex-direction: column; gap: 2px; }
.stat b { font: 700 1.9rem var(--mono); font-variant-numeric: tabular-nums; letter-spacing: -.02em; }

.ai-box { border-left: 3px solid var(--accent); padding-left: 12px; display: flex; flex-direction: column; gap: 8px; }
.ai-box ul { margin: 0; padding-left: 18px; }

/* Modal */
.modal-back { position: fixed; inset: 0; background: rgb(8 10 20 / .6); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
@media (min-width: 640px) { .modal-back { align-items: center; padding: 24px; } }
.modal {
  background: var(--surface); color: var(--ink); width: 100%; max-width: 560px; max-height: 92vh; overflow: auto;
  border-radius: 14px 14px 0 0; padding: 20px max(18px, env(safe-area-inset-right, 0px)) calc(20px + env(safe-area-inset-bottom, 0px)) max(18px, env(safe-area-inset-left, 0px));
  display: flex; flex-direction: column; gap: 14px;
}
@media (min-width: 640px) { .modal { border-radius: 14px; } }
.steps { display: flex; gap: 6px; }
.steps i { flex: 1; height: 4px; border-radius: 2px; background: var(--sunk); }
.steps i.on { background: var(--accent); }
.script { font-family: var(--display); font-size: 1.1rem; background: var(--sunk); padding: 12px 14px; border-radius: 8px; }

#toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(86px + env(safe-area-inset-bottom, 0px)); z-index: 60;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-weight: 700; font-size: .9rem; max-width: calc(100% - 32px);
}
@media (min-width: 760px) { #toast { bottom: 24px; } }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
