/* ─── KLMX.com ───────────────────────────────────────────────── */
:root {
  --bg: #0a0a0e;
  --bg-elevated: #12121a;
  --bg-panel: #181822;
  --border: #2a2a38;
  --border-strong: #3d3d52;
  --text: #f0efe8;
  --text-muted: #9a99a8;
  --accent: #ff5c5c;
  --accent-2: #ffd166;
  --accent-3: #6ee7b7;
  --ink: #0a0a0c;
  --radius: 12px;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  --font: "Space Grotesk", system-ui, sans-serif;
  --font-display: "Bangers", "Impact", sans-serif;
  --max: 1120px;
  /* Cinematic black → white lightning hover */
  --hover-color: #0c0c0e;
  --hover-r: 12;
  --hover-g: 12;
  --hover-b: 14;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
}

html {
  background: var(--bg);
}

body {
  position: relative;
  background-color: var(--bg);
}

/* Full-page video background (OBP) */
.site-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

.site-bg-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center center;
  max-width: none;
}

.site-bg-shade {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    180deg,
    rgba(10, 10, 14, 0.62) 0%,
    rgba(10, 10, 14, 0.72) 45%,
    rgba(10, 10, 14, 0.86) 100%
  );
}

body > .site-header,
body > .page-shell,
body > .site-footer,
body > main {
  position: relative;
  z-index: 1;
}

a {
  color: inherit;
  text-decoration: none;
}

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

button {
  cursor: pointer;
  border: none;
  background: none;
}

img,
video {
  max-width: 100%;
  display: block;
}

/* ─── Shell ──────────────────────────────────────────────────── */
.site-header {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 22px;
  background: rgba(10, 10, 14, 0.88);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-logo {
  display: block;
  height: 42px;
  width: auto;
  max-width: min(220px, 42vw);
  object-fit: contain;
  border-radius: 8px;
  background: transparent;
  pointer-events: none;
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--accent), #ff8a5c);
  color: white;
  font-weight: 700;
  font-size: 14px;
  box-shadow: 0 0 0 2px rgba(255, 92, 92, 0.25);
  flex-shrink: 0;
}

.brand-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.brand-name {
  font-family: var(--font-display);
  font-size: 22px;
  letter-spacing: 0.04em;
  line-height: 1;
}

