:root {
  color-scheme: light dark;
  --bg: #f4f4f1;
  --surface: #ffffff;
  --surface-2: #f0efeb;
  --border: #e2e0da;
  --text: #1b1b1a;
  --muted: #6d6b66;
  --accent: #e8a900;
  --accent-ink: #1b1b1a;
  --good: #1f9d55;
  --warn: #d98a00;
  --alert: #d7263d;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 24px rgba(0, 0, 0, 0.05);
  font-family:
    ui-sans-serif,
    system-ui,
    -apple-system,
    "Segoe UI",
    Roboto,
    "Helvetica Neue",
    Arial,
    sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121211;
    --surface: #1b1b1a;
    --surface-2: #242422;
    --border: #2f2f2c;
    --text: #f1f0ec;
    --muted: #9c9a94;
    --accent: #ffc72c;
    --shadow: none;
  }
}

* {
  box-sizing: border-box;
}
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
p {
  margin: 0;
}
h2 {
  font-size: 15px;
  font-weight: 650;
}

/* ---------- top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px 16px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 5;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
/* The Yureka mark comes on its own white disc */
.brand-mark {
  width: 30px;
  height: 30px;
  flex-shrink: 0;
}
.top-actions {
  margin-left: auto;
  display: flex;
  gap: 8px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--muted);
  transition:
    background-color 0.2s,
    color 0.2s;
}
.pill::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}
.pill[data-state="FOCUSED"] {
  background: color-mix(in srgb, var(--good) 15%, transparent);
  color: var(--good);
}
.pill[data-state="POSSIBLY_DISTRACTED"] {
  background: color-mix(in srgb, var(--warn) 18%, transparent);
  color: var(--warn);
}
.pill[data-state="DISTRACTED"] {
  background: var(--alert);
  color: #fff;
}
.pill[data-state="paused"] {
  background: color-mix(in srgb, var(--warn) 18%, transparent);
  color: var(--warn);
}

/* ---------- buttons & inputs ---------- */

.btn {
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  transition:
    transform 0.1s,
    background-color 0.15s,
    border-color 0.15s;
}
.btn:hover:not(:disabled) {
  border-color: var(--muted);
}
.btn:active:not(:disabled) {
  transform: scale(0.97);
}
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.btn:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.btn.big {
  font-size: 16px;
  padding: 12px 28px;
  border-radius: 12px;
}
.btn.small {
  font-size: 13px;
  padding: 7px 11px;
}
.btn.ghost {
  background: transparent;
}
.btn.danger {
  color: var(--alert);
}

/* ---------- layout ---------- */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(300px, 26vw, 380px);
  grid-template-areas:
    "stage side"
    "log   side";
  align-content: start;
  align-items: start; /* cards keep their own height instead of stretching */
  gap: 20px;
  max-width: 1500px;
  margin: 0 auto;
  padding: 20px 24px 40px;
}
.stage {
  grid-area: stage;
}
.log-card {
  grid-area: log;
}
.side {
  grid-area: side;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}
.side {
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

/* ---------- camera stage ---------- */

.stage {
  padding: 12px;
}
.viewport {
  position: relative;
  aspect-ratio: 16 / 10;
  /* don't let the camera push everything else off a short window */
  max-height: min(62vh, 560px);
  border-radius: 12px;
  overflow: hidden;
  background: #0d0d0c;
}
/* While a setup screen is up, let the box grow to the text instead of
   cropping it — on a phone the intro is taller than a 16:10 box. */
.viewport:has(.setup:not([hidden])) {
  aspect-ratio: auto;
  max-height: none;
  min-height: min(62vh, 360px);
}
/* ...which needs the setup layer in the flow, not laid over a fixed box */
.viewport .setup:not([hidden]) {
  position: relative;
  min-height: inherit;
}
.viewport video,
.viewport canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1); /* mirror, so it reads like a mirror */
}

