/* ============================================================
   Personal Health Tracker — Unified Stylesheet
   Aesthetic: warm-paper · Apple Health-ish · upright serif numerals
   Drop-in replacement for shared.css. Load on every page.

   Sections:
     01 · Design tokens
     02 · Base / reset
     03 · Layout shell
     04 · Top bar / breadcrumbs / page heading
     05 · Card primitives
     06 · Stat / pill / number components
     07 · Buttons
     08 · Form elements (input, textarea, radio-card)
     09 · Dividers, footnotes, focus ring
     10 · Numbness page — hero, calendar, trend SVG, dialog
     11 · Two-column responsive layout helpers
   ============================================================ */


/* ============================================================
   01 · Design tokens
   ============================================================ */
:root {
  /* — paper palette (background → surface → raised) — */
  --paper-0: #f4ece0;          /* deepest cream */
  --paper-1: #f8f1e6;          /* page background */
  --paper-2: #fcf6ec;          /* card surface */
  --paper-3: #fffaf2;          /* raised surface (inputs, dialogs) */
  --paper-line: #e9dcc7;       /* hairline borders */
  --paper-line-soft: #efe5d3;  /* internal-row borders */

  /* — ink (primary → tertiary) — */
  --ink-0: #1f1a14;            /* primary text */
  --ink-1: #3d342a;
  --ink-2: #6b5d4e;            /* secondary */
  --ink-3: #9a8a76;            /* tertiary, captions, mono labels */
  --ink-4: #bfae96;            /* placeholder, disabled */

  /* — accents (warm orange-red, ONLY for emphasis/risk) — */
  --accent:       #cf4a25;
  --accent-deep:  #a83918;
  --accent-soft:  #f4d5c5;
  --accent-wash:  #fae8dd;

  /* — semantic state colors (share warm chroma) — */
  --safe:        #5a7d4a;
  --safe-soft:   #d8e3c9;
  --warn:        #c98a21;
  --warn-soft:   #f1dfb4;
  --danger:      #c93820;
  --danger-soft: #f1cdc1;

  /* — coach module accent (muted slate blue, the one cool tone) — */
  --coach:       #5e7d92;
  --coach-soft:  #d6e0e7;
  --coach-wash:  #e8eef2;

  /* — shadows (warm, soft, never grey) — */
  --shadow-sm: 0 1px 2px rgba(80, 50, 20, 0.04),
               0 2px 6px rgba(80, 50, 20, 0.04);
  --shadow-md: 0 1px 2px rgba(80, 50, 20, 0.04),
               0 6px 18px rgba(80, 50, 20, 0.07);
  --shadow-lg: 0 1px 2px rgba(80, 50, 20, 0.05),
               0 14px 40px rgba(80, 50, 20, 0.09);

  /* — typography — */
  --font-display: "Instrument Serif", "Source Han Serif SC",
                  "Songti SC", "Noto Serif SC", serif;
  --font-body:    "Sora", -apple-system, BlinkMacSystemFont,
                  "PingFang SC", "Microsoft YaHei",
                  "Helvetica Neue", sans-serif;
  --font-mono:    "JetBrains Mono", ui-monospace, SFMono-Regular,
                  "Cascadia Mono", Menlo, Consolas, monospace;

  /* — radii — */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 18px;
  --radius-xl: 28px;
}


/* ============================================================
   02 · Base / reset
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
a { color: inherit; text-decoration: none; }
input, textarea, select { font: inherit; color: inherit; }
em, i, cite, address, var { font-style: normal; }   /* no italics anywhere */
::selection { background: var(--accent-soft); color: var(--ink-0); }

