/* Kanha Scene Studio — one warm, quiet design system.
   Light and dark follow the phone unless the owner picks one. */

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

html, body {
  margin: 0; padding: 0; height: 100%;
  font-family: -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Devanagari", sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
h1, h2, h3, h4, p { margin: 0; }
ul, ol { margin: 0; padding: 0; list-style: none; }
button, input, select, textarea { font: inherit; color: inherit; }
svg { display: block; width: 100%; height: 100%; }

:root {
  --radius-sm: 10px;
  --radius: 16px;
  --radius-lg: 22px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --shadow: 0 6px 24px rgba(30, 22, 14, 0.10);
  --gap: 14px;
}

html[data-theme="light"], html[data-theme="auto"] {
  --bg: #f7f3ec;
  --surface: #fffdf9;
  --surface-2: #efe7d9;
  --ink: #241d16;
  --ink-dim: #6c6053;
  --line: rgba(36, 29, 22, 0.14);
  --accent: #b1691c;
  --accent-ink: #fffaf2;
  --danger: #ad3c2c;
  --good: #2f6b4f;
  --warn: #9a6a12;
  --stage-back: #16120e;
}

html[data-theme="dark"] {
  --bg: #15110d;
  --surface: #211a14;
  --surface-2: #2b231b;
  --ink: #f4ece0;
  --ink-dim: #a99c8b;
  --line: rgba(255, 255, 255, 0.14);
  --accent: #e2a85c;
  --accent-ink: #241d16;
  --danger: #e2705c;
  --good: #7fc7a1;
  --warn: #e0b45f;
  --stage-back: #0c0a08;
}

@media (prefers-color-scheme: dark) {
  html[data-theme="auto"] {
    --bg: #15110d;
    --surface: #211a14;
    --surface-2: #2b231b;
    --ink: #f4ece0;
    --ink-dim: #a99c8b;
    --line: rgba(255, 255, 255, 0.14);
    --accent: #e2a85c;
    --accent-ink: #241d16;
    --danger: #e2705c;
    --good: #7fc7a1;
    --warn: #e0b45f;
    --stage-back: #0c0a08;
  }
}

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

#app { position: fixed; inset: 0; display: flex; flex-direction: column; }

/* ===== Top bar ===== */

.topbar {
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: calc(10px + var(--safe-top)) 16px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark { width: 30px; height: 30px; color: var(--accent); flex-shrink: 0; }
.topbar h1 { font-size: 1.02rem; font-weight: 650; letter-spacing: 0.1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-sub { font-size: 0.72rem; color: var(--ink-dim); }

.icon-btn {
  width: 44px; height: 44px; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  background: none; border: none; border-radius: 50%; color: var(--ink-dim); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn .icon { width: 22px; height: 22px; }

/* ===== Panels and tabs ===== */

#panels { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.panel { padding: 16px 16px calc(26px + var(--safe-bottom)); display: flex; flex-direction: column; gap: var(--gap); }

.tabbar {
  flex-shrink: 0; display: flex;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-bottom);
}
.tab {
  flex: 1; min-height: 56px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  background: none; border: none; color: var(--ink-dim); font-size: 0.7rem; cursor: pointer;
}
.tab .icon { width: 22px; height: 22px; }
.tab.active { color: var(--accent); }

.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.panel-head h2 { font-size: 1.25rem; font-weight: 680; }
.sub { font-size: 0.85rem; color: var(--ink-dim); line-height: 1.45; }
.hint { font-size: 0.78rem; color: var(--ink-dim); line-height: 1.45; }
.tiny { font-size: 0.72rem; color: var(--ink-dim); }
.centre { text-align: center; }
.warn-text { color: var(--warn); }

.empty {
  padding: 28px 18px; text-align: center; color: var(--ink-dim);
  background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius);
  font-size: 0.9rem; line-height: 1.5;
}

/* ===== Buttons ===== */

.btn {
  min-height: 44px; padding: 10px 16px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--ink);
  font-size: 0.9rem; font-weight: 600; cursor: pointer;
}
.btn .icon { width: 18px; height: 18px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.danger-ghost { background: transparent; border-color: var(--line); color: var(--danger); }
.btn.block { width: 100%; }
.btn.small { min-height: 38px; padding: 7px 12px; font-size: 0.82rem; }
.btn.big { min-height: 54px; padding: 14px 32px; font-size: 1rem; }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn:active:not(:disabled) { transform: translateY(1px); }

.row-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.row-actions .btn { flex: 1 1 140px; }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

/* ===== Cards and fields ===== */

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; display: flex; flex-direction: column; gap: 12px;
}
.card h3 { font-size: 0.95rem; font-weight: 650; }
.card.muted { background: transparent; border-style: dashed; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 0.78rem; font-weight: 600; color: var(--ink-dim); display: flex; justify-content: space-between; gap: 8px; }
.field-value { font-weight: 500; color: var(--ink-dim); }

input[type="text"], input[type="number"], select, textarea {
  width: 100%; min-height: 44px; padding: 10px 12px;
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius-sm);
  color: var(--ink); font-size: 0.92rem;
}
textarea {
  min-height: 220px; resize: vertical; line-height: 1.55;
  font-family: "Roboto Mono", "Consolas", ui-monospace, monospace; font-size: 0.88rem;
}
input[type="color"] {
  width: 100%; height: 44px; padding: 4px; background: var(--bg);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
}
input[type="range"] { width: 100%; height: 34px; accent-color: var(--accent); }

