/* 怦然整理：顏色照 Swift 版（AccentColor、系統分組背景）。一般畫面基礎美感就好；慶祝要繽紛。 */
:root {
  --bg: #f2f2f7;
  --card: #ffffff;
  --fill: rgba(118, 118, 128, 0.12);
  --fill-pressed: rgba(118, 118, 128, 0.22);
  --text: #000000;
  --secondary: rgba(60, 60, 67, 0.62);
  --separator: rgba(60, 60, 67, 0.18);
  --accent: #b84665;
  --on-accent: #ffffff;
  --danger: #d70015;
  --bar: rgba(249, 249, 249, 0.94);
  --recipe-bg: #d6ebf7;
  --recipe-title: #0e4a5f;
  --recipe-ink: #123e52;
  --recipe-label: #1c262b;
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --card: #1c1c1e;
    --fill: rgba(118, 118, 128, 0.24);
    --fill-pressed: rgba(118, 118, 128, 0.36);
    --text: #ffffff;
    --secondary: rgba(235, 235, 245, 0.62);
    --separator: rgba(84, 84, 88, 0.6);
    --accent: #e8819b;
    --on-accent: #000000;
    --danger: #ff6961;
    --bar: rgba(22, 22, 24, 0.94);
    --recipe-bg: #133144;
    --recipe-title: #9cddf2;
    --recipe-ink: #d2f0fa;
    --recipe-label: #c4d6df;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang TC", "Heiti TC", "Noto Sans TC", system-ui, sans-serif;
  font-size: 17px; line-height: 1.4; -webkit-text-size-adjust: 100%; overscroll-behavior: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
h1, h2, h3, p { margin: 0; }
h3 { font-size: 17px; font-weight: 600; }
hr { border: 0; border-top: 1px solid var(--separator); margin: 4px 0; width: 100%; }
a { color: var(--accent); }
.loading { display: grid; place-items: center; height: 100vh; color: var(--secondary); }

/* ───────── 版面 ───────── */
.app { position: fixed; inset: 0; display: flex; flex-direction: column; }
.tab-content { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.page { flex: 1; min-height: 0; display: flex; flex-direction: column; background: var(--bg); }
.navbar {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px;
  padding: calc(var(--safe-top) + 6px) 12px 6px; min-height: calc(var(--safe-top) + 44px);
  background: var(--bar); border-bottom: 0.5px solid var(--separator); position: relative; z-index: 2;
}
.nav-title { font-weight: 600; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 60vw; }
.nav-right { justify-self: end; display: flex; gap: 12px; align-items: center; }
.page-body { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 16px; display: flex; flex-direction: column; gap: 16px; }
.page-bottom { padding: 12px 16px calc(var(--safe-bottom) + 12px); background: var(--bar); border-top: 0.5px solid var(--separator); }
.sheet .page-bottom, .app > .tab-content .page-bottom { padding-bottom: calc(var(--safe-bottom) + 12px); }
.tab-content .page-bottom { padding-bottom: 12px; }
.large-title { font-size: 34px; font-weight: 700; margin-top: 4px; }
.big-title { font-size: 34px; font-weight: 700; line-height: 1.15; }
.tabbar {
  display: flex; background: var(--bar); border-top: 0.5px solid var(--separator);
  padding-bottom: var(--safe-bottom); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
}
.tab { flex: 1; border: 0; background: none; padding: 6px 0 4px; display: flex; flex-direction: column; align-items: center; gap: 1px; font-size: 11px; color: var(--secondary); }
.tab-icon { font-size: 22px; filter: grayscale(1); opacity: 0.7; }
.tab.active { color: var(--accent); }
.tab.active .tab-icon { filter: none; opacity: 1; }
.sheet { position: fixed; inset: 0; z-index: 20; background: var(--bg); display: flex; flex-direction: column; animation: sheet-up 0.28s ease-out; }
@keyframes sheet-up { from { transform: translateY(40px); opacity: 0.4; } to { transform: none; opacity: 1; } }
.overlay-full { position: fixed; inset: 0; z-index: 40; background: var(--bg); }

/* ───────── 元件 ───────── */
.card { background: var(--card); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.note { font-size: 13px; color: var(--secondary); }
.muted { color: var(--secondary); }
.small-text { font-size: 15px; }
.center { display: flex; justify-content: center; }
.center-text { text-align: center; padding: 24px 8px; }
.spacer { flex: 1; min-height: 12px; }
.padded { padding: 12px 16px; }
.grow { flex: 1; text-align: left; }
.right { display: flex; flex-direction: column; align-items: flex-end; }
.indent { padding-left: 20px; }
.inline-buttons { display: inline-flex; gap: 16px; align-items: center; }

.btn {
  display: flex; align-items: center; justify-content: center; gap: 6px; width: 100%;
  border: 0; border-radius: 16px; min-height: 52px; padding: 0 16px; font-weight: 600; text-align: center;
}
.btn.primary { background: var(--accent); color: var(--on-accent); }
.btn.primary:active { opacity: 0.8; }
.btn.primary:disabled { opacity: 0.35; }
.btn.secondary { background: var(--fill); color: var(--text); font-weight: 500; min-height: 46px; border-radius: 14px; }
.btn.secondary:active { background: var(--fill-pressed); }
.btn.secondary:disabled { opacity: 0.35; }
.btn.small { min-height: 40px; width: auto; flex: 1; font-size: 15px; }
.btn.ai {
  width: auto; min-height: 0; padding: 8px 12px; border-radius: 999px; font-size: 15px; font-weight: 500;
  color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); white-space: nowrap; align-self: flex-start;
}
.btn.ai:disabled { opacity: 0.4; }
.link { border: 0; background: none; color: var(--accent); padding: 4px 0; font-size: 17px; }
.link:disabled { opacity: 0.35; }
.link.strong { font-weight: 600; }
.link.muted { color: var(--secondary); }
.link.danger, .danger { color: var(--danger); }
.link.small { font-size: 15px; align-self: flex-start; }
.plain { border: 0; background: none; padding: 0; text-align: inherit; width: 100%; }

.field {
  width: 100%; border: 0; border-radius: 10px; background: var(--fill); padding: 10px 12px; font-size: 17px; outline: none;
}
.field.bare { background: none; padding: 0; }
textarea.field { resize: vertical; min-height: 88px; }
.field:focus { box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 45%, transparent); }
.field.bare:focus { box-shadow: none; }
.search { margin-bottom: -4px; }
.select { border: 0; border-radius: 12px; background: var(--fill); padding: 10px 14px; min-height: 44px; font-weight: 500; max-width: 100%; }
.select.small { min-height: 34px; padding: 4px 10px; font-size: 15px; }
.field-with-button { display: flex; gap: 10px; align-items: center; }
.field-with-button .field { flex: 1; min-width: 0; }

.section { display: flex; flex-direction: column; gap: 6px; }
.section-header { font-size: 13px; color: var(--secondary); text-transform: uppercase; padding: 0 16px; }
.section-footer { font-size: 13px; color: var(--secondary); padding: 0 16px; }
.section-body { background: var(--card); border-radius: var(--radius); overflow: hidden; }
.row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; padding: 10px 16px;
  border: 0; background: none; width: 100%; text-align: left; border-bottom: 0.5px solid var(--separator);
}
.section-body > :last-child { border-bottom: 0; }
.row.column { flex-direction: column; align-items: stretch; gap: 4px; }
.row-inline { display: flex; justify-content: space-between; align-items: center; gap: 12px; width: 100%; }
.row.tappable:active { background: var(--fill); }
.row.accent { color: var(--accent); }
.row-title { flex: 1; min-width: 0; }
.row-value { color: var(--secondary); text-align: right; }
.chev { color: var(--secondary); font-size: 22px; line-height: 1; }
.item-row { justify-content: flex-start; }
.item-text { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.item-label { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; }
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
input[type="checkbox"][role="switch"] {
  appearance: none; -webkit-appearance: none; width: 51px; height: 31px; border-radius: 999px; background: var(--fill-pressed);
  position: relative; flex: none; transition: background 0.2s; margin: 0;
}
input[type="checkbox"][role="switch"]::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2); transition: transform 0.2s;
}
input[type="checkbox"][role="switch"]:checked { background: #34c759; }
input[type="checkbox"][role="switch"]:checked::after { transform: translateX(20px); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 0; border-radius: 999px; background: var(--fill); padding: 7px 12px; font-size: 15px; white-space: nowrap; }
.chip.selected { background: var(--accent); color: var(--on-accent); }
.chip.static { cursor: default; }
.chip .plus { color: var(--accent); margin-right: 2px; }
.chip.selected .plus { color: inherit; }
.category-picker { display: flex; flex-direction: column; gap: 12px; align-items: flex-start; }
.choices { display: flex; gap: 10px; }
.choice { flex: 1; border: 0; border-radius: 12px; min-height: 44px; background: var(--fill); font-weight: 500; }
.choice.selected { background: var(--accent); color: var(--on-accent); }
.valuation { display: flex; flex-direction: column; gap: 10px; }
.amount-row { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.choice-row { display: flex; gap: 10px; align-items: flex-start; border: 0; background: none; padding: 4px 0; text-align: left; width: 100%; }
.radio { color: var(--secondary); width: 1.2em; flex: none; }
.radio.on { color: var(--accent); }
.recipe-builder { display: flex; flex-direction: column; gap: 16px; }
.suggest { display: flex; flex-direction: column; gap: 6px; font-size: 15px; }
.ai-name { display: flex; flex-direction: column; gap: 8px; }
.stepper { display: inline-flex; background: var(--fill); border-radius: 9px; overflow: hidden; }
.stepper button { border: 0; background: none; width: 46px; height: 32px; font-size: 20px; }
.stepper button + button { border-left: 0.5px solid var(--separator); }
.stepper button:disabled { opacity: 0.3; }
.category-row { align-items: flex-start; }
.sort-buttons { display: flex; flex-direction: column; gap: 4px; }
.sort-buttons button { border: 0; background: var(--fill); border-radius: 8px; width: 36px; height: 28px; }
.sort-buttons button:disabled { opacity: 0.3; }
.icon-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.icon-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(48px, 1fr)); gap: 8px; }
.icon-cell { border: 0; height: 48px; border-radius: 12px; background: var(--fill); font-size: 24px; }
.icon-cell.selected { background: var(--accent); }
.export-text { font: 13px/1.45 ui-monospace, "SF Mono", Menlo, monospace; white-space: pre-wrap; word-break: break-word; margin: 0; max-height: 220px; overflow: auto; user-select: text; -webkit-user-select: text; }
.assign-small, .assign-big { position: relative; display: inline-flex; align-items: center; }
.assign-small { color: var(--accent); min-height: 44px; padding: 0 4px; font-size: 15px; white-space: nowrap; }
.assign-small select, .assign-big select { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; font-size: 16px; }
.assign-big[aria-disabled="true"], .assign-small[aria-disabled="true"] { opacity: 0.35; }
.source { display: block; text-decoration: none; padding: 6px 0; }
.bubble-row { display: flex; }
.bubble-row.mine { justify-content: flex-end; }
.bubble { max-width: 80%; padding: 10px 14px; border-radius: 16px; background: var(--card); }
.bubble.mine { background: var(--accent); color: var(--on-accent); }
.working { display: flex; align-items: center; gap: 12px; color: var(--secondary); font-size: 15px; padding: 8px 0; }
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2.5px solid var(--fill-pressed); border-top-color: var(--accent); animation: spin 0.8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ───────── 配方卡（《Tiny Habits》） ───────── */
.recipe-card { background: var(--recipe-bg); border-radius: 20px; padding: 18px; display: flex; flex-direction: column; gap: 14px; text-align: left; }
.recipe-title { color: var(--recipe-title); font-weight: 800; text-align: center; }
.recipe-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.recipe-label { font-size: 12px; font-weight: 700; color: var(--recipe-label); margin-bottom: 6px; }
.recipe-ink { color: var(--recipe-ink); font-size: 20px; font-weight: 500; text-decoration: underline; text-underline-offset: 4px; font-family: ui-rounded, "SF Pro Rounded", -apple-system, sans-serif; }