.brand-tag {
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.04em;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.nav {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.nav a {
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  transition: color 0.12s, background 0.12s;
}

.nav a:hover,
.nav a.active {
  color: var(--text);
  background: var(--bg-panel);
}

.nav a.active {
  color: var(--accent-2);
}

.site-main {
  min-height: calc(100vh - 130px);
}

/* ─── Chess Tetris left column ───────────────────────────────── */
.page-shell {
  display: flex;
  align-items: stretch;
  min-height: calc(100vh - 70px);
  width: 100%;
}

.page-shell > .site-main {
  flex: 1;
  min-width: 0;
}

/* Compact game list (links + icons, no embeds) */
.game-links {
  flex: 0 0 200px;
  width: 200px;
  max-width: 100%;
  position: sticky;
  top: 72px;
  align-self: flex-start;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 16px 0 16px 16px;
  padding: 14px 12px;
  border-radius: 14px;
  border: 1px solid var(--border-strong);
  background: rgba(16, 16, 24, 0.82);
  backdrop-filter: blur(10px);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
}

.game-links-title {
  font-family: var(--font-display);
  font-size: 15px;
  letter-spacing: 0.06em;
  color: var(--accent-2);
  padding: 0 4px 4px;
}

.game-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(12, 12, 18, 0.7);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  transition: background 0.12s, border-color 0.12s, transform 0.12s;
}

.game-link:hover {
  background: linear-gradient(135deg, #ff5c5c28, #ffd16618);
  border-color: #ffd16655;
  transform: translateY(-1px);
}

.game-link-icon {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  font-size: 16px;
  background: linear-gradient(135deg, #ff5c5c33, #ffd16622);
  box-shadow: inset 0 0 0 1px #ffd16633;
}

.game-link-name {
  min-width: 0;
  line-height: 1.2;
}

@media (max-width: 860px) {
  .page-shell {
    flex-direction: column;
  }

  .game-links {
    position: relative;
    top: 0;
    width: auto;
    flex: none;
    margin: 12px;
    order: -1;
  }
}

.site-footer {
  border-top: 1px solid var(--border);
  padding: 22px;
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
}

.site-footer strong {
  color: var(--text);
}

/* ─── Buttons ────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: 10px;
  border: 1px solid transparent;
  font-weight: 600;
  font-size: 14px;
  transition: background 0.12s, border-color 0.12s, color 0.12s, transform 0.12s;
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #ff7a4d);
  color: white;
  box-shadow: 0 8px 24px rgba(255, 92, 92, 0.25);
}

.btn-primary:hover {
  filter: brightness(1.05);
}

.btn-ghost {
  background: var(--bg-panel);
  border-color: var(--border);
  color: var(--text);
}

.btn-ghost:hover {
  border-color: var(--border-strong);
  background: #1e1e2a;
}

.btn-accent {
  background: transparent;
  border-color: var(--accent-2);
  color: var(--accent-2);
}

.btn-accent:hover {
  background: rgba(255, 209, 102, 0.1);
}

.btn-danger {
  color: #ff8a8a;
  border: 1px solid #ff5c5c44;
  background: #ff5c5c12;
}

.btn-danger:hover {
  background: #ff5c5c22;
}

.btn-sm {
  padding: 6px 10px;
  font-size: 12px;
  border-radius: 8px;
}

.btn-lg {
  padding: 14px 22px;
  font-size: 15px;
}

.btn-block {
  width: 100%;
}

/* ─── Hero ───────────────────────────────────────────────────── */
.hero {
  position: relative;
  overflow: hidden;
  padding: 72px 22px 56px;
  text-align: center;
  background:
    radial-gradient(ellipse 80% 50% at 50% -10%, rgba(255, 92, 92, 0.18), transparent 60%),
    radial-gradient(ellipse 50% 40% at 80% 40%, rgba(255, 209, 102, 0.06), transparent 50%),
    transparent;
}

.hero-kicker {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--accent-2);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 18px;
}

.hero h1 {
  margin: 0 auto 14px;
  max-width: 720px;
  font-family: var(--font-display);
  font-size: clamp(42px, 8vw, 72px);
  letter-spacing: 0.03em;
  line-height: 1.05;
  font-weight: 400;
}

.hero h1 span {
  color: var(--accent);
}

.hero-logo-wrap {
  margin: 0 auto 18px;
  max-width: min(560px, 92vw);
  line-height: 0;
}

.hero-logo {
  display: block;
  width: 100%;
  height: auto;
  max-height: min(220px, 36vw);
  margin: 0 auto;
  object-fit: contain;
  border-radius: 12px;
  pointer-events: none;
  filter: drop-shadow(0 12px 40px rgba(0, 0, 0, 0.45));
}

.skynet-feature {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  max-width: 640px;
  margin: 28px auto 0;
  padding: 28px 22px;
  text-decoration: none;
  color: #140e0c;
  background: linear-gradient(180deg, #ffe08a 0%, #ff5c5c 100%);
  border: 3px solid #f0efe8;
  border-radius: 16px;
  box-shadow: 0 16px 40px rgba(255, 92, 92, 0.28);
}
.skynet-feature:hover {
  filter: brightness(1.05);
  transform: translateY(-2px);
}
.skynet-feature-title {
  font-family: var(--font-display);
  font-size: clamp(2.4rem, 7vw, 4rem);
  letter-spacing: 0.06em;
  line-height: 0.95;
}
.skynet-feature-line {
  max-width: 28em;
  font-size: 15px;
  font-style: italic;
  line-height: 1.35;
  text-align: center;
}

/* Homepage mini-game cards (always visible under hero) */
.home-games {
  margin: 28px auto 0;
  max-width: 720px;
  text-align: center;
}

.home-games-title {
  margin: 0 0 14px;
  font-family: var(--font-display);
  font-size: clamp(22px, 4vw, 32px);
  letter-spacing: 0.04em;
  font-weight: 400;
  color: var(--accent-2);
  text-shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
}

.home-games-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.home-game-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 16px 12px;
  border-radius: 14px;
  border: 1px solid var(--border-strong);
  background: rgba(16, 16, 24, 0.78);
  backdrop-filter: blur(10px);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
  transition: transform 0.12s, border-color 0.12s, background 0.12s;
}

.home-game-card:hover {
  transform: translateY(-2px);
  border-color: #ffd16666;
  background: linear-gradient(160deg, #ff5c5c22, #ffd16614 55%, #12121aee);
}

.home-game-icon {
  font-size: 28px;
  line-height: 1;
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #ff5c5c33, #ffd16622);
  box-shadow: inset 0 0 0 1px #ffd16633;
}

.home-game-name {
  font-weight: 700;
  font-size: 15px;
  color: var(--text);
}

.home-game-desc {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.3;
}

@media (max-width: 700px) {
  .home-games-grid {
    grid-template-columns: 1fr;
  }
}


.hero-lead {
  margin: 0 auto 28px;
  max-width: 540px;
  color: var(--text-muted);
  font-size: 17px;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  margin-bottom: 40px;
}

.hero-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 24px;
  justify-content: center;
  color: var(--text-muted);
  font-size: 13px;
}

.hero-stats strong {
  display: block;
  color: var(--text);
  font-size: 22px;
  font-weight: 700;
}

/* ─── Sections ───────────────────────────────────────────────── */
.section {
  padding: 48px 22px;
  max-width: var(--max);
  margin: 0 auto;
}

.section-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
  flex-wrap: wrap;
}

.section-head h2 {
  margin: 0;
  font-size: 22px;
  letter-spacing: 0.02em;
}

.section-head p {
  margin: 4px 0 0;
  color: var(--text-muted);
  font-size: 13px;
}

.features {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}

.feature {
  padding: 20px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
}

.feature-icon {
  font-size: 22px;
  margin-bottom: 10px;
}

.feature h3 {
  margin: 0 0 6px;
  font-size: 15px;
}

.feature p {
  margin: 0;
  color: var(--text-muted);
  font-size: 13px;
}

.steps {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
  counter-reset: step;
}

.step {
  position: relative;
  padding: 20px 20px 20px 56px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: linear-gradient(180deg, #16161f, var(--bg-elevated));
}

.step::before {
  counter-increment: step;
  content: counter(step);
  position: absolute;
  left: 16px;
  top: 18px;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: #ff5c5c22;
  color: var(--accent);
  font-weight: 700;
  font-size: 13px;
}

.step h3 {
  margin: 0 0 6px;
  font-size: 15px;
}

.step p {
  margin: 0;
  color: var(--text-muted);
  font-size: 13px;
}

/* ─── Cards / library ────────────────────────────────────────── */
.comic-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}

.comic-card {
  display: flex;
  flex-direction: column;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  overflow: hidden;
  transition: border-color 0.15s, transform 0.15s;
}

.comic-card:hover {
  border-color: var(--border-strong);
  transform: translateY(-2px);
}

.comic-cover {
  aspect-ratio: 3 / 4;
  background:
    linear-gradient(145deg, #1c1c28, #12121a),
    var(--bg-panel);
  position: relative;
  overflow: hidden;
}

.comic-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.comic-cover-empty {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  color: var(--text-muted);
  font-size: 28px;
  opacity: 0.6;
}

.comic-body {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}

.comic-body h3 {
  margin: 0;
  font-size: 15px;
  line-height: 1.3;
}

.comic-meta {
  color: var(--text-muted);
  font-size: 12px;
}

.comic-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: auto;
  padding-top: 4px;
}

.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 48px 20px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
}

