/* ============================================================
   基礎樣式：色彩、紙張質感、頁首、頁尾、按鈕與共用元件
   ============================================================ */
:root {
  --coral: #e8503a;
  --coral-dark: #b93826;
  --teal: #2f9c95;
  --teal-dark: #1f6f6a;
  --cream: #fdf6e7;
  --cream-2: #fffaf0;
  --paper: #f7eedb;
  --ink: #3d3a38;
  --ink-soft: #6b635c;
  --yellow: #f4cf4a;
  --blue: #4a9fd8;
  --purple: #8e63c4;
  --green: #5da95b;
  --line: #e4d8c2;
  --shadow: 0 10px 30px rgba(61, 58, 56, .12);
  --shadow-sm: 0 4px 14px rgba(61, 58, 56, .10);
  --radius: 22px;
  --radius-sm: 14px;
  --footer-h: 86px;
  --topbar-h: 68px;
  --font: "Noto Sans TC", "PingFang TC", "Yuanti TC", "Microsoft JhengHei", "Heiti TC", system-ui, -apple-system, "Segoe UI", sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

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

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  color: var(--ink);
  background-color: var(--cream);
  background-image:
    radial-gradient(circle at 12% 8%, rgba(244, 207, 74, .25), transparent 28%),
    radial-gradient(circle at 88% 18%, rgba(74, 159, 216, .18), transparent 30%),
    radial-gradient(circle at 50% 100%, rgba(47, 156, 149, .14), transparent 40%);
  line-height: 1.6;
  padding-bottom: 0;
  overflow-x: hidden;
}

body.reduced-motion *, body.reduced-motion *::before, body.reduced-motion *::after {
  animation-duration: .001ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: .001ms !important;
}

.bg { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; }
.bg__img {
  position: absolute; inset: 0;
  background-position: center;
  background-size: cover;
  background-repeat: no-repeat;
  opacity: .16;
  transition: opacity .6s ease;
}
.bg__paper {
  position: absolute; inset: 0;
  background-image:
    repeating-linear-gradient(0deg, rgba(61, 58, 56, .025) 0 1px, transparent 1px 4px),
    repeating-linear-gradient(90deg, rgba(61, 58, 56, .02) 0 1px, transparent 1px 5px);
  mix-blend-mode: multiply;
}

h1, h2, h3, p, dl, dd, blockquote { margin: 0; }
ul, ol { margin: 0; padding: 0; }
img { max-width: 100%; height: auto; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--teal-dark); }

:focus-visible {
  outline: 3px solid var(--blue);
  outline-offset: 3px;
  border-radius: 6px;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- 頁首 ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding: 8px clamp(10px, 3vw, 22px);
  padding-top: calc(8px + env(safe-area-inset-top));
  background: rgba(255, 250, 240, .94);
  border-bottom: 2px solid var(--line);
  backdrop-filter: blur(8px);
}
.topbar__left { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 1 1 auto; }
.brand { display: flex; align-items: center; gap: 9px; min-width: 0; }
.brand__mark { width: 38px; height: 38px; border-radius: 9px; flex: none; }
.brand__text { display: flex; flex-direction: column; min-width: 0; }
.brand__name { font-weight: 900; font-size: clamp(1rem, 3.4vw, 1.22rem); letter-spacing: .04em; color: var(--ink); white-space: nowrap; }
.brand__sub { font-size: .68rem; color: var(--ink-soft); white-space: nowrap; letter-spacing: .06em; }
.sysbar { display: flex; align-items: center; gap: 5px; flex: none; }
.topbar__back { flex: none; }

