:root {
  --bg: #fff7f5;
  --card: #ffffff;
  --text: #3a2a2e;
  --muted: #8a7479;
  --line: #f1dfe1;
  --accent: #ff6b8b;
  --accent-2: #ff9a7a;
  --accent-soft: #ffe8ec;
  --mine: #ff6b8b;
  --mine-text: #ffffff;
  --theirs: #f6eef0;
  --danger: #d6455d;
  --shadow: 0 6px 24px rgba(255, 107, 139, 0.12);
  --radius: 20px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1416;
    --card: #261c1f;
    --text: #f6e9ec;
    --muted: #b49ca2;
    --line: #3a2b2f;
    --accent-soft: #3d2229;
    --theirs: #33262a;
    --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  line-height: 1.55;
  -webkit-tap-highlight-color: transparent;
}
button, input, textarea { font: inherit; color: inherit; }

.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) 0 calc(24px + env(safe-area-inset-bottom));
}
.screen { padding: 8px 16px 24px; display: flex; flex-direction: column; gap: 16px; }
.screen.center { min-height: 90dvh; justify-content: center; }

/* ---------- 品牌 ---------- */
.brand { text-align: center; }
.brand img { border-radius: 18px; box-shadow: var(--shadow); }
.brand h1 { margin: 12px 0 0; font-size: 28px; letter-spacing: 0.08em; }
.brand p { margin: 2px 0 0; color: var(--muted); }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.topbar h1 { margin: 0; font-size: 18px; letter-spacing: 0.08em; }
.icon-btn {
  width: 40px; height: 40px; border: 0; border-radius: 50%;
  background: transparent; font-size: 20px; cursor: pointer;
  display: grid; place-items: center;
}
.icon-btn:active { background: var(--accent-soft); }

/* ---------- 卡片與表單 ---------- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 12px;
}
.card h2 { margin: 0; font-size: 17px; }
.card p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center-text { text-align: center; }

.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
.field input, textarea {
  width: 100%;
  border: 1.5px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  background: var(--bg);
  font-size: 16px; /* 避免 iOS 自動放大 */
  color: var(--text);
  outline: none;
}
.field input:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: none; }
.code-input { text-align: center; letter-spacing: 0.4em; font-size: 22px !important; font-weight: 700; text-transform: uppercase; }

button.primary, button.secondary, button.danger {
  border: 0; border-radius: 14px; padding: 13px 16px;
  font-weight: 600; cursor: pointer; width: 100%;
  transition: transform 0.1s ease, opacity 0.2s;
}
button:active:not(:disabled) { transform: scale(0.98); }
button:disabled { opacity: 0.55; cursor: default; }
.primary { background: linear-gradient(135deg, var(--accent-2), var(--accent)); color: #fff; }
.secondary { background: var(--accent-soft); color: var(--accent); }
.danger { background: transparent; color: var(--danger); }
button.small { padding: 7px 12px; width: auto; font-size: 13px; border-radius: 10px; }
.link {
  background: none; border: 0; color: var(--accent); cursor: pointer;
  padding: 6px; font-size: 14px; align-self: center;
}
.link.small { font-size: 12px; padding: 2px 0; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }

.steps { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; }
.kbd { display: inline-block; padding: 0 6px; border-radius: 6px; background: var(--accent-soft); }

/* ---------- 配對 ---------- */
.pair-code {
  text-align: center; font-size: 40px; font-weight: 800;
  letter-spacing: 0.25em; padding: 14px 0 14px 0.25em;
  color: var(--accent); background: var(--accent-soft); border-radius: 16px;
  font-variant-numeric: tabular-nums;
}
.waiting { display: flex; align-items: center; justify-content: center; gap: 8px; color: var(--muted); }
.pulse { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); animation: pulse 1.4s infinite; }
@keyframes pulse { 0%, 100% { opacity: 0.25; transform: scale(0.8); } 50% { opacity: 1; transform: scale(1.1); } }

