:root {
  --ivory: #F7F2EA;
  --ink: #17130F;
  --soft-ink: #5A5047;
  --rule: #D9CFC1;
  --ox: #742D2C;
  --clay: #B08F72;
  --display: "Cormorant Garamond", "Noto Serif TC", "Songti TC", Georgia, serif;
  --body: "Spectral", "Noto Serif TC", "Songti TC", Georgia, serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html { background: var(--ivory); -webkit-text-size-adjust: 100%; }
h1, h2, .order-text, .val, .res-marks, .num, .tool { font-variant-numeric: lining-nums tabular-nums; }
body {
  margin: 0; min-width: 320px; background: var(--ivory); color: var(--ink);
  font: 16px/1.45 var(--body);
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; touch-action: manipulation; }
button:focus-visible, summary:focus-visible { outline: 2px solid var(--ox); outline-offset: 3px; }
[hidden] { display: none !important; }

.shell {
  width: min(100%, 560px); margin: 0 auto; min-height: 100svh;
  padding: max(10px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(28px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
.top { display: flex; align-items: center; justify-content: space-between; min-height: 56px; border-bottom: 1px solid var(--ink); }
.mark { display:flex; align-items:center; gap:5px; margin: 0; min-width: 126px; min-height:44px; padding:0; text-align:left; font: 600 26px/1 var(--display); letter-spacing: .01em; }
.mark svg { width:25px; height:22px; flex:0 0 25px; }
.mark em { font-style: italic; font-weight: 500; }
.tools { display: flex; gap: 1px; align-items:center; margin-left:8px; }
.tool { min-height: 44px; min-width: 44px; padding: 0 10px; font-size: 13px; letter-spacing: .14em; text-transform: uppercase; font-variant-numeric: tabular-nums; }
.tool.lang { letter-spacing: .06em; text-transform: none; font-size: 15px; }
.howto-short { display:none; }

.label { font-size: 12px; letter-spacing: .18em; text-transform: uppercase; color: var(--soft-ink); }
:lang(zh-Hant) .label { letter-spacing: .08em; font-size: 13px; }

.goal-line { margin: 12px 0 0; text-align:center; font:600 18px/1.2 var(--display); }
.order { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 42px; padding-top: 3px; }
.order-person { width:38px; height:38px; flex:0 0 38px; }
.order-person svg, .send-person svg { display:block; width:100%; height:100%; }
.jars { display: flex; gap: 3px; align-items: flex-end; }
.jars svg { display: block; }
.order-text { font: 500 22px/1 var(--display); font-variant-numeric: tabular-nums; white-space:nowrap; }
.marks-counter { margin: 1px 0 4px; text-align:center; color:var(--soft-ink); font:600 14px/1.2 var(--body); letter-spacing:.04em; }

.tablet-wrap { position: relative; margin: 6px auto 0; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: manipulation; }
.tablet-wrap svg { display: block; margin: 0 auto; overflow: visible; }
.tablet-wrap .tablet-baking { animation: bake .4s ease-out forwards; transform-origin: center; }
@keyframes bake { from { filter: drop-shadow(0 0 0 rgba(194, 111, 47, 0)); } to { filter: brightness(.79) saturate(.82) drop-shadow(0 0 8px rgba(194, 111, 47, .72)); } }
.slot-hit { fill: transparent; cursor: pointer; }
.slot-hit:focus { outline: none; }
.slot-hit:focus-visible { stroke: var(--ox); stroke-width: 2; }
.dry-ring-base { fill:none; stroke:#D8C2A8; stroke-width:2.1; }
.dry-ring-segment { fill:none; stroke:#76533D; stroke-width:2.3; stroke-linecap:round; opacity:.22; }
.dry-ring-segment.closed { opacity:1; }
.lit { fill: none; stroke: var(--ox); stroke-width: 2.4; }
.lit.pulse { animation: litpulse 1.6s ease-in-out infinite; }
@keyframes litpulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }
.wedge.fresh { animation: press .22s ease-out; transform-box: fill-box; transform-origin: 50% 20%; }
@keyframes press { from { transform: scale(1.18); opacity: .4; } to { transform: scale(1); opacity: 1; } }
.smudge { animation: smudge .7s ease-out forwards; }
@keyframes smudge { from { opacity: .9; } to { opacity: 0; } }
.held-ring { fill: none; stroke: var(--ink); stroke-width: 1.2; stroke-dasharray: 3 3; animation: smudge 1.2s ease-out forwards; }
.wedge.ghost { opacity: .82; }
.wedge.smoothing { opacity: .4; }
.ghost-smudge { fill: #7A5B46; opacity: .35; }
.demo-puff { fill: #E7D2B8; opacity: 0; transform-box: fill-box; transform-origin: center; }
.demo-one, .demo-two, .hand-demo { pointer-events: none; transform-box: fill-box; transform-origin: center; }
.hand-demo .demo-wedge, .hand-demo .demo-ripple { opacity: 0; }
.hand-demo .demo-stylus { transform-box: fill-box; transform-origin: 50% 100%; filter: drop-shadow(0 1px 0 rgba(36, 25, 20, .32)); }
.hand-demo .demo-hand { filter: drop-shadow(0 1px 0 rgba(36, 25, 20, .18)); }
.demo-one .hand-demo { animation: hand-loop 3s ease-in-out infinite; }
.demo-one .demo-stylus { animation: stylus-loop 3s ease-in-out infinite; }
.demo-one .demo-wedge { animation: demo-show 3s ease-in-out infinite; }
.demo-one .demo-puff { animation: puff 3s ease-out infinite; }
.demo-one .tap-ripple { animation: tap-pulse 1.7s ease-out infinite; transform-box: fill-box; transform-origin: center; }
.demo-one .tap-core { animation: tap-core 1.7s ease-out infinite; }
@keyframes tap-pulse { 0%, 100% { opacity: .9; transform: scale(.72); } 62% { opacity: .08; transform: scale(1.3); } }
@keyframes tap-core { 0%, 100% { opacity: .88; } 62% { opacity: .25; } }
.demo-two .hand-demo { animation: hand-once 2.4s ease-in-out 1 both; }
.demo-two .demo-stylus { animation: stylus-once 2.4s ease-in-out 1 both; }
.demo-two .demo-wedge, .demo-two .demo-ripple { animation: demo-once 2.4s ease-in-out 1 both; }
@keyframes hand-loop { 0%, 14%, 88%, 100% { transform: translate(-4px,-6px); } 39%, 58% { transform: translate(0,0); } }
@keyframes stylus-loop { 0%, 14%, 88%, 100% { transform: rotate(-9deg) translateY(-3px); } 39%, 58% { transform: rotate(0) translateY(0); } }
@keyframes demo-show { 0%, 31%, 88%, 100% { opacity: 0; } 42%, 76% { opacity: .72; } }
@keyframes puff { 0%, 37%, 88%, 100% { opacity: 0; transform: scale(.35); } 44%, 62% { opacity: .72; transform: scale(1); } }
@keyframes hand-once { 0%, 16% { transform: translate(-4px,-6px); } 42%, 100% { transform: translate(0,0); } }
@keyframes stylus-once { 0%, 16% { transform: rotate(-9deg) translateY(-3px); } 42%, 100% { transform: rotate(0) translateY(0); } }
@keyframes demo-once { 0%, 35% { opacity: 0; } 45%, 100% { opacity: .72; } }
@media (prefers-reduced-motion: reduce) {
  .demo-one .tap-ripple, .demo-one .tap-core { animation: none; }
  .lit.pulse, .wedge.fresh, .smudge, .held-ring, .tablet-wrap .tablet-baking, .demo-one .hand-demo, .demo-two .hand-demo, .demo-one .hand-demo .demo-stylus, .demo-two .hand-demo .demo-stylus, .demo-one .hand-demo .demo-wedge, .demo-two .hand-demo .demo-wedge, .demo-two .hand-demo .demo-ripple, .demo-one .demo-puff { animation: none; }
  .demo-one .demo-wedge, .demo-two .demo-wedge, .demo-two .demo-ripple { opacity: .64; }
  .demo-one .demo-puff { opacity: .45; transform: scale(.8); }
}

.caption { margin: 8px 0 0; text-align: center; font: italic 400 14px/1.3 var(--body); color: var(--soft-ink); }
.msg { min-height: 26px; margin: 10px 0 0; text-align: center; font-size: 16px; line-height: 1.35; }
.msg.warn { color: var(--ox); }

.readers { display:none; }
.reader { display: flex; align-items: center; gap: 9px; min-height: 58px; border-top: 1px solid var(--rule); padding: 5px 3px; }
.reader.guard { flex-direction: row-reverse; justify-content: flex-start; animation: guard-arrive .45s ease-out both; }
@keyframes guard-arrive { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: translateX(0); } }
.reader-figure { width: 70px; height: 53px; flex: 0 0 70px; }
.reader-jars { display: flex; align-items: flex-end; gap: 3px; min-height: 28px; flex-wrap: wrap; }
.reader-jars .jar-ghost { opacity: .72; }
.reader-jars .jar-lost { opacity: .35; }
.reader.result-ok .reader-figure { animation: nod .55s ease-out both; transform-origin: 50% 75%; }
.reader.result-void .reader-figure { transform: rotate(-4deg); }
.reader.result-void .brow { transform: translateY(1.5px) rotate(12deg); transform-origin: center; }
.reader.result-ok .held-jars { transform: translateY(-4px); }
@keyframes nod { 0% { transform: rotate(0); } 42% { transform: rotate(7deg); } 100% { transform: rotate(0); } }

.actions { display: flex; gap: 8px; align-items:center; margin: 14px 0 6px; }
@media (max-width: 360px) { .actions { gap: 6px; } .actions .btn { font-size: 14px; letter-spacing: 0; padding: 0 3px; } .res-actions .btn { font-size: 14px; letter-spacing: 0; padding: 0 4px; } }
.btn { min-height: 48px; padding: 0 14px; border: 1px solid var(--ink); font-size: 15px; letter-spacing: .04em; }
.actions .btn { flex: 1 1 0; padding: 0 6px; }
.actions .send { flex: 1.4 1 0; }
.send-person { width:42px; height:48px; flex:0 0 42px; }
.send-person.running { animation: messenger-run .4s ease-in forwards; }
@keyframes messenger-run { to { transform:translateX(72px); opacity:0; } }
.action-btn { font: 600 16px/1 var(--display); letter-spacing: .07em; }
.btn.send { border-color: var(--ox); color: var(--ox); }
.btn.send.ready { background: var(--ox); color: var(--ivory); }
.btn[aria-disabled="true"] { border-color: var(--rule); color: #A79C90; }
.btn.send[aria-disabled="true"] { border-color: #C9A9A6; color: #B38582; }

.result { margin: 14px 0 6px; border-top: 1px solid var(--ink); border-bottom: 1px solid var(--ink); padding: 12px 0 10px; }
.res-title { margin: 0; font: 600 26px/1.1 var(--display); }
.res-title em { font-weight: 500; }
.res-reason { margin: 6px 0 0; font-size: 16px; }
.res-reason.warn { color: var(--ox); }
.screen-reader-note { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.res-score { display: flex; align-items: baseline; gap: 14px; margin-top: 10px; }
.res-marks { font: 600 40px/1 var(--display); color: var(--ox); font-variant-numeric: tabular-nums; }
.res-par { font-size: 15px; color: var(--soft-ink); }
.res-tally { margin: 6px 0 0; min-height: 22px; }
.res-tally svg { vertical-align: middle; }
.res-actions { display: grid; grid-template-columns: 1.3fr 1fr 1fr; gap: 8px; margin-top: 12px; }
.share-line { min-height: 20px; margin: 8px 0 0; font-size: 14px; color: var(--soft-ink); }
.why summary { display: inline-flex; align-items: center; min-height: 44px; cursor: pointer; font: italic 500 19px/1 var(--display); list-style: none; }
.why summary::-webkit-details-marker { display: none; }
.why p { margin: 0 0 4px; font-size: 15px; line-height: 1.5; max-width: 60ch; }
.why a { color:var(--ox); font-size:14px; }

.map { padding-top: 10px; }
.map-title { margin: 6px 0 10px; font: 600 26px/1 var(--display); }
.daily-card { width:100%; min-height:52px; margin:0 0 10px; padding:8px 12px; border:1px solid var(--ox); color:var(--ox); text-align:left; font:600 18px/1.15 var(--display); }
.map-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.tile { position: relative; min-height: 92px; padding: 8px 8px 6px; border: 1px solid var(--rule); text-align: left; display: flex; flex-direction: column; justify-content: space-between; }
.tile .num { font: 600 22px/1 var(--display); }
.tile .best { font-size: 13px; color: var(--soft-ink); font-variant-numeric: tabular-nums; }
.tile.done { border-color: var(--ink); }
.tile.atpar .best { color: var(--ox); }
.tile.locked { color: #A79C90; }
.tile.current { box-shadow: inset 0 -3px 0 var(--ox); }
.tile svg { position: absolute; right: 8px; top: 8px; }
.map .btn { width: 100%; margin-top: 14px; }

@media (min-width: 700px) {
  .shell { padding-top: 22px; }
  .mark { font-size: 30px; }
}

.howto-overlay { position:fixed; z-index:20; inset:0; display:grid; place-items:center; padding:20px; background:rgba(28,19,14,.48); }
.howto-card { width:min(100%, 390px); padding:18px; background:var(--ivory); border:1px solid var(--ink); box-shadow:0 12px 40px rgba(27,19,15,.28); }
.howto-card h2 { margin:0 0 10px; font:600 28px/1 var(--display); }
.howto-picture { height:130px; margin:0 0 13px; overflow:hidden; background:#E5CBAE; }
.howto-picture svg { display:block; width:100%; height:100%; }
.howto-picture img { display:block; width:100%; height:100%; }
.howto-card ul { margin:0 0 16px; padding-left:20px; }
.howto-card li { margin:5px 0; }
.howto-card .btn { width:100%; }

@media (max-width: 360px) {
  .shell { padding-left:10px; padding-right:10px; }
  .mark { min-width:96px; font-size:21px; gap:3px; }
  .mark svg { width:20px; height:19px; flex-basis:20px; }
  .map-tool { padding:0; font-size:0; }
  .map-tool::after { content:'□'; font-size:19px; }
  .howto-word { display:none; }
  .howto-short { display:inline; font-size:20px; }
  .howto-tool { padding:0; }
  .goal-line { font-size:17px; }
  .order { gap:5px; }
  .order-person { width:31px; height:34px; flex-basis:31px; }
  .order-text { font-size:20px; }
  .jars { gap:1px; }
  .jars svg { width:12px; height:17px; }
  .send-person { width:32px; flex-basis:32px; }
  .actions { display:grid; grid-template-columns:1fr 1fr; gap:8px; }
  .actions .btn { min-width:0; }
  .actions .send { grid-column:1; grid-row:2; }
  .send-person { grid-column:2; grid-row:2; justify-self:start; }
}

/* numbers stand upright everywhere (Cormorant defaults to old-style figures) */
.mark, .res-title, .res-marks, .readings .val, .order-text, .tile .num, .map-title, .tool { font-variant-numeric: lining-nums tabular-nums; font-feature-settings: "lnum" 1, "tnum" 1; }

/* CJK has no true italic: keep the emphasis upright */
:lang(zh-Hant) .mark em, :lang(zh-Hant) .res-title em, :lang(zh-Hant) .why summary { font-style: normal; }

/* one record: the bridge between touching marks, and the dashed outline round a group that stands alone */
.join { fill: #5C4231; opacity: .55; }
.split-group { fill: none; stroke: var(--ox); stroke-width: 2.4; stroke-dasharray: 7 5; }
/* the first minute */
.fm-bar { margin: 8px 0 0; padding: 8px 12px; border: 1px solid var(--ink); background: var(--ivory); }
.fm-top { display: flex; justify-content: space-between; align-items: center; }
.fm-count { font-size: 14px; color: #6B5E52; }
.fm-skip { min-height: 44px; min-width: 64px; padding: 0 10px; border: 0; background: none; color: #6B5E52; font: inherit; font-size: 15px; text-decoration: underline; }
.fm-skip[hidden] { display: none; }
.fm-premise { margin: 0 0 4px; font: 600 20px/1.3 var(--display); }
.fm-premise:empty { display: none; }
.fm-line { margin: 0 0 4px; font-size: 20px; line-height: 1.4; min-height: 1.4em; }
.fm-bar[hidden], .fm-glimpse[hidden] { display: none; }
#fmReplay { width: 100%; margin: 0 0 10px; }