.empty-state strong {
  display: block;
  color: var(--text);
  margin-bottom: 6px;
  font-size: 16px;
}

/* ─── Owner gate / studio ────────────────────────────────────── */
.gallery-upload-box {
  margin-bottom: 8px;
  max-width: 640px;
}

.gallery-upload-title {
  margin: 0 0 8px;
  font-size: 1.15rem;
  font-weight: 700;
}

.gate-box {
  max-width: 440px;
  margin: 0 auto;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 16px;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

.check-row input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

/* ─── Upload ─────────────────────────────────────────────────── */
.upload-layout {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 22px;
  align-items: start;
}

@media (max-width: 860px) {
  .upload-layout {
    grid-template-columns: 1fr;
  }
}

.panel-box {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  padding: 20px;
}

.panel-box h2 {
  margin: 0 0 6px;
  font-size: 18px;
}

.panel-box .lead {
  margin: 0 0 18px;
  color: var(--text-muted);
  font-size: 13px;
}

.dropzone {
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 36px 20px;
  text-align: center;
  background: rgba(0, 0, 0, 0.2);
  transition: border-color 0.15s, background 0.15s;
  cursor: pointer;
}

.dropzone:hover,
.dropzone.dragover {
  border-color: var(--accent);
  background: rgba(255, 92, 92, 0.06);
}

.dropzone-icon {
  font-size: 32px;
  margin-bottom: 10px;
}

.dropzone strong {
  display: block;
  margin-bottom: 4px;
}

.dropzone span {
  color: var(--text-muted);
  font-size: 13px;
}

.field {
  margin-bottom: 14px;
}

.field label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 6px;
  font-weight: 600;
}

