/* ============================================================
   SHELL — Nobocap AI Course
   Design tokens + layout (compact density for Full HD stage)
   Fonts: assets/css/fonts.css (load before this file)
   ============================================================ */

:root {
  /* Color — Nobocap brand (dark shell + designer palette) */
  --bg: #0f1f1a;
  --panel: #152a24;
  --panel2: #1c3630;
  --border: #2a4f45;
  --accent: #33aa92;
  --accent-strong: #33987c;
  --accent-mid: #2fa68f;
  --accent-soft: #66d0ba;
  --success: #a2da5a;
  --locked: #6b8a80;
  --text: #e8f4f0;
  --muted: #9bb5ac;
  --focus: #66d0ba;
  --danger: #e85d5d;
  --font-on-accent: #1e3c33;

  /* Type scale (family tokens in fonts.css) */
  --type-xs: 0.72rem;
  --type-sm: 0.8rem;
  --type-md: 0.9rem;
  --type-lg: 1.05rem;
  --type-xl: 1.2rem;

  /* Space (compact) */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --radius: 10px;
  --radius-sm: 8px;
  --sidebar-w: 300px;

  font-size: 16px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: var(--font-sans);
  background:
    radial-gradient(1200px 600px at 10% -10%, color-mix(in srgb, var(--accent) 14%, transparent), transparent 55%),
    radial-gradient(900px 500px at 100% 0%, color-mix(in srgb, var(--success) 8%, transparent), transparent 50%),
    var(--bg);
  color: var(--text);
  display: flex;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
}

input,
textarea {
  -webkit-user-select: text;
  user-select: text;
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* ---------- SIDEBAR ---------- */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 90;
}

aside {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: color-mix(in srgb, var(--panel) 92%, #000);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  transition: transform 0.25s ease;
  z-index: 100;
}

aside header {
  padding: var(--space-4) var(--space-4) var(--space-3);
  border-bottom: 1px solid var(--border);
  position: relative;
}

.brand {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
}

.brand-logo {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  box-shadow: 0 0 0 1px var(--border);
}

aside header h1 {
  font-family: var(--font-display);
  font-size: var(--type-md);
  font-weight: 600;
  line-height: 1.35;
  letter-spacing: -0.01em;
}

aside header p {
  color: var(--muted);
  font-size: var(--type-xs);
  margin-top: var(--space-1);
}

.btn-sidebar-close {
  display: none;
  position: absolute;
  top: var(--space-3);
  right: var(--space-2);
  width: 34px;
  height: 34px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--panel2);
  color: var(--text);
  cursor: pointer;
  font-size: 1.1rem;
  font-family: var(--font-sans);
  line-height: 1;
}

.progress-wrap {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
}

.progress-bar {
  height: 5px;
  background: var(--panel2);
  border-radius: 999px;
  overflow: hidden;
}

.progress-bar div {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--accent-strong), var(--success));
  transition: width 0.55s cubic-bezier(0.22, 1, 0.36, 1);
}

.progress-wrap span {
  display: block;
  margin-top: var(--space-2);
  font-size: var(--type-xs);
  color: var(--muted);
}

nav {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-2);
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--accent-soft) 55%, #ffffff)
    color-mix(in srgb, var(--panel2) 85%, transparent);
}

nav::-webkit-scrollbar {
  width: 10px;
}

nav::-webkit-scrollbar-track {
  background: color-mix(in srgb, var(--panel2) 85%, transparent);
  border-radius: 999px;
  margin: var(--space-1) 0;
}

