:root {
  color-scheme: dark;
  --gold: #f1d592;
  --gold-strong: #ffe7a9;
  --ink: #080b18;
  --panel: rgba(9, 12, 28, 0.94);
  --panel-border: rgba(241, 213, 146, 0.38);
  --blue-glow: rgba(81, 169, 255, 0.72);
  --violet-glow: rgba(176, 93, 255, 0.65);
  --safe-top: max(18px, env(safe-area-inset-top));
  --safe-right: max(18px, env(safe-area-inset-right));
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--ink);
  font-family: Georgia, "Times New Roman", serif;
}

button { font: inherit; }

.app {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  isolation: isolate;
  background: #050711;
}

.scene-backdrop {
  position: absolute;
  inset: -4%;
  z-index: -2;
  background-position: center;
  background-size: cover;
  filter: blur(26px) brightness(.38) saturate(.85);
  transform: scale(1.08);
  transition: background-image .5s ease, opacity .5s ease;
}

.scene-backdrop::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at center, transparent 40%, rgba(2, 3, 10, .58) 100%);
}

.scene {
  width: 100vw;
  height: 100vh;
  display: grid;
  place-items: center;
}

.scene-stage {
  position: relative;
  width: min(100vw, 177.683vh);
  height: min(100vh, 56.28vw);
  aspect-ratio: 1672 / 941;
  overflow: hidden;
  background: #090b17;
  box-shadow: 0 0 80px rgba(0, 0, 0, .66);
}

.scene-image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: fill;
  user-select: none;
  -webkit-user-drag: none;
  transition: transform .72s cubic-bezier(.2,.72,.2,1), filter .5s ease;
}

.scene-stage.is-entering .scene-image {
  animation: sceneEnter .72s cubic-bezier(.2,.72,.2,1) both;
}

@keyframes sceneEnter {
  from { opacity: .2; transform: scale(1.035); filter: blur(2px); }
  to { opacity: 1; transform: scale(1); filter: blur(0); }
}

.hotspots {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.hotspot {
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: var(--w);
  height: var(--h);
  padding: 0;
  border: 1px solid transparent;
  border-radius: 22px;
  color: white;
  background: transparent;
  cursor: pointer;
  pointer-events: auto;
  outline: none;
  isolation: isolate;
}

.hotspot::before {
  content: "";
  position: absolute;
  inset: 3%;
  border-radius: inherit;
  opacity: 0;
  background: radial-gradient(circle at center, rgba(255, 232, 168, .14), rgba(80, 160, 255, .05) 52%, transparent 74%);
  box-shadow: inset 0 0 30px rgba(255, 220, 140, .12), 0 0 30px rgba(91, 168, 255, .22);
  transition: opacity .25s ease, transform .25s ease;
}

.hotspot:hover::before,
.hotspot:focus-visible::before {
  opacity: 1;
  transform: scale(1.035);
}

.hotspot:focus-visible {
  border-color: rgba(255, 230, 168, .85);
  box-shadow: 0 0 0 3px rgba(80, 150, 255, .38), 0 0 28px rgba(176, 93, 255, .5);
}

.hotspot-tooltip {
  position: absolute;
  left: 50%;
  bottom: 5%;
  transform: translate(-50%, 8px);
  max-width: 90%;
  padding: 7px 11px;
  border: 1px solid rgba(255, 232, 177, .36);
  border-radius: 999px;
  background: rgba(7, 9, 21, .86);
  color: #fff4d3;
  font: 600 clamp(10px, .78vw, 14px)/1.15 system-ui, sans-serif;
  text-align: center;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity .22s ease, transform .22s ease;
  box-shadow: 0 8px 24px rgba(0,0,0,.38);
}

.hotspot:hover .hotspot-tooltip,
.hotspot:focus-visible .hotspot-tooltip {
  opacity: 1;
  transform: translate(-50%, 0);
}

.hotspot.is-learned::after {
  content: "✓";
  position: absolute;
  top: 7%;
  right: 7%;
  display: grid;
  place-items: center;
  width: clamp(22px, 2vw, 32px);
  aspect-ratio: 1;
  border: 1px solid rgba(255, 231, 169, .58);
  border-radius: 50%;
  color: #fff2be;
  background: rgba(12, 37, 35, .86);
  font: 700 clamp(12px, 1vw, 17px)/1 system-ui, sans-serif;
  box-shadow: 0 0 18px rgba(84, 255, 202, .34);
}

.top-navigation {
  position: fixed;
  z-index: 40;
  top: var(--safe-top);
  right: var(--safe-right);
  display: flex;
  gap: 8px;
}

.nav-button,
.close-panel {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1px solid rgba(245, 216, 150, .52);
  border-radius: 50%;
  color: #fff1c6;
  background: rgba(8, 11, 27, .68);
  backdrop-filter: blur(12px);
  cursor: pointer;
  box-shadow: 0 6px 22px rgba(0,0,0,.35), inset 0 0 12px rgba(255, 225, 154, .06);
  transition: transform .2s ease, background .2s ease, box-shadow .2s ease;
}

.nav-button:hover,
.nav-button:focus-visible,
.close-panel:hover,
.close-panel:focus-visible {
  transform: translateY(-1px) scale(1.04);
  background: rgba(22, 29, 58, .88);
  box-shadow: 0 0 24px var(--blue-glow), inset 0 0 16px rgba(255, 226, 157, .12);
  outline: none;
}

.nav-button svg {
  width: 21px;
  fill: currentColor;
}

.progress-badge {
  position: fixed;
  z-index: 35;
  top: var(--safe-top);
  left: max(18px, env(safe-area-inset-left));
  display: flex;
  align-items: baseline;
  gap: 7px;
  padding: 9px 13px;
  border: 1px solid rgba(245, 216, 150, .32);
  border-radius: 999px;
  background: rgba(7, 9, 21, .62);
  backdrop-filter: blur(12px);
  color: #fff0c8;
  box-shadow: 0 6px 22px rgba(0,0,0,.3);
}

#progressText { font-weight: 700; }
.progress-label { font: 500 12px/1 system-ui, sans-serif; opacity: .8; }

.transition-curtain {
  position: fixed;
  z-index: 70;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(circle at center, rgba(137, 191, 255, .12), rgba(7, 8, 19, .96) 70%);
}

.transition-curtain.is-active {
  animation: curtain .68s ease both;
}

@keyframes curtain {
  0% { opacity: 0; }
  45% { opacity: 1; }
  100% { opacity: 0; }
}

.panel-overlay {
  position: fixed;
  z-index: 79;
  inset: 0;
  background: rgba(0, 2, 11, .48);
  backdrop-filter: blur(3px);
  opacity: 0;
  transition: opacity .32s ease;
}

.panel-overlay.is-open { opacity: 1; }

.lesson-panel {
  position: fixed;
  z-index: 80;
  top: 0;
  right: 0;
  width: min(520px, 92vw);
  height: 100dvh;
  border-left: 1px solid var(--panel-border);
  background:
    linear-gradient(180deg, rgba(35, 28, 61, .35), transparent 28%),
    var(--panel);
  box-shadow: -24px 0 70px rgba(0,0,0,.5);
  transform: translateX(104%);
  transition: transform .38s cubic-bezier(.2,.75,.2,1);
  overflow: hidden;
}

.lesson-panel.is-open { transform: translateX(0); }

.lesson-scroll {
  height: 100%;
  overflow-y: auto;
  padding: clamp(30px, 5vw, 58px) clamp(24px, 5vw, 52px) 46px;
  scrollbar-width: thin;
  scrollbar-color: rgba(241,213,146,.45) transparent;
}

.close-panel {
  position: absolute;
  z-index: 2;
  top: max(14px, env(safe-area-inset-top));
  right: max(14px, env(safe-area-inset-right));
  width: 38px;
  height: 38px;
  font: 300 27px/1 system-ui, sans-serif;
}

.lesson-eyebrow {
  margin: 0 48px 10px 0;
  color: #b9b5ff;
  font: 700 12px/1.2 system-ui, sans-serif;
  letter-spacing: .16em;
  text-transform: uppercase;
}

.lesson-panel h1 {
  margin: 0 0 17px;
  color: var(--gold-strong);
  font-size: clamp(31px, 5vw, 50px);
  line-height: .98;
  font-weight: 500;
  text-wrap: balance;
}

.lesson-intro {
  margin: 0 0 30px;
  color: rgba(255,255,255,.88);
  font: 400 17px/1.65 system-ui, sans-serif;
}

.lesson-section {
  margin-top: 25px;
  padding-top: 21px;
  border-top: 1px solid rgba(241, 213, 146, .16);
}

.lesson-section h2 {
  margin: 0 0 11px;
  color: #f3d792;
  font-size: 18px;
  font-weight: 600;
}

.lesson-section p,
.lesson-section li {
  color: rgba(255,255,255,.82);
  font: 400 15px/1.62 system-ui, sans-serif;
}

.lesson-section ul { margin: 0; padding-left: 20px; }
.lesson-section li + li { margin-top: 8px; }

.lesson-example,
.lesson-exercise,
.lesson-recall {
  padding: 18px;
  border: 1px solid rgba(241,213,146,.15);
  border-radius: 16px;
  background: rgba(255,255,255,.035);
}

.lesson-exercise { background: rgba(69, 118, 168, .09); }
.lesson-recall { background: rgba(132, 73, 175, .09); }

.lesson-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 30px;
}

