/* ── Reset & Tokens ──────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Palette — deep theater blacks */
  --bg:          #09090F;
  --surface:     #0F0F1A;
  --surface2:    #161622;
  --surface3:    #1E1E2E;
  --border:      rgba(255,255,255,0.07);
  --border2:     rgba(255,255,255,0.13);

  /* Accent */
  --amber:       #F59E0B;
  --amber-hi:    #FCD34D;
  --amber-dim:   rgba(245,158,11,0.11);
  --amber-glow:  rgba(245,158,11,0.18);

  /* Text hierarchy */
  --text-hi:     #F8FAFC;
  --text:        #CBD5E1;
  --text-lo:     #94A3B8;
  --muted:       #8899AA; /* raised from 0.55 opacity for WCAG AA contrast ~5.8:1 */

  --white:       #ffffff;

  /* Character colors */
  --cc0: #F87171; --cc1: #38BDF8; --cc2: #86EFAC; --cc3: #FDE047;
  --cc4: #C084FC; --cc5: #22D3EE; --cc6: #FB923C; --cc7: #4ADE80;
  --cc8: #F472B6; --cc9: #67E8F9; --cc10:#D9F99D; --cc11:#FCA5A1;

  /* Typography */
  --font-ui:     'Noto Sans KR', 'Apple SD Gothic Neo', -apple-system, sans-serif;
  --font-script: 'Gowun Batang', 'Nanum Myeongjo', 'Georgia', serif;

  /* Motion */
  --ease:       cubic-bezier(0.16, 1, 0.3, 1);
  --ease-back:  cubic-bezier(0.34, 1.56, 0.64, 1);

  /* Font size scale factor (JS-controlled) */
  --sf: 1;

  /* Radii */
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 18px;
  --r-xl: 24px;
}