nav::-webkit-scrollbar-thumb {
  background: linear-gradient(
    180deg,
    color-mix(in srgb, var(--accent-soft) 78%, #ffffff),
    color-mix(in srgb, var(--accent) 72%, #ffffff)
  );
  border: 2px solid color-mix(in srgb, var(--panel2) 85%, transparent);
  border-radius: 999px;
}

nav::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(
    180deg,
    color-mix(in srgb, var(--accent-soft) 92%, #ffffff),
    color-mix(in srgb, var(--accent) 86%, #ffffff)
  );
}

.ch-head {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  margin-top: 2px;
  font-size: var(--type-sm);
  font-weight: 600;
  border: none;
  background: transparent;
  color: inherit;
  width: 100%;
  text-align: left;
  font-family: var(--font-sans);
  transition: background 0.15s ease;
}

.ch-head:hover {
  background: var(--panel2);
}

.ch-head .num {
  width: 24px;
  height: 24px;
  min-width: 24px;
  border-radius: 50%;
  background: var(--panel2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--type-xs);
}

.ch-head.done .num {
  background: var(--success);
  color: var(--font-on-accent);
}

.ch-head .ch-title {
  flex: 1;
  min-width: 0;
}

.ch-head .count {
  margin-left: auto;
  font-size: 0.68rem;
  color: var(--muted);
  font-weight: 400;
}

.ch-head .arrow {
  font-size: 0.65rem;
  color: var(--muted);
  transition: transform 0.2s;
  width: 0.8em;
}

.ch-head.open .arrow {
  transform: rotate(90deg);
}

.subs {
  display: none;
  padding-left: 12px;
}

.subs.open {
  display: block;
}

.sub {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.78rem;
  color: var(--muted);
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
  font-family: var(--font-sans);
  transition: background 0.15s ease, color 0.15s ease, opacity 0.15s ease;
}

.sub:hover:not(:disabled) {
  background: var(--panel2);
  color: var(--text);
}

.sub.active {
  background: color-mix(in srgb, var(--accent-soft) 32%, var(--panel2));
  color: var(--text);
  box-shadow: inset 3px 0 0 var(--accent);
}

.sub.done:not(.active) {
  color: color-mix(in srgb, var(--text) 75%, var(--success));
}

.sub.locked {
  opacity: 0.45;
  cursor: not-allowed;
}

.sub.just-done {
  animation: pulse-done 0.9s ease;
}

@keyframes pulse-done {
  0% {
    box-shadow: 0 0 0 0 color-mix(in srgb, var(--success) 55%, transparent);
  }
  70% {
    box-shadow: 0 0 0 10px transparent;
  }
  100% {
    box-shadow: none;
  }
}

.sub .dot {
  width: 8px;
  height: 8px;
  min-width: 8px;
  border-radius: 50%;
  background: var(--panel2);
  border: 1px solid var(--muted);
}

.sub.done .dot {
  background: var(--success);
  border-color: var(--success);
}

.sub.active .dot {
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 35%, transparent);
}

.sub.active.done .dot {
  background: var(--success);
  border-color: var(--success);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--success) 40%, transparent);
}

.sub.locked .dot {
  border-style: dashed;
  border-color: var(--locked);
  background: transparent;
}

.sub-label {
  flex: 1;
  min-width: 0;
}

/* Status is shown by .dot colours only (see .sub.done / .sub.active / .sub.locked) */

.nav-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  margin: 0 var(--space-4) var(--space-3);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--panel2);
  font-size: var(--type-xs);
  color: var(--muted);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.nav-legend .dot {
  width: 8px;
  height: 8px;
  min-width: 8px;
  border-radius: 50%;
  display: inline-block;
}

.nav-legend .dot-done {
  background: var(--success);
  border: 1px solid var(--success);
}

.nav-legend .dot-current {
  background: var(--accent);
  border: 1px solid var(--accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 35%, transparent);
}

.nav-legend .dot-pending {
  background: var(--panel2);
  border: 1px solid var(--muted);
}

.nav-legend .dot-locked {
  background: transparent;
  border: 1px dashed var(--locked);
}

@media (orientation: landscape) {
  .nav-legend {
    display: none;
  }
}

.lms-badge {
  margin: var(--space-2) var(--space-4) var(--space-4);
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  font-size: var(--type-xs);
  background: var(--panel2);
  color: var(--muted);
}

.lms-badge.on {
  color: var(--success);
}

.lms-badge[hidden] {
  display: none !important;
}

/* ---------- MAIN ---------- */
main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg);
}

main:fullscreen,
main:-webkit-full-screen {
  width: 100%;
  height: 100%;
  background:
    radial-gradient(1200px 600px at 10% -10%, color-mix(in srgb, var(--accent) 14%, transparent), transparent 55%),
    radial-gradient(900px 500px at 100% 0%, color-mix(in srgb, var(--success) 8%, transparent), transparent 50%),
    var(--bg);
}

