:root {
  --paper: #f5ede1;
  --card: #fffcf7;
  --ink: #2c241f;
  --ink2: #5e5249;
  --muted: #9a8e83;
  --line: #e8ddcf;
  --red: #b23a2b;
  --red-d: #8d2b1f;
  --gold: #c39a52;
  --serif: "Noto Serif TC", "Songti TC", "PMingLiU", serif;
  --sans: "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  --shadow: 0 18px 44px rgba(70, 38, 14, .20), 0 3px 10px rgba(70, 38, 14, .08);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: #e9dccb; overflow: hidden; }
body {
  font-family: var(--sans); color: var(--ink);
  background: radial-gradient(120% 90% at 50% 20%, #f3e8d8 0%, #e3d3be 60%, #d5c1a8 100%);
  display: flex; align-items: center; justify-content: center;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
#app {
  position: relative; width: 100vw; height: 100vh; height: 100dvh; overflow: hidden;
  background: linear-gradient(180deg, #8f1f16 0%, #a5281c 29%, #c49563 29.6%, #d2a46e 70%, #c08c58 100%); touch-action: none; user-select: none; -webkit-user-select: none;
}
@media (min-width: 520px) {
  /* 桌機：手機比例的框；視窗矮時框不再跟著變窄（r2 bug 11：1280×600 時框只有 277 寬，輸入卡蓋住標題） */
  #app { width: min(430px, max(calc(100dvh * 0.4621), 360px)); height: min(100dvh, 932px); border-radius: 30px; box-shadow: 0 30px 80px rgba(60, 30, 10, .28); }
}
/* 手機橫放：版面放不下，蓋一層「請轉成直式」（r2 bug 1；r1 把橫放手機當桌機，整個壞掉） */
.rotate { display: none; position: fixed; inset: 0; z-index: 100; align-items: center; justify-content: center; background: radial-gradient(120% 90% at 50% 30%, #f6ecdd, #e1cfb6); }
.rotate-card { display: flex; flex-direction: column; align-items: center; gap: 8px; color: var(--red-d); text-align: center; padding: 20px 28px; background: var(--card); border-radius: 22px; box-shadow: var(--shadow); }
.rotate-card svg { width: 46px; height: 46px; animation: rot 2.4s ease-in-out infinite; }
.rotate-card b { font: 700 18px var(--serif); color: var(--ink); letter-spacing: .08em; }
.rotate-card span { font-size: 13px; color: var(--ink2); letter-spacing: .04em; }
@keyframes rot { 0%, 30% { transform: rotate(-90deg); } 60%, 100% { transform: rotate(0); } }
@media (orientation: landscape) and (max-height: 520px) and (pointer: coarse) { .rotate { display: flex; } }
#stage { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; opacity: 0; transition: opacity .45s ease; }
#app.gl #stage { opacity: 1; }
.vignette {
  position: absolute; inset: 0; pointer-events: none;
  background:
    radial-gradient(120% 75% at 50% 52%, rgba(0,0,0,0) 55%, rgba(58, 28, 8, .30) 100%),
    linear-gradient(180deg, rgba(255, 244, 228, .0) 0%, rgba(255,244,228,0) 70%, rgba(60, 30, 10, .12) 100%);
}
.screen { position: absolute; inset: 0; pointer-events: none; }
.screen[hidden] { display: none; }
.screen > * { pointer-events: auto; }

/* 圓按鈕 */
.round-btn {
  position: absolute; z-index: 20; top: calc(14px + env(safe-area-inset-top)); right: 14px;
  width: 40px; height: 40px; border-radius: 50%; border: 0; padding: 0;
  background: rgba(255, 252, 247, .86); color: var(--ink2);
  box-shadow: 0 4px 14px rgba(70, 38, 14, .16); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  display: grid; place-items: center; cursor: pointer;
}
.round-btn svg { width: 20px; height: 20px; }
.round-btn .off { display: none; }
#app.on-card .round-btn { display: none; }
.round-btn.muted .on { display: none; }
.round-btn.muted .off { display: block; }

/* 印章 */
.seal {
  font-style: normal; font-family: var(--serif); font-weight: 700; color: #fff8ef;
  background: var(--red); border-radius: 6px; display: inline-grid; place-items: center;
  box-shadow: inset 0 0 0 2px rgba(255, 240, 220, .35);
}
.seal.sm { width: 26px; height: 26px; font-size: 15px; border-radius: 50%; flex: none; }

/* ---------- 開始 ---------- */
.hero { position: absolute; left: 0; right: 0; top: 30%; text-align: center; pointer-events: none; }
.eyebrow {
  display: table; margin: 0 auto; font-size: 11px; letter-spacing: .34em; color: #6d3f22; font-weight: 700;
  background: rgba(255, 249, 240, .78); padding: 5px 8px 5px 14px; border-radius: 999px;
}
.logo {
  margin: 8px 0 0; font-family: var(--serif); font-weight: 900; font-size: 74px; line-height: 1.05;
  color: #2a1c14; letter-spacing: .08em; padding-left: .08em; position: relative; display: inline-block;
  text-shadow: 0 1px 0 rgba(255, 246, 232, .6), 0 6px 22px rgba(255, 236, 205, .7);
}
.logo .seal { position: absolute; right: -30px; top: 8px; width: 24px; height: 44px; font-size: 12px; line-height: 1.1; writing-mode: vertical-rl; letter-spacing: .08em; transform: rotate(4deg); border-radius: 4px; text-shadow: none; }
.tagline { margin: 6px 0 0; font-family: var(--serif); font-weight: 700; font-size: 14px; color: #3f2c20; letter-spacing: .14em; text-shadow: 0 0 10px rgba(255, 240, 220, .95), 0 0 3px rgba(255, 240, 220, .9); }

.sheet {
  position: absolute; left: 14px; right: 14px; bottom: calc(14px + env(safe-area-inset-bottom));
  background: var(--card); border-radius: 26px; padding: 18px 18px 12px; box-shadow: var(--shadow);
}
.field-label { display: block; font-family: var(--serif); font-weight: 700; font-size: 18px; color: var(--ink); letter-spacing: .04em; margin: 0 2px 10px; }
.field { position: relative; }
.field input {
  width: 100%; height: 50px; border-radius: 14px; border: 1.5px solid var(--line); background: #f8f2e9;
  padding: 0 58px 0 16px; font: 500 16px var(--sans); color: var(--ink); outline: none; user-select: text; -webkit-user-select: text;
  transition: border-color .2s, background .2s;
}
.field input::placeholder { color: #b5a99c; }
.field input:focus { border-color: #d7a98c; background: #fff; }
.count { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 14px; }
.chip {
  border: 1px solid var(--line); background: #fff; color: var(--ink2); border-radius: 999px;
  padding: 7px 12px; font: 500 13px var(--sans); cursor: pointer; transition: all .15s;
}
.chip:active, .chip.on { background: #fbeee6; border-color: #e3b8a3; color: var(--red-d); }
.btn {
  display: block; width: 100%; height: 52px; border-radius: 999px; border: 0; cursor: pointer;
  font: 700 17px var(--sans); letter-spacing: .14em; transition: transform .12s, filter .12s;
}
.btn:active { transform: scale(.97); }
.btn[hidden] { display: none; }
.btn:disabled { filter: grayscale(.6) opacity(.7); cursor: default; }
.gl-fail { margin: 10px 0 0; padding: 10px 12px; border-radius: 12px; background: #fbeee6; color: var(--red-d); font-size: 13.5px; font-weight: 700; line-height: 1.5; text-align: center; }
.gl-fail[hidden] { display: none; }
.btn.primary { background: linear-gradient(180deg, #bd4433, #a3321f); color: #fff8ef; box-shadow: 0 8px 18px rgba(163, 50, 31, .30), inset 0 1px 0 rgba(255,255,255,.18); }
.btn.outline { background: #fffcf7; color: var(--red-d); box-shadow: inset 0 0 0 1.5px #d9b3a3; }
.btn.ghost { background: rgba(255, 252, 247, .9); color: var(--ink2); box-shadow: 0 4px 12px rgba(70, 38, 14, .14); }
.btn.sm { height: 38px; font-size: 13px; letter-spacing: .08em; width: auto; padding: 0 16px; margin: 12px auto 0; }
.note { margin: 12px 0 0; text-align: center; font-size: 12px; color: var(--muted); letter-spacing: .04em; }

/* ---------- 進行中 ---------- */
/* r2：HUD 縮成一列（問題＋三個聖筊圓點），讓香爐上的香露出來；進度文字移到底部 */
.hud {
  position: absolute; left: 14px; right: 64px; top: calc(14px + env(safe-area-inset-top));
  display: flex; align-items: center; gap: 8px;
  background: rgba(255, 252, 247, .95); border-radius: 999px; box-shadow: var(--shadow); padding: 5px 6px 5px 7px; pointer-events: none;
}
.qrow { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; font-family: var(--serif); font-weight: 700; font-size: 15.5px; color: var(--ink); }
.qrow span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.streak { display: flex; gap: 4px; flex: none; }
.streak b {
  width: 30px; height: 30px; border-radius: 50%; display: block;
  background: #f4ece1; border: 1.5px dashed #d6c6b2; transition: all .35s cubic-bezier(.2, 1.6, .4, 1);
}
.streak b.on { background: #fff6ee var(--sheng-icon) center / 88% no-repeat; border: 1.5px solid var(--red); box-shadow: 0 3px 8px rgba(150, 40, 20, .25); transform: scale(1.08); }
.status { position: absolute; left: 0; right: 0; bottom: calc(16px + env(safe-area-inset-bottom)); text-align: center; pointer-events: none; }
.streak-label { display: inline-block; max-width: calc(100% - 40px); font-size: 13px; color: #fff6ea; letter-spacing: .08em; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; background: rgba(44, 36, 31, .62); border-radius: 999px; padding: 7px 16px; }

.stamp { position: absolute; left: 0; right: 0; top: 25%; display: flex; flex-direction: column; align-items: center; pointer-events: none; }
.stamp[hidden] { display: none; }
.stamp-ring {
  width: 132px; height: 132px; border-radius: 50%; display: grid; place-items: center;
  background: rgba(255, 252, 247, .93); box-shadow: var(--shadow), inset 0 0 0 5px #fffcf7, inset 0 0 0 7px var(--red);
  animation: stampIn .5s cubic-bezier(.2, 1.5, .4, 1) both;
}
.stamp-ring span { font-family: var(--serif); font-weight: 900; font-size: 40px; color: var(--red); letter-spacing: .04em; padding-left: .04em; }
.stamp.gray .stamp-ring { box-shadow: var(--shadow), inset 0 0 0 5px #fffcf7, inset 0 0 0 7px #6d6058; }
.stamp.gray .stamp-ring span { color: #4e433c; }
.stamp-sub {
  margin-top: 12px; background: rgba(44, 36, 31, .82); color: #fff6ea; border-radius: 999px; padding: 7px 16px;
  font-size: 14px; letter-spacing: .1em; font-weight: 700; animation: fadeUp .45s .15s both;
}
@keyframes stampIn { from { transform: scale(1.7) rotate(-8deg); opacity: 0; } to { transform: scale(1) rotate(0); opacity: 1; } }
@keyframes fadeUp { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

.hint { position: absolute; left: 0; right: 0; bottom: calc(62px + env(safe-area-inset-bottom)); text-align: center; pointer-events: none; transition: opacity .3s; }
.hint.hide { opacity: 0; }
.hint .btn { pointer-events: auto; }
.hint.hide .btn { pointer-events: none; visibility: hidden; } /* r2 bug 2：淡出後不能再點到 */
/* 往上滑手勢：手指從下往上推，後面拖一道箭頭 */
.swipe { position: relative; width: 90px; height: 128px; margin: 0 auto 4px; }
.swipe .trail { position: absolute; left: 25px; top: 0; width: 40px; height: 120px; transform-origin: 50% 100%; animation: trail 1.8s ease-out infinite; filter: drop-shadow(0 1px 3px rgba(60, 30, 10, .35)); }
.swipe .hand { position: absolute; left: 22px; top: 52px; width: 58px; height: 72px; animation: hand 1.8s ease-out infinite; filter: drop-shadow(0 4px 8px rgba(60, 30, 10, .35)); }
.swipe .tap { animation: tap 1.8s ease-out infinite; transform-origin: 30px 10px; }
@keyframes hand { 0%, 10% { transform: translateY(26px); opacity: .85; } 60% { transform: translateY(-42px); opacity: 1; } 78% { transform: translateY(-48px); opacity: .35; } 100% { transform: translateY(26px); opacity: .85; } }
@keyframes trail { 0%, 10% { transform: scaleY(.25); opacity: .5; } 60% { transform: scaleY(1); opacity: 1; } 85%, 100% { transform: scaleY(1); opacity: .3; } }
@keyframes tap { 0%, 8% { transform: scale(.4); opacity: 0; } 14% { opacity: .9; } 30%, 100% { transform: scale(1.6); opacity: 0; } }
.hint-text {
  display: inline-block; background: rgba(255, 252, 247, .92); color: var(--ink2); border-radius: 999px; padding: 9px 18px;
  font-size: 14px; font-weight: 700; letter-spacing: .08em; box-shadow: 0 6px 16px rgba(70, 38, 14, .16);
}
.chev { height: 40px; position: relative; margin-bottom: 6px; }
.chev i { position: absolute; left: 50%; width: 16px; height: 16px; margin-left: -8px; border-left: 3px solid rgba(255, 250, 240, .95); border-top: 3px solid rgba(255, 250, 240, .95); transform: rotate(45deg); border-radius: 2px; animation: chev 1.4s infinite; filter: drop-shadow(0 1px 3px rgba(60, 30, 10, .35)); }
.chev i:nth-child(1) { top: 24px; animation-delay: 0s; }
.chev i:nth-child(2) { top: 13px; animation-delay: .18s; }
.chev i:nth-child(3) { top: 2px; animation-delay: .36s; }
@keyframes chev { 0%, 100% { opacity: .15; } 40% { opacity: 1; } }

/* ---------- 結算 ---------- */
#scr-card { background: rgba(70, 40, 18, .28); backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px); animation: fadeIn .35s both; overflow-y: auto; pointer-events: auto; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.card-wrap { min-height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: calc(18px + env(safe-area-inset-top)) 22px calc(16px + env(safe-area-inset-bottom)); }
/* r2 bug 12：卡圖依視窗高度縮，375×667 也能讓按鈕留在第一屏 */
#card-img { width: auto; max-width: min(100%, 346px); max-height: calc(100dvh - 200px); border-radius: 24px; box-shadow: 0 22px 50px rgba(40, 20, 6, .35); display: block; animation: cardIn .5s cubic-bezier(.2, 1.3, .4, 1) both; }
@keyframes cardIn { from { transform: translateY(26px) scale(.96); opacity: 0; } to { transform: none; opacity: 1; } }
.card-actions { width: 100%; max-width: 346px; margin-top: 16px; animation: fadeUp .4s .2s both; }
.card-actions .row { display: flex; gap: 10px; margin-top: 10px; }
.card-actions .row .btn { height: 46px; font-size: 15px; }
.link { display: block; margin: 10px auto 0; background: none; border: 0; color: #fff4e6; font: 700 13px var(--sans); letter-spacing: .1em; text-decoration: underline; text-underline-offset: 4px; cursor: pointer; padding: 6px 10px; text-shadow: 0 1px 6px rgba(40, 20, 6, .5); }

.toast { position: absolute; left: 50%; top: 46%; transform: translateX(-50%); z-index: 30; background: rgba(44, 36, 31, .9); color: #fff6ea; padding: 9px 16px; border-radius: 999px; font-size: 13px; letter-spacing: .06em; pointer-events: none; }
.toast[hidden] { display: none; }

/* r2 bug 11：矮視窗（桌機 1280×600、iPhone SE）標題往上收、字縮小，輸入卡不蓋住標題 */
@media (max-height: 760px) {
  .hero { top: 27%; }
  .logo { font-size: 58px; }
  .sheet { padding: 14px 16px 10px; }
  .field-label { font-size: 17px; margin-bottom: 8px; }
  .chips { margin: 10px 0 12px; gap: 6px; flex-wrap: nowrap; }
  .chip { font-size: 12.5px; padding: 6px 10px; white-space: nowrap; }
  .chip:nth-child(n+3) { display: none; } /* 題目變長後矮螢幕只留兩顆，免得輸入卡蓋住標題 */
  .note { margin-top: 8px; }
  .card-actions { margin-top: 12px; }
  .card-actions .btn.primary { height: 48px; }
  .card-actions .row { margin-top: 8px; }
  .card-actions .row .btn { height: 42px; }
  .link { margin-top: 4px; }
  .swipe { height: 104px; }
  .swipe .trail { height: 96px; }
  .swipe .hand { top: 36px; }
}
@media (max-height: 640px) {
  .logo { font-size: 48px; }
  .note { display: none; }
}
