:root {
  color-scheme: light;
  --ink: #102033;
  --muted: #506174;
  --panel: rgba(255, 255, 255, 0.84);
  --panel-strong: rgba(255, 255, 255, 0.95);
  --border: rgba(16, 42, 68, 0.18);
  --blue: #1f74d7;
  --green: #18a26b;
  --yellow: #ffc83d;
  --red: #e65645;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
  background: #8fd2ff;
  overflow: hidden;
  user-select: none;
  touch-action: none;
}

button {
  font: inherit;
}

.game-shell {
  position: relative;
  height: 100dvh;
  max-height: 100dvh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background:
    linear-gradient(180deg, rgba(127, 202, 255, 0.96) 0%, rgba(223, 249, 255, 0.92) 58%, rgba(126, 196, 103, 0.95) 100%);
}

.topbar {
  position: relative;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  width: min(1180px, calc(100vw - 28px));
  margin: 14px auto 0;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 10px 28px rgba(40, 77, 107, 0.14);
  backdrop-filter: blur(12px);
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--blue);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(24px, 4vw, 42px);
  line-height: 1;
  letter-spacing: 0;
  white-space: nowrap;
}

.stats {
  display: grid;
  grid-template-columns: repeat(6, minmax(72px, 1fr));
  gap: 8px;
  min-width: min(780px, 64vw);
}

.stat {
  min-height: 58px;
  padding: 8px 10px;
  border: 1px solid rgba(17, 32, 47, 0.1);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.64);
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.stat strong {
  display: block;
  margin-top: 3px;
  font-size: clamp(18px, 2.4vw, 26px);
  line-height: 1.05;
  white-space: nowrap;
}

#planeText,
#techniqueText,
#stateText {
  font-size: clamp(16px, 1.8vw, 23px);
}

.stage {
  position: relative;
  flex: 1 1 0;
  min-height: 0;
  display: block;
  overflow: hidden;
  cursor: pointer;
}

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

.power-panel {
  position: absolute;
  z-index: 4;
  left: 50%;
  bottom: calc(32px + env(safe-area-inset-bottom));
  width: min(520px, calc(100vw - 160px));
  min-width: 180px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-strong);
  box-shadow: 0 14px 34px rgba(20, 45, 68, 0.18);
}

.meter {
  position: relative;
  flex: 1;
  height: 18px;
  border-radius: 999px;
  background: rgba(17, 32, 47, 0.12);
  overflow: hidden;
}

.meter-fill {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--red), var(--yellow) 48%, var(--green));
  transition: width 80ms linear;
}

.safe-line {
  position: absolute;
  top: -3px;
  bottom: -3px;
  left: 48%;
  width: 3px;
  border-radius: 999px;
  background: rgba(17, 32, 47, 0.55);
}

#hintText {
  width: 118px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 800;
  text-align: center;
  white-space: nowrap;
}

.flight-controls {
  position: absolute;
  z-index: 5;
  left: max(18px, calc((100vw - 1180px) / 2));
  bottom: calc(22px + env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: repeat(3, 64px);
  grid-template-areas:
    ". up ."
    "left down right";
  align-items: center;
  justify-items: center;
  gap: 8px;
}

.control-button {
  width: 64px;
  height: 58px;
  padding: 0 8px;
  border: 0;
  border-radius: 8px;
  background: rgba(17, 32, 47, 0.82);
  color: white;
  font-size: 22px;
  font-weight: 900;
  box-shadow: 0 12px 26px rgba(17, 32, 47, 0.2);
  cursor: pointer;
}

.control-button span {
  display: block;
  line-height: 0.95;
}

.control-button small {
  display: block;
  margin-top: 1px;
  font-size: 11px;
  line-height: 1;
}

#leftControl {
  grid-area: left;
  background: #18a26b;
}

#rightControl {
  grid-area: right;
  background: #1f74d7;
}

.control-button.up-control {
  grid-area: up;
  font-size: 24px;
}

.control-button.down-control {
  grid-area: down;
  font-size: 24px;
}

.control-button:active,
.control-button.is-held {
  transform: translateY(2px);
  filter: brightness(0.92);
}

.control-button:disabled {
  opacity: 0.42;
  cursor: not-allowed;
  transform: none;
}

.help-button {
  position: absolute;
  z-index: 6;
  top: 16px;
  right: max(18px, calc((100vw - 1180px) / 2));
  min-width: 76px;
  height: 42px;
  border: 0;
  border-radius: 8px;
  background: rgba(17, 32, 47, 0.82);
  color: white;
  font-size: 15px;
  font-weight: 900;
  box-shadow: 0 12px 26px rgba(17, 32, 47, 0.18);
  cursor: pointer;
}

.help-button:active {
  transform: translateY(2px);
  filter: brightness(0.92);
}

.end-overlay {
  position: absolute;
  z-index: 8;
  inset: 0;
  display: none;
  place-items: center;
  background: rgba(17, 32, 47, 0.18);
  backdrop-filter: blur(3px);
}

.end-overlay.is-visible {
  display: grid;
}

.end-panel {
  width: min(460px, calc(100vw - 36px));
  padding: 24px;
  border: 1px solid rgba(255, 255, 255, 0.68);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 22px 58px rgba(17, 32, 47, 0.26);
  text-align: center;
}