html { scroll-behavior: smooth; }
body {
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* ── Screen System ───────────────────────────────────────── */
.screen { display: none; min-height: 100dvh; flex-direction: column; }
.screen.active { display: flex; }
.screen.slide-in { animation: slideIn 0.35s var(--ease) both; }
@keyframes slideIn {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ── Shared UI ───────────────────────────────────────────── */
.text-input {
  width: 100%;
  background: var(--surface2);
  border: 1.5px solid var(--border);
  border-radius: var(--r-md);
  padding: 13px 16px;
  color: var(--text-hi);
  font-family: var(--font-ui);
  font-size: 0.95rem;
  font-weight: 500;
  transition: border-color 0.2s, box-shadow 0.2s;
  letter-spacing: -0.01em;
}
.text-input::placeholder { color: var(--muted); font-weight: 400; }
.text-input:focus {
  outline: none;
  border-color: var(--amber);
  box-shadow: 0 0 0 3px var(--amber-dim);
}

.btn-primary {
  background: linear-gradient(135deg, var(--amber) 0%, #E08B00 100%);
  color: #0C0A00;
  border: none;
  border-radius: var(--r-md);
  padding: 13px 26px;
  font-family: var(--font-ui);
  font-size: 0.93rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  cursor: pointer;
  transition: transform 0.15s var(--ease), opacity 0.15s, box-shadow 0.2s;
  box-shadow: 0 2px 12px rgba(245,158,11,0.3);
}
.btn-primary:hover  { opacity: 0.92; box-shadow: 0 4px 20px rgba(245,158,11,0.4); }
.btn-primary:active { transform: scale(0.97); }
.btn-primary:disabled { opacity: 0.3; cursor: not-allowed; transform: none; box-shadow: none; }

.btn-secondary {
  background: transparent;
  color: var(--amber);
  border: 1.5px solid rgba(245,158,11,0.5);
  border-radius: var(--r-md);
  padding: 12px 20px;
  font-family: var(--font-ui);
  font-size: 0.93rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.btn-secondary:hover { background: var(--amber-dim); border-color: var(--amber); }

.btn-lg { width: 100%; padding: 16px; font-size: 1rem; border-radius: var(--r-lg); }

.btn-ghost-xs {
  background: var(--amber-dim);
  color: var(--amber);
  border: none;
  border-radius: var(--r-sm);
  padding: 5px 10px;
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-ghost-xs:hover { background: var(--amber-glow); }

.btn-ghost-sm {
  background: transparent;
  color: var(--text-lo);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 7px 14px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.btn-ghost-sm:hover { color: var(--text); border-color: var(--border2); }

.btn-amber-sm {
  background: var(--amber);
  color: #0C0A00;
  border: none;
  border-radius: var(--r-sm);
  padding: 7px 14px;
  font-size: 0.82rem;
  font-weight: 800;
  cursor: pointer;
  transition: opacity 0.15s;
}
.btn-amber-sm:hover { opacity: 0.88; }

.hidden { display: none !important; }

/* ── Top Bar ─────────────────────────────────────────────── */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: rgba(9,9,15,0.96);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  gap: 12px;
  flex-shrink: 0;
}
.top-bar h2 {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-hi);
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.back-btn {
  background: none;
  border: none;
  color: var(--text-lo);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: var(--r-sm);
  white-space: nowrap;
  transition: color 0.15s, background 0.15s;
}
.back-btn:hover { color: var(--text-hi); background: rgba(255,255,255,0.05); }

.room-code-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 6px 10px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  font-family: inherit;
}
.room-code-btn:hover {
  border-color: var(--amber);
  background: rgba(251,191,36,0.08);
}
.room-code-btn:active {
  background: rgba(251,191,36,0.16);
}
.room-code-label {
  font-size: 0.62rem;
  color: var(--muted);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  white-space: nowrap;
}
.room-code-value {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--amber);
  letter-spacing: 0.02em;
  font-family: 'SF Mono', 'Fira Code', monospace;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.room-code-copy-hint {
  font-size: 0.6rem;
  color: var(--muted);
  background: var(--surface3);
  border-radius: 3px;
  padding: 1px 5px;
  white-space: nowrap;
}
.room-code-btn:hover .room-code-copy-hint {
  color: var(--amber);
}
.room-code-btn.copied .room-code-copy-hint {
  color: #4ade80;
}

/* ── HOME SCREEN ─────────────────────────────────────────── */
#screen-home {
  position: relative;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
}

.home-bg {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 0;
}
.spotlight {
  position: absolute;
  border-radius: 50%;
  filter: blur(100px);
  animation: breathe 8s ease-in-out infinite alternate;
}
.sp1 {
  width: 600px; height: 600px;
  background: radial-gradient(circle, rgba(245,158,11,0.09), transparent 70%);
  top: -15%; left: -10%;
  animation-delay: 0s;
}
.sp2 {
  width: 500px; height: 500px;
  background: radial-gradient(circle, rgba(168,85,247,0.07), transparent 70%);
  bottom: -5%; right: -8%;
  animation-delay: -3s;
}
.sp3 {
  width: 350px; height: 350px;
  background: radial-gradient(circle, rgba(56,189,248,0.05), transparent 70%);
  top: 45%; left: 55%;
  animation-delay: -5s;
}
@keyframes breathe {
  from { transform: scale(1) translate(0, 0); }
  to   { transform: scale(1.15) translate(10px, -10px); }
}

.home-content {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 52px;
  padding: 48px 20px;
  width: 100%;
  max-width: 780px;
  margin: 0 auto;
}

.home-logo { text-align: center; }
.logo-icon {
  font-size: 4rem;
  display: block;
  margin-bottom: 16px;
  filter: drop-shadow(0 0 24px rgba(245,158,11,0.4));
}
.logo-title {
  font-size: clamp(2.8rem, 7vw, 5rem);
  font-weight: 900;
  letter-spacing: -0.04em;
  background: linear-gradient(140deg, var(--amber-hi) 0%, var(--amber) 50%, #E08B00 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1;
  margin-bottom: 10px;
}
.logo-sub {
  color: var(--text-lo);
  font-size: 0.92rem;
  font-weight: 500;
  letter-spacing: 0.02em;
}

.home-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(290px, 1fr));
  gap: 18px;
  width: 100%;
}

.home-card {
  background: linear-gradient(160deg, var(--surface) 0%, rgba(22,22,34,0.95) 100%);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: 30px 26px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: relative;
  overflow: hidden;
  transition: border-color 0.25s, transform 0.25s var(--ease), box-shadow 0.25s;
}
.home-card::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: radial-gradient(ellipse at 80% 20%, rgba(245,158,11,0.04), transparent 60%);
  pointer-events: none;
}
.home-card:hover {
  border-color: rgba(245,158,11,0.28);
  transform: translateY(-4px);
  box-shadow: 0 16px 40px rgba(0,0,0,0.4), 0 0 0 1px rgba(245,158,11,0.08);
}

.card-badge {
  position: absolute;
  top: 18px; right: 18px;
  font-size: 0.62rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  color: var(--amber);
  background: var(--amber-dim);
  border: 1px solid rgba(245,158,11,0.2);
  padding: 3px 9px;
  border-radius: 99px;
}
.card-icon { font-size: 2rem; }
.home-card h2 {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--text-hi);
  letter-spacing: -0.02em;
}
.home-card p {
  font-size: 0.85rem;
  color: var(--text-lo);
  line-height: 1.65;
  font-weight: 400;
}

