/* Fieldnote: warm paper palette, plain utility layout, light and dark. */

:root {
  --bg: #f6f1e7;
  --surface: #fffcf6;
  --surface-2: #efe7d8;
  --ink: #2a2520;
  --muted: #6d6358;
  --line: #ddd2bf;
  --accent: #a8471f;
  --accent-ink: #fffaf2;
  --accent-soft: #f3dccd;
  --logo-ink: #fffaf2;
  --warn: #c98a0c;
  --warn-bg: #fbe7a6;
  --warn-ink: #4a3500;
  --ok: #3d7a4c;
  --danger: #a33a2c;
  --focus: #2f6db3;
  --flash: #ffd34d;
  --flash-ink: #3a2a00;
  --flash-edge: #c98a0c;
  --flash-end: #ffd34d;
  --event-bg: #e6eef0;
  --event-line: #b9cdd3;
  --event-ink: #2f5d6b;
  --serif: 'Iowan Old Style', 'Palatino Linotype', Palatino, 'Book Antiqua', Georgia, serif;
  --sans: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  --radius: 12px;
  --tap: 48px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #1b1916;
    --surface: #24211d;
    --surface-2: #2f2a24;
    --ink: #eee7da;
    --muted: #a99e8f;
    --line: #3d372f;
    --accent: #e08a5c;
    --accent-ink: #1b1916;
    --accent-soft: #4a2e1f;
    --logo-ink: #1b1916;
    --warn: #e7b53b;
    --warn-bg: #5a4510;
    --warn-ink: #fff1c7;
    --ok: #79b98a;
    --danger: #ef8a7a;
    --focus: #7fb0ea;
    --flash: #24211d;
    --flash-ink: #eee7da;
    --flash-edge: #ffd34d;
    --flash-end: #c99a1a;
    --event-bg: #1e2b30;
    --event-line: #35505a;
    --event-ink: #8fc3d1;
    color-scheme: dark;
  }
}

:root[data-theme='dark'] {
  --bg: #1b1916;
  --surface: #24211d;
  --surface-2: #2f2a24;
  --ink: #eee7da;
  --muted: #a99e8f;
  --line: #3d372f;
  --accent: #e08a5c;
  --accent-ink: #1b1916;
  --accent-soft: #4a2e1f;
  --logo-ink: #1b1916;
  --warn: #e7b53b;
  --warn-bg: #5a4510;
  --warn-ink: #fff1c7;
  --ok: #79b98a;
  --danger: #ef8a7a;
  --focus: #7fb0ea;
  --flash: #24211d;
  --flash-ink: #eee7da;
  --flash-edge: #ffd34d;
  --flash-end: #c99a1a;
  --event-bg: #1e2b30;
  --event-line: #35505a;
  --event-ink: #8fc3d1;
  color-scheme: dark;
}

/* Outdoor contrast: set in Settings, or by the device's Increase contrast setting.
   Darker secondary text and solid edges, so buttons still read as buttons in sun glare. */
:root[data-contrast='more'] {
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #efe9df;
  --ink: #14110e;
  --muted: #3b342d;
  --line: #6f6455;
  --accent: #8f3a17;
  --accent-soft: #f3d4c1;
  --ok: #24592f;
  --danger: #8e2a1e;
  --event-bg: #eaf2f4;
  --event-line: #4f7480;
  --event-ink: #1f4855;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light'])[data-contrast='more'] {
    --bg: #000000;
    --surface: #12100e;
    --surface-2: #24201b;
    --ink: #fbf7f0;
    --muted: #ddd4c6;
    --line: #a39887;
    --accent: #f2a77f;
    --accent-soft: #5a3420;
    --ok: #92d8a3;
    --danger: #ff9d8e;
    --event-bg: #0f1d22;
    --event-line: #6f98a6;
    --event-ink: #a9dceb;
  }
}

:root[data-theme='dark'][data-contrast='more'] {
  --bg: #000000;
  --surface: #12100e;
  --surface-2: #24201b;
  --ink: #fbf7f0;
  --muted: #ddd4c6;
  --line: #a39887;
  --accent: #f2a77f;
  --accent-soft: #5a3420;
  --ok: #92d8a3;
  --danger: #ff9d8e;
  --event-bg: #0f1d22;
  --event-line: #6f98a6;
  --event-ink: #a9dceb;
}

[data-contrast='more'] .btn, [data-contrast='more'] .behavior, [data-contrast='more'] .channel,
[data-contrast='more'] .pill, [data-contrast='more'] .timer, [data-contrast='more'] .panel { border-width: 2px; }
[data-contrast='more'] .scored { font-weight: 800; font-size: 0.95rem; }
[data-contrast='more'] .tdot { border-width: 2px; }
[data-contrast='more'] .behavior:disabled, [data-contrast='more'] .btn:disabled { opacity: 0.6; }

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 var(--sans);
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
}