.field input,
.field textarea {
  width: 100%;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  outline: none;
}

.field input:focus,
.field textarea:focus {
  border-color: var(--accent);
}

.field textarea {
  min-height: 80px;
  resize: vertical;
}

.preview-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.preview-list li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  font-size: 13px;
}

.preview-list .muted {
  color: var(--text-muted);
}

.share-result {
  margin-top: 16px;
  padding: 14px;
  border-radius: 10px;
  border: 1px solid #6ee7b744;
  background: #6ee7b712;
  display: none;
}

.share-result.visible {
  display: block;
}

.share-result h3 {
  margin: 0 0 8px;
  color: var(--accent-3);
  font-size: 14px;
}

.share-url-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.share-url-row input {
  flex: 1;
  min-width: 180px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
}

/* ─── Reader page chrome ─────────────────────────────────────── */
.reader-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(ellipse at 50% 0%, #1a1520 0%, transparent 55%),
    var(--bg);
}

.reader-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 18px;
  background: rgba(18, 18, 26, 0.92);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(10px);
  flex-shrink: 0;
}

.reader-top h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

.reader-top .meta {
  font-size: 12px;
  color: var(--text-muted);
}

.reader-top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.reader-stage {
  flex: 1;
  overflow: hidden;
  padding: 0;
  position: relative;
  touch-action: none;
  cursor: default;
}

/* Hold Space → ready to pan */
.reader-stage.space-pan {
  cursor: grab;
}

.reader-stage.space-pan.is-panning,
.reader-stage.is-panning {
  cursor: grabbing;
}

.reader-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 10px 14px;
  background: rgba(22, 22, 29, 0.9);
  border: 1px solid var(--border);
  border-radius: 999px;
  backdrop-filter: blur(8px);
  flex-wrap: wrap;
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  width: fit-content;
  max-width: calc(100% - 24px);
  cursor: default;
}

.reader-nav > button {
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 14px;
}

.reader-nav > button:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent-2);
}

.reader-nav > button:disabled {
  opacity: 0.35;
  cursor: default;
}

.reader-zoom {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-panel);
  margin-left: 4px;
}

.reader-zoom .zoom-btn {
  min-width: 32px;
  padding: 4px 8px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  font-weight: 600;
  font-size: 14px;
  line-height: 1;
}

.reader-zoom .zoom-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.06);
  color: var(--accent-2);
}

.reader-zoom .zoom-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.reader-zoom .zoom-label {
  min-width: 52px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--accent-2);
  letter-spacing: 0.02em;
}

.reader-hint {
  position: absolute;
  bottom: 10px;
  left: 0;
  right: 0;
  font-size: 12px;
  color: var(--text-muted);
  margin: 0;
  text-align: center;
  pointer-events: none;
  z-index: 4;
  padding: 0 12px;
}

/* Desktop vs mobile control hints */
.reader-hint-mobile {
  display: none;
}

@media (hover: none), (pointer: coarse) {
  .reader-hint-desktop {
    display: none;
  }
  .reader-hint-mobile {
    display: block;
  }
}

.reader-error {
  max-width: 480px;
  margin: 60px auto;
  padding: 28px;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
}

.reader-error h2 {
  margin: 0 0 8px;
}

.reader-error p {
  color: var(--text-muted);
  margin: 0 0 16px;
}

