/* Japandi design system for the TCM tracker.
   Wabi-sabi + hygge: warm neutrals, flat matte colour, generous space,
   organic (never geometric-perfect) accents. No gradients, no glass, no
   neon, no emoji, no pure black/white. */

:root {
  --bg: #F5F1E8;
  --surface: #FDFCFA;
  --surface-2: #ECE6D8;
  --ink: #2C2823;
  --ink-soft: #7C7468;
  --line: #E1D8C6;
  --line-strong: #C9BC9F;

  --accent: #8B7355;
  --accent-hover: #7A6347;
  --accent-ink: #FBF8F2;

  --danger: #A9503B;

  /* Muted per-section accent set — earth tones only, used as a thin rule, never a fill. */
  --tone-mauve: #A08F8A;
  --tone-ochre: #C0964F;
  --tone-clay: #B37146;
  --tone-slate: #7E8A8F;
  --tone-moss: #7A8B6E;
  --tone-stone-blue: #7D8FA0;
  --tone-rose: #C08D80;

  --shadow-sm: 0 1px 3px rgba(44, 40, 35, 0.07);
  --shadow-md: 0 6px 20px rgba(44, 40, 35, 0.08);
  --radius: 14px;
  --radius-sm: 9px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #211D18;
    --surface: #2A251E;
    --surface-2: #332C22;
    --ink: #EDE7DA;
    --ink-soft: #A69C8C;
    --line: #443B2E;
    --line-strong: #574B39;
    --accent: #C4A77D;
    --accent-hover: #D4BA92;
    --accent-ink: #211D18;
    --danger: #D48770;
  }
}
:root[data-theme="dark"] {
  --bg: #211D18;
  --surface: #2A251E;
  --surface-2: #332C22;
  --ink: #EDE7DA;
  --ink-soft: #A69C8C;
  --line: #443B2E;
  --line-strong: #574B39;
  --accent: #C4A77D;
  --accent-hover: #D4BA92;
  --accent-ink: #211D18;
  --danger: #D48770;
}

* { box-sizing: border-box; }

html, body { background: var(--bg); }

body {
  color: var(--ink);
  font-family: "Inter", "Noto Sans TC", -apple-system, system-ui, sans-serif;
  font-weight: 400;
  margin: 0;
  padding: 0 0 96px;
  min-height: 100vh;
}

h1, h2, h3 { text-wrap: balance; margin: 0; }

.display {
  font-family: "Fraunces", "Noto Serif TC", "Noto Sans TC", serif;
  font-weight: 500;
}
[data-lang="zh"] .display { font-family: "Noto Sans TC", sans-serif; font-weight: 700; }

a { color: inherit; }

button { font: inherit; cursor: pointer; color: inherit; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

/* ---------- App shell ---------- */

.app-topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 22px 20px 10px;
  max-width: 640px; margin: 0 auto;
}
.app-brand { font-size: 1.15rem; letter-spacing: -0.01em; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

/* status strip — sticky under the header, never over content, always visible */
.status-strip {
  position: sticky; top: 0; z-index: 15;
  background: var(--surface-2); border-bottom: 1px solid var(--line);
}
.status-strip-inner {
  max-width: 640px; margin: 0 auto; padding: 6px 20px;
  display: flex; align-items: center; gap: 8px;
  font-size: 0.72rem; color: var(--ink-soft);
}
.save-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--line-strong); flex-shrink: 0; }
.status-strip[data-state="saving"] .save-dot { background: var(--tone-ochre); }
.status-strip[data-state="saved"] .save-dot { background: var(--tone-moss); }
.status-strip[data-state="offline"] .save-dot { background: var(--danger); }
.status-strip[data-state="offline"] .save-label { color: var(--danger); font-weight: 600; }
.status-sync { margin-left: auto; opacity: .85; }

.langtoggle { display: flex; border: 1px solid var(--line-strong); border-radius: 999px; overflow: hidden; }
.langtoggle button {
  border: none; background: var(--surface); color: var(--ink-soft);
  padding: 6px 13px; font-size: 0.76rem; font-weight: 500;
}
.langtoggle button.on { background: var(--accent); color: var(--accent-ink); }