h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.2; margin: 0; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.05rem; margin-top: 0.5rem; }
p { margin: 0.25rem 0 0.75rem; }
a { color: var(--accent); }
kbd { font-family: var(--mono); }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.block { display: block; }
.warn-text { color: var(--warn); }
.lede { color: var(--muted); font-size: 1.02rem; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 44px;
  padding: 0.5rem 1rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  font: 600 0.95rem/1.2 var(--sans);
  cursor: pointer;
  text-decoration: none;
  touch-action: manipulation;
}
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: var(--accent-ink); }
.btn.danger-ghost { color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.small { min-height: 36px; padding: 0.3rem 0.75rem; font-size: 0.85rem; }
.btn.big { min-height: 56px; font-size: 1.05rem; }
.btn.wide { width: 100%; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--ink);
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn.remove { width: 36px; height: 36px; font-size: 1.3rem; color: var(--muted); flex: none; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  min-height: 34px;
  padding: 0.25rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font: 600 0.8rem/1 var(--sans);
  cursor: pointer;
  white-space: nowrap;
}
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.pill.ok .dot { background: var(--ok); }
.pill.wait { color: var(--ink); }
.pill.wait .dot { background: var(--warn); }
.pill.busy .dot { background: var(--focus); }
.pill.auth { border-color: var(--danger); color: var(--danger); }
.pill.auth .dot { background: var(--danger); }

.row { display: flex; gap: 0.5rem; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.row.end { justify-content: flex-end; }

/* ---------- page frame ---------- */

.page { min-height: 100dvh; display: flex; flex-direction: column; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: calc(0.5rem + env(safe-area-inset-top)) 1rem 0.5rem;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.topbar-title { font-size: 1.25rem; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-actions { display: flex; align-items: center; gap: 0.25rem; }
.brand-mark { color: var(--accent); display: inline-grid; place-items: center; width: 36px; }
.back { font-size: 2rem; margin-left: -0.5rem; }
/* Text zoomed to 150–200%: the title gets its own row and the pill shrinks to its dot. */
@media (max-width: 340px) {
  .topbar { position: static; flex-wrap: wrap; }
  .topbar-title { order: 3; flex-basis: 100%; white-space: normal; }
  .topbar-actions { margin-left: auto; }
  .topbar .sync-pill .pill-text { display: none; }
  .section-head { flex-wrap: wrap; }
  .list-row { flex-wrap: wrap; min-width: 0; }
  .question-row input:first-child, .question-row .grow { flex: 1 1 100%; }
  .list-row input[type='text'] { flex: 1 1 8rem; }
  .channel-edit-head { flex-wrap: wrap; }
  .channel-edit-head select, .question-row select { flex: 1 1 100%; width: 100%; }
  .grid-2 { grid-template-columns: 1fr; }
  input, select { min-width: 0; max-width: 100%; }
}

.content { width: 100%; max-width: 1080px; margin: 0 auto; padding: 1rem 1rem 3rem; }
.content.narrow { max-width: 760px; }

.section-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin: 1.25rem 0 0.75rem; }

.notice {
  padding: 0.75rem 1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
  margin: 0.75rem 0;
}
.notice.error { border-color: var(--danger); color: var(--danger); background: var(--surface); }
.notice.error ul { margin: 0; padding-left: 1.2rem; }
.notice.warn.backup-notice, .notice.warn.install-notice { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem 1rem; flex-wrap: wrap; }
.notice.warn.backup-notice p, .notice.warn.install-notice p { margin: 0 0 0.35rem; flex: 1 1 18rem; }
.notice.warn.install-notice > div { flex: 1 1 18rem; }
.ok-text { color: var(--ok); font-weight: 600; }
.backup-panel h3 { margin-top: 0; }
.backup-panel.urgent { border: 2px solid var(--warn); background: var(--warn-bg); color: var(--warn-ink); }
.notice.active-session { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; border-color: var(--accent); }

.empty { padding: 2rem 1rem; text-align: center; border: 1px dashed var(--line); border-radius: var(--radius); color: var(--muted); }

/* ---------- sign-in ---------- */

.signin { position: relative; min-height: 100dvh; display: grid; justify-items: center; align-content: start; gap: 2rem; padding: 3rem 1rem 2rem; }
.signin-card { width: 100%; max-width: 420px; display: grid; gap: 0.75rem; }
.signin-card h1 { font-size: 2.4rem; }
.signin-logo { color: var(--accent); }
.signin-theme { position: absolute; top: calc(0.5rem + env(safe-area-inset-top)); right: 0.75rem; }
.signin-logo svg { width: 56px; height: 56px; }

/* ---------- forms ---------- */

.field { display: grid; gap: 0.35rem; margin: 0 0 1rem; border: 0; padding: 0; min-width: 0; }
.field-label { font-weight: 600; font-size: 0.92rem; padding: 0; }
.field-hint { color: var(--muted); font-size: 0.82rem; }

input[type='text'], input[type='url'], input[type='number'], input[type='email'], input[type='date'], select, textarea {
  width: 100%;
  min-height: 44px;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  font: 1rem/1.3 var(--sans);
}
textarea { resize: vertical; }
input:disabled { opacity: 0.5; }
input[type='color'] { width: 44px; height: 44px; padding: 2px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); flex: none; }
input.strong { font-weight: 700; font-family: var(--serif); font-size: 1.05rem; }

.choice { display: flex; gap: 0.75rem; align-items: flex-start; padding: 0.75rem; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); cursor: pointer; }
.choice input { margin-top: 0.25rem; accent-color: var(--accent); width: 18px; height: 18px; }

.toggle { display: inline-flex; align-items: center; gap: 0.6rem; min-height: 44px; cursor: pointer; margin-right: 1rem; }
.toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.toggle-track { width: 42px; height: 26px; border-radius: 13px; background: var(--line); position: relative; flex: none; transition: background 0.15s; }
.toggle-track::after { content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: var(--surface); box-shadow: 0 1px 2px rgb(0 0 0 / 0.25); transition: transform 0.15s; }
.toggle input:checked + .toggle-track { background: var(--accent); }
.toggle input:checked + .toggle-track::after { transform: translateX(16px); }
.toggle input:focus-visible + .toggle-track { outline: 3px solid var(--focus); outline-offset: 2px; }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 0.75rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 0.75rem; }
@media (max-width: 560px) {
  .grid-3 { grid-template-columns: 1fr; }
}

