:root {
  --bg: #f6efe4;
  --panel: #fffaf2;
  --ink: #2b2420;
  --muted: #7a6e63;
  --line: #e7dccb;
  --chip: #efe5d6;
  --accent: #c8553d;
  --accent-ink: #fff;
  --warm: #e08a5e;
  --past: #d9cfc2;
  --soft: #f9e6dc;
  --shadow: 0 1px 2px rgba(80, 50, 20, .05), 0 12px 32px rgba(80, 50, 20, .08);
  --sans: -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  --serif: "Noto Serif TC", "Songti TC", "PMingLiU", serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1714; --panel: #25201c; --ink: #f2e9dd; --muted: #b0a394; --line: #3a322b; --chip: #312a24;
    --accent: #e3725a; --warm: #e99a6f; --past: #4a413a; --soft: #3a2620;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 12px 32px rgba(0, 0, 0, .3);
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--sans); line-height: 1.6; -webkit-font-smoothing: antialiased; }
body.modal-open { overflow: hidden; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
small { font-size: .8em; color: var(--muted); font-weight: 400; }

/* ---------- 頁首 ---------- */
.top, main, .foot { max-width: 860px; margin: 0 auto; padding: 0 20px; }
.top { display: flex; align-items: center; justify-content: space-between; padding-top: 18px; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.brand b { font-family: var(--serif); font-size: 20px; letter-spacing: .04em; }
.brand small { margin-left: 6px; letter-spacing: .12em; }
.dot-logo { width: 18px; height: 18px; border-radius: 50%; background: var(--accent); box-shadow: 10px 0 0 -3px var(--warm), 18px 0 0 -6px var(--past); margin-right: 12px; flex: none; }
.dot-logo.big { width: 34px; height: 34px; box-shadow: 18px 0 0 -6px var(--warm), 32px 0 0 -11px var(--past); margin: 0 26px 10px 0; }
.nav { display: flex; gap: 4px; }
.nav a { text-decoration: none; padding: 6px 12px; border-radius: 99px; font-size: 15px; color: var(--muted); }
.nav a.on { background: var(--chip); color: var(--ink); font-weight: 600; }

/* ---------- 首頁 ---------- */
.hero { text-align: center; padding: 64px 0 40px; }
.hero.small { padding: 44px 0 20px; }
.eyebrow { color: var(--accent); font-weight: 700; letter-spacing: .12em; font-size: 14px; margin: 0 0 10px; }
.hero h1 { font-family: var(--serif); font-size: clamp(34px, 7vw, 54px); line-height: 1.3; margin: 0 0 18px; letter-spacing: .02em; }
.lead { color: var(--muted); font-size: 17px; max-width: 560px; margin: 0 auto; }
.hero-dots { display: grid; grid-template-columns: repeat(15, 14px); gap: 9px; justify-content: center; margin: 34px auto; }
.hero-dots i { width: 14px; height: 14px; border-radius: 50%; background: var(--warm); animation: pop .5s backwards; }
.hero-dots i.past { background: var(--past); }
.hero-dots i:nth-child(n) { animation-delay: calc(var(--i, 0) * 1ms); }
@keyframes pop { from { transform: scale(0); } }
.btn.huge { font-family: var(--serif); font-size: 30px; padding: 22px 76px; letter-spacing: .12em; box-shadow: 0 10px 30px rgba(200, 85, 61, .3); animation: breathe 3s ease-in-out infinite; }
@keyframes breathe { 50% { transform: scale(1.03); box-shadow: 0 14px 40px rgba(200, 85, 61, .38); } }
.hero-sub { margin: 26px 0 6px; }
.hero-sub a { color: var(--muted); font-size: 15px; }

/* ---------- 結果的文字 ---------- */
.summary { text-align: center; background: var(--panel); border: 1px solid var(--line); border-radius: 24px; padding: 28px 20px; margin-bottom: 20px; box-shadow: var(--shadow); }
.summary:empty { display: none; }
.summary p { margin: 0; color: var(--muted); }
.sum-num { font-family: var(--serif); font-size: clamp(44px, 10vw, 64px); color: var(--accent); font-weight: 800; line-height: 1.3; margin: 6px 0; }
.sum-sub { font-size: 15px; }
.story { font-family: var(--serif); font-size: 17px; line-height: 1.95; margin: 6px 0 20px; padding: 22px 22px 22px 24px; border-left: 3px solid var(--warm); background: var(--bg); border-radius: 4px 18px 18px 4px; }
.story h4 { font-family: var(--sans); font-size: 14px; color: var(--muted); margin: 0 0 12px; letter-spacing: .05em; }
.age-row { display: grid; grid-template-columns: 1fr 2fr; gap: 0 14px; }
.age-row .inline { margin-top: 0; }
.age-row .inline input { width: 100%; max-width: 140px; }
.req { color: var(--accent); font-weight: 700; }
.warn { background: #fdeae4; color: #a5371f; border: 1px solid #f3c2b4; border-radius: 12px; padding: 10px 14px; font-size: 14px; margin: -4px 0 14px; }
@media (prefers-color-scheme: dark) { .warn { background: #3a2018; color: #ffb6a1; border-color: #5a3024; } }
.story p { margin: 0 0 12px; }
.story p:last-child { margin: 0; color: var(--accent); font-weight: 700; }
.story b { color: var(--accent); }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 8px; margin-bottom: 18px; }
.fact { background: var(--bg); border-radius: 14px; padding: 12px 14px; display: flex; flex-direction: column; }
.fact span { font-size: 13px; color: var(--muted); }
.fact b { font-family: var(--serif); font-size: 20px; }
.timeline { margin-bottom: 18px; }
.timeline h4, .fest-detail summary { font-size: 15px; margin: 0 0 8px; color: var(--muted); }
.tl-row { display: flex; gap: 12px; align-items: flex-start; padding: 8px 0 8px 2px; position: relative; }
.tl-row:not(:last-child)::after { content: ''; position: absolute; left: 7px; top: 24px; bottom: -8px; width: 2px; background: var(--line); }
.tl-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--warm); margin-top: 7px; flex: none; }
.tl-row:nth-child(n+4) .tl-dot { background: var(--past); }
.tl-row small { display: block; }
.tl-row b { color: var(--accent); }
.fest-detail { margin-bottom: 16px; }
.fest-detail summary { cursor: pointer; font-weight: 600; padding: 6px 0; }
.fest-detail[open] summary { margin-bottom: 8px; }
.closing { text-align: center; padding: 20px 0 10px; }
.closing-q { font-family: var(--serif); font-size: 21px; line-height: 1.9; margin: 0 0 18px; }
.r-actions.center { justify-content: center; }
.center { text-align: center; }

/* ---------- 按鈕 ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--panel); border-radius: 99px; padding: 10px 18px; font-weight: 600; cursor: pointer; text-decoration: none; font-size: 15px; transition: transform .1s, background .2s; }
.btn:hover { background: var(--chip); }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.big { padding: 14px 28px; font-size: 17px; }
.btn.small { padding: 6px 14px; font-size: 14px; }
.btn.wide { width: 100%; }
.link-btn { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 10px; text-decoration: underline; display: block; margin: 8px auto 0; }
.icon-btn { border: 0; background: transparent; cursor: pointer; font-size: 16px; padding: 6px 9px; border-radius: 8px; color: var(--muted); }
.icon-btn:hover { background: var(--chip); }

/* ---------- 表單 ---------- */
.block { background: var(--panel); border: 1px solid var(--line); border-radius: 22px; box-shadow: var(--shadow); padding: 22px; margin-bottom: 18px; }
.block h2 { font-family: var(--serif); font-size: 22px; margin: 0 0 16px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.num { width: 28px; height: 28px; border-radius: 50%; background: var(--accent); color: #fff; font: 700 15px/28px var(--sans); text-align: center; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; min-width: 0; }
.flabel { font-size: 14px; font-weight: 600; color: var(--muted); }
input[type=number], input[type=date], input:not([type]), select, textarea {
  width: 100%; border: 1px solid var(--line); background: var(--bg); border-radius: 12px; padding: 10px 12px; font-size: 16px; min-height: 44px;
}
textarea { resize: vertical; line-height: 1.6; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--warm); outline-offset: 1px; }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 32px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 14px; }
.seg { display: flex; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 3px; gap: 3px; min-height: 44px; }
.seg button { flex: 1; border: 0; background: transparent; border-radius: 9px; padding: 6px 8px; cursor: pointer; font-size: 15px; color: var(--muted); white-space: nowrap; }
.seg button.on { background: var(--panel); color: var(--ink); font-weight: 700; box-shadow: 0 1px 3px rgba(0, 0, 0, .1); }
.seg.tiny { min-height: 0; padding: 2px; border-radius: 10px; }
.seg.tiny button { font-size: 13px; padding: 4px 8px; }
.seg.tiny button.on[data-val="1"] { background: var(--accent); color: #fff; }
.seg.tiny button.on[data-val="0.5"] { background: var(--warm); color: #fff; }
.check { display: flex; align-items: center; gap: 8px; font-size: 15px; color: var(--muted); margin: 4px 0 12px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.inline { display: flex; align-items: center; gap: 8px; font-size: 15px; margin-top: 6px; }
.inline input { width: 90px; }
.note { font-size: 13px; color: var(--muted); margin: 6px 0; }
.empty-hint { color: var(--muted); text-align: center; padding: 18px; margin: 0; }

.role-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.chip { border: 1px dashed var(--line); background: var(--bg); border-radius: 99px; padding: 8px 14px; cursor: pointer; font-size: 15px; }
.chip:hover { border-style: solid; border-color: var(--warm); background: var(--soft); }
.chip.on { background: var(--accent); border: 1px solid var(--accent); color: #fff; font-weight: 700; box-shadow: 0 4px 12px rgba(200, 85, 61, .25); }
.chip.on:hover { background: var(--accent); filter: brightness(1.05); }

.person { border: 1px solid var(--line); border-radius: 18px; padding: 16px; margin-bottom: 14px; background: var(--bg); animation: rise .3s; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
.person.gone { opacity: .8; }
.p-head, .r-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.p-emoji { font-size: 26px; line-height: 1; }
.p-name { flex: 1; font-family: var(--serif); font-size: 20px !important; font-weight: 700; border-color: transparent !important; background: transparent !important; padding: 4px 8px !important; min-height: 0 !important; }
.p-name:hover, .p-name:focus { border-color: var(--line) !important; background: var(--panel) !important; }
.sub-box { border-top: 1px dashed var(--line); padding-top: 10px; margin-top: 6px; }
.sub-box summary { cursor: pointer; font-weight: 600; padding: 6px 0; list-style-position: inside; }
.sub-box[open] summary { margin-bottom: 8px; }
.fest-quick { margin-bottom: 4px; }
.bday { display: grid; grid-template-columns: 1.6fr 1fr 1fr; gap: 8px; }
.bday:not(:has([data-part=d])) { grid-template-columns: 1.6fr 1fr; }
.fest-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 20px; margin: 12px 0; }
.fest-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 15px; }
.fest-row > span { min-width: 0; flex: 1; line-height: 1.35; }
.fest-row .seg.tiny { flex: none; }
.dates .field { margin-bottom: 4px; }
.calc-bar { text-align: center; padding: 10px 0 40px; }
.calc-bar .note { display: block; color: var(--accent); min-height: 20px; }

/* ---------- 結果 ---------- */
.results { padding-top: 30px; }
.results-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.results-head h2 { font-family: var(--serif); font-size: 28px; margin: 0; }
.result { background: var(--panel); border: 1px solid var(--line); border-radius: 24px; box-shadow: var(--shadow); padding: 26px; margin-bottom: 20px; animation: rise .4s backwards; }
.result:nth-child(2) { animation-delay: .1s; } .result:nth-child(3) { animation-delay: .2s; }
.r-head h3 { font-family: var(--serif); font-size: 24px; margin: 0; }
.big-line { font-family: var(--serif); font-size: clamp(24px, 5vw, 32px); line-height: 1.4; }
.big-line b { color: var(--accent); font-size: 1.6em; padding: 0 4px; }
.sub { color: var(--muted); margin: 6px 0 18px; font-size: 16px; }
.sub b { color: var(--ink); }
.hl { background: var(--bg); border-radius: 18px; padding: 18px; margin-bottom: 16px; }
.hl-text { font-family: var(--serif); font-size: 21px; margin-bottom: 12px; }
.hl-text b { color: var(--accent); font-size: 1.4em; }
.dots { display: flex; flex-wrap: wrap; gap: 7px; }
.dots i, .legend i { width: 14px; height: 14px; border-radius: 50%; background: var(--warm); display: inline-block; animation: pop .4s backwards; }
.dots i.past, .legend i.past { background: var(--past); }
.legend { font-size: 13px; color: var(--muted); margin: 12px 0 0; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.legend i { width: 10px; height: 10px; animation: none; margin-left: 6px; }
.fest-list { list-style: none; padding: 0; margin: 0 0 14px; display: grid; grid-template-columns: 1fr 1fr; gap: 4px 18px; }
.fest-list li { display: grid; grid-template-columns: 28px 1fr auto; align-items: baseline; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.fest-list .fe { font-size: 18px; }
.fest-list b { color: var(--accent); white-space: nowrap; }
.fnext { grid-column: 2 / 4; font-size: 12px; }
.calls { margin: 4px 0 14px; }
.calls b, .used b, .more b { color: var(--accent); }
.used { margin: 12px 0 18px; }
.used p { margin: 8px 0 0; color: var(--muted); font-size: 15px; }
.used-bar { height: 12px; background: var(--warm); border-radius: 99px; overflow: hidden; }
.used-bar i { display: block; height: 100%; background: var(--past); border-radius: 99px 0 0 99px; transition: width .8s; }
.more { background: var(--soft); border-radius: 16px; padding: 14px 16px; margin-bottom: 18px; }
.more input[type=range] { width: 100%; accent-color: var(--accent); margin: 8px 0 2px; }
.more-out { margin: 0; font-size: 16px; }
.r-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.memorial { text-align: center; }
.memorial h3 { font-family: var(--serif); font-size: 26px; margin: 0 0 6px; }
.mem-lead { font-family: var(--serif); font-size: 20px; }
.memorial p { color: var(--muted); max-width: 520px; margin: 8px auto 18px; }
.method { color: var(--muted); font-size: 14px; padding: 10px 4px 30px; }
.method h3 { color: var(--ink); font-size: 16px; }
.method li { margin-bottom: 6px; }

/* ---------- 問題卡 ---------- */
.draw-opts { display: grid; grid-template-columns: 1.2fr 1.6fr .8fr; gap: 0 14px; }
.draw-area { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 16px; margin-top: 18px; }
.draw-area:empty { display: none; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.qcard { perspective: 1000px; min-height: 230px; }
.q-inner { position: relative; height: 100%; min-height: 230px; transition: transform .6s cubic-bezier(.3, 1.3, .5, 1); transform-style: preserve-3d; }
.qcard.flip .q-inner { transform: rotateY(180deg); }
.q-front, .q-back { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; border-radius: 20px; border: 1px solid var(--line); }
.q-front { background: var(--panel); padding: 18px; display: flex; flex-direction: column; box-shadow: var(--shadow); position: relative; min-height: 230px; }
.q-back { transform: rotateY(180deg); background: var(--accent); color: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center; font-family: var(--serif); font-size: 20px; }
.q-back .dot-logo { background: #fff; box-shadow: 18px 0 0 -6px rgba(255, 255, 255, .7), 32px 0 0 -11px rgba(255, 255, 255, .4); }
.qcard:not(.flip) .q-back { pointer-events: none; }
.q-meta { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); }
.depth { padding: 1px 8px; border-radius: 99px; background: var(--chip); }
.depth.d2 { background: var(--soft); }
.depth.d3 { background: var(--accent); color: #fff; }
.q-text { font-family: var(--serif); font-size: 20px; font-weight: 700; line-height: 1.55; margin: 14px 0; flex: 1; }
.q-note { font-size: 14px; color: var(--muted); margin: -4px 0 12px; font-style: italic; }
.c-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.c-actions button { border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 6px 4px; font-size: 13px; cursor: pointer; }
.c-actions button.on { background: var(--soft); border-color: var(--warm); color: var(--accent); font-weight: 700; }
.c-actions button:hover { border-color: var(--warm); }
.c-actions button.wide { grid-column: 1 / -1; }
.tabs { display: flex; gap: 6px; margin-bottom: 12px; flex-wrap: wrap; }
.tabs button, .cat-nav button { border: 1px solid var(--line); background: var(--bg); border-radius: 99px; padding: 7px 14px; cursor: pointer; font-size: 15px; }
.tabs button.on, .cat-nav button.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.tabs button.on small { color: inherit; }
.cat-nav { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 8px; scrollbar-width: none; }
.cat-nav button { white-space: nowrap; font-size: 14px; padding: 5px 12px; }
.cat-group { margin-top: 18px; scroll-margin-top: 20px; }
.cat-group h2 { font-size: 20px; }
.note-q { font-family: var(--serif); font-weight: 700; font-size: 18px; }

/* ---------- 彈窗 ---------- */
.modal { position: fixed; inset: 0; background: rgba(30, 20, 10, .45); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50; animation: fade .2s; }
@keyframes fade { from { opacity: 0; } }
.modal-box { background: var(--panel); border-radius: 22px; padding: 22px; width: 100%; max-width: 460px; max-height: 92vh; overflow: auto; box-shadow: 0 20px 60px rgba(0, 0, 0, .25); }
.modal-box h3 { font-family: var(--serif); margin: 0 0 12px; font-size: 21px; }
.modal-box .row { display: flex; gap: 8px; flex-wrap: wrap; }
#share-img { width: 100%; border-radius: 14px; border: 1px solid var(--line); display: block; margin-bottom: 10px; aspect-ratio: 1; background: var(--bg); }
.share-opts { align-items: center; justify-content: space-between; margin-bottom: 6px; }
.switch { display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--muted); }
.inline-field { flex-direction: row; align-items: center; margin: 0; flex: 1; }
.inline-field input { flex: 1; }
.share-title { margin-top: 10px; }
.share-apps { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; margin: 8px 0 12px; }
.share-apps .app { display: flex; flex-direction: column; align-items: center; gap: 4px; border: 0; background: none; cursor: pointer; font-size: 11px; color: var(--muted); text-decoration: none; padding: 0; }
.share-apps .app i { width: 42px; height: 42px; border-radius: 12px; color: #fff; display: flex; align-items: center; justify-content: center; font: 800 12px var(--sans); font-style: normal; }
.share-row .btn { flex: 1; padding: 9px 10px; font-size: 14px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 200%); visibility: hidden; background: var(--ink); color: var(--bg); padding: 12px 18px; border-radius: 14px; font-size: 15px; z-index: 60; transition: transform .3s, visibility .3s; max-width: calc(100% - 32px); box-shadow: 0 8px 30px rgba(0, 0, 0, .2); }
.toast.show { transform: translate(-50%, 0); visibility: visible; }

.foot { text-align: center; color: var(--muted); font-size: 13px; padding: 30px 20px 40px; }
.foot p { margin: 4px 0; }

/* ---------- 手機 ---------- */
@media (max-width: 640px) {
  .age-row { grid-template-columns: 1fr; }
  .story { padding: 18px 16px 18px 18px; }
  .top { padding-top: 14px; }
  .brand small { display: none; }
  .nav a { padding: 6px 10px; font-size: 14px; }
  .hero { padding: 40px 0 26px; }
  .hero-dots { grid-template-columns: repeat(12, 12px); gap: 8px; }
  .hero-dots i { width: 12px; height: 12px; }
  .hero-dots i:nth-child(n+49) { display: none; }
  .block { padding: 18px 16px; border-radius: 18px; }
  .grid3, .grid2, .draw-opts { grid-template-columns: 1fr; }
  .fest-grid, .fest-list { grid-template-columns: 1fr; }
  .result { padding: 20px 16px; }
  .r-actions .btn { flex: 1 1 100%; }
  .btn.huge { font-size: 26px; padding: 20px 60px; }
  .story { font-size: 16px; padding-left: 14px; }
  .bday { grid-template-columns: 2fr 1fr 1fr; gap: 6px; }
  .bday select { padding: 10px 26px 10px 10px; font-size: 15px; background-position: calc(100% - 14px) 50%, calc(100% - 9px) 50%; }
  .share-apps { grid-template-columns: repeat(3, 1fr); row-gap: 12px; }
}