.check { display: flex; align-items: flex-start; gap: 10px; font-size: 0.86rem; line-height: 1.4; cursor: pointer; }
.check input { width: 22px; height: 22px; margin: 0; accent-color: var(--accent); flex-shrink: 0; }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }

.inline-field { display: flex; align-items: center; gap: 6px; font-size: 0.8rem; color: var(--ink-dim); }
.inline-field select { min-height: 38px; width: auto; }

/* ===== Chips ===== */

.chip-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.chip-label { font-size: 0.75rem; color: var(--ink-dim); font-weight: 600; }
.chip {
  min-height: 38px; padding: 8px 12px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px;
  color: var(--ink); font-size: 0.82rem; cursor: pointer;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }

/* ===== Scene list ===== */

.scene-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.scene-card {
  display: flex; flex-direction: column; gap: 8px; padding: 8px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  text-align: left; cursor: pointer; color: inherit;
}
.scene-card .thumb {
  display: block; border-radius: var(--radius-sm); overflow: hidden; background: var(--stage-back);
  display: flex; align-items: center; justify-content: center;
}
.scene-card canvas { display: block; width: 100%; height: auto; }
.scene-meta { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.scene-name { font-size: 0.88rem; font-weight: 640; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scene-sub { font-size: 0.72rem; color: var(--ink-dim); }

/* ===== Script list ===== */

.list { display: flex; flex-direction: column; gap: 8px; }
.list-row {
  display: flex; align-items: center; gap: 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 6px 6px 12px;
}
.list-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; padding: 10px 0; background: none; border: none; text-align: left; cursor: pointer; }
.list-title { font-size: 0.94rem; font-weight: 620; }
.list-sub { font-size: 0.78rem; color: var(--ink-dim); }

.banner {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  background: var(--surface-2); border-radius: var(--radius); font-size: 0.8rem; line-height: 1.4;
}
.banner .icon { width: 20px; height: 20px; flex-shrink: 0; color: var(--warn); }

/* ===== Editor ===== */

.editor-head { display: flex; align-items: center; gap: 6px; }
.title-input {
  flex: 1; min-width: 0; min-height: 44px; padding: 8px 10px;
  background: transparent; border: 1px solid transparent; border-radius: var(--radius-sm);
  font-size: 1.02rem; font-weight: 650;
}
.title-input:hover, .title-input:focus { background: var(--surface); border-color: var(--line); }

.stage-host { display: flex; justify-content: center; }
.stage-frame {
  display: flex; align-items: center; justify-content: center;
  background: var(--stage-back); border-radius: var(--radius); overflow: hidden;
  max-width: 100%;
}
.stage-canvas { display: block; max-width: 100%; max-height: 50vh; width: auto; height: auto; touch-action: none; }

.stage-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.inspector { display: flex; flex-direction: column; gap: 12px; }

/* ===== Check results and stats ===== */

.result { border-radius: var(--radius); padding: 12px 14px; font-size: 0.85rem; line-height: 1.5; border: 1px solid var(--line); }
.result h4 { display: flex; align-items: center; gap: 8px; font-size: 0.88rem; margin-bottom: 6px; }
.result .icon { width: 18px; height: 18px; }
.result ul { display: flex; flex-direction: column; gap: 6px; }
.result.good { background: color-mix(in srgb, var(--good) 14%, var(--surface)); color: var(--ink); }
.result.bad { background: color-mix(in srgb, var(--danger) 14%, var(--surface)); }
.result.warn { background: color-mix(in srgb, var(--warn) 16%, var(--surface)); }

.stat-row { display: flex; gap: 16px; flex-wrap: wrap; }
.stat { display: flex; flex-direction: column; font-size: 0.74rem; color: var(--ink-dim); }
.stat b { font-size: 1.05rem; color: var(--ink); font-weight: 650; }

details summary { cursor: pointer; font-size: 0.82rem; color: var(--ink-dim); padding: 4px 0; }
.cue-sheet { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; font-size: 0.8rem; max-height: 230px; overflow-y: auto; }
.cue-sheet li { display: flex; gap: 10px; }
.cue-time { color: var(--ink-dim); min-width: 52px; font-variant-numeric: tabular-nums; }

/* ===== Sheets ===== */

.overlay {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(20, 14, 9, 0.5);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 0;
}
.sheet {
  width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto;
  background: var(--surface); color: var(--ink);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 18px 16px calc(18px + var(--safe-bottom));
  display: flex; flex-direction: column; gap: 12px;
  box-shadow: var(--shadow);
}
.overlay.wide .sheet { max-height: 96vh; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.sheet-title { font-size: 1.05rem; font-weight: 660; }
.sheet-text { font-size: 0.88rem; color: var(--ink-dim); line-height: 1.55; }
.sheet-actions { display: flex; justify-content: space-between; gap: 10px; margin-top: 4px; }
.sheet-actions .btn { flex: 1; }

.menu-list { display: flex; flex-direction: column; gap: 4px; }
.menu-item {
  display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 10px 12px;
  background: none; border: none; border-radius: var(--radius-sm); text-align: left; font-size: 0.92rem; cursor: pointer;
}
.menu-item .icon { width: 20px; height: 20px; color: var(--ink-dim); }
.menu-item:hover { background: var(--surface-2); }
.menu-item.danger { color: var(--danger); }
.menu-item.danger .icon { color: var(--danger); }

.doc { font-size: 0.86rem; line-height: 1.6; display: flex; flex-direction: column; gap: 10px; color: var(--ink); }
.doc h4 { font-size: 0.88rem; font-weight: 650; margin-top: 4px; }
.doc pre {
  margin: 0; padding: 10px 12px; background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius-sm);
  font-family: "Roboto Mono", Consolas, ui-monospace, monospace; font-size: 0.78rem; line-height: 1.6; overflow-x: auto; white-space: pre;
}
.doc code { font-family: "Roboto Mono", Consolas, ui-monospace, monospace; font-size: 0.82rem; }

/* ===== Preview and export ===== */

.preview-host, .export-host { display: flex; justify-content: center; }
.preview-host .stage-canvas { max-height: 54vh; }
.export-host .stage-canvas { max-height: 34vh; }
.preview-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.progress { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.progress .bar { height: 100%; width: 0; background: var(--accent); transition: width 120ms linear; }

.media-list { display: flex; flex-direction: column; gap: 6px; }
.media-row { display: flex; align-items: center; gap: 10px; padding: 6px 4px; border-bottom: 1px solid var(--line); }
.media-row:last-child { border-bottom: none; }
.media-row .icon { width: 20px; height: 20px; color: var(--ink-dim); flex-shrink: 0; }
.media-name { flex: 1; min-width: 0; font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini-list { display: flex; flex-direction: column; gap: 4px; font-size: 0.82rem; }

/* ===== Toast ===== */

.toast {
  position: fixed; left: 50%; bottom: calc(82px + var(--safe-bottom)); transform: translateX(-50%);
  z-index: 200; max-width: 88vw;
  background: var(--ink); color: var(--bg);
  padding: 11px 16px; border-radius: 999px; font-size: 0.85rem; box-shadow: var(--shadow);
}
.toast.warn { background: var(--warn); color: #201804; }
.toast.error { background: var(--danger); color: #fff; }

/* ===== Performance mode ===== */

body.performing #app { visibility: hidden; }

.perform-root { position: fixed; inset: 0; z-index: 300; background: #000; touch-action: none; user-select: none; }
.perform-stage { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }
.perform-stage .stage-frame { width: 100%; height: 100%; border-radius: 0; background: #000; }
.perform-stage.frame .stage-canvas { max-width: 100%; max-height: 100%; width: auto; height: auto; }
.perform-stage.fill .stage-canvas { width: 100%; height: 100%; max-width: none; max-height: none; object-fit: cover; }

.perform-overlay {
  position: absolute; inset: 0; z-index: 10;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px;
  background: rgba(10, 8, 6, 0.82); color: #f6efe4; text-align: center; padding: 32px 26px;
}
.perform-overlay h2 { font-size: 1.2rem; font-weight: 650; }
.perform-overlay p { font-size: 0.9rem; line-height: 1.55; max-width: 420px; color: #d9cfc0; }
.perform-overlay .tiny { color: #a99c8b; }

.perform-countdown {
  position: absolute; inset: 0; z-index: 12;
  display: flex; align-items: center; justify-content: center;
  background: rgba(8, 6, 5, 0.55); color: #fff;
}
.perform-countdown .count { font-size: 5.2rem; font-weight: 750; animation: countPop 1s ease; }
@keyframes countPop { 0% { transform: scale(1.4); opacity: 0; } 25% { transform: scale(1); opacity: 1; } 100% { opacity: 1; } }

.take-bar {
  position: absolute; left: 50%; bottom: calc(26px + var(--safe-bottom)); transform: translateX(-50%);
  z-index: 14; display: flex; align-items: center; gap: 16px;
  background: rgba(18, 14, 10, 0.86); color: #f6efe4;
  padding: 10px 16px; border-radius: 999px; font-size: 0.85rem;
}
.take-bar button { display: flex; align-items: center; gap: 6px; background: none; border: none; color: inherit; font-size: 0.85rem; cursor: pointer; }
.take-bar .icon { width: 17px; height: 17px; }

/* A host's floating badge lives in the bottom-right corner; keep our tabs clear of it. */
body.host-badge .tabbar { padding-bottom: calc(var(--safe-bottom) + 46px); }
body.host-badge .toast { bottom: calc(128px + var(--safe-bottom)); }

[hidden] { display: none !important; }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

@media (min-width: 720px) {
  .panel { max-width: 760px; margin: 0 auto; width: 100%; }
  .overlay { align-items: center; padding: 20px; }
  .sheet { border-radius: var(--radius-lg); }
}