.chips { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.chip { position: relative; cursor: pointer; }
.chip input { position: absolute; opacity: 0; }
.chip span {
  display: inline-flex; align-items: center; gap: 0.5rem; min-height: 44px; padding: 0.4rem 0.9rem;
  border: 1px solid var(--line); border-radius: 999px; background: var(--surface); font-weight: 600;
}
.chip span::before { content: ''; width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--subject); }
.chip input:checked + span { border-color: var(--subject); background: color-mix(in srgb, var(--subject) 14%, var(--surface)); }
.chip input:checked + span::before { background: var(--subject); }
.chip input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }

.segmented { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.segmented label { position: relative; cursor: pointer; }
.segmented input { position: absolute; opacity: 0; }
.segmented span { display: inline-flex; align-items: center; min-height: 40px; padding: 0.35rem 0.85rem; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.segmented input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.segmented input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }

/* ---------- home ---------- */

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr)); gap: 0.75rem; }
.card {
  display: flex; flex-direction: column; justify-content: space-between; gap: 0.75rem;
  padding: 1rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface);
}
.card h3 { font-size: 1.2rem; margin: 0 0 0.15rem; }
.card .meta { margin: 0.15rem 0; }
.card-actions { display: flex; gap: 0.5rem; justify-content: flex-end; }
.card-actions .btn.primary { flex: 1; }
.meta { color: var(--muted); font-size: 0.875rem; }

