:root {
  color-scheme: dark;
  --ink: #10161d;
  --ink-2: #17212a;
  --panel: #fbfaf6;
  --paper: #ffffff;
  --text: #15202a;
  --muted: #66727c;
  --line: #dce0df;
  --soft: #eef0ed;
  --accent: #f5c84c;
  --accent-strong: #e7b72e;
  --mint: #80d7bf;
  --radius: 18px;
  --shadow: 0 22px 60px rgba(7, 12, 17, .12);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--ink); }
body { margin: 0; min-width: 320px; min-height: 100vh; font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; color: var(--text); background: #f0f1ed; }
body.modal-open, body.player-open { overflow: hidden; }
.player-page { overflow: hidden; color-scheme: dark; background: #050708; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.app-shell { min-height: 100vh; }
.topbar { height: 78px; padding: 0 clamp(22px, 4vw, 64px); display: flex; align-items: center; justify-content: space-between; gap: 24px; color: #fff; background: var(--ink); }
.brand { display: inline-flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; }
.brand-mark { position: relative; width: 38px; height: 38px; display: grid; place-items: center; border: 1px solid rgba(255,255,255,.2); border-radius: 50%; background: #17212a; }
.brand-mark::before, .brand-mark::after, .brand-mark span { content: ""; display: block; height: 2px; border-radius: 2px; background: var(--accent); }
.brand-mark::before { width: 18px; transform: translateY(-5px); }
.brand-mark span { width: 12px; }
.brand-mark::after { width: 18px; transform: translateY(5px); }
.brand strong { display: block; font-family: Georgia, "Times New Roman", serif; font-size: 21px; letter-spacing: -.02em; }
.brand small { display: block; margin-top: 1px; color: #9ba6ad; font-size: 10px; letter-spacing: .13em; text-transform: uppercase; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.privacy-pill { display: inline-flex; align-items: center; gap: 8px; margin-right: 10px; color: #bcc5ca; font-size: 12px; }
.privacy-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--mint); box-shadow: 0 0 0 4px rgba(128,215,191,.12); }

.button { min-height: 40px; padding: 0 15px; display: inline-flex; align-items: center; justify-content: center; border: 1px solid transparent; border-radius: 10px; font-weight: 700; font-size: 13px; text-decoration: none; cursor: pointer; transition: transform .18s ease, background .18s ease, border-color .18s ease; }
.button:hover { transform: translateY(-1px); }
.button:disabled { cursor: wait; opacity: .65; transform: none; }
.button:focus-visible, .source-button:focus-visible, .segmented button:focus-visible, .player-button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible { outline: 3px solid rgba(245,200,76,.48); outline-offset: 2px; }
.button-quiet { color: #dce1e4; background: transparent; border-color: #33404a; }
.button-quiet:hover { background: #1b2630; }
.button-primary { color: #17202a; background: var(--accent); border-color: var(--accent); box-shadow: 0 10px 24px rgba(231,183,46,.24); }
.button-primary:hover { background: #ffd665; }
.button-secondary { color: var(--text); background: #fff; border-color: #ccd2d2; }
.button-secondary:hover { border-color: #9da7a9; }
.button-large { width: 100%; min-height: 52px; border-radius: 12px; font-size: 14px; }

.workspace { min-height: calc(100vh - 78px); display: grid; grid-template-columns: minmax(0, 1fr) minmax(340px, 430px); }
.editor-panel { min-width: 0; padding: clamp(32px, 4.2vw, 68px) clamp(24px, 5vw, 76px) 56px; background: #f0f1ed; }
.setup-panel { padding: clamp(32px, 4.2vw, 64px) clamp(24px, 3.2vw, 48px) 42px; border-left: 1px solid #d8dcda; background: var(--panel); box-shadow: -16px 0 40px rgba(18,29,37,.04); }
.editor-heading { display: flex; justify-content: space-between; align-items: flex-end; gap: 24px; margin-bottom: 26px; }
.eyebrow { margin: 0 0 9px; color: #718078; font-size: 10px; font-weight: 800; letter-spacing: .18em; text-transform: uppercase; }
h1, h2, p { margin-top: 0; }
h1 { max-width: 680px; margin-bottom: 9px; font-family: Georgia, "Times New Roman", serif; font-size: clamp(36px, 4vw, 58px); font-weight: 500; line-height: .98; letter-spacing: -.045em; }
.editor-heading > div > p:last-child { max-width: 650px; margin: 0; color: var(--muted); font-size: 15px; line-height: 1.55; }
h2 { margin-bottom: 0; font-family: Georgia, "Times New Roman", serif; font-size: 28px; font-weight: 500; letter-spacing: -.03em; }
.connection-chip { display: inline-flex; align-items: center; gap: 9px; flex: 0 0 auto; padding: 10px 13px; border: 1px solid #c8ded6; border-radius: 999px; color: #27594a; background: #eff9f5; font-size: 11px; cursor: pointer; }
.connection-chip:hover { background: #e4f5ef; }
.connection-chip span { width: 8px; height: 8px; border-radius: 50%; background: #46b893; box-shadow: 0 0 0 4px rgba(70,184,147,.15); }

.source-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-bottom: 12px; }
.source-button { min-width: 0; min-height: 64px; padding: 10px 12px; display: flex; align-items: center; gap: 11px; text-align: left; color: var(--text); border: 1px solid #d8dcda; border-radius: 13px; background: rgba(255,255,255,.62); transition: border-color .18s ease, background .18s ease, transform .18s ease; }
.source-button:hover { transform: translateY(-1px); border-color: #adb5b3; background: #fff; }
.source-button.is-active { border-color: #bea23e; background: #fff9dd; }
.source-icon { width: 32px; height: 32px; flex: 0 0 32px; display: grid; place-items: center; border: 1px solid #d6dbd9; border-radius: 9px; color: #354047; background: #fff; font-family: Georgia, serif; font-size: 13px; font-weight: 700; }
.source-button strong, .source-button small { overflow: hidden; display: block; white-space: nowrap; text-overflow: ellipsis; }
.source-button strong { margin-bottom: 2px; font-size: 12px; }
.source-button small { color: #78837e; font-size: 10px; }

.script-card { position: relative; min-height: 490px; display: flex; flex-direction: column; overflow: hidden; border: 1px solid #d5d9d7; border-radius: var(--radius); background: #fff; box-shadow: var(--shadow); }
.script-card.is-dragging { border-color: #c9a930; box-shadow: 0 0 0 4px rgba(245,200,76,.25), var(--shadow); }
.script-title-row { min-height: 58px; display: flex; align-items: center; gap: 18px; padding: 0 20px; border-bottom: 1px solid #ebedeb; }
.script-title { min-width: 0; flex: 1; padding: 8px 0; border: 0; color: #3f4b53; background: transparent; font-size: 12px; font-weight: 750; }
.saved-state { flex: 0 0 auto; color: #84908a; font-size: 10px; }
#scriptEditor { width: 100%; min-height: 380px; flex: 1; resize: vertical; padding: 26px 28px; border: 0; outline: 0; color: #26323a; background: transparent; font-family: Georgia, "Times New Roman", serif; font-size: 18px; line-height: 1.72; }
#scriptEditor::placeholder { color: #a4ada9; }
.script-footer { min-height: 52px; padding: 0 20px; display: flex; align-items: center; justify-content: space-between; gap: 18px; border-top: 1px solid #ebedeb; color: #839089; font-size: 10px; }
.script-footer p { margin: 0; text-align: right; }
.script-stats { display: flex; gap: 18px; }
.script-stats span { white-space: nowrap; }
.script-stats strong { color: #49565d; }

.setup-heading { display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 28px; }
.reset-link, .text-button { padding: 0; border: 0; color: #76827c; background: none; font-size: 11px; font-weight: 700; }
.reset-link:hover, .text-button:hover { color: #27343b; text-decoration: underline; }
.control-group { margin-bottom: 24px; }
.control-group.compact { margin-bottom: 22px; }
.control-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 22px; }
.control-label { min-height: 20px; margin-bottom: 10px; display: flex; align-items: center; justify-content: space-between; color: #435057; font-size: 11px; font-weight: 750; }
.control-label.plain { display: block; min-height: auto; }
.control-label output { padding: 4px 7px; border-radius: 6px; color: #655618; background: #f9edb9; font-size: 10px; }
.range { width: 100%; height: 4px; appearance: none; border-radius: 4px; background: linear-gradient(90deg, var(--accent) 0 34%, #d8dcd9 34% 100%); }
.range::-webkit-slider-thumb { width: 18px; height: 18px; appearance: none; border: 3px solid #fff; border-radius: 50%; background: #25323a; box-shadow: 0 1px 5px rgba(0,0,0,.22); }
.range::-moz-range-thumb { width: 13px; height: 13px; border: 3px solid #fff; border-radius: 50%; background: #25323a; box-shadow: 0 1px 5px rgba(0,0,0,.22); }
.range-labels { margin-top: 8px; display: flex; justify-content: space-between; color: #9aa29e; font-size: 8px; text-transform: uppercase; letter-spacing: .08em; }
.segmented { display: grid; grid-template-columns: repeat(2, 1fr); gap: 4px; padding: 3px; border: 1px solid #d9ddda; border-radius: 10px; background: #ebecea; }
.segmented.three { grid-template-columns: repeat(3, 1fr); }
.segmented button { min-height: 32px; padding: 0 9px; border: 0; border-radius: 7px; color: #6e7974; background: transparent; font-size: 10px; font-weight: 750; }
.segmented button.is-selected { color: #263238; background: #fff; box-shadow: 0 1px 4px rgba(18,29,37,.12); }
.theme-dot { width: 9px; height: 9px; display: inline-block; margin-right: 5px; vertical-align: -1px; border: 1px solid #8b9490; border-radius: 50%; }
.theme-dot.dark { background: #11171c; }
.theme-dot.paper { background: #f5eedc; }
.theme-dot.green { background: #99e6b0; }
.select-control, .text-input { width: 100%; border: 1px solid #d2d7d4; border-radius: 9px; color: #344047; background: #fff; }
.select-control { height: 40px; padding: 0 10px; font-size: 11px; font-weight: 650; }
.toggle-list { margin: 0 0 24px; border-top: 1px solid #e3e5e2; }
.toggle-row { min-height: 57px; display: flex; align-items: center; justify-content: space-between; gap: 15px; border-bottom: 1px solid #e3e5e2; cursor: pointer; }
.toggle-row strong, .toggle-row small { display: block; }
.toggle-row strong { margin-bottom: 3px; color: #445159; font-size: 11px; }
.toggle-row small { color: #929b97; font-size: 9px; }
.toggle-row input { position: absolute; opacity: 0; }
.toggle { position: relative; width: 36px; height: 21px; flex: 0 0 auto; border-radius: 999px; background: #c8ceca; transition: background .18s ease; }
.toggle::after { content: ""; position: absolute; top: 3px; left: 3px; width: 15px; height: 15px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.2); transition: transform .18s ease; }
.toggle-row input:checked + .toggle { background: #26343c; }
.toggle-row input:checked + .toggle::after { transform: translateX(15px); background: var(--accent); }
.toggle-row input:focus-visible + .toggle { outline: 3px solid rgba(245,200,76,.5); outline-offset: 2px; }
.launch-card { padding-top: 3px; }
.launch-card .button + .button { margin-top: 9px; }
.launch-card p { margin: 11px 0 0; color: #929b96; text-align: center; font-size: 9px; }
.play-symbol { width: 0; height: 0; display: inline-block; margin-right: 8px; border-top: 6px solid transparent; border-bottom: 6px solid transparent; border-left: 9px solid currentColor; vertical-align: -2px; }
.pause-symbol { width: 11px; height: 13px; display: inline-block; margin-right: 8px; border-left: 4px solid currentColor; border-right: 4px solid currentColor; vertical-align: -2px; }
.device-symbol { position: relative; width: 15px; height: 11px; display: inline-block; margin-right: 8px; border: 1.5px solid currentColor; border-radius: 2px; vertical-align: -1px; }
.device-symbol::after { content: ""; position: absolute; left: 3px; right: 3px; bottom: -4px; height: 1.5px; background: currentColor; }

.modal-backdrop { position: fixed; z-index: 50; inset: 0; display: grid; place-items: center; padding: 22px; background: rgba(8,13,17,.76); backdrop-filter: blur(10px); }
.modal { position: relative; width: min(100%, 440px); padding: 34px; border-radius: 20px; color: var(--text); background: #fbfaf6; box-shadow: 0 34px 90px rgba(0,0,0,.36); }
.modal h2 { margin-bottom: 10px; font-size: 32px; }
.modal > p:not(.eyebrow):not(.field-note) { margin-bottom: 23px; color: #68747b; font-size: 13px; line-height: 1.55; }
.modal-close { position: absolute; top: 12px; right: 14px; width: 34px; height: 34px; border: 0; border-radius: 50%; color: #5f6b71; background: transparent; font-size: 26px; }
.modal-close:hover { background: #e9ebe7; }
.modal-icon { width: 42px; height: 42px; margin-bottom: 20px; display: grid; place-items: center; border-radius: 12px; color: #fff; background: #4285f4; font-family: Georgia, serif; font-weight: 700; }
.modal label { display: block; margin-bottom: 7px; color: #3f4c52; font-size: 11px; font-weight: 800; }
.text-input { height: 47px; padding: 0 13px; }
.field-note { min-height: 34px; margin: 8px 0 16px; color: #8b9691; font-size: 9px; line-height: 1.45; }
.field-note.is-error { color: #a14d43; }
.pair-modal { text-align: center; }
.pair-modal .eyebrow { margin-top: 4px; }
.qr-frame { width: 226px; height: 226px; margin: 24px auto 18px; padding: 12px; display: grid; place-items: center; border: 1px solid #d5d9d6; border-radius: 17px; background: #fff; box-shadow: inset 0 0 0 6px #f4f4ef; }
#qrCode canvas, #qrCode img { display: block; max-width: 100%; height: auto !important; }
.pair-status { margin: 0 0 16px; display: flex; align-items: center; justify-content: center; gap: 11px; text-align: left; }
.pair-status strong, .pair-status small { display: block; }
.pair-status strong { margin-bottom: 2px; font-size: 11px; }
.pair-status small { color: #8a9590; font-size: 9px; }
.status-spinner { width: 16px; height: 16px; flex: 0 0 auto; border: 2px solid #d2d6d3; border-top-color: #425059; border-radius: 50%; animation: spin .9s linear infinite; }
.pair-status.is-connected .status-spinner { border: 0; background: #57bf9c; box-shadow: 0 0 0 4px rgba(87,191,156,.15); animation: none; }
.pair-modal .button + .button { margin-top: 9px; }
.text-button.danger { margin-top: 15px; color: #a55e55; }
@keyframes spin { to { transform: rotate(360deg); } }

.toast { position: fixed; z-index: 80; left: 50%; bottom: 24px; transform: translateX(-50%); max-width: calc(100vw - 32px); padding: 11px 16px; border: 1px solid rgba(255,255,255,.14); border-radius: 999px; color: #fff; background: #172129; box-shadow: 0 12px 34px rgba(0,0,0,.25); font-size: 12px; font-weight: 650; }

.player { position: fixed; z-index: 100; inset: 0; overflow: hidden; color: #fff; background: #050708; --prompt-bg: #050708; --prompt-text: #f7f5ed; }
.player.theme-paper { --prompt-bg: #f0eadc; --prompt-text: #161c20; }
.player.theme-green { --prompt-bg: #08120d; --prompt-text: #aef7c0; }
.prompt-scroll { position: absolute; inset: 0; overflow-x: hidden; overflow-y: auto; scrollbar-width: none; overscroll-behavior: contain; background: var(--prompt-bg); }
.prompt-scroll::-webkit-scrollbar { display: none; }
.prompt-content { width: min(86vw, 1200px); margin: 0 auto; padding: 36vh 0 62vh; color: var(--prompt-text); font-family: Arial, Helvetica, sans-serif; font-size: clamp(34px, 5vw, 64px); font-weight: 650; line-height: 1.45; letter-spacing: -.025em; text-align: center; white-space: pre-wrap; transform-origin: center center; }
.reading-guide { position: absolute; z-index: 2; top: 34vh; left: 0; right: 0; height: 1.7em; pointer-events: none; border-top: 1px solid rgba(245,200,76,.25); border-bottom: 1px solid rgba(245,200,76,.25); background: rgba(245,200,76,.045); }
.reading-guide::before, .reading-guide::after { content: ""; position: absolute; top: 50%; width: 16px; height: 2px; background: var(--accent); }
.reading-guide::before { left: 13px; }
.reading-guide::after { right: 13px; }
.player-topbar { position: absolute; z-index: 5; top: 0; left: 0; right: 0; min-height: 74px; padding: max(14px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) 12px max(18px, env(safe-area-inset-left)); display: flex; align-items: center; justify-content: space-between; background: linear-gradient(rgba(0,0,0,.7), transparent); transition: opacity .3s ease; }
.player-status { color: rgba(255,255,255,.7); font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.player-controls { position: absolute; z-index: 6; left: 50%; bottom: max(22px, env(safe-area-inset-bottom)); transform: translateX(-50%); min-width: min(92vw, 560px); padding: 10px; display: flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid rgba(255,255,255,.16); border-radius: 18px; background: rgba(15,20,23,.82); box-shadow: 0 16px 50px rgba(0,0,0,.42); backdrop-filter: blur(16px); transition: opacity .3s ease, transform .3s ease; }
.player.is-controls-hidden .player-controls { opacity: 0; transform: translate(-50%, 18px); pointer-events: none; }
.player.is-controls-hidden .player-topbar { opacity: 0; pointer-events: none; }
.player-button { min-width: 43px; height: 43px; padding: 0 9px; border: 1px solid rgba(255,255,255,.14); border-radius: 12px; color: #fff; background: rgba(255,255,255,.08); font-size: 11px; font-weight: 800; }
.player-button:hover { background: rgba(255,255,255,.15); }
.player-button.text { min-width: 56px; border-color: transparent; background: transparent; }
.player-button.play { width: 52px; height: 52px; border-color: var(--accent); border-radius: 50%; color: #151c20; background: var(--accent); }
.player-button.play .play-symbol { margin-right: -2px; }
.player-button.play.is-playing .play-symbol { width: 12px; height: 15px; margin: 0; border: 0; border-left: 4px solid currentColor; border-right: 4px solid currentColor; }
.player-button.small { min-width: 34px; height: 34px; }
.player-speed { min-width: 132px; display: flex; align-items: center; justify-content: center; gap: 8px; }
.player-speed span { min-width: 42px; color: #fff; text-align: center; line-height: 1; }
.player-speed strong, .player-speed small { display: block; }
.player-speed strong { font-size: 13px; }
.player-speed small { margin-top: 3px; color: #9ba4a8; font-size: 7px; letter-spacing: .1em; text-transform: uppercase; }
.countdown { position: absolute; z-index: 8; inset: 0; display: grid; place-items: center; color: var(--accent); background: rgba(3,5,6,.86); font-family: Georgia, serif; font-size: min(34vw, 260px); }
.player-settings-popover { position: absolute; z-index: 9; top: 70px; right: 18px; width: min(300px, calc(100vw - 36px)); padding: 18px; border: 1px solid rgba(255,255,255,.15); border-radius: 14px; color: #fff; background: rgba(18,24,28,.94); box-shadow: 0 18px 50px rgba(0,0,0,.4); }
.player-settings-popover label { margin-bottom: 12px; display: flex; justify-content: space-between; font-size: 11px; font-weight: 700; }
.player-settings-popover .range { margin-bottom: 20px; }
.player-settings-popover .button { color: #fff; background: #283239; border-color: #465159; }
.player-settings-popover .button.is-active { color: #1b2429; background: var(--accent); border-color: var(--accent); }

.session-handoff { position: fixed; z-index: 120; inset: 0; padding: 24px; display: grid; place-items: center; color: #f7f5ed; background: radial-gradient(circle at 50% 35%, #26343c 0, #11181e 42%, #070a0c 100%); opacity: 0; transition: opacity .35s ease; }
.session-handoff.is-visible { opacity: 1; }
.session-handoff-card { width: min(100%, 520px); padding: clamp(32px, 7vw, 58px); text-align: center; border: 1px solid rgba(255,255,255,.13); border-radius: 24px; background: rgba(12,17,21,.72); box-shadow: 0 30px 90px rgba(0,0,0,.38); backdrop-filter: blur(18px); }
.session-handoff .eyebrow { color: #aab5b9; }
.session-handoff h1 { margin: 0 auto 14px; color: #fff; font-size: clamp(36px, 7vw, 58px); line-height: 1.02; }
.session-handoff-card > p:not(.eyebrow) { margin-bottom: 28px; color: #b9c2c6; font-size: 14px; line-height: 1.6; }
.session-handoff .button { min-width: 150px; }
.handoff-mark { position: relative; width: 52px; height: 52px; margin: 0 auto 24px; display: grid; place-items: center; border: 1px solid rgba(255,255,255,.2); border-radius: 50%; background: #17212a; }
.handoff-mark::before, .handoff-mark::after, .handoff-mark span { content: ""; display: block; height: 2px; border-radius: 2px; background: var(--accent); }
.handoff-mark::before { width: 24px; transform: translateY(-7px); }
.handoff-mark span { width: 16px; }
.handoff-mark::after { width: 24px; transform: translateY(7px); }

@media (max-width: 980px) {
  .workspace { grid-template-columns: 1fr; }
  .setup-panel { border-top: 1px solid #d8dcda; border-left: 0; }
  .privacy-pill { display: none; }
}

@media (max-width: 640px) {
  .topbar { height: 66px; padding: 0 15px; }
  .topbar-actions .button:first-of-type { display: none; }
  .topbar-actions .button { min-height: 36px; padding: 0 10px; font-size: 11px; }
  .editor-panel, .setup-panel { padding: 28px 16px 36px; }
  h1 { font-size: 40px; }
  .editor-heading { display: block; }
  .source-row { grid-template-columns: 1fr 1fr; }
  .source-button:first-child { grid-column: 1 / -1; }
  .script-card { min-height: 440px; }
  #scriptEditor { min-height: 330px; padding: 22px 20px; font-size: 17px; }
  .script-footer { align-items: flex-start; padding: 13px 16px; }
  .script-footer p { display: none; }
  .script-stats { flex-wrap: wrap; gap: 8px 15px; }
  .control-grid { gap: 13px; }
  .modal { padding: 30px 22px 24px; }
  .prompt-content { width: 88vw; }
  .player-controls { min-width: calc(100vw - 20px); gap: 4px; padding: 7px; }
  .player-speed { min-width: 108px; gap: 4px; }
  .player-button { min-width: 38px; height: 40px; }
  .player-button.play { width: 48px; height: 48px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
