/* 樹蔭（shade）暫定皮膚：深夜色系（星空需要深底）。
   正式視覺待 /rush-ui 重新設計（SPEC.md 皮膚段）；
   結構 token（間距、圓角、動效）沿用 training-wall DESIGN.md 骨架。 */
:root {
  --color-bg: #0F1216;
  --color-surface: #181D25;
  --color-surface-2: #212836;
  --color-ink: #E9E6DF;
  --color-ink-soft: #99A0AC;
  --color-line: rgba(233, 230, 223, .09);
  --color-accent: #E4B15E;      /* 燭光琥珀：唯一出手色 */
  --color-accent-deep: #C4913F;
  --color-accent-tint: rgba(228, 177, 94, .12);
  --color-ok: #7FB08A;
  --color-danger: #C96A5B;

  --shadow-card: 0 1px 3px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
  --radius-card: 16px;
  --radius-btn: 12px;
  --radius-chip: 999px;
  --ease: cubic-bezier(.2, .8, .3, 1);
  --dur: 180ms;
  /* 彈簧 token（ui-checklists 第一部，全站唯二） */
  --spring-pop: cubic-bezier(0.34, 1.56, 0.64, 1);
  --spring-smooth: cubic-bezier(0.16, 1, 0.3, 1);
  --tabbar-h: 64px;
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  font-size: 15px;
  line-height: 1.6;
  color: var(--color-ink);
  background: var(--color-bg);
}

button { font: inherit; color: inherit; background: none; border: none; }
a { color: inherit; text-decoration: none; }

:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(228, 177, 94, .35);
}

#view {
  max-width: 480px;
  margin: 0 auto;
  padding: 0 16px calc(var(--tabbar-h) + 24px);
}

.page-head { padding: 20px 0 12px; }

.page-head h1 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: .01em;
}

.page[hidden] { display: none; }

.page:not([hidden]) > .enter {
  animation: enter .35s var(--spring-smooth);
}

@keyframes enter {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

.icon {
  width: 1em;
  height: 1em;
  flex: none;
  vertical-align: -.125em;
}

/* ---- 登入門 ---- */

#auth {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}

/* id 選擇器的 display 會壓過瀏覽器 [hidden] 預設，必須明寫（登入卡疊影 bug） */
#auth[hidden] { display: none; }

.auth-card {
  width: min(320px, 100%);
  text-align: center;
}

.auth-logo {
  color: var(--color-accent);
  margin-bottom: 8px;
}

.auth-logo svg { width: 44px; height: 44px; }

.auth-card h1 {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: .3em;
  text-indent: .3em;
  margin-bottom: 28px;
}

.auth-card .field { text-align: left; }

.auth-card .btn-primary { width: 100%; margin-top: 16px; }

.form-error {
  margin-top: 10px;
  font-size: 13px;
  color: var(--color-danger);
  text-align: left;
}

/* ---- 表單元件 ---- */

.field { display: block; }

.field + .field { margin-top: 14px; }

.field > span {
  display: block;
  font-size: 13px;
  color: var(--color-ink-soft);
  margin-bottom: 6px;
}

.field input, .field textarea {
  width: 100%;
  font: inherit;
  color: var(--color-ink);
  background: var(--color-surface);
  border: 1px solid var(--color-line);
  border-radius: var(--radius-btn);
  padding: 11px 14px;
  transition: border-color var(--dur) var(--ease);
}

.field input:focus, .field textarea:focus {
  border-color: var(--color-accent);
  outline: none;
  box-shadow: none;
}

.field textarea { resize: none; min-height: 76px; }

/* 數值欄位列：欄位橫排、單位標在標籤（A4：單位標一次）。
   手機寬度三格一列、四格自動折成兩列，標籤「每邊次數（下）」不擠。 */
.value-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
  gap: 10px;
}

/* 列內欄位齊頂：蓋掉 .log-form .field 的 margin-top */
.log-form .value-row .field, .value-row .field { margin-top: 0; }

.field input[inputmode="decimal"],
.field input[inputmode="numeric"] {
  font-variant-numeric: tabular-nums;
  font-size: 20px;
  text-align: center;
  padding: 12px 8px;
}

