:root {
  color-scheme: dark;
  --ink: #18232a;
  --paper: #fff7df;
  --sea: #55b7c8;
  --sun: #f2c14e;
  --danger: #e94f37;
  --grass: #77b255;
  --sludge: #6e4a31;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #0e1b24;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
}

.app {
  position: fixed;
  inset: 0;
  min-width: 320px;
  min-height: 220px;
  background: #0e1b24;
  touch-action: none;
}

#gameCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.hud {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  right: max(12px, env(safe-area-inset-right));
  z-index: 4;
  display: grid;
  grid-template-columns: auto auto minmax(120px, 1fr) minmax(120px, 1fr) auto;
  gap: 8px;
  align-items: center;
  color: var(--paper);
  pointer-events: none;
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.app[data-state="playing"] .hud {
  opacity: 1;
  transform: translateY(0);
}

.hud__block,
.hud__weather,
.hud__bar {
  min-height: 38px;
  border: 2px solid rgba(255, 247, 223, 0.38);
  background: rgba(14, 27, 36, 0.62);
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.18);
  border-radius: 8px;
  backdrop-filter: blur(8px);
}

.hud__block {
  min-width: 76px;
  padding: 5px 9px;
}

.hud__label,
.hud__bar span {
  display: block;
  font-size: 10px;
  line-height: 1;
  text-transform: uppercase;
  color: rgba(255, 247, 223, 0.78);
}

.hud__block strong {
  display: block;
  margin-top: 2px;
  font-size: 18px;
  line-height: 1;
}

.hud__bar {
  position: relative;
  overflow: hidden;
  padding: 5px 8px;
}

.hud__bar i {
  position: absolute;
  left: 7px;
  right: 7px;
  bottom: 6px;
  height: 10px;
  width: calc(var(--fill, 1) * (100% - 14px));
  border-radius: 999px;
  background: linear-gradient(90deg, #77b255, #f2c14e);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.25);
}

.hud__bar--splat i {
  background: linear-gradient(90deg, #8b5a2b, #5bbf6a);
}

.hud__weather {
  min-width: 88px;
  padding: 9px 10px 0;
  font-size: 13px;
  white-space: nowrap;
  text-align: center;
}

.controls {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  justify-content: space-between;
  align-items: stretch;
  padding: max(72px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  pointer-events: none;
  opacity: 0;
  transition: opacity 160ms ease;
}

.app[data-state="playing"] .controls {
  opacity: 1;
}

.controls__trim,
.controls__actions {
  display: flex;
  pointer-events: auto;
}

.controls__trim {
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 8px;
}

.controls__actions {
  width: min(31vw, 190px);
  max-width: 190px;
  min-width: 128px;
  flex-direction: column;
  justify-content: flex-end;
  gap: 8px;
}

.control-button,
.primary-button,
.secondary-button,
.shop-card {
  border: 2px solid rgba(24, 35, 42, 0.92);
  border-radius: 8px;
  color: var(--ink);
  box-shadow: 0 5px 0 rgba(0, 0, 0, 0.28);
  touch-action: none;
  cursor: pointer;
}

.control-button {
  min-height: 58px;
  width: 100%;
  font-weight: 900;
  text-transform: uppercase;
}

.control-button:active,
.primary-button:active,
.secondary-button:active,
.shop-card:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.28);
}

.control-button--small {
  width: 64px;
  height: 64px;
  min-height: 64px;
  background: #f2c14e;
  font-size: 28px;
}

.control-button--flap {
  height: 76px;
  background: #fff7df;
  font-size: clamp(18px, 3vw, 26px);
}

.control-button--splat {
  height: 82px;
  background: #91c46c;
  font-size: clamp(18px, 3vw, 26px);
}

.control-button--power {
  min-height: 48px;
  background: #58c0d7;
  font-size: 13px;
}

.control-button:disabled {
  opacity: 0.42;
  filter: grayscale(1);
  cursor: default;
}

.trim-gauge {
  position: relative;
  width: 22px;
  height: 108px;
  border: 2px solid rgba(255, 247, 223, 0.46);
  border-radius: 999px;
  background: rgba(14, 27, 36, 0.55);
}

.trim-gauge i {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 30px;
  height: 6px;
  border-radius: 999px;
  background: #fff7df;
  transform: translate(-50%, calc(-50% + var(--trim, 0px)));
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: grid;
  place-items: center;
  padding: 18px max(18px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  background: rgba(9, 18, 24, 0.48);
}

.overlay[hidden] {
  display: none;
}

.overlay__panel {
  width: min(92vw, 440px);
  border: 3px solid rgba(24, 35, 42, 0.94);
  border-radius: 8px;
  background: rgba(255, 247, 223, 0.95);
  color: var(--ink);
  padding: 22px;
  box-shadow: 0 18px 0 rgba(0, 0, 0, 0.18);
}

.overlay__panel--menu {
  width: min(94vw, 760px);
  max-height: min(90vh, 620px);
  overflow: auto;
}

.overlay__panel--wide {
  width: min(94vw, 740px);
  max-height: min(88vh, 520px);
  overflow: auto;
}

.overlay h1,
.overlay h2 {
  margin: 0;
  font-size: clamp(32px, 7vw, 64px);
  line-height: 0.94;
}

.overlay h2 {
  font-size: clamp(28px, 5vw, 46px);
}

.overlay__tag,
#resultReason {
  margin: 10px 0 16px;
  color: rgba(24, 35, 42, 0.72);
}

.menu-stats,
.score-grid {
  display: grid;
  gap: 8px;
}

.menu-stats {
  grid-template-columns: 1fr 1fr;
  margin: 0 0 12px;
}

.menu-stats div,
.score-grid div,
.shop-panel {
  border: 2px solid rgba(24, 35, 42, 0.18);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.42);
}

