:root {
  color-scheme: dark;
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  background: #020b18;
  color: #eff9ff;
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  min-width: 280px;
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background:
    radial-gradient(circle at 50% -20%, rgba(78, 201, 255, 0.28), transparent 48%),
    linear-gradient(150deg, #031326, #020817 68%, #061830);
}

button { font: inherit; }

.game-shell {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: 100%;
  height: 100%;
  min-height: 300px;
  isolation: isolate;
}

.game-shell::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  opacity: 0.42;
  background-image:
    linear-gradient(120deg, transparent 46%, rgba(154, 230, 255, 0.08) 47%, transparent 48%),
    linear-gradient(60deg, transparent 46%, rgba(154, 230, 255, 0.06) 47%, transparent 48%);
  background-size: 70px 70px;
}

.hud {
  display: grid;
  grid-template-columns: minmax(13rem, auto) minmax(18rem, 1fr) auto;
  align-items: center;
  gap: clamp(0.45rem, 2vw, 1.2rem);
  padding: max(0.45rem, env(safe-area-inset-top)) max(0.55rem, env(safe-area-inset-right)) 0.55rem max(0.55rem, env(safe-area-inset-left));
  border-bottom: 1px solid rgba(125, 211, 252, 0.2);
  background:
    linear-gradient(180deg, rgba(13, 50, 83, 0.94), rgba(1, 11, 27, 0.92));
  backdrop-filter: blur(12px);
  box-shadow: inset 0 1px rgba(255, 255, 255, 0.12), 0 10px 30px rgba(0, 0, 0, 0.34);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
  margin-right: auto;
  color: inherit;
  text-decoration: none;
  transition: filter 160ms ease, transform 160ms ease;
}

