:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Hiragino Sans", sans-serif;
  background: #071420;
  color: #f7fbff;
}

* { box-sizing: border-box; }

body {
  min-height: 100dvh;
  margin: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: radial-gradient(circle at 50% 0%, #16314a 0, #071420 62%);
}

.game-shell {
  position: relative;
  width: min(100vw, 1280px, calc(100dvh * 16 / 9));
  aspect-ratio: 16 / 9;
  container-type: size;
  overflow: hidden;
  background: #11263a;
  box-shadow: 0 30px 80px #0009;
}

canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.touch-controls { display: none; }
.mobile-start-tip { display: none; }

.hud {
  position: absolute;
  z-index: 3;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  padding: clamp(9px, 3cqh, 22px) clamp(12px, 3cqw, 28px);
  pointer-events: none;
  text-shadow: 0 2px 5px #000a;
  transition: opacity .15s;
}
.hud.hidden { visibility: hidden; opacity: 0; }

.hud div { display: grid; gap: 1px; }
.hud div:nth-child(2) { text-align: center; }
.hud .timer { text-align: right; }
.hud span, .eyebrow { color: #a8d5ee; font-size: clamp(9px, min(1.7cqh, 1cqw), 11px); font-weight: 800; letter-spacing: .16em; }
.hud strong { font-size: clamp(17px, min(4cqh, 2.2cqw), 24px); letter-spacing: .04em; }
.hud .timer strong { color: #ffe36e; }

.overlay {
  position: absolute;
  z-index: 5;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  padding: clamp(14px, 7cqh, 70px) clamp(12px, 3cqw, 24px) clamp(12px, 3cqh, 24px);
  text-align: center;
  background: linear-gradient(#071420aa, #071420e8);
  transition: opacity .2s;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.overlay.hidden { opacity: 0; pointer-events: none; }

.language-switcher {
  position: absolute;
  top: max(8px, env(safe-area-inset-top));
  right: max(8px, env(safe-area-inset-right));
  display: flex;
  gap: 3px;
  padding: 3px;
  border: 1px solid #9ac1d555;
  border-radius: 999px;
  background: #061622cc;
}

.language-switcher button {
  min-height: 0;
  margin: 0;
  padding: 5px 9px;
  border-radius: 999px;
  color: #b9cad4;
  background: transparent;
  box-shadow: none;
  font-size: clamp(9px, min(2.1cqh, 1.2cqw), 12px);
}
.language-switcher button[aria-pressed="true"] { color: #112017; background: #9fffd0; }
.language-switcher button:hover { transform: none; }
.language-switcher button:active { transform: none; box-shadow: none; }

h1, h2, p { margin: 0; }
h1, h2 { font-weight: 950; letter-spacing: -.06em; line-height: .82; }
h1 { font-size: clamp(38px, min(14cqh, 9cqw), 120px); }
h2 { font-size: clamp(34px, min(12cqh, 8cqw), 96px); }
h1 em { color: #ffcf47; font-style: normal; }
.lead { margin-top: clamp(10px, 3.5cqh, 25px); font-size: clamp(12px, min(3cqh, 2cqw), 22px); line-height: 1.55; }
.controls { margin-top: clamp(10px, 4cqh, 30px); display: flex; align-items: center; gap: 7px; color: #c9ddec; font-size: clamp(12px, min(2.5cqh, 1.5cqw), 16px); font-weight: 700; }
.controls span { width: 25px; }
kbd { min-width: 26px; padding: 4px 6px; border: 1px solid #91b6cf; border-bottom-width: 3px; border-radius: 4px; color: #fff; font: inherit; }
.tip { max-width: 450px; margin: clamp(8px, 3cqh, 20px) auto 0; color: #b9cad4; font-size: clamp(11px, min(2.2cqh, 1.35cqw), 14px); line-height: 1.5; }

button {
  margin-top: clamp(12px, 4cqh, 30px);
  padding: clamp(9px, 2cqh, 15px) clamp(18px, 3cqw, 25px);
  border: 0;
  border-radius: 999px;
  color: #1c210c;
  background: #e8fa62;
  font: 900 clamp(14px, min(2.5cqh, 1.5cqw), 17px) inherit;
  cursor: pointer;
  box-shadow: 0 5px 0 #8da33a;
}
button:hover { filter: brightness(1.08); transform: translateY(-1px); }
button:active { transform: translateY(3px); box-shadow: 0 2px 0 #8da33a; }

@media (hover: none), (pointer: coarse), (max-aspect-ratio: 1/1) {
  .keyboard-controls, .keyboard-tip { display: none; }
  .mobile-start-tip { display: block; }
}

@media (hover: none), (pointer: coarse), (max-aspect-ratio: 1/1) {
  .touch-controls:not(.hidden) {
    position: absolute;
    z-index: 4;
    left: max(8px, env(safe-area-inset-left));
    right: max(8px, env(safe-area-inset-right));
    bottom: max(8px, env(safe-area-inset-bottom));
    display: grid;
    grid-template-columns: minmax(88px, 1fr) auto minmax(88px, 1fr);
    align-items: end;
    gap: clamp(6px, 1.5cqw, 14px);
    pointer-events: none;
  }

  .touch-button {
    min-height: clamp(42px, 15cqh, 64px);
    margin: 0;
    padding: 7px clamp(10px, 2.5cqw, 24px);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    border: 1px solid #bfeeff99;
    border-radius: 14px;
    color: #f7fbff;
    background: #08243bd9;
    box-shadow: 0 3px 0 #00131fbb;
    font: 900 clamp(12px, min(3.6cqh, 3.4cqw), 18px) inherit;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    pointer-events: auto;
  }

  .touch-button:hover { filter: none; transform: none; }
  .touch-button.active {
    color: #112017;
    background: #9fffd0;
    border-color: #d9ffed;
    transform: translateY(2px);
    box-shadow: 0 1px 0 #00131fbb;
  }

  #touch-status {
    align-self: center;
    width: clamp(82px, 25cqw, 170px);
    padding: 5px 6px;
    border-radius: 999px;
    color: #c7dae4;
    background: #061622cc;
    font-size: clamp(8px, min(2.2cqh, 2.2cqw), 12px);
    font-weight: 800;
    line-height: 1.25;
    text-align: center;
    pointer-events: none;
  }

  .touch-controls.grounded #touch-status { color: #d9ffed; background: #124a42e6; }
}

@media (max-aspect-ratio: 1/1) {
  .language-switcher { top: 4px; right: 4px; padding: 2px; }
  .language-switcher button { padding: 3px 6px; font-size: 8px; }
  #start-screen { padding: 24px 7px 4px; overflow: hidden; }
  #start-screen .language-switcher + .eyebrow { display: none; }
  #start-screen h1 { font-size: clamp(25px, 12cqh, 34px); }
  #start-screen h1 + .eyebrow { font-size: 7px; }
  #start-screen .lead { margin-top: 4px; font-size: clamp(8px, 2.8cqh, 10px); line-height: 1.2; }
  #start-screen .mobile-start-tip { max-width: 94%; margin-top: 4px; font-size: clamp(7px, 2.2cqh, 9px); line-height: 1.2; }
  #start-screen > button { margin-top: 5px; padding: 5px 13px; font-size: clamp(8px, 2.7cqh, 11px); }
  #result-screen { padding: 6px 8px; overflow: hidden; }
  #result-screen .eyebrow { font-size: 8px; }
  #result-screen h2 { font-size: clamp(25px, 10cqh, 44px); }
  #result-screen .result-grid {
    width: min(620px, 96%);
    margin-top: clamp(5px, 2cqh, 10px);
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  #result-screen .result-grid div, #result-screen .result-grid .total {
    grid-column: auto;
    padding: clamp(4px, 1.6cqh, 9px) 4px;
  }
  #result-screen dt { font-size: clamp(7px, 1.9cqh, 9px); letter-spacing: .06em; }
  #result-screen dd, #result-screen .total dd { font-size: clamp(15px, 5.2cqh, 25px); }
  #result-screen .tip {
    margin-top: clamp(4px, 1.6cqh, 8px);
    font-size: clamp(8px, 2.4cqh, 11px);
    line-height: 1.25;
  }
  #result-screen button {
    margin-top: clamp(5px, 1.8cqh, 9px);
    padding: clamp(6px, 1.8cqh, 9px) 16px;
    font-size: clamp(10px, 3cqh, 14px);
  }
}

.result-grid { width: min(440px, 90vw); margin: 28px 0 0; display: grid; grid-template-columns: 1fr 1fr; gap: 2px; background: #71a0b833; }
.result-grid div { padding: 14px; background: #102637; }
.result-grid .total { grid-column: 1 / -1; background: #183c50; }
dt { color: #9ac1d5; font-size: 10px; font-weight: 800; letter-spacing: .14em; }
dd { margin: 4px 0 0; color: #f8fbff; font-size: 28px; font-weight: 900; }
.total dd { color: #e8fa62; font-size: 38px; }

@media (max-aspect-ratio: 16/9) {
  .game-shell { width: 100vw; }
}

@container (max-height: 360px) {
  .overlay { align-content: start; }
  .eyebrow { font-size: 9px; }
  .controls span { width: 12px; }
  kbd { min-width: 22px; padding: 3px 5px; }
  .result-grid { margin-top: 14px; }
  .result-grid div { padding: 9px; }
  dd { font-size: 21px; }
  .total dd { font-size: 29px; }
}