/* ---------- 按鈕 ---------- */
.icon-btn {
  width: 46px; height: 46px;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0;
  border: 2px solid var(--line);
  border-radius: 13px;
  background: var(--cream-2);
  color: var(--ink);
  box-shadow: 0 2px 0 rgba(61, 58, 56, .08);
  transition: transform .15s ease, background .15s ease, border-color .15s ease;
}
.icon-btn svg { width: 23px; height: 23px; fill: currentColor; }
.icon-btn:hover { background: #fff; border-color: var(--teal); transform: translateY(-1px); }
.icon-btn:active { transform: translateY(1px); }
.icon-btn[hidden] { display: none; }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px;
  min-height: 46px;
  padding: 10px 20px;
  border-radius: 999px;
  border: 2px solid transparent;
  font-weight: 800;
  letter-spacing: .02em;
  text-decoration: none;
  transition: transform .15s ease, box-shadow .15s ease, background .15s ease;
  box-shadow: var(--shadow-sm);
  overflow-wrap: anywhere;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.btn--primary { background: var(--coral); color: #fff; border-color: var(--coral-dark); }
.btn--primary:hover { background: #f0604a; }
.btn--ghost { background: var(--cream-2); color: var(--ink); border-color: var(--line); }
.btn--soft { background: #fff8ec; color: var(--ink); border-color: var(--line); }
.btn--soft:hover { background: #fff; }
.btn--danger { background: #fbe4df; color: var(--coral-dark); border-color: #efb6a9; }
.btn--xl { min-height: 54px; padding: 12px 30px; font-size: 1.16rem; }
.btn--sm { min-height: 44px; padding: 8px 14px; font-size: 1rem; }
.btn--icon { padding: 8px 12px; }

.kicker {
  display: inline-block;
  font-size: .78rem;
  font-weight: 800;
  letter-spacing: .12em;
  color: var(--teal-dark);
  text-transform: none;
}
.pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 5px 12px;
  border-radius: 999px;
  background: #fff8ec;
  border: 2px solid var(--line);
  font-size: .86rem;
  font-weight: 700;
  white-space: nowrap;
}
.pill b { font-variant-numeric: tabular-nums; }
.pill--stars { color: #8a6412; }
.pill--stars b { color: #6d4f0c; }

.card {
  position: relative;
  background: var(--cream-2);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

/* ---------- 主內容與頁尾 ---------- */
.main {
  position: relative;
  z-index: 1;
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 18px clamp(12px, 3.4vw, 26px);
  padding-left: calc(clamp(12px, 3.4vw, 26px) + env(safe-area-inset-left));
  padding-right: calc(clamp(12px, 3.4vw, 26px) + env(safe-area-inset-right));
  padding-bottom: calc(var(--footer-h) + 30px + env(safe-area-inset-bottom));
}

.site-footer {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 35;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  background: #fffaf0;
  border-top: 2px solid var(--line);
  text-align: center;
  font-size: clamp(.7rem, 2.6vw, .82rem);
  color: var(--ink-soft);
  line-height: 1.5;
  overflow-wrap: anywhere;
}
.site-footer a { color: var(--teal-dark); font-weight: 700; }
.site-footer a:hover { color: var(--coral-dark); }

/* ---------- 模態視窗 ---------- */
.modal {
  position: fixed; inset: 0; z-index: 120;
  display: grid; place-items: center;
  padding: 14px;
}
.modal[hidden] { display: none; }
.modal__backdrop { position: absolute; inset: 0; background: rgba(45, 38, 33, .55); backdrop-filter: blur(3px); }
.modal__panel {
  position: relative;
  width: min(560px, 100%);
  max-height: min(88vh, 760px);
  display: flex; flex-direction: column;
  background: var(--cream-2);
  border: 3px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 24px 70px rgba(0, 0, 0, .3);
  overflow: hidden;
}
.modal__panel--small { width: min(440px, 100%); }
.modal__head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 14px 16px;
  border-bottom: 2px solid var(--line);
  background: #fff4e0;
}
.modal__head h2 { font-size: clamp(1.1rem, 4vw, 1.35rem); }
.modal__body { padding: 14px 18px; overflow-y: auto; overscroll-behavior: contain; }
.modal__foot {
  display: flex; align-items: center; justify-content: flex-end; gap: 10px; flex-wrap: wrap;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  border-top: 2px solid var(--line);
  background: #fffaf0;
}
.modal__foot .tiny { margin-right: auto; }

.set-group {
  border: 2px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 14px 14px;
  margin: 0 0 14px;
  background: #fffdf8;
}
.set-group legend { padding: 0 8px; font-weight: 900; color: var(--teal-dark); }
.switch-row {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  min-height: 46px;
  padding: 4px 0;
  cursor: pointer;
  overflow-wrap: anywhere;
}
.switch-row input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch {
  position: relative;
  width: 52px; height: 30px;
  flex: none;
  border-radius: 999px;
  background: #d8cfbe;
  border: 2px solid #c6bba7;
  transition: background .18s ease;
}
.switch::after {
  content: "";
  position: absolute; top: 2px; left: 2px;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .25);
  transition: transform .18s ease;
}
.switch-row input:checked + .switch { background: var(--teal); border-color: var(--teal-dark); }
.switch-row input:checked + .switch::after { transform: translateX(22px); }
.switch-row input:focus-visible + .switch { outline: 3px solid var(--blue); outline-offset: 3px; }
.slider-row {
  display: grid;
  grid-template-columns: 82px 1fr;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  font-size: .92rem;
}
.slider-row input[type="range"] { width: 100%; accent-color: var(--coral); min-height: 44px; }
.set-note { font-size: .84rem; color: var(--ink-soft); overflow-wrap: anywhere; }
.install-guide { margin-top: 10px; font-size: .9rem; }
.steps-list { padding-left: 1.4em; margin-top: 8px; }
.steps-list li { margin-bottom: 6px; overflow-wrap: anywhere; }
.kbd {
  display: inline-block; padding: 1px 7px; border: 1px solid var(--line);
  border-radius: 6px; background: #fff; font-size: .9em;
}

/* ---------- 回饋、提示與彩紙 ---------- */
.feedback {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 10px 14px;
  border-radius: 16px;
  background: #fff;
  border: 2px solid var(--line);
  overflow-wrap: anywhere;
  scroll-margin-bottom: 6px;
}
.feedback[hidden] { display: none; }
.feedback.is-pop { animation: pop-in .28s ease both; }
.feedback.is-good { border-color: var(--teal); background: #eafaf5; }
.feedback.is-bad { border-color: #e8a18f; background: #fff1ec; }
.feedback.is-info { border-color: var(--blue); background: #eef8ff; }
.feedback__face { flex: none; font-size: 1.35rem; }
.feedback__text { display: flex; flex-direction: column; min-width: 0; }
.feedback__title { font-size: .98rem; line-height: 1.35; }
.feedback__sub { font-size: .78rem; color: var(--ink-soft); font-weight: 600; }

.toast {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 76px);
  left: 50%;
  transform: translate(-50%, -14px);
  z-index: 70;
  max-width: min(92vw, 440px);
  padding: 10px 16px;
  border-radius: 14px;
  background: rgba(61, 58, 56, .94);
  color: #fff;
  font-size: .88rem;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  overflow-wrap: anywhere;
}
.toast.is-show { opacity: 1; transform: translate(-50%, 0); }

.confetti-layer { position: fixed; inset: 0; pointer-events: none; z-index: 65; overflow: hidden; }
.confetti__piece {
  position: absolute; top: -12px;
  width: 10px; height: 16px;
  border-radius: 3px;
  animation: confetti-fall linear forwards;
}

/* ---------- 小螢幕與高度不足 ---------- */
@media (max-width: 430px) {
  .brand__sub { display: none; }
  .brand__mark { width: 34px; height: 34px; }
  .icon-btn { width: 44px; height: 44px; }
  .sysbar { gap: 4px; }
  :root { --footer-h: 78px; }
}

@media (max-width: 560px) {
  :root { --footer-h: 0px; }
  .main { padding-bottom: calc(30px + env(safe-area-inset-bottom)); }
  .site-footer { position: static; }
}

@media (max-height: 560px) {
  body { padding-bottom: 0; }
  .site-footer { position: static; }
  .main { padding-bottom: calc(30px + env(safe-area-inset-bottom)); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
}
