:root {
  --bg: #f7f6f3;
  --surface: #ffffff;
  --surface-2: #f0efeb;
  --border: #e3e1dc;
  --ink: #1c1d20;
  --ink-2: #4a4c52;
  --muted: #7a7c83;
  --accent: #2f5bd3;
  --accent-ink: #ffffff;
  --focus: #2f5bd3;
  --focus-soft: #e6ecfb;
  --vibe: #b8660b;
  --vibe-soft: #fbf0e0;
  --idle: #6b6e76;
  --idle-soft: #ecebe8;
  --good: #1f7a4d;
  --good-soft: #e3f3ea;
  --warn: #9a6200;
  --warn-soft: #fbf1db;
  --bad: #b3261e;
  --bad-soft: #fbe7e5;
  --bar: #2f5bd3;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.04), 0 4px 16px rgb(0 0 0 / 0.04);
  --radius: 14px;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16171a;
    --surface: #1f2024;
    --surface-2: #26282d;
    --border: #33353b;
    --ink: #ececee;
    --ink-2: #b9bbc2;
    --muted: #8a8d95;
    --accent: #7d9cf0;
    --accent-ink: #0f1115;
    --focus: #7d9cf0;
    --focus-soft: #1f2a44;
    --vibe: #f0a94e;
    --vibe-soft: #3a2c19;
    --idle: #a3a6ae;
    --idle-soft: #2a2c31;
    --good: #5cc38d;
    --good-soft: #17332a;
    --warn: #e7b04c;
    --warn-soft: #3a2f16;
    --bad: #f08a80;
    --bad-soft: #3d1f1d;
    --bar: #7d9cf0;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}
[hidden] { display: none !important; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h2 { font-size: 1.05rem; }
h3 { font-size: 0.95rem; }
p { margin: 0; }

/* ---------- header ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 12px;
  padding: 10px max(16px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; color: var(--ink); text-decoration: none; }
.brand-mark { width: 12px; height: 12px; border-radius: 50%; background: var(--idle); transition: background .3s; }
body[data-mode="focus"] .brand-mark { background: var(--focus); }
body[data-mode="vibe"] .brand-mark { background: var(--vibe); }
.tabs { display: flex; gap: 2px; margin-left: 8px; }
.tabs a { padding: 6px 10px; border-radius: 8px; color: var(--ink-2); text-decoration: none; font-size: 0.93rem; }
.tabs a[aria-current="page"] { background: var(--surface-2); color: var(--ink); font-weight: 600; }
.top-actions { margin-left: auto; display: flex; gap: 6px; }
.icon-btn {
  min-width: 36px; height: 36px; padding: 0 10px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--ink); font: inherit; font-weight: 600; line-height: 1; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}

main { max-width: 760px; margin: 0 auto; padding: 18px 16px 80px; display: grid; gap: 14px; }

/* ---------- cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); display: grid; gap: 12px; min-width: 0;
}
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.sub { color: var(--muted); font-size: 0.88rem; }
.card-body { display: grid; gap: 12px; min-width: 0; }
.banner { border-radius: var(--radius); padding: 14px 16px; display: grid; gap: 10px; }
.banner.warn { background: var(--warn-soft); color: var(--ink); border: 1px solid color-mix(in srgb, var(--warn) 35%, transparent); }
.banner.info { background: var(--focus-soft); border: 1px solid color-mix(in srgb, var(--focus) 30%, transparent); }

/* ---------- mode card ---------- */
.mode-card { border-width: 1px; transition: border-color .3s; }
.mode-card[data-mode="focus"] { border-color: color-mix(in srgb, var(--focus) 45%, var(--border)); }
.mode-card[data-mode="vibe"] { border-color: color-mix(in srgb, var(--vibe) 45%, var(--border)); }
.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px;
  font-size: 0.82rem; font-weight: 600; background: var(--idle-soft); color: var(--idle);
}
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill[data-mode="focus"] { background: var(--focus-soft); color: var(--focus); }
.pill[data-mode="vibe"] { background: var(--vibe-soft); color: var(--vibe); }
.timer { font: 600 clamp(2.6rem, 11vw, 3.8rem)/1 var(--mono); letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.timer-label { color: var(--muted); font-size: 0.85rem; }

.progress-row { display: grid; gap: 6px; }
.progress-label { display: flex; justify-content: space-between; gap: 10px; font-size: 0.88rem; color: var(--ink-2); }
.progress-label b { color: var(--ink); font-variant-numeric: tabular-nums; }
.meter { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.meter > span { display: block; height: 100%; width: 0; border-radius: 999px; background: var(--focus); transition: width .6s ease; }
.meter.vibe > span { background: var(--vibe); }
.or { text-align: center; font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }

.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.stat { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; min-width: 0; }
.stat .v { font: 600 1.25rem/1.2 var(--mono); font-variant-numeric: tabular-nums; }
.stat .k { color: var(--muted); font-size: 0.78rem; }

.gate-line { display: flex; align-items: center; gap: 8px; font-size: 0.92rem; }
.gate-line .lock { font-size: 1.05rem; }

/* ---------- buttons & forms ---------- */
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
button, .btn {
  font: inherit; font-weight: 600; border-radius: 10px; padding: 10px 16px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--ink);
}
button.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
button.focus { background: var(--focus); color: var(--accent-ink); border-color: transparent; }
button.vibe { background: var(--vibe); color: #fff; border-color: transparent; }
button.ghost { background: transparent; }
button.link { background: none; border: none; padding: 0; color: var(--muted); font-weight: 500; text-decoration: underline; text-underline-offset: 3px; }
button:disabled { opacity: .45; cursor: not-allowed; }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
label { display: grid; gap: 5px; font-size: 0.88rem; color: var(--ink-2); min-width: 0; }
input, textarea, select {
  font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--border);
  border-radius: 10px; padding: 9px 11px; width: 100%; min-width: 0;
}
textarea { resize: vertical; min-height: 72px; }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.check { display: flex; align-items: center; gap: 8px; }
.check input { width: auto; }
.hint { font-size: 0.82rem; color: var(--muted); }
.why { font-size: 0.82rem; color: var(--muted); border-left: 3px solid var(--border); padding-left: 10px; }

/* ---------- note ---------- */
.note-card { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; font-size: 0.93rem; }
.note-card .k { color: var(--muted); font-size: 0.78rem; display: block; margin-bottom: 2px; }

/* ---------- submissions ---------- */
.subs { display: grid; gap: 10px; }
.sub-item { border: 1px solid var(--border); border-radius: 12px; padding: 12px; display: grid; gap: 8px; }
.sub-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.badge { font-size: 0.75rem; font-weight: 650; padding: 2px 8px; border-radius: 999px; }
.badge.pass, .badge.self, .badge.attested { background: var(--good-soft); color: var(--good); }
.badge.pending { background: var(--surface-2); color: var(--ink-2); }
.badge.fail { background: var(--bad-soft); color: var(--bad); }
.badge.contested, .badge.error { background: var(--warn-soft); color: var(--warn); }
.thumbs { display: flex; gap: 6px; flex-wrap: wrap; }
.thumbs img { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); }
.feedback { font-size: 0.9rem; color: var(--ink-2); white-space: pre-wrap; }
.file-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* ---------- plan ---------- */
.plan-tasks { display: grid; gap: 8px; }
.plan-task { border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; display: grid; gap: 8px; }
.plan-task-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; color: var(--ink); font-size: 0.95rem; }
.plan-task-head input { width: 72px; flex: none; text-align: center; }
.plan-todos { display: grid; gap: 6px; }