/* ---------- 首頁 ---------- */
.hero {
  text-align: center;
  padding: 26px 18px 22px;
  border-radius: 28px;
  color: #fff;
  background: linear-gradient(145deg, #ffb199 0%, #ff6b8b 55%, #e9507a 100%);
  box-shadow: 0 12px 32px rgba(255, 107, 139, 0.32);
}
.hero p { margin: 0; }
.hero .names { font-weight: 600; font-size: 16px; }
.hero .heart { display: inline-block; animation: beat 1.6s infinite; }
@keyframes beat { 0%, 100% { transform: scale(1); } 15% { transform: scale(1.25); } 30% { transform: scale(1); } }
.hero .label { margin-top: 14px; opacity: 0.9; font-size: 14px; }
.hero .days { font-size: 18px; font-weight: 600; }
.hero .days span { font-size: 64px; font-weight: 800; line-height: 1.1; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.hero .since { opacity: 0.85; font-size: 13px; }
.hero .special { margin-top: 12px; font-weight: 700; }
.milestones { margin-top: 14px; display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.milestones span { background: rgba(255, 255, 255, 0.22); padding: 4px 10px; border-radius: 999px; font-size: 12px; }

.banner {
  background: var(--accent-soft); color: var(--text);
  border-radius: 16px; padding: 12px 14px; font-size: 14px;
}
.banner.action { display: flex; align-items: center; gap: 10px; justify-content: space-between; }

.pinned blockquote {
  margin: 0; font-size: 19px; font-weight: 600; line-height: 1.5;
  white-space: pre-wrap; word-break: break-word;
}
.pinned-head { display: flex; justify-content: space-between; align-items: center; font-size: 13px; color: var(--muted); }
.pinned.empty { align-items: center; text-align: center; gap: 4px; }

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  border: 1.5px solid var(--line); background: transparent; border-radius: 999px;
  padding: 5px 12px; font-size: 13px; cursor: pointer;
}
.chip:active { background: var(--accent-soft); }

.options { display: flex; flex-direction: column; gap: 10px; }
.toggle { display: flex; align-items: center; gap: 12px; cursor: pointer; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.switch {
  flex: none; width: 44px; height: 26px; border-radius: 999px; background: var(--line);
  position: relative; transition: background 0.2s;
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px;
  border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2); transition: transform 0.2s;
}
.toggle input:checked + .switch { background: var(--accent); }
.toggle input:checked + .switch::after { transform: translateX(18px); }
.toggle input:focus-visible + .switch { outline: 2px solid var(--accent); outline-offset: 2px; }
.toggle input:disabled ~ * { opacity: 0.45; }
.toggle-text { display: flex; flex-direction: column; line-height: 1.3; }
.toggle-text strong { font-size: 15px; font-weight: 600; }
.toggle-text small { color: var(--muted); font-size: 12px; }

.section-title { font-size: 15px; margin: 8px 4px 0; color: var(--muted); font-weight: 600; }
.messages { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.msg { display: flex; flex-direction: column; max-width: 82%; }
.msg.mine { align-self: flex-end; align-items: flex-end; }
.msg.theirs { align-self: flex-start; align-items: flex-start; }
.bubble {
  padding: 10px 14px; border-radius: 18px; white-space: pre-wrap; word-break: break-word;
}
.mine .bubble { background: var(--mine); color: var(--mine-text); border-bottom-right-radius: 6px; }
.theirs .bubble { background: var(--theirs); border-bottom-left-radius: 6px; }
.meta { display: flex; gap: 8px; align-items: center; font-size: 11px; color: var(--muted); margin-top: 3px; padding: 0 4px; }
.pinned-tag { color: var(--accent); font-weight: 600; }

.token { display: block; padding: 10px; border-radius: 10px; background: var(--bg); font-size: 12px; word-break: break-all; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  background: rgba(40, 28, 32, 0.92); color: #fff;
  padding: 10px 18px; border-radius: 999px; font-size: 14px; z-index: 20;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}

/* ---------- 通知診斷 ---------- */
.diag-title { margin: 6px 0 0; font-size: 14px; color: var(--muted); font-weight: 600; }
.diag { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.diag li { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.diag li:last-child { border-bottom: 0; }
.diag span { color: var(--muted); flex: none; }
.diag strong { font-weight: 600; text-align: right; word-break: break-all; }
