:root {
  --ink: #17214b;
  --paper: #fff8e8;
  --coral: #ef796d;
  --mint: #a7d9c1;
  --night: #142453;
}

* {
  box-sizing: border-box;
}
[hidden] {
  display: none !important;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  color: var(--ink);
  background: linear-gradient(#e7eeff, #fff2d7);
  font-family: ui-rounded, "Trebuchet MS", sans-serif;
}

button,
a {
  max-width: 100%;
  min-height: 44px;
  font: inherit;
}

button {
  padding: 8px 12px;
  border: 2px solid var(--ink);
  border-radius: 12px;
  color: var(--ink);
  background: #fff;
  font-weight: 800;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.primary {
  min-height: 50px;
  background: var(--coral);
  box-shadow: 0 3px 0 var(--ink);
}

:focus-visible {
  outline: 4px solid #fff;
  outline-offset: 3px;
  box-shadow: 0 0 0 7px var(--ink);
}

.game-bar {
  display: flex;
  min-height: 58px;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px clamp(8px, 2vw, 24px);
  color: #fff;
  background: var(--night);
}

.game-bar a,
.dialog-all-games {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  padding: 5px 10px;
  border: 2px solid var(--ink);
  border-radius: 10px;
  color: var(--night);
  background: #fff9e8;
  font-weight: 900;
  text-decoration: none;
}

.game-bar p {
  margin: 0;
  font-size: clamp(0.7rem, 2vw, 1rem);
  font-weight: 900;
  letter-spacing: 0.08em;
}

.cp-profile-slot {
  min-width: 44px;
  max-width: 42vw;
  overflow-wrap: anywhere;
}

.card {
  min-width: 0;
  border: 3px solid var(--ink);
  border-radius: 22px;
  background: rgba(255, 253, 245, 0.96);
  box-shadow: 0 6px 0 rgba(23, 33, 75, 0.25);
}

#game-main {
  max-width: 1200px;
  margin: auto;
  padding: clamp(10px, 3vw, 28px);
}

.welcome {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  align-items: center;
  gap: 24px;
  max-width: 920px;
  margin: clamp(18px, 7vh, 80px) auto;
  padding: clamp(20px, 5vw, 52px);
}

h1,
h2,
p {
  margin-top: 0;
}

.welcome h1 {
  font-size: clamp(2.4rem, 7vw, 5rem);
  line-height: 0.9;
}

.welcome p {
  max-width: 50ch;
  font-size: 1.1rem;
}

.eyebrow {
  color: #a14048;
  font-size: 0.77rem;
  font-weight: 900;
  letter-spacing: 0.08em;
}

.mini-scene {
  position: relative;
  min-height: 220px;
  overflow: hidden;
  border-radius: 18px;
  background: var(--night);
}

.mini-moon,
.mini-launcher,
.mini-capsule,
.mini-pad {
  position: absolute;
}
.mini-moon {
  top: 22px;
  right: 24px;
  width: 90px;
  height: 90px;
  border-radius: 50%;
  background: #fff1c9;
}
.mini-launcher {
  bottom: 38px;
  left: 35px;
  width: 80px;
  height: 35px;
  background: #c9934b;
  clip-path: polygon(0 100%, 100% 100%, 75% 0);
}
.mini-capsule {
  bottom: 110px;
  left: 107px;
  color: #fff1c9;
  font-size: 32px;
}
.mini-pad {
  right: 28px;
  bottom: 35px;
  width: 94px;
  height: 20px;
  border-radius: 14px;
  background: var(--coral);
}

.round-head {
  padding: 5px 4px;
}
.round-head h1 {
  margin-bottom: 7px;
  font-size: clamp(1.7rem, 4vw, 3.1rem);
}
#feedback {
  min-height: 1.4em;
  font-weight: 800;
}

.game-layout {
  display: grid;
  min-width: 0;
  grid-template-columns: minmax(0, 1.55fr) minmax(280px, 0.9fr);
  gap: 16px;
}

.scene-card {
  align-self: start;
  padding: 10px;
}

.scene {
  min-height: 0;
  aspect-ratio: 1.875;
}