/* ---------- to-dos ---------- */
.todo-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.todo { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 10px; background: var(--surface-2); }
.todo .check { flex: 1; min-width: 0; color: var(--ink); font-size: 0.95rem; }
.todo .check span { overflow-wrap: anywhere; }
.todo.done .check span { text-decoration: line-through; color: var(--muted); }
.todo input[type="checkbox"] { width: 18px; height: 18px; flex: none; accent-color: var(--focus); }
.todo .link { text-decoration: none; }
form.actions > input { flex: 1; min-width: 160px; width: auto; }

/* ---------- science ---------- */
details.science summary { cursor: pointer; font-weight: 600; }
.science-list { display: grid; gap: 10px; margin-top: 10px; }
.science-list div { font-size: 0.9rem; }
.science-list b { display: block; }
.science-list span { color: var(--ink-2); }

/* ---------- review ---------- */
.chart { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 2px; align-items: end; height: 150px; padding-top: 18px; border-bottom: 1px solid var(--border); position: relative; }
.chart .col { position: relative; height: 100%; display: flex; align-items: flex-end; justify-content: center; }
.chart .bar { width: min(28px, 70%); background: var(--bar); border-radius: 4px 4px 0 0; min-height: 0; }
.chart .col:hover .bar, .chart .col:focus-visible .bar { background: color-mix(in srgb, var(--bar) 80%, var(--ink)); }
.chart .val { position: absolute; top: -18px; font-size: 0.75rem; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.chart-x { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 2px; font-size: 0.75rem; color: var(--muted); text-align: center; }
.tip {
  position: fixed; z-index: 20; pointer-events: none; background: var(--ink); color: var(--bg);
  padding: 6px 9px; border-radius: 8px; font-size: 0.8rem; max-width: 220px;
}
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 0.86rem; }
th, td { text-align: right; padding: 7px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; font-variant-numeric: tabular-nums; }
th:first-child, td:first-child { text-align: left; }
th { color: var(--muted); font-weight: 600; }
.log { display: grid; gap: 8px; }
.log div { font-size: 0.9rem; }
.log .when { color: var(--muted); font-size: 0.78rem; margin-right: 6px; font-variant-numeric: tabular-nums; }