body {
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink-0);
  background:
    radial-gradient(1200px 700px at 88% -10%, #f7e6d2 0%, transparent 55%),
    radial-gradient(900px 600px at -5% 105%, #f1e1c8 0%, transparent 55%),
    var(--paper-1);
  background-attachment: fixed;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* Subtle paper grain (SVG noise as data URI) */
body::before {
  content: "";
  position: fixed; inset: 0;
  pointer-events: none;
  opacity: 0.35;
  z-index: 0;
  background-image: url("data:image/svg+xml;utf8,<svg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.92' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.45  0 0 0 0 0.35  0 0 0 0 0.22  0 0 0 0.06 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
  mix-blend-mode: multiply;
}
main, .shell { position: relative; z-index: 1; }


/* ============================================================
   03 · Layout shell
   ============================================================ */
.shell {
  max-width: 1120px;
  margin: 0 auto;
  padding: 40px 32px 96px;
}
@media (max-width: 640px) {
  .shell { padding: 24px 18px 64px; }
}


/* ============================================================
   04 · Top bar / breadcrumbs / page heading
   ============================================================ */
.topbar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 24px;
  padding-bottom: 28px;
  border-bottom: 1px solid var(--paper-line);
  margin-bottom: 36px;
}
.brand { display: flex; align-items: baseline; gap: 14px; }
.brand__mark {
  font-family: var(--font-display);
  font-size: 32px;
  line-height: 1;
  color: var(--accent-deep);
  letter-spacing: -0.01em;
}
.brand__title,
.brand__sub {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.brand__sub { letter-spacing: 0.14em; }

.crumbs {
  display: flex; gap: 10px; align-items: center;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.crumbs a { color: var(--ink-3); }
.crumbs a:hover { color: var(--accent); }
.crumbs .sep::before { content: "/"; opacity: 0.6; }
.crumbs .here { color: var(--ink-1); }

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 32px;
  margin: 8px 0 36px;
  flex-wrap: wrap;
}
.page-head h1 {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(48px, 7vw, 84px);
  letter-spacing: -0.02em;
  line-height: 0.95;
  margin: 0;
}
.page-head h1 .em { color: var(--accent); }
.page-head .lede {
  max-width: 360px;
  color: var(--ink-2);
  font-size: 14px;
  line-height: 1.6;
}


/* ============================================================
   05 · Card primitives
   ============================================================ */
.card {
  background: var(--paper-2);
  border: 1px solid var(--paper-line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  position: relative;
}
.card--raised { background: var(--paper-3); box-shadow: var(--shadow-md); }

.card__head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px 0;
}
.card__title {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin: 0;
}
.card__hint  { font-family: var(--font-mono); font-size: 11px; color: var(--ink-3); }
.card__body  { padding: 16px 22px 22px; }

/* Top-edge accent stripe inside a card */
.card--accent::before {
  content: "";
  position: absolute;
  top: 0; left: 22px; right: 22px;
  height: 3px;
  background: var(--accent);
  border-bottom-left-radius: 2px;
  border-bottom-right-radius: 2px;
}


/* ============================================================
   06 · Stat / pill / number components
   ============================================================ */
.stat { display: flex; align-items: baseline; gap: 10px; }
.stat__num {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(64px, 8vw, 96px);
  line-height: 0.9;
  letter-spacing: -0.02em;
  color: var(--ink-0);
}
.stat__num--accent { color: var(--accent); }
.stat__unit {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-3);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.stat__sub { font-size: 13px; color: var(--ink-2); margin-top: 4px; }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--paper-3);
  border: 1px solid var(--paper-line);
  color: var(--ink-1);
}
.pill::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%;
  background: currentColor; opacity: 0.7;
}
.pill--safe   { color: var(--safe);   background: var(--safe-soft);   border-color: transparent; }
.pill--warn   { color: var(--warn);   background: var(--warn-soft);   border-color: transparent; }
.pill--danger { color: var(--accent); background: var(--accent-soft); border-color: transparent; }