.session-list { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.session-item { display: flex; justify-content: space-between; align-items: center; gap: 0.75rem; padding: 0.75rem 1rem; border-top: 1px solid var(--line); }
.session-item:first-child { border-top: 0; }
.session-title { font-weight: 600; }

/* ---------- editor ---------- */

.panel { padding: 1rem; margin: 0 0 1rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.panel > h2 { margin-bottom: 0.75rem; }
.panel input[type='text'], .panel input[type='url'], .panel input[type='number'], .panel select { background: var(--bg); }

.list { display: grid; gap: 0.5rem; margin: 0.5rem 0 0.75rem; }
.list-row { display: flex; gap: 0.5rem; align-items: center; }
.list-row input[type='text'] { min-width: 0; flex: 1 1 0; }
.list-row .grow { flex: 3 1 0; }
.list-row .key-input { flex: 0 0 3.2rem; }
.key-input { width: 3.2rem !important; flex: none; text-align: center; font-family: var(--mono); }
.subject-row input[type='text']:last-of-type { flex: 1.4 1 0; }
.question-row select { width: auto; flex: none; }

.channel-edit { padding: 0.75rem; margin: 0 0 0.75rem; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
.channel-edit > input { margin-top: 0.5rem; }
.channel-edit .panel, .channel-edit input[type='text'], .channel-edit select { background: var(--surface); }
.channel-edit-head { display: flex; gap: 0.5rem; align-items: center; }
.channel-edit-head select { width: auto; flex: none; }

.panel h3 { margin: 1rem 0 0.6rem; }

@media (max-width: 640px) {
  .behavior-row { display: grid; grid-template-columns: 1fr 3.2rem 36px; gap: 0.4rem; padding-bottom: 0.6rem; border-bottom: 1px solid var(--line); }
  .behavior-row > :nth-child(3), .behavior-row > :nth-child(4) { grid-column: 1 / -1; }
  .behavior-row > .remove { grid-column: 3; grid-row: 1; }
  .question-row { flex-wrap: wrap; }
  .question-row input:first-child { flex: 1 1 50%; }
  .question-row .grow { flex: 1 1 100%; }
}

.map-preview img { display: block; max-width: 100%; max-height: 280px; border-radius: 10px; border: 1px solid var(--line); margin-bottom: 0.75rem; }

.save-bar {
  position: sticky; bottom: 0; display: flex; gap: 0.5rem; justify-content: flex-end;
  padding: 0.75rem 0 calc(0.75rem + env(safe-area-inset-bottom)); background: var(--bg); border-top: 1px solid var(--line);
}
.save-bar .btn.ghost { margin-right: auto; }

.start-head { margin: 0.5rem 0 1rem; }
.start-head h2 { font-size: 1.6rem; }

.summary-counts { display: flex; flex-wrap: wrap; gap: 0.75rem; margin: 1rem 0; }
.stat { padding: 0.75rem 1rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); min-width: 120px; }
.stat-n { font: 600 1.8rem/1.1 var(--serif); }
.stat.warn { border-color: var(--warn); background: var(--warn-bg); color: var(--warn-ink); }
.stat.warn .muted { color: inherit; }

.summary-panel h3 { margin-top: 0; }
.summary-head { display: flex; align-items: center; gap: 0.5rem; margin: 1rem 0 0.4rem; }
.summary-head h4 { margin: 0; font: 600 1rem/1.2 var(--serif); }
.table-wrap { overflow-x: auto; }
.summary-table { width: 100%; border-collapse: collapse; font-size: 0.92rem; font-variant-numeric: tabular-nums; }
.summary-table th, .summary-table td { padding: 0.4rem 0.5rem; border-bottom: 1px solid var(--line); text-align: right; vertical-align: top; }
.summary-table th:first-child { text-align: left; font-weight: 600; }
.summary-table thead th { font-size: 0.8rem; color: var(--muted); font-weight: 600; }
.summary-table .v { display: block; font-weight: 700; }
.summary-table .sub { display: block; font-size: 0.78rem; color: var(--muted); }
.summary-table th.zero, .summary-table td.zero .v { color: var(--muted); font-weight: 400; }
.summary-panel { margin-top: 1.25rem; }

/* ---------- recording screen ---------- */

.record { --rec-gap: 0.75rem; }
.record-head {
  position: sticky; top: 0; z-index: 10; background: var(--bg);
  padding: calc(0.5rem + env(safe-area-inset-top)) 0.75rem 0.5rem; border-bottom: 1px solid var(--line);
}
.record-title { display: flex; align-items: center; gap: 0.5rem; font-size: 0.85rem; margin-bottom: 0.3rem; }
.record-name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.record-title .defs-toggle { min-height: 32px; flex: none; }

.timer {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 0.75rem;
  padding: 0.5rem 0.75rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface);
}
.timer.warning { background: var(--warn-bg); border-color: var(--warn); color: var(--warn-ink); }
.timer.warning .muted { color: inherit; }
.timer.paused { opacity: 0.7; }
.timer-label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.timer.warning .timer-label { color: inherit; }
.timer-big { font: 600 2.2rem/1 var(--mono); font-variant-numeric: tabular-nums; }
.timer-side { display: grid; gap: 0.1rem; font-size: 0.9rem; font-variant-numeric: tabular-nums; }
.timer-actions { display: flex; gap: 0.4rem; }

/* Scan flash. Light: a yellow fill. Dark: a thick yellow edge, since no text color reads well on dark yellow. */
body.flash .timer { animation: none; background: var(--flash); color: var(--flash-ink); border-color: var(--flash-edge); box-shadow: 0 0 0 3px var(--flash-edge); }
body.flash .timer .muted, body.flash .timer .timer-label { color: inherit; }
body.flash .record-head { background: var(--flash); }
body.flash-pause .pause-banner { box-shadow: 0 0 0 4px var(--flash-edge); }
/* Session over: the whole screen blinks, unlike a scan, which lights only the timer. */
body.flash-end::after {
  content: ''; position: fixed; inset: 0; z-index: 50; pointer-events: none;
  background: var(--flash-end); animation: end-blink 0.6s ease-in-out 4 alternate;
}
@keyframes end-blink { from { opacity: 0.85; } to { opacity: 0.1; } }
@media (prefers-reduced-motion: reduce) { body.flash-end::after { animation: none; opacity: 0.5; } }
/* Big scan flash (Settings): a yellow and black border around the whole screen pulses twice,
   2 per second, under the 3-per-second photosensitivity limit. pointer-events: none, so taps go through. */
[data-big-flash='on'] body.flash::before {
  content: ''; position: fixed; inset: 0; z-index: 49; pointer-events: none;
  box-shadow: inset 0 0 0 10px #ffd34d, inset 0 0 0 14px #111;
  animation: scan-pulse 0.5s ease-in-out 2;
}
@keyframes scan-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.15; } }
@media (prefers-reduced-motion: reduce) { [data-big-flash='on'] body.flash::before { animation: none; } }