.menu-stats div {
  padding: 10px;
}

.menu-stats dt {
  font-size: 11px;
  text-transform: uppercase;
  color: rgba(24, 35, 42, 0.62);
}

.menu-stats dd {
  margin: 2px 0 0;
  font-size: 22px;
  font-weight: 900;
}

.menu-help {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 0 0 14px;
}

.menu-help section {
  min-height: 118px;
  border: 2px solid rgba(24, 35, 42, 0.16);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.38);
  padding: 10px;
}

.menu-help h2 {
  margin: 0 0 7px;
  font-size: 15px;
  line-height: 1;
  text-transform: uppercase;
}

.menu-help p,
.menu-help li {
  margin: 0 0 6px;
  font-size: 12px;
  line-height: 1.25;
  color: rgba(24, 35, 42, 0.78);
}

.menu-help ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

.legend {
  display: inline-block;
  width: 16px;
  height: 16px;
  margin-right: 5px;
  vertical-align: -3px;
  border: 2px solid var(--ink);
}

.legend--chip {
  width: 19px;
  height: 11px;
  border-radius: 3px;
  background: #f2c14e;
  transform: rotate(-14deg);
}

.legend--hazard {
  background: #e94f37;
  transform: rotate(45deg);
}

.legend--target {
  width: 12px;
  height: 20px;
  border-radius: 8px 8px 3px 3px;
  background: #2b4c7e;
}

.legend--power,
.legend--refill,
.legend--shield,
.legend--multi,
.legend--tank {
  border-radius: 50%;
  box-shadow: 0 0 0 3px rgba(88, 192, 215, 0.28);
}

.legend--power {
  background: #91c46c;
}

.legend--refill {
  background: #f2c14e;
}

.legend--shield {
  background: #58c0d7;
}

.legend--multi {
  background: #91c46c;
}

.legend--tank {
  background: #e94f37;
}

.primary-button,
.secondary-button {
  min-height: 48px;
  padding: 0 16px;
  font-weight: 900;
  text-transform: uppercase;
}

.primary-button {
  width: 100%;
  background: #f2c14e;
}

.secondary-button {
  background: #fff7df;
}

.result-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
}

.result-head strong {
  font-size: clamp(32px, 7vw, 64px);
  line-height: 0.92;
  color: #6e4a31;
}

.new-high {
  display: inline-block;
  margin: 0 0 10px;
  padding: 5px 9px;
  border-radius: 999px;
  background: #e94f37;
  color: #fff7df;
  font-weight: 900;
  text-transform: uppercase;
}

.score-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 12px;
}

.score-grid div {
  padding: 8px;
}

.score-grid span {
  display: block;
  font-size: 11px;
  color: rgba(24, 35, 42, 0.62);
  text-transform: uppercase;
}

.score-grid strong {
  font-size: 20px;
}

.shop-panel {
  padding: 10px;
}

.shop-panel__head,
.result-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.shop-panel__head {
  margin-bottom: 8px;
  font-weight: 900;
}

.shop-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.shop-card {
  min-height: 76px;
  padding: 8px;
  background: #58c0d7;
  text-align: left;
}

.shop-card strong,
.shop-card span {
  display: block;
}

.shop-card strong {
  font-size: 14px;
}

.shop-card span {
  margin-top: 4px;
  font-size: 11px;
  color: rgba(24, 35, 42, 0.72);
}

.shop-card[data-selected="true"] {
  background: #91c46c;
  outline: 3px solid #e94f37;
}

.shop-card:disabled {
  opacity: 0.42;
  cursor: default;
}

.result-actions {
  margin-top: 14px;
}

.result-actions .primary-button {
  width: auto;
  flex: 1;
}

.rotate-overlay {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 20;
  place-items: center;
  padding: 22px;
  background: #0e1b24;
  color: #fff7df;
  text-align: center;
}

.rotate-overlay div {
  max-width: 280px;
}

.rotate-overlay strong,
.rotate-overlay span {
  display: block;
}

.rotate-overlay strong {
  font-size: 28px;
  line-height: 1;
}

.rotate-overlay span {
  margin-top: 8px;
  color: rgba(255, 247, 223, 0.72);
}

@media (orientation: portrait) and (max-width: 900px) {
  .rotate-overlay {
    display: grid;
  }
}

@media (max-width: 780px) {
  .hud {
    grid-template-columns: auto auto 1fr 1fr;
  }

  .hud__weather {
    display: none;
  }

  .score-grid,
  .shop-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .menu-help {
    grid-template-columns: 1fr;
  }

  .overlay__panel {
    padding: 16px;
  }
}

@media (max-height: 420px) {
  .hud {
    top: max(6px, env(safe-area-inset-top));
  }

  .controls {
    padding-top: max(52px, env(safe-area-inset-top));
  }

  .control-button--small {
    width: 52px;
    height: 52px;
    min-height: 52px;
  }

  .trim-gauge {
    height: 76px;
  }

  .control-button--flap,
  .control-button--splat {
    height: 60px;
    min-height: 60px;
  }
}