.primary-button,
.secondary-button {
  min-height: 48px;
  padding: 11px 15px;
  border-radius: 12px;
  cursor: pointer;
  transition: transform .2s ease, box-shadow .2s ease, background .2s ease;
}

.primary-button {
  border: 1px solid rgba(255, 229, 162, .7);
  color: #17121f;
  background: linear-gradient(135deg, #ffe6a4, #cfaa59);
  font-weight: 700;
}

.primary-button.is-learned {
  color: #e6fff7;
  border-color: rgba(101, 255, 210, .45);
  background: rgba(29, 96, 77, .58);
}

.secondary-button {
  border: 1px solid rgba(177, 162, 255, .35);
  color: #eeeaff;
  background: rgba(89, 72, 147, .24);
}

.primary-button:hover,
.secondary-button:hover { transform: translateY(-1px); box-shadow: 0 8px 22px rgba(0,0,0,.28); }

.toast {
  position: fixed;
  z-index: 100;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  padding: 10px 16px;
  border: 1px solid rgba(241,213,146,.34);
  border-radius: 999px;
  background: rgba(7, 10, 24, .9);
  color: #fff2cd;
  font: 600 13px/1.2 system-ui, sans-serif;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
}

.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

[hidden] { display: none !important; }

@media (max-width: 740px) {
  .nav-button { width: 48px; height: 48px; }
  .progress-label { display: none; }
  .progress-badge { padding: 10px 13px; }

  .lesson-panel {
    top: auto;
    bottom: 0;
    width: 100%;
    height: min(84dvh, 760px);
    border-left: 0;
    border-top: 1px solid var(--panel-border);
    border-radius: 22px 22px 0 0;
    transform: translateY(104%);
  }

  .lesson-panel.is-open { transform: translateY(0); }
  .lesson-scroll { padding: 50px 22px max(34px, env(safe-area-inset-bottom)); }
  .lesson-actions { grid-template-columns: 1fr; }
  .hotspot-tooltip { display: none; }
}

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