/* Page is moved/scaled by JS: translate(pan) scale(zoom) — origin 0 0 */
#page-host,
.page-host {
  width: 720px;
  max-width: none;
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  will-change: transform;
  user-select: none;
}

#page-host .comic-page {
  width: 100%;
  max-width: none;
  margin: 0;
  /* Fallback page format if studio-styles.css fails to load */
  display: grid;
  gap: 10px;
  padding: 10px;
  aspect-ratio: 3 / 4;
  position: relative;
  overflow: hidden;
  box-sizing: border-box;
}

/* Keep panels in the comic page grid (not stacked as separate videos) */
#page-host .comic-page-panels {
  position: relative;
  z-index: 1;
  display: grid;
  gap: inherit;
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

#page-host .comic-page[data-layout="freeform"] .comic-page-panels {
  display: block;
  position: absolute;
  inset: 0;
  gap: 0;
}

#page-host .comic-page[data-layout="freeform"] .panel {
  position: absolute;
  width: auto;
  height: auto;
}

#page-host .comic-page-bg {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-size: cover;
  background-position: center;
}

#page-host .comic-page-shapes {
  position: absolute;
  inset: 0;
  z-index: 15;
  pointer-events: none;
  overflow: hidden;
}

#page-host .comic-page-shapes .geo-shape {
  pointer-events: auto;
}

#page-host .resize-handle,
#page-host .rot-handle,
#page-host .shape-delete-btn,
#page-host .panel-index {
  display: none !important;
}

#page-host .panel.selected,
#page-host .geo-shape.selected {
  outline: none !important;
  box-shadow: none !important;
}

/* Panels fill their grid cells inside the page format */
#page-host .panel {
  position: relative;
  cursor: default;
  overflow: hidden;
  min-height: 0;
  width: 100%;
  height: 100%;
  box-sizing: border-box;
}

#page-host .panel-media,
#page-host .panel-media.video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  display: block;
}

#page-host .panel.fit-contain .panel-media,
#page-host .panel-media.fit-contain {
  object-fit: contain !important;
}
#page-host .panel.fit-fill .panel-media,
#page-host .panel-media.fit-fill {
  object-fit: fill !important;
}
#page-host .panel.fit-cover .panel-media,
#page-host .panel-media.fit-cover {
  object-fit: cover !important;
}

#page-host .panel.has-video {
  cursor: pointer;
}

/* No play/pause chrome — hover alone drives video */
#page-host .video-overlay,
#page-host .play-badge,
#page-host .video-pill {
  display: none !important;
}

/* Audio pills from studio exports */
#page-host .audio-pill {
  position: absolute;
  left: 6px;
  bottom: 6px;
  z-index: 12;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  color: #0a0a0e;
  background: linear-gradient(135deg, #ffd166, #ffb347);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  cursor: pointer;
  pointer-events: auto;
  user-select: none;
}

#page-host .comic-page > .audio-pill {
  left: 10px;
  bottom: 10px;
  z-index: 30;
}

#page-host .has-audio.audio-playing .audio-pill {
  background: linear-gradient(135deg, #6ee7b7, #34d399);
}

#page-host .klmx-audio-el {
  display: none !important;
}

#page-host .comic-page.is-narrating .panel:not(.narrating),
#page-host .comic-page.is-narrating .geo-shape:not(.narrating) {
  opacity: 0.42;
  filter: saturate(0.7);
}

#page-host .panel.narrating,
#page-host .geo-shape.narrating {
  outline: 3px solid #ffd166;
  outline-offset: 2px;
  z-index: 42;
  box-shadow: 0 0 0 4px rgba(255, 209, 102, 0.28);
}

#page-host .geo-shape.has-audio {
  pointer-events: auto;
  cursor: pointer;
}

.narrate-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
}

.narrate-bar[hidden] {
  display: none !important;
}

.narrate-bar button {
  background: transparent;
  border: 1px solid #3d3d52;
  color: #f0efe8;
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  font: inherit;
}

.narrate-bar button:hover {
  border-color: #ffd166;
  color: #ffd166;
}

#page-host .geo-shape {
  pointer-events: auto;
  cursor: default;
}

#page-host .geo-shape.has-video {
  cursor: pointer;
}