/* ============================================================
   07 · Buttons
   ============================================================ */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.01em;
  background: var(--paper-3);
  border: 1px solid var(--paper-line);
  color: var(--ink-0);
  transition: all .15s ease;
}
.btn:hover { background: #fff; border-color: var(--ink-4); }
.btn--primary {
  background: var(--accent);
  color: #fff8f1;
  border-color: var(--accent-deep);
  box-shadow: 0 1px 0 rgba(255,255,255,0.25) inset,
              0 2px 6px rgba(168, 57, 24, 0.25);
}
.btn--primary:hover { background: var(--accent-deep); color: #fff; border-color: var(--accent-deep); }
.btn--ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn--ghost:hover { color: var(--ink-0); background: var(--paper-3); }
.btn--sm { padding: 6px 12px; font-size: 12px; }
.btn--xs { padding: 4px 10px; font-size: 11px; }


/* ============================================================
   08 · Form elements
   ============================================================ */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.input, .textarea {
  background: var(--paper-3);
  border: 1px solid var(--paper-line);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  font-size: 14px;
  color: var(--ink-0);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus, .textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-wash);
}
.textarea { resize: vertical; min-height: 56px; font-family: inherit; }

/* Two-up radio cards (e.g. 左手麻 / 无症状) */
.radiogroup { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.radio-card {
  position: relative;
  cursor: pointer;
  padding: 16px 18px;
  border-radius: var(--radius-md);
  border: 1px solid var(--paper-line);
  background: var(--paper-3);
  display: flex; flex-direction: column; gap: 4px;
  transition: all .15s ease;
}
.radio-card input { position: absolute; opacity: 0; pointer-events: none; }
.radio-card__icon {
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 1.5px solid var(--ink-4);
  margin-bottom: 6px;
}
.radio-card__title { font-weight: 500; font-size: 15px; }
.radio-card__sub   { font-size: 12px; color: var(--ink-3); }
.radio-card:hover  { border-color: var(--ink-4); }
.radio-card.is-checked {
  border-color: var(--accent);
  background: var(--accent-wash);
}
.radio-card.is-checked .radio-card__icon {
  border-color: var(--accent); background: var(--accent);
  box-shadow: inset 0 0 0 4px var(--paper-3);
}
.radio-card.is-checked.radio-card--clear { border-color: var(--safe); background: var(--safe-soft); }
.radio-card.is-checked.radio-card--clear .radio-card__icon {
  border-color: var(--safe); background: var(--safe);
}


/* ============================================================
   09 · Dividers, footnotes, focus ring
   ============================================================ */
.hr {
  border: 0; height: 1px;
  background: var(--paper-line);
  margin: 24px 0;
}
.footnote {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  color: var(--ink-3);
  text-transform: uppercase;
}
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}


/* ============================================================
   10 · Numbness page-specific
   (hero stats, calendar, SVG trend, dialog)
   ============================================================ */

/* — Hero 3-cell stat strip — */
.hero-stats {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  padding: 28px 8px;
  margin-bottom: 24px;
}
@media (max-width: 720px) {
  .hero-stats { grid-template-columns: 1fr; padding: 18px 8px; }
  .hero-stats .hero-cell--middle {
    border-left: 0; border-right: 0;
    border-top: 1px dashed var(--paper-line);
    border-bottom: 1px dashed var(--paper-line);
  }
}
.hero-cell { padding: 12px 28px; display: flex; flex-direction: column; gap: 6px; }
.hero-cell--middle {
  border-left: 1px dashed var(--paper-line);
  border-right: 1px dashed var(--paper-line);
}
.hero-cell__label {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.hero-cell__big {
  font-family: var(--font-display);
  font-size: clamp(72px, 9vw, 112px);
  line-height: 0.9;
  letter-spacing: -0.025em;
  color: var(--ink-0);
}
.hero-cell:first-child .hero-cell__big { color: var(--accent); }
.hero-cell__big .unit {
  font-family: var(--font-mono);
  font-size: 14px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin-left: 8px;
}
.hero-cell__pill { margin-top: 8px; }
.hero-cell__pill .pill { font-size: 12px; padding: 6px 14px; }
.hero-cell__sub {
  font-size: 12px;
  color: var(--ink-3);
  font-family: var(--font-mono);
  letter-spacing: 0.06em;
  margin-top: 4px;
}

/* — This-month bistat — */
.bistat {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 8px 0;
}
.bistat__cell { text-align: center; }
.bistat__num {
  font-family: var(--font-display);
  font-size: 64px;
  line-height: 1;
  letter-spacing: -0.02em;
  color: var(--accent);
}
.bistat__sub {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin-top: 6px;
}
.bistat__sep { width: 1px; align-self: stretch; background: var(--paper-line); margin: 6px 0; }

.mom { display: flex; flex-direction: column; gap: 8px; }
.mom__row { display: flex; justify-content: space-between; font-size: 13px; color: var(--ink-2); }
.mom__v { font-family: var(--font-mono); color: var(--ink-0); font-size: 12px; letter-spacing: 0.04em; }
.mom__v.up   { color: var(--accent); }
.mom__v.down { color: var(--safe); }
.mom__v.flat { color: var(--ink-3); }

/* — Calendar — */
.cal-card { margin-bottom: 24px; }
.cal-head { flex-wrap: wrap; gap: 12px; padding-bottom: 8px; }
.cal-nav  { display: flex; align-items: center; gap: 8px; }
.cal-title {
  font-family: var(--font-display);
  font-size: 24px;
  letter-spacing: -0.01em;
  min-width: 140px;
  text-align: center;
  color: var(--ink-0);
}
.cal-weekrow {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  padding: 8px 0 12px;
  border-bottom: 1px dashed var(--paper-line);
  margin-bottom: 12px;
}
.cal-weekrow span {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-3);
  text-align: center;
}
.cal-weekrow .we { color: var(--ink-4); }

.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-day {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: var(--radius-md);
  background: var(--paper-3);
  border: 1px solid transparent;
  padding: 8px 8px 6px;
  display: flex; flex-direction: column;
  cursor: pointer;
  transition: all .15s ease;
  min-height: 60px;
}
.cal-day:hover {
  border-color: var(--ink-4);
  background: #fff;
  transform: translateY(-1px);
}
.cal-day__n {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--ink-1);
  letter-spacing: 0.02em;
  line-height: 1;
}
.cal-day__we  { color: var(--ink-3); }
.cal-day__out { opacity: 0.35; cursor: default; pointer-events: none; }
.cal-day__today { outline: 2px solid var(--ink-1); outline-offset: -2px; }
.cal-day__today .cal-day__n { font-weight: 600; color: var(--ink-0); }