/* ───────── 照片與白邊貼紙 ───────── */
.photo-slot { display: grid; place-items: center; flex: none; border-radius: 10px; overflow: visible; }
.photo-slot.empty { background: var(--fill); color: var(--secondary); }
.sticker {
  max-width: 82%; max-height: 82%; object-fit: contain; background: #fff; border: 3px solid #fff; border-radius: 6px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25); transition: transform 0.15s ease-out;
}
.photo-slot.plain .sticker { max-width: 100%; max-height: 100%; }
.sticker.big { max-width: 78%; max-height: 82%; border-width: 8px; border-radius: 10px; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25); }
.rotatable { display: flex; flex-direction: column; gap: 10px; }
.rotatable-stage { display: grid; place-items: center; touch-action: none; }
.rotate-controls { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; }
.photo-row { display: flex; gap: 10px; }
.photo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; justify-items: center; width: 100%; }

/* ───────── 去留 ───────── */
.judge { position: absolute; inset: 0; display: flex; flex-direction: column; background: var(--card); }
.judge-question { font-size: 24px; font-weight: 700; text-align: center; padding: calc(var(--safe-top) + 40px) 20px 24px; }
.judge-choice { flex: 1; border: 0; font-size: 72px; font-weight: 700; }
.judge-choice.letgo { background: var(--fill); color: var(--text); }
.judge-choice.keep { background: var(--accent); color: var(--on-accent); padding-bottom: var(--safe-bottom); }
.close-x { position: absolute; top: calc(var(--safe-top) + 8px); right: 12px; border: 0; background: var(--fill); width: 32px; height: 32px; border-radius: 50%; color: var(--secondary); font-size: 15px; }
.destination, .box-step { position: absolute; inset: 0; display: flex; flex-direction: column; gap: 14px; padding: calc(var(--safe-top) + 16px) 20px calc(var(--safe-bottom) + 20px); background: var(--card); }
.row-start { display: flex; }
.destination-title { font-size: 28px; font-weight: 700; text-align: center; padding: 16px 0; }
.big-choice { border: 0; border-radius: 20px; min-height: 96px; background: var(--fill); font-size: 34px; font-weight: 700; }
.big-choice:active { background: var(--fill-pressed); }
.box-step { align-items: center; text-align: center; gap: 24px; }
.box-icon { font-size: 84px; }
.box-step h1 { font-size: 34px; }