.app-screen { max-width: 640px; margin: 0 auto; padding: 0 20px; }
.app-screen[hidden] { display: none; }

/* Bottom nav — 5 destinations */
.app-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  background: var(--surface); border-top: 1px solid var(--line);
  padding: 8px 6px calc(8px + env(safe-area-inset-bottom));
}
.app-nav-inner {
  max-width: 640px; margin: 0 auto;
  display: grid; grid-template-columns: repeat(5, 1fr);
}
.nav-item {
  background: none; border: none; display: flex; flex-direction: column; align-items: center;
  gap: 4px; padding: 6px 2px; color: var(--ink-soft); border-radius: var(--radius-sm);
}
.nav-item svg { width: 21px; height: 21px; }
.nav-item span { font-size: 0.64rem; letter-spacing: 0.01em; }
.nav-item.active { color: var(--ink); }
.nav-item.active svg { color: var(--accent); }

/* ---------- Save-state dock ---------- */

/* ---------- Generic section/card ---------- */

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px 18px 16px; margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
}

.placeholder-screen { padding: 60px 4px 20px; }
.placeholder-screen h1 { font-size: 1.6rem; margin-bottom: 10px; }
.placeholder-screen p { color: var(--ink-soft); line-height: 1.6; max-width: 40ch; }

/* ticket-stub date card */
.ticket { position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; margin-bottom: 14px; box-shadow: var(--shadow-sm); }
.ticket-inner { display: flex; align-items: center; padding: 16px 20px; gap: 14px; }
.ticket-date { font-family: "Fraunces", "Noto Sans TC", serif; font-weight: 500; font-size: 1.5rem; flex: 1; font-variant-numeric: tabular-nums; }
[data-lang="zh"] .ticket-date { font-family: "Noto Sans TC", sans-serif; font-weight: 700; }
.ticket-sub { font-size: 0.74rem; color: var(--ink-soft); margin-top: 2px; }
.ticket-progress { font-size: 0.74rem; color: var(--ink-soft); }
.ticket::before, .ticket::after { content: ""; position: absolute; top: 50%; width: 15px; height: 15px; background: var(--bg); border-radius: 50%; transform: translateY(-50%); border: 1px solid var(--line); }
.ticket::before { left: -8px; } .ticket::after { right: -8px; }
.ticket-perf { border-top: 1px dashed var(--line-strong); margin: 0 18px; }
.ticket input[type="date"] { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }

/* mood row */
.mood-card { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 18px 16px 14px; margin-bottom: 14px; }
.mood-prompt { font-size: 1rem; font-weight: 600; margin: 0 0 3px; }
.mood-hint { font-size: 0.75rem; color: var(--ink-soft); margin: 0 0 14px; }
.mood-row { display: flex; gap: 6px; justify-content: space-between; }
.buddy-wrap { display: flex; flex-direction: column; align-items: center; gap: 6px; flex: 1; border: none; background: none; padding: 4px 0; }
.buddy { width: 100%; max-width: 50px; aspect-ratio: 1; margin: 0 auto; }
.buddy svg { width: 100%; height: 100%; display: block; }
.buddy-wrap[aria-pressed="true"] .buddy { filter: drop-shadow(0 2px 4px rgba(44,40,35,0.18)); transform: translateY(-2px); }
.buddy-wrap[aria-pressed="true"] .buddy-label { color: var(--ink); font-weight: 600; }
.buddy-label { font-size: 0.66rem; color: var(--ink-soft); text-align: center; transition: color .2s; }

.cycle-field .opts { margin-top: 2px; }

.progress { font-size: 0.78rem; color: var(--ink-soft); margin: 0 0 10px; }

/* section cards */
section.sec {
  border: 1px solid var(--line); border-radius: var(--radius);
  margin-bottom: 12px; overflow: hidden; scroll-margin-top: 14px;
  background: var(--surface);
}
section.sec.enter { animation: riseIn .35s ease-out; }
@keyframes riseIn { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: translateY(0); } }
@media (prefers-reduced-motion: reduce) { section.sec.enter { animation: none; } }

