/* styles/tally.css — Tally visual system (DESIGN_SYSTEM §10, direction A 「格纸」).
   Tokens only in :root (R-CSS-1); system fonts (R-CSS-2); one reading column;
   one shadow (dialog); one ≤ 200 ms transition (R-A11Y-4). */

:root {
  --paper:#F6F3EC; --paper-2:#EBE8E1; --ink:#1E1C19; --ink-soft:#5F5D58; --rule:#D3D1CA;
  --accent:#2F4A80; --on-accent:#F6F3EC; --error:#9E3420;
  --backdrop:rgba(30,28,25,.42); --shadow:0 12px 40px rgba(30,28,25,.18);
  --font-text:"PingFang SC","Hiragino Sans GB","Microsoft YaHei","Noto Sans CJK SC","Source Han Sans SC",system-ui,sans-serif;
  --font-display:"Songti SC","STSong","Noto Serif CJK SC","Source Han Serif SC","SimSun",serif;
  --font-mono:ui-monospace,"SF Mono",Menlo,Consolas,monospace;
  --fs-cap:13px; --fs-meta:14px; --fs-body:16px; --fs-name:17px; --fs-slot:18px; --fs-title:22px; --fs-remain:30px;
  --lh-text:1.7; --lh-tight:1.3;
  --s-1:4px; --s-2:8px; --s-3:12px; --s-4:16px; --s-5:24px; --s-6:32px; --s-7:40px; --s-8:56px;
  --w-col:720px; --pad:32px; --r-ctl:4px; --r-cell:3px; --r-dialog:6px;
  --box:24px; --cell:20px; --cell-gap:6px; --slot-rule-width:1px; --edit-w:48px;
  --t-check:160ms ease-out;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { background: var(--paper); }
body {
  font-family: var(--font-text);
  font-size: var(--fs-body);
  line-height: var(--lh-text);
  color: var(--ink);
  background: var(--paper);
  padding: var(--s-5) var(--pad) var(--s-7);
  max-width: calc(var(--w-col) + 2 * var(--pad));
  margin: 0 auto;
  min-height: 100vh;
}

/* ---- masthead ---------------------------------------------------------- */
.masthead {
  display: flex; justify-content: space-between; align-items: baseline;
  padding-bottom: var(--s-5);
}
.brand { font-family: var(--font-display); font-size: 15px; letter-spacing: .06em; font-weight: 700; }
.today { font-size: var(--fs-meta); color: var(--ink-soft); }

/* ---- notices ----------------------------------------------------------- */
.notices { display: grid; gap: var(--s-2); padding-bottom: var(--s-3); }
.notice {
  display: flex; justify-content: space-between; align-items: center; gap: var(--s-3);
  background: var(--paper-2); border-left: 3px solid var(--ink);
  border-radius: var(--r-ctl); padding: var(--s-3) var(--s-4);
  font-size: 15px;
}
.notice-corrupt { border-left-color: var(--ink); color: var(--ink); }
.notice-unsaveable { border-left-color: var(--error); color: var(--error); font-weight: 600; }

/* ---- remaining line ------------------------------------------------------ */
.remaining {
  font-family: var(--font-display); font-size: var(--fs-remain); line-height: var(--lh-tight);
  font-weight: 700; margin: var(--s-3) 0 var(--s-5);
  font-variant-numeric: tabular-nums;
}
.remaining .n { text-decoration: underline; text-decoration-thickness: 3px; text-underline-offset: 6px; }

/* ---- empty state --------------------------------------------------------- */
.empty { padding: var(--s-6) 0 var(--s-4); }
.empty-title { font-family: var(--font-display); font-size: 24px; line-height: var(--lh-tight); font-weight: 700; }
.empty-body { color: var(--ink-soft); max-width: 30em; margin-top: var(--s-3); text-wrap: pretty; }
/* T5-12: number stays with its unit; no two-character widow in the lede. */
.empty-body .nb { white-space: nowrap; }

/* ---- slot sections -------------------------------------------------------- */
.slot-rule { border-top: var(--slot-rule-width) solid var(--ink); margin: var(--s-5) 0 var(--s-2); }
.slot-head { display: flex; justify-content: space-between; align-items: baseline; gap: var(--s-3); }
.slot-title {
  font-family: var(--font-display); font-size: var(--fs-slot); line-height: var(--lh-tight);
  font-weight: 700; letter-spacing: .08em;
}
/* T5-04: weekday labels share the strip's column tracks, so each label sits
   over its cell (offset by the 编辑 column + gap at >= 600px). */
.weekdays {
  font-size: var(--fs-cap); color: var(--ink-soft); white-space: nowrap;
  display: inline-flex; gap: var(--cell-gap);
  margin-right: calc(var(--edit-w) + var(--s-3));
}
.wd { width: var(--cell); text-align: center; }
.wd-today { font-weight: 700; color: var(--ink); }

ul.rows { list-style: none; }

/* ---- habit row (T5-02: one line >= 600px, DESIGN_SYSTEM §5) ------------------ */
.row { padding: var(--s-1) 0; border-bottom: 1px solid var(--rule); }
/* T5-10: no row rule under an open edit panel (avoids a doubled line). */
.row:has(form.edit-panel) { border-bottom-color: transparent; }
.row-main {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  grid-template-areas: 'check streak strip edit';
  gap: var(--s-3); align-items: center;
}
.row-main .checkin { grid-area: check; }
.row-main .streak { grid-area: streak; }
.row-main .strip { grid-area: strip; }
.row-main .edit-trigger { grid-area: edit; }

.checkin {
  display: flex; align-items: center; gap: var(--s-3);
  min-height: 48px; padding: var(--s-2) var(--s-2) var(--s-2) 0;
  background: none; border: none; border-radius: var(--r-ctl);
  font: inherit; text-align: left; color: var(--ink); cursor: pointer;
  width: 100%;
}
.name { font-size: var(--fs-name); line-height: 1.45; overflow-wrap: anywhere; }
.box {
  flex: none; width: var(--box); height: var(--box);
  border: 2px solid var(--ink); border-radius: var(--r-ctl);
  position: relative;
  transition: background-color var(--t-check), border-color var(--t-check);
}
.box::after {
  content: ''; position: absolute; inset: 0;
  background: no-repeat center / 60% 60%;
}
.checkin[aria-pressed='true'] { color: var(--ink-soft); }
.checkin[aria-pressed='true'] .name { text-decoration: line-through; text-decoration-color: var(--ink-soft); text-decoration-thickness: 1px; }
.checkin[aria-pressed='true'] .box { background-color: var(--accent); border-color: var(--accent); }
.checkin[aria-pressed='true'] .box::after {
  /* check-mark glyph drawn with the paper colour */
  content: '\2713';
  color: var(--on-accent);
  font-size: 15px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  background: none;
}

.streak { font-size: var(--fs-meta); color: var(--ink); font-variant-numeric: tabular-nums; white-space: nowrap; }
.row.done .streak { color: var(--ink-soft); }

/* ---- 7-day strip ------------------------------------------------------------ */
.strip {
  display: flex; gap: var(--cell-gap); list-style: none; flex: none;
  position: relative; padding-bottom: 10px;
}
.cell { width: var(--cell); height: var(--cell); border-radius: var(--r-cell); position: relative; flex: none; }
.cell.s-done { background: var(--accent); }
.cell.s-pending { border: 2px dashed var(--ink); }
.cell.s-missed { border: 1.5px solid var(--ink-soft); }
.cell.s-missed::after {
  content: ''; position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: 8px; height: 2px; background: var(--ink-soft);
}
.cell.s-notStarted::after {
  content: ''; position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: 4px; height: 4px; border-radius: 50%; background: var(--ink-soft);
}
/* non-colour today marker: ink bar 6px under the right-most cell */
.cell.today::before {
  content: ''; position: absolute; left: 0; right: 0; top: calc(100% + 4px);
  border-top: 2px solid var(--ink);
}

/* ---- edit trigger / panel ---------------------------------------------------- */
.edit-trigger {
  background: none; border: none; font: inherit; font-size: var(--fs-meta);
  color: var(--ink-soft); text-decoration: underline; text-decoration-color: var(--rule);
  min-width: 48px; min-height: 48px; padding: var(--s-1) var(--s-2);
  border-radius: var(--r-ctl); cursor: pointer; align-self: stretch;
}

.edit-panel {
  background: var(--paper-2); border-radius: var(--r-ctl);
  padding: var(--s-4); display: grid; gap: var(--s-3); margin: var(--s-1) 0;
}
.panel-actions { display: flex; gap: var(--s-2); align-items: center; flex-wrap: wrap; }
.panel-actions .btn-danger-text { margin-left: auto; }

/* ---- forms ---------------------------------------------------------------------- */
.create { margin-top: var(--s-5); border-top: var(--slot-rule-width) solid var(--ink); padding-top: var(--s-5); display: grid; gap: var(--s-3); }
/* T5-05: inline [input][添加] pair — no full-width bar, fits the 390px fold. */
.create-row { display: flex; gap: var(--s-2); align-items: stretch; }
.create-row .field { flex: 1 1 auto; min-width: 0; }
.create-row .btn { flex: none; }
.label { font-size: var(--fs-meta); font-weight: 600; }
.field {
  font: inherit; min-height: 44px; padding: var(--s-2) var(--s-3);
  background: var(--paper); color: var(--ink);
  border: 1.5px solid var(--ink-soft); border-radius: var(--r-ctl); width: 100%;
}
.field::placeholder { color: var(--ink-soft); }
.field[aria-invalid='true'] { border: 2px solid var(--error); }

.slots { border: none; display: flex; gap: var(--s-2); flex-wrap: wrap; }
.slots legend { padding: 0; }
.chip {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 52px; min-height: 36px; padding: var(--s-1) var(--s-3);
  border: 1.5px solid var(--ink-soft); border-radius: var(--r-ctl);
  font-size: var(--fs-meta); cursor: pointer;
}
.chip input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.chip:has(input:checked) { background: var(--ink); color: var(--paper); font-weight: 600; border-color: var(--ink); }

.error { font-size: var(--fs-meta); font-weight: 600; color: var(--error); }

/* ---- buttons ---------------------------------------------------------------------- */
.btn {
  font: inherit; font-weight: 600; font-size: var(--fs-meta);
  min-height: 44px; min-width: 24px; padding: var(--s-2) var(--s-4);
  border-radius: var(--r-ctl); cursor: pointer;
}
.btn-primary { background: var(--ink); color: var(--paper); border: none; }
.btn-secondary { background: none; color: var(--ink); border: 1.5px solid var(--ink); }
.btn-danger { background: var(--error); color: var(--paper); border: none; }
.btn-danger-text {
  background: none; border: none; color: var(--error); text-decoration: underline;
  font: inherit; font-size: var(--fs-meta); cursor: pointer; min-height: 24px;
}
button:hover { background-color: var(--paper-2); }
button:hover.btn-primary, button:hover.btn-danger { background-color: var(--ink-soft); color: var(--paper); }

/* T5-09: the dismiss control never wraps mid-word; the text wraps instead. */
.notice .btn { white-space: nowrap; flex: none; }

/* ---- delete dialog -------------------------------------------------------------------- */
/* T5-01: centring — the global `* { margin: 0 }` reset defeats the UA
   `dialog { margin: auto }`; restore it after the reset (ARCHITECTURE fix
   from TASTE_SCORECARD T5-01). */
dialog.delete-dialog, dialog.import-dialog { margin: auto; }
.delete-dialog, .import-dialog {
  border: none; border-radius: var(--r-dialog);
  background: var(--paper); color: var(--ink);
  max-width: 440px; width: min(440px, calc(100vw - 48px));
  padding: 28px; box-shadow: var(--shadow);
}
.delete-dialog::backdrop, .import-dialog::backdrop { background: var(--backdrop); }
.delete-dialog h2, .import-dialog h2 { font-family: var(--font-display); font-size: var(--fs-title); line-height: var(--lh-tight); font-weight: 700; }
.dialog-body { margin: var(--s-3) 0 var(--s-5); color: var(--ink-soft); text-wrap: normal; line-break: strict; }
.dialog-body .nb { white-space: nowrap; }
/* T5-19: one safe reflow break below 380 px; the whole middle clause stays
   atomic at 380/390/768/1440 so the visible break is the clause comma. */
@media (min-width: 380px) {
  /* The <wbr> is a 320 px-only fallback; above 360 px the middle clause is
     atomic and the visible break is the clause comma, matching the board. */
  .dialog-body .nb.middle wbr { display: none; }
}
@media (max-width: 379px) {
  .dialog-body .nb.middle { white-space: normal; word-break: keep-all; }
}
.delete-dialog h2, .import-dialog h2 { text-wrap: balance; }
.dialog-actions { display: flex; justify-content: flex-end; gap: var(--s-2); flex-wrap: wrap; }

/* ---- M2 data panel (backup export/import) --------------------------------- */
.data-panel {
  margin-top: var(--s-7);
  padding-top: var(--s-4);
  border-top: 1px solid var(--rule);
}
.data-panel .label { display: block; margin-bottom: var(--s-2); }
.data-help { color: var(--ink-soft); font-size: var(--fs-meta); max-width: 30em; margin: 0 0 var(--s-3); }
.data-help .nb { white-space: nowrap; }
.data-actions { display: flex; gap: var(--s-2); flex-wrap: wrap; align-items: center; }
.data-actions .btn { min-height: 44px; }
.data-status { min-height: 1.7em; margin: var(--s-2) 0 0; color: var(--ink-soft); font-size: var(--fs-meta); }

/* ---- focus visibility (NF-011) ----------------------------------------------------------- */
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.chip:has(input:focus-visible) { outline: 2px solid var(--ink); outline-offset: 2px; }

/* ---- visually hidden labels ---------------------------------------------------------------- */
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

/* ---- no-JS / file:// fallback --------------------------------------------------------------- */
.boot-fallback {
  max-width: 40em; margin: var(--s-8) auto; text-align: left;
}
.boot-title { font-family: var(--font-display); font-size: var(--fs-title); line-height: var(--lh-tight); font-weight: 700; margin-bottom: var(--s-3); }
.boot-body { margin: var(--s-2) 0; }
.boot-command {
  font-family: var(--font-mono); font-size: var(--fs-meta);
  background: var(--paper-2); border-radius: var(--r-ctl);
  padding: var(--s-3) var(--s-4); overflow-x: auto; margin: var(--s-2) 0;
}

/* ---- notebook margin rule (DESIGN_SYSTEM §5; T5-13) ---------------------- */
/* Direction A 「格纸」: at >= 600px a continuous 1px rule-coloured vertical
   line 18px left of the 720px column (x=342 at 1440), full page height.
   Decorative only (contrast 1.38:1, never a control boundary). */
@media (min-width: 600px) {
  body { position: relative; }
  body::before {
    content: ''; position: absolute; top: 0; bottom: 0;
    left: calc(var(--pad) - 18px);
    border-left: var(--slot-rule-width) solid var(--rule);
  }
}

/* ---- responsive: two-line row below 600px (DESIGN_SYSTEM §5) -------------------- */
@media (max-width: 599px) {
  body { padding: var(--s-4) var(--s-4) var(--s-6); }
  .remaining { font-size: 25px; }
  .row-main {
    grid-template-columns: 1fr auto;
    grid-template-areas: 'check check edit' 'streak strip strip';
  }
  .row-main .streak { padding-left: calc(var(--box) + var(--s-3)); justify-self: start; }
  .row-main .strip { justify-self: end; }
  .weekdays { margin-right: 0; }
  .slot-head { flex-wrap: wrap; }
  .notice { flex-wrap: wrap; }
}

/* ---- reduced motion (ARCHITECTURE §7.3, verbatim) ---------------------------------------------- */
@media (prefers-reduced-motion: reduce) { *, *::before, *::after {
  transition-duration: 0s !important; animation-duration: 0s !important; animation-iteration-count: 1 !important; } }
