:root {
  --void: #080a0f;
  --ink: #111927;
  --panel: rgba(16, 24, 34, 0.92);
  --line: rgba(224, 231, 255, 0.18);
  --text: #f5f1e8;
  --muted: #aeb7c7;
  --sun: #ffd166;
  --reef: #49c6a4;
  --rose: #ff6b8a;
  --sky: #62b6ff;
  --ember: #ff9f43;
}

* {
  box-sizing: border-box;
}

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

body {
  position: relative;
  overflow: hidden;
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: clamp(10px, 2.2vh, 20px);
  font-family: Inter, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    linear-gradient(155deg, #080a0f 0%, #142031 48%, #211827 100%);
  background-size: 32px 32px, 32px 32px, auto;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 18% 24%, rgba(255, 209, 102, 0.18) 0 1px, transparent 2px),
    radial-gradient(circle at 72% 18%, rgba(98, 182, 255, 0.2) 0 1px, transparent 2px),
    radial-gradient(circle at 84% 74%, rgba(73, 198, 164, 0.18) 0 1px, transparent 2px),
    radial-gradient(circle at 34% 82%, rgba(255, 107, 138, 0.16) 0 1px, transparent 2px);
  background-size: 140px 140px, 190px 190px, 170px 170px, 220px 220px;
  opacity: 0.9;
}

.home-screen {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 18px;
  padding: 24px;
  overflow: hidden;
  text-align: center;
  background:
    linear-gradient(rgba(255, 255, 255, 0.026) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.026) 1px, transparent 1px),
    radial-gradient(circle at 50% 42%, rgba(98, 182, 255, 0.18), transparent 38%),
    linear-gradient(155deg, #070a10 0%, #111827 52%, #1c1722 100%);
  background-size: 34px 34px, 34px 34px, auto, auto;
  transition: opacity 0.34s ease, transform 0.34s ease, visibility 0.34s ease;
}

.home-screen.is-hidden {
  visibility: hidden;
  opacity: 0;
  transform: scale(1.02);
  pointer-events: none;
}

.language-switch {
  position: absolute;
  top: 18px;
  right: 18px;
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px;
  padding: 4px;
  border: 1px solid rgba(245, 241, 232, 0.16);
  border-radius: 8px;
  background: rgba(6, 10, 16, 0.58);
}

.language-switch button {
  min-width: 42px;
  min-height: 34px;
  padding: 6px 9px;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  border-color: transparent;
  box-shadow: none;
}

.language-switch button[aria-pressed="true"] {
  color: #071015;
  background: var(--sun);
}

.home-art {
  position: relative;
  width: min(70vw, 280px);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
}

.home-art::before,
.home-art::after {
  content: "";
  position: absolute;
  border: 1px solid rgba(98, 182, 255, 0.18);
  border-radius: 50%;
  animation: home-orbit 8s linear infinite;
}

.home-art::before {
  inset: 16%;
}

.home-art::after {
  inset: 2%;
  animation-duration: 13s;
  animation-direction: reverse;
}

.home-dot {
  position: absolute;
  width: 42px;
  aspect-ratio: 1;
  border-radius: 50%;
  box-shadow: 0 0 34px currentColor;
  animation: home-float 2.2s ease-in-out infinite;
}

.home-dot.sun {
  color: var(--sun);
  background: var(--sun);
  transform: translate(-32px, -16px);
}

.home-dot.reef {
  color: var(--reef);
  background: var(--reef);
  transform: translate(28px, 28px);
  animation-delay: -0.45s;
}

.home-dot.rose {
  color: var(--rose);
  background: var(--rose);
  transform: translate(52px, -46px);
  animation-delay: -0.9s;
}

.home-line {
  position: absolute;
  width: 104px;
  height: 2px;
  border-radius: 99px;
  background: rgba(245, 241, 232, 0.28);
  transform-origin: left center;
}

.home-line.one {
  transform: translate(-30px, -9px) rotate(36deg);
}

.home-line.two {
  transform: translate(0, -26px) rotate(136deg);
  width: 82px;
}

.home-copy {
  display: grid;
  gap: 10px;
}

.home-copy h1 {
  font-size: clamp(3rem, 12vw, 6rem);
}

.home-subtitle {
  width: min(92vw, 520px);
  color: var(--muted);
  font-size: clamp(1rem, 2.8vw, 1.2rem);
  line-height: 1.55;
}