.join-row { display: flex; gap: 8px; margin-top: 4px; }
.join-row input { flex: 1; min-width: 0; }

/* ── SETUP SCREEN ────────────────────────────────────────── */
.setup-body {
  flex: 1;
  padding: 28px 20px 48px;
  max-width: 640px;
  margin: 0 auto;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 30px;
}

.setup-step { display: flex; flex-direction: column; gap: 10px; }
.step-label {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-lo);
  display: flex;
  align-items: center;
  gap: 8px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.step-num {
  width: 22px; height: 22px;
  background: var(--amber-dim);
  color: var(--amber);
  border-radius: 50%;
  font-size: 0.68rem;
  font-weight: 900;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  border: 1px solid rgba(245,158,11,0.2);
}

.drop-zone {
  border: 2px dashed rgba(245,158,11,0.25);
  border-radius: var(--r-lg);
  padding: 40px 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, transform 0.2s var(--ease);
  background: rgba(245,158,11,0.025);
}
.drop-zone:hover, .drop-zone.drag-over {
  border-color: var(--amber);
  background: var(--amber-dim);
  transform: scale(1.01);
}
.dz-icon { font-size: 2.5rem; margin-bottom: 10px; }
.dz-text { font-weight: 700; color: var(--text); margin-bottom: 5px; font-size: 0.95rem; }
.dz-hint { font-size: 0.8rem; color: var(--muted); }

.file-info {
  background: rgba(134,239,172,0.08);
  border: 1px solid rgba(134,239,172,0.22);
  border-radius: var(--r-md);
  padding: 11px 15px;
  font-size: 0.85rem;
  font-weight: 600;
  color: #86EFAC;
  letter-spacing: -0.01em;
}

.char-preview-list { display: flex; flex-wrap: wrap; gap: 8px; }

.char-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 13px;
  border-radius: 99px;
  font-size: 0.82rem;
  font-weight: 700;
  border: 1.5px solid;
  background: transparent;
  letter-spacing: -0.01em;
}

.hint { font-size: 0.8rem; color: var(--muted); }

/* Password field */
.pw-wrap {
  display: flex;
  gap: 8px;
  align-items: center;
}
.pw-wrap .text-input { flex: 1; min-width: 0; }
.pw-toggle { flex-shrink: 0; white-space: nowrap; }
.step-optional {
  color: var(--muted);
  font-weight: 400;
  text-transform: none;
  font-size: 0.72rem;
  letter-spacing: 0;
}

/* ── JOIN SCREEN ─────────────────────────────────────────── */
.join-body {
  flex: 1;
  padding: 28px 20px 48px;
  max-width: 640px;
  margin: 0 auto;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 28px;
}
.join-state { display: flex; flex-direction: column; gap: 24px; }
.join-state.hidden { display: none; }

.spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--amber);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 40px auto 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

.char-select-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
}
.char-select-card {
  background: var(--surface2);
  border: 2px solid var(--border);
  border-radius: var(--r-md);
  padding: 16px 12px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s var(--ease), transform 0.15s var(--ease), background 0.15s, box-shadow 0.15s;
}
.char-select-card:hover {
  border-color: rgba(245,158,11,0.4);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0,0,0,0.3);
}
.char-select-card.selected {
  border-color: var(--amber);
  background: var(--amber-dim);
  box-shadow: 0 0 0 1px rgba(245,158,11,0.15);
}
.char-select-card.taken { opacity: 0.35; cursor: not-allowed; pointer-events: none; }

.char-card-dot {
  width: 14px; height: 14px;
  border-radius: 50%;
  margin: 0 auto 10px;
  transition: box-shadow 0.15s;
}
.char-select-card:hover .char-card-dot { transform: scale(1.2); }
.char-card-name {
  font-weight: 800;
  font-size: 0.88rem;
  /* color set inline by JS */
  letter-spacing: -0.01em;
}
.char-select-card {
  border-top-width: 3px !important; /* color set inline by JS */
}
.char-card-taken { font-size: 0.7rem; color: var(--muted); margin-top: 4px; }

/* ── READER SCREEN ───────────────────────────────────────── */
#screen-reader {
  height: 100dvh;
  overflow: hidden;
}