/* Calendar state cells */
.cal-day--left  { background: var(--accent-wash); border-color: var(--accent-soft); }
.cal-day--left .cal-day__n { color: var(--accent-deep); font-weight: 500; }
.cal-day--clear { background: var(--safe-soft); border-color: rgba(90,125,74,0.2); }
.cal-day--clear .cal-day__n { color: #3f5a30; }

.cal-day__mark { margin-top: auto; display: flex; align-items: center; gap: 4px; height: 14px; }
.cal-day__mark .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--ink-4); opacity: 0.35;
}
.cal-day--left  .cal-day__mark .dot { background: var(--accent); opacity: 1; }
.cal-day--clear .cal-day__mark .dot { background: var(--safe);   opacity: 1; }
.cal-day__note  { width: 4px; height: 4px; border-radius: 50%; background: var(--ink-3); align-self: center; }

.cal-legend {
  margin-top: 18px;
  display: flex; gap: 18px; flex-wrap: wrap;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.cal-legend .legend { display: inline-flex; align-items: center; gap: 6px; }
.cal-legend .dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.cal-legend .dot--danger { background: var(--accent); }
.cal-legend .dot--safe   { background: var(--safe); }
.cal-legend .dot--empty  { background: var(--ink-4); opacity: 0.4; }
.cal-legend .dot--note   { background: var(--ink-3); width: 4px; height: 4px; }

/* — Segmented control (8w / 12w / 24w) — */
.seg {
  display: inline-flex;
  background: var(--paper-3);
  border: 1px solid var(--paper-line);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
}
.seg__btn {
  padding: 5px 14px;
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-2);
  transition: all .15s ease;
}
.seg__btn:hover { color: var(--ink-0); }
.seg__btn.is-active { background: var(--ink-0); color: var(--paper-3); }

/* — Hand-rolled SVG bar chart (zero deps) — */
.trend-wrap { padding: 8px 4px 0; min-height: 240px; }
.trend-svg  { display: block; width: 100%; height: 240px; overflow: visible; }
.trend-svg .trend-bar { transition: opacity .15s ease; }
.trend-svg .trend-bar:hover { opacity: 0.78; cursor: default; }
.trend-svg .trend-y,
.trend-svg .trend-x {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  fill: var(--ink-3);
}
.trend-svg .trend-val {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.04em;
  fill: var(--ink-1);
}
.trend-foot { margin-top: 6px; }

/* — Modal dialog — */
.dialog-backdrop[hidden] { display: none !important; }
.dialog-backdrop {
  position: fixed; inset: 0;
  background: rgba(40, 26, 14, 0.4);
  backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  animation: fade .15s ease;
}
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }
.dialog {
  width: min(440px, calc(100vw - 32px));
  background: var(--paper-2);
  border-radius: var(--radius-lg);
  border: 1px solid var(--paper-line);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: pop .2s cubic-bezier(.2,.8,.2,1.2);
}
@keyframes pop {
  from { opacity: 0; transform: scale(.96) translateY(8px); }
  to   { opacity: 1; transform: none; }
}
.dialog__head {
  display: flex; align-items: flex-start; justify-content: space-between;
  padding: 20px 24px 14px;
  border-bottom: 1px solid var(--paper-line);
}
.dialog__title {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 32px;
  margin: 4px 0 0;
  line-height: 1;
  letter-spacing: -0.01em;
}
.dialog__body { padding: 18px 24px 4px; }
.dialog__foot {
  padding: 14px 20px;
  display: flex; align-items: center; gap: 8px;
  background: var(--paper-1);
  border-top: 1px solid var(--paper-line);
}


/* ============================================================
   11 · Two-column responsive helpers
   ============================================================ */
.two-col {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 22px;
  margin-bottom: 24px;
}
@media (max-width: 820px) { .two-col { grid-template-columns: 1fr; } }
.row-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