.setup {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: safe center; /* never centre content out of reach */
  overflow-y: auto;
  padding: 24px;
  background: radial-gradient(ellipse at top, rgba(0, 0, 0, 0.35), rgba(0, 0, 0, 0.75));
  color: #f5f4f0;
}
.setup-card {
  max-width: 440px;
  text-align: center;
  display: grid;
  gap: 16px;
  justify-items: center;
}
@media (max-width: 560px) {
  .setup {
    padding: 18px 14px;
  }
  .setup-card {
    gap: 12px;
  }
  .setup-card .lede {
    font-size: 14px;
  }
  .steps {
    font-size: 14px;
    padding-left: 18px;
  }
}
.setup-card h1 {
  font-size: clamp(24px, 3vw, 32px);
  letter-spacing: -0.02em;
  line-height: 1.15;
}
.setup-card .lede {
  color: #d8d6cf;
}
.steps {
  text-align: left;
  margin: 0;
  padding-left: 20px;
  display: grid;
  gap: 6px;
  color: #e6e4dd;
}
.fine {
  font-size: 12px;
  color: #aaa79f;
}
.setup-card .error {
  color: #ff9aa6;
}

.progress {
  width: 260px;
  height: 6px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.18);
  overflow: hidden;
}
.progress > div {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.15s;
}
.spinner {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.2);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation-duration: 3s;
  }
}

.notice {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  padding: 10px 14px;
  border-radius: 10px;
  background: rgba(20, 20, 19, 0.88);
  color: #f5f4f0;
  font-size: 14px;
}
.notice button {
  margin-left: 8px;
}

/* ---------- distraction meter ---------- */

.meter {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 12px;
  padding: 12px 4px 2px;
}
.meter .bar {
  min-width: 140px;
}
.meter-label {
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
}
.score {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  min-width: 2.4ch;
  text-align: right;
}
.bar {
  position: relative;
  flex: 1;
  height: 8px;
  border-radius: 99px;
  background: var(--surface-2);
  overflow: hidden;
}
.bar .fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  background: var(--good);
  transition:
    width 0.12s linear,
    background-color 0.2s;
}
.bar .fill[data-level="warn"] {
  background: var(--warn);
}
.bar .fill[data-level="alert"] {
  background: var(--alert);
}
.bar .mark {
  position: absolute;
  top: 0;
  bottom: 0;
  right: 0;
  width: 2px;
  background: var(--alert);
  opacity: 0.5;
}
.reason {
  font-size: 13px;
  color: var(--muted);
  min-width: 120px;
  text-align: right;
  flex: 1 0 auto;
}