/* ---------- rules ---------- */
.task-edit { border: 1px solid var(--border); border-radius: 12px; padding: 12px; display: grid; gap: 10px; }
.pending-tag { justify-self: start; font-size: 0.78rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--warn-soft); color: var(--warn); }
.pending-box { background: var(--warn-soft); border-radius: 10px; padding: 10px 12px; font-size: 0.88rem; }

/* ---------- focus screen ---------- */
/* Always dark and low-contrast chrome: it sits on a monitor for hours. */
#screen {
  position: fixed; inset: 0; z-index: 25; overflow-y: auto;
  --bg: #0e0f11; --surface: #16171a; --surface-2: #1d1f23; --border: #2a2c31;
  --ink: #e6e6e8; --ink-2: #a9abb2; --muted: #74777f;
  --focus: #7d9cf0; --focus-soft: #1c2640; --vibe: #f0a94e; --vibe-soft: #35291a;
  --idle: #9a9da5; --idle-soft: #25272c; --accent: #7d9cf0; --accent-ink: #0e0f11;
  background: var(--bg); color: var(--ink); color-scheme: dark;
}
body.screen-open { overflow: hidden; }
.screen {
  min-height: 100%; max-width: 900px; margin: 0 auto; display: grid; grid-template-rows: auto 1fr auto;
  gap: 24px; padding: max(20px, env(safe-area-inset-top)) 24px max(20px, env(safe-area-inset-bottom));
}
.screen-top { display: flex; align-items: center; gap: 12px; }
.screen-clock { margin-left: auto; font: 500 1.1rem var(--mono); color: var(--muted); font-variant-numeric: tabular-nums; }
.screen-main { display: grid; gap: 18px; align-content: center; justify-items: stretch; }
.screen-timer {
  font: 600 clamp(4.5rem, 20vw, 13rem)/1 var(--mono); letter-spacing: -0.03em; text-align: center;
  font-variant-numeric: tabular-nums; color: var(--ink);
}
.screen[data-mode="focus"] .screen-timer { color: color-mix(in srgb, var(--focus) 35%, var(--ink)); }
.screen[data-mode="vibe"] .screen-timer { color: color-mix(in srgb, var(--vibe) 45%, var(--ink)); }
.screen .timer-label { text-align: center; margin-top: -10px; }
.screen-progress { display: grid; gap: 8px; width: min(640px, 100%); justify-self: center; }
.screen-progress .meter { height: 10px; }
.screen-todos { width: min(640px, 100%); justify-self: center; }
.screen-todos .todo { padding: 12px 14px; font-size: 1.05rem; }
.screen .note-card { width: min(640px, 100%); justify-self: center; }
.screen-actions { justify-content: center; }
.screen-foot {
  display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  color: var(--muted); font-size: 0.88rem; border-top: 1px solid var(--border); padding-top: 12px;
}

/* ---------- dialog & toast ---------- */
dialog {
  border: 1px solid var(--border); border-radius: var(--radius); padding: 0; width: min(460px, calc(100vw - 32px));
  background: var(--surface); color: var(--ink); box-shadow: 0 10px 40px rgb(0 0 0 / .25);
}
dialog::backdrop { background: rgb(0 0 0 / .35); }
dialog form { padding: 18px; display: grid; gap: 12px; }
#toast {
  position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 30;
  max-width: calc(100vw - 32px); font-size: 0.9rem;
}

.login { max-width: 360px; margin: 12vh auto 0; }

@media (max-width: 520px) {
  .tabs { margin-left: 0; }
  .tabs a { padding: 6px 8px; }
  .brand { font-size: 0; gap: 0; }
  .brand-mark { width: 14px; height: 14px; }
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .card { padding: 14px; }
}

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

/* WOOP example chips under the if-then field */
.woop-ex { display: grid; gap: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 0.82rem; padding: 4px 10px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); color: var(--ink); cursor: pointer; }
.chip:hover { border-color: var(--accent); }
