:root {
  color-scheme: light;
  --ink: #153049;
  --muted: #50677b;
  --cream: #fff7e2;
  --panel: rgba(255, 248, 224, 0.86);
  --panel-border: rgba(27, 66, 96, 0.18);
  --blue: #4fa8dd;
  --blue-deep: #2372ad;
  --red: #b64035;
  --gold: #e1aa3c;
  --shadow: 0 22px 70px rgba(16, 54, 87, 0.24);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
}

body {
  margin: 0;
  font-family: "Trebuchet MS", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 18% 18%, rgba(255, 255, 255, 0.9) 0 7%, transparent 8%),
    radial-gradient(circle at 78% 8%, rgba(255, 255, 255, 0.76) 0 5%, transparent 6%),
    linear-gradient(180deg, #78c8f2 0%, #bfeaff 46%, #eef8ff 100%);
  overflow: hidden;
}

.game-shell {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  margin: 0;
  padding: 0;
}

.stage-wrap {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 0;
  border: 0;
  border-radius: 0;
  overflow: hidden;
  box-shadow: none;
  background: #7cc9ef;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.hud {
  position: absolute;
  inset: 16px 120px auto 16px;
  display: grid;
  grid-template-columns: repeat(5, minmax(86px, max-content)) minmax(138px, max-content) minmax(156px, max-content);
  gap: 8px;
  pointer-events: none;
}

.hud-item {
  min-width: 86px;
  padding: 10px;
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  background: var(--panel);
  box-shadow: 0 8px 20px rgba(30, 74, 102, 0.12);
}

.hud-item span,
.kicker {
  display: block;
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0;
}

.hud-item strong {
  display: block;
  margin-top: 2px;
  color: var(--ink);
  font-size: 28px;
  line-height: 1;
}

.hud-item.wide {
  min-width: 138px;
}

.hud-item.wide strong {
  font-size: 18px;
  line-height: 1.2;
}

.hud-item.skill {
  min-width: 156px;
  cursor: pointer;
  pointer-events: auto;
}

.hud-item.skill strong {
  font-size: 18px;
  line-height: 1.2;
  white-space: nowrap;
}

.hud-item.skill[aria-disabled="true"] {
  cursor: default;
  opacity: 0.82;
}

.sound-toggle {
  position: absolute;
  top: 16px;
  right: 16px;
  min-height: 46px;
  padding: 0 16px;
  border-width: 1px;
  border-color: rgba(23, 64, 92, 0.28);
  color: var(--ink);
  background: rgba(255, 248, 224, 0.88);
  box-shadow: 0 8px 18px rgba(30, 74, 102, 0.13);
  font-size: 16px;
  z-index: 4;
}

.sound-toggle:hover {
  box-shadow: 0 10px 20px rgba(30, 74, 102, 0.18);
}

.sound-toggle:active {
  box-shadow: 0 4px 12px rgba(30, 74, 102, 0.12);
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 14px;
  padding: 28px;
  text-align: center;
  overflow-y: auto;
  background:
    linear-gradient(180deg, rgba(96, 177, 222, 0.2), rgba(37, 101, 151, 0.46)),
    rgba(218, 242, 255, 0.28);
  backdrop-filter: blur(2px);
}

.overlay.hidden {
  display: none;
}

.overlay h1,
.overlay h2 {
  margin: 0;
  color: #12314a;
  font-family: Georgia, "Noto Serif SC", "Songti SC", serif;
  letter-spacing: 0;
}

.overlay h1 {
  font-size: clamp(42px, 7vw, 84px);
  text-shadow: 0 3px 0 rgba(255, 247, 226, 0.75);
}

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

.overlay p {
  max-width: 520px;
  margin: 0;
  color: #234d6c;
  font-size: clamp(20px, 2.4vw, 26px);
  font-weight: 700;
}

.plane-select {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(134px, 1fr));
  width: min(920px, calc(100vw - 48px));
  gap: 9px;
  margin: 2px 0 6px;
}

.plane-option {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 58px;
  padding: 8px 10px;
  border: 1px solid rgba(23, 64, 92, 0.2);
  border-radius: 6px;
  color: var(--ink);
  background: rgba(255, 248, 224, 0.84);
  box-shadow: 0 8px 18px rgba(30, 74, 102, 0.12);
  text-align: left;
  font-size: 14px;
  transform: none;
}

.plane-option:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 20px rgba(30, 74, 102, 0.16);
}

.plane-option:active {
  transform: translateY(1px);
  box-shadow: 0 5px 12px rgba(30, 74, 102, 0.12);
}