.subject-tiles { display: flex; gap: 0.5rem; overflow-x: auto; padding: 0.5rem 0 0.1rem; scrollbar-width: none; }
.subject-tiles::-webkit-scrollbar { display: none; }
.subject-tiles.wrap { flex-wrap: wrap; overflow-x: visible; }
.subject-tiles.wrap .tile-wrap { flex: 1 1 8rem; }
.tile-wrap { display: flex; flex-direction: column; gap: 0.25rem; flex: 0 0 auto; }
.tile-wrap .subject-tile { width: 100%; }
.oov-btn {
  min-height: 30px; padding: 0.15rem 0.5rem; border: 1px dashed var(--muted); border-radius: 8px;
  background: transparent; color: var(--muted); font: 600 0.78rem/1.1 var(--sans); cursor: pointer; touch-action: manipulation;
}
.oov-btn.on { border-style: solid; border-color: var(--ink); background: var(--ink); color: var(--bg); }
.oov-btn:disabled { opacity: 0.45; }
.who-label { margin-left: auto; font-size: 0.8rem; font-weight: 600; color: var(--event-ink); }
.subject-pick { justify-content: flex-start; border-left: 6px solid var(--subject); gap: 0.6rem; }
.pick-key { font: 600 0.75rem var(--mono); color: var(--muted); }
.subject-tile {
  position: relative; flex: 0 0 auto; min-width: 92px; min-height: 56px; padding: 0.4rem 0.75rem;
  display: grid; gap: 0.25rem; justify-items: start; text-align: left;
  border: 2px solid var(--line); border-left: 6px solid var(--subject); border-radius: 10px;
  background: var(--surface); color: var(--ink); font: 600 0.95rem/1.15 var(--sans); cursor: pointer;
}
.subject-tile.active { border-color: var(--subject); background: color-mix(in srgb, var(--subject) 16%, var(--surface)); }
.subject-tile.done .tile-name::after { content: ' ✓'; color: var(--ok); }
.tile-name { padding-right: 0.9rem; }
.tile-key { position: absolute; top: 3px; right: 6px; font: 600 0.7rem var(--mono); color: var(--muted); }
.tile-dots { display: flex; gap: 3px; }
.tdot { width: 9px; height: 9px; border-radius: 50%; border: 1.5px solid var(--muted); }
.tdot.on { background: var(--subject); border-color: var(--subject); }

.record-body { flex: 1; padding: 0.75rem; display: grid; gap: var(--rec-gap); align-content: start; }
.channels { display: grid; gap: var(--rec-gap); }
.channel { padding: 0.75rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.channel-head { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 0.5rem; }
.channel-head h2 { font-size: 1.1rem; }
.badge { font: 600 0.7rem/1 var(--sans); text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); padding: 0.3rem 0.45rem; border: 1px solid var(--line); border-radius: 6px; }
.stopwatch, .scored { margin-left: auto; font-size: 0.85rem; font-variant-numeric: tabular-nums; }
.scored { color: var(--ok); font-weight: 600; }
.stopwatch strong { font-family: var(--mono); }
.channel-def { font-size: 0.85rem; color: var(--muted); margin: -0.25rem 0 0.5rem; }