.reader-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: rgba(9,9,15,0.98);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 30;
  gap: 12px;
}
.reader-bar-left, .reader-bar-right { flex: 1; }
.reader-bar-right { display: flex; justify-content: flex-end; gap: 6px; }
.reader-bar-center { text-align: center; }

.reader-title {
  font-weight: 700;
  font-size: 0.88rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: -0.02em;
}
.reader-counter {
  font-size: 0.78rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}

.icon-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--text-lo);
  padding: 7px 11px;
  font-size: 0.82rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  white-space: nowrap;
  font-family: var(--font-ui);
}
.icon-btn:hover { background: var(--surface3); color: var(--text-hi); border-color: var(--border2); }

/* Font size button levels */
.font-size-btn { font-weight: 900; min-width: 34px; font-family: var(--font-ui); }
.font-size-btn[data-level="1"] { font-size: 0.78rem; color: var(--text-lo); }
.font-size-btn[data-level="2"] { font-size: 0.9rem; color: var(--amber); border-color: rgba(245,158,11,0.3); }
.font-size-btn[data-level="3"] { font-size: 1rem; color: var(--amber); border-color: var(--amber); background: var(--amber-dim); }

.reader-layout {
  display: flex;
  flex: 1 1 0;
  min-height: 0;
  position: relative;
  overflow: hidden;
}

/* Script area */
.script-wrap {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  scroll-behavior: smooth;
  padding: 48px 24px 140px;
}
.script-wrap::-webkit-scrollbar { width: 4px; }
.script-wrap::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.08);
  border-radius: 2px;
}
.script-wrap::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.15); }

.script-container {
  max-width: 660px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 0;
}

/* ── Script Lines ────────────────────────────────────────── */
.script-line {
  padding: 5px 16px 5px 20px;
  border-radius: var(--r-sm);
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background 0.12s;
  position: relative;
}
.script-line:hover { background: rgba(255,255,255,0.025); }

.script-line.current-line {
  background: rgba(245,158,11,0.09) !important;
  border-left-color: var(--amber) !important;
  box-shadow: inset 0 0 0 1px rgba(245,158,11,0.08);
}
.script-line.current-line .dl-text {
  color: #FDE68A !important;
}

.script-line.has-note::after {
  content: '📎';
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.68rem;
  opacity: 0.6;
}

/* Scene heading */
.line-scene { margin-top: 28px; margin-bottom: 4px; }
.line-scene .scene-text {
  font-size: calc(0.68rem * var(--sf));
  font-family: var(--font-ui);
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(245,158,11,0.55);
  padding: 4px 0;
  display: flex;
  align-items: center;
  gap: 12px;
}
.line-scene .scene-text::after {
  content: '';
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, rgba(245,158,11,0.2), transparent);
}

/* Empty line */
.line-empty { height: 10px; }

/* Character name line (screenplay format) */
.line-character { padding-top: 20px; padding-bottom: 2px; }
.char-name-block {
  font-family: var(--font-ui);
  font-size: calc(0.78rem * var(--sf));
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-lo);
}

/* Dialogue line */
.line-dialogue { padding-left: 20px; padding-top: 6px; padding-bottom: 8px; border-left-width: 3px; }
.dl-char {
  font-family: var(--font-ui);
  font-size: calc(0.65rem * var(--sf));
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-bottom: 6px;
  display: inline-block;
  padding: 2px 10px 2px 7px;
  border-radius: 4px 12px 12px 4px;
  /* color, background, border-left, box-shadow set inline by JS */
}
.dl-text {
  font-family: var(--font-script);
  font-size: calc(1.08rem * var(--sf));
  line-height: 1.95;
  color: var(--text-hi);
  display: block;
  word-break: keep-all;
  overflow-wrap: break-word;
}

/* Action / Stage direction */
.line-action { padding: 4px 20px; }
.line-action .action-text {
  font-family: var(--font-ui);
  font-size: calc(0.86rem * var(--sf));
  color: var(--text-lo);
  font-style: italic;
  line-height: 1.65;
  font-weight: 400;
}

/* My character highlight */
.my-char { border-left-width: 4px !important; }
.my-char .dl-char { opacity: 1; }
.my-char .dl-text {
  font-weight: 700;
  letter-spacing: 0.005em;
}

/* Current dialogue line — amber spotlight + glow */
.script-line.current-line .dl-text { color: #FDE68A !important; }
.script-line.current-line .dl-char { opacity: 1; }

/* ── Side Panels ─────────────────────────────────────────── */
.side-panel {
  width: 300px;
  flex-shrink: 0;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: panelSlide 0.22s var(--ease) both;
}
.side-panel[hidden] { display: none; }
@keyframes panelSlide {
  from { opacity: 0; transform: translateX(16px); }
  to   { opacity: 1; transform: translateX(0); }
}

.panel-hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 15px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.panel-hd h3 {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text-hi);
  letter-spacing: -0.02em;
}