.sec-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 15px 18px; cursor: pointer; background: var(--surface);
  border-top: 3px solid var(--sec-tone, var(--line-strong));
}
.sec-header h2 { font-size: 0.95rem; font-weight: 600; }
.sec-header .tag { font-size: 0.7rem; color: var(--ink-soft); }
.sec-body { padding: 4px 18px 18px; border-top: 1px solid var(--line); }

.field { margin: 16px 0; }
.field:first-child { margin-top: 4px; }
.field label.q { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: 8px; }

.opts { display: flex; flex-wrap: wrap; gap: 7px; }
.opt {
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  border-radius: 9px; padding: 7px 12px; font-size: 0.81rem;
}
.opt.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }

.scale { display: flex; gap: 6px; }
.scale .opt { flex: 1; text-align: center; }

textarea, input[type="text"], input[type="number"], input[type="password"] {
  width: 100%; font: inherit; padding: 9px 11px;
  border: 1px solid var(--line-strong); border-radius: 9px;
  background: var(--surface); color: var(--ink);
}
textarea { min-height: 58px; resize: vertical; }
input[type="number"] { font-variant-numeric: tabular-nums; }
.other-input { margin-top: 7px; font-size: 0.81rem; padding: 7px 10px; }

.slider-wrap { padding: 4px 2px; }
.slider-wrap input[type="range"] { width: 100%; accent-color: var(--accent); }
.slider-labels { display: flex; justify-content: space-between; font-size: 0.73rem; color: var(--ink-soft); margin-top: 4px; }
.slider-labels .slider-val { font-weight: 700; color: var(--ink); font-size: 0.88rem; }

.detail { margin-top: 9px; padding-top: 9px; border-top: 1px dashed var(--line); }
.detail .q { font-size: 0.77rem; color: var(--ink-soft); margin-bottom: 5px; font-weight: 600; }

.btnrow { display: flex; gap: 8px; padding: 14px 0 2px; }
.btn { border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); border-radius: 9px; padding: 10px 16px; font-size: 0.84rem; font-weight: 500; }
.btn.primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.btn.accent { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.ghost { border-color: transparent; color: var(--ink-soft); background: none; }
.btn:disabled { opacity: .45; }

.actionbar { display: flex; gap: 8px; align-items: center; padding: 4px 0 24px; flex-wrap: wrap; }
.actionbar .spacer { flex: 1; }

.banner { font-size: 0.78rem; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 13px; margin: 12px 0; display: none; }
.banner.show { display: block; }
.banner.warn { border-color: var(--danger); color: var(--danger); }

.modal-backdrop { position: fixed; inset: 0; background: rgba(33, 29, 24, 0.45); z-index: 30; display: flex; align-items: flex-end; justify-content: center; }
.modal { background: var(--bg); border-radius: 18px 18px 0 0; padding: 20px; width: 100%; max-width: 640px; max-height: 82vh; overflow-y: auto; }
.modal h2 { font-size: 1.02rem; margin: 0 0 12px; }
.modal textarea { min-height: 240px; font-size: 0.78rem; font-family: ui-monospace, monospace; }
.modal .btnrow { padding: 12px 0 0; }

/* settings form (profile screen) */
.settings-form label { display: block; font-size: 0.8rem; font-weight: 600; margin: 12px 0 6px; }
.settings-form label:first-child { margin-top: 0; }
.settings-hint { font-size: 0.75rem; color: var(--ink-soft); margin: 4px 0 0; line-height: 1.5; }
.settings-status { font-size: 0.8rem; margin-top: 10px; padding: 8px 11px; border-radius: 9px; background: var(--surface-2); display: none; }
.settings-status.show { display: block; }
.settings-status.ok { color: var(--tone-moss); }
.settings-status.error { color: var(--danger); }

.hist-list { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.hist-row { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
