/* Tablet Together — cozy bedtime UI, big touch targets for little fingers */

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

:root {
  --plum: #4c1d95;
  --plum-deep: #2e1065;
  --peach: #ff8a5c;
  --gold: #ffd54f;
  --cream: #fff8ec;
  --ink: #3b2f4a;
}

html, body { height: 100%; }
body {
  font-family: -apple-system, "Avenir Next Rounded", "Trebuchet MS", "Segoe UI", sans-serif;
  background: linear-gradient(160deg, var(--plum-deep) 0%, var(--plum) 60%, #6d28d9 100%);
  color: var(--cream);
  overflow: hidden;
}

.view { display: none; height: 100vh; height: 100dvh; }
.view.active { display: flex; flex-direction: column; }
.hidden { display: none !important; }
.spacer { flex: 1; }

/* ---------- Landing ---------- */
#view-landing { align-items: center; justify-content: center; }
.landing-inner { text-align: center; max-width: 640px; padding: 24px; }
.landing-stars { color: var(--gold); letter-spacing: 18px; font-size: 20px; opacity: 0.8; margin-bottom: 12px; }
.logo { font-size: clamp(36px, 6vw, 56px); font-weight: 800; }
.logo span { color: var(--gold); }
.tagline { margin: 16px 0 34px; font-size: clamp(16px, 2.4vw, 20px); line-height: 1.5; opacity: 0.92; }

.role-buttons { display: flex; gap: 22px; justify-content: center; flex-wrap: wrap; }
.role-btn {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  width: 250px; padding: 26px 18px; border: none; border-radius: 28px; cursor: pointer;
  color: #fff; transition: transform 0.12s ease, box-shadow 0.12s ease;
  box-shadow: 0 10px 26px rgba(0,0,0,0.35);
}
.role-btn:active { transform: scale(0.96); }
.role-btn.adult { background: linear-gradient(150deg, #f97316, #ea580c); }
.role-btn.kid { background: linear-gradient(150deg, #22c1dc, #0e9db6); }
.role-emoji { font-size: 52px; }
.role-title { font-size: 22px; font-weight: 800; }
.role-sub { font-size: 14px; opacity: 0.9; }
.landing-foot { margin-top: 36px; font-size: 15px; opacity: 0.75; line-height: 1.5; }

/* ---------- Kid join ---------- */
#view-join { align-items: center; justify-content: center; }
.join-inner { text-align: center; padding: 24px; }
.join-inner h2 { font-size: 34px; margin-bottom: 8px; }
.join-hint { opacity: 0.8; margin-bottom: 26px; }
#join-code {
  display: block; margin: 0 auto 22px; width: 300px; padding: 18px;
  font-size: 52px; text-align: center; letter-spacing: 16px; text-transform: uppercase;
  border: 4px solid var(--gold); border-radius: 20px; background: rgba(255,255,255,0.12);
  color: #fff; outline: none; font-weight: 800;
}
#join-code::placeholder { color: rgba(255,255,255,0.35); letter-spacing: 12px; }
.join-error { color: #fca5a5; min-height: 22px; margin-top: 14px; font-weight: 600; }

.big-btn {
  padding: 16px 34px; font-size: 22px; font-weight: 800; border: none; border-radius: 20px;
  background: linear-gradient(150deg, var(--gold), #f5b301); color: #4a3200; cursor: pointer;
  box-shadow: 0 8px 20px rgba(0,0,0,0.3); transition: transform 0.12s ease;
}
.big-btn:active { transform: scale(0.95); }
.link-btn {
  background: none; border: none; color: var(--gold); font-size: 16px; cursor: pointer;
  padding: 10px 14px; font-weight: 700;
}

/* ---------- Room ---------- */
.room-header {
  display: flex; align-items: center; gap: 14px; padding: 10px 18px;
  padding-top: calc(10px + env(safe-area-inset-top, 0px));
  background: rgba(0,0,0,0.25);
}
.room-logo { font-size: 22px; }
.code-chip {
  font-size: 24px; font-weight: 800; letter-spacing: 6px; color: var(--gold);
  background: rgba(255,255,255,0.1); padding: 4px 14px; border-radius: 12px;
  border: 2px dashed rgba(255,213,79,0.5);
}
.status { font-size: 14px; font-weight: 600; padding: 4px 12px; border-radius: 999px; }
.status.waiting { background: rgba(255,255,255,0.15); color: #e9d5ff; }
.status.connected { background: #16a34a; color: #fff; }
.book-chip { font-size: 15px; font-weight: 700; opacity: 0.9; }

.room-body {
  flex: 1; display: flex; gap: 14px; padding: 14px; min-height: 0;
  padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
}

/* video column */
.video-col { width: 232px; display: flex; flex-direction: column; gap: 12px; flex-shrink: 0; }
.video-tile {
  position: relative; border-radius: 22px; overflow: hidden; background: #241640;
  box-shadow: 0 8px 20px rgba(0,0,0,0.35); aspect-ratio: 4 / 3.4;
}
.video-tile.remote { aspect-ratio: 4 / 4.4; }
.video-tile video { width: 100%; height: 100%; object-fit: cover; display: block; }
.video-placeholder {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; font-size: 40px; gap: 4px;
  color: rgba(255,255,255,0.75);
}
.video-placeholder small { font-size: 13px; }
.hear-btn {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  border: none; border-radius: 999px; padding: 10px 16px; cursor: pointer;
  background: rgba(255, 213, 79, 0.95); color: #4a3200; font-weight: 800; font-size: 14px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.4); animation: pop 0.4s ease;
}
.video-label {
  position: absolute; left: 10px; bottom: 8px; font-size: 12px; font-weight: 700;
  background: rgba(0,0,0,0.45); padding: 3px 10px; border-radius: 999px;
}
.call-controls { display: flex; gap: 10px; justify-content: center; }
.call-controls button {
  width: 52px; height: 52px; font-size: 22px; border: none; border-radius: 50%;
  background: rgba(255,255,255,0.15); color: #fff; cursor: pointer;
}
.call-controls button.off { background: #dc2626; }

/* content column */
.content-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }

/* shelf */
.shelf { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.shelf-top { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 12px; }
.shelf-top h2 { font-size: 24px; }
.adult-tools { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.tool {
  display: inline-flex; align-items: center; gap: 8px; background: rgba(255,255,255,0.12);
  padding: 8px 14px; border-radius: 14px; font-size: 15px; cursor: pointer; font-weight: 600;
}
.tool input[type="text"] {
  border: none; background: transparent; color: #fff; font-size: 16px; width: 120px;
  outline: none; font-weight: 700; border-bottom: 2px solid rgba(255,255,255,0.3);
}
.avatar-preview { width: 44px; height: 44px; border-radius: 50%; object-fit: cover; border: 3px solid var(--gold); }
.look-tool { padding: 4px 6px; gap: 4px; }
.look-btn {
  border: 2px solid transparent; background: transparent; font-size: 22px;
  border-radius: 10px; padding: 3px 8px; cursor: pointer; opacity: 0.45;
}
.look-btn.on { background: rgba(255,213,79,0.25); border-color: var(--gold); opacity: 1; }

.shelf-grid {
  flex: 1; overflow-y: auto; display: grid; gap: 16px; align-content: start;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); padding-bottom: 12px;
}
.shelf-section-title {
  grid-column: 1 / -1; font-size: 17px; font-weight: 800; opacity: 0.9;
  margin: 6px 2px 0; letter-spacing: 0.3px;
}
.book-card {
  border: none; border-radius: 20px; overflow: hidden; cursor: pointer; text-align: left;
  background: var(--cream); color: var(--ink); box-shadow: 0 8px 18px rgba(0,0,0,0.3);
  transition: transform 0.12s ease; padding: 0;
}
.book-card:active { transform: scale(0.96); }
.book-card .cover { display: block; line-height: 0; }
.book-card .cover svg { width: 100%; height: auto; display: block; }
.book-card .meta { padding: 10px 14px 12px; }
.book-card .meta strong { display: block; font-size: 16px; line-height: 1.25; }
.book-card .meta small { opacity: 0.65; font-weight: 600; }
.book-card.new-story {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  background: linear-gradient(150deg, #7c3aed, #5b21b6); color: #fff; min-height: 180px;
  border: 3px dashed rgba(255,255,255,0.4); font-size: 17px; font-weight: 800;
}
.book-card.new-story .plus { font-size: 44px; }

/* reader */
.reader { flex: 1; display: flex; flex-direction: column; min-height: 0; position: relative; }
.find-bar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px;
  font-size: 15px; min-height: 40px;
}
.find-label { font-weight: 700; opacity: 0.85; }
.find-chip {
  display: inline-flex; align-items: center; gap: 6px; background: rgba(255,255,255,0.14);
  padding: 6px 14px; border-radius: 999px; font-weight: 700; font-size: 15px;
  border: 2px solid transparent; transition: all 0.2s ease;
}
.find-chip.found { background: #16a34a; border-color: #86efac; }
.find-chip .check { display: none; }
.find-chip.found .check { display: inline; }

.scene {
  flex: 1; min-height: 0; border-radius: 22px; overflow: hidden; background: #cdeeff;
  box-shadow: 0 10px 26px rgba(0,0,0,0.35); line-height: 0;
}
.scene svg { width: 100%; height: 100%; }
.scene .hotspot { cursor: pointer; }

.page-text {
  margin: 12px 4px 8px; font-size: clamp(17px, 2.2vw, 23px); line-height: 1.45;
  font-weight: 700; text-align: center; color: var(--cream); min-height: 2.6em;
}

.page-nav { display: flex; align-items: center; justify-content: center; gap: 18px; padding-bottom: 4px; }
.nav-btn {
  width: 64px; height: 64px; font-size: 26px; border: none; border-radius: 50%;
  background: linear-gradient(150deg, var(--gold), #f5b301); color: #4a3200; cursor: pointer;
  box-shadow: 0 6px 14px rgba(0,0,0,0.3); transition: transform 0.1s ease;
}
.nav-btn:active { transform: scale(0.92); }
.nav-btn:disabled { opacity: 0.3; cursor: default; }
.page-dots { display: flex; gap: 8px; }
.page-dots .dot { width: 12px; height: 12px; border-radius: 50%; background: rgba(255,255,255,0.3); }
.page-dots .dot.on { background: var(--gold); }

.celebrate {
  position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%);
  background: rgba(76, 29, 149, 0.92); border: 3px solid var(--gold);
  padding: 20px 36px; border-radius: 24px; font-size: 28px; font-weight: 800;
  animation: pop 0.45s ease; pointer-events: none; box-shadow: 0 12px 30px rgba(0,0,0,0.4);
}
@keyframes pop {
  0% { transform: translate(-50%, -50%) scale(0.3); opacity: 0; }
  70% { transform: translate(-50%, -50%) scale(1.1); }
  100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

/* tap label bubble inside the SVG */
.tap-label { font-family: inherit; font-weight: 800; }

/* ---------- Story Studio modal ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(20, 10, 40, 0.7); z-index: 40;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal-card {
  background: var(--cream); color: var(--ink); border-radius: 26px; padding: 28px 30px;
  width: 100%; max-width: 460px; box-shadow: 0 20px 50px rgba(0,0,0,0.5);
}
.modal-card h2 { font-size: 26px; margin-bottom: 4px; }
.studio-sub { opacity: 0.7; margin-bottom: 20px; font-weight: 600; }
.modal-card label { display: block; font-weight: 700; margin-bottom: 16px; font-size: 15px; }
.modal-card input, .modal-card select {
  display: block; width: 100%; margin-top: 6px; padding: 12px 14px; font-size: 17px;
  border: 2px solid #d8c9ee; border-radius: 12px; background: #fff; color: var(--ink);
  font-weight: 600; outline-color: var(--plum);
}
.modal-actions { display: flex; justify-content: flex-end; align-items: center; gap: 10px; margin-top: 8px; }
.modal-actions .link-btn { color: var(--plum); }

.crop-card { text-align: center; }
#crop-canvas {
  border-radius: 18px; touch-action: none; cursor: grab; margin: 4px auto 12px;
  display: block; max-width: 100%;
}
#crop-canvas:active { cursor: grabbing; }
#crop-zoom { width: 100%; margin-bottom: 12px; accent-color: var(--plum); }
.crop-card .modal-actions { justify-content: center; }

/* ---------- Narrow screens (portrait tablets / phones) ---------- */
@media (max-width: 820px) {
  /* Phones scroll like a normal page — never trap content off-screen. */
  body { overflow-y: auto; }
  .view.active { height: auto; min-height: 100dvh; }
  .room-header { position: sticky; top: 0; z-index: 10; background: #2c1367; }
  .room-body { flex-direction: column; gap: 8px; padding: 8px; padding-bottom: calc(30px + env(safe-area-inset-bottom, 0px)); }
  .room-header { gap: 8px; padding-left: 10px; padding-right: 10px; }
  .code-chip { font-size: 18px; letter-spacing: 4px; padding: 3px 10px; }
  .status { font-size: 12px; }
  .book-chip { display: none; }
  .video-col { width: 100%; flex-direction: row; align-items: stretch; }
  .video-tile, .video-tile.remote { flex: 1; aspect-ratio: auto; height: 108px; }
  .video-placeholder { font-size: 26px; }
  .call-controls { flex-direction: column; justify-content: center; gap: 8px; }
  .call-controls button { width: 42px; height: 42px; font-size: 17px; }
  .scene { flex: 0 1 auto; aspect-ratio: 8 / 5; margin: 0 auto; width: 100%; }
  .video-tile, .video-tile.remote { height: 132px; }
  .find-bar { gap: 5px; font-size: 13px; min-height: 0; margin-bottom: 5px; }
  .find-chip { padding: 4px 10px; font-size: 13px; }
  .page-text { font-size: 15px; line-height: 1.35; margin: 8px 2px 5px; min-height: 0; max-height: 4.2em; overflow-y: auto; }
  .nav-btn { width: 52px; height: 52px; font-size: 21px; }
  .page-dots .dot { width: 9px; height: 9px; }
  .shelf-top h2 { font-size: 18px; }
  .shelf-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
}
