:root {
  color-scheme: light;
  font-family: "Leelawadee UI", "Noto Sans Thai", "Segoe UI", system-ui, sans-serif;
  --ink: #18334d;
  --muted: #64788d;
  --blue: #356fd4;
  --blue-dark: #2859ae;
  --cream: #fff9e9;
  --line: #dbe7f4;
  --panel: #f7faff;
  --shadow: 0 18px 50px rgba(41, 74, 112, 0.14);
}

* { box-sizing: border-box; }

html,
body {
  margin: 0;
  width: 100%;
  min-width: 760px;
  height: 100%;
  overflow: hidden;
  background: #eaf2fd;
  color: var(--ink);
}

button,
input { font: inherit; }

button { touch-action: manipulation; }

.app-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: 100vw;
  height: 100vh;
  background:
    radial-gradient(circle at 8% 0%, rgba(255, 231, 157, 0.5), transparent 28%),
    radial-gradient(circle at 92% 4%, rgba(149, 205, 255, 0.4), transparent 30%),
    #eaf2fd;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto minmax(180px, 1fr);
  gap: 20px;
  align-items: center;
  padding: 12px 18px;
  border-bottom: 1px solid rgba(120, 148, 178, 0.22);
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(16px);
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  flex: 0 0 auto;
  border-radius: 15px;
  background: linear-gradient(145deg, #4a88ef, #315fb8);
  color: white;
  box-shadow: 0 8px 20px rgba(53, 111, 212, 0.28);
  font-size: 24px;
  font-weight: 900;
}

.brand h1,
.brand p { margin: 0; }

.brand h1 { font-size: 22px; line-height: 1.1; }
.brand p { margin-top: 2px; color: var(--muted); font-size: 13px; }

.mode-tabs {
  display: flex;
  gap: 6px;
  padding: 5px;
  border: 1px solid #d8e3f0;
  border-radius: 18px;
  background: #edf3fa;
}

.mode-tab {
  min-width: 112px;
  min-height: 44px;
  border: 0;
  border-radius: 13px;
  padding: 8px 17px;
  background: transparent;
  color: #4f6881;
  font-weight: 800;
  cursor: pointer;
}

.mode-tab.active {
  background: white;
  color: var(--blue-dark);
  box-shadow: 0 4px 14px rgba(44, 82, 127, 0.14);
}

.session-badge {
  justify-self: end;
  padding: 9px 13px;
  border-radius: 999px;
  background: #e6f7ee;
  color: #24774f;
  font-size: 13px;
  font-weight: 800;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(270px, 22vw);
  gap: 14px;
  min-height: 0;
  padding: 14px;
}

.activity-frame,
.side-panel { min-width: 0; min-height: 0; }

.activity-frame {
  overflow: hidden;
  border: 4px solid white;
  border-radius: 28px;
  background: white;
  box-shadow: var(--shadow);
}

.activity-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: 100%;
  height: 100%;
  background: var(--cream);
}

.activity-panel[data-panel="youtube"] {
  grid-template-rows: auto auto minmax(0, 1fr) auto;
}

.activity-panel[hidden] { display: none; }

[hidden] { display: none !important; }

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 70px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  background: white;
}

.panel-header h2,
.panel-header p { margin: 0; }

.panel-header h2 {
  margin-top: 2px;
  font-size: clamp(21px, 2vw, 30px);
  line-height: 1.2;
}

