/* ============================================================
   元件：版面工具、按鈕、表單、卡片、標籤、對話框、提示、各頁共用區塊
   ============================================================ */

/* ---------- 版面工具 ---------- */
.page { display: grid; gap: 18px; animation: pageIn .28s ease-out both; }
.page.narrow { max-width: 780px; margin: 0 auto; width: 100%; }
/* grid 子元素預設 min-width:auto，裡面有寬表格時會把整欄撐寬（手機版整頁左右溢出），所以明確設為 0 */
.page > * { min-width: 0; }
@keyframes pageIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.page-head { display: grid; gap: 6px; padding-top: 6px; }
.page-head .lead { color: var(--ink-2); max-width: 62ch; }
.head-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); }
.row { display: flex; align-items: center; flex-wrap: wrap; }
.row.gap { gap: 12px; }
.row.gap-sm { gap: 8px; }
.row.between { justify-content: space-between; }
.row.center { justify-content: center; }
.row.top { align-items: flex-start; }
.stack { display: grid; gap: 12px; }
.stack-lg { display: grid; gap: 20px; }
.center { text-align: center; }
.muted { color: var(--ink-3); }
.small { font-size: .875rem; }
.nowrap { white-space: nowrap; }
.grow { flex: 1; min-width: 0; }
.right { margin-left: auto; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- 按鈕 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45em;
  min-height: 44px; padding: 0 18px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font-weight: 650; line-height: 1.2; text-decoration: none; cursor: pointer;
  transition: background .15s, border-color .15s, transform .06s; -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.btn:hover { background: var(--bg-2); color: var(--ink); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn-primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); color: var(--brand-ink); }