.home-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

#homeStartButton {
  min-width: 160px;
  background: linear-gradient(135deg, var(--sun), var(--reef));
  box-shadow: 0 16px 34px rgba(73, 198, 164, 0.22);
}

.home-best {
  display: grid;
  gap: 4px;
  min-width: 140px;
  padding: 12px 16px;
  border: 1px solid rgba(245, 241, 232, 0.14);
  border-radius: 8px;
  background: rgba(6, 10, 16, 0.5);
}

.home-best strong {
  color: var(--sun);
  font-size: 1.45rem;
}

@keyframes home-float {
  0%,
  100% {
    margin-top: -3px;
  }

  50% {
    margin-top: 8px;
  }
}

@keyframes home-orbit {
  to {
    transform: rotate(360deg);
  }
}

.app-shell {
  position: relative;
  width: min(96vw, 920px);
  height: min(96svh, 720px);
  display: grid;
  grid-template-columns: minmax(320px, 430px) minmax(250px, 310px);
  gap: clamp(10px, 2vh, 18px);
  align-items: stretch;
  justify-content: center;
}

.sky-panel,
.command-panel {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.06), transparent 36%),
    var(--panel);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.45);
}

.sky-panel {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  place-items: center;
  gap: 10px;
  padding: clamp(10px, 1.8vh, 16px);
  border-color: rgba(255, 209, 102, 0.28);
  box-shadow:
    0 24px 70px rgba(0, 0, 0, 0.48),
    0 0 0 1px rgba(255, 209, 102, 0.07),
    inset 0 0 42px rgba(98, 182, 255, 0.08);
}

.sky-panel::after {
  content: "";
  position: absolute;
  inset: 12px;
  pointer-events: none;
  border: 1px solid rgba(245, 241, 232, 0.09);
  border-radius: 6px;
}

#gameHost canvas,
#nextCanvas {
  display: block;
  width: 100%;
  max-width: 100%;
  border: 1px solid rgba(245, 241, 232, 0.18);
  border-radius: 6px;
  background: #070a10;
}

#gameHost {
  width: auto;
  height: min(100%, 660px);
  max-height: calc(96svh - 34px);
  aspect-ratio: 3 / 5;
  overflow: hidden;
  border-radius: 6px;
  touch-action: none;
  user-select: none;
  box-shadow:
    0 18px 42px rgba(0, 0, 0, 0.4),
    0 0 34px rgba(98, 182, 255, 0.14);
}

#gameHost canvas {
  width: 100%;
  height: 100%;
}

.command-panel {
  display: flex;
  flex-direction: column;
  gap: clamp(8px, 1.7vh, 14px);
  padding: clamp(12px, 2vh, 18px);
}

.brand {
  display: grid;
  gap: 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid rgba(245, 241, 232, 0.1);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(2rem, 4.6vw, 2.65rem);
  line-height: 1;
  letter-spacing: 0;
  color: #fff7dc;
  white-space: nowrap;
  text-shadow: 0 0 20px rgba(255, 209, 102, 0.26);
}

.label {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

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

.stat-box,
.preview-box {
  border: 1px solid rgba(245, 241, 232, 0.13);
  border-radius: 6px;
  background: rgba(6, 10, 16, 0.58);
}

.stat-box {
  min-height: clamp(58px, 10vh, 74px);
  padding: 9px 8px;
  display: grid;
  align-content: center;
  gap: 7px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.stat-box strong {
  font-size: clamp(1.2rem, 3vw, 1.55rem);
  line-height: 1;
}

.stat-box:nth-child(1) strong {
  color: var(--sun);
}

.stat-box:nth-child(2) strong {
  color: var(--reef);
}

.stat-box:nth-child(3) strong {
  color: var(--sky);
}

.stat-box:nth-child(4) strong {
  color: var(--rose);
}

.stat-box:nth-child(5) strong {
  color: #fff7dc;
}

.wide-stat {
  grid-column: span 2;
}

.preview-box {
  padding: 10px;
  display: grid;
  gap: 12px;
  border-color: rgba(98, 182, 255, 0.22);
}

.stats .preview-box {
  grid-column: 1 / -1;
}

#nextCanvas {
  justify-self: center;
  width: min(100%, 138px);
  box-shadow: inset 0 0 26px rgba(98, 182, 255, 0.09);
}

.controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
}

