:root {
  color-scheme: dark;
  --paper: #f3f8ed;
  --muted: #93a79f;
  --mint: #85ffd1;
  --cyan: #55dfff;
  --amber: #ffc963;
  --coral: #ff7a68;
  --night: #06111b;
  --panel: rgba(7, 20, 30, 0.91);
  --line: rgba(186, 244, 224, 0.17);
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: #030a11;
}

body {
  position: fixed;
  inset: 0;
  color: var(--paper);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

button,
a,
select {
  color: inherit;
  font: inherit;
  -webkit-tap-highlight-color: transparent;
}

button,
a { touch-action: manipulation; }

button:focus-visible,
a:focus-visible,
select:focus-visible {
  outline: 2px solid var(--mint);
  outline-offset: 3px;
}

.game-root {
  position: fixed;
  inset: 0;
  min-width: 280px;
  min-height: 320px;
  overflow: hidden;
  isolation: isolate;
  background: #07131f;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-user-drag: none;
}

#gameCanvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.grain {
  position: absolute;
  z-index: 1;
  inset: 0;
  opacity: .14;
  pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 160 160' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.18'/%3E%3C/svg%3E");
  mix-blend-mode: soft-light;
}

.top-bar {
  position: absolute;
  z-index: 20;
  top: max(14px, env(safe-area-inset-top));
  left: max(17px, env(safe-area-inset-left));
  right: max(17px, env(safe-area-inset-right));
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;
}

.logo,
.top-actions,
.top-actions > * { pointer-events: auto; }

.logo {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--paper);
  text-decoration: none;
  font-size: 12px;
  font-weight: 950;
  letter-spacing: .2em;
}

.logo-hook {
  display: grid;
  place-items: center;
  width: 31px;
  height: 31px;
  border: 1px solid rgba(133, 255, 209, .48);
  border-radius: 50% 50% 50% 13%;
  color: var(--mint);
  background: rgba(8, 26, 33, .74);
  font-size: 20px;
  line-height: 1;
  transform: rotate(-18deg);
}

.top-actions { display: flex; align-items: center; gap: 7px; }

.language-control {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 9px 0 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(5, 17, 27, .82);
  font-size: 8px;
  font-weight: 800;
  letter-spacing: .13em;
}

