:root {
  --ink: #2c1d45;
  --ink-soft: rgba(44, 29, 69, .7);
  --paper: #fff8ec;
  --gold: #f2b14a;
  --serif: 'Bodoni Moda', 'Didot', 'Bodoni 72', 'Noto Serif SC', 'Songti SC', 'STSong', Georgia, serif;
  --sans: 'Jost', 'Avenir Next', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'Segoe UI', system-ui, sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --txt: var(--ink);
  --txt-shadow: 0 1px 12px rgba(255, 255, 255, .55);
}
body.night { --txt: #fdf6ff; --txt-shadow: 0 1px 14px rgba(20, 14, 60, .6); }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #ffb99c; font-family: var(--sans); color: var(--ink); user-select: none; -webkit-user-select: none; overscroll-behavior: none; touch-action: manipulation; -webkit-touch-callout: none; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }

#bg, #c, #fade { position: fixed; inset: 0; width: 100%; height: 100%; }
#bg { overflow: hidden; }
#c { display: block; touch-action: none; cursor: pointer; }
#fade { background: var(--paper); opacity: 1; pointer-events: none; transition: opacity .6s ease; z-index: 50; }
#fade.clear { opacity: 0; }
/* first load only: a small rising sun, shown after a short delay so fast loads never see it */
#fade { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 22px; }
#fade .loader { width: 34px; height: 34px; border-radius: 50%; background: radial-gradient(circle at 36% 30%, #fff6d0, #ffcf5e 45%, #f08f3c); box-shadow: 0 0 22px 6px rgba(242, 177, 74, .45); opacity: 0; animation: boot-in .6s ease .45s forwards, breathe-sun 2.4s ease-in-out .45s infinite; }
#boot-msg { margin: 0; max-width: 78vw; text-align: center; font-size: 14px; line-height: 1.6; color: var(--ink-soft); min-height: 1.6em; }
html.ready #fade .loader, html.ready #boot-msg { display: none; }
html.boot-slow:not(.ready) #fade, html.boot-fail:not(.ready) #fade { pointer-events: auto; cursor: pointer; }
html.boot-fail #fade .loader { animation: none; opacity: .35; filter: grayscale(1); }
@keyframes boot-in { to { opacity: 1; } }
@keyframes breathe-sun { 50% { transform: scale(.86); box-shadow: 0 0 30px 10px rgba(242, 177, 74, .6); } }
/* gentle nudge on the hint button when a player has been still for a while */
#b-hint.nudge { animation: nudge 1.6s ease-in-out 3; }
@keyframes nudge { 50% { box-shadow: 0 0 0 6px rgba(242, 177, 74, .35), 0 0 22px 6px rgba(255, 200, 100, .7); background: rgba(255, 246, 220, .9); } }

.off { opacity: 0 !important; pointer-events: none !important; }

/* ── HUD ── */
#hud { position: fixed; left: 0; right: 0; top: 0; padding: calc(14px + var(--safe-t)) 16px 0; display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; z-index: 10; transition: opacity .5s; pointer-events: none; }
#hud > * { pointer-events: auto; }
#hud .right { display: flex; gap: 8px; }
.ib { width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; background: rgba(255, 252, 246, .46); backdrop-filter: blur(10px) saturate(1.2); -webkit-backdrop-filter: blur(10px) saturate(1.2); box-shadow: 0 2px 14px rgba(70, 40, 80, .12), inset 0 0 0 1px rgba(255, 255, 255, .55); transition: transform .15s, background .2s; }
.ib:hover { background: rgba(255, 252, 244, .85); }
.ib:active { transform: scale(.92); }
.ib svg { width: 20px; height: 20px; fill: none; stroke: var(--ink); stroke-width: 1.45; stroke-linecap: round; stroke-linejoin: round; }
#b-sound .mute { display: none; }
#b-sound.muted .waves { display: none; }
#b-sound.muted .mute { display: block; }
#where { position: absolute; left: 50%; top: calc(16px + var(--safe-t)); transform: translateX(-50%); text-align: center; pointer-events: none; color: var(--txt); text-shadow: var(--txt-shadow); transition: color .8s; white-space: nowrap; }
#w-ch { display: block; font-size: 10px; letter-spacing: .42em; text-indent: .42em; text-transform: uppercase; opacity: .78; font-weight: 400; }
#w-name { display: block; font-family: var(--serif); font-size: 20px; font-style: italic; font-weight: 400; margin-top: 2px; letter-spacing: .01em; }

#lamps { position: fixed; top: calc(74px + var(--safe-t)); left: 50%; transform: translateX(-50%); display: flex; gap: 9px; z-index: 9; transition: opacity .5s; }
#lamps i { width: 11px; height: 11px; transform: rotate(45deg); border: 1.5px solid var(--txt); opacity: .6; transition: all .5s; }
#lamps i.lit { background: #ffd67a; border-color: #fff3cf; opacity: 1; box-shadow: 0 0 14px 3px rgba(255, 200, 100, .9); }

/* ── sundial ── */
#dial-wrap { position: fixed; left: 50%; bottom: calc(10px + var(--safe-b)); transform: translateX(-50%); width: min(62vw, 250px); z-index: 10; text-align: center; transition: opacity .5s; }
#mood { font-family: var(--serif); font-style: italic; font-size: 18px; color: var(--txt); text-shadow: var(--txt-shadow); transition: color .8s; margin-bottom: -2px; letter-spacing: .02em; }
#dial { width: 100%; display: block; overflow: visible; cursor: grab; touch-action: none; outline: none; }
#dial:active { cursor: grabbing; }
#dial .plate { fill: url(#g-plate); filter: drop-shadow(0 8px 18px rgba(60, 30, 80, .22)); }
#dial .rim { fill: none; stroke: url(#g-gold); stroke-width: 1.6; }
#dial .track { fill: none; stroke: var(--ink); stroke-opacity: .3; stroke-width: 1; stroke-dasharray: .6 4.2; stroke-linecap: round; }
#dial .notch { fill: #fffaf0; stroke: url(#g-gold); stroke-width: 1.4; transition: all .3s; }
#dial .notch.cur { fill: #f2b24a; stroke: #fff6dc; }
#dial .notch.hint { fill: #fff; stroke: #f2b24a; stroke-width: 3; animation: pulse 0.8s ease-in-out infinite; }
#dial .gnomon { fill: var(--ink); opacity: .9; }
#gshadow { stroke: var(--ink); stroke-opacity: .26; stroke-width: 6; stroke-linecap: round; }
#knob { cursor: grab; }
#knob .halo { fill: rgba(255, 214, 122, .34); }
#knob .core { fill: url(#g-sun); stroke: #fffaf0; stroke-width: 1.6; filter: drop-shadow(0 2px 6px rgba(190, 100, 20, .55)); }
#knob .rays line { stroke: #fff3cf; stroke-width: 1.6; stroke-linecap: round; }
#dial.shake { animation: shake .4s; }
#dial.beckon #knob .halo { animation: beckon 1.5s ease-in-out infinite; transform-origin: center; transform-box: fill-box; }
#dial-keys { font-size: 9.5px; letter-spacing: .36em; text-transform: uppercase; color: var(--txt); opacity: .55; margin-top: -6px; text-shadow: var(--txt-shadow); transition: color .8s; }
#dial-keys span { font-size: 13px; letter-spacing: 0; }
@keyframes shake { 20% { transform: translateX(-7px); } 40% { transform: translateX(6px); } 60% { transform: translateX(-4px); } 80% { transform: translateX(2px); } }
@keyframes pulse { 50% { r: 9; } }
@keyframes beckon { 50% { transform: scale(1.7); opacity: .2; } }

/* ── messages ── */
#toast, #tip { position: fixed; left: 50%; transform: translate(-50%, 8px); z-index: 12; pointer-events: none; opacity: 0; transition: opacity .4s, transform .4s; text-align: center; max-width: 86vw; }
#toast { bottom: calc(min(40vw, 172px) + 34px + var(--safe-b)); padding: 9px 18px; border-radius: 22px; background: rgba(58, 42, 77, .82); color: #fff8ec; font-size: 14px; letter-spacing: .02em; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
#tip { top: calc(98px + var(--safe-t)); font-family: var(--serif); font-style: italic; font-size: 18px; color: var(--txt); text-shadow: var(--txt-shadow); }
#toast.show, #tip.show { opacity: 1; transform: translate(-50%, 0); }

/* ── veils (title, cards) ── */
.veil { position: fixed; inset: 0; z-index: 20; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 24px; transition: opacity .7s ease; }
#title { justify-content: flex-start; padding-top: clamp(64px, 12vh, 130px); pointer-events: none; }
#title > * { pointer-events: auto; }
#title.off > * { pointer-events: none; }
.kicker { display: flex; align-items: center; gap: 14px; font-size: 10.5px; letter-spacing: .5em; text-indent: .5em; text-transform: uppercase; color: var(--ink); opacity: .82; margin: 0 0 18px; }
.kicker b, #dial-keys b { font-weight: inherit; }
.kicker span { width: 34px; height: 1px; background: var(--ink); opacity: .5; }
.logo { font-family: var(--serif); font-weight: 500; font-size: clamp(42px, 11.5vw, 112px); letter-spacing: .14em; margin: 0 0 0 .14em; color: var(--ink); line-height: 1; display: flex; align-items: center; white-space: nowrap; font-optical-sizing: auto; }
.logo .o { display: inline-block; width: .7em; height: .7em; border-radius: 50%; margin: 0 .14em 0 0; flex: none; }
.logo .sun { background: radial-gradient(circle at 36% 30%, #fff6d0 0%, #ffcf5e 45%, #f08f3c 100%); box-shadow: 0 0 .5em .05em rgba(255, 190, 90, .6); animation: breathe 5s ease-in-out infinite; }
.logo .moon { background: radial-gradient(circle at 70% 28%, #5a4a8c 0%, var(--ink) 55%); box-shadow: inset .05em -.04em 0 0 rgba(255, 255, 255, .16); }
.tag { font-family: var(--serif); font-style: italic; font-size: clamp(17px, 4.2vw, 25px); margin: 18px 0 30px; color: var(--ink); opacity: .85; }
.fine { font-size: 10px; letter-spacing: .34em; text-indent: .34em; text-transform: uppercase; opacity: .62; margin-top: 24px; }
.btns { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
@keyframes breathe { 50% { box-shadow: 0 0 .8em .12em rgba(255, 190, 90, .75); } }
.pill { padding: 14px 38px; border-radius: 40px; background: var(--ink); color: var(--paper); font-size: 11.5px; font-weight: 400; letter-spacing: .42em; text-transform: uppercase; text-indent: .42em; box-shadow: 0 8px 24px rgba(58, 42, 77, .28); transition: transform .15s, box-shadow .2s, background .2s; }
.pill:hover { transform: translateY(-2px); box-shadow: 0 12px 28px rgba(58, 42, 77, .34); }
.pill:active { transform: scale(.96); }
.pill.ghost { background: rgba(255, 252, 244, .34); color: var(--ink); box-shadow: inset 0 0 0 1px rgba(44, 29, 69, .55); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.sunmark { width: 54px; height: 30px; overflow: hidden; position: relative; border-bottom: 1.5px solid var(--ink); }
.sunmark i { position: absolute; left: 50%; bottom: -19px; width: 38px; height: 38px; margin-left: -19px; border-radius: 50%; background: radial-gradient(circle at 36% 30%, #fff6d0, #ffcf5e 45%, #f08f3c); box-shadow: 0 0 22px 6px rgba(242, 177, 74, .55); animation: rise 5s ease-in-out infinite alternate; }
.sunmark.big { transform: scale(1.4); margin-bottom: 18px; }
@keyframes rise { from { transform: translateY(9px); } to { transform: translateY(-4px); } }

#card { background: radial-gradient(ellipse at 50% 42%, #fffaf0 0%, #fff3e2 55%, #fbe3cf 100%); z-index: 18; transition: opacity 1.1s ease; }
#card .numeral { font-family: var(--serif); font-size: 44px; font-style: italic; letter-spacing: .06em; color: var(--gold); line-height: 1; }
#card .chapter { font-size: 10.5px; letter-spacing: .5em; text-transform: uppercase; opacity: .75; margin-top: 12px; text-indent: .5em; }
#card h2, #done h2, #finale h2 { font-family: var(--serif); font-weight: 400; font-style: italic; font-size: clamp(34px, 9vw, 64px); margin: 16px 0 10px; letter-spacing: -.005em; }
#card p, #done p, #finale p { font-family: var(--sans); font-weight: 300; letter-spacing: .04em; font-size: clamp(14px, 3.6vw, 17px); color: var(--ink-soft); margin: 0; line-height: 1.45; }
#card::after { content: ''; width: 44px; height: 1px; background: var(--ink); opacity: .35; margin-top: 22px; }

#done { background: radial-gradient(ellipse at 50% 46%, rgba(255, 250, 238, .97) 0%, rgba(255, 246, 228, .93) 40%, rgba(255, 240, 215, .7) 100%); backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px); }
#done .spark { color: var(--gold); font-size: 28px; animation: twirl 6s linear infinite; }
#done .btns, #finale .btns { margin-top: 26px; }
#finale .fine { margin-top: 30px; }
#finale p { max-width: 30em; }
#finale { background: radial-gradient(ellipse at 50% 46%, rgba(255, 250, 238, .97) 0%, rgba(255, 244, 224, .88) 45%, rgba(255, 236, 205, .35) 90%); }
@keyframes twirl { to { transform: rotate(360deg); } }

/* ── chapter sheet ── */
.sheet { position: fixed; inset: 0; z-index: 30; background: rgba(255, 248, 236, .9); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px); overflow-y: auto; padding: calc(26px + var(--safe-t)) 22px calc(40px + var(--safe-b)); transition: opacity .4s; touch-action: pan-y; }
.sheet h3 { font-family: var(--serif); font-weight: 400; font-size: 36px; font-style: italic; margin: 6px 0 22px; text-align: center; }
.sheet .close { position: absolute; right: 16px; top: calc(14px + var(--safe-t)); }
#l-grid { max-width: 680px; margin: 0 auto; }
.ch { margin-bottom: 26px; }
.ch-h { display: flex; align-items: baseline; gap: 12px; border-bottom: 1px solid rgba(58, 42, 77, .16); padding-bottom: 7px; margin-bottom: 12px; }
.ch-h b { font-family: var(--serif); font-weight: 500; font-size: 24px; color: var(--gold); width: 30px; }
.ch-h span { font-size: 11.5px; letter-spacing: .32em; text-transform: uppercase; }
.lv-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
.lv { text-align: left; padding: 13px 15px; border-radius: 14px; background: rgba(255, 255, 255, .72); box-shadow: 0 2px 10px rgba(70, 40, 80, .07), inset 0 0 0 1px rgba(58, 42, 77, .08); display: flex; align-items: center; gap: 12px; transition: transform .15s, background .2s; }
.lv:hover { background: #fff; transform: translateY(-1px); }
.lv .n { font-family: var(--serif); font-size: 22px; width: 24px; text-align: center; opacity: .55; }
.lv .t { font-family: var(--serif); font-size: 19px; font-style: italic; line-height: 1.1; }
.lv .s { margin-left: auto; color: var(--gold); font-size: 15px; }
.lv.locked { opacity: .42; pointer-events: none; }
.lv.cur { box-shadow: 0 2px 10px rgba(70, 40, 80, .07), inset 0 0 0 1.5px var(--gold); }

@media (max-height: 560px) {
  #dial-wrap { width: min(34vw, 190px); left: auto; right: calc(14px + env(safe-area-inset-right, 0px)); transform: none; }
  #toast { bottom: 24px; }
  #title { padding-top: 5vh; }
  .kicker { margin-bottom: 8px; }
  .tag { margin: 8px 0 14px; }
  #tip { top: calc(64px + var(--safe-t)); font-size: 17px; }
  #lamps { top: calc(64px + var(--safe-t)); }
}
@media (prefers-reduced-motion: reduce) { .sunmark i, #done .spark { animation: none; } #fade .loader { animation: boot-in .6s ease .45s forwards; } }

@media (max-width: 560px) {
  #where { top: calc(64px + var(--safe-t)); }
  #w-ch { font-size: 9.5px; letter-spacing: .28em; }
  #w-name { font-size: 20px; }
  #lamps { top: calc(116px + var(--safe-t)); }
  #tip { top: calc(138px + var(--safe-t)); font-size: 18px; }
  .ib { width: 40px; height: 40px; }
  .logo { letter-spacing: .1em; margin-left: .1em; }
  .kicker { font-size: 9px; letter-spacing: .3em; text-indent: .3em; gap: 10px; max-width: 88vw; line-height: 1.7; }
  .kicker span { width: 16px; flex: none; }
  .fine { font-size: 8.5px; letter-spacing: .22em; text-indent: .22em; max-width: 82vw; line-height: 1.8; margin-top: 18px; }
  .tag { margin: 14px 0 22px; max-width: 88vw; }
  #title .btns { flex-wrap: nowrap; gap: 10px; }
  #title .pill { padding: 15px 22px; letter-spacing: .28em; text-indent: .28em; font-size: 11px; white-space: nowrap; }
}

/* ── language ── */
.lang-btn { position: absolute; right: 16px; top: calc(14px + var(--safe-t)); height: 40px; padding: 0 14px 0 11px; border-radius: 22px; display: flex; align-items: center; gap: 7px; background: rgba(255, 252, 246, .46); backdrop-filter: blur(10px) saturate(1.2); -webkit-backdrop-filter: blur(10px) saturate(1.2); box-shadow: 0 2px 14px rgba(70, 40, 80, .12), inset 0 0 0 1px rgba(255, 255, 255, .55); font-size: 11px; letter-spacing: .22em; font-weight: 500; color: var(--ink); }
.lang-btn svg { width: 18px; height: 18px; fill: none; stroke: var(--ink); stroke-width: 1.3; }
.sheet .lang-btn { right: auto; left: 16px; background: rgba(255, 255, 255, .7); box-shadow: inset 0 0 0 1px rgba(44, 29, 69, .14); }
#langs { z-index: 40; }
#lg-list { max-width: 420px; margin: 0 auto; display: grid; gap: 10px; }
.lg { padding: 16px 20px; border-radius: 16px; background: rgba(255, 255, 255, .72); box-shadow: inset 0 0 0 1px rgba(44, 29, 69, .1); font-family: var(--serif); font-size: 21px; text-align: center; transition: transform .15s, background .2s; }
.lg:active { transform: scale(.98); }
.lg.cur { box-shadow: inset 0 0 0 1.5px var(--gold); background: #fff; }
html[lang="zh"] * { font-style: normal !important; }
html[lang="zh"] .tag, html[lang="zh"] #w-name, html[lang="zh"] #mood, html[lang="zh"] #tip, html[lang="zh"] #card h2, html[lang="zh"] #done h2, html[lang="zh"] #finale h2, html[lang="zh"] .lv .t { letter-spacing: .12em; }
html[lang="zh"] #w-ch, html[lang="zh"] .kicker, html[lang="zh"] .fine, html[lang="zh"] .pill, html[lang="zh"] #dial-keys, html[lang="zh"] #card .chapter, html[lang="zh"] .ch-h span { font-size: 12px; }
html[lang="zh"] #card p, html[lang="zh"] #done p, html[lang="zh"] #finale p { letter-spacing: .1em; font-weight: 400; }

/* ── phones first: undo and hint sit beside the sundial, under the thumbs ── */
@media (max-width: 560px) and (min-height: 561px) {
  #b-undo, #b-hint { position: fixed; bottom: calc(42px + var(--safe-b)); width: 52px; height: 52px; }
  #b-undo { left: calc((100vw - min(62vw, 250px)) / 4 - 26px); }
  #b-hint { right: calc((100vw - min(62vw, 250px)) / 4 - 26px); }
  #b-undo svg, #b-hint svg { width: 23px; height: 23px; }
  .ib { width: 44px; height: 44px; }
  #toast { font-size: 13.5px; }
  .pill { padding: 16px 34px; }
  .lv-row { grid-template-columns: 1fr 1fr; }
}