/* Cinema mode — mobile landscape fullscreen only (class set by shell JS) */
.btn-exit-cinema {
  display: none;
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 30;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid color-mix(in srgb, var(--accent-soft) 55%, transparent);
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--accent) 78%, transparent);
  color: #fff;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(6px);
  opacity: 0.9;
  transition: opacity 0.2s ease, background 0.2s ease, border-color 0.2s ease;
}

.btn-exit-cinema svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
  display: block;
}

.btn-exit-cinema:hover {
  opacity: 1;
  background: var(--accent);
  border-color: color-mix(in srgb, #fff 45%, var(--accent-soft));
  color: #fff;
}

.btn-cinema-nav {
  display: none;
  position: absolute;
  top: 50%;
  z-index: 25;
  width: 40px;
  height: 40px;
  margin: 0;
  padding: 0;
  border: 1px solid color-mix(in srgb, var(--accent-soft) 55%, transparent);
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--accent) 78%, transparent);
  color: #fff;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(6px);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition:
    opacity 0.35s ease,
    visibility 0.35s ease,
    transform 0.35s cubic-bezier(0.22, 1, 0.36, 1),
    background 0.2s ease,
    border-color 0.2s ease;
}

.btn-cinema-prev {
  left: 12px;
  transform: translate(-120%, -50%);
}

.btn-cinema-next {
  right: 12px;
  transform: translate(120%, -50%);
}

.btn-cinema-nav svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
  display: block;
}

.btn-cinema-nav:disabled {
  cursor: default;
}

main.is-cinema .topbar,
main.is-cinema .nav-bar {
  display: none !important;
}

main.is-cinema .stage {
  margin: 0;
  flex: 1 1 auto;
  min-height: 0;
}

main.is-cinema .stage-scaler iframe {
  border-radius: 0;
}

main.is-cinema .btn-exit-cinema {
  display: inline-flex;
}

main.is-cinema .btn-cinema-nav {
  display: inline-flex;
}

main.is-cinema.cinema-controls-visible .btn-cinema-nav {
  opacity: 0.9;
  visibility: visible;
  pointer-events: auto;
  transform: translate(0, -50%);
}

main.is-cinema.cinema-controls-visible .btn-cinema-nav:disabled {
  opacity: 0.35;
  pointer-events: none;
}