button {
  appearance: none;
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 10px 12px;
  font: inherit;
  font-weight: 800;
  color: #071015;
  cursor: pointer;
  transition: transform 0.16s ease, filter 0.16s ease, border-color 0.16s ease;
}

button:hover {
  filter: brightness(1.07);
  transform: translateY(-1px);
}

button:disabled {
  cursor: not-allowed;
  filter: grayscale(0.6) brightness(0.75);
  opacity: 0.65;
  transform: none;
}

#startButton {
  grid-column: 1 / -1;
  background: linear-gradient(135deg, var(--sun), var(--reef));
  box-shadow: 0 10px 24px rgba(73, 198, 164, 0.24);
}

.boost {
  color: #071015;
  background: linear-gradient(135deg, var(--rose), var(--sun));
  box-shadow: 0 10px 24px rgba(255, 107, 138, 0.18);
}

.secondary {
  color: var(--text);
  background: rgba(98, 182, 255, 0.18);
  border-color: rgba(98, 182, 255, 0.32);
}

.ghost {
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(245, 241, 232, 0.18);
}

.rules {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.9rem;
  padding-top: 2px;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: none;
  place-items: center;
  padding: 18px;
  background: rgba(4, 7, 12, 0.68);
  backdrop-filter: blur(10px);
}

.modal.is-open {
  display: grid;
}

.modal-card {
  width: min(92vw, 360px);
  max-height: min(86svh, 640px);
  overflow: auto;
  border: 1px solid rgba(245, 241, 232, 0.18);
  border-radius: 8px;
  padding: 16px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.08), transparent 42%),
    rgba(16, 24, 34, 0.96);
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.58);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 14px;
}

.modal.rules-only .modal-actions {
  display: none;
}

.modal.rules-only .rules {
  display: grid;
}

.bonus-copy {
  margin: 0 0 14px;
  color: var(--muted);
  line-height: 1.5;
}

.color-choices {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 9px;
}

.color-choice {
  width: 100%;
  min-width: 0;
  aspect-ratio: 1;
  min-height: 54px;
  padding: 0;
  border-radius: 8px;
  border-color: rgba(245, 241, 232, 0.22);
  background: var(--choice-color);
  box-shadow:
    inset 0 0 0 8px rgba(255, 255, 255, 0.16),
    0 12px 28px var(--choice-glow);
}

.color-choice:disabled {
  cursor: not-allowed;
  filter: grayscale(1);
  opacity: 0.36;
  box-shadow: none;
}

.tutorial-copy {
  margin: 12px 0 16px;
  color: var(--text);
  font-size: 1rem;
  line-height: 1.58;
}

.tutorial-visual {
  min-height: 96px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(245, 241, 232, 0.12);
  border-radius: 8px;
  background:
    linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    rgba(6, 10, 16, 0.62);
  background-size: 24px 24px;
}

.tutorial-demo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.tutorial-dot {
  width: 28px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--dot-color);
  box-shadow: 0 0 20px var(--dot-color);
}

.tutorial-key {
  min-width: 42px;
  padding: 8px 10px;
  border: 1px solid rgba(245, 241, 232, 0.18);
  border-radius: 6px;
  color: var(--text);
  font-weight: 800;
  text-align: center;
  background: rgba(245, 241, 232, 0.07);
}

.tutorial-arrow {
  color: var(--sun);
  font-size: 1.6rem;
  font-weight: 900;
}

.tutorial-actions {
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 8px;
}

h2 {
  color: #fff7dc;
  font-size: 1.35rem;
  line-height: 1;
}

.icon-button {
  min-width: 38px;
  width: 38px;
  min-height: 38px;
  padding: 0;
  color: var(--text);
  background: rgba(245, 241, 232, 0.08);
  border-color: rgba(245, 241, 232, 0.18);
  font-size: 1.4rem;
  line-height: 1;
}

