:root {
  --bg: #eef1f5; --panel: #ffffff; --ink: #1f2d3d; --muted: #6b7686; --line: #dde3ec;
  --brand: #1f2d3d; --accent: #e8833a; --good: #2e9d5b; --bad: #d6453d;
  --radius: 16px;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html { scroll-padding-top: 8px; }
body { margin: 0; background: var(--bg); color: var(--ink); min-height: 100vh; min-height: 100dvh; -webkit-tap-highlight-color: transparent; }
button, .choice { touch-action: manipulation; -webkit-user-select: none; user-select: none; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; }
input { font: inherit; min-width: 0; max-width: 100%; }
#app { max-width: 560px; margin: 0 auto; padding: 16px 16px calc(32px + env(safe-area-inset-bottom)); }
.screen { display: none; }
.screen.on { display: block; animation: fade .35s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.card { background: var(--panel); border-radius: var(--radius); padding: 18px; margin-top: 14px; box-shadow: 0 2px 10px rgba(31,45,61,.07); }
.hero { text-align: center; padding: 28px 8px 6px; }
.hero-emoji { font-size: 56px; }
.hero h1 { margin: 6px 0 8px; font-size: 32px; letter-spacing: 2px; }
.tagline { margin: 0; color: var(--muted); line-height: 1.7; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
#nameInput { width: 100%; padding: 13px 14px; border: 1.5px solid var(--line); border-radius: 12px; font-size: 16px; /* 16px 以上 iOS 才不會自動放大 */ margin-bottom: 12px; }
#nameInput:focus { outline: 0; border-color: var(--accent); }
.hint { margin: 10px 0 0; font-size: 12.5px; color: var(--muted); text-align: center; }

.primary, .secondary, .ghost { width: 100%; padding: 13px 16px; border-radius: 12px; font-size: 16px; font-weight: 600; transition: transform .08s, filter .15s; }
.primary { background: var(--brand); color: #fff; }
.secondary { background: #e8edf4; }
.ghost { background: none; color: var(--muted); margin-top: 8px; }
.primary:active, .secondary:active { transform: scale(.98); }
.primary:hover { filter: brightness(1.15); }

/* HUD */
.hud { position: sticky; top: 0; z-index: 3; background: var(--bg); padding: 8px 0 6px; }
.hud-top { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.bar { height: 5px; background: var(--line); border-radius: 3px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .4s; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 14px; margin-top: 10px; }
.stat { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 8px; font-size: 12.5px; }
.stat .meter { height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; }
.stat .meter i { display: block; height: 100%; border-radius: 4px; transition: width .5s, background .3s; }
.stat.pulse { animation: pulse .6s; }
@keyframes pulse { 40% { transform: scale(1.06); } }

/* 場景 */
.stage { font-size: 38px; text-align: center; letter-spacing: 6px; padding: 14px 0 10px; background: linear-gradient(#f6f8fb, #fff); border-radius: 12px; }
.scene-text { margin: 14px 2px 4px; line-height: 1.85; font-size: 16px; }
.scene-text p { margin: 0 0 10px; }
.choices { display: grid; gap: 10px; margin-top: 14px; }
.choice { min-height: 52px; text-align: left; background: #f4f6fa; border: 1.5px solid transparent; border-radius: 12px; padding: 13px 14px; font-size: 15.5px; line-height: 1.5; transition: background .15s, border-color .15s, transform .08s; }
.choice:hover { background: #fff6ec; border-color: var(--accent); }
.choice:active { transform: scale(.99); }
.choice:disabled { opacity: .45; cursor: default; }
.choice.picked { background: #fff1e2; border-color: var(--accent); opacity: 1; }
.result { margin-top: 14px; animation: fade .35s; }
.result-text { background: #fbf7f0; border-left: 4px solid var(--accent); border-radius: 8px; padding: 12px 14px; line-height: 1.8; font-size: 15px; margin-bottom: 10px; }
.result-text p { margin: 0 0 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.chip { font-size: 12.5px; padding: 3px 9px; border-radius: 999px; font-weight: 600; }
.chip.up { background: #e2f5ea; color: #1d7a45; }
.chip.down { background: #fde6e4; color: #b5342d; }

/* 結局 */
.end-kicker { text-align: center; margin: 0 0 10px; color: var(--muted); font-size: 13px; letter-spacing: 3px; }
#cardCanvas { width: 100%; height: auto; display: block; border-radius: 14px; box-shadow: 0 10px 30px rgba(0,0,0,.25); }
.end-desc { margin: 16px 2px 14px; line-height: 1.85; font-size: 15px; }
.end-desc p { margin: 0 0 8px; }
.end-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.end-actions .primary { grid-column: 1 / -1; }

.coll-head { display: flex; justify-content: space-between; margin-bottom: 10px; }
.coll-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; }
.coll-item { aspect-ratio: 1; display: grid; place-items: center; font-size: 24px; border-radius: 12px; background: #eef1f5; position: relative; }
.coll-item.lock { filter: grayscale(1) opacity(.35); }
.coll-item.lock::after { content: '?'; position: absolute; font-size: 18px; color: var(--muted); }
.coll-item.lock span { visibility: hidden; }
.coll-item.now { outline: 2.5px solid var(--accent); }
@media (max-width: 380px) { .coll-grid { grid-template-columns: repeat(5, 1fr); } }

/* 手機：安全區、固定在底部的「繼續」 */
.nextbar { position: sticky; bottom: calc(10px + env(safe-area-inset-bottom)); padding-top: 8px; background: linear-gradient(rgba(255,255,255,0), #fff 40%); z-index: 2; }
.nextbar .primary { box-shadow: 0 6px 18px rgba(31,45,61,.28); padding: 15px 16px; }
.foot { text-align: center; margin: 18px 0 0; font-size: 13px; }
.foot a { color: var(--muted); }
.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); max-width: min(92vw, 420px); background: rgba(31,45,61,.95); color: #fff; padding: 11px 16px; border-radius: 12px; font-size: 14px; line-height: 1.5; text-align: center; opacity: 0; pointer-events: none; transition: .25s; z-index: 20; }
.toast.on { opacity: 1; transform: translate(-50%, 0); }

/* 結局卡與分享 */
.card-img { width: 100%; height: auto; display: block; border-radius: 14px; box-shadow: 0 10px 30px rgba(0,0,0,.25); -webkit-touch-callout: default; -webkit-user-select: auto; user-select: auto; aspect-ratio: 1080 / 1350; background: #ddd; }
.pic-hint { margin: 10px 0 0; }
.guest-cta { margin: 4px 0 8px; }
.send-title { font-size: 15px; margin: 18px 0 10px; color: var(--muted); font-weight: 600; text-align: center; }
.sendgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.sbtn { display: grid; grid-template-columns: 40px 1fr; grid-template-rows: auto auto; column-gap: 10px; align-items: center; text-align: left; background: #f4f6fa; border-radius: 14px; padding: 10px 12px; min-height: 58px; transition: transform .08s, background .15s; }
.sbtn:active { transform: scale(.97); background: #e8edf4; }
.sbtn .ic { grid-row: 1 / 3; width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 13px; letter-spacing: -.5px; }
.sbtn b { font-size: 14.5px; line-height: 1.25; align-self: end; }
.sbtn small { font-size: 11.5px; color: var(--muted); align-self: start; }
.sbtn.line .ic { background: #06c755; }
.sbtn.threads .ic { background: #111; font-size: 18px; }
.sbtn.igstory .ic { background: linear-gradient(45deg, #f9a825, #e1306c 50%, #833ab4); }
.sbtn.igdm .ic { background: linear-gradient(45deg, #833ab4, #e1306c); font-size: 18px; }
.sbtn.link .ic { background: #3a86ff; font-size: 18px; }
.sbtn.save .ic { background: #6b7686; font-size: 18px; }
#nativeBtn { margin-top: 10px; }

@media (max-width: 480px) {
  #app { padding-left: 12px; padding-right: 12px; }
  .card { padding: 14px; }
  .hero { padding-top: 18px; }
  .hero h1 { font-size: 28px; }
  .stage { font-size: 32px; padding: 10px 0 8px; }
  .scene-text { font-size: 15.5px; line-height: 1.8; }
  .stats { gap: 4px 12px; margin-top: 8px; }
  .stat { font-size: 12px; }
  .sendgrid { gap: 8px; }
  .sbtn { padding: 9px 10px; grid-template-columns: 36px 1fr; column-gap: 8px; }
  .sbtn .ic { width: 36px; height: 36px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
[hidden] { display: none !important; }

.about h2 { font-size: 16px; margin: 0 0 8px; }
.about p { font-size: 13.5px; line-height: 1.8; color: var(--muted); margin: 0 0 8px; }
.about a { color: var(--ink); }
.linkrow { display: flex; gap: 8px; margin-bottom: 10px; }
.linkrow input { flex: 1; min-width: 0; padding: 11px 12px; border: 1.5px solid var(--line); border-radius: 12px; font-size: 14px; color: var(--muted); background: #f8f9fb; }
.linkrow button { flex: none; padding: 0 14px; border-radius: 12px; background: var(--brand); color: #fff; font-weight: 600; font-size: 14px; }
.viewlink { display: block; text-align: center; margin-top: 12px; font-size: 13.5px; color: var(--muted); }
.end-desc { margin-top: 18px; }

.igguide { background: #fff4e6; border: 1.5px solid var(--accent); border-radius: 12px; padding: 12px 14px; font-size: 14px; line-height: 1.6; margin-bottom: 10px; }
.igguide b { display: block; }
.igguide ol { margin: 6px 0 0; padding-left: 20px; }
.igguide .igopen { display: block; margin-top: 10px; text-align: center; padding: 13px; border-radius: 12px; color: #fff; font-weight: 700; text-decoration: none; background: linear-gradient(45deg, #f9a825, #e1306c 50%, #833ab4); }