.panel-close {
  background: none; border: none;
  color: var(--muted); font-size: 1.05rem;
  cursor: pointer; padding: 4px 8px; border-radius: var(--r-sm);
  transition: color 0.15s, background 0.15s;
}
.panel-close:hover { color: var(--text-hi); background: rgba(255,255,255,0.05); }

.panel-empty {
  font-size: 0.82rem;
  color: var(--muted);
  text-align: center;
  padding: 28px 16px;
  line-height: 1.6;
}

/* Notes list */
.notes-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.note-card {
  background: var(--surface2);
  border-radius: var(--r-md);
  padding: 10px 12px;
  border-left: 3px solid;
}
.note-card-meta {
  font-size: 0.7rem;
  color: var(--muted);
  margin-bottom: 5px;
  font-weight: 500;
}
.note-card-text {
  font-size: 0.84rem;
  line-height: 1.6;
  word-break: break-word;
  color: var(--text);
}

.note-compose {
  border-top: 1px solid var(--border);
  padding: 12px;
  flex-shrink: 0;
}
.note-line-ref {
  font-size: 0.75rem;
  color: var(--muted);
  background: var(--surface2);
  border-radius: var(--r-sm);
  padding: 6px 10px;
  margin-bottom: 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-style: italic;
}
.note-compose textarea {
  width: 100%;
  background: var(--surface2);
  border: 1.5px solid var(--border);
  border-radius: var(--r-sm);
  padding: 10px 12px;
  color: var(--text-hi);
  font-family: var(--font-ui);
  font-size: 0.85rem;
  line-height: 1.6;
  resize: vertical;
  min-height: 80px;
  transition: border-color 0.2s;
}
.note-compose textarea:focus { outline: none; border-color: var(--amber); }
.note-compose-actions { display: flex; gap: 8px; margin-top: 8px; justify-content: flex-end; }

/* Participants list */
.participants-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.participant-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface2);
  border-radius: var(--r-md);
  border-left: 3px solid;
  transition: background 0.15s;
}
.participant-row:hover { background: var(--surface3); }
.p-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.p-info { flex: 1; min-width: 0; }
.p-name {
  font-weight: 700;
  font-size: 0.88rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-hi);
  letter-spacing: -0.01em;
}
.p-char { font-size: 0.73rem; color: var(--muted); margin-top: 1px; }
.p-host-badge {
  font-size: 0.62rem;
  font-weight: 900;
  letter-spacing: 0.06em;
  color: var(--amber);
  background: var(--amber-dim);
  border: 1px solid rgba(245,158,11,0.18);
  padding: 2px 7px;
  border-radius: 99px;
  white-space: nowrap;
}