main.is-cinema.cinema-controls-visible .btn-cinema-nav:hover:not(:disabled) {
  opacity: 1;
  background: var(--accent);
  border-color: color-mix(in srgb, #fff 45%, var(--accent-soft));
}

/* Hide cinema nav while unit drag is active (drag lives in iframe) */
main.is-cinema.cinema-drag-active .btn-cinema-nav {
  opacity: 0 !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

main.is-cinema.cinema-drag-active .btn-cinema-prev {
  transform: translate(-120%, -50%) !important;
}

main.is-cinema.cinema-drag-active .btn-cinema-next {
  transform: translate(120%, -50%) !important;
}

/* Portrait fullscreen — hide Open Menu (sidebar is outside fullscreen main) */
@media (orientation: portrait) {
  main:fullscreen .btn-menu,
  main:-webkit-full-screen .btn-menu,
  main.is-fullscreen .btn-menu {
    display: none !important;
  }
}

/* Rotate hint (fullscreen portrait when landscape lock unavailable) */
.rotate-hint {
  position: fixed;
  left: 50%;
  top: 50%;
  bottom: auto;
  z-index: 40;
  transform: translate(-50%, -50%);
  max-width: min(340px, calc(100% - 32px));
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--panel) 92%, #000);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: var(--type-sm);
  font-weight: 500;
  text-align: center;
  line-height: 1.35;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition:
    opacity 0.55s ease,
    visibility 0.55s ease;
}

.rotate-hint.is-visible {
  opacity: 1;
  visibility: visible;
}

.rotate-hint[hidden] {
  display: none !important;
}

@media (orientation: landscape) {
  .rotate-hint {
    display: none !important;
  }
}

.topbar {
  padding: 0 0 0 var(--space-5);
  display: flex;
  align-items: stretch;
  gap: var(--space-4);
  border-bottom: 1px solid color-mix(in srgb, var(--accent-strong) 70%, #000);
  background: #33aa92;
  color: #fff;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex: 0 0 auto;
  padding: 14px 0;
  min-height: 40px;
}

.topbar-logo {
  flex-shrink: 0;
  height: 40px;
  width: auto;
  display: block;
}

.topbar-right {
  display: flex;
  align-items: stretch;
  gap: var(--space-3);
  flex: 1 1 0;
  min-width: 0;
  justify-content: flex-end;
}

.topbar-actions {
  display: flex;
  align-items: center;
  align-self: center;
  gap: var(--space-2);
  padding-right: var(--space-3);
}

.topbar-deco-pair {
  display: flex;
  align-items: center;
  align-self: stretch;
  flex: 1 1 0;
  min-width: 0;
  justify-content: flex-end;
}

.topbar-deco,
.topbar-deco1 {
  /* Scale asset (719×136); shrink proportionally when topbar-right runs out of space */
  aspect-ratio: 719 / 136;
  align-self: center;
  height: 100%;
  width: auto;
  flex: 0 1 auto;
  min-width: 0;
  max-width: 50%;
  background: url("../image/header_right.png") no-repeat right center;
  background-size: auto 100%;
}

.topbar-deco1 {
  transform: scaleX(-1);
  background-position: left center;
}

.btn-topbar {
  border: 1px solid color-mix(in srgb, #fff 35%, transparent);
  background: color-mix(in srgb, #fff 18%, transparent);
  color: #fff;
  border-radius: var(--radius-sm);
  padding: 0 14px;
  min-height: 36px;
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: var(--type-sm);
  font-weight: 500;
  white-space: nowrap;
  transition: filter 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.btn-topbar:hover {
  filter: none;
  background: color-mix(in srgb, #fff 28%, transparent);
  border-color: color-mix(in srgb, #fff 55%, transparent);
}

.btn-topbar-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  padding: 0;
  flex-shrink: 0;
}

.btn-topbar-texticon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex-shrink: 0;
}

.btn-topbar-texticon .btn-topbar-svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
  flex-shrink: 0;
  display: none;
}

.btn-topbar-texticon .btn-topbar-label {
  display: inline;
}

.btn-fullscreen {
  position: relative;
}

.btn-fullscreen svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
  display: block;
  position: absolute;
  inset: 0;
  margin: auto;
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.btn-fullscreen .icon-fs-exit {
  opacity: 0;
  transform: scale(0.85);
  pointer-events: none;
}

.btn-fullscreen.is-active {
  background: color-mix(in srgb, #fff 42%, transparent);
  border-color: #fff;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, #fff 40%, transparent);
}

.btn-fullscreen.is-active .icon-fs-enter {
  opacity: 0;
  transform: scale(0.85);
  pointer-events: none;
}

.btn-fullscreen.is-active .icon-fs-exit {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

.btn-menu {
  display: none;
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, #fff 18%, transparent);
  color: #fff;
  cursor: pointer;
  align-items: center;
  justify-content: center;
}

.btn-menu svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.topbar h2 {
  font-family: var(--font-display);
  font-size: var(--type-lg);
  font-weight: 600;
  white-space: nowrap;
  letter-spacing: -0.015em;
}

.topbar-titles {
  flex: 0 0 auto;
  animation: title-in 0.35s ease;
}

@keyframes title-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.chapter-label {
  margin: 0 0 1px;
  color: color-mix(in srgb, #fff 78%, transparent);
  font-size: var(--type-md);
  font-weight: 500;
  white-space: nowrap;
}

.stage {
  flex: 1;
  position: relative;
  margin: var(--space-3) var(--space-4) var(--space-2);
  min-height: 0;
  overflow: hidden;
}

.stage-scaler {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 1920px;
  height: 1080px;
  transform-origin: center center;
  will-change: transform;
}

.stage-scaler iframe {
  display: block;
  width: 1920px;
  height: 1080px;
  border: 0;
  border-radius: var(--radius);
  background: var(--panel);
  transition: opacity 0.28s ease;
}

.stage-scaler.is-fading iframe {
  opacity: 0.35;
}

.stage-scaler.has-error iframe {
  opacity: 0.15;
  pointer-events: none;
}

.stage-loading,
.stage-error {
  position: absolute;
  inset: 0;
  z-index: 5;
  pointer-events: none;
}

.stage-loading[hidden],
.stage-error[hidden] {
  display: none !important;
}

.stage-loading {
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--accent) 88%, var(--panel));
  color: #fff;
  font-size: 28px;
  font-weight: 500;
}

/* Align with .vbtn-bigplay (120×120, centered on the 1920×1080 stage) */
.stage-spinner {
  box-sizing: border-box;
  position: absolute;
  left: 50%;
  top: 50%;
  width: 120px;
  height: 120px;
  margin: 0;
  border: 3px solid color-mix(in srgb, #fff 55%, transparent);
  border-top-color: #fff;
  border-radius: 50%;
  background: color-mix(in srgb, #fff 15%, transparent);
  transform: translate(-50%, -50%);
  animation: spin 0.8s linear infinite;
}

.stage-loading #stageLoadingText {
  position: absolute;
  left: 50%;
  top: calc(50% + 80px);
  transform: translateX(-50%);
  white-space: nowrap;
}

@keyframes spin {
  to {
    transform: translate(-50%, -50%) rotate(360deg);
  }
}

.stage-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  text-align: center;
  padding: var(--space-5);
  pointer-events: auto;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
}

.stage-error h3 {
  font-family: var(--font-display);
  font-size: var(--type-xl);
  color: var(--danger);
}

.stage-error p {
  color: var(--muted);
  max-width: 36ch;
  line-height: 1.45;
  font-size: var(--type-sm);
}

.nav-bar {
  display: flex;
  justify-content: space-between;
  align-items: stretch;
  gap: var(--space-4);
  padding: var(--space-2) var(--space-4) var(--space-4);
  flex-shrink: 0;
}

.work-instruction {
  flex: 1;
  min-width: 0;
  margin: 0;
  display: flex;
  align-items: center;
  padding: 0 14px 0 16px;
  min-height: 40px;
  color: var(--text);
  font-size: var(--type-md);
  font-weight: 500;
  line-height: 1.35;
  background: var(--panel2);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--accent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 22%, transparent);
  position: relative;
  overflow: hidden;
}

.work-instruction:empty {
  display: none;
}

.work-instruction-inner {
  display: block;
  width: 100%;
  min-width: 0;
  transform: translateY(0);
  opacity: 1;
  transition:
    transform 1s cubic-bezier(0.22, 1, 0.36, 1),
    opacity 0.85s ease;
}

.work-instruction-inner.is-enter {
  position: absolute;
  left: 16px;
  right: 14px;
  top: 50%;
  transform: translateY(calc(-50% + 22px));
  opacity: 0;
}

.work-instruction-inner.is-leave {
  position: absolute;
  left: 16px;
  right: 14px;
  top: 50%;
  transform: translateY(calc(-50% - 22px));
  opacity: 0;
  pointer-events: none;
}

.work-instruction-inner strong {
  font-weight: 700;
  color: var(--text);
}

.nav-bar .btns {
  display: flex;
  align-items: stretch;
  gap: var(--space-2);
  flex-shrink: 0;
  margin-left: auto;
}

.nav-bar .btns button {
  background: var(--panel2);
  color: var(--text);
  border: none;
  padding: 0 16px;
  min-height: 40px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: var(--type-sm);
  font-family: var(--font-sans);
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: filter 0.15s ease, transform 0.15s ease;
}

.nav-btn-icon {
  display: none;
  width: 22px;
  height: 22px;
  fill: currentColor;
  flex-shrink: 0;
}

.nav-btn-icon--finish {
  display: none;
}

.nav-bar .btns button.primary {
  background: var(--accent);
  color: #fff;
}

.nav-bar .btns button.ghost {
  background: transparent;
  border: 1px solid var(--border);
}

.nav-bar .btns button:disabled {
  opacity: 0.35;
  cursor: default;
}

.nav-bar .btns button:not(:disabled):hover {
  filter: brightness(1.08);
}

.nav-bar .btns button:not(:disabled):active {
  transform: translateY(1px);
}

/* ---------- FINISH OVERLAY ---------- */
.finish-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(8, 18, 14, 0.72);
  align-items: center;
  justify-content: center;
  padding: var(--space-5);
}

.finish-overlay.open {
  display: flex;
}

.finish-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 24px;
  max-width: 420px;
  width: 100%;
  text-align: center;
  animation: title-in 0.35s ease;
}

.finish-card h3 {
  font-family: var(--font-display);
  font-size: var(--type-xl);
  margin-bottom: var(--space-2);
}

.finish-card p {
  color: var(--muted);
  font-size: var(--type-md);
  line-height: 1.5;
  margin-bottom: var(--space-5);
}

.finish-card .actions {
  display: flex;
  gap: var(--space-2);
  justify-content: center;
  flex-wrap: wrap;
}

.finish-card button {
  border: none;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: var(--type-sm);
  font-family: var(--font-sans);
  background: var(--panel2);
  color: var(--text);
}

.finish-card button.primary {
  background: var(--accent);
  color: #fff;
}

/* ---------- AUTH GATE / UPGRADE ---------- */
.auth-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 220;
  background:
    radial-gradient(900px 500px at 20% 0%, color-mix(in srgb, var(--accent) 18%, transparent), transparent 55%),
    rgba(8, 18, 14, 0.88);
  align-items: center;
  justify-content: center;
  padding: var(--space-5);
}

.auth-overlay.open {
  display: flex;
}

.auth-overlay.open[hidden] {
  display: flex !important;
}

.auth-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 28px;
  max-width: 440px;
  width: 100%;
  text-align: center;
  animation: title-in 0.35s ease;
}