.brand:hover { filter: brightness(1.1); transform: translateY(-1px); }
.brand:focus-visible { outline: 3px solid #bae6fd; outline-offset: 3px; border-radius: 0.55rem; }
.brand__logo {
  display: block;
  width: clamp(8.2rem, 17vw, 10.8rem);
  height: auto;
  flex: 0 0 auto;
  filter: drop-shadow(0 0 0.28rem rgba(56, 189, 248, 0.42)) drop-shadow(0 0.2rem 0.22rem rgba(0, 0, 0, 0.7));
}
.brand__game-name { padding-left: 0.65rem; border-left: 1px solid rgba(125, 211, 252, 0.28); }

.brand__flake {
  display: grid;
  place-items: center;
  width: clamp(2rem, 5vw, 2.7rem);
  aspect-ratio: 1;
  flex: 0 0 auto;
  border: 1px solid rgba(186, 230, 253, 0.48);
  border-radius: 0.8rem;
  background: linear-gradient(145deg, rgba(125, 211, 252, 0.35), rgba(30, 64, 175, 0.2));
  box-shadow: inset 0 1px rgba(255, 255, 255, 0.35), 0 8px 28px rgba(14, 165, 233, 0.18);
  color: #e0f7ff;
}

.brand strong,
.brand small { display: block; }
.brand strong { font-size: clamp(0.78rem, 2vw, 1.05rem); }
.brand small { color: #7dd3fc; font-size: clamp(0.52rem, 1.2vw, 0.68rem); }

.hud__stats {
  display: grid;
  grid-template-columns: repeat(5, minmax(3rem, 4.8rem));
  justify-content: end;
  gap: clamp(0.25rem, 1vw, 0.6rem);
}

.hud__stats > span {
  display: grid;
  min-width: clamp(3rem, 8vw, 4.8rem);
  padding: 0.32rem 0.48rem;
  border: 1px solid rgba(125, 211, 252, 0.16);
  border-radius: 0.7rem;
  background: linear-gradient(150deg, rgba(22, 78, 118, 0.88), rgba(3, 20, 42, 0.82));
  text-align: center;
  box-shadow: inset 0 1px rgba(255, 255, 255, 0.16), inset 0 -3px rgba(0, 0, 0, 0.22), 0 5px 12px rgba(0, 0, 0, 0.18);
}

.hud__stats small { color: #7dd3fc; font-size: clamp(0.48rem, 1vw, 0.58rem); text-transform: uppercase; letter-spacing: 0.08em; }
.hud__stats strong { color: #f0f9ff; font-size: clamp(0.7rem, 1.7vw, 0.92rem); font-variant-numeric: tabular-nums; }

.hud__button,
.hud__icon-button,
.start-card button,
.result-card button {
  border: 1px solid rgba(186, 230, 253, 0.45);
  border-radius: 0.75rem;
  color: #fff;
  background: linear-gradient(145deg, #0ea5e9, #2563eb);
  box-shadow: inset 0 1px rgba(255, 255, 255, 0.32), 0 8px 24px rgba(14, 165, 233, 0.25);
  font-weight: 800;
  cursor: pointer;
  transition: transform 140ms ease, filter 140ms ease;
}

.hud__controls {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.4rem;
}

.hud__button,
.hud__icon-button,
.language-control select {
  min-width: 2.75rem;
  min-height: 2.75rem;
}

.hud__button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  padding: 0.55rem 0.75rem;
  font-size: clamp(0.62rem, 1.3vw, 0.78rem);
}

.hud__icon-button {
  display: inline-grid;
  place-items: center;
  padding: 0.55rem;
  color: #dff8ff;
  background: linear-gradient(145deg, rgba(17, 94, 140, 0.94), rgba(3, 27, 58, 0.96));
}

.sound-icon { width: 1.25rem; height: 1.25rem; fill: currentColor; }
.sound-icon--off { display: none; }
.hud__icon-button[aria-pressed="false"] .sound-icon--on { display: none; }
.hud__icon-button[aria-pressed="false"] .sound-icon--off { display: block; }

.language-control { position: relative; display: block; }
.language-control select {
  appearance: none;
  padding: 0.48rem 1.65rem 0.48rem 0.65rem;
  border: 1px solid rgba(186, 230, 253, 0.4);
  border-radius: 0.75rem;
  color: #effbff;
  background:
    linear-gradient(45deg, transparent 50%, #7dd3fc 50%) calc(100% - 0.75rem) 52% / 0.35rem 0.35rem no-repeat,
    linear-gradient(135deg, #0f5e8c, #061b3a);
  box-shadow: inset 0 1px rgba(255, 255, 255, 0.2), 0 6px 18px rgba(0, 0, 0, 0.2);
  font-size: 0.72rem;
  font-weight: 900;
  cursor: pointer;
}
.language-control select:focus-visible { outline: 3px solid #bae6fd; outline-offset: 2px; }
.language-control option { color: #061326; background: #e6f7ff; }
button:hover { filter: brightness(1.12); transform: translateY(-1px); }
button:focus-visible { outline: 3px solid #bae6fd; outline-offset: 2px; }

.stage { position: relative; min-height: 0; overflow: hidden; }

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: pointer;
  outline: none;
  -webkit-tap-highlight-color: transparent;
}

#game-canvas:focus-visible { box-shadow: inset 0 0 0 3px rgba(186, 230, 253, 0.8); }

.start-card,
.result-card {
  position: absolute;
  top: 50%;
  left: 50%;
  width: min(88%, 25rem);
  padding: clamp(1rem, 3vw, 1.6rem);
  transform: translate(-50%, -50%);
  border: 1px solid rgba(186, 230, 253, 0.42);
  border-radius: 1.35rem;
  background:
    linear-gradient(145deg, rgba(14, 83, 132, 0.94), rgba(3, 24, 50, 0.97)),
    #061a33;
  box-shadow:
    inset 0 2px rgba(255, 255, 255, 0.28),
    inset 0 -10px 25px rgba(0, 4, 20, 0.3),
    0 14px 0 rgba(1, 9, 25, 0.72),
    0 32px 80px rgba(0, 0, 0, 0.58),
    0 0 45px rgba(34, 211, 238, 0.16);
  text-align: center;
  max-height: calc(100% - 1rem);
  overflow: auto;
  overscroll-behavior: contain;
}

.start-card::before,
.result-card::before {
  content: "";
  position: absolute;
  inset: 1px;
  pointer-events: none;
  border-radius: inherit;
  background: linear-gradient(118deg, rgba(255,255,255,0.16), transparent 30%, transparent 70%, rgba(103,232,249,0.08));
}

.start-card__crystal {
  display: inline-grid;
  place-items: center;
  width: 3.5rem;
  aspect-ratio: 1;
  margin-bottom: 0.35rem;
  transform: rotate(45deg);
  border: 1px solid rgba(224, 247, 255, 0.75);
  border-radius: 0.75rem;
  color: #fff;
  background: linear-gradient(145deg, #bae6fd, #38bdf8 42%, #1d4ed8);
  box-shadow:
    inset 10px 10px 18px rgba(255, 255, 255, 0.48),
    inset -10px -10px 18px rgba(5, 45, 120, 0.5),
    8px 10px 0 rgba(3, 24, 60, 0.5),
    0 0 38px rgba(56, 189, 248, 0.62);
  animation: crystal-float 3.2s ease-in-out infinite;
}

.start-card__crystal::first-letter { transform: rotate(-45deg); }
.start-card__eyebrow,
.result-card__eyebrow { margin: 0.3rem 0; color: #7dd3fc; font-size: 0.7rem; font-weight: 900; letter-spacing: 0.12em; text-transform: uppercase; }
.start-card h1,
.result-card h2 { margin: 0.2rem 0 0.55rem; font-size: clamp(1.6rem, 5vw, 2.45rem); line-height: 1; }
.start-card p,
.result-card p { margin: 0 auto 1rem; max-width: 30rem; color: #c8eaf8; font-size: clamp(0.75rem, 2vw, 0.92rem); line-height: 1.5; }
.start-card button,
.result-card button { min-width: 11rem; padding: 0.72rem 1.25rem; }
.start-card small { display: block; margin-top: 0.7rem; color: #8bc9e4; font-size: 0.62rem; }
.result-card[hidden] { display: none; }
.result-card__icon { display: block; margin-bottom: 0.35rem; font-size: 2.6rem; filter: drop-shadow(0 0 18px rgba(125, 211, 252, 0.7)); }

.event-banner {
  position: absolute;
  z-index: 4;
  top: 16%;
  left: 50%;
  display: grid;
  min-width: min(78%, 25rem);
  padding: 0.8rem 1.35rem 0.95rem;
  transform: translate(-50%, -22px) scale(0.84) rotateX(-13deg);
  opacity: 0;
  overflow: hidden;
  border: 1px solid rgba(207, 250, 254, 0.75);
  border-radius: 1.15rem;
  color: #fff;
  background:
    linear-gradient(120deg, rgba(13, 148, 136, 0.96), rgba(8, 145, 178, 0.97) 48%, rgba(126, 34, 206, 0.96));
  box-shadow:
    inset 0 2px rgba(255, 255, 255, 0.32),
    inset 0 -8px rgba(9, 24, 70, 0.18),
    0 9px 0 rgba(4, 24, 54, 0.75),
    0 26px 55px rgba(0, 0, 0, 0.46),
    0 0 42px rgba(45, 212, 191, 0.42);
  text-align: center;
  transition: opacity 220ms ease, transform 380ms cubic-bezier(.2,.86,.2,1.18);
  perspective: 800px;
}

.event-banner::after {
  content: "";
  position: absolute;
  inset: -60% -20%;
  transform: translateX(-55%) rotate(18deg);
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.28), transparent);
  animation: banner-shine 1.35s ease-in-out infinite;
}

.event-banner[hidden] { display: none; }
.event-banner.is-visible { transform: translate(-50%, 0) scale(1) rotateX(0); opacity: 1; }
.event-banner strong { position: relative; z-index: 1; font-size: clamp(1rem, 3vw, 1.45rem); letter-spacing: 0.09em; }
.event-banner span { position: relative; z-index: 1; margin-top: 0.2rem; color: #dcfce7; font-size: clamp(0.68rem, 1.6vw, 0.82rem); font-weight: 800; }

@keyframes crystal-float {
  0%, 100% { transform: translateY(0) rotate(45deg); }
  50% { transform: translateY(-7px) rotate(45deg); }
}

@keyframes banner-shine {
  0% { transform: translateX(-70%) rotate(18deg); }
  100% { transform: translateX(70%) rotate(18deg); }
}

.help {
  margin: 0;
  padding: 0.4rem max(0.75rem, env(safe-area-inset-right)) max(0.4rem, env(safe-area-inset-bottom)) max(0.75rem, env(safe-area-inset-left));
  border-top: 1px solid rgba(125, 211, 252, 0.14);
  color: #8fc8df;
  background: rgba(2, 13, 30, 0.78);
  font-size: clamp(0.56rem, 1.4vw, 0.7rem);
  text-align: center;
}

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

@media (max-width: 860px) {
  .hud {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 0.42rem 0.55rem;
  }
  .hud__stats {
    grid-column: 1 / -1;
    grid-row: 2;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    justify-content: stretch;
  }
  .hud__stats > span { min-width: 0; }
  .brand small { display: none; }
}

@media (max-width: 520px) {
  .hud { padding-top: max(0.3rem, env(safe-area-inset-top)); }
  .brand__game-name { display: none; }
  .brand__logo { width: clamp(6.2rem, 31vw, 7.4rem); }
  .hud__stats { gap: 0.16rem; }
  .hud__stats > span { padding: 0.25rem 0.12rem; border-radius: 0.5rem; }
  .hud__stats small { overflow: hidden; font-size: clamp(0.39rem, 2vw, 0.5rem); letter-spacing: 0.03em; text-overflow: ellipsis; }
  .hud__stats strong { font-size: clamp(0.64rem, 3vw, 0.8rem); }
  .hud__controls { gap: 0.25rem; }
  .hud__button,
  .hud__icon-button,
  .language-control select { min-width: 2.5rem; min-height: 2.5rem; }
  .hud__button { padding-inline: 0.55rem; font-size: 0.82rem; }
  .hud__button-label { display: none; }
  .language-control select { padding-left: 0.48rem; padding-right: 1.25rem; background-position: calc(100% - 0.55rem) 52%, 0 0; }
  .start-card,
  .result-card { width: min(94%, 23rem); padding: 0.85rem; border-radius: 1rem; }
  .start-card__crystal { width: 2.65rem; }
  .start-card h1,
  .result-card h2 { font-size: clamp(1.35rem, 8vw, 1.9rem); }
  .start-card p,
  .result-card p { margin-bottom: 0.65rem; line-height: 1.35; }
  .start-card button,
  .result-card button { min-height: 2.75rem; }
  .help { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
}

@media (max-height: 520px) and (orientation: landscape) {
  .game-shell { grid-template-rows: auto minmax(0, 1fr); }
  .hud {
    grid-template-columns: auto minmax(15rem, 1fr) auto;
    gap: 0.35rem;
    padding: max(0.25rem, env(safe-area-inset-top)) max(0.35rem, env(safe-area-inset-right)) 0.25rem max(0.35rem, env(safe-area-inset-left));
  }
  .brand__logo { width: 5.8rem; }
  .brand__game-name { display: none; }
  .hud__stats { grid-column: auto; grid-row: auto; grid-template-columns: repeat(5, minmax(2.5rem, 1fr)); gap: 0.18rem; }
  .hud__stats > span { min-width: 0; padding-block: 0.2rem; }
  .hud__stats small { font-size: 0.4rem; }
  .hud__stats strong { font-size: 0.66rem; }
  .hud__button,
  .hud__icon-button,
  .language-control select { min-width: 2.25rem; min-height: 2.25rem; }
  .hud__button-label { display: none; }
  .help { display: none; }
  .start-card,
  .result-card { width: min(88%, 22rem); padding: 0.7rem; }
  .start-card__crystal { width: 2.3rem; margin-bottom: 0.1rem; }
  .start-card h1,
  .result-card h2 { font-size: 1.45rem; }
  .start-card p,
  .result-card p { margin-bottom: 0.55rem; font-size: 0.7rem; }
  .start-card small { margin-top: 0.35rem; }
}

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