.invite-section {
  padding: 14px 15px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.invite-label {
  font-size: 0.7rem;
  color: var(--muted);
  font-weight: 700;
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.invite-row { display: flex; align-items: center; gap: 8px; }
.invite-code {
  flex: 1; min-width: 0;
  font-size: 0.7rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 7px 10px;
  color: var(--amber);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
  font-family: 'SF Mono', 'Fira Code', monospace;
}

/* ── Host Controls ───────────────────────────────────────── */
.host-ctrl {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 12px 20px;
  background: rgba(9,9,15,0.97);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border);
  z-index: 40;
}
.host-ctrl.hidden { display: none; }

.ctrl-arrow {
  width: 50px; height: 50px;
  background: var(--surface2);
  border: 1.5px solid var(--border2);
  border-radius: var(--r-md);
  color: var(--text);
  font-size: 1.1rem;
  cursor: pointer;
  transition: background 0.15s var(--ease), border-color 0.15s, transform 0.1s, color 0.15s;
}
.ctrl-arrow:hover {
  background: rgba(245,158,11,0.1);
  border-color: var(--amber);
  color: var(--amber);
}
.ctrl-arrow:active { transform: scale(0.9); }

.ctrl-meta {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 130px;
}
.ctrl-char-name {
  font-size: 0.82rem;
  font-weight: 800;
  color: var(--text-hi);
  max-width: 170px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: -0.01em;
}
.ctrl-pos {
  font-size: 0.72rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}

/* ── Toast ───────────────────────────────────────────────── */
.toast-root {
  position: fixed;
  bottom: 88px; right: 20px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 9999;
  pointer-events: none;
}
.toast {
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: var(--r-md);
  padding: 10px 16px;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text);
  animation: toastIn 0.28s var(--ease) both;
  pointer-events: auto;
  max-width: 280px;
  backdrop-filter: blur(12px);
  letter-spacing: -0.01em;
}
.toast.success { border-color: rgba(134,239,172,0.35); color: #86EFAC; }
.toast.error   { border-color: rgba(248,113,113,0.35); color: #F87171; }
@keyframes toastIn {
  from { opacity: 0; transform: translateY(8px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ── Onboarding Tour ─────────────────────────────────────── */
#tour-overlay {
  position: fixed; inset: 0;
  z-index: 8999;
  pointer-events: all;
  background: transparent;
}
#tour-spotlight {
  position: fixed;
  border-radius: var(--r-md);
  box-shadow: 0 0 0 4000px rgba(0,0,0,0.82);
  outline: 2px solid var(--amber);
  outline-offset: 0;
  pointer-events: none;
  z-index: 9000;
  transition: left 0.25s var(--ease), top 0.25s var(--ease),
              width 0.25s var(--ease), height 0.25s var(--ease);
}
#tour-tooltip {
  position: fixed;
  width: 280px;
  background: var(--surface2);
  border: 1px solid rgba(245,158,11,0.4);
  border-radius: var(--r-lg);
  padding: 1.1rem 1.2rem;
  box-shadow: 0 12px 40px rgba(0,0,0,0.6), 0 0 0 1px rgba(245,158,11,0.08);
  z-index: 9001;
  animation: tour-fade 0.2s var(--ease) both;
}
@keyframes tour-fade { from { opacity: 0; } to { opacity: 1; } }

.tour-badge {
  font-size: 0.65rem;
  color: var(--amber);
  font-family: var(--font-ui);
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-bottom: 0.35rem;
}
.tour-title {
  font-size: 0.97rem;
  font-weight: 800;
  color: var(--text-hi);
  font-family: var(--font-ui);
  letter-spacing: -0.02em;
  margin-bottom: 0.38rem;
}
.tour-desc {
  font-size: 0.82rem;
  color: var(--text-lo);
  line-height: 1.6;
  font-family: var(--font-ui);
  margin-bottom: 0.9rem;
  font-weight: 400;
}
.tour-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 0.5rem;
}
.tour-skip {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 0.78rem;
  cursor: pointer;
  padding: 0.3rem 0.4rem;
  font-family: var(--font-ui);
  transition: color 0.15s;
}
.tour-skip:hover { color: var(--text); }
.tour-next {
  background: var(--amber);
  color: #0C0A00;
  border: none;
  border-radius: var(--r-sm);
  font-size: 0.82rem;
  font-weight: 800;
  cursor: pointer;
  padding: 0.38rem 0.95rem;
  font-family: var(--font-ui);
  transition: opacity 0.15s, transform 0.1s;
  letter-spacing: -0.01em;
}
.tour-next:hover { opacity: 0.88; }
.tour-next:active { transform: scale(0.96); }

/* Help button */
#help-btn {
  font-size: 0.78rem;
  font-weight: 800;
  border-radius: 50%;
  width: 30px; height: 30px;
  padding: 0;
  color: var(--muted);
  display: flex; align-items: center; justify-content: center;
}
#help-btn:hover { color: var(--amber); border-color: rgba(245,158,11,0.3); }

/* ── Progress Bar (#7) ───────────────────────────────────── */
.reader-progress {
  height: 3px;
  background: rgba(255,255,255,0.05);
  flex-shrink: 0;
  position: relative;
  z-index: 29;
}
.reader-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--amber), var(--amber-hi));
  transition: width 0.4s var(--ease);
  width: 0%;
}

/* (reader-layout uses flex: 1 1 0 — no fixed height override needed) */

/* ── My-Line Hint (#5) ───────────────────────────────────── */
.my-line-hint {
  position: fixed;
  top: 62px;
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(135deg, rgba(245,158,11,0.18), rgba(245,158,11,0.1));
  border: 1px solid rgba(245,158,11,0.4);
  border-radius: 99px;
  padding: 7px 18px;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--amber-hi);
  z-index: 28;
  white-space: nowrap;
  backdrop-filter: blur(12px);
  letter-spacing: -0.01em;
  animation: hintPop 0.3s var(--ease-back) both;
}
@keyframes hintPop {
  from { opacity: 0; transform: translateX(-50%) scale(0.9); }
  to   { opacity: 1; transform: translateX(-50%) scale(1); }
}