.rules p {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.rules .rules-intro {
  display: block;
  line-height: 1.55;
  color: var(--text);
}

.rules span {
  min-width: 118px;
  padding: 4px 7px;
  border: 1px solid rgba(245, 241, 232, 0.15);
  border-radius: 5px;
  color: var(--text);
  text-align: center;
  background: rgba(245, 241, 232, 0.07);
}

.rules p > span:last-child:not(:first-child) {
  flex: 1;
  min-width: 0;
  padding: 0;
  border: 0;
  color: var(--muted);
  text-align: left;
  background: transparent;
}

@media (max-height: 680px) and (min-width: 701px) {
  #nextCanvas {
    width: min(100%, 112px);
  }
}

@media (max-height: 610px) and (min-width: 701px) {
  .preview-box {
    display: none;
  }

  .stat-box {
    min-height: 56px;
  }
}

@media (max-width: 700px) {
  html,
  body {
    min-height: 100%;
  }

  body {
    overflow: hidden;
    min-height: 100svh;
    padding: 6px;
    place-items: start center;
    touch-action: none;
  }

  .app-shell {
    width: min(100%, 460px);
    height: calc(100svh - 12px);
    min-height: 0;
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
    gap: 7px;
  }

  .command-panel {
    order: -1;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "brand controls"
      "stats stats";
    align-items: center;
    gap: 8px;
    padding: 8px;
    overflow: visible;
  }

  .brand {
    grid-area: brand;
    min-width: 0;
    gap: 0;
    padding-bottom: 0;
    border-bottom: 0;
  }

  .brand .label {
    display: none;
  }

  h1 {
    font-size: clamp(1.2rem, 5.4vw, 1.58rem);
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .stats {
    grid-area: stats;
    min-width: 0;
    display: grid;
    grid-template-columns: minmax(72px, 1fr) 58px minmax(72px, 1fr) 54px;
    gap: 6px;
    align-items: stretch;
  }

  .stat-box {
    min-width: 0;
    min-height: 54px;
    padding: 6px 8px;
    gap: 4px;
  }

  .stat-box:nth-child(2),
  .stat-box:nth-child(5) {
    display: none;
  }

  .level-stat {
    padding-inline: 6px;
    border-color: rgba(255, 209, 102, 0.32);
    background: rgba(255, 209, 102, 0.08);
  }

  .level-stat .label {
    font-size: 0.48rem;
  }

  .level-stat strong {
    color: var(--sun);
  }

  .stat-box .label {
    font-size: 0.56rem;
    letter-spacing: 0.04em;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .stat-box strong {
    font-size: 1.08rem;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .wide-stat {
    grid-column: auto;
  }

  .rules {
    display: none;
  }

  .stats .preview-box {
    grid-area: auto;
    grid-column: auto;
    width: 54px;
    height: 54px;
    aspect-ratio: 1;
    padding: 4px;
    display: grid;
    place-items: center;
    gap: 0;
    border-color: rgba(98, 182, 255, 0.28);
  }

  .preview-box .label {
    display: none;
  }

  #nextCanvas {
    width: 42px;
    height: 42px;
  }

  .controls {
    grid-area: controls;
    display: flex;
    gap: 5px;
    justify-content: end;
  }

  #startButton,
  #restartButton {
    display: none;
  }

  #helperButton,
  #pauseButton,
  #helpButton {
    min-height: 36px;
    padding: 7px 9px;
    font-size: 0.78rem;
    white-space: nowrap;
  }

  #helperButton,
  #pauseButton {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 42px;
  }

  .sky-panel {
    min-height: 0;
    padding: 6px;
    gap: 0;
  }

  #gameHost {
    width: auto;
    height: min(100%, calc((100vw - 24px) * 1.6667));
    max-width: 100%;
    max-height: 100%;
  }

}

@media (max-width: 380px) {
  #gameHost {
    height: min(100%, calc((100vw - 22px) * 1.6667));
  }

  h1 {
    font-size: 1.08rem;
  }

  .stat-box .label {
    font-size: 0.48rem;
  }

  .controls {
    gap: 4px;
  }

  #helperButton,
  #pauseButton,
  #helpButton {
    min-height: 34px;
    padding: 6px 7px;
    font-size: 0.72rem;
  }

  .stats {
    grid-template-columns: minmax(62px, 1fr) 50px minmax(62px, 1fr) 48px;
    gap: 5px;
  }

  .stat-box {
    min-height: 48px;
  }

  .stats .preview-box {
    width: 48px;
    height: 48px;
  }

  #nextCanvas {
    width: 36px;
    height: 36px;
  }
}