.language-control > span { color: #7f9d96; }
.language-control select { max-width: 108px; border: 0; outline: 0; color: #dff9ed; background: transparent; font-size: 10px; font-weight: 800; }
.language-control option { background: #0a1b26; }

.icon-button,
.round-button,
.hud-actions button {
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  cursor: pointer;
  background: rgba(5, 17, 27, .82);
}

.icon-button { width: 40px; height: 40px; border-radius: 50%; color: #b8d2cb; }
.icon-button.is-muted { color: #677c78; }

.screen {
  position: absolute;
  z-index: 10;
  inset: 0;
  display: none;
}

.screen.is-active { display: flex; animation: screen-in .35s cubic-bezier(.2,.8,.2,1) both; }

@keyframes screen-in {
  from { opacity: 0; transform: scale(1.012); }
}

.menu-screen {
  align-items: center;
  justify-content: space-between;
  gap: clamp(24px, 7vw, 110px);
  padding: clamp(76px, 10vh, 124px) clamp(28px, 8vw, 130px) clamp(40px, 8vh, 90px);
  background: linear-gradient(90deg, rgba(3, 11, 17, .93) 0%, rgba(3, 11, 17, .68) 48%, rgba(3, 11, 17, .2) 100%);
}

.menu-copy { position: relative; width: min(58%, 690px); }

.menu-stamp {
  position: absolute;
  top: 20px;
  right: 22px;
  color: var(--coral);
  font: 900 8px/1 monospace;
  letter-spacing: .12em;
}

.eyebrow {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 0 0 10px;
  color: var(--mint);
  font-size: clamp(9px, 1vw, 12px);
  letter-spacing: .2em;
  text-transform: uppercase;
}

.eyebrow > span { width: 25px; height: 1px; background: currentColor; }

.menu-copy h1 {
  margin: 0;
  font-size: clamp(58px, 8.8vw, 132px);
  line-height: .78;
  letter-spacing: -.075em;
  font-weight: 1000;
}

.menu-copy h1 span,
.menu-copy h1 em { display: block; }

.menu-copy h1 em {
  margin-left: .08em;
  color: transparent;
  font-style: normal;
  -webkit-text-stroke: 1.5px rgba(133, 255, 209, .78);
}

.menu-description {
  width: min(580px, 100%);
  margin: clamp(18px, 3.5vh, 34px) 0 25px;
  color: #a2b8b1;
  font-size: clamp(12px, 1.25vw, 16px);
  line-height: 1.8;
}

.menu-actions,
.dialog-actions { display: flex; align-items: stretch; gap: 10px; }

.primary-button,
.secondary-button {
  min-height: 56px;
  border-radius: 13px;
  cursor: pointer;
  font-weight: 900;
  letter-spacing: .08em;
  transition: transform .16s ease, border-color .16s ease;
}

.primary-button {
  min-width: 210px;
  padding: 10px 24px;
  border: 1px solid #b2ffe2;
  color: #061713;
  background: linear-gradient(120deg, #b4ffe4, #70ebbd 72%, #72dfee);
}

.primary-button b,
.primary-button small { display: block; }
.primary-button small { margin-top: 3px; opacity: .58; font-size: 8px; }

.secondary-button {
  min-width: 145px;
  padding: 0 18px;
  border: 1px solid rgba(192, 237, 221, .2);
  color: #d9eee7;
  background: rgba(8, 24, 34, .82);
}

.primary-button:active,
.secondary-button:active { transform: scale(.97); }
.primary-button:disabled,
.secondary-button:disabled { cursor: wait; opacity: .55; transform: none; }

.how-card {
  width: min(34%, 370px);
  align-self: flex-end;
  padding: clamp(17px, 2.2vw, 27px);
  border: 1px solid rgba(178, 237, 215, .16);
  border-radius: 20px;
  background: rgba(5, 17, 27, .86);
}

.how-heading { display: flex; justify-content: space-between; color: #9db2ac; font-size: 9px; letter-spacing: .14em; }
.how-heading b { color: var(--mint); font-size: 8px; }
.how-card ol { display: grid; gap: 5px; margin: 19px 0 13px; padding: 0; list-style: none; }
.how-card li { display: grid; grid-template-columns: 38px 1fr; align-items: center; min-height: 55px; border-top: 1px solid rgba(185, 234, 218, .1); }
.how-card li > i { color: #48645d; font: normal 700 11px/1 monospace; }
.how-card li div { display: grid; gap: 4px; }
.how-card li b { color: #e5f8f1; font-size: 11px; letter-spacing: .13em; }
.how-card li span { color: #7f9891; font-size: 10px; }
.how-card > p { margin: 12px 0 0; color: #526f67; font-size: 9px; }

.dialog-card h2 { margin: 0; font-size: clamp(33px, 5vw, 68px); line-height: .9; letter-spacing: -.06em; }

.hud {
  position: absolute;
  z-index: 8;
  top: 0;
  left: 0;
  right: 0;
  display: none;
  align-items: flex-start;
  gap: 10px;
  min-height: 78px;
  padding: max(13px, env(safe-area-inset-top)) max(17px, env(safe-area-inset-right)) 12px max(17px, env(safe-area-inset-left));
  background: linear-gradient(to bottom, rgba(3, 12, 18, .88), transparent);
  pointer-events: none;
}

body[data-screen="playing"] .hud { display: flex; }
.hud > * { pointer-events: none; }
.hud-actions,
.hud-actions button { pointer-events: auto; }

.score-block {
  display: grid;
  gap: 2px;
  min-width: 118px;
}

.score-block > span { color: var(--mint); font: 800 8px/1.1 monospace; letter-spacing: .16em; }
.score-block > b { font: 900 clamp(18px, 2.5vw, 28px)/1 monospace; }
.score-block small { color: #68847c; font-size: 7px; letter-spacing: .11em; }
.score-block small b { color: #aec1bb; font: 800 8px/1 monospace; }

.hud-stats {
  display: flex;
  align-items: center;
  gap: clamp(12px, 2.5vw, 32px);
  margin-left: auto;
}
.hud-stats > span { display: grid; gap: 2px; }
.hud-stats i { color: var(--amber); font-style: normal; }
.hud-stats small { color: #68847c; font-size: 7px; letter-spacing: .13em; }
.hud-stats b { font: 800 11px/1.2 monospace; }
.coin-stat b { display: flex; align-items: center; gap: 5px; }

.gas-block {
  --gas-safety: 100%;
  position: absolute;
  top: 50vh;
  right: max(15px, env(safe-area-inset-right));
  display: grid;
  justify-items: center;
  gap: 7px;
  width: 58px;
  min-height: 178px;
  padding: 10px 8px;
  transform: translateY(-50%);
  border: 1px solid rgba(186, 244, 224, .2);
  border-radius: 12px;
  background: rgba(5, 17, 27, .76);
}

.gas-heading small { color: #8aa49d; font-size: 7px; font-weight: 900; letter-spacing: .1em; }
.gas-track { position: relative; width: 9px; height: min(27vh, 210px); min-height: 105px; overflow: hidden; border-radius: 99px; background: rgba(194, 238, 220, .15); }
.gas-track i { position: absolute; right: 0; bottom: 0; left: 0; height: var(--gas-safety); background: linear-gradient(to top, var(--coral), var(--amber) 45%, var(--mint)); transition: height .18s linear, width .18s linear; }
.gas-block > b { color: #d8ede6; font: 800 9px/1 monospace; white-space: nowrap; }
.gas-block[data-safety="warning"] { border-color: rgba(255, 201, 99, .64); }
.gas-block[data-safety="danger"] { border-color: rgba(255, 122, 104, .8); background: rgba(47, 14, 17, .84); }
.gas-block[data-safety="danger"] > b,
.gas-block[data-safety="danger"] .gas-heading small { color: var(--coral); }

.hud-actions { display: flex; gap: 8px; }
.hud-actions button { width: 42px; height: 42px; border-radius: 11px; color: #abc2bb; }

.touch-hint {
  position: absolute;
  z-index: 7;
  left: max(18px, env(safe-area-inset-left));
  bottom: max(22px, calc(env(safe-area-inset-bottom) + 13px));
  display: none;
  grid-template-columns: 42px auto;
  grid-template-rows: auto auto;
  column-gap: 10px;
  width: min(300px, calc(50vw - max(18px, env(safe-area-inset-left)) - 24px));
  min-width: 0;
  padding: 10px 17px 10px 11px;
  transform: none;
  border: 1px solid rgba(175, 239, 217, .13);
  border-radius: 999px;
  color: #cae3da;
  background: rgba(5, 17, 27, .78);
  transition: border-color .16s ease, background .16s ease, transform .16s ease;
  pointer-events: none;
}

body[data-screen="playing"] .touch-hint { display: grid; }
.touch-ring { grid-row: 1 / 3; display: grid; place-items: center; width: 38px; height: 38px; border: 1px solid rgba(133,255,209,.46); border-radius: 50%; }
.touch-ring i { width: 13px; height: 13px; border-radius: 50%; background: var(--mint); opacity: .75; }
.touch-hint b { align-self: end; font-size: 11px; letter-spacing: .11em; }
.touch-hint small { color: #8da69e; font-size: 9px; letter-spacing: .045em; }
.game-root.is-holding .touch-ring { animation: touch-pulse .65s ease-in-out infinite alternate; }
.game-root[data-control-state="release"] .touch-hint { border-color: rgba(133,255,209,.72); background: rgba(12, 48, 42, .88); transform: translateY(-3px); }
.game-root[data-control-state="release"] .touch-ring { border-color: var(--mint); box-shadow: 0 0 0 7px rgba(133,255,209,.1), 0 0 22px rgba(133,255,209,.34); }
.game-root[data-control-state="retry"] .touch-hint { border-color: rgba(255,122,104,.55); }
.game-root[data-control-state="retry"] .touch-ring { border-color: var(--coral); }
.game-root[data-control-state="retry"] .touch-ring i { background: var(--coral); }

@keyframes touch-pulse { to { transform: scale(.88); border-color: var(--mint); } }

.dialog-screen {
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(2, 9, 14, .78);
}

.dialog-card {
  width: min(470px, 94%);
  max-height: calc(100dvh - 48px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: clamp(28px, 5vw, 48px);
  text-align: center;
  border: 1px solid rgba(182, 238, 218, .18);
  border-radius: 23px;
  background: linear-gradient(145deg, rgba(12, 34, 42, .98), rgba(5, 17, 27, .98));
}

.dialog-card .eyebrow { justify-content: center; margin-top: 13px; }
.dialog-icon { display: grid; place-items: center; width: 62px; height: 62px; margin: auto; border: 1px solid rgba(133,255,209,.4); border-radius: 50%; color: var(--mint); font: 900 19px/1 monospace; }
.dialog-actions { justify-content: center; margin-top: 27px; }
.slim { min-width: 145px; }
.result-card { width: min(560px, 94%); }
.result-score { display: inline-grid; min-width: 154px; gap: 5px; margin: 0 auto 6px; padding: 12px 20px; border: 1px solid rgba(133,255,209,.4); border-radius: 16px; background: rgba(133,255,209,.08); }
.result-score span { color: var(--mint); font-size: 8px; font-weight: 900; letter-spacing: .16em; }
.result-score b { font: 1000 34px/1 monospace; }
.result-name { margin: 10px 0 19px; color: #91a9a1; }
.result-stats { display: grid; grid-template-columns: 1fr 1fr; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.result-stats div { display: grid; gap: 6px; padding: 15px 8px; }
.result-stats div:nth-child(even) { border-left: 1px solid var(--line); }
.result-stats div:nth-child(n + 3) { border-top: 1px solid var(--line); }
.result-stats span { color: #6d8980; font-size: 8px; letter-spacing: .12em; }
.result-stats b { font: 800 14px/1 monospace; }
.record-text { min-height: 12px; margin: 11px 0 -5px; color: var(--amber); font-size: 9px; font-weight: 900; letter-spacing: .16em; opacity: 0; }
.record-text.is-visible { opacity: 1; }

.toast {
  position: absolute;
  z-index: 30;
  left: 50%;
  bottom: 16%;
  padding: 9px 15px;
  transform: translate(-50%, 12px);
  opacity: 0;
  border: 1px solid rgba(210, 244, 231, .17);
  border-radius: 999px;
  color: #dff6ed;
  background: rgba(4, 15, 23, .92);
  font-size: 10px;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
}

.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

body[data-screen="playing"] .top-bar,
body[data-screen="paused"] .top-bar,
body[data-screen="gameOver"] .top-bar { display: none; }

body[data-screen="playing"] .grain { display: none; }

@media (orientation: portrait) {
  .menu-screen {
    align-items: flex-start;
    justify-content: flex-start;
    flex-direction: column;
    gap: clamp(18px, 4vh, 38px);
    overflow-x: hidden;
    overflow-y: auto;
    padding: max(80px, calc(env(safe-area-inset-top) + 67px)) clamp(23px, 7vw, 60px) max(28px, env(safe-area-inset-bottom));
    background: linear-gradient(to bottom, rgba(3,11,17,.87), rgba(3,11,17,.52));
  }

  .menu-copy { width: calc(100% - 36px); margin-inline: auto; }
  .menu-copy h1 { font-size: clamp(61px, 18vw, 124px); }
  .menu-description { line-height: 1.58; }
  .how-card { width: calc(100% - 18px); max-width: 620px; align-self: auto; margin-inline: auto; }
  .how-card ol { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .how-card li { grid-template-columns: 1fr; align-content: start; gap: 8px; padding: 12px 7px; }
  .how-card li span { line-height: 1.35; }
  .hud { gap: 7px; min-height: 112px; }
  .score-block { min-width: min(94px, 27vw); }
  .score-block > b { font-size: clamp(16px, 4.5vw, 22px); }
  .hud-stats { gap: 10px; }
  .hud-stats > span { min-width: 42px; }
  .hud-actions { gap: 6px; }
  .hud-actions button { width: 44px; height: 44px; }
  .gas-block {
    top: max(84px, calc(env(safe-area-inset-top) + 71px));
    right: max(14px, env(safe-area-inset-right));
    left: max(14px, env(safe-area-inset-left));
    grid-template-columns: auto minmax(60px, 1fr) auto;
    align-items: center;
    justify-items: stretch;
    width: auto;
    min-height: 0;
    padding: 7px 10px;
    transform: none;
  }
  .gas-track { width: 100%; height: 8px; min-height: 0; }
  .gas-track i { top: 0; width: var(--gas-safety); height: 100%; }
  .gas-block > b { text-align: right; }
  .touch-hint {
    top: max(124px, calc(env(safe-area-inset-top) + 111px));
    bottom: auto;
    width: min(360px, calc(100vw - 26px));
  }
}

@media (orientation: landscape) and (max-height: 650px) {
  .top-bar { top: max(8px, env(safe-area-inset-top)); }
  .menu-screen { padding-top: max(52px, calc(env(safe-area-inset-top) + 43px)); padding-bottom: max(13px, env(safe-area-inset-bottom)); }
  .menu-copy h1 { font-size: clamp(54px, 16vh, 91px); }
  .menu-description { margin: 12px 0 15px; line-height: 1.45; }
  .how-card { padding: 14px; }
  .how-card ol { margin: 10px 0 5px; }
  .how-card li { min-height: 42px; }
  .how-card > p { margin-top: 5px; }
  .hud { min-height: 60px; padding-top: max(8px, env(safe-area-inset-top)); }
  .touch-hint { left: max(18px, env(safe-area-inset-left)); right: auto; bottom: max(11px, env(safe-area-inset-bottom)); transform: none; }
  .dialog-screen { align-items: flex-start; overflow-y: auto; padding: max(42px, calc(env(safe-area-inset-top) + 34px)) max(18px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left)); }
  .dialog-card { width: min(540px, 94%); margin: auto; padding: 18px 25px; }
  .dialog-card h2 { font-size: 28px; }
  .dialog-card .eyebrow { margin: 6px 0; font-size: 8px; }
  .dialog-icon { width: 44px; height: 44px; font-size: 15px; }
  .result-score { padding: 8px 16px; }
  .result-score b { font-size: 25px; }
  .result-name { margin: 4px 0 9px; }
  .result-stats div { padding: 8px 6px; }
  .record-text { margin: 6px 0 -3px; }
  .dialog-actions { margin-top: 12px; }
  .dialog-actions .primary-button,
  .dialog-actions .secondary-button { min-height: 44px; }
}

@media (max-width: 560px) {
  .language-control > span { display: none; }
  .logo > span:last-child { display: none; }
  .menu-copy { width: calc(100% - 28px); padding-inline: 20px; }
  .menu-copy h1 { max-width: 100%; font-size: clamp(50px, 14.5vw, 60px); }
  .menu-actions { width: 100%; }
  .primary-button { flex: 1; min-width: 0; }
  .secondary-button { min-width: 115px; padding-inline: 12px; font-size: 10px; }
  .how-card { width: calc(100% - 28px); min-width: 0; padding: 14px; }
  .how-heading { min-width: 0; gap: 8px; font-size: 8px; }
  .how-heading > span { min-width: 0; overflow-wrap: anywhere; }
  .how-heading b { flex: 0 0 auto; white-space: nowrap; }
  .time-stat { display: none !important; }
  .hud-stats { margin-left: auto; }
  .hud-actions { gap: 5px; }
}

@media (max-width: 360px) {
  .hud { padding-inline: max(9px, env(safe-area-inset-left)); gap: 6px; }
  .score-block { min-width: 76px; }
  .score-block > b { font-size: 18px; }
  .score-block small { font-size: 6px; }
  .hud-stats { gap: 8px; }
  .hud-stats > span { min-width: 34px; }
  .gas-block { right: max(9px, env(safe-area-inset-right)); left: max(9px, env(safe-area-inset-left)); }
  .dialog-actions { flex-direction: column; }
  .dialog-actions .primary-button,
  .dialog-actions .secondary-button { width: 100%; }
}

@media (orientation: landscape) and (max-width: 480px) {
  .touch-hint small { display: none; }
  .touch-hint { grid-template-rows: auto; padding-block: 8px; }
  .touch-ring { grid-row: 1; }
}

@media (hover: none), (pointer: coarse) {
  .language-control select { font-size: 16px; }
}

.game-root.performance-mode .grain { display: none; }
.game-root.performance-mode .screen,
.game-root.performance-mode .how-card,
.game-root.performance-mode .language-control { backdrop-filter: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
  }
}
