:root {
  --ink: #123746;
  --teal: #0e718f;
  --teal-dark: #09546c;
  --sky: #68c8e8;
  --ice: #edf9fc;
  --red: #d84343;
  --red-dark: #9d282f;
  --gold: #d8a54b;
  --paper: #fff;
  --line: #9fcbd9;
  --muted: #617987;
  --shadow: 0 18px 50px rgba(18, 55, 70, .1);
  --serif: 'Noto Serif TC', 'PMingLiU', serif;
  --sans: 'Noto Sans TC', 'Microsoft JhengHei', sans-serif;
}

* { box-sizing: border-box; }
html { color-scheme: light; }
body { margin: 0; min-width: 320px; color: var(--ink); background: radial-gradient(circle at 11% 6%, rgba(104,200,232,.2), transparent 24rem), linear-gradient(145deg, #fff 0%, #f5fbfd 56%, #e6f5f9 100%); font-family: var(--sans); min-height: 100vh; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }
.ambient-mark { position: fixed; z-index: -1; right: 2vw; bottom: -4vh; color: rgba(14,113,143,.045); font: 900 clamp(7rem, 17vw, 15rem)/.82 var(--serif); letter-spacing: -.11em; writing-mode: vertical-rl; user-select: none; }
.app-shell { width: min(1120px, calc(100% - 40px)); margin: 0 auto; padding: 42px 0 24px; }
.masthead { display: flex; align-items: flex-end; justify-content: space-between; padding: 0 10px 28px; }
.eyebrow, .section-kicker { margin: 0 0 6px; color: var(--teal); font: 700 .68rem/1 var(--sans); letter-spacing: .22em; }
h1 { margin: 0; font: 900 clamp(2.7rem, 6vw, 5.6rem)/.92 var(--serif); letter-spacing: -.08em; }
h1 span { color: var(--red); }
.intro { margin: 13px 0 0; color: var(--muted); font-size: .95rem; letter-spacing: .08em; }
.seal { width: 80px; aspect-ratio: 1; display: grid; grid-template-columns: 1fr 1fr; border: 3px solid var(--red); padding: 7px; color: var(--red); font: 900 1.18rem/1 var(--serif); transform: rotate(3deg); }
.seal span { display: grid; place-items: center; border: 1px solid currentColor; }
.tool-tabs { display: grid; grid-template-columns: repeat(4, 1fr); border: 1px solid var(--ink); box-shadow: 7px 7px 0 rgba(14,113,143,.16); background: var(--sky); }
.tool-tab { border: 0; border-right: 1px solid var(--ink); background: transparent; min-height: 66px; display: flex; gap: 10px; align-items: center; justify-content: center; color: var(--ink); transition: color .2s ease, background .2s ease; }
.tool-tab:last-child { border-right: 0; }
.tool-tab:hover { background: rgba(255,255,255,.38); }
.tool-tab.is-active { color: #fff; background: var(--teal-dark); }
.tab-index { font: 700 .72rem/1 var(--serif); opacity: .65; }
.tool-panel { background: rgba(255,255,255,.82); border: 1px solid var(--ink); border-top: 0; padding: clamp(24px, 4vw, 48px); min-height: 600px; animation: panel-in .35s ease both; backdrop-filter: blur(12px); }
.tool-heading { display: flex; justify-content: space-between; gap: 40px; align-items: flex-end; margin-bottom: 30px; padding-bottom: 18px; border-bottom: 1px solid var(--line); }
.tool-heading h2 { margin: 0; font: 900 clamp(1.7rem, 3vw, 2.5rem)/1.1 var(--serif); letter-spacing: -.05em; }
.tool-heading > p { max-width: 340px; margin: 0; color: var(--muted); line-height: 1.75; font-size: .9rem; }
.tool-layout { display: grid; grid-template-columns: minmax(280px,.72fr) minmax(420px,1.28fr); gap: 25px; align-items: stretch; }
.controls-card, .stage-card { position: relative; border: 1px solid var(--line); background: rgba(255,255,255,.78); padding: 24px; }
.controls-card { display: flex; flex-direction: column; gap: 23px; }
.stage-card { min-height: 470px; overflow: hidden; background: linear-gradient(155deg, rgba(237,249,252,.82), #fff 58%); }
.stage-label { position: absolute; top: 13px; right: 15px; color: var(--teal); font-size: .58rem; letter-spacing: .2em; opacity: .65; }
.field-group { display: grid; gap: 8px; }
.field-heading { display: flex; justify-content: space-between; align-items: center; }
.field-group label, fieldset legend { font-weight: 700; font-size: .88rem; }
.field-count { color: var(--teal); font-size: .75rem; }
textarea, input[type='number'] { width: 100%; border: 1px solid #8fb7c4; background: #fbfeff; border-radius: 0; padding: 12px 13px; transition: border .2s, box-shadow .2s; }
textarea { resize: vertical; line-height: 1.62; min-height: 210px; }
textarea:focus, input[type='number']:focus { border-color: var(--teal); box-shadow: inset 4px 0 0 var(--sky); outline: 0; }
.field-hint { margin: 0; color: var(--muted); font-size: .75rem; }
.field-error { min-height: 1.15em; margin: 0; color: var(--red-dark); font-weight: 600; font-size: .77rem; }
.check-row { display: flex; gap: 12px; align-items: flex-start; cursor: pointer; }
.check-row input { position: absolute; opacity: 0; }
.check-control { width: 22px; height: 22px; flex: 0 0 auto; border: 1px solid var(--teal); display: grid; place-items: center; }
.check-row input:checked + .check-control { background: var(--teal); box-shadow: inset 0 0 0 4px #fff; }
.check-row strong, .check-row small { display: block; }
.check-row strong { font-size: .84rem; }
.check-row small { margin-top: 3px; color: var(--muted); font-size: .7rem; }
.primary-action { margin-top: auto; min-height: 54px; padding: 0 16px 0 20px; display: flex; justify-content: space-between; align-items: center; border: 0; color: #fff; background: var(--red); box-shadow: 5px 5px 0 var(--red-dark); font-weight: 800; letter-spacing: .06em; transition: transform .18s, box-shadow .18s, filter .18s; }
.primary-action:hover { transform: translate(2px,2px); box-shadow: 3px 3px 0 var(--red-dark); filter: saturate(1.12); }
.primary-action:active { transform: translate(5px,5px); box-shadow: none; }
.primary-action:disabled { cursor: wait; filter: grayscale(.35); opacity: .55; transform: none; box-shadow: 3px 3px 0 #8b7474; }
.primary-action i { width: 28px; aspect-ratio: 1; display: grid; place-items: center; border: 1px solid rgba(255,255,255,.55); border-radius: 50%; font-style: normal; }
.wheel-stage { display: grid; place-items: center; padding-bottom: 86px; }
.wheel-wrap { width: min(76%, 370px); aspect-ratio: 1; position: relative; display: grid; place-items: center; }
#wheel-canvas { width: 100%; height: 100%; border-radius: 50%; filter: drop-shadow(10px 13px 0 rgba(14,113,143,.15)); }
.wheel-pointer { position: absolute; z-index: 3; top: -7px; left: 50%; width: 30px; height: 44px; background: var(--red); clip-path: polygon(0 0,100% 0,50% 100%); transform: translateX(-50%); filter: drop-shadow(0 3px 0 var(--red-dark)); }
.wheel-hub { position: absolute; width: 15%; aspect-ratio: 1; border-radius: 50%; display: grid; place-items: center; background: var(--paper); border: 5px solid var(--teal-dark); box-shadow: 0 4px 12px rgba(18,55,70,.22); font: 900 clamp(.75rem,2vw,1.2rem)/1 var(--serif); color: var(--red); }
.result-slip { position: absolute; left: 22px; right: 22px; bottom: 20px; min-height: 56px; display: flex; align-items: center; gap: 18px; padding: 11px 20px; border-left: 5px solid var(--red); background: #fff; box-shadow: var(--shadow); }
.result-slip.is-revealed { animation: result-reveal .65s cubic-bezier(.22,.9,.3,1.2); }
.result-label { color: var(--red); font-size: .68rem; font-weight: 800; letter-spacing: .18em; }
.result-slip strong { font: 800 1.25rem/1.2 var(--serif); }
.range-grid { display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; align-items: end; }
.range-divider { padding-bottom: 13px; color: var(--line); }
.radio-field, .dice-count-field { border: 0; padding: 0; margin: 0; display: grid; gap: 10px; }
.segmented-radio { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--teal); }
.segmented-radio label input, .dice-count-options input { position: absolute; opacity: 0; }
.segmented-radio span { display: grid; place-items: center; min-height: 43px; font-size: .8rem; cursor: pointer; }
.segmented-radio label:first-child span { border-right: 1px solid var(--teal); }
.segmented-radio input:checked + span { color: #fff; background: var(--teal); font-weight: 700; }
.numbers-stage { display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 26px; }
.number-grid { width: 100%; display: grid; grid-template-columns: repeat(auto-fit, minmax(66px,1fr)); gap: 12px; align-content: center; }
.number-tile, .number-placeholder { min-height: 78px; display: grid; place-items: center; border: 1px solid var(--teal); background: #fff; box-shadow: 4px 4px 0 rgba(104,200,232,.55); font: 900 clamp(1.45rem,4vw,2.5rem)/1 var(--serif); color: var(--teal-dark); }
.number-tile.is-revealed { color: #fff; background: var(--red); border-color: var(--red-dark); box-shadow: 4px 4px 0 var(--red-dark); animation: tile-flip .45s ease both; }
.result-summary { margin: 0; color: var(--muted); text-align: center; font-size: .82rem; }
.jiaobei-guide h3 { margin: 0; font: 800 1.15rem/1 var(--serif); }
.jiaobei-guide dl { margin: 0; display: grid; gap: 8px; }
.jiaobei-guide dl > div { border-bottom: 1px solid #d8e8ed; padding: 11px 0; }
.jiaobei-guide dt { display: flex; align-items: center; gap: 10px; color: var(--red-dark); font: 800 1rem/1 var(--serif); }
.jiaobei-guide dd { margin: 4px 0 0 38px; color: var(--muted); font-size: .74rem; }
.mini-jiaobei { display: inline-block; width: 28px; height: 14px; border-radius: 100% 12% 12% 100%; background: var(--red); box-shadow: inset -5px 0 0 rgba(120,15,25,.3); }
.mini-jiaobei.flat { box-shadow: inset 0 0 0 2px #f79ca0; }
.mini-jiaobei.round { box-shadow: inset -7px 0 6px #8d1822; }
.jiaobei-stage { display: flex; flex-direction: column; align-items: center; justify-content: flex-start; padding-top: 62px; }
.jiaobei-pair { display: flex; gap: 50px; min-height: 120px; align-items: center; }
.jiaobei-piece { width: 72px; height: 142px; border-radius: 100% 18% 18% 100%; background: linear-gradient(90deg,#991c2a,#ed4d54 42%,#bd2832); box-shadow: inset -12px 0 18px rgba(80,0,10,.32), 8px 12px 20px rgba(100,20,25,.2); transform: rotate(-18deg); transform-style: preserve-3d; }
.jiaobei-piece:nth-child(2) { transform: scaleX(-1) rotate(-18deg); }
.jiaobei-piece.is-flat { background: linear-gradient(90deg,#b82b35,#f35d63 52%,#c62e38); box-shadow: inset 0 0 0 4px #ff9b9f, 8px 12px 20px rgba(100,20,25,.18); }
.jiaobei-piece.is-throwing { animation: jiaobei-throw 1.5s cubic-bezier(.3,.7,.3,1) both; }
.jiaobei-piece:nth-child(2).is-throwing { animation-name: jiaobei-throw-right; }
.oracle-result { margin-top: 18px; text-align: center; min-height: 66px; }
.oracle-result strong, .oracle-result span { display: block; }
.oracle-result strong { color: var(--red); font: 900 1.65rem/1.2 var(--serif); }
.oracle-result span { margin-top: 7px; color: var(--muted); font-size: .76rem; }
.history-block { width: 100%; margin-top: 26px; padding-top: 15px; border-top: 1px solid var(--line); }
.history-heading { display: flex; justify-content: space-between; align-items: center; }
.history-heading h3 { margin: 0; font-size: .78rem; }
.history-heading span { color: var(--teal); font-size: .68rem; }
.history-list { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 0; padding: 0; list-style: none; }
.history-list li:not(.empty-history) { padding: 5px 9px; border: 1px solid var(--line); background: #fff; font-size: .68rem; }
.empty-history { color: var(--muted); font-size: .7rem; }
.dice-count-options { display: grid; grid-template-columns: repeat(3,1fr); gap: 8px; }
.dice-count-options span { min-height: 46px; display: grid; place-items: center; border: 1px solid var(--line); cursor: pointer; font-weight: 700; }
.dice-count-options input:checked + span { color: #fff; background: var(--teal); border-color: var(--teal); }
.dice-note { display: flex; gap: 12px; align-items: center; padding: 14px; background: var(--ice); border-left: 3px solid var(--gold); }
.dice-note span { color: var(--red); font: 900 1rem/1 var(--serif); white-space: nowrap; }
.dice-note p { margin: 0; color: var(--muted); font-size: .7rem; line-height: 1.55; }
.dice-stage { padding-bottom: 95px; }
.dice-table { height: 330px; display: grid; place-items: end center; position: relative; perspective: 700px; }
.dice-table:after { content: ''; position: absolute; width: 82%; height: 24%; bottom: 23px; border-radius: 50%; background: radial-gradient(ellipse,rgba(10,84,108,.18),transparent 68%); }
.dice-cup { position: absolute; z-index: 3; left: 50%; bottom: 58px; width: 245px; height: 245px; opacity: 0; transform: translate(-50%,-110%); border-radius: 50% 50% 12% 12% / 38% 38% 10% 10%; background: linear-gradient(100deg,#063949 0%,#1285a8 34%,#075269 70%,#032f3e 100%); box-shadow: inset 22px 0 24px rgba(255,255,255,.08), inset -24px 0 28px rgba(0,0,0,.35), 0 22px 30px rgba(5,50,65,.28); transition: transform .65s cubic-bezier(.2,.8,.2,1), opacity .2s ease; }
.dice-cup:before { content: ''; position: absolute; top: -22px; left: 50%; width: 86px; height: 48px; transform: translateX(-50%); border-radius: 50% 50% 15% 15%; background: linear-gradient(90deg,#052e3a,#0d718e,#032833); }
.dice-cup.is-covering { opacity: 1; transform: translate(-50%,0); }
.dice-cup.is-shaking { animation: cup-shake .16s linear infinite; }
.cup-shine { position: absolute; inset: 12px auto 30px 24px; width: 28%; border-radius: 50%; background: linear-gradient(90deg,rgba(255,255,255,.15),transparent); transform: rotate(7deg); }
.cup-rim { position: absolute; left: -8px; right: -8px; bottom: -8px; height: 28px; border-radius: 50%; background: linear-gradient(#062f3d,#021c25); box-shadow: inset 0 5px 3px rgba(255,255,255,.08); }
.dice-row { z-index: 2; width: 100%; min-height: 104px; display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 13px; padding-bottom: 36px; }
.die { width: 72px; aspect-ratio: 1; display: grid; grid-template-columns: repeat(3,1fr); grid-template-rows: repeat(3,1fr); gap: 4px; padding: 10px; border-radius: 15px; border: 1px solid #c9d6d9; background: linear-gradient(145deg,#fff,#e5ecee); box-shadow: 7px 9px 0 rgba(18,55,70,.15), inset -5px -5px 9px rgba(18,55,70,.08); }
.die-dot { border-radius: 50%; background: transparent; }
.die-dot.is-on { background: var(--ink); box-shadow: inset 1px 1px 2px #000; }
.die.is-settled { animation: die-land .4s ease both; }
.dice-result { position: absolute; left: 22px; right: 22px; bottom: 20px; display: flex; align-items: baseline; justify-content: center; gap: 12px; padding: 10px; border-top: 1px solid var(--line); }
.sum-label { color: var(--muted); font-size: .68rem; }
.dice-result strong { color: var(--red); font: 900 2rem/1 var(--serif); }
.dice-result em { padding: 4px 8px; color: #fff; background: var(--red); font: 800 .65rem/1 var(--serif); font-style: normal; transform: rotate(-3deg); }
footer { display: flex; justify-content: space-between; align-items: center; padding: 28px 10px 0; color: var(--muted); font-size: .68rem; }
footer span { color: var(--teal); font: 800 .9rem/1 var(--serif); }
footer p { margin: 0; }
@keyframes panel-in { from { opacity: 0; transform: translateY(9px); } }
@keyframes result-reveal { from { opacity: 0; transform: translateX(-18px) rotate(-1deg); } }
@keyframes tile-flip { 0% { opacity: .25; transform: rotateX(80deg) scale(.9); } 100% { opacity: 1; transform: none; } }
@keyframes jiaobei-throw { 0% { transform: rotate(-18deg) translateY(0); } 45% { transform: rotate(620deg) translateY(-115px) scale(.78); } 100% { transform: rotate(342deg) translateY(0); } }
@keyframes jiaobei-throw-right { 0% { transform: scaleX(-1) rotate(-18deg); } 45% { transform: scaleX(-1) rotate(-580deg) translateY(-125px) scale(.78); } 100% { transform: scaleX(-1) rotate(-378deg); } }
@keyframes cup-shake { 0%,100% { transform: translate(-50%,0) rotate(-2deg); } 50% { transform: translate(-46%,-5px) rotate(2deg); } }
@keyframes die-land { from { opacity: .5; transform: translateY(-16px) rotate(14deg); } to { opacity: 1; transform: none; } }
@media (max-width: 760px) {
  .app-shell { width: min(100% - 22px, 620px); padding-top: 24px; }
  .masthead { padding-inline: 4px; }
  .seal { width: 62px; }
  .tool-tab { min-height: 59px; flex-direction: column; gap: 4px; font-size: .82rem; }
  .tab-index { font-size: .55rem; }
  .tool-panel { padding: 23px 15px; }
  .tool-heading { display: block; margin-bottom: 20px; }
  .tool-heading > p { margin-top: 10px; }
  .tool-layout { grid-template-columns: 1fr; }
  .stage-card { min-height: 430px; }
  .wheel-stage { min-height: 480px; }
  .wheel-wrap { width: min(88%, 360px); }
  .jiaobei-pair { gap: 32px; }
  footer { display: block; text-align: center; line-height: 1.6; }
  footer p { margin-top: 5px; }
}
@media (max-width: 430px) {
  .masthead .intro { max-width: 210px; }
  .seal { display: none; }
  .tool-panel { min-height: 0; }
  .controls-card, .stage-card { padding: 20px 16px; }
  .stage-card { min-height: 405px; }
  .wheel-stage { min-height: 440px; padding-bottom: 82px; }
  .number-grid { grid-template-columns: repeat(3,1fr); }
  .jiaobei-piece { width: 58px; height: 116px; }
  .dice-cup { width: 205px; height: 205px; }
  .die { width: 58px; padding: 8px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