.behaviors { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(46%, 150px), 1fr)); gap: 0.5rem; }
.behavior {
  position: relative; min-height: 56px; padding: 0.55rem 0.7rem; display: grid; align-content: center; gap: 0.2rem;
  text-align: left; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--ink);
  font: 600 1rem/1.2 var(--sans); cursor: pointer; touch-action: manipulation; user-select: none;
}
.behavior:active { transform: scale(0.98); }
.b-name { overflow-wrap: anywhere; }
.channel.long .behaviors { grid-template-columns: repeat(auto-fill, minmax(clamp(5rem, 31%, 130px), 1fr)); gap: 0.4rem; }
.channel.long .behavior { min-height: 48px; padding: 0.45rem 0.55rem; font-size: 0.92rem; }
.behavior.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.behavior:disabled { opacity: 0.4; }
.b-counts { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.b-count {
  min-width: 1.9rem; padding: 0.2rem 0.4rem; border-radius: 7px; border-left: 4px solid var(--subject); background: var(--surface-2);
  font: 700 0.95rem/1 var(--mono); text-align: center;
}
.channel .b-count.zero { font-weight: 400; color: var(--muted); }
.b-key { display: none; position: absolute; top: 4px; right: 6px; font-size: 0.7rem; color: var(--muted); }
.m-all-occurrence .b-key { top: 3px; right: 3px; }
.behavior.on .b-key { color: inherit; opacity: 0.8; }
.b-def { font: 400 0.78rem/1.25 var(--sans); color: var(--muted); }
.behavior.on .b-def { color: inherit; opacity: 0.85; }
@media (hover: hover) and (pointer: fine) {
  .b-key { display: block; }
  .m-all-occurrence .b-key { display: none; }
}

.map-surface { position: relative; display: inline-block; max-width: 100%; cursor: crosshair; line-height: 0; touch-action: manipulation; }
.map-surface img { max-width: 100%; max-height: 60vh; border-radius: 8px; user-select: none; -webkit-user-drag: none; }
.map-grid {
  position: absolute; inset: 0; pointer-events: none; border-radius: 8px;
  background-image: linear-gradient(to right, rgb(255 255 255 / 0.5) 1px, transparent 1px), linear-gradient(to bottom, rgb(255 255 255 / 0.5) 1px, transparent 1px);
}
.marker {
  position: absolute; width: 26px; height: 26px; margin: -13px 0 0 -13px; border-radius: 50%;
  display: grid; place-items: center; background: var(--subject); color: #fff; border: 2px solid #fff;
  font: 700 0.75rem/1 var(--sans); box-shadow: 0 1px 4px rgb(0 0 0 / 0.4); pointer-events: none;
}

.record-bar {
  position: sticky; bottom: 0; z-index: 10; display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center;
  padding: 0.5rem 0.75rem calc(0.5rem + env(safe-area-inset-bottom)); background: var(--bg); border-top: 1px solid var(--line);
}
.undo-btn { flex: 0 1 auto; min-width: 5rem; max-width: 22rem; justify-content: flex-start; white-space: nowrap; overflow: hidden; }
.undo-what { font-weight: 400; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.record-bar .btn { flex: none; }
.record-bar .undo-btn { flex: 0 1 auto; }
/* The pill gives way first, so Undo keeps its size when the pill's text is long. */
.record-bar .sync-pill { margin-left: auto; flex: 0 1 auto; min-width: 34px; overflow: hidden; }
.record-bar .sync-pill .pill-text { overflow: hidden; text-overflow: ellipsis; }
.defs-toggle { display: inline-flex; align-items: center; gap: 0.35rem; font-size: 0.85rem; min-height: 44px; cursor: pointer; }
.defs-toggle input { accent-color: var(--accent); width: 18px; height: 18px; }

@media (max-width: 600px) {
  .record-head { padding: calc(0.4rem + env(safe-area-inset-top)) 0.6rem 0.4rem; }
  .record-title { margin-bottom: 0.3rem; }
  .timer { gap: 0.6rem; padding: 0.4rem 0.6rem; }
  .timer-big { font-size: 1.9rem; }
  .timer-side { font-size: 0.82rem; line-height: 1.3; }
  .timer-actions { flex-direction: column; gap: 0.3rem; }
  .timer-actions .btn { min-height: 44px; padding: 0.25rem 0.8rem; }
  .subject-tiles { padding-top: 0.4rem; }
  .subject-tile { min-height: 50px; min-width: 84px; }
  .record-body { padding: 0.6rem; }
  .channel { padding: 0.6rem; }
  .behavior { min-height: 52px; }
  .undo-what { display: none; }
}

/* Very narrow: a phone with text zoomed to 150–200% (Safari's aA menu) is 260 or 195 px wide.
   The header scrolls away instead of covering the screen, and tiles scroll sideways. */
@media (max-width: 340px), (max-height: 480px) and (orientation: portrait) {
  .record-head { position: static; }
  .timer { grid-template-columns: 1fr auto; }
  .timer-side { grid-column: 1 / -1; grid-row: 2; display: flex; flex-wrap: wrap; gap: 0 0.6rem; }
  .timer-actions { grid-column: 2; grid-row: 1; }
  .subject-tiles.wrap { flex-wrap: nowrap; overflow-x: auto; }
  .subject-tiles.wrap .tile-wrap { flex: 0 0 auto; }
  .record-bar { gap: 0.35rem; padding-left: 0.5rem; padding-right: 0.5rem; }
  .record-bar .btn { padding: 0.4rem 0.6rem; }
  .record-bar .undo-btn { min-width: 3.75rem; }
  .record-bar .sync-pill .pill-text { display: none; }
}
/* At 200% there is room for one row of Undo, Note and Lock only; upload status shows on the home screen. */
@media (max-width: 240px) {
  .record-bar { flex-wrap: nowrap; }
  .record-bar .sync-pill { display: none; }
  .record-bar .btn, .record-bar .undo-btn { flex: 1 1 0; min-width: 0; padding: 0.4rem 0.3rem; justify-content: center; }
}

/* Landscape (phones, tablets, laptops): timer and subjects in a side rail, buttons on the right. */
@media (orientation: landscape) and (min-width: 560px) {
  .record { --rail: 220px; display: grid; grid-template-columns: var(--rail) minmax(0, 1fr); grid-template-rows: 1fr auto; min-height: 100dvh; }
  .record .record-head {
    grid-column: 1; grid-row: 1 / span 2; position: sticky; top: 0; height: 100dvh; overflow-y: auto;
    border-bottom: 0; border-right: 1px solid var(--line);
    padding: calc(0.5rem + env(safe-area-inset-top)) 0.6rem 0.6rem calc(0.6rem + env(safe-area-inset-left));
  }
  .record .record-title { flex-wrap: wrap; }
  .record .timer { grid-template-columns: 1fr; gap: 0.4rem; }
  .record .timer-big { font-size: 2rem; }
  .record .timer-actions { flex-direction: row; }
  .record .timer-actions .btn { flex: 1; }
  .record .subject-tiles { flex-direction: column; flex-wrap: nowrap; overflow: visible; padding-top: 0.5rem; }
  .record .subject-tile, .record .subject-tiles.wrap .subject-tile { width: 100%; flex: none; min-height: 50px; }
  .record .tile-wrap, .record .subject-tiles.wrap .tile-wrap { width: 100%; flex: none; }
  .record .record-body { grid-column: 2; grid-row: 1; padding: 0.6rem; }
  .record .record-bar { grid-column: 2; grid-row: 2; }
}
@media (orientation: landscape) and (min-width: 900px) {
  .record { --rail: 320px; }
  .record .record-head { padding: 1rem; }
  .record .timer-big { font-size: 3rem; }
  .record .subject-tile { min-height: 60px; }
  .record .record-body { padding: 1rem; }
  .record .channels { grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); align-items: start; }
}

/* ---------- pause banner and lock ---------- */

.pause-banner {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 0.5rem 0.75rem;
  margin-top: 0.5rem; padding: 0.5rem 0.75rem; border: 2px solid var(--focus); border-radius: var(--radius); background: var(--surface);
}
.pause-banner > div { flex: 1 1 12rem; }
.pause-banner strong { font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.pause-banner .small { color: var(--muted); }
.pause-banner.long { border-color: var(--warn); background: var(--warn-bg); color: var(--warn-ink); }
.pause-banner.long .small { color: inherit; }

.lock-cover {
  position: fixed; inset: 0; z-index: 40; display: grid; place-items: end center; touch-action: none;
  padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom)); background: rgb(20 16 12 / 0.35);
}
.lock-card {
  width: min(100%, 360px); display: grid; gap: 0.25rem; justify-items: center; text-align: center;
  padding: 1rem; border: 2px solid var(--ink); border-radius: 16px; background: var(--surface); color: var(--ink);
}
.lock-card strong { font: 600 1.3rem/1.2 var(--serif); }
.unlock-btn { position: relative; overflow: hidden; width: 100%; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: none; }
.unlock-btn > span:last-child { position: relative; }
.unlock-fill { position: absolute; inset: 0; background: var(--accent-soft); transform: scaleX(0); transform-origin: left; }
.unlock-btn.holding .unlock-fill { transform: scaleX(1); transition: transform 0.8s linear; }