/* ---------- stats ---------- */

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(128px, 1fr));
  gap: 10px;
}
.tile {
  background: var(--surface-2);
  border-radius: 12px;
  padding: 10px 12px;
  display: grid;
  gap: 2px;
}
.tile-label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}
.tile-value {
  font-size: clamp(18px, 2.2vw, 22px);
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.segmented {
  display: inline-flex;
  background: var(--surface-2);
  border-radius: 9px;
  padding: 2px;
}
.segmented button {
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 4px 10px;
  border-radius: 7px;
  cursor: pointer;
}
.segmented button[aria-selected="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.board {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}
.board th {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
  text-align: left;
  padding: 0 6px 6px;
}
.board td {
  padding: 7px 6px;
  border-top: 1px solid var(--border);
  font-size: 14px;
}
.board .num {
  text-align: right;
}
.board .rank {
  color: var(--muted);
  width: 22px;
}
.board tr.me td {
  font-weight: 700;
}
.board tr.me td:nth-child(2)::after {
  content: " (you)";
  font-weight: 500;
  color: var(--muted);
}
.empty {
  color: var(--muted);
  font-size: 14px;
  padding: 6px 0 2px;
}

/* ---------- settings ---------- */

.settings {
  display: grid;
  gap: 12px;
}
.field {
  display: grid;
  gap: 4px;
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
}
.field input,
.field select {
  font: inherit;
  font-size: 14px;
  color: var(--text);
  padding: 8px 10px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface-2);
}
.toggle {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  font-size: 14px;
  cursor: pointer;
}
.toggle input {
  margin-top: 3px;
  accent-color: var(--accent);
}
.button-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* ---------- the card screen ---------- */

.alarm {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background: #000;
}
.alarm-text {
  position: relative;
  text-align: center;
  color: #fff;
  padding: 24px;
  display: grid;
  gap: 10px;
}
.alarm-kicker {
  justify-self: center;
  background: var(--alert);
  padding: 6px 14px;
  border-radius: 999px;
  font-weight: 800;
  letter-spacing: 0.08em;
  font-size: 14px;
}
.alarm[data-card="yellow"] .alarm-kicker {
  background: #e8a900;
  color: #1b1b1a;
}
.alarm[data-card="red"] .alarm-kicker {
  background: var(--alert);
  color: #fff;
}
.alarm[data-card="red"] .alarm-timer {
  color: #ff6b7d;
}
.alarm-message {
  font-size: clamp(26px, 4.5vw, 52px);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.1;
  max-width: 900px;
  text-wrap: balance;
}
.alarm-timer {
  font-size: 40px;
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.alarm-hint {
  color: #ddd;
}

/* ---------- picture-in-picture window ---------- */

.pip {
  display: grid;
  gap: 8px;
  padding: 10px;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}
.pip-view {
  position: relative;
  aspect-ratio: 4 / 3;
  border-radius: 10px;
  overflow: hidden;
  background: #000;
}
.pip-view video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.pip-cam {
  transform: scaleX(-1);
}
.pip-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.pip-timer {
  font-weight: 700;
  color: var(--alert);
  font-variant-numeric: tabular-nums;
}
.pip-message {
  font-weight: 700;
  font-size: 15px;
  line-height: 1.25;
}

/* ---------- session log ---------- */

.table-wrap {
  overflow-x: auto;
}
.log {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}
.log th {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
  text-align: left;
  padding: 0 10px 8px;
  white-space: nowrap;
}
.log td {
  padding: 9px 10px;
  border-top: 1px solid var(--border);
  font-size: 14px;
  white-space: nowrap;
}
@media (max-width: 560px) {
  .log th,
  .log td {
    padding: 8px 6px;
    font-size: 13px;
  }
  .log .when {
    font-size: 12px;
  } /* stays on one line; the table scrolls */
}
.log .num {
  text-align: right;
}
.log .session {
  font-weight: 650;
}
.log .when {
  color: var(--muted);
}
.log .lost {
  color: var(--alert);
}
.log tr.live td {
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}
.log tr.live .session::after {
  content: "live";
  margin-left: 8px;
  padding: 1px 7px;
  border-radius: 99px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.pill-soft {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  background: var(--surface-2);
  padding: 3px 9px;
  border-radius: 99px;
}

/* ---------- calibration ---------- */

.calib {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: #0d0d0c;
  color: #f5f4f0;
}
.calib-dot {
  position: absolute;
  width: 30px;
  height: 30px;
  margin: -15px 0 0 -15px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 10px color-mix(in srgb, var(--accent) 22%, transparent);
  transition:
    left 0.28s cubic-bezier(0.2, 0.8, 0.2, 1),
    top 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
  display: grid;
  align-items: end;
  overflow: hidden;
}
/* fills up as the samples for this target are collected */
.calib-dot-fill {
  display: block;
  width: 100%;
  background: #fff;
  opacity: 0.55;
  height: 0;
  transition: height 0.1s linear;
}
.calib-dot[data-settling="true"] {
  box-shadow: 0 0 0 16px color-mix(in srgb, var(--accent) 12%, transparent);
}

.calib-text {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(460px, 76vw);
  text-align: center;
  display: grid;
  gap: 10px;
  justify-items: center;
  pointer-events: none;
}
.calib-step {
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.calib-label {
  font-size: clamp(20px, 3vw, 30px);
  font-weight: 700;
  letter-spacing: -0.01em;
}
.calib .progress {
  background: rgba(255, 255, 255, 0.16);
}
.calib .fine {
  color: #97948d;
}

@media (prefers-reduced-motion: reduce) {
  .calib-dot {
    transition: none;
  }
}

/* ---------- responsive ----------
   Kept at the end so these win over the base rules above. */

/* One column once the side panel would get too cramped: camera, the numbers
   you watch, then the log. */
@media (max-width: 1020px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "stage" "side" "log";
  }
  /* side by side while there's room, each sharing the width evenly */
  .side {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    align-items: start;
  }
}

@media (max-width: 640px) {
  .layout {
    gap: 14px;
    padding: 14px 14px 28px;
  }
  .card {
    padding: 13px;
    border-radius: 14px;
  }
  .side {
    grid-template-columns: 1fr;
  }
}

/* ---------- goal form & session report ---------- */

.goal-form {
  display: grid;
  gap: 12px;
  width: min(420px, 82vw);
  justify-items: stretch;
  text-align: left;
}
.goal-form .field span {
  color: #cfccc5;
}
.goal-form input {
  font: inherit;
  font-size: 15px;
  width: 100%;
  padding: 9px 11px;
  border-radius: 9px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.06);
  color: #f5f4f0;
}
.goal-form input::placeholder {
  color: #8d8a83;
}
.goal-form button {
  justify-self: center;
  margin-top: 2px;
}

.subject-picks {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0;
  padding: 0;
  border: 0;
}
.subject-picks legend {
  width: 100%;
  margin-bottom: 6px;
  padding: 0;
  font-size: 13px;
  font-weight: 600;
  color: #cfccc5;
}
.subject-pick {
  flex: 1 1 0;
}
.goal-form .subject-pick input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}
.subject-pick span {
  display: block;
  padding: 9px 6px;
  border-radius: 9px;
  text-align: center;
  cursor: pointer;
  font-size: 14px;
  font-weight: 700;
  color: #f5f4f0;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.06);
}
.subject-pick input:checked + span {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.subject-pick input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.report {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin: 0;
  width: min(520px, 84vw);
  text-align: left;
}
.report > div {
  background: rgba(255, 255, 255, 0.07);
  border-radius: 12px;
  padding: 9px 12px;
}
.report dt {
  font-size: 12px;
  color: #b9b6ae;
  font-weight: 600;
}
.report dd {
  margin: 2px 0 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.log .cards {
  font-variant-numeric: tabular-nums;
}

/* ---------- calendar: D-Day, study calendar, weekly schedule ---------- */

.tabs {
  display: inline-flex;
  background: var(--surface-2);
  border-radius: 10px;
  padding: 3px;
}
.tabs button {
  font: inherit;
  font-size: 13px;
  font-weight: 650;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
}
.tabs button[aria-selected="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}
.tabs button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.cal-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(300px, 26vw, 380px);
  grid-template-areas:
    "today dday"
    "sched chart";
  align-items: start;
  gap: 20px;
  max-width: 1500px;
  margin: 0 auto;
  padding: 20px 24px 40px;
}
.now-stack {
  grid-area: today;
  display: grid;
  gap: 20px;
  align-content: start;
}
.dday-card {
  grid-area: dday;
}
.sched-card {
  grid-area: sched;
}
.chart-card {
  grid-area: chart;
}
@media (max-width: 1020px) {
  .cal-layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "today" "dday" "sched" "chart";
  }
}
@media (max-width: 640px) {
  .cal-layout {
    gap: 14px;
    padding: 14px 14px 28px;
  }
}

.fine-muted {
  font-size: 12px;
  color: var(--muted);
  margin: 0 0 10px;
}
.form-error {
  font-size: 13px;
  color: var(--alert);
  min-height: 0;
}
.form-error:empty {
  display: none;
}
.icon-btn {
  font: inherit;
  font-size: 18px;
  line-height: 1;
  border: 0;
  background: none;
  color: var(--muted);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 6px;
}
.icon-btn:hover {
  color: var(--alert);
  background: var(--surface-2);
}
.dday-form input {
  font: inherit;
  font-size: 13px;
  color: var(--text);
  padding: 6px 8px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface-2);
}

.dday-list {
  list-style: none;
  margin: 0 0 10px;
  padding: 0;
  display: grid;
  gap: 6px;
}
.dday-list li {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  align-items: center;
  gap: 8px;
}
.dday-badge {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
  background: var(--accent);
  color: var(--accent-ink);
  padding: 3px 8px;
  border-radius: 99px;
}
.dday-badge[data-past="true"] {
  background: var(--surface-2);
  color: var(--muted);
}
.dday-title {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dday-date {
  font-size: 12px;
  color: var(--muted);
}
.dday-form {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 6px;
}
.dday-form input {
  min-width: 0;
}

.chart {
  display: flex;
  align-items: stretch;
  gap: 4px;
  height: 150px;
}
.chart[data-range="month"] {
  gap: 2px;
}
.chart-col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  border: 0;
  background: none;
  padding: 0;
  cursor: pointer;
  font: inherit;
  color: var(--muted);
}
.chart-bar {
  flex: 1;
  width: 100%;
  display: flex;
  align-items: flex-end;
  border-radius: 4px;
  background: var(--surface-2);
  overflow: hidden;
}
.chart-bar > span {
  display: block;
  width: 100%;
  background: var(--accent);
  border-radius: 4px 4px 0 0;
  transition: height 0.2s;
}
.chart-col[aria-pressed="true"] .chart-bar > span {
  background: var(--text);
}
.chart-col[data-today="true"] .chart-tick {
  color: var(--text);
  font-weight: 700;
}
.chart-tick {
  font-size: 11px;
  height: 14px;
  font-variant-numeric: tabular-nums;
}
.chart-detail {
  margin: 10px 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--surface-2);
  font-size: 14px;
  display: grid;
  gap: 4px;
}
.chart-detail .fine-muted {
  margin: 0;
}
.window-list {
  margin: 0;
  padding-left: 18px;
}

