:root {
  color-scheme: light;
  font-family: "Arial Rounded MT Bold", "PingFang SC", ui-rounded, system-ui, sans-serif;
  --green: #45c7ff;
  --green-dark: #159fe6;
  --green-soft: #d8f5ff;
  --orange: #28b8ff;
  --blue-deep: #0875c9;
  --glass: rgba(255, 255, 255, .42);
  --glass-strong: rgba(255, 255, 255, .66);
  --glass-border: rgba(255, 255, 255, .82);
  --control-blue-gradient: linear-gradient(145deg, #7cddff 0%, var(--green) 55%, #1fb2f0 100%);
  --ink: #171717;
  --muted: #6b7789;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { min-width: 320px; min-height: 100%; }
body { margin: 0; min-height: 100vh; display: grid; place-items: center; overflow: hidden; color: var(--ink); background: #f8fdff; }
button { font: inherit; -webkit-tap-highlight-color: transparent; }
button:focus, button:focus-visible { outline: none; }
[tabindex]:focus-visible { outline: 4px solid rgba(53, 127, 230, .38); outline-offset: 3px; }

.lesson-shell { position: relative; width: 100vw; min-height: min(100vh, 760px); height: 100vh; overflow: hidden; border: 0; background: #f8fdff; box-shadow: none; }

.lesson-header {
  position: absolute; inset: 0 0 auto 0; z-index: 20; height: 100px;
  display: flex; align-items: center; padding-top: 8px; padding-bottom: 8px;
  padding-left: max(clamp(36px, 4vw, 64px), calc(env(safe-area-inset-left, 0px) + 18px));
  padding-right: max(clamp(36px, 4vw, 64px), calc(env(safe-area-inset-right, 0px) + 18px));
  color: var(--blue-deep); background: transparent;
}
.lesson-title { display: grid; align-content: center; gap: 2px; margin-right: 20px; color: var(--green); line-height: 1.05; }
#course-code { color: var(--green); font-size: clamp(25px, 2.35vw, 34px); letter-spacing: .02em; text-shadow: none; }
.lesson-title span { font-size: clamp(16px, 1.45vw, 22px); font-weight: 900; letter-spacing: .04em; }
.header-actions { margin-left: auto; display: flex; gap: 18px; }

.round-button, .nav-button, .header-back-button {
  border: 1px solid var(--glass-border); border-radius: 50%; color: var(--blue-deep);
  background: linear-gradient(145deg, rgba(220,246,255,.88), rgba(92,204,250,.38));
  box-shadow: inset 0 1px 0 rgba(255,255,255,.98), inset 0 -2px 0 rgba(20,148,220,.2), 0 10px 0 rgba(14,137,202,.13), 0 15px 28px rgba(3,111,183,.22);
  backdrop-filter: blur(20px) saturate(180%); -webkit-backdrop-filter: blur(20px) saturate(180%);
  cursor: pointer; transition: transform .16s ease, filter .16s ease, box-shadow .16s ease;
}
.round-button { width: 84px; height: 84px; padding: 0; font-size: 27px; font-weight: 950; letter-spacing: 1px; }
.lesson-header .round-button, .lesson-header .header-back-button { color: #fff; border-color: rgba(255,255,255,.9); background: var(--control-blue-gradient); }
.round-button svg { width: 43px; height: 43px; display: block; margin: auto; color: #fff; fill: currentColor; filter: drop-shadow(0 2px 3px rgba(2,85,140,.35)); }
.audio-button { position: relative; }
.sound-bars { display: none; position: absolute; left: 50%; top: 50%; align-items: end; gap: 5px; height: 28px; transform: translate(-50%,-50%); }
.audio-button.playing .replay-icon { display: none; }
.audio-button.playing .sound-bars { display: flex; }
.sound-bars i { display: block; width: 5px; height: 35%; border-radius: 5px; background: #fff; animation: bars .55s infinite alternate; }
.sound-bars i:nth-child(2) { height: 90%; animation-delay: .16s; }
.sound-bars i:nth-child(3) { height: 58%; animation-delay: .32s; }
.header-back-button { flex: 0 0 auto; width: 72px; height: 72px; margin: 0 16px 0 0; padding: 0; color: #fff; text-shadow: 0 2px 4px rgba(2,85,140,.42); font-size: 44px; font-weight: 900; line-height: 1; }
.header-back-button span { display: block; width: 32px; height: 28px; margin: auto; background: currentColor; clip-path: polygon(0 50%, 55% 8%, 55% 34%, 100% 34%, 100% 66%, 55% 66%, 55% 92%); font-size: 0; }
.round-button:hover, .nav-button:not(:disabled):hover, .header-back-button:hover { transform: translateY(-2px) scale(1.02); filter: brightness(1.06) saturate(1.12); box-shadow: inset 0 1px 0 white, 0 10px 26px rgba(3,111,183,.28); }
.round-button:active, .nav-button:not(:disabled):active, .header-back-button:active { transform: translateY(5px) scale(.98); box-shadow: inset 0 1px 0 white, inset 0 -1px 0 rgba(20,148,220,.18), 0 4px 0 rgba(14,137,202,.13), 0 8px 18px rgba(3,111,183,.2); }

.lesson-scene {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 12% 15%, rgba(190, 239, 255, .45), transparent 27%),
    radial-gradient(circle at 90% 75%, rgba(203, 245, 255, .38), transparent 28%),
    #f8fdff;
}
.scene-counter { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.game-stage { position: absolute; inset: 86px 8px 104px; display: grid; place-items: center; }
.visual-stage { position: relative; width: min(100%, calc((100vh - 190px) * 1.7928)); height: 100%; max-height: 100%; aspect-ratio: auto; overflow: visible; cursor: default; background: transparent; }
.media-wrap { position: absolute; inset: 0; display: grid; place-items: center; overflow: visible; }
#main-image {
  position: absolute; inset: 0; display: block; width: 100%; height: 100%; object-fit: contain; object-position: 50% 50%;
  transform: translateY(var(--image-y, 0%)) scale(var(--image-scale, 1)); transform-origin: 50% 50%;
  user-select: none; -webkit-user-drag: none; filter: drop-shadow(0 10px 14px rgba(4,83,132,.1)); transition: opacity .12s ease;
}
.caption-wrap {
  position: absolute; z-index: 15;
  left: max(clamp(44px, 5vw, 84px), calc(env(safe-area-inset-left, 0px) + 22px));
  right: max(clamp(44px, 5vw, 84px), calc(env(safe-area-inset-right, 0px) + 22px));
  bottom: 24px; --nav-control-height: 108px; --caption-height: 104px;
  display: grid; grid-template-columns: var(--nav-control-height) minmax(0, 1fr) var(--nav-control-height); gap: clamp(14px, 2vw, 28px); align-items: center; pointer-events: none;
}
.nav-button {
  --nav-icon-width: 38px; --nav-icon-height: 44px; position: relative;
  width: var(--nav-control-height); height: var(--nav-control-height); padding: 0; display: grid; place-items: center;
  color: #fff; border-color: rgba(255,255,255,.9); background: var(--control-blue-gradient);
  text-shadow: 0 2px 4px rgba(2,85,140,.42); font-size: 0; line-height: 0; pointer-events: auto;
}
.nav-button::before { content: ""; position: absolute; left: 50%; top: 50%; width: var(--nav-icon-width); height: var(--nav-icon-height); background: currentColor; transform: translate(-50%, -50%); filter: drop-shadow(0 2px 3px rgba(2,85,140,.3)); }
#prev-button { grid-column: 1; }
#next-button { grid-column: 3; }
#prev-button::before { clip-path: polygon(100% 0, 0 50%, 100% 100%); }
#next-button::before { clip-path: polygon(0 0, 100% 50%, 0 100%); }
.nav-button:disabled { color: rgba(255,255,255,.78); border-color: rgba(255,255,255,.7); background: linear-gradient(145deg, rgba(211,221,228,.9), rgba(153,171,184,.72)); box-shadow: inset 0 1px 0 rgba(255,255,255,.82), 0 6px 0 rgba(111,132,145,.16), 0 10px 18px rgba(61,83,96,.12); filter: saturate(.18); cursor: default; transform: none; }
.caption-pill {
  position: relative; grid-column: 2; width: 100%; height: var(--caption-height); min-height: var(--caption-height); padding: 4px 24px;
  display: grid; place-items: center; align-content: center; gap: 3px;
  border: 1px solid rgba(255,255,255,.38); border-radius: calc(var(--caption-height) / 2); color: var(--ink); text-align: center;
  background: linear-gradient(145deg, rgba(255,255,255,.12), rgba(67,190,244,.045));
  box-shadow: inset 0 1px 0 rgba(255,255,255,.48), 0 5px 16px rgba(3,111,183,.055);
  backdrop-filter: blur(1px) saturate(108%); -webkit-backdrop-filter: blur(1px) saturate(108%);
  transition: opacity .2s ease, visibility .2s ease, transform .2s ease;
}
.caption-pill strong { display: block; margin: 0; font-size: clamp(24px, 2.5vw, 34px); line-height: 1; text-shadow: 0 1px 2px rgba(255,255,255,.98), 0 0 8px rgba(255,255,255,.9); }
.caption-pill span { color: #357fa9; font-family: system-ui, sans-serif; font-size: clamp(12px, 1.05vw, 16px); font-weight: 750; }
.caption-pill.hide-copy { opacity: 0; visibility: hidden; transform: translateY(8px) scale(.98); }

.course-menu {
  position: absolute; z-index: 30; inset: 0 0 0 auto; width: min(360px, 58vw); padding: 46px 26px 24px; overflow-y: auto; color: var(--blue-deep);
  background: linear-gradient(180deg, rgba(222,247,255,.82), rgba(151,222,252,.68)); border-left: 1px solid rgba(255,255,255,.86);
  box-shadow: -100vw 0 0 rgba(2,45,75,.34), -12px 0 34px rgba(2,98,163,.22);
  backdrop-filter: blur(30px) saturate(180%); -webkit-backdrop-filter: blur(30px) saturate(180%);
}
.menu-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.menu-head strong { font-size: 26px; }
.menu-head button { width: 44px; height: 44px; border: 1px solid var(--glass-border); border-radius: 50%; color: var(--blue-deep); background: linear-gradient(145deg, rgba(220,246,255,.86), rgba(92,204,250,.34)); box-shadow: inset 0 1px 0 white, 0 7px 0 rgba(14,137,202,.12), 0 12px 20px rgba(3,111,183,.14); backdrop-filter: blur(18px); font-size: 28px; cursor: pointer; }
.menu-section-title { margin: 4px 0 10px; font-size: 18px; }
.chapter-panel, .settings-panel { border: 1px solid rgba(255,255,255,.78); border-radius: 22px; background: rgba(255,255,255,.42); box-shadow: inset 0 1px 0 rgba(255,255,255,.9); backdrop-filter: blur(18px); }
.chapter-panel { padding: 15px; margin-bottom: 12px; }
.chapter-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.chapter-grid button { width: min(48px, 100%); aspect-ratio: 1; min-height: 0; justify-self: center; display: grid; place-items: center; border: 1px solid var(--glass-border); border-radius: 50%; color: var(--blue-deep); background: linear-gradient(145deg, rgba(220,246,255,.9), rgba(92,204,250,.42)); box-shadow: inset 0 1px 0 rgba(255,255,255,.95), 0 7px 20px rgba(3,111,183,.14); backdrop-filter: blur(18px) saturate(170%); cursor: pointer; }
.chapter-grid button:hover, .chapter-grid button.active { background: rgba(255,255,255,.72); box-shadow: inset 0 0 0 2px rgba(54,183,241,.66), inset 0 1px 0 white, 0 9px 24px rgba(3,111,183,.17); }
.chapter-grid button:disabled { opacity: .58; cursor: default; filter: saturate(.4); }
.chapter-grid b { display: grid; place-items: center; color: var(--blue-deep); font-size: 23px; line-height: 1; }
.settings-panel { padding: 4px 12px; }
.setting-row { margin: 0; padding: 10px 2px; display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.setting-row + .setting-row { border-top: 1px solid rgba(255,255,255,.7); }
.setting-row span { display: grid; gap: 2px; }
.setting-row b { font-size: 14px; }
.setting-row small { color: #5d8faa; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch i { display: block; width: 44px; height: 25px; padding: 3px; border: 1px solid rgba(255,255,255,.72); border-radius: 999px; background: rgba(124,172,195,.4); box-shadow: inset 0 1px 4px rgba(8,77,119,.14); cursor: pointer; transition: .2s; }
.switch i::after { content: ""; display: block; width: 19px; height: 19px; border-radius: 50%; background: white; box-shadow: 0 2px 5px rgba(0,0,0,.16); transition: .2s; }
.switch input:checked + i { background: rgba(38,177,242,.82); }
.switch input:checked + i::after { transform: translateX(19px); }
.menu-actions { display: grid; gap: 14px; margin-top: 16px; }
.restart-button { width: 100%; height: 58px; margin: 0 auto; border: 1px solid var(--glass-border); border-radius: 29px; color: var(--blue-deep); background: linear-gradient(145deg, rgba(220,246,255,.86), rgba(92,204,250,.4)); box-shadow: inset 0 1px 0 white, 0 7px 0 rgba(14,137,202,.12), 0 12px 22px rgba(3,111,183,.16); backdrop-filter: blur(20px) saturate(170%); font-weight: 900; cursor: pointer; }

@keyframes bars { to { height: 100%; } }

@media (max-width: 720px) {
  .lesson-header { height: 72px; padding-top: 5px; padding-bottom: 5px; padding-left: max(28px, calc(env(safe-area-inset-left, 0px) + 18px)); padding-right: max(28px, calc(env(safe-area-inset-right, 0px) + 18px)); }
  #course-code { font-size: 20px; }
  .lesson-title span { font-size: 13px; }
  .round-button { width: 56px; height: 56px; font-size: 20px; }
  .round-button svg { width: 30px; height: 30px; }
  .header-back-button { width: 50px; height: 50px; margin-right: 7px; font-size: 31px; }
  .header-actions { gap: 7px; }
  .game-stage { inset: 66px 4px 74px; }
  .visual-stage { width: min(100%, calc((100vh - 140px) * 1.7928)); width: min(100%, calc((100dvh - 140px) * 1.7928)); }
  .caption-wrap { --nav-control-height: 66px; --caption-height: 64px; left: max(34px, calc(env(safe-area-inset-left, 0px) + 22px)); right: max(34px, calc(env(safe-area-inset-right, 0px) + 22px)); bottom: 8px; gap: 8px; }
  .nav-button { --nav-icon-width: 22px; --nav-icon-height: 26px; }
  .caption-pill { padding: 4px 10px; }
  .caption-pill strong { font-size: clamp(16px, 4vw, 20px); }
  .caption-pill span { font-size: 11px; }
  .course-menu { padding-top: 28px; }
}

@media (max-width: 520px) { .lesson-title { margin-right: 6px; } }

@media (orientation: landscape) and (min-width: 721px) and (max-width: 1600px) and (min-height: 650px) and (max-aspect-ratio: 8/5) {
  .game-stage { inset: 104px 6vw 120px; }
  .visual-stage { width: min(88vw, calc((100dvh - 244px) * 1.7928)); }
  .caption-wrap { --nav-control-height: 90px; }
}

@media (max-height: 600px) {
  .lesson-header { height: 56px; padding-top: 4px; padding-bottom: 4px; padding-left: max(28px, calc(env(safe-area-inset-left, 0px) + 18px)); padding-right: max(28px, calc(env(safe-area-inset-right, 0px) + 18px)); }
  #course-code { font-size: 19px; }
  .lesson-title span { font-size: 12px; }
  .lesson-title { margin-right: 10px; }
  .round-button { width: 50px; height: 50px; font-size: 18px; }
  .round-button svg { width: 27px; height: 27px; }
  .header-back-button { width: 46px; height: 46px; margin-right: 8px; font-size: 29px; }
  .header-actions { gap: 8px; }
  .game-stage { inset: 50px 4px 62px; }
  .visual-stage { width: min(100%, calc((100vh - 112px) * 1.7928)); width: min(100%, calc((100dvh - 112px) * 1.7928)); }
  .caption-wrap { --nav-control-height: 58px; --caption-height: 56px; left: max(36px, calc(env(safe-area-inset-left, 0px) + 22px)); right: max(36px, calc(env(safe-area-inset-right, 0px) + 22px)); bottom: 6px; gap: 8px; }
  .nav-button { --nav-icon-width: 20px; --nav-icon-height: 24px; }
  .caption-pill strong { font-size: clamp(16px, 2.6vw, 22px); }
  .course-menu { width: min(320px, 52vw); padding: 8px 14px; }
  .menu-head { margin-bottom: 2px; }
  .menu-head strong { font-size: 20px; }
  .menu-head button { width: 32px; height: 32px; font-size: 21px; }
  .menu-section-title { margin: 0 0 5px; font-size: 15px; }
  .chapter-panel { padding: 7px 8px; margin-bottom: 7px; border-radius: 16px; }
  .chapter-grid { gap: 4px; }
  .chapter-grid button { width: 38px; }
  .chapter-grid b { font-size: 18px; }
  .settings-panel { padding: 2px 10px; border-radius: 16px; }
  .setting-row { padding: 5px 0; }
  .setting-row b { font-size: 12px; }
  .setting-row small { display: block; font-size: 9px; line-height: 1.05; }
  .menu-actions { gap: 10px; margin-top: 10px; }
  .restart-button { height: 44px; border-radius: 22px; font-size: 14px; }
}

@media (orientation: portrait) {
  .lesson-shell { position: fixed; left: 50%; top: 50%; width: 100vh; width: 100dvh; height: 100vw; min-height: 0; transform: translate(-50%, -50%) rotate(90deg); transform-origin: center; }
  .lesson-header { height: 56px; padding-top: 4px; padding-bottom: 4px; padding-left: max(28px, calc(env(safe-area-inset-left, 0px) + 18px)); padding-right: max(28px, calc(env(safe-area-inset-right, 0px) + 18px)); }
  #course-code { font-size: 19px; }
  .lesson-title span { font-size: 12px; }
  .lesson-title { margin-right: 10px; }
  .round-button { width: 50px; height: 50px; font-size: 18px; }
  .round-button svg { width: 27px; height: 27px; }
  .header-back-button { width: 46px; height: 46px; margin-right: 8px; font-size: 29px; }
  .header-actions { gap: 8px; }
  .game-stage { inset: 50px 4px 62px; }
  .visual-stage { width: min(100%, calc((100vw - 112px) * 1.7928)); }
  .caption-wrap { --nav-control-height: 58px; --caption-height: 56px; left: max(36px, calc(env(safe-area-inset-left, 0px) + 22px)); right: max(36px, calc(env(safe-area-inset-right, 0px) + 22px)); bottom: 6px; gap: 8px; }
  .nav-button { --nav-icon-width: 20px; --nav-icon-height: 24px; }
  .caption-pill strong { font-size: clamp(16px, 2.6vw, 22px); }
  .course-menu { width: min(320px, 52vw); padding: 8px 14px; }
  .menu-head { margin-bottom: 2px; }
  .menu-head strong { font-size: 20px; }
  .menu-head button { width: 32px; height: 32px; font-size: 21px; }
  .menu-section-title { margin: 0 0 5px; font-size: 15px; }
  .chapter-panel { padding: 7px 8px; margin-bottom: 7px; border-radius: 16px; }
  .chapter-grid { gap: 4px; }
  .chapter-grid button { width: 38px; }
  .chapter-grid b { font-size: 18px; }
  .settings-panel { padding: 2px 10px; border-radius: 16px; }
  .setting-row { padding: 5px 0; }
  .setting-row b { font-size: 12px; }
  .setting-row small { display: block; font-size: 9px; line-height: 1.05; }
  .menu-actions { gap: 10px; margin-top: 10px; }
  .restart-button { height: 44px; border-radius: 22px; font-size: 14px; }
}

@media (orientation: portrait) and (min-width: 721px) {
  .game-stage { inset: 64px 6vw 76px; }
  .visual-stage { width: min(88%, calc((100vw - 190px) * 1.7928)); }
  .caption-wrap { --nav-control-height: 52px; }
  .nav-button { --nav-icon-width: 24px; --nav-icon-height: 30px; }
}

@media (max-width: 720px), (max-height: 600px) { .header-back-button span { width: 24px; height: 22px; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }
