:root {
  color-scheme: dark;
  --page-bg: #080a0e;
  --panel-bg: rgba(18, 22, 29, 0.92);
  --panel-line: rgba(255, 255, 255, 0.14);
  --text: #f6f7fb;
  --muted: #b6bfcb;
  --accent: #ffcf3f;
  --accent-strong: #f25d3d;
  --surface: #11151d;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  background: var(--page-bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
textarea,
select {
  font: inherit;
}

[hidden] {
  display: none !important;
}

.start-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px;
  background: linear-gradient(180deg, #151922 0%, #080a0e 100%);
}

.start-panel {
  width: min(620px, 100%);
  padding: clamp(28px, 6vw, 56px);
  border: 1px solid var(--panel-line);
  border-radius: 8px;
  background: rgba(13, 17, 24, 0.86);
  text-align: center;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.32);
}

.eyebrow {
  margin: 0 0 12px;
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 18px;
  font-size: clamp(2.4rem, 7vw, 5rem);
  line-height: 0.95;
  letter-spacing: 0;
}

.level-set {
  min-height: 1.5em;
  margin-bottom: 30px;
  color: var(--muted);
  font-size: clamp(1rem, 2.3vw, 1.25rem);
}

.lesson-label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  text-transform: uppercase;
}

.lesson-select {
  width: min(360px, 100%);
  min-height: 52px;
  margin-bottom: 14px;
  padding: 0 44px 0 16px;
  border: 1px solid var(--panel-line);
  border-radius: 8px;
  background: #171c25;
  color: var(--text);
  cursor: pointer;
  font-weight: 750;
}

.lesson-select:focus-visible {
  outline: 3px solid #73d5ff;
  outline-offset: 4px;
}

.lesson-select:disabled {
  cursor: wait;
  opacity: 0.58;
}

.primary-button,
.secondary-button {
  min-width: 190px;
  min-height: 58px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 850;
}

.primary-button {
  border: 0;
  background: var(--accent);
  color: #151009;
  box-shadow: 0 12px 32px rgba(255, 207, 63, 0.28);
}

.primary-button:hover:not(:disabled) {
  background: #ffe07a;
}

.secondary-button {
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
}

.secondary-button:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.14);
}

.primary-button:focus-visible,
.secondary-button:focus-visible,
.exit-button:focus-visible,
.play-surface:focus-visible {
  outline: 3px solid #73d5ff;
  outline-offset: 4px;
}

.primary-button:disabled,
.secondary-button:disabled,
.exit-button:disabled {
  cursor: wait;
  opacity: 0.58;
  box-shadow: none;
}

.load-error {
  margin: 22px auto 0;
  max-width: 48ch;
  color: #ffc3b6;
}

.game-screen {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background: #050608;
}

.play-surface {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #050608;
  user-select: none;
  touch-action: manipulation;
}

.frame-image {
  display: block;
  max-width: 100vw;
  max-height: 100vh;
  width: auto;
  height: auto;
  object-fit: contain;
  pointer-events: none;
}

.progress-chip {
  position: fixed;
  top: 14px;
  left: 14px;
  z-index: 20;
  padding: 8px 12px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 999px;
  background: rgba(8, 10, 14, 0.76);
  color: rgba(255, 255, 255, 0.9);
  font-size: 0.9rem;
  font-weight: 700;
  line-height: 1;
  backdrop-filter: blur(8px);
  pointer-events: none;
}

.exit-button {
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 34;
  min-width: 58px;
  min-height: 44px;
  padding: 8px 14px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 999px;
  background: rgba(8, 10, 14, 0.72);
  color: rgba(255, 255, 255, 0.88);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 800;
  line-height: 1;
  backdrop-filter: blur(8px);
}

.exit-button:hover:not(:disabled) {
  background: rgba(32, 38, 49, 0.86);
  color: var(--text);
}

.hotspot {
  position: fixed;
  z-index: 10;
  border-radius: 50%;
  pointer-events: none;
  transform-origin: center;
  isolation: isolate;
  will-change: opacity, transform;
  --hotspot-core: #fff8dc;
  --hotspot-glow: rgba(255, 211, 64, 0.72);
  --hotspot-bloom: rgba(255, 183, 40, 0.34);
  --hotspot-rim: rgba(24, 14, 3, 0.66);
}