.plane-option[aria-pressed="true"] {
  border-color: rgba(159, 49, 43, 0.46);
  background: rgba(255, 241, 198, 0.94);
  box-shadow: inset 0 -3px 0 rgba(159, 49, 43, 0.28), 0 10px 20px rgba(30, 74, 102, 0.14);
}

.plane-option span:last-child {
  min-width: 0;
}

.plane-option strong,
.plane-option small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.plane-option strong {
  color: #17364f;
  font-size: 15px;
  line-height: 1.1;
}

.plane-option small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.plane-swatch {
  position: relative;
  flex: 0 0 30px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background:
    linear-gradient(90deg, transparent 0 28%, var(--wing-color) 29% 71%, transparent 72%),
    linear-gradient(180deg, var(--plane-color), color-mix(in srgb, var(--plane-color), #172d42 28%));
  box-shadow: inset 0 0 0 2px rgba(21, 48, 73, 0.18);
}

.plane-swatch::after {
  content: "";
  position: absolute;
  inset: 10px 13px 5px;
  border-radius: 50% 50% 45% 45%;
  background: rgba(255, 255, 255, 0.52);
}

button {
  appearance: none;
  min-height: 58px;
  padding: 0 30px;
  border: 2px solid rgba(76, 37, 26, 0.28);
  border-radius: 6px;
  color: #fff8e7;
  background: linear-gradient(180deg, #cf584a 0%, #9f312b 100%);
  box-shadow: 0 10px 0 #6d281f, 0 18px 26px rgba(75, 36, 26, 0.28);
  font: inherit;
  font-size: 22px;
  font-weight: 900;
  letter-spacing: 0;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 140ms ease, box-shadow 140ms ease;
}

button:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 0 #6d281f, 0 22px 30px rgba(75, 36, 26, 0.28);
}

button:active {
  transform: translateY(7px);
  box-shadow: 0 3px 0 #6d281f, 0 9px 18px rgba(75, 36, 26, 0.2);
}

.secondary-button {
  min-height: 48px;
  padding: 0 22px;
  border-color: rgba(23, 64, 92, 0.28);
  color: #17364f;
  background: rgba(255, 248, 224, 0.88);
  box-shadow: 0 8px 18px rgba(30, 74, 102, 0.13);
  font-size: 17px;
}

.secondary-button:hover {
  box-shadow: 0 10px 20px rgba(30, 74, 102, 0.18);
}

.secondary-button:active {
  box-shadow: 0 4px 12px rgba(30, 74, 102, 0.12);
}

@media (max-width: 720px) {
  .hud {
    inset: calc(env(safe-area-inset-top) + 8px) auto auto calc(env(safe-area-inset-left) + 8px);
    display: flex;
    flex-wrap: wrap;
    max-width: calc(100vw - 94px - env(safe-area-inset-left) - env(safe-area-inset-right));
    gap: 6px;
  }

  .hud-item {
    display: flex;
    align-items: baseline;
    min-width: 0;
    min-height: 30px;
    gap: 5px;
    padding: 5px 7px;
    border-radius: 5px;
    background: rgba(255, 248, 224, 0.78);
    box-shadow: 0 5px 14px rgba(30, 74, 102, 0.1);
  }

  .hud-item:nth-child(2),
  .hud-item:nth-child(4),
  .hud-item.wide {
    display: none;
  }

  .hud-item.skill {
    min-width: 0;
    max-width: 46vw;
  }

  .hud-item span,
  .kicker {
    font-size: 11px;
    line-height: 1;
  }

  .hud-item strong {
    margin-top: 0;
    font-size: 16px;
    line-height: 1;
    white-space: nowrap;
  }

  .hud-item.skill strong {
    max-width: 34vw;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 13px;
  }

  .overlay {
    padding: 18px;
  }

  .plane-select {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: min(420px, calc(100vw - 28px));
    gap: 8px;
  }

  .plane-option {
    min-height: 48px;
    padding: 6px 8px;
  }

  .plane-option strong {
    font-size: 13px;
  }

  .plane-option small {
    font-size: 11px;
  }

  .plane-swatch {
    flex-basis: 26px;
    width: 26px;
    height: 26px;
  }

  .sound-toggle {
    top: calc(env(safe-area-inset-top) + 8px);
    right: calc(env(safe-area-inset-right) + 8px);
    min-height: 36px;
    padding: 0 10px;
    font-size: 13px;
  }
}

@media (max-height: 620px) {
  .overlay {
    align-content: start;
    padding-top: 16px;
    padding-bottom: 16px;
  }

  .overlay h1 {
    font-size: clamp(34px, 8vh, 52px);
  }

  .overlay p {
    font-size: clamp(17px, 4vh, 22px);
  }
}
