:root {
  --bg: #0e130d;
  --cream: #f7f0e3;
  --cream-2: #e9dfcc;
  --terra: #d9583b;
  --terra-d: #a83f27;
  --moss: #a9c255;
  --moss-d: #6f8a2a;
  --ink: #1a2016;
  --glass: rgba(20, 26, 17, 0.62);
  --display: 'Dela Gothic One', 'Hiragino Sans', 'Yu Gothic', system-ui, sans-serif;
  --round: 'M PLUS Rounded 1c', 'Hiragino Maru Gothic ProN', 'Hiragino Sans', 'Yu Gothic', system-ui, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; background: var(--bg); color: var(--cream);
  font-family: var(--round); -webkit-font-smoothing: antialiased; overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
body {
  background:
    radial-gradient(120% 80% at 50% 0%, #26321d 0%, rgba(14, 19, 13, 0) 60%),
    radial-gradient(80% 60% at 50% 110%, #2b2016 0%, rgba(14, 19, 13, 0) 70%),
    var(--bg);
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
.hidden { display: none !important; }

#app { position: fixed; inset: 0; display: grid; place-items: center; }

.stage {
  position: relative; width: 100vw; height: 100vh; height: 100dvh;
  overflow: hidden; background: #000; touch-action: none; user-select: none; -webkit-user-select: none;
  isolation: isolate;
}
@media (min-aspect-ratio: 4/5) {
  .stage {
    height: min(96vh, 1120px); height: min(96dvh, 1120px);
    width: calc(min(96vh, 1120px) * 0.75); width: calc(min(96dvh, 1120px) * 0.75);
    border-radius: 26px;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(255, 255, 255, 0.06);
  }
}
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#splat { pointer-events: none; }

/* ---------------------------------------------------------------- HUD */
.hud { position: absolute; inset: 0; pointer-events: none; z-index: 5; }
.timer {
  position: absolute; top: calc(14px + var(--safe-top)); left: 0; right: 0; text-align: center;
  font-family: var(--display); font-size: clamp(42px, 11vmin, 76px); line-height: 1; letter-spacing: 0.01em;
  font-variant-numeric: tabular-nums; color: var(--cream);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.35), 0 6px 24px rgba(0, 0, 0, 0.55);
}
.timer small { font-size: 0.38em; margin-left: 0.12em; opacity: 0.85; }
.hud-best {
  position: absolute; top: calc(clamp(42px, 11vmin, 76px) + 22px + var(--safe-top)); left: 0; right: 0; text-align: center;
  font-size: 13px; font-weight: 800; letter-spacing: 0.08em; opacity: 0.8; text-shadow: 0 1px 6px rgba(0, 0, 0, 0.7);
}
.hud-best b { font-variant-numeric: tabular-nums; }
.hud-pause {
  position: absolute; top: calc(14px + var(--safe-top)); right: 14px; pointer-events: auto;
}

.icon-btn {
  width: 46px; height: 46px; border-radius: 50%; display: inline-grid; place-items: center;
  background: var(--glass); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.14); color: var(--cream); fill: currentColor;
  transition: transform 0.12s ease, background 0.2s;
}
.icon-btn:hover { background: rgba(40, 50, 33, 0.75); }
.icon-btn:active { transform: scale(0.92); }
.icon-btn.lang { font-weight: 800; font-size: 14px; letter-spacing: 0.05em; }
.icon-btn .i-off { display: none; }
.icon-btn.off .i-on { display: none; }
.icon-btn.off .i-off { display: block; }

/* ---------------------------------------------------------------- callouts */
.countdown {
  position: absolute; left: 0; right: 0; top: 58%; text-align: center; z-index: 6; pointer-events: none;
  font-family: var(--display); font-size: clamp(36px, 10vmin, 64px); color: var(--cream);
  text-shadow: 0 4px 24px rgba(0, 0, 0, 0.6); opacity: 0;
}
.countdown.show { animation: pop 0.5s cubic-bezier(.2, 1.6, .4, 1) forwards; }
.countdown.go { color: #d6ec8a; font-size: clamp(54px, 15vmin, 104px); animation: popout 0.7s cubic-bezier(.2, 1.4, .4, 1) forwards; }
@keyframes pop { from { opacity: 0; transform: scale(0.6); } to { opacity: 1; transform: scale(1); } }
@keyframes popout {
  0% { opacity: 0; transform: scale(0.5) rotate(-6deg); }
  25% { opacity: 1; transform: scale(1.12) rotate(2deg); }
  70% { opacity: 1; transform: scale(1) rotate(0); }
  100% { opacity: 0; transform: scale(1.25); }
}

.banner {
  position: absolute; left: 0; right: 0; top: 30%; text-align: center; z-index: 6; pointer-events: none;
  font-family: var(--display); font-size: clamp(30px, 8.5vmin, 58px); color: var(--cream); opacity: 0;
  text-shadow: 0 4px 0 rgba(0, 0, 0, 0.3), 0 8px 30px rgba(0, 0, 0, 0.6);
}
.banner.show { animation: banner 2.2s ease forwards; }
.banner.m-rage { color: #ff8a6a; }
.banner.m-herd { color: #ffd27a; }
.banner.m-legend { color: #e5f59b; }
@keyframes banner {
  0% { opacity: 0; transform: translateY(18px) scale(1.4); letter-spacing: 0.3em; }
  15% { opacity: 1; transform: translateY(0) scale(1); letter-spacing: 0.04em; }
  75% { opacity: 1; transform: translateY(0) scale(1); }
  100% { opacity: 0; transform: translateY(-14px) scale(0.96); }
}

.near {
  position: absolute; left: 50%; top: 40%; z-index: 6; pointer-events: none; opacity: 0;
  font-weight: 800; font-size: 18px; color: #fff2b8; letter-spacing: 0.06em;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.7);
}
.near.show { animation: near 0.8s ease-out forwards; }
@keyframes near {
  0% { opacity: 0; transform: translate(calc(-50% + var(--dx)), 10px) scale(0.8); }
  20% { opacity: 1; transform: translate(calc(-50% + var(--dx)), 0) scale(1.1); }
  100% { opacity: 0; transform: translate(calc(-50% + var(--dx)), -36px) scale(1); }
}

.hint {
  position: absolute; left: 50%; bottom: calc(26px + var(--safe-bot)); transform: translate(-50%, 10px); z-index: 6;
  padding: 10px 18px; border-radius: 999px; background: var(--glass); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  font-weight: 800; font-size: 14px; white-space: nowrap; opacity: 0; transition: opacity 0.4s, transform 0.4s; pointer-events: none;
  max-width: calc(100% - 32px); white-space: normal; text-align: center;
}
.hint.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------------------------------------------------------------- screens */
.screen { position: absolute; inset: 0; z-index: 10; }
.title {
  display: flex; flex-direction: column; justify-content: space-between;
  padding: calc(28px + var(--safe-top)) 22px calc(22px + var(--safe-bot));
  background:
    linear-gradient(180deg, rgba(8, 12, 6, 0.82) 0%, rgba(8, 12, 6, 0.35) 30%, rgba(8, 12, 6, 0) 46%),
    linear-gradient(0deg, rgba(8, 12, 6, 0.88) 0%, rgba(8, 12, 6, 0.5) 24%, rgba(8, 12, 6, 0) 44%);
}
.title.enter .title-top > * , .title.enter .title-bottom > * { animation: rise 0.7s cubic-bezier(.2, .9, .3, 1) both; }
.title.enter .title-top > :nth-child(2) { animation-delay: 0.06s; }
.title.enter .title-top > :nth-child(3) { animation-delay: 0.12s; }
.title.enter .title-bottom > :nth-child(1) { animation-delay: 0.18s; }
.title.enter .title-bottom > :nth-child(2) { animation-delay: 0.22s; }
.title.enter .title-bottom > :nth-child(3) { animation-delay: 0.26s; }
.title.enter .title-bottom > :nth-child(4) { animation-delay: 0.3s; }
@keyframes rise { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }

.title-top { text-align: center; }
.kicker { margin: 0 0 6px; font-size: 12px; font-weight: 800; letter-spacing: 0.32em; color: var(--moss); opacity: 0.95; }
.logo { margin: 0; line-height: 0.95; font-weight: 400; font-family: var(--display); }
.logo span { display: block; }
.logo .l1 {
  font-size: clamp(40px, 12vmin, 80px); color: var(--cream);
  text-shadow: 0 4px 0 var(--terra-d), 0 10px 30px rgba(0, 0, 0, 0.55);
}
.logo .l2 {
  position: relative; display: inline-block; margin-top: 4px;
  font-size: clamp(44px, 13.5vmin, 88px); color: #cfe77b;
  text-shadow: 0 4px 0 #4d6416, 0 10px 30px rgba(0, 0, 0, 0.55);
}
.logo .l2::after { /* a drip */
  content: ''; position: absolute; right: 18%; bottom: -0.32em; width: 0.16em; height: 0.42em;
  background: #cfe77b; border-radius: 0 0 0.1em 0.1em; box-shadow: 0 3px 0 #4d6416;
  animation: drip 3.2s ease-in-out infinite; transform-origin: top;
}
@keyframes drip { 0%, 100% { transform: scaleY(0.55); } 50% { transform: scaleY(1.05); } }
.logo .l3 { margin-top: 10px; font-size: clamp(15px, 4.2vmin, 24px); letter-spacing: 0.3em; color: var(--cream-2); font-family: var(--round); font-weight: 800; }
.tagline { margin: 14px 0 0; font-weight: 800; font-size: clamp(14px, 3.6vmin, 18px); text-shadow: 0 2px 10px rgba(0, 0, 0, 0.8); }

.title-bottom { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.btn-primary {
  min-width: 220px; padding: 16px 34px; border-radius: 999px; font-weight: 800; font-size: 20px; letter-spacing: 0.08em;
  background: linear-gradient(180deg, #f39a6a 0%, var(--terra) 55%, #c24a2f 100%); color: #fff8ef;
  box-shadow: 0 6px 0 var(--terra-d), 0 14px 30px rgba(0, 0, 0, 0.45), inset 0 2px 0 rgba(255, 255, 255, 0.35);
  transition: transform 0.1s, box-shadow 0.1s, filter 0.2s;
}
.btn-primary:hover { filter: brightness(1.06); }
.btn-primary:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--terra-d), 0 6px 16px rgba(0, 0, 0, 0.4), inset 0 2px 0 rgba(255, 255, 255, 0.35); }
.btn-primary:focus-visible, .btn-ghost:focus-visible, .btn-x:focus-visible, .icon-btn:focus-visible { outline: 3px solid #fff2b8; outline-offset: 3px; }
.btn-start { font-size: 22px; padding: 18px 44px; animation: breathe 2.4s ease-in-out infinite; }
@keyframes breathe { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.035); } }
.best-line { margin: 4px 0 0; font-weight: 800; font-size: 14px; letter-spacing: 0.06em; opacity: 0.9; }
.best-line b { font-family: var(--display); font-weight: 400; font-size: 18px; margin-left: 4px; }
.howto { margin: 0; font-size: 13px; opacity: 0.8; text-align: center; }
.icon-row { display: flex; gap: 12px; margin-top: 6px; }

.btn-ghost {
  white-space: nowrap; padding: 12px 20px; border-radius: 999px; font-weight: 800; font-size: 15px;
  background: rgba(255, 255, 255, 0.08); border: 1px solid rgba(255, 255, 255, 0.2);
  transition: background 0.2s, transform 0.1s;
}
.btn-ghost:hover { background: rgba(255, 255, 255, 0.14); }
.btn-ghost:active { transform: scale(0.96); }
.btn-x {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px; white-space: nowrap;
  padding: 13px 24px; border-radius: 999px; font-weight: 800; font-size: 16px;
  background: #0b0b0b; color: #fff; fill: #fff; border: 1px solid rgba(255, 255, 255, 0.22);
  transition: transform 0.1s, background 0.2s;
}
.btn-x:hover { background: #1b1b1b; }
.btn-x:active { transform: scale(0.97); }

/* game over */
.over {
  display: flex; flex-direction: column; align-items: center; justify-content: space-between;
  padding: calc(22px + var(--safe-top)) 12px calc(12px + var(--safe-bot));
  background:
    linear-gradient(180deg, rgba(8, 12, 6, 0.55) 0%, rgba(8, 12, 6, 0) 26%),
    linear-gradient(0deg, rgba(8, 12, 6, 0.75) 0%, rgba(8, 12, 6, 0.2) 45%, rgba(8, 12, 6, 0) 60%);
}
.over-head { text-align: center; }
.over.enter .over-head { animation: drop 0.6s cubic-bezier(.2, 1.4, .4, 1) both; }
@keyframes drop { from { opacity: 0; transform: translateY(-20px) scale(1.2); } to { opacity: 1; transform: none; } }
.over-kicker { margin: 0; font-family: var(--display); font-size: clamp(40px, 11vmin, 64px); line-height: 1; color: #cfe77b; text-shadow: 0 4px 0 #4d6416, 0 10px 30px rgba(0, 0, 0, 0.6); }
.over-sub { margin: 6px 0 0; font-size: 14px; font-weight: 800; text-shadow: 0 2px 10px rgba(0, 0, 0, 0.9); }
.over-card {
  width: min(440px, 100%); text-align: center; padding: 14px 14px 12px; border-radius: 24px;
  background: rgba(16, 21, 13, 0.74); backdrop-filter: blur(12px) saturate(1.1); -webkit-backdrop-filter: blur(12px) saturate(1.1);
  border: 1px solid rgba(255, 255, 255, 0.12); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
.over.enter .over-card { animation: sheet 0.55s 0.1s cubic-bezier(.2, .9, .3, 1.05) both; }
@keyframes sheet { from { opacity: 0; transform: translateY(40px) scale(0.97); } to { opacity: 1; transform: none; } }
.new-record {
  display: inline-block; margin: 0 0 6px; padding: 4px 14px; border-radius: 999px; font-weight: 800; font-size: 13px; color: #3a2a00;
  background: linear-gradient(90deg, #ffd66b, #fff3b0, #ffd66b); background-size: 200% 100%; animation: shine 1.6s linear infinite;
}
@keyframes shine { from { background-position: 0 0; } to { background-position: -200% 0; } }
.over-main { display: flex; align-items: center; justify-content: center; gap: 14px; flex-wrap: wrap; }
.over-score { text-align: center; }
.over-side { text-align: left; max-width: 190px; }
.over-label { margin: 0; font-size: 11px; font-weight: 800; letter-spacing: 0.2em; opacity: 0.7; }
.over-time { font-family: var(--display); font-size: clamp(46px, 12vmin, 66px); line-height: 1.05; font-variant-numeric: tabular-nums; }
.over-time small { font-size: 0.36em; margin-left: 0.1em; }
.over-rank { margin: 0; font-weight: 800; font-size: 18px; color: #ff9b78; line-height: 1.3; }
.over-next { margin: 4px 0 0; font-size: 11px; opacity: 0.72; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 10px 0 12px; }
.stats div { padding: 6px 4px; border-radius: 12px; background: rgba(255, 255, 255, 0.06); display: flex; flex-direction: column; gap: 1px; }
.stats span { font-size: 10px; font-weight: 800; opacity: 0.7; }
.stats b { font-family: var(--display); font-weight: 400; font-size: 18px; font-variant-numeric: tabular-nums; }
.over-actions { display: flex; flex-direction: column; gap: 8px; align-items: stretch; }
.over-actions .btn-primary { min-width: 0; padding: 14px; }
.row3 { display: grid; grid-template-columns: 1.3fr 1fr 1fr; gap: 8px; }
.row3 button { padding: 11px 6px; font-size: 13px; gap: 6px; }
.over-tip { margin: 10px 0 0; font-size: 11px; opacity: 0.72; }

/* pause / modal */
.pause, .modal { display: grid; place-items: center; background: rgba(6, 9, 5, 0.55); padding: 20px; }
.pause-card, .modal-card {
  width: min(380px, 100%); padding: 22px; border-radius: 24px; text-align: center;
  background: rgba(16, 21, 13, 0.86); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(255, 255, 255, 0.12); display: flex; flex-direction: column; gap: 12px;
  animation: sheet 0.35s cubic-bezier(.2, .9, .3, 1.05) both;
}
.pause-card h2, .modal-card h2 { margin: 0 0 4px; font-family: var(--display); font-weight: 400; font-size: 26px; }
.modal-card { text-align: left; max-height: 86%; overflow: auto; }
.modal-card h2 { text-align: center; }
.modal-card p { margin: 0 0 12px; font-size: 13px; line-height: 1.7; opacity: 0.92; }
.modal-card a { color: #cfe77b; }
.toggle { display: flex; align-items: center; justify-content: space-between; padding: 10px 4px; font-weight: 800; cursor: pointer; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle i { width: 50px; height: 28px; border-radius: 999px; background: rgba(255, 255, 255, 0.18); position: relative; transition: background 0.2s; }
.toggle i::after { content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform 0.2s; }
.toggle input:checked + i { background: var(--moss-d); }
.toggle input:checked + i::after { transform: translateX(22px); }
.toggle input:focus-visible + i { outline: 3px solid #fff2b8; outline-offset: 2px; }
.lang-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 4px; font-weight: 800; }
.seg { display: flex; background: rgba(255, 255, 255, 0.1); border-radius: 999px; padding: 3px; }
.seg button { padding: 7px 12px; border-radius: 999px; font-weight: 800; font-size: 13px; }
.seg button.on { background: var(--cream); color: var(--ink); }

/* misc */
.toast {
  position: absolute; left: 50%; top: 18%; transform: translateX(-50%); z-index: 30; padding: 10px 16px; border-radius: 12px;
  background: var(--glass); font-weight: 800; opacity: 0; pointer-events: none;
}
.toast.show { animation: toast 2s ease forwards; }
@keyframes toast { 10%, 80% { opacity: 1; } 100% { opacity: 0; } }
.fps { position: absolute; left: 8px; bottom: 8px; z-index: 40; font: 12px ui-monospace, monospace; background: rgba(0, 0, 0, 0.5); padding: 2px 6px; border-radius: 6px; }

.loading {
  position: absolute; inset: 0; z-index: 50; display: grid; place-content: center; justify-items: center; gap: 14px;
  background: var(--bg); transition: opacity 0.6s ease, visibility 0.6s;
}
.loading p { margin: 0; font-weight: 800; opacity: 0.85; padding: 0 24px; text-align: center; }
.loading.done { opacity: 0; visibility: hidden; pointer-events: none; }
.loading.error .spinner { display: none; }
.spinner { width: 44px; height: 44px; border-radius: 50%; border: 4px solid rgba(255, 255, 255, 0.15); border-top-color: var(--moss); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .btn-start, .logo .l2::after { animation: none; }
}
@media (max-height: 640px) {
  .over-card { padding: 10px; }
  .stats { margin: 6px 0 8px; }
  .over-tip { display: none; }
  .over-sub { display: none; }
}

/* English title is longer: keep "SPIT DODGE" on one line */
html[lang="en"] .logo .l1 { font-size: clamp(34px, 10vmin, 66px); }
html[lang="en"] .logo .l2 { font-size: clamp(30px, 9.2vmin, 60px); white-space: nowrap; }
html[lang="en"] .logo .l3 { letter-spacing: 0.4em; text-transform: uppercase; font-size: clamp(12px, 3.2vmin, 17px); }
