/* Pixel Storyteller — kid-proof narrated storybook */
:root {
  --bg: #140b24;
  --bg2: #1b1030;
  --panel: #241640;
  --panel2: #2c1b4e;
  --ink: #f6eefc;
  --dim: #b9a8d6;
  --accent: #ffcf5c;
  --accent2: #ff8fb1;
  --good: #7ee0a6;
  --shadow: 0 10px 30px rgba(0, 0, 0, .45);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
/* the [hidden] attribute must always win over the display rules below */
[hidden] { display: none !important; }

html, body {
  margin: 0; height: 100%; background: var(--bg); color: var(--ink);
  font-family: "Baloo 2", "Comic Sans MS", "Segoe UI", system-ui, sans-serif;
  /* kid-proofing: no selection, no zoom-jank, no pull-to-refresh */
  user-select: none; -webkit-user-select: none;
  touch-action: manipulation; overscroll-behavior: none;
  overflow: hidden; position: fixed; inset: 0;
}
img { -webkit-user-drag: none; user-select: none; }

.view { position: absolute; inset: 0; display: none; flex-direction: column; }
.view.active { display: flex; }

/* ───────────── SHELF ───────────── */
#shelf {
  background:
    radial-gradient(1200px 600px at 80% -10%, #34215e 0%, transparent 60%),
    radial-gradient(900px 500px at -10% 110%, #3a1c53 0%, transparent 55%),
    var(--bg2);
  padding: env(safe-area-inset-top) 0 0;
}
.shelf-top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 20px 10px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 26px; letter-spacing: .5px; }
.brand-pixel {
  width: 22px; height: 22px; border-radius: 4px; image-rendering: pixelated;
  background: conic-gradient(from 45deg, var(--accent), var(--accent2), var(--good), var(--accent));
  box-shadow: 0 0 0 3px #0004 inset;
}
.shelf-grid {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 16px; padding: 8px 18px calc(28px + env(safe-area-inset-bottom));
}
.story-card {
  border: 0; padding: 0; background: var(--panel); color: var(--ink);
  border-radius: 18px; overflow: hidden; box-shadow: var(--shadow);
  display: flex; flex-direction: column; cursor: pointer;
  transition: transform .12s ease;
}
.story-card:active { transform: scale(.96); }
.story-card .cover {
  width: 100%; aspect-ratio: 4/3; object-fit: cover; display: block;
  image-rendering: pixelated; background: #100a1e;
}
.story-card .cap { padding: 10px 12px 12px; text-align: left; }
.story-card .cap b { font-size: 16px; line-height: 1.15; display: block; }
.story-card .cap span { font-size: 12px; color: var(--dim); }

.shelf-empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; }
.shelf-empty p { margin: 2px; font-size: 20px; }
.shelf-empty .dim { color: var(--dim); font-size: 15px; }
.shelf-empty-art {
  width: 92px; height: 92px; border-radius: 16px; margin-bottom: 8px; image-rendering: pixelated;
  background: repeating-conic-gradient(#2c1b4e 0 25%, #241640 0 50%) 0 0 / 24px 24px;
  box-shadow: var(--shadow);
}
.dim { color: var(--dim); }

/* hold-to-unlock grown-up button */
.lock {
  position: relative; width: 44px; height: 44px; border-radius: 50%;
  border: 0; background: #ffffff14; display: grid; place-items: center; cursor: pointer;
}
.lock-glyph { width: 16px; height: 13px; border: 3px solid var(--dim); border-radius: 3px; position: relative; margin-top: 6px; }
.lock-glyph::before { content: ""; position: absolute; width: 10px; height: 9px; border: 3px solid var(--dim); border-bottom: 0; border-radius: 6px 6px 0 0; left: 0; top: -10px; }
.lock-ring { position: absolute; inset: 0; transform: rotate(-90deg); pointer-events: none; }
.lock-ring circle { fill: none; stroke: var(--accent); stroke-width: 3;
  stroke-dasharray: 126; stroke-dashoffset: 126; transition: stroke-dashoffset .05s linear; }
.lock.holding { background: #ffffff22; }

/* ───────────── PLAYER ───────────── */
#player { background: #05030c; }
.scene-wrap { position: relative; flex: 1; min-height: 0; background: #05030c; overflow: hidden; }
.scene {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: contain; image-rendering: pixelated;
  filter: drop-shadow(0 0 30px #0008);
}
.tapzone { position: absolute; top: 0; bottom: 0; width: 34%; z-index: 3; }
.tapzone.left { left: 0; }
.tapzone.right { right: 0; }
.home {
  position: absolute; top: calc(10px + env(safe-area-inset-top)); left: 12px; z-index: 5;
  width: 46px; height: 46px; border-radius: 50%; border: 0; background: #00000055;
  backdrop-filter: blur(4px); display: grid; place-items: center; cursor: pointer;
}
.home span { position: relative; width: 16px; height: 2.5px; border-radius: 2px; background: var(--ink); }
.home span::before, .home span::after { content: ""; position: absolute; left: -1px; width: 9px; height: 2.5px; border-radius: 2px; background: var(--ink); }
.home span::before { transform: rotate(-45deg); top: -3px; }
.home span::after { transform: rotate(45deg); top: 3px; }
.playpause {
  position: absolute; inset: 0; margin: auto; width: 96px; height: 96px; border-radius: 50%;
  background: #00000066; display: grid; place-items: center; z-index: 4; pointer-events: none;
  opacity: 0; transition: opacity .25s ease; transform: scale(.8);
}
.playpause.show { opacity: 1; transform: scale(1); }
.playpause::before {
  content: ""; width: 0; height: 0; border-left: 30px solid var(--ink);
  border-top: 20px solid transparent; border-bottom: 20px solid transparent; margin-left: 6px;
}
.playpause.paused::before { border: 0; width: 26px; height: 30px;
  background: linear-gradient(90deg, var(--ink) 0 34%, transparent 0 66%, var(--ink) 0); margin: 0; }

.page-panel {
  background: linear-gradient(180deg, var(--panel) 0%, var(--bg2) 100%);
  padding: 16px 22px calc(14px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 10px; min-height: 22vh; justify-content: center;
}
.narration { margin: 0; font-size: clamp(20px, 5.4vw, 30px); line-height: 1.32; font-weight: 700; text-align: center; }
.dots { display: flex; gap: 8px; justify-content: center; }
.dots i { width: 9px; height: 9px; border-radius: 50%; background: #ffffff2b; transition: all .18s; }
.dots i.on { background: var(--accent); transform: scale(1.25); }

.end-card {
  position: absolute; inset: 0; z-index: 8; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 18px; background: #0a0618ee; backdrop-filter: blur(3px);
}
.end-card h2 { margin: 0; font-size: 40px; }
.end-star { width: 84px; height: 84px; image-rendering: pixelated;
  background: conic-gradient(from 0deg, var(--accent), var(--accent2), var(--accent));
  clip-path: polygon(50% 0, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
  filter: drop-shadow(0 0 18px #ffcf5c88); animation: spin 6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.end-actions { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }

.big-btn {
  border: 0; border-radius: 16px; padding: 15px 24px; font-size: 19px; font-weight: 800;
  background: var(--accent); color: #3a2400; cursor: pointer; box-shadow: var(--shadow);
}
.big-btn:active { transform: scale(.96); }
.big-btn.ghost { background: #ffffff1a; color: var(--ink); }

/* ───────────── GROWN-UP SHEET ───────────── */
.sheet { position: absolute; inset: 0; z-index: 20; background: #05030ccc; display: flex; align-items: flex-end; }
.sheet-card {
  width: 100%; max-height: 92%; overflow-y: auto; background: var(--bg2);
  border-radius: 24px 24px 0 0; padding: 18px 20px calc(24px + env(safe-area-inset-bottom));
  box-shadow: 0 -12px 40px #000a; display: flex; flex-direction: column; gap: 14px;
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head h2 { margin: 0; font-size: 22px; }
.x { border: 0; background: #ffffff14; color: var(--ink); width: 38px; height: 38px; border-radius: 50%; font-size: 16px; cursor: pointer; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field span { font-size: 14px; color: var(--dim); }
.field input {
  font: inherit; padding: 14px 14px; border-radius: 14px; border: 2px solid #ffffff1f;
  background: var(--panel); color: var(--ink); outline: none;
}
.field input:focus { border-color: var(--accent); }
.row { display: flex; gap: 12px; }
.mini { flex: 1; display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--dim); }
.mini select { font: inherit; padding: 10px; border-radius: 12px; border: 2px solid #ffffff1f; background: var(--panel); color: var(--ink); }
.gen-status { display: flex; flex-direction: column; gap: 8px; }
.gen-bar { height: 12px; border-radius: 8px; background: #ffffff14; overflow: hidden; }
.gen-bar span { display: block; height: 100%; width: 0%; background: linear-gradient(90deg, var(--accent2), var(--accent)); transition: width .4s ease; }
.gen-status.err .gen-bar span { background: #ff6b6b; }
.sheet-list-head { font-size: 13px; color: var(--dim); margin-top: 4px; }
.manage-list { display: flex; flex-direction: column; gap: 8px; }
.manage-row { display: flex; align-items: center; gap: 10px; background: var(--panel); border-radius: 12px; padding: 8px 10px; }
.manage-row img { width: 46px; height: 36px; object-fit: cover; border-radius: 8px; image-rendering: pixelated; }
.manage-row b { flex: 1; font-size: 15px; }
.manage-row button { border: 0; background: #ff6b6b22; color: #ff9d9d; border-radius: 10px; padding: 8px 12px; font-weight: 700; cursor: pointer; }

@media (min-width: 720px) {
  .sheet { align-items: center; justify-content: center; }
  .sheet-card { max-width: 520px; border-radius: 24px; max-height: 88%; }
}