/* ---------- modal and toast ---------- */

.modal {
  width: min(92vw, 440px); max-height: 85dvh; padding: 0; border: 1px solid var(--line); border-radius: 16px;
  background: var(--surface); color: var(--ink); box-shadow: 0 20px 50px rgb(0 0 0 / 0.3);
}
.modal::backdrop { background: rgb(20 16 12 / 0.45); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; padding: 0.75rem 0.75rem 0 1rem; }
.modal-head h2 { font-size: 1.15rem; }
.modal-body { padding: 0.5rem 1rem 1rem; display: grid; gap: 0.75rem; }
.modifier-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 0.5rem; }

.toast {
  position: fixed; left: 50%; bottom: calc(5rem + env(safe-area-inset-bottom)); z-index: 100;
  max-width: min(92vw, 520px); padding: 0.7rem 1rem; border-radius: 10px;
  background: var(--ink); color: var(--bg); font-weight: 600; font-size: 0.92rem;
  transform: translate(-50%, 1rem); opacity: 0; pointer-events: none; transition: opacity 0.15s, transform 0.15s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--danger); color: #fff; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
  .behavior:active { transform: none; }
}
.channel-edit-head input { flex: 1 1 0; min-width: 0; }

/* Scan channels still waiting for this scan's answer stand out; all-occurrence channels get their own tint. */
.channel.needs { border-color: var(--accent); box-shadow: inset 4px 0 0 var(--accent); }
.needs-label { margin-left: auto; font-size: 0.8rem; font-weight: 700; color: var(--accent); }
.record:has(.timer.warning) .channel.needs { background: color-mix(in srgb, var(--warn-bg) 55%, var(--surface)); }
.channel.m-all-occurrence { background: var(--event-bg); border-color: var(--event-line); }
.channel.m-all-occurrence .badge { color: var(--event-ink); border-color: var(--event-line); }
.channel.m-all-occurrence .behavior { background: var(--surface); border-color: var(--event-line); }
.channel.m-all-occurrence .b-count { background: var(--event-bg); color: var(--event-ink); }
.notice.warn { border-color: var(--warn); background: var(--warn-bg); color: var(--warn-ink); display: grid; gap: 0.5rem; justify-items: start; }
.notice.warn p { margin: 0; }

.b-recv { font: 600 0.7rem/1 var(--sans); color: var(--muted); }

/* Guide: sign-in page and the Guide view */
.guide-wrap { width: 100%; max-width: 760px; }
.guide h2 { margin-bottom: 0.5rem; }
.guide ul, .guide ol { margin: 0; padding-left: 1.25rem; display: grid; gap: 0.6rem; line-height: 1.45; }
.guide p { line-height: 1.45; }
.guide.warnings { border-color: var(--warn); background: var(--warn-bg); color: var(--warn-ink); }
.ack { display: flex; gap: 0.6rem; align-items: flex-start; font-size: 0.92rem; line-height: 1.4; }
.ack input { width: 20px; height: 20px; margin-top: 2px; flex: none; accent-color: var(--accent); }
.help-btn { font: 600 1.15rem/1 var(--sans); }

/* Phones: four header controls (sync, theme, guide, settings) leave the title room to breathe. */
@media (max-width: 480px) {
  .topbar { gap: 0.35rem; padding-left: 0.75rem; padding-right: 0.5rem; }
  .topbar-actions { gap: 0; }
  .topbar-actions .icon-btn { width: 40px; }
  .topbar .brand-mark { width: 30px; }
  .topbar .sync-pill { padding: 0.25rem 0.6rem; gap: 0.35rem; }
}

/* ---------- dashboard ---------- */

