:root {
  color-scheme: light;
  --bg: #f5ede3; --card: #fffaf4; --ink: #4a2c1f; --sub: #8b6a55; --line: #eadccb;
  --pink: #ff7d93; --gold: #ffb627; --green: #7cc35a;
  --ease: cubic-bezier(.22, 1, .36, 1); --spring: cubic-bezier(.34, 1.56, .64, 1);
  --pad: clamp(10px, 2vw, 28px);
}
* { box-sizing: border-box; margin: 0; }
html, body { min-height: 100%; }
body {
  background: radial-gradient(120% 90% at 15% 0%, #fff8f1 0%, var(--bg) 62%);
  color: var(--ink); font: 15px/1.6 "PingFang TC", "Noto Sans TC", system-ui, sans-serif;
  min-height: 100dvh; padding: var(--pad);
  display: grid; grid-template-columns: auto minmax(220px, 300px); gap: clamp(16px, 3vw, 44px);
  place-content: center; align-items: center;
}
.stage {
  height: calc(100dvh - 2 * var(--pad)); max-height: 1180px; aspect-ratio: 9 / 16; position: relative; overflow: hidden; overflow: clip;
  border-radius: clamp(14px, 2vw, 28px); background: #fff5ee; touch-action: manipulation; user-select: none; -webkit-user-select: none;
  box-shadow: 0 44px 90px -44px rgba(90, 55, 25, .55), 0 0 0 1px rgba(90, 55, 25, .08);
}
canvas { display: block; width: 100%; height: 100%; }
/* UI 用 1080×1920 設計尺寸排版，再整塊縮放 */
#ui { position: absolute; left: 0; top: 0; width: 1080px; height: 1920px; transform-origin: 0 0; pointer-events: none; font-size: 40px; line-height: 1.35; }
#ui > * { pointer-events: auto; }
button { font: inherit; color: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.b {
  appearance: none; border: 4px solid var(--ink); background: #fffaf2; border-radius: 34px; padding: 14px 28px; font-weight: 700;
  box-shadow: 0 8px 0 var(--ink); transition: transform .18s var(--spring), box-shadow .18s var(--ease), background .25s var(--ease), opacity .25s;
  display: inline-flex; align-items: center; justify-content: center; gap: 12px; white-space: nowrap;
}
.b:active { transform: translateY(6px); box-shadow: 0 2px 0 var(--ink); }
.b[disabled] { opacity: .45; pointer-events: none; }
.b.gold { background: linear-gradient(#ffe680, #ffb020); }
.b.pink { background: var(--pink); color: #fff; }
.b.dark { background: var(--ink); color: #ffe7a8; }
.b small { font-size: .7em; font-weight: 600; opacity: .85; }
.snd { position: absolute; right: 30px; top: 36px; width: 104px; height: 104px; padding: 0; border-radius: 50%; font-size: 46px; box-shadow: 0 6px 0 var(--ink); }
.snd.off { opacity: .55; }
#bar { position: absolute; left: 30px; right: 30px; bottom: 34px; display: flex; gap: 20px; align-items: center; transition: transform .45s var(--ease), opacity .3s; }
#bar .b { height: 116px; }
#bar .grow { flex: 1; }
#bar.hide { transform: translateY(260px); opacity: 0; pointer-events: none; }
.king { position: relative; overflow: hidden; }
.king i { position: absolute; left: 0; bottom: 0; top: 0; background: rgba(255, 200, 40, .45); width: 0; transition: width .3s var(--ease); }
.king span { position: relative; }
.king.ready { animation: pulse 0.9s var(--ease) infinite alternate; background: linear-gradient(#ffe680, #ffb020); }
@keyframes pulse { to { transform: scale(1.06); } }
#sheet {
  position: absolute; left: 20px; right: 20px; bottom: 20px; background: #fffaf2; border: 5px solid var(--ink); border-radius: 44px; padding: 30px 34px 34px;
  box-shadow: 0 -10px 40px -20px rgba(90, 55, 25, .5); transform: translateY(calc(100% + 80px)); visibility: hidden; transition: transform .45s var(--ease), visibility 0s .45s;
}
#sheet.show { transform: none; visibility: visible; transition: transform .45s var(--ease); }
[hidden] { display: none !important; }
#sheet h3 { font-size: 48px; display: flex; align-items: baseline; gap: 18px; }
#sheet h3 small { font-size: 32px; color: var(--sub); font-weight: 600; }
#sheet .x { position: absolute; right: 22px; top: 18px; border: 0; background: none; font-size: 56px; line-height: 1; padding: 10px 18px; color: var(--sub); }
.stats { display: flex; gap: 30px; color: var(--sub); font-size: 34px; margin: 6px 0 20px; flex-wrap: wrap; }
.stats b { color: var(--ink); }
.row { display: flex; gap: 20px; }
.row .b { flex: 1; height: 120px; }
.builds { display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px; margin-top: 16px; }
.bt {
  appearance: none; border: 4px solid var(--line); background: #fff; border-radius: 28px; padding: 10px 4px 14px; display: grid; justify-items: center; gap: 2px;
  transition: transform .18s var(--spring), border-color .2s;
}
.bt:active { transform: scale(.94); }
.bt canvas { width: 130px; height: 130px; }
.bt b { font-size: 30px; }
.bt span { font-size: 28px; color: var(--sub); font-weight: 700; }
.bt.no { opacity: .4; }
.bt.lock { opacity: .3; filter: grayscale(1); }
.bt .sugar::before, .cost::before { content: "🍬"; font-size: .9em; margin-right: 4px; }
#modal { position: absolute; inset: 0; display: none; place-items: center; background: rgba(60, 35, 20, .42); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
#modal.show { display: grid; animation: fade .35s var(--ease); }
@keyframes fade { from { opacity: 0; } }
.card-box { width: 960px; max-height: 1760px; overflow: auto; background: #fffaf2; border: 6px solid var(--ink); border-radius: 56px; padding: 50px 44px; text-align: center; animation: pop .5s var(--spring); }
@keyframes pop { from { transform: scale(.82); opacity: 0; } }
.card-box h2 { font-size: 72px; line-height: 1.15; }
.card-box p.sub { color: var(--sub); font-size: 36px; margin-top: 8px; }
.cards { display: grid; gap: 22px; margin: 36px 0 10px; }
.cd {
  appearance: none; text-align: left; border: 5px solid var(--ink); background: #fff; border-radius: 36px; padding: 28px 34px; display: grid; grid-template-columns: 110px 1fr; gap: 6px 26px; align-items: center;
  box-shadow: 0 8px 0 var(--ink); transition: transform .2s var(--spring), box-shadow .2s;
}
.cd:active { transform: translateY(6px); box-shadow: 0 2px 0 var(--ink); }
.cd .ic { grid-row: span 2; width: 110px; height: 110px; border-radius: 30px; display: grid; place-items: center; font-size: 64px; background: #fff1dc; }
.cd b { font-size: 46px; }
.cd span { font-size: 34px; color: var(--sub); }
.big { font: 700 120px/1.05 "Arial Rounded MT Bold", "Arial Black", sans-serif; color: #ffb627; -webkit-text-stroke: 5px var(--ink); paint-order: stroke fill; margin: 20px 0; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 10px 30px; text-align: left; font-size: 40px; margin: 26px 40px 40px; }
.kv dt { color: var(--sub); }
.kv dd { font-weight: 700; text-align: right; }
.tree-box { padding: 38px 44px 44px; }
.th { display: flex; align-items: center; justify-content: space-between; }
.th h2 { font-size: 64px; }
.tree { position: relative; width: 872px; height: 1000px; margin: 6px 0 20px; }
.tree svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.ln { fill: none; stroke-linecap: round; }
.ln.ink { stroke: var(--ink); stroke-width: 21; }
.ln.own { stroke-width: 11; }
.ln.open { stroke: #ccb59c; stroke-width: 9; stroke-dasharray: 0 22; }
.ln.hint { stroke: #e3d4c2; stroke-width: 8; stroke-dasharray: 0 22; }
.ln.seed { stroke: #ecdfcf; stroke-width: 6; stroke-dasharray: 0 18; }
.seed { position: absolute; width: 28px; height: 28px; border-radius: 50%; background: #eee2d3; }
.ln.grow { stroke-dasharray: 1; animation: grow .9s var(--ease) both; }
@keyframes grow { from { stroke-dashoffset: 1; } }
.troot { position: absolute; left: 356px; top: 12px; width: 160px; height: 160px; border-radius: 50%; border: 6px solid var(--ink); background: radial-gradient(#fff 55%, #ffe9c7); display: grid; place-items: center; overflow: hidden; }
.troot img { width: 150px; height: 150px; margin-top: 14px; }
.bp { position: absolute; top: 188px; transform: translateX(-50%); background: var(--c); color: #fff; border: 4px solid var(--ink); border-radius: 30px; padding: 0 20px; font-size: 28px; font-weight: 800; white-space: nowrap; }
.bp small { font-size: 22px; opacity: .9; }
.tn { position: absolute; width: 116px; height: 116px; padding: 0; appearance: none; border-radius: 50%; border: 5px dashed #ccb59c; background: #fffaf2; display: grid; place-items: center; transition: transform .3s var(--spring); }
.tn .f { width: 90px; height: 90px; border-radius: 50%; background: #fff; display: grid; place-items: center; font-size: 52px; line-height: 1; overflow: hidden; }
.tn img { width: 104px; height: 104px; margin-top: 10px; }
.tn b { position: absolute; top: calc(100% + 10px); left: 50%; transform: translateX(-50%); font-size: 27px; white-space: nowrap; background: #fffaf2; padding: 0 8px; border-radius: 14px; line-height: 1.3; }
.tn i { position: absolute; top: -10px; right: -16px; font-style: normal; font: 800 24px/1.5 "Arial Rounded MT Bold", sans-serif; background: var(--ink); color: #fff; border-radius: 20px; padding: 0 11px; }
.tn.own { border: 5px solid var(--ink); background: conic-gradient(var(--c) calc(var(--p) * 360deg), #eadccb 0); }
.tn.max .f { background: color-mix(in srgb, var(--c) 24%, #fff); }
.tn.max i { background: var(--c); }
.tn.hint { background: #efe4d6; border-color: #dccab6; }
.tn.hint .f { background: none; color: #c3ad94; font: 800 58px/1 "Arial Rounded MT Bold", sans-serif; }
.tn.hint b { color: #c3ad94; }
.tn.ok { animation: glow 1.5s ease-in-out infinite; border-color: var(--gold); border-style: solid; }
.tn.own.ok { border-color: var(--ink); }
@keyframes glow { 50% { box-shadow: 0 0 0 14px rgba(255, 182, 39, .38); } }
.tn.sel { transform: scale(1.1); outline: 5px solid var(--ink); outline-offset: 7px; z-index: 2; }
.tn.pop .f { animation: pop2 .6s var(--spring); }
@keyframes pop2 { 0% { transform: scale(.4); } }
.tdet { display: grid; grid-template-columns: 130px 1fr; gap: 14px 26px; align-items: center; text-align: left; background: #fff; border: 5px solid var(--c, var(--line)); border-radius: 40px; padding: 22px 28px; min-height: 230px; transition: border-color .3s var(--ease); }
.tdet > .f { grid-row: span 2; width: 130px; height: 130px; border-radius: 50%; background: color-mix(in srgb, var(--c) 18%, #fff); display: grid; place-items: center; font-size: 72px; overflow: hidden; }
.tdet > .f img { width: 124px; height: 124px; margin-top: 14px; }
.tdet h4 { font-size: 44px; line-height: 1.2; }
.tdet h4 small { font-size: 30px; color: var(--sub); }
.tdet p { font-size: 32px; color: var(--sub); line-height: 1.35; }
.tdet p b { color: var(--ink); }
.tdet .b { grid-column: 2; height: 108px; font-size: 38px; }
.stars { font-size: 46px; font-weight: 700; }
.stars::before { content: "⭐"; margin-right: 8px; }
.side { display: flex; flex-direction: column; gap: 18px; }
.side h1 { font-size: 30px; line-height: 1.15; }
.side .eyebrow { font-size: 12px; letter-spacing: .2em; color: var(--sub); }
.side p, .side li { font-size: 14px; color: var(--sub); }
.side ul { padding-left: 18px; display: grid; gap: 4px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; background: #eee1d1; border-radius: 14px; padding: 4px; }
.seg button { appearance: none; border: 0; border-radius: 10px; padding: 8px; background: transparent; color: var(--sub); font-weight: 600; transition: background .3s var(--ease); }
.seg button[aria-checked="true"] { background: var(--card); color: var(--ink); box-shadow: 0 6px 16px -8px rgba(90, 55, 25, .45); }
.link { appearance: none; border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 9px 12px; font-weight: 600; }
@media (max-width: 760px) {
  body { display: grid; place-items: center; padding: 0; grid-template-columns: 1fr; }
  .stage { width: min(100vw, 100dvh * 9 / 16); height: auto; max-height: none; margin: 0 auto; border-radius: 0; }
  .side { display: none; }
}
@media (orientation: landscape) and (max-height: 560px) { body { display: block; padding: 0; } .stage { height: 100dvh; width: auto; margin: 0 auto; border-radius: 0; } .side { display: none; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
body.bot .side { display: none; }
.kv dd small.who { display: block; font-size: .62em; font-weight: 600; color: var(--sub); }   /* 塔最高一擊：哪座塔打的 */