.end-panel p {
  margin: 0;
  color: var(--muted);
  font-size: 16px;
  font-weight: 800;
}

.end-panel #endKicker {
  color: var(--blue);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.end-panel h2 {
  margin: 8px 0 8px;
  color: var(--ink);
  font-size: clamp(34px, 6vw, 54px);
  line-height: 1.05;
  letter-spacing: 0;
}

.end-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 20px;
}

.end-actions button {
  min-width: 132px;
  height: 52px;
  border: 0;
  border-radius: 8px;
  color: white;
  font-size: 18px;
  font-weight: 900;
  cursor: pointer;
}

#retryButton {
  background: #1f74d7;
}

#restartButton {
  background: #334155;
}

.help-overlay {
  position: absolute;
  z-index: 9;
  inset: 0;
  display: none;
  place-items: center;
  padding: 20px;
  background: rgba(17, 32, 47, 0.2);
  backdrop-filter: blur(3px);
}

.help-overlay.is-visible {
  display: grid;
}

.help-panel {
  width: min(760px, calc(100vw - 34px));
  max-height: min(700px, calc(100dvh - 110px));
  overflow: auto;
  padding: 18px;
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 24px 60px rgba(17, 32, 47, 0.28);
}

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

.help-head p {
  margin: 0;
  color: var(--blue);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.help-head h2 {
  margin: 4px 0 0;
  font-size: clamp(26px, 4vw, 38px);
  line-height: 1.05;
  letter-spacing: 0;
}

#helpCloseButton {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 8px;
  background: #334155;
  color: white;
  font-size: 26px;
  line-height: 1;
  font-weight: 900;
  cursor: pointer;
}

.help-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 16px;
}

.help-card {
  min-height: 220px;
  padding: 12px;
  border: 1px solid rgba(17, 32, 47, 0.12);
  border-radius: 8px;
  background: rgba(248, 250, 252, 0.88);
}

.help-card h3 {
  margin: 0;
  font-size: 18px;
  line-height: 1.1;
}

.help-card p {
  margin: 7px 0 10px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
  font-weight: 700;
}

.help-card.good {
  border-color: rgba(24, 162, 107, 0.28);
  background: rgba(231, 255, 243, 0.9);
}

.help-card.bad {
  border-color: rgba(255, 200, 61, 0.36);
  background: rgba(255, 249, 224, 0.9);
}

.help-card.boom {
  border-color: rgba(230, 86, 69, 0.3);
  background: rgba(255, 239, 236, 0.92);
}

.help-list {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.help-chip {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 6px 9px;
  border-radius: 999px;
  color: #102033;
  font-size: 13px;
  line-height: 1;
  font-weight: 900;
  background: white;
  box-shadow: inset 0 0 0 1px rgba(17, 32, 47, 0.1);
}

.help-chip.good {
  background: #bbf7d0;
}

.help-chip.bad {
  background: #fde68a;
}

.help-chip.boom {
  background: #fecaca;
}

.help-controls {
  margin: 14px 0 0;
  padding: 11px 12px;
  border-radius: 8px;
  background: rgba(17, 32, 47, 0.08);
  color: var(--ink);
  font-size: 16px;
  font-weight: 900;
  text-align: center;
}

@media (max-width: 940px) {
  .topbar {
    width: calc(100vw - 18px);
    gap: 10px;
  }

  h1 {
    font-size: clamp(25px, 3.4vw, 32px);
  }

  .stats {
    min-width: 0;
    flex: 1;
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }

  .stat {
    min-height: 54px;
    padding: 7px 8px;
  }

  .stat strong {
    font-size: clamp(16px, 2.3vw, 23px);
  }

  .power-panel {
    bottom: calc(170px + env(safe-area-inset-bottom));
    width: min(520px, calc(100vw - 220px));
  }

  .flight-controls {
    left: 10px;
    bottom: calc(12px + env(safe-area-inset-bottom));
  }

  .help-button {
    top: 10px;
    right: 10px;
  }
}

@media (max-width: 760px) {
  body {
    overflow: hidden;
  }

  .topbar {
    width: calc(100vw - 18px);
    margin-top: 9px;
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
    padding: 10px;
  }

  .stats {
    width: 100%;
    min-width: 0;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .stat {
    min-height: 52px;
    padding: 7px;
  }

  .stat span {
    font-size: 11px;
  }

  .stat strong {
    font-size: 17px;
  }

  .power-panel {
    bottom: calc(162px + env(safe-area-inset-bottom));
    width: calc(100vw - 28px);
  }

  .flight-controls {
    left: 12px;
    right: auto;
    bottom: calc(12px + env(safe-area-inset-bottom));
  }

  .control-button {
    width: 58px;
    height: 54px;
  }

  .help-panel {
    max-height: calc(100dvh - 150px);
    padding: 14px;
  }

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

  .help-card {
    min-height: 0;
  }
}

@media (max-width: 430px) {
  .control-button.up-control,
  .control-button.down-control {
    font-size: 22px;
  }

  .control-button small {
    font-size: 10px;
  }

  .end-actions {
    flex-direction: column;
  }

  .end-actions button {
    width: 100%;
  }

  h1 {
    font-size: 25px;
  }

  .stats {
    gap: 6px;
  }

  .power-panel {
    gap: 8px;
  }

  #hintText {
    width: 96px;
    font-size: 12px;
  }
}
