:root{
  --bg:#0b1020;
  --panel:rgba(255,255,255,.08);
  --text:rgba(255,255,255,.92);
  --muted:rgba(255,255,255,.7);
  --shadow: 0 18px 55px rgba(0,0,0,.45);
  --radius: 18px;
}

*{box-sizing:border-box}
html,body{height:100%}
body{
  margin:0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial;
  background: radial-gradient(1200px 700px at 20% 10%, rgba(108,152,255,.25), transparent 55%),
              radial-gradient(900px 600px at 80% 20%, rgba(255,140,56,.18), transparent 55%),
              var(--bg);
  color:var(--text);
}

.app{height:100%; display:flex; align-items:center; justify-content:center; padding:18px;}

.stage{
  width:min(1200px, 100%);
  aspect-ratio: 16/9;
  position:relative;
  border-radius: var(--radius);
  background: rgba(0,0,0,.25);
  box-shadow: var(--shadow);
  outline:none;
  overflow:hidden;
}

.slide-wrap{position:absolute; inset:0; padding:14px;}

.slide{
  width:100%; height:100%;
  object-fit:contain;
  border-radius: calc(var(--radius) - 6px);
  background: rgba(255,255,255,.03);
  box-shadow: 0 12px 40px rgba(0,0,0,.4);
  opacity:0;
  transform: translateY(4px) scale(.995);
  transition: opacity 180ms ease, transform 220ms ease;
}
.slide.ready{opacity:1; transform: translateY(0) scale(1);}

/* Nav arrows */
.nav{
  position:absolute;
  top:50%;
  transform:translateY(-50%);
  width:56px; height:72px;
  border:1px solid rgba(255,255,255,.22);
  background: rgba(0,0,0,.28);
  color:var(--text);
  border-radius: 18px;
  cursor:pointer;
  display:grid;
  place-items:center;
  font-size:44px;
  line-height:1;
  backdrop-filter: blur(8px);
  transition: transform 120ms ease, background 120ms ease, border-color 120ms ease, opacity 160ms ease;
}
.nav:hover{ background: rgba(0,0,0,.42); border-color: rgba(255,255,255,.35); }
.nav:active{ transform: translateY(-50%) scale(.98); }
.nav.prev{ left:14px; }
.nav.next{ right:14px; }

/* HUD (bottom bar) */
.hud{
  position:absolute;
  left:14px; right:14px; bottom:14px;
  display:flex;
  gap:10px;
  align-items:center;
  padding:10px 12px;
  background: rgba(255,255,255,.10);
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 16px;
  backdrop-filter: blur(10px);
  transition: opacity 160ms ease;
}
.counter{font-variant-numeric: tabular-nums; color:var(--muted);}
.spacer{flex:1;}

.btn{
  appearance:none;
  border:1px solid rgba(255,255,255,.20);
  background: rgba(0,0,0,.22);
  color: var(--text);
  padding:8px 10px;
  border-radius: 12px;
  cursor:pointer;
  font-weight: 600;
}
.btn:hover{ background: rgba(0,0,0,.35); border-color: rgba(255,255,255,.32); }
.btn.primary{ background: rgba(108,152,255,.28); border-color: rgba(108,152,255,.5); }

.progress{
  position:absolute;
  left:0; right:0; bottom:0;
  height:4px;
  background: rgba(255,255,255,.08);
  border-radius: 0 0 var(--radius) var(--radius);
  overflow:hidden;
}
.bar{height:100%; width:0%; background: rgba(255,255,255,.55); transition: width 200ms ease;}

/* =========================
   Help overlay (FIXED2 STYLE)
   Default CLOSED; opens only with .is-open
   ========================= */
.help{
  position:absolute;
  inset:0;
  display:none;                /* IMPORTANT: default hidden */
  place-items:center;
  background: rgba(0,0,0,.55);
  backdrop-filter: blur(8px);
  border-radius: var(--radius);
  z-index: 10;
}
.help.is-open{ display:grid; } /* IMPORTANT: JS toggles this class */

.help-card{
  width:min(520px, calc(100% - 26px));
  background: rgba(20,24,38,.92);
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 18px;
  padding: 18px 18px 14px;
  box-shadow: var(--shadow);
}
.help-card h2{margin:0 0 10px; font-size:18px;}
.help-card ul{margin:0 0 14px; padding-left:18px; color:var(--muted);}
.help-card li{margin:6px 0;}

kbd{
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.9em;
  padding: 2px 6px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,.18);
  background: rgba(255,255,255,.08);
  color: var(--text);
}

/* =========================
   Auto-hide controls (prevents covering slide content)
   Controls show on hover/focus.
   While help is open, controls stay hidden (overlay owns the screen).
   ========================= */
.stage .nav,
.stage .hud{
  opacity: 0;
  pointer-events: none;
}

.stage:hover .nav,
.stage:hover .hud,
.stage:focus-within .nav,
.stage:focus-within .hud{
  opacity: 1;
  pointer-events: auto;
}

/* If help overlay is open, suppress controls */
.stage .help.is-open ~ .nav,
.stage .help.is-open ~ .hud{
  opacity: 0;
  pointer-events: none;
}

@media (max-width: 720px){
  .nav{ width:46px; height:64px; font-size:38px; border-radius: 16px; }
  .hud{ padding:10px; }
  .btn{ padding:8px 9px; }
}
/* ===== Auto-hide controls (robust: works with .hud/.nav OR #hud/#prevBtn/#nextBtn) ===== */
.stage .nav,
.stage .hud,
.stage #hud,
.stage #prevBtn,
.stage #nextBtn{
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease;
}

.stage:hover .nav,
.stage:hover .hud,
.stage:hover #hud,
.stage:hover #prevBtn,
.stage:hover #nextBtn,
.stage:focus-within .nav,
.stage:focus-within .hud,
.stage:focus-within #hud,
.stage:focus-within #prevBtn,
.stage:focus-within #nextBtn{
  opacity: 1;
  pointer-events: auto;
}

/* If help is open, keep controls hidden */
.stage .help.is-open ~ .nav,
.stage .help.is-open ~ .hud,
.stage .help.is-open ~ #hud,
.stage .help.is-open ~ #prevBtn,
.stage .help.is-open ~ #nextBtn{
  opacity: 0;
  pointer-events: none;
}
/* ===== AUT0HIDE CONTROLS (high-specificity + override-safe) ===== */
.stage.autohide .nav,
.stage.autohide .hud{
  opacity: 0 !important;
  pointer-events: none !important;
  transition: opacity 160ms ease !important;
}

/* Show on hover/focus (desktop + keyboard) */
.stage.autohide:hover .nav,
.stage.autohide:hover .hud,
.stage.autohide:focus-within .nav,
.stage.autohide:focus-within .hud{
  opacity: 1 !important;
  pointer-events: auto !important;
}

/* While help is open, keep controls hidden */
.stage.autohide .help.is-open ~ .nav,
.stage.autohide .help.is-open ~ .hud{
  opacity: 0 !important;
  pointer-events: none !important;
}