.day-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.day-chip input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.day-chip span {
  display: inline-block;
  padding: 5px 10px;
  border-radius: 99px;
  font-size: 13px;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
}
.day-chip input:checked + span {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.day-chip input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- calendar: month / week / day (laid out like Mathiné's, in Yureka colours) ---------- */

.cal-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 10px;
}
.cal-nav,
.cal-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}
.cal-nav .btn {
  min-width: 34px;
}
.cal-title {
  font-size: 18px;
  letter-spacing: -0.01em;
  margin: 0 0 0 8px;
}

/* Periods: breaks, exam weeks, public holidays (red days) */
[data-period] {
  --period: var(--good);
}
[data-period="exams"] {
  --period: var(--warn);
}
[data-period="holiday"] {
  --period: var(--alert);
}
.cal-period {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.3;
  padding: 2px 6px;
  border-radius: 4px;
  color: color-mix(in srgb, var(--period) 75%, var(--text));
  background: color-mix(in srgb, var(--period) 16%, var(--surface));
}

/* Right now / next up: one row per event, like Mathiné's dashboard cards */
.now-card {
  padding: 18px 20px;
  min-height: 110px;
}
.now-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.now-label {
  margin: 0;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.now-date {
  margin-left: 6px;
  color: var(--muted);
  font-weight: 700;
}
.now-list {
  display: grid;
  gap: 8px;
}
.now-groups {
  display: grid;
  gap: 12px;
}
.now-group-title {
  margin: 0 0 6px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}
.now-empty {
  margin: 0;
  font-size: 18px;
  font-style: italic;
  color: var(--muted);
}
.summary-card {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-width: 0;
  padding: 10px 14px;
  border: 0;
  border-left: 4px solid var(--kind, var(--period));
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  font: inherit;
  color: var(--text);
  text-align: left;
}
button.summary-card {
  cursor: pointer;
  transition: box-shadow 0.15s;
}
button.summary-card:hover,
button.summary-card:focus-visible {
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.12);
}
.summary-card[data-period] {
  background: color-mix(in srgb, var(--period) 10%, var(--surface));
}
.summary-name {
  flex: 1;
  min-width: 0;
  font-size: 15px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.summary-badges {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.summary-badge {
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  background: var(--surface-2);
  color: var(--muted);
}
.summary-score {
  background: var(--accent);
  color: var(--accent-ink);
}
.summary-go {
  color: var(--muted);
  font-size: 16px;
}
.pager {
  display: flex;
  align-items: center;
  gap: 6px;
}
.pager-btn {
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  font: inherit;
  color: var(--text);
  cursor: pointer;
}
.pager-btn:disabled {
  opacity: 0.35;
  cursor: default;
}
.pager-count {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

/* Event colours by type: Study is Yureka yellow */
[data-kind] {
  --kind: var(--muted);
}
[data-kind="study"] {
  --kind: var(--accent);
}
[data-kind="school"] {
  --kind: #3b82f6;
}
[data-kind="class"] {
  --kind: #8b5cf6;
}

.cal-dday {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.3;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--accent);
  color: var(--accent-ink);
}
.cal-dday[data-past="true"] {
  background: var(--surface-2);
  color: var(--muted);
}
.ev-score {
  padding: 0 5px;
  border-radius: 99px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  background: rgba(0, 0, 0, 0.78);
  color: #fff;
}

/* month */
.cm-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  grid-template-rows: auto;
  grid-auto-rows: minmax(96px, auto); /* weekday names, then the days */
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.cm-head {
  padding: 7px 0;
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  background: var(--surface-2);
}
.cm-day {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  padding: 5px;
  background: var(--surface);
  cursor: pointer;
  user-select: none;
}
.cm-day[data-outside="true"] {
  background: var(--surface-2);
}
.cm-day[data-outside="true"] .cm-num {
  color: var(--muted);
}
.cm-day[data-selected="true"] {
  box-shadow: inset 0 0 0 2px var(--accent);
}
.cm-num {
  align-self: flex-end;
  display: inline-grid;
  place-items: center;
  min-width: 24px;
  height: 24px;
  padding: 0 4px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.cm-day[data-today="true"] .cm-num {
  background: var(--accent);
  color: var(--accent-ink);
}
.cm-chip {
  display: flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
  width: 100%;
  padding: 2px 5px;
  border: 0;
  border-left: 3px solid var(--kind);
  border-radius: 4px;
  font: inherit;
  font-size: 11px;
  line-height: 1.3;
  text-align: left;
  color: var(--text);
  cursor: pointer;
  background: color-mix(in srgb, var(--kind) 22%, var(--surface));
}
.cm-chip:hover,
.cw-event:hover {
  filter: brightness(0.95);
}
.cm-chip .ev-label {
  flex: 1;
  min-width: 0;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cm-chip .ev-time {
  flex-shrink: 0;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.cm-chip .ev-score {
  flex-shrink: 0;
  font-size: 10px;
}
.cm-more {
  align-self: flex-start;
  border: 0;
  background: none;
  padding: 1px 4px;
  border-radius: 4px;
  font: inherit;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  cursor: pointer;
}
.cm-more:hover {
  background: var(--surface-2);
  color: var(--text);
}

/* week and day */
.cw {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface);
}
.cw-row {
  display: grid;
  grid-template-columns: 56px repeat(var(--cols), minmax(0, 1fr));
}
.cw-head {
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.cw-corner {
  border-right: 1px solid var(--border);
}
.cw-dayhead {
  display: grid;
  justify-items: center;
  gap: 2px;
  padding: 7px 0;
  border: 0;
  border-right: 1px solid var(--border);
  background: none;
  font: inherit;
  color: var(--text);
  cursor: pointer;
}
.cw-dayhead:last-child {
  border-right: 0;
}
.cw-dayhead:hover {
  background: color-mix(in srgb, var(--text) 5%, transparent);
}
.cw-dayhead[data-selected="true"] {
  background: color-mix(in srgb, var(--accent) 16%, transparent);
}
.cw-dayname {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}
.cw-daynum {
  display: inline-grid;
  place-items: center;
  min-width: 30px;
  height: 30px;
  padding: 0 4px;
  border-radius: 99px;
  font-size: 17px;
  font-variant-numeric: tabular-nums;
}
.cw-dayhead[data-today="true"] .cw-daynum {
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 800;
}
.cw-allday {
  border-bottom: 1px solid var(--border);
}
.cw-allday-label {
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
}
.cw-allday-cell {
  display: grid;
  align-content: start;
  gap: 2px;
  min-width: 0;
  padding: 3px;
  border-right: 1px solid var(--border);
}
.cw-allday-cell:last-child {
  border-right: 0;
}

.cw-body {
  max-height: 560px;
  overflow-y: auto;
}
.cw-grid {
  position: relative;
}
.cw-gutter {
  position: relative;
  border-right: 1px solid var(--border);
}
.cw-gutter span {
  position: absolute;
  right: 6px;
  transform: translateY(-50%);
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.cw-gutter .cw-now-pill {
  right: 3px;
  z-index: 3;
  padding: 2px 5px;
  border-radius: 99px;
  background: var(--alert);
  color: #fff;
  font-weight: 700;
}
.cw-col {
  position: relative;
  min-width: 0;
  border-right: 1px solid var(--border);
  cursor: cell;
  touch-action: pan-y;
  /* an hour line, and a fainter half-hour line */
  background-image:
    linear-gradient(to bottom, var(--border) 1px, transparent 1px),
    linear-gradient(
      to bottom,
      color-mix(in srgb, var(--border) 45%, transparent) 1px,
      transparent 1px
    );
  background-size:
    100% var(--hour),
    100% calc(var(--hour) / 2);
}
.cw-col:last-child {
  border-right: 0;
}
.cw-col[data-today="true"] {
  background-color: color-mix(in srgb, var(--accent) 6%, transparent);
}
.cw-now {
  position: absolute;
  left: 0;
  right: 0;
  z-index: 2;
  pointer-events: none;
  border-top: 1px solid color-mix(in srgb, var(--alert) 35%, transparent);
}
.cw-now-today {
  border-top: 2px solid var(--alert);
  margin-top: -1px;
}
.cw-now-today::before {
  content: "";
  position: absolute;
  left: -5px;
  top: -6px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--alert);
}
.cw-event {
  position: absolute;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  overflow: hidden;
  padding: 3px 6px;
  border: 0;
  border-left: 4px solid var(--kind);
  border-radius: 5px;
  font: inherit;
  font-size: 12px;
  line-height: 1.25;
  text-align: left;
  color: var(--text);
  cursor: pointer;
  background: color-mix(in srgb, var(--kind) 26%, var(--surface));
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}
.cw-event .ev-label {
  max-width: 100%;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cw-event .ev-time {
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
.cw-event .ev-score {
  position: absolute;
  bottom: 3px;
  right: 3px;
  font-size: 11px;
}
.cw-event[data-short="true"] .ev-label {
  flex-shrink: 0;
}
.cw-event[data-short="true"] .ev-time {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cw-event[data-short="true"] {
  flex-direction: row;
  gap: 6px;
  padding-top: 1px;
}
.cw-ghost {
  position: absolute;
  left: 2px;
  right: 2px;
  z-index: 4;
  pointer-events: none;
  padding: 2px 6px;
  border: 1px dashed var(--accent);
  border-radius: 5px;
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  background: color-mix(in srgb, var(--accent) 22%, transparent);
}

/* event dialogs */
.cal-dialog {
  width: min(440px, calc(100vw - 32px));
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}
.cal-dialog::backdrop {
  background: rgba(0, 0, 0, 0.35);
}
.cal-dialog h2 {
  font-size: 18px;
  margin: 0;
}
.ev-form {
  display: grid;
  gap: 12px;
}
.ev-form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.ev-form .field input,
.ev-form .field select {
  width: 100%;
}
.attack-toggle {
  padding: 10px 12px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--accent) 14%, var(--surface));
  font-size: 13px;
  color: var(--muted);
}
.attack-toggle b {
  color: var(--text);
}
.ev-flag {
  margin-right: 3px;
}
.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}
.dialog-actions .danger {
  margin-right: auto;
}
.ev-info-head {
  display: grid;
  gap: 6px;
  padding-left: 12px;
  border-left: 4px solid var(--kind);
  margin-bottom: 14px;
}
.ev-kind {
  justify-self: start;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 700;
  background: color-mix(in srgb, var(--kind) 22%, var(--surface));
}
.ev-info-rows {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 14px;
  margin: 0 0 14px;
  font-size: 14px;
}
.ev-info-rows dt {
  color: var(--muted);
  font-weight: 600;
}
.ev-info-rows dd {
  margin: 0;
}
.ev-log {
  display: grid;
  gap: 10px;
  margin: 0 0 12px;
  padding: 12px;
  border-radius: 10px;
  background: var(--surface-2);
}
.ev-log .fine-muted {
  margin: 0;
}
.ev-log .field input {
  background: var(--surface);
  width: 100%;
}
.ev-log-title {
  margin: 0;
  font-weight: 700;
}

.mode-picks {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  border: 0;
}
.mode-picks legend {
  margin-bottom: 6px;
  padding: 0;
  font-size: 13px;
  font-weight: 600;
  color: #cfccc5;
}
.goal-form .mode-pick input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}
.mode-pick span {
  display: grid;
  gap: 2px;
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  color: #f5f4f0;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.06);
}
.mode-pick small {
  font-size: 12px;
  color: #bdbab2;
}
.mode-pick input:checked + span {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 22%, transparent);
}
.mode-pick input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (max-width: 640px) {
  .cal-title {
    margin: 4px 0 0;
    width: 100%;
  }
  .cm-grid {
    grid-auto-rows: minmax(64px, auto);
  }
  .cm-chip .ev-time {
    display: none;
  }
  .cw-row {
    grid-template-columns: 42px repeat(var(--cols), minmax(0, 1fr));
  }
}

.window-banner {
  width: min(420px, 82vw);
  padding: 9px 12px;
  border-radius: 10px;
  font-size: 14px;
  text-align: left;
  background: rgba(255, 255, 255, 0.08);
  color: #e6e4dd;
}
.window-banner[data-open="true"] {
  background: color-mix(in srgb, var(--accent) 30%, transparent);
  color: #fff;
}

/* ---------- sign-in gate (auth.js) ---------- */

/* Until signed in, only the gate shows; the app's markup stays hidden. Scoped to the page with
   the gate: the pop-out window copies these styles and must not hide its own content. */
body:has(> #gate):not(.signed-in) > :not(#gate):not(script):not(template) {
  display: none !important;
}
body.signed-in #gate {
  display: none;
}
.gate {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: safe center;
  padding: 24px 16px;
}
/* Nothing to show until we know whether there's a session (avoids a flash of the form). */
body:not(.signed-out) .gate-card {
  visibility: hidden;
}
.gate-card {
  width: min(400px, 100%);
  display: grid;
  gap: 14px;
  padding: 28px;
}
.gate-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 18px;
  color: var(--text);
  text-decoration: none;
  justify-self: start;
}
.gate-card h1 {
  font-size: 22px;
  line-height: 1.25;
}
.gate-sub {
  color: var(--muted);
  font-size: 14px;
}
.gate-google {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border-radius: 999px;
  background: var(--surface);
  padding: 10px 14px;
}
.gate-google-slot {
  display: flex;
  justify-content: center;
  min-height: 44px;
}
.gate-error {
  color: var(--alert);
  font-size: 14px;
}
.account {
  font-size: 13px;
  color: var(--muted);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.gate-consent {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  font-size: 13px;
  line-height: 1.5;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--surface-2);
  cursor: pointer;
}
.gate-consent input {
  margin-top: 3px;
  accent-color: var(--accent);
  flex: none;
}
.gate-consent a {
  color: var(--text);
  font-weight: 700;
}
.gate-consent small {
  color: var(--muted);
}
.gate-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.lang-btn {
  font-size: 12px;
  padding: 5px 10px;
}