.hotspot-layer {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  transform-origin: center;
}

.hotspot-core {
  z-index: 3;
  border: 3px solid var(--hotspot-core);
  background:
    radial-gradient(circle, rgba(255, 232, 125, 0.18) 0 40%, rgba(255, 209, 61, 0.08) 54%, transparent 68%);
  box-shadow:
    0 0 0 1px var(--hotspot-rim),
    inset 0 0 0 1px rgba(38, 22, 4, 0.38),
    0 0 8px 1px rgba(255, 249, 218, 0.88),
    0 0 18px 5px var(--hotspot-glow),
    0 0 36px 11px var(--hotspot-bloom);
  animation: hotspot-core-breathe 2200ms ease-in-out infinite;
  will-change: filter, transform;
}

.hotspot-core::before,
.hotspot-core::after {
  content: "";
  position: absolute;
  border-radius: inherit;
  pointer-events: none;
}

.hotspot-core::before {
  inset: -48%;
  z-index: -1;
  background:
    radial-gradient(circle, rgba(255, 237, 156, 0.24) 0 30%, rgba(255, 213, 62, 0.18) 45%, rgba(255, 174, 32, 0.08) 58%, transparent 72%);
  filter: blur(1px);
}

.hotspot-core::after {
  inset: -1px;
  border: 1px solid var(--hotspot-rim);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.24);
}

.hotspot-pulse {
  z-index: 1;
  border: 2px solid rgba(255, 246, 204, 0.78);
  box-shadow:
    0 0 0 1px rgba(44, 26, 4, 0.28),
    0 0 13px rgba(255, 219, 92, 0.5),
    0 0 26px rgba(255, 186, 36, 0.24);
  opacity: 0;
  animation: hotspot-sonar 1400ms ease-out infinite;
  will-change: opacity, transform;
}

.hotspot-pulse-delayed {
  animation-delay: -700ms;
}

.hotspot.is-popping {
  animation: hotspot-pop 220ms cubic-bezier(0.2, 0.9, 0.24, 1.18) both;
}

.key-prompt {
  position: fixed;
  left: 50%;
  bottom: clamp(18px, 4vh, 42px);
  z-index: 30;
  display: flex;
  max-width: calc(100vw - 28px);
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid rgba(255, 217, 96, 0.34);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(24, 21, 14, 0.88), rgba(8, 10, 14, 0.8));
  box-shadow:
    0 0 0 1px rgba(36, 21, 3, 0.3),
    0 10px 28px rgba(0, 0, 0, 0.32),
    0 0 20px rgba(255, 205, 58, 0.16);
  transform: translateX(-50%);
  transform-origin: center;
  backdrop-filter: blur(8px);
  flex-wrap: wrap;
  will-change: opacity, transform;
}

.key-prompt.is-popping {
  animation: key-prompt-pop 180ms cubic-bezier(0.2, 0.9, 0.24, 1.18) both;
}

.key-prompt-text {
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 700;
}

.key-cap {
  min-width: 42px;
  min-height: 38px;
  display: inline-grid;
  place-items: center;
  padding: 7px 12px 8px;
  border: 1px solid rgba(255, 213, 83, 0.42);
  border-bottom-width: 4px;
  border-radius: 7px;
  background: #fff6d8;
  color: #11151d;
  font-weight: 850;
  line-height: 1;
  white-space: nowrap;
  box-shadow: 0 0 14px rgba(255, 210, 69, 0.16);
}

.key-plus {
  color: rgba(255, 255, 255, 0.75);
  font-weight: 850;
}

.mascot {
  position: fixed;
  right: clamp(10px, 2vw, 28px);
  bottom: clamp(8px, 2vw, 22px);
  z-index: 28;
  width: clamp(132px, 22vw, 260px);
  height: auto;
  pointer-events: none;
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.35));
  transform-origin: center;
  will-change: left, top, width, height, transform, filter, opacity;
}