.btn-soft { background: var(--brand-soft); border-color: transparent; color: var(--brand-soft-ink); }
.btn-soft:hover { background: var(--brand-soft); color: var(--brand-soft-ink); filter: brightness(.97); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger); filter: brightness(.92); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-sm { min-height: 36px; padding: 0 14px; font-size: .9rem; }
.btn-block { width: 100%; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.icon-btn {
  display: inline-grid; place-items: center; width: 44px; height: 44px; border: 0; border-radius: 50%;
  background: transparent; color: var(--ink-2); cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.icon-btn:hover { background: var(--bg-2); color: var(--ink); }
.icon-btn.sm { width: 36px; height: 36px; }
.link-btn { border: 0; background: none; padding: 0; color: var(--brand); font-weight: 650; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }

/* ---------- 表單 ---------- */
.field { display: grid; gap: 6px; min-width: 0; }
.field > span, .field-label { font-size: .875rem; font-weight: 650; color: var(--ink-2); }
.field small { color: var(--ink-3); font-size: .8rem; line-height: 1.5; }
input[type="text"], input[type="date"], input[type="time"], input[type="number"], input[type="search"], input[type="url"], select, textarea {
  width: 100%; min-height: 44px; padding: 8px 12px; border-radius: var(--r-sm);
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: inherit;
}
textarea { min-height: 92px; resize: vertical; line-height: 1.6; }
input:focus, select:focus, textarea:focus { outline: 3px solid color-mix(in srgb, var(--focus) 40%, transparent); outline-offset: 0; border-color: var(--focus); }
input[type="checkbox"], input[type="radio"] { width: 20px; height: 20px; accent-color: var(--brand); flex: none; margin: 0; }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
legend { padding: 0; margin-bottom: 8px; font-size: .875rem; font-weight: 650; color: var(--ink-2); }
.form-grid { display: grid; gap: 14px; }
.form-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 480px) { .form-grid.three { grid-template-columns: 1fr 1fr; } .form-grid.three > :first-child { grid-column: 1 / -1; } }
.form-error { color: var(--danger); font-weight: 650; font-size: .9rem; min-height: 1.4em; }

/* ---------- 卡片 ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 18px; box-shadow: var(--shadow-1); min-width: 0; }
.card.flat { box-shadow: none; }
.card.tint { background: var(--surface-2); }
.card-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.card-title h2, .card-title h3 { display: flex; align-items: center; gap: 8px; }
.card-title .ic { color: var(--brand); }
.card-link { font-size: .9rem; font-weight: 650; text-decoration: none; white-space: nowrap; }
.empty { padding: 22px 12px; text-align: center; color: var(--ink-3); display: grid; gap: 10px; justify-items: center; }
.empty-big { width: 72px; height: 72px; margin: 8px auto; display: grid; place-items: center; border-radius: 50%; background: var(--brand-soft); color: var(--brand); }
.empty-big .ic { width: 34px; height: 34px; }

.hint { font-size: .86rem; color: var(--ink-2); background: var(--info-soft); padding: 8px 12px; border-radius: 10px; line-height: 1.6; }
.rot-up, .rot-down { transform: rotate(90deg); }
.bullets { margin: 10px 0 0; padding-left: 1.2em; display: grid; gap: 6px; }

/* ---------- 標籤 / 進度 ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 7px; min-height: 40px; padding: 0 14px; border-radius: 999px;
  border: 1.5px solid var(--line); background: var(--surface); color: var(--ink);
  font-size: .95rem; font-weight: 650; cursor: pointer; line-height: 1.2; -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
.chip:hover { background: var(--bg-2); }
.chip[aria-pressed="true"], .chip.on { background: var(--c-soft, var(--brand-soft)); border-color: var(--c, var(--brand)); }
.chip-subject::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--c); flex: none; }
.chip-sm { min-height: 32px; padding: 0 11px; font-size: .86rem; }
.chip-dashed { border-style: dashed; color: var(--ink-2); }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 999px; font-size: .78rem; font-weight: 700; background: var(--bg-2); color: var(--ink-2); white-space: nowrap; }
.badge.brand { background: var(--brand-soft); color: var(--brand-soft-ink); }
.badge.leaf { background: var(--leaf-soft); color: var(--leaf); }
.badge.gold { background: var(--gold-soft); color: var(--gold); }
.badge.info { background: var(--info-soft); color: var(--info); }

.progress { height: 10px; border-radius: 99px; background: var(--bg-2); overflow: hidden; }
.progress > i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--brand-2), var(--brand)); transition: width .5s ease; }
.progress.leaf > i { background: linear-gradient(90deg, #4cc790, var(--leaf)); }

.seg { display: inline-flex; padding: 3px; border-radius: 999px; background: var(--bg-2); border: 1px solid var(--line); }
.seg button { border: 0; background: transparent; padding: 0 16px; min-height: 36px; border-radius: 999px; font-weight: 650; color: var(--ink-2); cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-1); }

.ring { position: relative; display: grid; place-items: center; flex: none; }
.ring-svg { display: block; }
.ring-track { stroke: var(--bg-2); }
.ring-label { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; line-height: 1.15; }
.ring-label b { font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.ring-label small { font-size: .7rem; color: var(--ink-3); }

/* ---------- 對話框 / 提示 ---------- */
dialog.modal {
  width: min(580px, calc(100vw - 24px)); max-height: min(92vh, 780px); max-height: min(92dvh, 780px); padding: 0;
  border: 0; border-radius: var(--r-lg); background: var(--surface); color: var(--ink); box-shadow: var(--shadow-2);
  overflow: hidden; flex-direction: column;
}
dialog.modal[open] { display: flex; animation: modalIn .2s ease-out; }
dialog.modal::backdrop { background: rgba(30, 18, 10, .5); }
dialog.modal-sm { width: min(430px, calc(100vw - 24px)); }
@keyframes modalIn { from { opacity: 0; transform: translateY(14px) scale(.98); } to { opacity: 1; transform: none; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 8px 8px 22px; border-bottom: 1px solid var(--line-2); }
.modal-title { font-size: 1.15rem; }
.modal-body { padding: 16px 22px 20px; overflow: auto; overscroll-behavior: contain; }
.modal-text { line-height: 1.75; }
.modal-foot { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; align-items: center; padding: 12px 22px calc(12px + var(--safe-b)); border-top: 1px solid var(--line-2); background: var(--surface-2); }
.modal-foot .spacer { margin-right: auto; }
@media (max-width: 600px) {
  dialog.modal { width: 100vw; max-width: 100vw; max-height: 94dvh; margin: auto 0 0; border-radius: 22px 22px 0 0; }
  dialog.modal[open] { animation: sheetIn .24s ease-out; }
  @keyframes sheetIn { from { transform: translateY(40px); opacity: .4; } to { transform: none; opacity: 1; } }
}

.toast { pointer-events: auto; display: flex; align-items: center; gap: 12px; max-width: 540px; padding: 10px 12px 10px 18px; border-radius: 14px; background: #2b2420; color: #fff; box-shadow: var(--shadow-2); animation: toastIn .2s ease-out; font-size: .95rem; }
:root[data-theme="dark"] .toast { background: #f4ece4; color: #2a2420; }
.toast.out { opacity: 0; transform: translateY(8px); transition: .2s; }
.toast-success { background: var(--leaf); color: #fff; }
:root[data-theme="dark"] .toast-success { background: var(--leaf); color: #06231a; }
.toast-act { border: 0; background: transparent; color: #ffb9a4; font-weight: 800; padding: 6px 10px; cursor: pointer; border-radius: 8px; white-space: nowrap; }
:root[data-theme="dark"] .toast-act { color: #b0311a; }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ---------- 首頁 ---------- */
.home { gap: 16px; }
.hero {
  position: relative; overflow: hidden; border-radius: var(--r-lg); padding: 22px 20px 20px;
  background: linear-gradient(135deg, var(--brand-soft) 0%, var(--gold-soft) 120%);
  border: 1px solid var(--line);
}
.hero::after {
  content: ""; position: absolute; right: -36px; top: -40px; width: 190px; height: 190px; opacity: .13; pointer-events: none;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='-32 -32 64 64'%3E%3Cg fill='%23c83b22'%3E%3Cellipse cy='-11.5' rx='7.6' ry='12.6'/%3E%3Cellipse cy='-11.5' rx='7.6' ry='12.6' transform='rotate(72)'/%3E%3Cellipse cy='-11.5' rx='7.6' ry='12.6' transform='rotate(144)'/%3E%3Cellipse cy='-11.5' rx='7.6' ry='12.6' transform='rotate(216)'/%3E%3Cellipse cy='-11.5' rx='7.6' ry='12.6' transform='rotate(288)'/%3E%3C/g%3E%3C/svg%3E") no-repeat center / contain;
}
:root[data-theme="dark"] .hero { background: linear-gradient(135deg, #3a1d14 0%, #2b2110 120%); }
.hero > * { position: relative; z-index: 1; }
.hero-hello { font-size: 1rem; color: var(--ink-2); font-weight: 650; }
.hero-goal { display: inline-flex; align-items: center; gap: 6px; margin-top: 2px; font-weight: 800; font-size: 1.15rem; }
.hero-goal .ic { color: var(--brand); }
.hero-count { display: flex; align-items: baseline; gap: 8px; margin: 14px 0 2px; flex-wrap: wrap; }
.hero-label { font-weight: 650; color: var(--ink-2); width: 100%; }
.hero-num { font-size: clamp(3.2rem, 2.2rem + 5vw, 5rem); font-weight: 850; line-height: 1; color: var(--brand); font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.hero-unit { font-size: 1.4rem; font-weight: 800; color: var(--brand); }
.hero-sub { color: var(--ink-2); font-size: .95rem; }
.hero-live { margin-top: 4px; font-variant-numeric: tabular-nums; color: var(--ink-3); font-size: .86rem; }
.hero .progress { margin: 14px 0 6px; background: rgba(255, 255, 255, .55); }
:root[data-theme="dark"] .hero .progress { background: rgba(255, 255, 255, .12); }
.hero-note { font-size: .84rem; color: var(--ink-3); }

.install-card { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; border-color: var(--brand); background: var(--brand-soft); }
.install-card .logo { width: 44px; height: 44px; }
.install-card p { color: var(--brand-soft-ink); }
.install-card b { color: var(--brand-soft-ink); }

.today-list { display: grid; gap: 8px; list-style: none; padding: 0; margin: 0; }
.tl-item {
  display: grid; grid-template-columns: auto 1fr; gap: 12px; align-items: center; padding: 10px 12px;
  border-radius: var(--r-md); background: var(--c-soft); border-left: 5px solid var(--c);
}
.tl-item.done { opacity: .62; }
.tl-item.done .tl-title { text-decoration: line-through; }
.tl-check {
  width: 32px; height: 32px; border-radius: 50%; border: 2px solid var(--c); background: var(--surface); color: transparent;
  display: grid; place-items: center; cursor: pointer; padding: 0; touch-action: manipulation;
}
.tl-check[aria-pressed="true"] { background: var(--c); color: #fff; }
.tl-check .ic { width: 18px; height: 18px; stroke-width: 3; }
.tl-time { font-size: .82rem; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.tl-title { font-weight: 700; line-height: 1.4; }
.tl-title small { font-weight: 500; color: var(--ink-2); font-size: .88rem; margin-left: 6px; }

.stats-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.stat { display: grid; gap: 2px; justify-items: center; text-align: center; padding: 12px 6px; border-radius: var(--r-md); background: var(--bg-2); }
.stat b { font-size: 1.5rem; font-variant-numeric: tabular-nums; line-height: 1.2; }
.stat small { color: var(--ink-2); font-size: .78rem; }
.stat .ic { color: var(--brand); width: 1.4rem; height: 1.4rem; }

.quote-card { position: relative; background: var(--surface); }
.quote-text { font-family: var(--font-serif); font-size: 1.28rem; line-height: 1.75; font-weight: 600; padding-left: 4px; text-wrap: pretty; }
.quote-by { margin-top: 10px; color: var(--ink-3); font-size: .9rem; }
.quote-mark { position: absolute; right: 16px; top: 4px; font: 800 4.4rem/1 var(--font-serif); color: var(--brand-soft); pointer-events: none; user-select: none; }
.quote-actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }

.phase-card h3 { font-size: 1.1rem; }
.phase-range { color: var(--ink-3); font-size: .85rem; }
.bullets { margin: 10px 0 0; padding-left: 1.2em; display: grid; gap: 6px; }

.link-grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 200px), 1fr)); }
.link-tile {
  display: flex; align-items: center; gap: 12px; min-height: 64px; padding: 12px 14px; border-radius: var(--r-md);
  background: var(--surface); border: 1px solid var(--line); color: var(--ink); text-decoration: none; font-weight: 700;
}
.link-tile:hover { border-color: var(--brand); color: var(--ink); background: var(--surface-2); }
.link-tile .ic { color: var(--brand); width: 1.6rem; height: 1.6rem; }
.link-tile small { display: block; font-weight: 500; color: var(--ink-3); font-size: .78rem; }

/* ---------- 倒數頁 ---------- */
.cd-hero { text-align: center; padding: 26px 18px; }
.cd-hero .hero-num { font-size: clamp(3.6rem, 2.4rem + 7vw, 6rem); }
.cd-big-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; margin-top: 16px; }
.cd-list { display: grid; gap: 12px; }
.cd-item { display: grid; grid-template-columns: 6px 1fr auto; gap: 14px; align-items: center; padding: 14px 16px 14px 0; }
.cd-bar { align-self: stretch; border-radius: 6px 0 0 6px; background: var(--c); }
.cd-name { font-weight: 800; font-size: 1.05rem; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.cd-date { color: var(--ink-3); font-size: .86rem; }
.cd-days { text-align: right; line-height: 1.1; }
.cd-days b { display: block; font-size: 1.9rem; font-weight: 850; color: var(--c); font-variant-numeric: tabular-nums; }
.cd-days small { color: var(--ink-3); }
.cd-actions { display: flex; gap: 2px; margin-top: 4px; flex-wrap: wrap; }
.cd-item.past { opacity: .7; }

/* ---------- 名言頁 ---------- */
.q-list { display: grid; gap: 10px; }
.q-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: start; padding: 14px 16px; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface); }
.q-row .quote-text { font-size: 1.08rem; }
.q-fav[aria-pressed="true"] { color: var(--brand); }
.q-fav[aria-pressed="true"] .ic { fill: currentColor; }
.q-big { padding: 24px 22px; }
.q-big .quote-text { font-size: clamp(1.3rem, 1.05rem + 1vw, 1.7rem); }

/* ---------- 設定頁 ---------- */
.set-section { display: grid; gap: 14px; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 4px 0; }
.set-row + .set-row { border-top: 1px dashed var(--line); padding-top: 12px; }
.set-row > div:first-child { min-width: 0; flex: 1 1 220px; }
.set-row b { display: block; }
.set-row small { color: var(--ink-3); }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch { width: 32px; height: 32px; border-radius: 50%; border: 3px solid transparent; background: var(--c); cursor: pointer; padding: 0; }
.swatch[aria-pressed="true"] { border-color: var(--ink); box-shadow: 0 0 0 2px var(--surface) inset; }

/* ---------- 其他 ---------- */
.res-group { display: grid; gap: 10px; }
.res-item { display: grid; gap: 2px; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface); text-decoration: none; color: var(--ink); }
.res-item:hover { border-color: var(--brand); color: var(--ink); }
.res-item b { display: flex; align-items: center; gap: 6px; }
.res-item b .ic { color: var(--brand); width: 1rem; height: 1rem; }
.res-item small { color: var(--ink-3); word-break: break-all; }
.res-item p { color: var(--ink-2); font-size: .9rem; line-height: 1.6; }

.hub-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); }
.hub-card { display: grid; gap: 8px; align-content: start; padding: 18px; border-radius: var(--r-lg); background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-1); color: var(--ink); text-decoration: none; transition: transform .12s, border-color .12s; }
.hub-card:hover { transform: translateY(-2px); border-color: var(--brand); color: var(--ink); }
.hub-card .ic-wrap { width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand); }
.hub-card .ic-wrap .ic { width: 24px; height: 24px; }
.hub-card h3 { font-size: 1.12rem; }
.hub-card p { color: var(--ink-2); font-size: .92rem; line-height: 1.65; }
.hub-card .go { color: var(--brand); font-weight: 700; font-size: .9rem; }