.auth-card .auth-logo {
  display: block;
  margin: 0 auto var(--space-4);
  height: 40px;
  width: auto;
}

.auth-card h3 {
  font-family: var(--font-display);
  font-size: var(--type-xl);
  margin-bottom: var(--space-2);
}

.auth-card p {
  color: var(--muted);
  font-size: var(--type-md);
  line-height: 1.5;
  margin-bottom: var(--space-5);
}

.auth-card .actions {
  display: flex;
  gap: var(--space-2);
  justify-content: center;
  flex-wrap: wrap;
}

.auth-card button {
  border: none;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: var(--type-sm);
  font-family: var(--font-sans);
  background: var(--panel2);
  color: var(--text);
}

.auth-card button.primary {
  background: var(--accent);
  color: #fff;
}

body.is-auth-blocked #sidebar,
body.is-auth-blocked #shellMain,
body.is-auth-blocked .sidebar-backdrop {
  visibility: hidden;
  pointer-events: none;
}

/* ---------- HELP / RESOURCES DIALOG ---------- */
.dialog-overlay {
  display: flex;
  position: fixed;
  inset: 0;
  z-index: 210;
  background: rgba(8, 18, 14, 0.72);
  align-items: center;
  justify-content: center;
  padding: var(--space-5);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition:
    opacity 0.35s ease,
    visibility 0.35s ease;
}

