:root {
  --bg1: #14102a; --bg2: #2a1b4d; --fg: #fff; --muted: #b9b2d8; --accent: #ffd23f; --good: #22c55e; --bad: #ff4d4f;
  --safe-top: env(safe-area-inset-top, 0px); --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
button, a.ghost-btn { font-family: inherit; }
:focus { outline: none; }
:focus-visible { outline: 3px solid #fff; outline-offset: 3px; box-shadow: 0 0 0 6px rgba(20,16,42,.9); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg1); color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", system-ui, sans-serif;
  -webkit-user-select: none; user-select: none; touch-action: manipulation; overscroll-behavior: none; }
#app { position: relative; height: 100%; max-width: 520px; margin: 0 auto; overflow: hidden;
  background: radial-gradient(120% 80% at 50% 0%, var(--bg2), var(--bg1)); }
#fx { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 5; }
.screen { position: absolute; inset: 0; display: none; flex-direction: column; align-items: center;
  padding: calc(16px + var(--safe-top)) 20px calc(16px + var(--safe-bottom)); }
.screen.active { display: flex; animation: fadeIn .25s ease; }
@keyframes fadeIn { from { opacity: 0; transform: scale(.98); } to { opacity: 1; transform: none; } }

.topbar { width: 100%; display: flex; justify-content: space-between; }
.topbar-right { display: flex; gap: 8px; }
#btn-cb { display: flex; align-items: center; gap: 4px; padding: 0 12px; font-size: 13px; letter-spacing: 1px; }
#btn-cb .cb-icon { font-size: 18px; }
#btn-cb .cb-shapes { opacity: .55; }
#btn-cb.on { background: #fff; color: #1b1333; } #btn-cb.on .cb-shapes { opacity: 1; }
.icon-btn { background: rgba(255,255,255,.1); border: 0; color: var(--fg); font-size: 18px; min-width: 44px; height: 44px; border-radius: 22px; cursor: pointer; }
.icon-btn.pill { padding: 0 16px; font-weight: 700; font-size: 15px; }
.logo { margin: 4vh 0 4px; font-size: clamp(44px, 14vw, 64px); letter-spacing: 4px; line-height: 1.1;
  background: linear-gradient(90deg, #ff4d4f, #facc15, #22c55e, #2f7cff, #a855f7); -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 4px 0 rgba(0,0,0,.35)); }
.subtitle { margin: 0; color: var(--muted); font-size: 17px; }
.demo { margin: 3vh 0 2vh; font-size: 44px; font-weight: 900; display: flex; gap: 18px; }
.demo span { animation: bob 1.6s ease-in-out infinite; text-shadow: 0 3px 0 rgba(0,0,0,.3); }
.demo span:nth-child(2) { animation-delay: .2s; } .demo span:nth-child(3) { animation-delay: .4s; }
@keyframes bob { 50% { transform: translateY(-8px); } }
.best-line { color: var(--muted); margin-bottom: 14px; } .best-line b { color: var(--accent); font-size: 20px; }
.big-btn { width: min(320px, 100%); min-height: 60px; border: 0; border-radius: 30px; font-size: 22px; font-weight: 800; color: #1b1333; cursor: pointer;
  background: linear-gradient(180deg, #ffe066, #ffb703); box-shadow: 0 6px 0 #c77d00, 0 10px 24px rgba(0,0,0,.35); margin: 8px 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; transition: transform .08s; }
.big-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 #c77d00; }
.big-btn small { font-size: 12px; font-weight: 600; opacity: .75; }
.big-btn.reward { background: linear-gradient(180deg, #7ef0a8, #22c55e); box-shadow: 0 6px 0 #15803d, 0 10px 24px rgba(0,0,0,.35); }
.big-btn.reward > span::before { content: '▶ '; font-size: .8em; }
.big-btn[hidden] { display: none; }
#btn-play { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.05); } }
.daily-btn { width: min(320px, 100%); min-height: 64px; margin: 10px 0 4px; border: 2px solid rgba(255,255,255,.18); border-radius: 22px;
  background: rgba(255,255,255,.07); color: var(--fg); display: flex; align-items: center; gap: 12px; padding: 8px 14px; cursor: pointer; text-align: left; }
.daily-btn:active { transform: translateY(2px); }
.daily-cal { width: 46px; flex: none; border-radius: 10px; overflow: hidden; background: #fff; color: #1b1333; display: flex; flex-direction: column; align-items: center; line-height: 1; }
.daily-cal small { width: 100%; text-align: center; background: var(--bad); color: #fff; font-size: 11px; font-weight: 800; padding: 3px 0; }
.daily-cal b { font-size: 22px; padding: 3px 0 4px; }
.daily-text { flex: 1; display: flex; flex-direction: column; } .daily-text b { font-size: 18px; } .daily-text small { color: var(--muted); font-size: 13px; }
.daily-streak { font-weight: 900; color: var(--accent); font-size: 18px; }
.daily-btn.done { border-color: rgba(255,210,63,.5); }
.ghost-btn { background: transparent; color: var(--fg); border: 2px solid rgba(255,255,255,.35); border-radius: 24px; min-height: 46px; padding: 0 22px; font-size: 16px; font-weight: 700; margin-top: 6px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.ghost-btn.primary { border-color: var(--accent); color: var(--accent); }
.over-row { display: flex; gap: 10px; justify-content: center; width: min(320px, 100%); } .over-row > * { flex: 1; }
.howto { margin-top: auto; text-align: center; color: var(--muted); font-size: 14px; line-height: 1.5; }
.howto h2 { font-size: 15px; color: var(--fg); margin: 0 0 4px; }
.howto p { margin: 2px 0; } .howto b { color: var(--fg); } .muted { opacity: .7; }
@media (hover: none) { .desktop-only { display: none; } }

/* HUD */
.hud { width: 100%; display: flex; justify-content: space-between; align-items: flex-end; gap: 6px; }
.hud-item { display: flex; flex-direction: column; min-width: 80px; }
.timerow { width: 100%; display: flex; align-items: center; gap: 10px; }
.timerow .timebar { flex: 1; }
.pause-btn { width: 44px; height: 44px; flex: none; border: 0; border-radius: 22px; background: rgba(255,255,255,.1); color: var(--fg); font-size: 13px; letter-spacing: -2px; cursor: pointer; }
#hud-score.bump { animation: pop .2s ease; display: inline-block; }
.hud-item.right { position: relative; }
.time-gain { position: absolute; right: 0; top: 100%; font-size: 13px; font-weight: 900; color: #7ef0a8; opacity: 0; pointer-events: none; white-space: nowrap; }
.time-gain.show { animation: gainUp .7s ease-out; }
@keyframes gainUp { 0% { opacity: 1; transform: translateY(0) scale(1.15); } 100% { opacity: 0; transform: translateY(-14px) scale(1); } }
#hud-time { display: inline-block; }
#hud-time.beat { animation: beat .35s ease-out; color: var(--bad); }
@keyframes beat { 30% { transform: scale(1.3); } }
.hud-item.center { position: relative; }
#hud-combo { display: inline-block; }
.hud-item.broke #hud-combo { animation: broke .5s ease; }
@keyframes broke { 0%, 60% { color: var(--bad); } 15% { transform: translateX(-5px) rotate(-6deg); } 35% { transform: translateX(4px) rotate(4deg); } }
.hud-item.center { align-items: center; } .hud-item.right { align-items: flex-end; }
.hud-item small { color: var(--muted); font-size: 12px; }
.hud-item b { font-size: 28px; font-variant-numeric: tabular-nums; }
.mult { font-size: 13px; font-weight: 800; color: var(--accent); }
.mult.hot { animation: pop .3s ease; }
.timebar { width: 100%; height: 10px; border-radius: 5px; background: rgba(255,255,255,.12); margin: 8px 0; overflow: hidden; }
#timebar-fill { height: 100%; width: 100%; background: linear-gradient(90deg, #22c55e, #facc15); transform-origin: left; border-radius: 5px; }
#timebar-fill.low { background: var(--bad); animation: blink .5s steps(2) infinite; }
#timebar-fill.gain { box-shadow: 0 0 12px 2px #7ef0a8; }
.coaching #timebar-fill { filter: grayscale(1) brightness(.8); }
@keyframes blink { 50% { opacity: .5; } }
.stage { position: relative; flex: 1; width: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.mode-tag { position: absolute; top: 8px; font-size: 13px; font-weight: 700; color: var(--muted); background: rgba(255,255,255,.08); padding: 4px 12px; border-radius: 12px; }
.mode-tag[hidden] { display: none; }
.rule { font-size: 20px; font-weight: 800; padding: 6px 18px; border-radius: 20px; margin-bottom: 10px; letter-spacing: 2px; }
.rule-ink { background: rgba(255,255,255,.14); }
.rule-ink::before { content: '🎨 '; letter-spacing: 0; }
.rule-word { background: #fff; color: #1b1333; }
.rule-word::before { content: '🔤 '; letter-spacing: 0; }
.rule.flip { animation: flip .45s ease; }
@keyframes flip { 0% { transform: rotateX(90deg) scale(1.3); } 60% { transform: rotateX(0) scale(1.15); } 100% { transform: none; } }
.word-wrap { position: relative; display: flex; align-items: center; justify-content: center; }
.ink-shape { display: none; }
.cb .ink-shape { display: block; position: absolute; right: -46px; top: 50%; transform: translateY(-50%); width: 36px; height: 36px; }
.ink-shape .shape { width: 100%; height: 100%; fill: currentColor; stroke: #fff; stroke-width: 1.5; }
.coach { position: absolute; bottom: 4px; left: 0; right: 0; margin: 0 auto; width: fit-content; max-width: 100%; background: #fff; color: #1b1333;
  font-size: 16px; font-weight: 600; line-height: 1.35; padding: 10px 16px; border-radius: 16px; text-align: center; box-shadow: 0 8px 24px rgba(0,0,0,.4); z-index: 2; }
.coach::after { content: ''; position: absolute; left: 50%; bottom: -8px; margin-left: -8px; border: 8px solid transparent; border-bottom: 0; border-top-color: #fff; }
.coach b { color: #c2410c; }
.coach[hidden] { display: none; }
.coach.nudge { animation: shake .3s; }
/* Combo heat: the word glows hotter as the multiplier climbs. */
#app[data-heat="1"] .word { filter: drop-shadow(0 0 10px rgba(255,210,63,.35)); }
#app[data-heat="2"] .word { filter: drop-shadow(0 0 16px rgba(255,210,63,.55)); }
#app[data-heat="3"] .word { filter: drop-shadow(0 0 22px rgba(255,140,40,.8)); }
#app[data-heat="3"] .mult { color: #ff8a3d; text-shadow: 0 0 8px rgba(255,140,40,.9); }
#app[data-heat="3"]::after { content: ''; position: absolute; inset: 0; pointer-events: none; box-shadow: inset 0 0 60px rgba(255,140,40,.25); animation: glow 1.2s ease-in-out infinite; }
#app.danger::after { content: ''; position: absolute; inset: 0; pointer-events: none; box-shadow: inset 0 0 70px rgba(255,77,79,.45); animation: glow .5s ease-in-out infinite; }
@keyframes glow { 50% { opacity: .4; } }
.word { font-size: clamp(84px, 30vw, 140px); font-weight: 900; line-height: 1.1; text-shadow: 0 6px 0 rgba(0,0,0,.35); }
.word.en { font-size: clamp(48px, 15vw, 76px); }
.word.in { animation: popIn .18s ease-out; }
@keyframes popIn { from { transform: scale(.6); opacity: .35; } to { transform: scale(1); opacity: 1; } }
@keyframes pop { 50% { transform: scale(1.25); } }
.shake { animation: shake .3s; }
@keyframes shake { 20% { transform: translateX(-10px); } 40% { transform: translateX(9px); } 60% { transform: translateX(-6px); } 80% { transform: translateX(4px); } }
#float-layer { position: absolute; inset: 0; pointer-events: none; }
.floater { position: absolute; left: 50%; top: 26%; transform: translateX(-50%); font-weight: 900; font-size: 26px; color: var(--accent);
  text-shadow: 0 2px 0 rgba(0,0,0,.5); animation: floatUp .8s ease-out forwards; white-space: nowrap; }
.floater.bad { color: var(--bad); font-size: 22px; } .floater.big { font-size: 34px; color: #fff; top: 12%; white-space: normal; width: 92%; text-align: center; }
@keyframes floatUp { from { opacity: 1; transform: translate(-50%, 0) scale(1.1); } to { opacity: 0; transform: translate(-50%, -70px) scale(1); } }

.options { width: 100%; display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; padding-bottom: 8px; }
.options.n4 { grid-template-columns: repeat(2, 1fr); }
.opt { position: relative; height: 84px; border: 0; border-radius: 20px; cursor: pointer; font-size: 19px; font-weight: 900;
  box-shadow: inset 0 -6px 0 rgba(0,0,0,.22), 0 6px 14px rgba(0,0,0,.3); transition: transform .06s;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; padding-bottom: 6px; }
.opt .shape { width: 26px; height: 26px; fill: currentColor; opacity: .9; }
.opt .lbl { line-height: 1; }
.cb .opt .shape { width: 32px; height: 32px; opacity: 1; }
.opt.hint { animation: hint 1s ease-in-out infinite; z-index: 1; }
.opt.hint::after { content: '👆'; position: absolute; bottom: -14px; right: 6px; font-size: 30px; animation: bob 1s ease-in-out infinite; }
@keyframes hint { 0%, 100% { box-shadow: inset 0 -6px 0 rgba(0,0,0,.22), 0 0 0 4px #fff; } 50% { box-shadow: inset 0 -6px 0 rgba(0,0,0,.22), 0 0 0 10px rgba(255,255,255,.35); } }
.opt:active, .opt.pressed { transform: scale(.94); }
.opt.right { outline: 4px solid #fff; animation: pop .3s; }
.opt.reveal { outline: 4px dashed #fff; }
.opt kbd { position: absolute; top: 6px; left: 8px; font: 700 11px/1 monospace; opacity: .6; }
@media (hover: none) { .opt kbd { display: none; } }

/* Game over */
.over-title { margin: 5vh 0 0; font-size: 30px; }
.new-best { margin-top: 6px; background: var(--accent); color: #1b1333; font-weight: 900; padding: 4px 14px; border-radius: 14px; animation: pop .6s ease 2; }
.final-score { font-size: 84px; font-weight: 900; color: var(--accent); text-shadow: 0 5px 0 rgba(0,0,0,.35); line-height: 1.1; margin-top: 8px; }
.rank { font-size: 18px; font-weight: 700; }
.next-rank { font-size: 14px; color: var(--muted); margin: 2px 0 8px; }
.daily-result { font-size: 14px; font-weight: 700; color: var(--accent); margin-bottom: 8px; }
.daily-result[hidden] { display: none; }
.grid-line { display: flex; gap: 4px; margin: 0 0 12px; min-height: 12px; }
.grid-line i { width: 12px; height: 12px; border-radius: 3px; } .grid-line .g { background: #22c55e; } .grid-line .y { background: #facc15; } .grid-line .r { background: #ff4d4f; }
.screen.locked button { pointer-events: none; }
.stats { display: flex; gap: 12px; width: 100%; justify-content: center; margin-bottom: 14px; }
.stats div { background: rgba(255,255,255,.08); border-radius: 14px; padding: 8px 14px; display: flex; flex-direction: column; align-items: center; min-width: 86px; }
.stats small { color: var(--muted); font-size: 12px; } .stats b { font-size: 22px; }
.share-text { width: 100%; margin-top: 10px; background: rgba(0,0,0,.25); color: var(--muted); border: 1px solid rgba(255,255,255,.15); border-radius: 10px; padding: 8px; font-size: 12px; resize: none; -webkit-user-select: text; user-select: text; }
.toast { position: absolute; bottom: calc(24px + var(--safe-bottom)); left: 50%; transform: translateX(-50%); background: #fff; color: #1b1333; padding: 10px 18px; border-radius: 20px; font-weight: 700; z-index: 20; }

.pause { position: absolute; inset: 0; background: rgba(10,6,25,.75); display: flex; align-items: center; justify-content: center; z-index: 30; }
.pause[hidden] { display: none; }
.pause-card { text-align: center; width: min(320px, 80%); display: flex; flex-direction: column; align-items: center; }
.modal { position: absolute; inset: 0; z-index: 40; background: rgba(10,6,25,.96); display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal[hidden] { display: none; }
.modal-card { position: relative; width: min(360px, 100%); max-height: 100%; overflow: auto; display: flex; flex-direction: column; align-items: center; }
.card-img { width: 100%; max-height: 52vh; object-fit: contain; border-radius: 18px; box-shadow: 0 12px 40px rgba(0,0,0,.6); }
.modal-actions { width: 100%; display: flex; flex-direction: column; align-items: center; }
.modal-actions .over-row { width: 100%; }
.close-x { position: absolute; top: 8px; right: 8px; margin: 0; min-height: 44px; width: 44px; padding: 0; border-radius: 22px; background: rgba(20,16,42,.9); }

/* Ad stub overlay (rendered by ads.js) */
.ad-stub { position: fixed; inset: 0; z-index: 100; background: rgba(0,0,0,.85); display: flex; align-items: center; justify-content: center; }
.ad-stub-card { width: min(320px, 86vw); background: #222; border: 2px dashed #888; border-radius: 16px; padding: 24px; text-align: center; color: #eee; font-family: system-ui, sans-serif; }
.ad-stub-tag { font: 700 11px/1 monospace; color: #aaa; margin-bottom: 16px; }
.ad-stub-body { font-size: 18px; margin-bottom: 12px; }
.ad-stub-count { font-size: 36px; font-weight: 900; margin-bottom: 14px; }
.ad-stub button { display: block; width: 100%; min-height: 44px; border-radius: 22px; border: 0; font-weight: 800; font-size: 16px; cursor: pointer; margin-top: 8px; }
.ad-stub-close { background: #22c55e; color: #fff; } .ad-stub-skip { background: transparent; color: #aaa; border: 1px solid #555 !important; }
.ad-stub button[hidden] { display: none; }
@media (max-height: 640px) { .opt { height: 70px; } .word { font-size: clamp(64px, 24vw, 110px); } .daily-btn { min-height: 56px; } .logo { margin-top: 1vh; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
  #app::after { display: none; } }