/* 秒數輸入的即時解析（標籤右側），非說明文字 */
.seconds-preview {
  float: right;
  font-weight: 600;
  color: var(--color-accent);
  font-variant-numeric: tabular-nums;
}

/* ---- 按鈕（五態） ---- */

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--color-accent);
  color: #1A1508;
  font-weight: 600;
  border-radius: var(--radius-btn);
  padding: 12px 20px;
  min-height: 46px;
  cursor: pointer;
  transition: background var(--dur) var(--ease), transform .4s var(--spring-pop);
}

.btn-primary:hover { background: #ECBE74; transform: translateY(-1px); }
.btn-primary:active { transform: scale(.95); transition-duration: 80ms; }
.btn-primary:disabled { opacity: .55; cursor: default; transform: none; }

.btn-quiet {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--color-ink-soft);
  border: 1px solid var(--color-line);
  border-radius: var(--radius-btn);
  padding: 10px 16px;
  min-height: 42px;
  cursor: pointer;
  transition: color var(--dur) var(--ease), border-color var(--dur) var(--ease), transform .4s var(--spring-pop);
}

.btn-quiet:hover { color: var(--color-ink); border-color: rgba(233, 230, 223, .25); transform: translateY(-1px); }
.btn-quiet:active { transform: scale(.95); transition-duration: 80ms; }

.btn-danger { color: var(--color-danger); border-color: rgba(201, 106, 91, .4); }
.btn-danger:hover { color: var(--color-danger); border-color: var(--color-danger); }

/* 等待中：按鈕內轉圈 */
.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(26, 21, 8, .3);
  border-top-color: #1A1508;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ---- 卡片與列 ---- */

.card {
  background: var(--color-surface);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: 16px;
}

.card + .card { margin-top: 12px; }

.row-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  background: var(--color-surface);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: 14px 16px;
  cursor: pointer;
  transition: background var(--dur) var(--ease), transform .4s var(--spring-pop);
}

.row-btn:hover { background: var(--color-surface-2); transform: translateY(-1px); }
.row-btn:active { transform: scale(.995); transition-duration: 80ms; }

.row-btn + .row-btn { margin-top: 10px; }

.row-main { flex: 1; min-width: 0; }

.row-title { font-size: 17px; font-weight: 600; }

.row-sub {
  font-size: 13px;
  color: var(--color-ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row-btn > .icon { color: var(--color-ink-soft); }

/* 左滑刪除：列滑開露出刪除鈕 */
.swipe-wrap { position: relative; }

.swipe-wrap + .swipe-wrap { margin-top: 10px; }

.swipe-wrap .row-btn {
  margin: 0;
  width: 100%;
  position: relative;
  z-index: 1;
  touch-action: pan-y;
}

.swipe-del {
  position: absolute;
  top: 0;
  bottom: 0;
  right: 0;
  width: 84px;
  border-radius: var(--radius-card);
  background: rgba(201, 106, 91, .18);
  color: var(--color-danger);
  font-weight: 600;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}

.swipe-del.armed { background: var(--color-danger); color: #fff; }
.swipe-del:disabled { opacity: .55; cursor: default; }

/* 動作色點（星色） */
.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: none;
}

/* 欄位 chip */
.chips { display: flex; gap: 6px; flex-wrap: wrap; }

.chip {
  font-size: 12px;
  color: var(--color-ink-soft);
  border: 1px solid var(--color-line);
  border-radius: var(--radius-chip);
  padding: 1px 10px;
}

/* 勾選型 chip（選單編輯欄位用） */
.chip-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  color: var(--color-ink-soft);
  border: 1px solid var(--color-line);
  border-radius: var(--radius-chip);
  padding: 8px 16px;
  min-height: 40px;
  cursor: pointer;
  transition: all var(--dur) var(--ease), transform .4s var(--spring-pop);
}

.chip-toggle:hover { transform: translateY(-1px); }
.chip-toggle:active { transform: scale(.95); transition-duration: 80ms; }

.chip-toggle[aria-pressed="true"] {
  color: var(--color-accent);
  border-color: var(--color-accent);
  background: var(--color-accent-tint);
}

/* ---- 空狀態 ---- */

.empty {
  border-radius: var(--radius-card);
  padding: 48px 24px;
  text-align: center;
  margin-top: 32px;
}

.empty-title { font-size: 17px; font-weight: 600; }

.empty .btn-quiet { margin-top: 20px; }

/* ---- 底部導覽 ---- */

.tabbar {
  position: fixed;
  inset: auto 0 0;
  height: var(--tabbar-h);
  background: rgba(15, 18, 22, .92);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--color-line);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  max-width: 480px;
  margin: 0 auto;
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 10;
}