.dialog-overlay.open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.dialog-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  aspect-ratio: 16 / 9;
  width: min(960px, 92vw, calc((100vh - 40px) * 16 / 9));
  max-height: calc(100vh - 40px);
  display: flex;
  flex-direction: column;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.4);
  opacity: 0;
  transform: translateY(28px) scale(0.96);
  transition:
    transform 0.45s cubic-bezier(0.22, 1, 0.36, 1),
    opacity 0.35s ease;
}

.dialog-overlay.open .dialog-card {
  opacity: 1;
  transform: none;
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.dialog-header h3 {
  font-family: var(--font-display);
  font-size: var(--type-lg);
  font-weight: 600;
  margin: 0;
}

.dialog-close {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--panel2);
  color: var(--text);
  cursor: pointer;
  font-size: 1.35rem;
  line-height: 1;
  flex-shrink: 0;
}

.dialog-close:hover {
  filter: brightness(1.1);
}

.dialog-body {
  flex: 1;
  min-height: 0;
  padding: 16px 18px 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--accent-soft) 55%, #ffffff) color-mix(in srgb, var(--panel2) 85%, transparent);
}

.dialog-body::-webkit-scrollbar {
  width: 12px;
}

.dialog-body::-webkit-scrollbar-track {
  background: color-mix(in srgb, var(--panel2) 85%, transparent);
  border-radius: 999px;
}