.next-my-hint {
  font-size: 0.7rem;
  color: var(--amber);
  font-weight: 600;
  opacity: 0.85;
  letter-spacing: -0.01em;
}

/* Inline timer in reader bar */
.timer-display {
  font-size: 0.75rem;
  color: var(--amber);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  background: var(--amber-dim);
  border: 1px solid rgba(245,158,11,0.2);
  border-radius: 99px;
  padding: 3px 10px;
  letter-spacing: 0.02em;
}

/* ── Chat Panel (#13) ────────────────────────────────────── */
.chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.chat-msg {
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-width: 85%;
  align-self: flex-start;
}
.chat-msg.chat-msg-mine { align-self: flex-end; align-items: flex-end; }
.chat-from {
  font-size: 0.68rem;
  color: var(--muted);
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 0 4px;
}
.chat-bubble {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 12px 12px 12px 4px;
  padding: 8px 12px;
}
.chat-msg-mine .chat-bubble {
  background: var(--amber-dim);
  border-color: rgba(245,158,11,0.25);
  border-radius: 12px 12px 4px 12px;
}
.chat-text {
  font-size: 0.85rem;
  line-height: 1.55;
  color: var(--text);
  word-break: break-word;
}
.chat-msg-mine .chat-text { color: var(--text-hi); }
.chat-time {
  font-size: 0.65rem;
  color: var(--muted);
  padding: 0 4px;
}
.chat-compose {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.chat-compose .text-input { padding: 9px 12px; font-size: 0.85rem; }
.chat-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #F87171;
  color: white;
  font-size: 0.6rem;
  font-weight: 900;
  border-radius: 99px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  margin-left: 2px;
  vertical-align: middle;
  line-height: 1;
}