.tabbar[hidden] { display: none; }

.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 11px;
  color: var(--color-ink-soft);
  transition: color var(--dur) var(--ease);
}

.tab .icon { font-size: 22px; }

.tab[aria-current="page"] { color: var(--color-accent); }

.tab:active { transform: scale(.95); }

/* 中央「記一筆」圓鈕浮凸 */
.tab-log { position: relative; }

.tab-log-btn {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  margin-top: -22px;
  background: var(--color-accent);
  color: #1A1508;
  border-radius: 50%;
  box-shadow: 0 4px 12px rgba(228, 177, 94, .35);
  transition: transform .4s var(--spring-pop);
}

.tab-log-btn .icon { font-size: 22px; }

.tab-log:hover .tab-log-btn { transform: translateY(-2px); }
.tab-log:active .tab-log-btn { transform: scale(.92); transition-duration: 80ms; }
.tab-log[aria-current="page"] { color: var(--color-accent); }

/* ---- 星空 ---- */

.sky {
  position: relative;
  height: calc(100dvh - var(--tabbar-h) - 120px);
  min-height: 360px;
}

.star {
  position: absolute;
  border: none;
  border-radius: 50%;
  padding: 0;
  cursor: pointer;
  /* 觸控目標 40px：視覺星體是 ::after，熱區是本體 */
  width: 40px;
  height: 40px;
  transform: translate(-50%, -50%);
  display: grid;
  place-items: center;
  background: none;
}

.star::after {
  content: "";
  width: var(--star-size, 5px);
  height: var(--star-size, 5px);
  border-radius: 50%;
  background: var(--star-color, #fff);
  box-shadow: 0 0 6px 1px var(--star-glow, rgba(255, 255, 255, .4));
  transition: transform .4s var(--spring-pop);
}

.star:hover::after { transform: scale(1.8); }
.star:active::after { transform: scale(1.3); transition-duration: 80ms; }
.star:focus-visible { box-shadow: none; }
.star:focus-visible::after { box-shadow: 0 0 0 3px rgba(228, 177, 94, .35), 0 0 6px 1px var(--star-glow, rgba(255, 255, 255, .4)); }

/* 招牌時刻（全站唯一）：新星入空 */
.star-born::after {
  animation: star-born .9s var(--spring-pop);
}

@keyframes star-born {
  0% { transform: scale(6); opacity: 0; box-shadow: 0 0 40px 12px var(--star-glow, rgba(255, 255, 255, .5)); }
  55% { transform: scale(2.2); opacity: 1; box-shadow: 0 0 24px 8px var(--star-glow, rgba(255, 255, 255, .5)); }
  100% { transform: scale(1); }
}

/* ---- 日記 ---- */

.day-label {
  font-size: 13px;
  color: var(--color-ink-soft);
  margin: 20px 4px 8px;
}

.day-label:first-child { margin-top: 4px; }

.journal-note { margin-top: 6px; white-space: pre-wrap; }

/* ---- 累積 ---- */

.total-card { display: block; }

.total-head {
  display: flex;
  align-items: center;
  gap: 10px;
}

.total-name { font-size: 17px; font-weight: 600; flex: 1; }

.total-count {
  font-size: 13px;
  color: var(--color-ink-soft);
  font-variant-numeric: tabular-nums;
}

.total-sums {
  display: flex;
  gap: 24px;
  margin-top: 12px;
}

.total-sum .n {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  color: var(--color-accent);
}

.total-sum .u {
  font-size: 12px;
  color: var(--color-ink-soft);
}

/* ---- 選單頁 ---- */

.menu-add { width: 100%; margin-bottom: 16px; }

.section-label {
  font-size: 13px;
  color: var(--color-ink-soft);
  margin: 24px 4px 8px;
}

.stagger > .section-label:first-child { margin-top: 4px; }

/* ---- 詳情彈窗 ---- */

#sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .5);
  display: grid;
  place-items: end center;
  z-index: 20;
  animation: fade var(--dur) var(--ease);
}