.eyebrow {
  color: #678099;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.page-pill,
.timer-pill {
  flex: 0 0 auto;
  padding: 8px 13px;
  border-radius: 999px;
  background: #eaf2ff;
  color: #2e5ba4;
  font-weight: 900;
}

.story-scene {
  min-height: 0;
  padding: 12px;
}

.story-scene svg {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 300px;
  border-radius: 22px;
  background: #dff2ff;
}

.story-controls {
  display: grid;
  grid-template-columns: minmax(130px, 1fr) auto minmax(130px, 1fr);
  gap: 12px;
  align-items: center;
  padding: 12px 16px 15px;
  border-top: 1px solid rgba(218, 229, 240, 0.65);
  background: rgba(255, 255, 255, 0.76);
}

.button {
  min-height: 46px;
  border: 0;
  border-radius: 14px;
  padding: 9px 15px;
  font-weight: 900;
  cursor: pointer;
}

.button:disabled { opacity: 0.45; cursor: default; }

.button.primary {
  background: var(--blue);
  color: white;
  box-shadow: 0 7px 18px rgba(53, 111, 212, 0.24);
}

.button.primary:hover:not(:disabled) { background: var(--blue-dark); }
.button.soft { background: #e7effa; color: #315e9d; }
.button.tool { background: #f0f4f9; color: #425d78; }
.button.tool.active { outline: 3px solid #9ec2f5; background: #dceaff; }
.button.danger { background: #ffe7e9; color: #a23d48; }
.button.camera { min-width: 94px; background: #2f9c69; color: white; }
.button.camera.stop { background: #b84753; }

.word-chips {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 7px;
}

.word-chips span {
  padding: 7px 11px;
  border: 2px solid #dae8fa;
  border-radius: 999px;
  background: white;
  font-size: clamp(14px, 1.3vw, 19px);
  font-weight: 900;
}

.draw-heading { align-items: flex-end; }

.draw-tools {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
}

.color-tools { display: flex; gap: 5px; }

.color-button {
  width: 34px;
  height: 34px;
  border: 4px solid white;
  border-radius: 50%;
  background: var(--swatch);
  box-shadow: 0 0 0 1px #c9d7e7;
  cursor: pointer;
}

.color-button.selected { box-shadow: 0 0 0 3px #8ab4ef; }

.brush-label {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #4b6178;
  font-size: 13px;
  font-weight: 800;
}

.brush-label input { width: 96px; }

.canvas-wrap {
  min-height: 0;
  padding: 12px;
  background:
    linear-gradient(90deg, rgba(86, 132, 188, 0.06) 1px, transparent 1px),
    linear-gradient(rgba(86, 132, 188, 0.06) 1px, transparent 1px),
    #f7fbff;
  background-size: 28px 28px;
}

#drawingCanvas {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 340px;
  border: 3px solid white;
  border-radius: 22px;
  background: white;
  box-shadow: inset 0 0 0 1px #d9e5f2, 0 10px 26px rgba(53, 84, 121, 0.1);
  cursor: crosshair;
  touch-action: none;
}

.drawing-footer,
.youtube-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 62px;
  padding: 10px 17px;
  border-top: 1px solid var(--line);
  background: white;
  color: #5a7086;
  font-size: 14px;
}

.youtube-parent-controls {
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  background: #f7faff;
}

.youtube-parent-controls label {
  display: block;
  margin-bottom: 6px;
  color: #415c75;
  font-size: 13px;
  font-weight: 900;
}

.youtube-input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.youtube-input-row input {
  min-width: 0;
  min-height: 46px;
  border: 2px solid #d2dfed;
  border-radius: 13px;
  padding: 8px 12px;
  color: var(--ink);
  outline: none;
}

.youtube-input-row input:focus { border-color: #73a1e6; box-shadow: 0 0 0 4px #dceaff; }

#youtubeStatus {
  margin: 7px 0 0;
  color: #687f94;
  font-size: 12px;
}

#youtubeStatus.error { color: #b03e49; }
#youtubeStatus.success { color: #277b52; }

.youtube-stage {
  display: grid;
  place-items: center;
  min-height: 0;
  padding: 12px;
  background: #172232;
}

.youtube-stage iframe {
  width: 100%;
  height: 100%;
  min-height: 320px;
  border: 0;
  border-radius: 19px;
  background: #000;
}

.youtube-placeholder {
  display: grid;
  place-items: center;
  gap: 8px;
  width: min(540px, 80%);
  padding: 48px 24px;
  border: 2px dashed #6d8099;
  border-radius: 22px;
  color: #d9e5f4;
  text-align: center;
}

.youtube-placeholder span:last-child { color: #99adc4; font-size: 13px; }
.play-symbol { font-size: 44px; color: #ef5c62; }

.side-panel {
  display: grid;
  grid-template-rows: minmax(225px, 42vh) minmax(0, 1fr) auto;
  gap: 12px;
}

.camera-card,
.guide-card,
.privacy-card {
  overflow: hidden;
  border: 3px solid white;
  border-radius: 23px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.camera-card {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  background: #172130;
}

.camera-view { position: relative; min-height: 0; }

.camera-view video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
  background: #172130;
}

.camera-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 5px;
  padding: 18px;
  color: #d7e4f4;
  text-align: center;
}

.camera-placeholder span:last-child { color: #93a7bd; font-size: 12px; }
.camera-icon { color: #80a8db; font-size: 32px; }

.camera-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 9px;
  padding: 9px 10px;
  background: white;
}

.camera-controls > div { display: grid; min-width: 0; }
.camera-controls strong { font-size: 14px; }
.camera-controls span { overflow: hidden; color: var(--muted); font-size: 11px; white-space: nowrap; text-overflow: ellipsis; }

.guide-card {
  min-height: 0;
  padding: 17px;
  overflow: auto;
}

.guide-card h2 { margin: 4px 0 8px; font-size: 20px; }
.guide-card > p:not(.eyebrow) { margin: 0; color: #526a82; line-height: 1.55; font-size: 14px; }

.observable-note {
  display: grid;
  gap: 4px;
  margin-top: 14px;
  padding: 12px;
  border: 1px solid #d8e5f3;
  border-radius: 15px;
  background: white;
  color: #5a7188;
  font-size: 12px;
  line-height: 1.45;
}

.observable-note strong { color: #304d69; }

.privacy-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
}

.privacy-card > div { display: grid; }
.privacy-card strong { font-size: 13px; }
.privacy-card span:last-child { color: var(--muted); font-size: 11px; }

.privacy-dot {
  width: 12px;
  height: 12px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #39a570;
  box-shadow: 0 0 0 5px #dff4ea;
}

@media (max-width: 1050px) {
  .topbar { grid-template-columns: auto 1fr auto; gap: 10px; }
  .mode-tab { min-width: 90px; padding-inline: 11px; }
  .workspace { grid-template-columns: minmax(0, 1fr) 250px; gap: 9px; padding: 9px; }
  .draw-heading { align-items: center; }
  .draw-tools { max-width: 430px; }
  .guide-card { padding: 12px; }
}

/* Drawing mode keeps child controls touch-friendly while giving the canvas
   nearly all remaining screen space. */
html[data-mode="draw"] .topbar {
  grid-template-columns: minmax(150px, 0.7fr) auto minmax(120px, 0.7fr);
  gap: 8px;
  padding: 5px 10px;
}

html[data-mode="draw"] .brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  font-size: 21px;
}

html[data-mode="draw"] .brand p,
html[data-mode="draw"] .session-badge { display: none; }

html[data-mode="draw"] .mode-tabs { padding: 3px; }

html[data-mode="draw"] .mode-tab {
  min-width: 92px;
  min-height: 42px;
  padding: 6px 12px;
}

html[data-mode="draw"] .workspace {
  grid-template-columns: minmax(0, 1fr) minmax(170px, 16vw);
  gap: 6px;
  padding: 6px;
}

html[data-mode="draw"] .activity-frame {
  border-width: 2px;
  border-radius: 16px;
}

html[data-mode="draw"] #drawPanel {
  grid-template-rows: auto minmax(0, 1fr) auto;
}

html[data-mode="draw"] .draw-heading {
  min-height: 52px;
  gap: 8px;
  padding: 5px 8px;
}

html[data-mode="draw"] .draw-heading > div:first-child { display: none; }

html[data-mode="draw"] .draw-tools {
  width: 100%;
  max-width: none;
  justify-content: center;
  gap: 6px;
}

html[data-mode="draw"] .color-button {
  width: 38px;
  height: 38px;
}

html[data-mode="draw"] .button.tool,
html[data-mode="draw"] .button.danger {
  min-height: 42px;
  padding: 7px 12px;
}

html[data-mode="draw"] .canvas-wrap { padding: 4px; }

html[data-mode="draw"] #drawingCanvas {
  min-height: 0;
  border-width: 2px;
  border-radius: 12px;
}

html[data-mode="draw"] .drawing-footer {
  min-height: 34px;
  padding: 5px 9px;
  font-size: 12px;
}

html[data-mode="draw"] .side-panel {
  grid-template-rows: minmax(145px, 34vh) minmax(0, 1fr);
  gap: 6px;
}

html[data-mode="draw"] .camera-card,
html[data-mode="draw"] .guide-card {
  border-width: 2px;
  border-radius: 14px;
}

html[data-mode="draw"] .camera-placeholder { padding: 8px; }
html[data-mode="draw"] .camera-icon { font-size: 24px; }
html[data-mode="draw"] .camera-controls { padding: 5px 6px; }
html[data-mode="draw"] .button.camera { min-width: 78px; min-height: 42px; padding: 6px 8px; }

html[data-mode="draw"] .guide-card {
  padding: 9px;
}

html[data-mode="draw"] .guide-card .eyebrow,
html[data-mode="draw"] .observable-note,
html[data-mode="draw"] .privacy-card { display: none; }

html[data-mode="draw"] .guide-card h2 {
  margin: 0 0 5px;
  font-size: 15px;
}

html[data-mode="draw"] .guide-card > p:not(.eyebrow) {
  font-size: 12px;
  line-height: 1.35;
}

.draw-menu-button {
  position: absolute;
  right: 10px;
  bottom: 10px;
  z-index: 20;
  min-width: 76px;
  min-height: 46px;
  border: 3px solid white;
  border-radius: 999px;
  background: rgba(34, 70, 112, 0.9);
  color: white;
  box-shadow: 0 6px 18px rgba(28, 55, 88, 0.24);
  font-weight: 900;
  cursor: pointer;
}

html[data-mode="draw"] #drawPanel { position: relative; }

html[data-mode="draw"].draw-focus .app-shell {
  grid-template-rows: minmax(0, 1fr);
}

html[data-mode="draw"].draw-focus .topbar,
html[data-mode="draw"].draw-focus .side-panel,
html[data-mode="draw"].draw-focus .draw-heading,
html[data-mode="draw"].draw-focus .drawing-footer {
  display: none;
}

html[data-mode="draw"].draw-focus .workspace {
  grid-template-columns: minmax(0, 1fr);
  gap: 0;
  padding: 0;
}

html[data-mode="draw"].draw-focus .activity-frame {
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

html[data-mode="draw"].draw-focus #drawPanel {
  grid-template-rows: minmax(0, 1fr);
}

html[data-mode="draw"].draw-focus .canvas-wrap { padding: 0; }

html[data-mode="draw"].draw-focus #drawingCanvas {
  border: 0;
  border-radius: 0;
  box-shadow: none;
}