.mascot.is-guiding,
.mascot.is-celebrating {
  right: auto;
  bottom: auto;
  object-fit: contain;
}

.mascot.is-celebrating {
  z-index: 45;
}

.win-overlay,
.confirm-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.58);
}

.win-overlay {
  z-index: 40;
  animation: overlay-in 220ms ease-out both;
}

.confirm-overlay {
  z-index: 50;
}

.win-panel,
.confirm-panel {
  width: min(480px, 100%);
  padding: clamp(26px, 5vw, 42px);
  border: 1px solid var(--panel-line);
  border-radius: 8px;
  background: var(--panel-bg);
  text-align: center;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.44);
}

.win-panel {
  transform-origin: center;
  animation: win-panel-in 260ms cubic-bezier(0.2, 0.84, 0.22, 1) both;
}

.confirm-panel {
  width: min(390px, 100%);
}

@keyframes hotspot-pop {
  0% {
    opacity: 0;
    transform: scale(0.72);
  }

  66% {
    opacity: 1;
    transform: scale(1.16);
  }

  100% {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes hotspot-core-breathe {
  0%,
  100% {
    filter: brightness(1);
    transform: scale(1);
  }

  50% {
    filter: brightness(1.12);
    transform: scale(1.06);
  }
}

@keyframes hotspot-sonar {
  0% {
    opacity: 0.72;
    transform: scale(1);
  }

  62% {
    opacity: 0.24;
  }

  100% {
    opacity: 0;
    transform: scale(1.7);
  }
}

@keyframes key-prompt-pop {
  0% {
    opacity: 0;
    transform: translateX(-50%) scale(0.86);
  }

  68% {
    opacity: 1;
    transform: translateX(-50%) scale(1.07);
  }

  100% {
    opacity: 1;
    transform: translateX(-50%) scale(1);
  }
}

@keyframes overlay-in {
  0% {
    opacity: 0;
  }

  100% {
    opacity: 1;
  }
}

@keyframes win-panel-in {
  0% {
    opacity: 0;
    transform: scale(0.95);
  }

  100% {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes fade-in {
  0% {
    opacity: 0;
  }

  100% {
    opacity: 1;
  }
}

@keyframes key-prompt-fade-in {
  0% {
    opacity: 0;
    transform: translateX(-50%);
  }

  100% {
    opacity: 1;
    transform: translateX(-50%);
  }
}

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

  .hotspot.is-popping,
  .win-overlay,
  .win-panel {
    animation-name: fade-in;
  }

  .hotspot-core,
  .hotspot-pulse {
    animation: none !important;
  }

  .hotspot-pulse {
    opacity: 0;
  }

  .key-prompt.is-popping {
    animation-name: key-prompt-fade-in;
  }
}

.win-panel h2,
.confirm-panel h2 {
  margin-bottom: 12px;
  font-size: clamp(2rem, 8vw, 4.5rem);
  line-height: 0.95;
  letter-spacing: 0;
}

.confirm-panel h2 {
  margin-bottom: 24px;
  font-size: clamp(1.7rem, 7vw, 2.45rem);
}

.win-panel p {
  margin-bottom: 28px;
  color: var(--muted);
  font-size: 1.18rem;
  font-weight: 700;
}

.win-actions,
.dialog-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

.win-actions .primary-button,
.win-actions .secondary-button,
.dialog-actions .primary-button,
.dialog-actions .secondary-button {
  min-width: 150px;
  min-height: 52px;
}

@media (max-width: 560px) {
  .start-screen {
    padding: 16px;
  }

  .start-panel {
    padding: 28px 20px;
  }

  .primary-button,
  .secondary-button {
    width: 100%;
  }

  .progress-chip {
    max-width: calc(100vw - 104px);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .exit-button {
    min-width: 52px;
    padding: 8px 12px;
  }

  .key-prompt {
    gap: 7px;
    padding: 10px;
  }

  .key-cap {
    min-width: 36px;
    min-height: 34px;
    padding: 6px 9px 7px;
    font-size: 0.9rem;
  }
}