/* ───────── 慶祝 ───────── */
.celebration { position: absolute; inset: 0; overflow: hidden; background: var(--bg); }
.festive {
  position: absolute; inset: 0;
  background: linear-gradient(135deg, #ff6fa1, #ff9f43, #ffd93b, #5be3b0, #3ad0e8, #a66bff);
  animation: festive 1.6s ease-out forwards;
}
@keyframes festive { from { opacity: 0.75; filter: hue-rotate(0deg); } to { opacity: 0.28; filter: hue-rotate(50deg); } }
.confetti { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 3; }
.celebration-body {
  position: relative; z-index: 2; height: 100%; display: flex; flex-direction: column; align-items: center; gap: 18px;
  padding: calc(var(--safe-top) + 24px) 24px calc(var(--safe-bottom) + 24px); text-align: center;
}
.celebration-body.scroll { overflow-y: auto; }
.celebration-body .stack, .celebration-body > .btn { width: 100%; }
.celebration-body .card { width: 100%; text-align: left; }
.celebrate-phrase { font-size: 34px; font-weight: 800; animation: phrase-pop 0.7s cubic-bezier(.2, 1.6, .4, 1) both; }
.celebrate-note { color: var(--secondary); animation: fade-in 0.5s 0.15s both; }
@keyframes phrase-pop { 0% { transform: scale(0.5); opacity: 0; } 45% { transform: scale(1.18); opacity: 1; } 70% { transform: scale(0.96); } 100% { transform: scale(1); } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.pop-emoji { position: relative; width: var(--size); height: var(--size); display: grid; place-items: center; }
.pop-emoji .emoji { font-size: var(--size); line-height: 1; animation: emoji-pop 0.9s cubic-bezier(.2, 1.5, .4, 1) both; }
@keyframes emoji-pop {
  0% { transform: scale(0.2) rotate(-30deg); opacity: 0; }
  35% { transform: scale(1.35) rotate(14deg); opacity: 1; }
  55% { transform: scale(0.92) rotate(-9deg); }
  75% { transform: scale(1.08) rotate(5deg); }
  100% { transform: scale(1) rotate(0); }
}
.ring { position: absolute; inset: 0; border-radius: 50%; border: 6px solid #ff6fa1; animation: ring 0.9s ease-out both; }
.ring.r1 { border-color: #ffd93b; animation-delay: 0.14s; }
.ring.r2 { border-color: #3ad0e8; animation-delay: 0.28s; }
@keyframes ring { from { transform: scale(0.3); opacity: 0.9; } to { transform: scale(2.6); opacity: 0; } }
.blitz-clock {
  align-self: center; font-weight: 600; padding: 8px 16px; border-radius: 999px; font-variant-numeric: tabular-nums;
  background: color-mix(in srgb, var(--card) 80%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.material-box { padding: 18px; border-radius: 18px; font-size: 20px; font-weight: 700; background: color-mix(in srgb, var(--card) 80%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
.blitz-over { animation: slide-up 0.45s ease-out both; }
@keyframes slide-up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.burst { position: fixed; inset: 0; z-index: 50; pointer-events: none; display: grid; place-items: center; }
.burst-phrase {
  position: relative; z-index: 4; font-size: 28px; font-weight: 800; padding: 14px 22px; border-radius: 20px;
  background: color-mix(in srgb, var(--card) 85%, transparent); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  animation: phrase-pop 0.7s cubic-bezier(.2, 1.6, .4, 1) both, fade-out 0.4s 2.1s forwards;
}
@keyframes fade-out { to { opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  .festive, .celebrate-phrase, .pop-emoji .emoji, .ring, .blitz-over, .burst-phrase, .sheet { animation-duration: 0.01s !important; animation-delay: 0s !important; }
}