#sheet-backdrop[hidden] { display: none; }

@keyframes fade { from { opacity: 0; } }

#sheet {
  width: min(480px, 100%);
  background: var(--color-surface);
  border-radius: var(--radius-card) var(--radius-card) 0 0;
  padding: 20px 20px calc(20px + env(safe-area-inset-bottom));
  animation: sheet-up .35s var(--spring-smooth);
}

@keyframes sheet-up {
  from { transform: translateY(24px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.sheet-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
}

.sheet-title { font-size: 17px; font-weight: 600; flex: 1; }

.sheet-close {
  color: var(--color-ink-soft);
  cursor: pointer;
  padding: 8px;
  margin: -8px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  transition: color var(--dur) var(--ease);
}

.sheet-close:hover { color: var(--color-ink); }

/* 站內 YouTube 播放器 */
.sheet-video {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  border: none;
  border-radius: var(--radius-btn);
  background: #000;
  margin-top: 8px;
}

.sheet-values {
  font-size: 13px;
  color: var(--color-ink-soft);
  font-variant-numeric: tabular-nums;
}

.sheet-note { margin: 12px 0; white-space: pre-wrap; }

.sheet-date {
  font-size: 12px;
  color: var(--color-ink-soft);
  opacity: .7;
}

.sheet-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}

/* 修改記錄表單：沿用記一筆的欄位排版，但按鈕留在右下角、不撐滿 */
.sheet-form .sheet-date { margin-top: 16px; }
.log-form.sheet-form .btn-primary { width: auto; margin-top: 0; min-height: 42px; padding: 10px 20px; }
.sheet-form .sheet-actions .btn-quiet { white-space: nowrap; }

/* ---- 記一筆頁 ---- */

.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--color-ink-soft);
  cursor: pointer;
  padding: 8px 8px 8px 0;
  transition: color var(--dur) var(--ease);
}

.back-btn:hover { color: var(--color-ink); }

.log-form .field { margin-top: 14px; }

/* 動作備註：記一筆時的提示文字，保留換行 */
.action-note {
  margin: 0 0 4px;
  padding: 10px 12px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--color-ink-soft);
  white-space: pre-wrap;
  border-left: 2px solid var(--color-accent);
}

.log-form .btn-primary { width: 100%; margin-top: 20px; }

.demo-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--color-accent);
  margin-top: 8px;
  cursor: pointer;
}

.demo-link:hover { text-decoration: underline; }

/* 列表進場 stagger（上限 8 則，ui-checklists 第一部第 3 段） */
.stagger > * { animation: enter .35s var(--spring-smooth) backwards; }
.stagger > :nth-child(1) { animation-delay: 0ms; }
.stagger > :nth-child(2) { animation-delay: 40ms; }
.stagger > :nth-child(3) { animation-delay: 80ms; }
.stagger > :nth-child(4) { animation-delay: 120ms; }
.stagger > :nth-child(5) { animation-delay: 160ms; }
.stagger > :nth-child(6) { animation-delay: 200ms; }
.stagger > :nth-child(7) { animation-delay: 240ms; }
.stagger > :nth-child(8) { animation-delay: 280ms; }

/* ---- 減少動態防護區（每加一個動畫 class 同步加進來） ---- */
@media (prefers-reduced-motion: reduce) {
  .page:not([hidden]) > .enter,
  .stagger > *,
  #sheet,
  #sheet-backdrop { animation-duration: .01ms; animation-delay: 0ms; }
  .star-born::after { animation: none; }
  .btn-primary, .btn-quiet, .chip-toggle, .row-btn, .tab-log-btn, .star::after {
    transition: none;
  }
}