.dash-head { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem 1rem; flex-wrap: wrap; margin: 0.25rem 0 0.25rem; }
.dash-head select { width: auto; max-width: 100%; }
.dash-exp { font: 600 1.1rem/1.2 var(--serif); }
.dash-filters { gap: 0.5rem 0.75rem; }
.dash-filters .toggle { margin-right: 0; }
.dash-source { margin: 0.25rem 0 0; }
.dash-tiles { margin: 0.75rem 0 0.5rem; }
.dash-tiles .stat { flex: 1 1 120px; }
.dash-grid { display: grid; grid-template-columns: 1fr; gap: 0 1rem; margin-top: 0.75rem; align-items: start; }
@media (min-width: 820px) {
  .dash-grid { grid-template-columns: 1fr 1fr; }
  .dash-wide { grid-column: 1 / -1; }
}
.dash-panel h3 { margin: 0 0 0.25rem; }
.dash-trend-head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem 1rem; flex-wrap: wrap; margin-bottom: 0.25rem; }
.dash-trend-head select { width: auto; max-width: 100%; }

.chart-legend { display: flex; flex-wrap: wrap; gap: 0.25rem 1rem; list-style: none; padding: 0; margin: 0.5rem 0; font-size: 0.85rem; }
.chart-legend li { display: inline-flex; align-items: center; gap: 0.4rem; }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; background: var(--subject); flex: none; }
.chart { margin-top: 0.25rem; }
.chart-readout { min-height: 1.3em; margin: 0.4rem 0 0; font-variant-numeric: tabular-nums; }

.bar-rows { display: grid; gap: 2px; }
.bar-row {
  display: grid; grid-template-columns: minmax(6.5rem, 38%) 1fr; gap: 0.6rem; align-items: center;
  width: 100%; padding: 0.35rem 0.4rem; border: 0; border-radius: 8px; background: transparent; color: var(--ink);
  font: inherit; text-align: left; cursor: pointer; touch-action: manipulation;
}
.bar-row:hover, .bar-row.on { background: var(--surface-2); }
.bar-label { font-size: 0.9rem; line-height: 1.2; overflow-wrap: anywhere; }
.bar-row.zero .bar-label { color: var(--muted); }
.bar-set { display: grid; gap: 3px; }
.bar-line { display: grid; grid-template-columns: 1fr 3.2rem; gap: 0.4rem; align-items: center; }
.bar-track { height: 10px; position: relative; }
.bar { display: block; height: 100%; min-width: 0; background: var(--subject); border-radius: 0 4px 4px 0; }
.bar-value { font-size: 0.8rem; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.bar-row.on .bar-value { color: var(--ink); }
@media (max-width: 400px) {
  .bar-row { grid-template-columns: 1fr; gap: 0.25rem; }
}

.vis-rows { display: grid; gap: 0.9rem; margin-top: 0.5rem; }
.vis-head { display: flex; align-items: baseline; justify-content: space-between; gap: 0.5rem; }
.vis-name { display: inline-flex; align-items: center; gap: 0.45rem; font-weight: 600; }
.vis-big { font: 600 1.35rem/1 var(--serif); font-variant-numeric: tabular-nums; }
.vis-bar { display: flex; gap: 2px; height: 14px; margin: 0.4rem 0 0.2rem; }
.vis-seg { display: block; height: 100%; min-width: 3px; }
.vis-seg:first-child { border-radius: 4px 0 0 4px; }
.vis-seg:last-child { border-radius: 0 4px 4px 0; }
.vis-seg:only-child { border-radius: 4px; }
.vis-seg.in { background: var(--subject); }
.vis-seg.out { background: repeating-linear-gradient(135deg, var(--line) 0 4px, var(--surface-2) 4px 8px); box-shadow: inset 0 0 0 1px var(--line); }
.vis-seg.miss { background: var(--warn); }
.vis-note { margin: 0; }

.chart-box { width: 100%; min-height: 1px; }
.chart-svg { display: block; touch-action: pan-y; overflow: visible; }
.chart-svg .grid { stroke: var(--line); stroke-width: 1; stroke-dasharray: 2 3; }
.chart-svg .axis { stroke: var(--line); stroke-width: 1; }
.chart-svg .tick { fill: var(--muted); font: 11px var(--sans); font-variant-numeric: tabular-nums; }
.chart-svg .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-svg .dot { stroke: var(--surface); stroke-width: 2; }
.chart-svg .rule { stroke: var(--muted); stroke-width: 1; }
.chart-svg .col { fill: var(--accent); }
.chart-svg .col.on { fill: var(--ink); }
.chart-svg .hit { fill: transparent; cursor: pointer; }

.dash-line { margin: 0.5rem 0 0; }
.home-dash .dash-tiles { margin-top: 0; }
.home-dash .dash-grid { margin-top: 0.5rem; }
.exp-rows { list-style: none; margin: 0.25rem 0 0; padding: 0; display: grid; gap: 2px; }
.exp-row {
  display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; width: 100%; min-height: 52px;
  padding: 0.45rem 0.5rem; border: 0; border-radius: 8px; background: transparent; color: var(--ink);
  font: inherit; text-align: left; cursor: pointer; touch-action: manipulation;
}
.exp-row:hover { background: var(--surface-2); }
.exp-row:disabled { cursor: default; background: transparent; }
.exp-row-main { display: grid; gap: 0.1rem; min-width: 0; }
.exp-row-name { font-weight: 600; overflow-wrap: anywhere; }
.exp-row-go { color: var(--muted); font-size: 1.5rem; line-height: 1; }