/* Cinematic hover: black jagged lightning ants → solid white inner glow @ 30s */
#page-host .panel,
#page-host .geo-shape {
  --lz-speed: 1.2s;
  --lz-speed-b: 1.55s;
  --lz-speed-glow: 1.9s;
  --lz-speed-spark: 0.85s;
  --lz-dir: normal;
  --lz-dir-b: reverse;
  --lz-bright: 1;
  --lz-opacity: 0.85;
  --lz-dash: 10 14;
  --lz-dash-b: 4 18;
  --lz-dash-glow: 13 17;
  --lz-dash-spark: 2 26;
  --lz-stroke: rgba(12, 12, 14, 0.92);
  --lz-stroke-b: rgba(20, 20, 24, 0.75);
  --lz-stroke-glow: rgba(8, 8, 10, 0.45);
  --lz-stroke-spark: rgba(30, 30, 35, 0.7);
  --lz-inner: rgba(12, 12, 14, 0.15);
  --lz-inner-width: 0.6;
  --lz-width: 1.7;
  --lz-width-glow: 4.5;
}

#page-host .hover-march {
  display: block !important;
  position: absolute;
  inset: -10px;
  width: calc(100% + 20px);
  height: calc(100% + 20px);
  pointer-events: none;
  z-index: 8;
  overflow: visible;
  opacity: 0;
  transition: opacity 0.22s ease, filter 0.55s ease;
  filter: blur(0.15px) brightness(var(--lz-bright));
}

#page-host .panel:hover .hover-march,
#page-host .geo-shape:hover .hover-march {
  opacity: 1;
}

#page-host .hover-march .march-path {
  fill: none;
  stroke: var(--lz-stroke);
  stroke-width: var(--lz-width);
  stroke-dasharray: var(--lz-dash);
  stroke-linecap: square;
  stroke-linejoin: miter;
  vector-effect: non-scaling-stroke;
  opacity: var(--lz-opacity);
  transition:
    stroke 0.5s ease,
    stroke-width 0.5s ease,
    opacity 0.5s ease,
    stroke-dasharray 0.5s ease;
}

#page-host .hover-march .march-path.glow {
  stroke: var(--lz-stroke-glow);
  stroke-width: var(--lz-width-glow);
  stroke-dasharray: var(--lz-dash-glow);
  filter: blur(2.2px);
  opacity: calc(var(--lz-opacity) * 0.75);
  stroke-linecap: round;
}

#page-host .hover-march .march-path.b {
  stroke: var(--lz-stroke-b);
  stroke-width: calc(var(--lz-width) * 0.72);
  stroke-dasharray: var(--lz-dash-b);
  filter: blur(0.35px);
  opacity: calc(var(--lz-opacity) * 0.8);
}

#page-host .hover-march .march-path.spark {
  stroke: var(--lz-stroke-spark);
  stroke-width: calc(var(--lz-width) * 0.5);
  stroke-dasharray: var(--lz-dash-spark);
  filter: blur(0.25px);
  opacity: calc(var(--lz-opacity) * 0.75);
}

/* Clean inner frame — grows into solid white glow at final stage */
#page-host .hover-march .march-path.inner-glow {
  stroke: var(--lz-inner);
  stroke-width: var(--lz-inner-width);
  stroke-dasharray: none;
  opacity: 0;
  filter: none;
  transition: opacity 0.6s ease, stroke 0.6s ease, stroke-width 0.6s ease;
}

#page-host .panel:hover .hover-march .march-path.inner-glow,
#page-host .geo-shape:hover .hover-march .march-path.inner-glow {
  opacity: calc(0.2 + var(--lz-bright) * 0.12);
}

#page-host .panel:hover .hover-march .march-path:not(.inner-glow),
#page-host .geo-shape:hover .hover-march .march-path:not(.inner-glow) {
  animation: klmx-lightning-crawl var(--lz-speed) linear infinite;
  animation-direction: var(--lz-dir);
}

#page-host .panel:hover .hover-march .march-path.b,
#page-host .geo-shape:hover .hover-march .march-path.b {
  animation: klmx-lightning-crawl var(--lz-speed-b) linear infinite;
  animation-direction: var(--lz-dir-b);
}