.dialog-body::-webkit-scrollbar-thumb {
  background: linear-gradient(
    180deg,
    color-mix(in srgb, var(--accent-soft) 78%, #ffffff),
    color-mix(in srgb, var(--accent) 72%, #ffffff)
  );
  border: 2px solid color-mix(in srgb, var(--panel2) 85%, transparent);
  border-radius: 999px;
}

.dialog-body::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(
    180deg,
    color-mix(in srgb, var(--accent-soft) 92%, #ffffff),
    color-mix(in srgb, var(--accent) 86%, #ffffff)
  );
}

.dialog-lead {
  margin: 0;
  color: var(--muted);
  font-size: var(--type-sm);
  line-height: 1.5;
}

.dialog-footnote {
  margin: 0;
  color: var(--muted);
  font-size: var(--type-xs);
  line-height: 1.45;
}

.help-tips {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.help-tips li {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 14px;
  background: var(--panel2);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.work-instruction strong,
.help-tips strong,
.dialog-body strong,
.resource-card-desc strong,
.dialog-lead strong,
.dialog-footnote strong {
  font-weight: 700;
  color: var(--text);
}

.help-tips li > strong {
  font-size: var(--type-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--accent);
}

.help-tips span strong {
  font-size: inherit;
  font-weight: 700;
  text-transform: none;
  letter-spacing: normal;
  color: var(--text);
}

.help-tips span {
  color: color-mix(in srgb, var(--text) 88%, var(--muted));
  font-size: var(--type-sm);
  line-height: 1.5;
}

.resource-cards {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.resource-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--panel2);
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.15s ease;
}

.resource-card:hover {
  border-color: color-mix(in srgb, var(--accent) 50%, var(--border));
  background: color-mix(in srgb, var(--accent) 12%, var(--panel2));
  transform: translateY(-1px);
}

.resource-card-label {
  font-size: var(--type-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--accent);
}

.resource-card-title {
  font-size: var(--type-md);
  font-weight: 600;
  color: var(--text);
}

.resource-card-desc {
  font-size: var(--type-sm);
  color: var(--muted);
  line-height: 1.45;
}

.dialog-body p {
  margin: 0;
  color: var(--muted);
  font-size: var(--type-sm);
  line-height: 1.55;
}

/* ---------- DEBUG PANEL ---------- */
.debug-panel {
  position: fixed;
  right: var(--space-4);
  bottom: var(--space-4);
  z-index: 300;
  width: min(420px, calc(100vw - 32px));
  max-height: min(50vh, 420px);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  font-size: 0.72rem;
}

.debug-panel[hidden] {
  display: none !important;
}

.debug-panel header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  cursor: grab;
  user-select: none;
  touch-action: none;
}

.debug-panel.is-dragging header {
  cursor: grabbing;
}

.debug-panel pre {
  margin: 0;
  padding: 10px;
  overflow: auto;
  color: var(--muted);
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--font-mono);
  line-height: 1.4;
}

.debug-panel button {
  border: none;
  background: var(--panel2);
  color: var(--text);
  border-radius: 6px;
  padding: 4px 8px;
  cursor: pointer;
  font-size: 0.7rem;
}

/* ---------- RESPONSIVE (compact shell) ----------
   Apply on narrow viewports OR any touch/mobile device,
   regardless of CSS pixel resolution (phones/tablets in any orientation). */
@media (max-width: 900px), (hover: none) and (pointer: coarse) {
  .btn-menu {
    display: inline-flex;
  }

  .btn-sidebar-close {
    display: block;
  }

  .sidebar-backdrop.open {
    display: block;
  }

  aside {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    transform: translateX(-105%);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.35);
  }

  aside.open {
    transform: translateX(0);
  }

  aside header h1 {
    font-size: 0.88rem;
    padding-right: 36px;
  }

  /* Topbar — compact, no deco, titles ellipsis */
  .topbar {
    padding: 0 0 0 var(--space-3);
    gap: var(--space-2);
  }

  .topbar-left {
    flex: 1 1 auto;
    min-width: 0;
    padding: 10px 0;
    gap: var(--space-2);
  }

  .topbar-right {
    flex: 0 0 auto;
  }

  .topbar-deco-pair {
    display: none;
  }

  .topbar-logo {
    height: 28px;
  }

  .topbar-titles {
    flex: 1 1 auto;
    min-width: 0;
  }

  .chapter-label,
  .topbar h2 {
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .chapter-label {
    font-size: var(--type-xs);
  }

  .topbar h2 {
    font-size: var(--type-sm);
  }

  .topbar-actions {
    gap: 6px;
    padding-right: var(--space-2);
  }

  .btn-topbar-texticon {
    width: 36px;
    padding: 0;
  }

  .btn-topbar-texticon .btn-topbar-label {
    display: none;
  }

  .btn-topbar-texticon .btn-topbar-svg {
    display: block;
  }

  .stage {
    margin: var(--space-2);
  }

  .stage-scaler iframe {
    border-radius: 8px;
  }

  /* Nav — icon buttons (layout by orientation below) */
  .nav-bar {
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3)
      max(var(--space-2), env(safe-area-inset-bottom, 0px));
  }

  .work-instruction {
    font-size: var(--type-sm);
    min-height: 44px;
    padding: 8px 10px;
  }

  .nav-bar .btns {
    margin-left: 0;
    gap: var(--space-2);
    align-items: stretch;
  }

  .nav-bar .btns button {
    flex: 0 0 44px;
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    padding: 0;
    font-size: 0.8rem;
  }

  .nav-btn-icon {
    display: block;
  }

  .nav-btn-icon--finish {
    display: none;
  }

  .nav-btn.is-finish .nav-btn-icon--next {
    display: none;
  }

  .nav-btn.is-finish .nav-btn-icon--finish {
    display: block;
  }

  .nav-btn-label {
    display: none;
  }
}

/* Portrait: line 1 = instruction, line 2 = nav + replay */
@media (max-width: 900px) and (orientation: portrait),
  (hover: none) and (pointer: coarse) and (orientation: portrait) {
  /* Header: menu + logo + actions | titles below */
  .topbar {
    display: grid;
    grid-template-columns: auto auto minmax(0, 1fr);
    grid-template-rows: auto auto;
    align-items: center;
    column-gap: var(--space-2);
    row-gap: 4px;
    padding: 8px var(--space-2) 8px var(--space-3);
  }

  .topbar-left,
  .topbar-right {
    display: contents;
  }

  .btn-menu {
    grid-column: 1;
    grid-row: 1;
  }

  .topbar-logo {
    grid-column: 2;
    grid-row: 1;
  }

  .topbar-actions {
    grid-column: 3;
    grid-row: 1;
    justify-self: end;
    align-self: center;
    padding-right: 0;
  }

  .topbar-titles {
    grid-column: 1 / -1;
    grid-row: 2;
    min-width: 0;
    padding-bottom: 2px;
  }

  .chapter-label,
  .topbar h2 {
    white-space: normal;
  }

  .nav-bar {
    flex-direction: column;
    flex-wrap: nowrap;
    align-items: stretch;
  }

  .work-instruction {
    flex: 0 0 auto;
    width: 100%;
    min-width: 0;
    order: 0;
  }

  .nav-bar .btns {
    flex: 0 0 auto;
    width: 100%;
    justify-content: stretch;
  }

  .nav-bar .btns button {
    flex: 1 1 0;
    width: auto;
    min-width: 44px;
  }

  /* Help / Resources — tall, but leave room for header + footer */
  .dialog-overlay {
    padding: 100px var(--space-3) 116px;
    align-items: center;
  }

  .dialog-card {
    aspect-ratio: auto;
    width: 100%;
    max-width: none;
    height: auto;
    max-height: calc(100vh - 240px);
    max-height: calc(100dvh - 240px);
    border-radius: var(--radius);
  }
}

/* Landscape: instruction + buttons on one row */
@media (max-width: 900px) and (orientation: landscape),
  (hover: none) and (pointer: coarse) and (orientation: landscape) {
  .nav-bar {
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: stretch;
  }

  .work-instruction {
    flex: 1 1 auto;
    width: auto;
    min-width: 0;
    order: 0;
  }

  .nav-bar .btns {
    flex: 0 0 auto;
    width: auto;
  }
}

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