.scene svg {
  display: block;
  width: 100%;
  height: 100%;
}
.launcher {
  fill: #c9934b;
  stroke: var(--ink);
  stroke-width: 0.7;
}
.capsule {
  fill: #fff1c9;
  stroke: var(--ink);
  stroke-width: 0.7;
}
.flight {
  fill: none;
  stroke: #fff1c9;
  stroke-width: 1.1;
  stroke-dasharray: 2 1;
}
.flight.fence {
  stroke: #ef796d;
}
.fence line {
  stroke: #367a6b;
  stroke-width: 1.5;
}
.fence circle {
  fill: #f2709a;
}
.pad-mark {
  fill: #fff;
  font-size: 4px;
}
.trace-label {
  margin: 4px 2px 0;
  font-size: 0.9rem;
  font-weight: 800;
}

.controls {
  min-width: 0;
  padding: 14px;
}
fieldset {
  min-inline-size: 0;
  margin: 0 0 10px;
  padding: 8px;
  border: 0;
  border-top: 2px solid #c9bfd3;
}
legend {
  padding: 0 5px;
  font-weight: 900;
}

.choice-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}

.choice-grid button {
  display: flex;
  min-width: 0;
  min-height: 50px;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 0.9rem;
}

.angle-arrow {
  display: inline-block;
  font-style: normal;
  line-height: 1;
}
.a25 {
  transform: rotate(-22deg);
}
.a40 {
  transform: rotate(-38deg);
}
.a55 {
  transform: rotate(-54deg);
}
.a70 {
  transform: rotate(-68deg);
}
.choice-grid button[aria-pressed="true"] {
  background: var(--mint);
  box-shadow: inset 0 0 0 2px var(--ink);
}

.actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
  margin-top: 10px;
}

.actions button {
  min-height: 44px;
  font-size: 0.85rem;
}
#hint-output {
  min-height: 1.4em;
  margin: 10px 0;
  font-weight: 800;
}

#result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

#result-actions button {
  flex: 1 1 135px;
}

.ending {
  max-width: 680px;
  margin: 10px auto;
  padding: 18px;
  text-align: center;
}

.seals {
  display: flex;
  justify-content: center;
  gap: 12px;
}
.seals b {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border: 2px solid var(--ink);
  border-radius: 50%;
  color: #d35c67;
  background: #fff1c9;
}
.finish-actions {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
}

dialog {
  max-width: min(700px, calc(100% - 20px));
  max-height: calc(100dvh - 20px);
  border: 3px solid var(--ink);
  border-radius: 18px;
  color: var(--ink);
  background: #fff9ed;
}

dialog::backdrop {
  background: rgba(20, 36, 83, 0.65);
}
dialog section {
  padding: 16px;
}
dialog header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

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

.help-examples article {
  min-width: 0;
  padding: 9px;
  border-radius: 10px;
  background: #dff0e7;
}
.help-sky {
  position: relative;
  height: 55px;
  margin: 8px 0;
  overflow: hidden;
  border-radius: 7px;
  background: var(--night);
}
.help-launch {
  position: absolute;
  bottom: 3px;
  left: 9px;
  color: #c9934b;
}
.help-arc {
  position: absolute;
  bottom: 7px;
  left: 15px;
  width: 80px;
  height: 45px;
  border-top: 3px dashed #fff1c9;
  border-radius: 50%;
}
.angle-low {
  transform: rotate(-8deg);
}
.angle-high {
  height: 75px;
  transform: rotate(-25deg);
}
.strength-short {
  width: 47px;
  transform: rotate(-12deg);
}
.strength-long {
  width: 100px;
  transform: rotate(-12deg);
}
.fence-arc {
  width: 54px;
  transform: rotate(-8deg);
}
.help-fence {
  position: absolute;
  bottom: 0;
  left: 62px;
  width: 5px;
  height: 31px;
  background: #367a6b;
}

.is-result .controls fieldset,
.is-result #launch,
.is-result .actions,
.is-result #hint-output {
  display: none;
}
.is-finished .controls {
  display: none;
}
.is-finished .game-layout {
  grid-template-columns: minmax(0, 1fr);
  max-width: 680px;
  margin: auto;
}
.is-finished .scene {
  max-height: none;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

@media (max-width: 620px) {
  .game-bar p {
    display: none;
  }
  .welcome,
  .game-layout {
    grid-template-columns: 1fr;
  }
  .mini-scene {
    min-height: 150px;
  }
  .scene {
    min-height: 0;
    aspect-ratio: 1.875;
  }
  .choice-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  .choice-grid button {
    padding: 6px 2px;
    flex-direction: column;
    gap: 0;
  }
  .choice-grid b {
    font-size: 0.62rem;
  }
  .choice-grid span {
    font-size: 0.7rem;
  }
  .help-examples {
    grid-template-columns: 1fr;
  }
  .is-result .round-head {
    padding: 2px 4px;
  }
  .is-result .round-head h1 {
    margin-bottom: 2px;
    font-size: 1.35rem;
  }
  .is-result .round-head p {
    margin-bottom: 3px;
  }
  .is-result .scene-card {
    padding: 7px;
  }
  .is-result .controls {
    padding: 7px;
  }
  .is-result #result-actions {
    gap: 6px;
  }
  .is-finished .scene {
    min-height: 0;
    max-height: none;
  }
  .is-finished .ending {
    margin-top: 6px;
    padding: 9px;
  }
  .is-finished .ending p {
    margin-bottom: 8px;
  }
  .is-finished .seals {
    gap: 7px;
  }
}

@media (max-height: 390px) and (min-width: 600px) {
  #game-main {
    padding: 4px 12px;
  }
  .game-bar {
    min-height: 42px;
    padding: 1px 10px;
  }
  .welcome {
    grid-template-columns: minmax(0, 1.15fr) minmax(220px, 0.85fr);
    gap: 12px;
    margin: 4px auto;
    padding: 10px 16px;
  }
  .welcome h1 {
    font-size: 2rem;
  }
  .welcome p {
    margin-bottom: 6px;
    font-size: 0.78rem;
  }
  .welcome .eyebrow {
    margin-bottom: 3px;
    font-size: 0.64rem;
  }
  .mini-scene {
    min-height: 150px;
  }
  .round-head {
    display: flex;
    align-items: baseline;
    gap: 8px;
    padding: 0;
  }
  .round-head p {
    margin: 0;
  }
  .round-head h1 {
    margin: 0;
    font-size: 1.25rem;
  }
  .round-head .eyebrow {
    white-space: nowrap;
  }
  .game-layout {
    grid-template-columns: minmax(300px, 0.9fr) minmax(420px, 1.2fr);
    gap: 8px;
  }
  .scene {
    min-height: 0;
    max-height: none;
  }
  .controls {
    padding: 6px;
  }
  .controls fieldset {
    margin-bottom: 3px;
    padding: 2px;
  }
  .choice-grid {
    grid-template-columns: repeat(4, 1fr);
  }
  .choice-grid button {
    min-height: 48px;
    padding: 2px;
    font-size: 0.7rem;
  }
  .actions {
    grid-template-columns: repeat(4, 1fr);
    margin-top: 4px;
  }
  .actions button {
    min-height: 44px;
    padding: 3px;
    font-size: 0.66rem;
  }

  .is-result .round-head {
    display: flex;
    align-items: baseline;
    gap: 8px;
    padding: 0;
  }
  .is-result .round-head #feedback {
    display: none;
  }
  .is-result .round-head h1 {
    font-size: 1.1rem;
  }
  .is-result .game-layout {
    grid-template-columns: minmax(280px, 0.8fr) minmax(440px, 1.2fr);
  }
  .is-result .scene-card {
    padding: 6px;
  }
  .is-result .controls {
    padding: 6px;
  }

  .is-finished {
    display: grid;
    grid-template-columns: minmax(300px, 0.9fr) minmax(390px, 1.1fr);
    column-gap: 8px;
  }

  .is-finished .round-head {
    grid-column: 1 / -1;
  }
  .is-finished .game-layout {
    display: block;
    grid-column: 1;
    grid-row: 2;
  }
  .is-finished .scene-card {
    width: 300px;
    justify-self: end;
    padding: 6px;
  }
  .is-finished .scene {
    height: auto;
    min-height: 0;
    max-height: none;
  }
  .is-finished .ending {
    display: grid;
    grid-column: 2;
    grid-row: 2;
    grid-template-columns: 1fr auto;
    gap: 4px 8px;
    align-content: center;
    margin: 0;
    padding: 7px;
    text-align: left;
  }

  .is-finished .ending .eyebrow,
  .is-finished .ending h2 {
    grid-column: 1 / -1;
    margin: 0;
  }
  .is-finished .ending > p:not(.eyebrow) {
    display: none;
  }
  .is-finished .seals {
    grid-column: 1;
    justify-content: flex-start;
    gap: 4px;
  }
  .is-finished .seals b {
    width: 34px;
    height: 34px;
  }
  .is-finished .finish-actions {
    grid-column: 2;
    align-self: center;
    flex-direction: column;
  }
  .is-finished .finish-actions button {
    min-height: 44px;
    padding: 3px 7px;
    font-size: 0.76rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}