#page-host .panel:hover .hover-march .march-path.glow,
#page-host .geo-shape:hover .hover-march .march-path.glow {
  animation:
    klmx-lightning-crawl var(--lz-speed-glow) linear infinite,
    klmx-lightning-breathe 2.2s ease-in-out infinite;
  animation-direction: var(--lz-dir), normal;
}

#page-host .panel:hover .hover-march .march-path.spark,
#page-host .geo-shape:hover .hover-march .march-path.spark {
  animation: klmx-lightning-crawl var(--lz-speed-spark) linear infinite;
  animation-direction: var(--lz-dir-b);
}

#page-host .panel.hover-sustained .hover-march,
#page-host .geo-shape.hover-sustained .hover-march {
  opacity: 1;
  filter: blur(0.1px) brightness(var(--lz-bright))
    drop-shadow(
      0 0 calc(3px + var(--lz-bright) * 2.5px)
        rgba(0, 0, 0, 0.45)
    );
}

/* 30s final: solid white line + glowing inner frame */
#page-host .panel.lightning-final .hover-march,
#page-host .geo-shape.lightning-final .hover-march {
  filter: brightness(2) drop-shadow(0 0 8px rgba(255, 255, 255, 0.85))
    drop-shadow(0 0 20px rgba(255, 255, 255, 0.55))
    drop-shadow(0 0 36px rgba(255, 255, 255, 0.3));
}

#page-host .panel.lightning-final .hover-march .march-path,
#page-host .geo-shape.lightning-final .hover-march .march-path {
  animation: none !important;
  stroke: #ffffff !important;
  stroke-width: 2.4 !important;
  stroke-dasharray: none !important;
  opacity: 1 !important;
  filter: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#page-host .panel.lightning-final .hover-march .march-path.glow,
#page-host .geo-shape.lightning-final .hover-march .march-path.glow {
  animation: klmx-lightning-breathe-hot 1.6s ease-in-out infinite !important;
  stroke: rgba(255, 255, 255, 0.8) !important;
  stroke-width: 8 !important;
  stroke-dasharray: none !important;
  opacity: 0.9 !important;
  filter: blur(3.5px);
}

#page-host .panel.lightning-final .hover-march .march-path.b,
#page-host .panel.lightning-final .hover-march .march-path.spark,
#page-host .geo-shape.lightning-final .hover-march .march-path.b,
#page-host .geo-shape.lightning-final .hover-march .march-path.spark {
  animation: none !important;
  stroke: rgba(255, 255, 255, 0.55) !important;
  stroke-dasharray: none !important;
  opacity: 0.4 !important;
  stroke-width: 1 !important;
}

/* Solid white glowing inner frame */
#page-host .panel.lightning-final .hover-march .march-path.inner-glow,
#page-host .geo-shape.lightning-final .hover-march .march-path.inner-glow {
  animation: klmx-inner-pulse 2s ease-in-out infinite !important;
  stroke: #ffffff !important;
  stroke-width: 3.4 !important;
  stroke-dasharray: none !important;
  opacity: 1 !important;
  filter: drop-shadow(0 0 6px rgba(255, 255, 255, 0.95))
    drop-shadow(0 0 14px rgba(255, 255, 255, 0.65));
}

@keyframes klmx-lightning-crawl {
  to {
    stroke-dashoffset: -72;
  }
}

@keyframes klmx-lightning-breathe {
  0%,
  100% {
    opacity: 0.3;
  }
  50% {
    opacity: 0.65;
  }
}

@keyframes klmx-lightning-breathe-hot {
  0%,
  100% {
    opacity: 0.55;
  }
  50% {
    opacity: 1;
  }
}

@keyframes klmx-inner-pulse {
  0%,
  100% {
    opacity: 0.85;
    filter: drop-shadow(0 0 6px rgba(255, 255, 255, 0.9))
      drop-shadow(0 0 12px rgba(255, 255, 255, 0.5));
  }
  50% {
    opacity: 1;
    filter: drop-shadow(0 0 10px rgba(255, 255, 255, 1))
      drop-shadow(0 0 22px rgba(255, 255, 255, 0.75));
  }
}

/* ─── Toast ──────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-panel);
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 100;
  box-shadow: var(--shadow);
  max-width: min(90vw, 420px);
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.error {
  border-color: #ff5c5c88;
  color: #ffb4b4;
}

.toast.ok {
  border-color: #6ee7b788;
}