/* ── Modals (#6 Scene / #18 Timer) ──────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.72);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.18s ease both;
}
.modal-overlay.hidden { display: none; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal-box {
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: var(--r-xl);
  width: 100%;
  max-width: 440px;
  max-height: 80dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 24px 60px rgba(0,0,0,0.7);
  animation: modalPop 0.22s var(--ease-back) both;
}
@keyframes modalPop {
  from { opacity: 0; transform: scale(0.95) translateY(8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-hd h3 {
  font-size: 0.93rem;
  font-weight: 700;
  color: var(--text-hi);
  letter-spacing: -0.02em;
}

/* Scene list */
.scene-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
}
.scene-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--r-md);
  cursor: pointer;
  transition: background 0.12s;
  border-bottom: 1px solid var(--border);
}
.scene-item:last-child { border-bottom: none; }
.scene-item:hover { background: rgba(245,158,11,0.07); }
.scene-item-num {
  font-size: 0.68rem;
  font-weight: 900;
  color: var(--amber);
  background: var(--amber-dim);
  border: 1px solid rgba(245,158,11,0.18);
  border-radius: 99px;
  padding: 2px 8px;
  white-space: nowrap;
  flex-shrink: 0;
}
.scene-item-text {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

/* Timer modal */
.timer-modal-box { max-width: 300px; }
.timer-display-lg {
  font-size: 3rem;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  color: var(--text-hi);
  text-align: center;
  padding: 28px 20px 16px;
  letter-spacing: 0.04em;
  font-family: var(--font-ui);
}
.timer-controls {
  display: flex;
  gap: 10px;
  padding: 12px 18px 20px;
  justify-content: center;
}

/* ── Script Library (#14) ────────────────────────────────── */
.library-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.library-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 12px 14px;
  transition: border-color 0.15s, background 0.15s;
}
.library-item:hover { border-color: var(--border2); background: var(--surface3); }
.library-info { flex: 1; min-width: 0; }
.library-title {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text-hi);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: -0.01em;
}
.library-meta {
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 2px;
  font-weight: 400;
}
.library-load-btn {
  background: var(--amber-dim);
  color: var(--amber);
  border: 1px solid rgba(245,158,11,0.2);
  border-radius: var(--r-sm);
  padding: 5px 11px;
  font-size: 0.76rem;
  font-weight: 800;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
  font-family: var(--font-ui);
}
.library-load-btn:hover { background: var(--amber-glow); }
.library-del-btn {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 5px 9px;
  font-size: 0.76rem;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
  font-family: var(--font-ui);
}
.library-del-btn:hover { color: #F87171; border-color: rgba(248,113,113,0.35); }

/* ── Parser Hint (#15) ───────────────────────────────────── */
.parser-hint {
  background: rgba(251,146,60,0.09);
  border: 1px solid rgba(251,146,60,0.28);
  border-radius: var(--r-md);
  padding: 10px 14px;
  font-size: 0.81rem;
  color: #FB923C;
  line-height: 1.6;
  font-weight: 500;
}

/* ── Observer Mode (#12) ─────────────────────────────────── */
.observer-btn {
  margin-top: 4px;
  width: 100%;
  text-align: center;
  color: var(--text-lo);
  font-size: 0.82rem;
}
.observer-btn:hover { color: var(--text); }
.p-observer-badge {
  font-size: 0.62rem;
  font-weight: 700;
  color: var(--text-lo);
  background: rgba(148,163,184,0.1);
  border: 1px solid rgba(148,163,184,0.18);
  padding: 2px 7px;
  border-radius: 99px;
  white-space: nowrap;
}

/* ── Bookmark Button (#8) ────────────────────────────────── */
.ctrl-bookmark {
  width: 44px; height: 44px;
  background: transparent;
  border: 1.5px solid var(--border);
  border-radius: var(--r-md);
  color: var(--muted);
  font-size: 1rem;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.ctrl-bookmark:hover { color: var(--amber); border-color: rgba(245,158,11,0.4); background: var(--amber-dim); }
.ctrl-bookmark.active { color: var(--amber); border-color: var(--amber); background: var(--amber-dim); }

/* ── Notes Panel Header Actions (#16) ───────────────────── */
.panel-hd-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ── QR Code (#17) ───────────────────────────────────────── */
.qr-container {
  margin-top: 12px;
  display: flex;
  justify-content: center;
}
.qr-container canvas {
  border-radius: var(--r-md);
  padding: 8px;
  background: white;
}

/* ── #19 Accessibility — Focus Rings ────────────────────── */
:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 2px;
  border-radius: 4px;
}
/* Remove default outline only when :focus-visible is supported */
:focus:not(:focus-visible) { outline: none; }

/* ── #11 Note Visibility Toggle ──────────────────────────── */
.note-vis-toggle {
  display: flex;
  gap: 6px;
  margin: 8px 0 4px;
}
.note-vis-btn {
  flex: 1;
  background: var(--surface2);
  border: 1.5px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--text-lo);
  font-size: 0.75rem;
  font-weight: 700;
  font-family: var(--font-ui);
  padding: 6px 10px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.note-vis-btn.active[data-vis="private"] {
  background: rgba(148,163,184,0.12);
  border-color: var(--border2);
  color: var(--text);
}
.note-vis-btn.active[data-vis="shared"] {
  background: var(--amber-dim);
  border-color: rgba(245,158,11,0.4);
  color: var(--amber);
}
.note-shared-badge {
  display: inline-block;
  font-size: 0.62rem;
  font-weight: 700;
  color: var(--amber);
  background: var(--amber-dim);
  border: 1px solid rgba(245,158,11,0.2);
  border-radius: 99px;
  padding: 1px 7px;
  margin-left: 6px;
  vertical-align: middle;
}
.note-private-badge {
  display: inline-block;
  font-size: 0.62rem;
  font-weight: 600;
  color: var(--muted);
  background: rgba(148,163,184,0.08);
  border: 1px solid rgba(148,163,184,0.15);
  border-radius: 99px;
  padding: 1px 7px;
  margin-left: 6px;
  vertical-align: middle;
}

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 600px) {
  /* Panels use position: fixed to cover reader-bar and host-ctrl properly */
  .side-panel {
    position: fixed;
    inset: 0;
    z-index: 60;
    width: 100%;
    max-height: 100dvh;
    border-left: none;
    border-top: 1px solid var(--border);
  }
  .home-cards { grid-template-columns: 1fr; }
  .char-select-grid { grid-template-columns: repeat(2, 1fr); }
  .reader-title { font-size: 0.78rem; max-width: 90px; }
  .script-wrap { padding: 32px 12px 140px; }
  .line-dialogue { padding-left: 14px; }

  /* #10 Larger touch targets on mobile */
  .ctrl-arrow { width: 58px; height: 58px; font-size: 1.3rem; }
  .ctrl-bookmark { width: 50px; height: 50px; }
  .icon-btn { padding: 9px 13px; font-size: 0.88rem; }
  .my-line-hint { top: 68px; font-size: 0.78rem; max-width: 90vw; white-space: normal; text-align: center; }
  .modal-box { max-height: 90dvh; }
  .timer-display-lg { font-size: 2.4rem; }
}
