/* GhostActor Web – Mobile-First Dark Theme */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:      #0d0b1a;
  --surface: #13112a;
  --card:    #1e1b40;
  --accent:  #7c3aed;
  --accent2: #a78bfa;
  --glow:    rgba(124,58,237,0.35);
  --text:    #e8e4f0;
  --muted:   #7b7a9e;
  --green:   #4ade80;
  --yellow:  #fbbf24;
  --red:     #f87171;
  --border:  rgba(167,139,250,0.12);
  --radius:  10px;
  --shadow:  0 6px 30px rgba(0,0,0,0.6);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html { height: 100%; }
body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--card); border-radius: 2px; }

/* ── Header ── */
header {
  background: linear-gradient(135deg, #13112a 0%, #1a1240 100%);
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  z-index: 10;
  box-shadow: 0 2px 20px rgba(124,58,237,0.15);
}

/* ── Logo mark in header ── */
.logo-wrap { display: flex; align-items: center; gap: 10px; }
.logo-wrap img { width: 32px; height: 32px; }
.logo-text {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: .03em;
  color: var(--text);
}
.logo-text .ghost { color: #c4b5fd; }
.logo-text .actor { color: var(--accent2); }

/* ── Tab bar ── */
#tab-bar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-shrink: 0;
}
.tab-btn {
  flex: 1;
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: .76rem;
  padding: 10px 4px 8px;
  transition: color .2s, border-color .2s;
  white-space: nowrap;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  line-height: 1.2;
}
.tab-btn .tab-icon { font-size: 1.1rem; }
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--accent2); border-bottom-color: var(--accent); }
.tab-btn:disabled { opacity: .35; cursor: not-allowed; }

/* ── Content area ── */
#content { flex: 1; overflow: hidden; display: flex; flex-direction: column; min-height: 0; }
.tab-panel { display: none; flex: 1; overflow: hidden; flex-direction: column; min-height: 0; }
.tab-panel.active { display: flex; }

/* ── Buttons ── */
button, .btn {
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: .875rem;
  padding: 9px 16px;
  transition: opacity .15s, transform .1s, box-shadow .2s;
  touch-action: manipulation;
}
button:active { transform: scale(.95); }
.btn-primary  { background: linear-gradient(135deg, #7c3aed, #9d4edd); color: #fff; box-shadow: 0 2px 12px rgba(124,58,237,.4); }
.btn-primary:hover  { opacity: .9; box-shadow: 0 4px 20px rgba(124,58,237,.6); }
.btn-secondary { background: var(--card); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { border-color: var(--accent2); opacity: .9; }
.btn-accent2  { background: linear-gradient(135deg, #6d28d9, #7c3aed); color: #fff; }
.btn-accent2:hover  { opacity: .85; }
.btn-sm  { padding: 6px 12px; font-size: .78rem; }
.btn-danger { background: var(--red); color: #fff; }

/* ── Inputs ── */
input[type=text], input[type=password], textarea, select {
  background: rgba(255,255,255,.04);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 1rem;
  padding: 10px 12px;
  outline: none;
  transition: border-color .2s, box-shadow .2s;
  width: 100%;
  -webkit-appearance: none;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(124,58,237,.15);
}
select option { background: var(--surface); }
label { font-size: .8rem; color: var(--muted); display: block; margin-bottom: 4px; }

/* ── Cards ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}

/* ── Badges ── */
.badge { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: .72rem; font-weight: 700; }
.badge-green  { background: rgba(74,222,128,.2); color: var(--green); }
.badge-yellow { background: rgba(251,191,36,.2); color: var(--yellow); }
.badge-red    { background: rgba(248,113,113,.2); color: var(--red); }
.badge-blue   { background: rgba(167,139,250,.2); color: var(--accent2); }

/* ── Progress bar ── */
.progress-wrap { height: 6px; background: rgba(255,255,255,.08); border-radius: 3px; overflow: hidden; }
.progress-bar  { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent2)); border-radius: 3px; transition: width .3s; }

/* ── Toast ── */
#toast {
  position: fixed; bottom: calc(20px + var(--safe-bottom)); left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 20px; font-size: .875rem; max-width: calc(100vw - 40px); width: max-content;
  box-shadow: var(--shadow); opacity: 0; transition: opacity .3s, transform .3s;
  pointer-events: none; z-index: 9999; text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.error { border-color: var(--red); color: var(--red); }

/* ── Utilities ── */
.row { display: flex; align-items: center; gap: 8px; }
.gap-col { display: flex; flex-direction: column; gap: 8px; }
.hidden { display: none !important; }
.text-muted { color: var(--muted); font-size: .82rem; }
.spin { animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.section-title {
  font-size: .68rem; font-weight: 700; letter-spacing: .12em;
  text-transform: uppercase; color: var(--muted); margin-bottom: 10px;
}

/* ══════════════════════════════════════════════════════════════
   IMPORT TAB
══════════════════════════════════════════════════════════════ */
#tab-import {
  padding: 16px; gap: 14px; overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
#script-input {
  width: 100%; min-height: 180px; resize: vertical;
  font-family: 'Courier New', monospace; font-size: .85rem; line-height: 1.5;
}
.import-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.import-actions .btn { flex: 1; min-width: 130px; text-align: center; }

.gemini-box { display: flex; flex-direction: column; gap: 10px; }
.gemini-box .row { gap: 8px; }
.gemini-box input { flex: 1; }
.gemini-help { font-size: .75rem; color: var(--muted); line-height: 1.5; }
.gemini-help a { color: var(--accent2); }

.parse-result { font-size: .82rem; color: var(--muted); padding: 6px 0; }
.parse-result strong { color: var(--accent2); }
.import-grid { display: flex; flex-direction: column; gap: 14px; }

/* ══════════════════════════════════════════════════════════════
   SETUP TAB
══════════════════════════════════════════════════════════════ */
#tab-setup {
  padding: 16px; gap: 14px; overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.setup-grid { display: flex; flex-direction: column; gap: 14px; }

.actor-list { display: flex; flex-wrap: wrap; gap: 8px; }
.actor-chip {
  background: var(--card); border: 2px solid transparent;
  border-radius: 20px; color: var(--text); cursor: pointer;
  font-size: .9rem; padding: 8px 16px; transition: all .2s;
  touch-action: manipulation;
}
.actor-chip.selected {
  border-color: var(--accent); color: var(--accent2);
  background: rgba(124,58,237,.15);
  box-shadow: 0 0 12px rgba(124,58,237,.25);
}

.voice-table { width: 100%; border-collapse: collapse; font-size: .85rem; }
.voice-table th {
  text-align: left; color: var(--muted); font-size: .72rem;
  padding: 6px 8px; border-bottom: 1px solid var(--border);
}
.voice-table td { padding: 8px 6px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.voice-table tr:last-child td { border-bottom: none; }
.voice-table select { font-size: .82rem; padding: 6px 8px; }

.piper-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.install-log { font-size: .74rem; color: var(--muted); margin-top: 6px; min-height: 16px; }
#start-rehearsal-btn { width: 100%; padding: 14px; font-size: 1rem; margin-top: 4px; }

/* ══════════════════════════════════════════════════════════════
   REHEARSAL TAB – Mobile first
══════════════════════════════════════════════════════════════ */
#tab-rehearsal {
  display: flex; flex-direction: column;
  overflow: hidden; position: relative;
}

#rehearsal-main {
  flex: 1; padding: 16px; display: flex; flex-direction: column;
  gap: 12px; overflow-y: auto; -webkit-overflow-scrolling: touch; min-height: 0;
}

#current-line-card {
  flex-shrink: 0;
  border-left: 3px solid var(--accent);
  box-shadow: -4px 0 20px rgba(124,58,237,.2);
}
.current-char {
  font-size: .78rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .1em; color: var(--accent2);
}
.current-text { font-size: 1.25rem; line-height: 1.65; color: var(--text); }
.emotion-badge {
  font-size: .73rem; padding: 3px 12px; border-radius: 12px;
  background: rgba(124,58,237,.15); color: var(--accent2);
  border: 1px solid rgba(167,139,250,.2); display: inline-block;
}

#insitu-voice-row { flex-wrap: wrap; }
#insitu-voice-row label { margin: 0; font-size: .78rem; white-space: nowrap; }
#insitu-voice-row select { flex: 1; min-width: 120px; }

/* Controls */
.rehearsal-controls {
  display: flex; align-items: center; gap: 8px; flex-shrink: 0;
}
.rehearsal-controls .nav-btn {
  width: 48px; height: 48px; font-size: 1.2rem;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%; flex-shrink: 0;
}
#play-btn {
  width: 62px; height: 62px; font-size: 1.5rem;
  border-radius: 50%; flex-shrink: 0;
  box-shadow: 0 0 24px rgba(124,58,237,.5);
}
.toggle-wrap { display: flex; align-items: center; gap: 6px; font-size: .82rem; }
.toggle-wrap input[type=checkbox] { accent-color: var(--accent); width: 16px; height: 16px; }
#progress-label { font-size: .78rem; color: var(--muted); margin-left: auto; white-space: nowrap; }

/* Mic bar */
#mic-bar {
  background: var(--surface); border-top: 1px solid var(--border);
  padding: 8px 14px; padding-bottom: calc(8px + var(--safe-bottom));
  display: flex; align-items: center; gap: 10px;
  flex-shrink: 0; flex-wrap: wrap;
}
#vad-toggle { font-size: .78rem; white-space: nowrap; }
.mic-level-wrap {
  flex: 1; min-width: 60px; max-width: 140px;
  height: 8px; background: rgba(255,255,255,.08); border-radius: 4px; overflow: hidden;
}
#mic-level-bar {
  height: 100%; border-radius: 4px; background: var(--green); width: 0%;
  transition: width .08s;
}
#mic-status { font-size: .75rem; color: var(--muted); min-width: 64px; }
.slider-wrap { display: flex; align-items: center; gap: 6px; font-size: .72rem; color: var(--muted); }
.slider-wrap input[type=range] { accent-color: var(--accent); width: 70px; }

/* Bottom sheet (mobile) */
#script-list-wrap {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: var(--surface);
  border-top: 2px solid var(--accent);
  box-shadow: 0 -8px 40px rgba(124,58,237,.25);
  border-radius: 20px 20px 0 0;
  transform: translateY(100%);
  transition: transform .32s cubic-bezier(.32,1,.4,1);
  z-index: 20; max-height: 68vh;
  display: flex; flex-direction: column;
}
#script-list-wrap.open { transform: translateY(0); }

#sheet-handle {
  height: 38px; display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0; gap: 10px; color: var(--muted); font-size: .78rem;
}
#sheet-handle::before {
  content: ''; width: 44px; height: 4px;
  background: var(--accent); border-radius: 2px; opacity: .6;
}

#script-list {
  overflow-y: auto; padding: 4px 10px 20px;
  display: flex; flex-direction: column; gap: 4px;
  -webkit-overflow-scrolling: touch;
}

#script-toggle-btn {
  position: fixed; right: 16px; bottom: 110px;
  width: 50px; height: 50px; border-radius: 50%;
  background: var(--card); border: 1px solid var(--accent);
  font-size: 1.1rem; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 20px rgba(124,58,237,.4); z-index: 15; cursor: pointer;
  transition: background .2s, box-shadow .2s;
}
#script-toggle-btn.active { background: var(--accent); box-shadow: 0 4px 24px rgba(124,58,237,.7); }

#sheet-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.55); z-index: 19;
}
#sheet-overlay.show { display: block; }

/* Script cards */
.script-card {
  border-radius: 6px; border: 1px solid transparent;
  cursor: pointer; padding: 8px 10px; transition: all .12s;
}
.script-card:active { background: rgba(167,139,250,.08); }
.script-card.actor-line  { border-left: 3px solid var(--accent2); }
.script-card.other-line  { border-left: 3px solid var(--muted); opacity: .7; }
.script-card.current {
  background: rgba(124,58,237,.15); border-color: var(--accent); opacity: 1;
  box-shadow: 0 0 12px rgba(124,58,237,.2);
}
.script-card.played { opacity: .35; }
.card-char {
  font-size: .68rem; font-weight: 700; color: var(--accent2);
  text-transform: uppercase; letter-spacing: .06em; margin-bottom: 2px;
}
.script-card.other-line .card-char { color: var(--muted); }
.card-text { font-size: .8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ══════════════════════════════════════════════════════════════
   LOGIN PAGE
══════════════════════════════════════════════════════════════ */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center;
  justify-content: center; background: var(--bg); padding: 20px;
  background-image: radial-gradient(ellipse at 30% 30%, rgba(124,58,237,.12) 0%, transparent 60%),
                    radial-gradient(ellipse at 70% 70%, rgba(109,40,217,.08) 0%, transparent 60%);
}
.login-box {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 36px 28px; width: 100%; max-width: 370px;
  box-shadow: 0 8px 60px rgba(124,58,237,.2);
}
.login-logo {
  display: flex; flex-direction: column; align-items: center; gap: 12px; margin-bottom: 28px;
}
.login-logo img { width: 72px; height: 72px; }
.login-logo h1 { font-size: 1.8rem; font-weight: 800; letter-spacing: -.01em; }
.login-logo h1 .ghost { color: #c4b5fd; }
.login-logo h1 .actor { color: var(--accent2); }
.login-logo .sub { color: var(--muted); font-size: .85rem; }
.login-box .field { margin-bottom: 16px; }
.login-box .error-msg { color: var(--red); font-size: .82rem; margin-top: 10px; display: none; }
.login-box .error-msg.show { display: block; }

/* ══════════════════════════════════════════════════════════════
   DESKTOP ≥ 768px
══════════════════════════════════════════════════════════════ */
@media (min-width: 768px) {
  header { height: 54px; padding: 0 24px; }
  .logo-wrap img { width: 34px; height: 34px; }
  .logo-text { font-size: 1.2rem; }

  #tab-bar { padding: 0 24px; }
  .tab-btn {
    flex: none; flex-direction: row; gap: 6px;
    font-size: .88rem; padding: 12px 20px;
  }
  .tab-btn .tab-icon { font-size: 1rem; }

  #tab-import { padding: 24px; }
  .import-grid { display: grid; grid-template-columns: 1fr 320px; gap: 20px; flex: 1; min-height: 0; }
  .import-left { display: flex; flex-direction: column; gap: 12px; }
  .import-right { display: flex; flex-direction: column; gap: 12px; }
  #script-input { flex: 1; min-height: 0; resize: none; }
  .import-actions .btn { flex: none; }

  #tab-setup { padding: 24px; }
  .setup-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

  #tab-rehearsal {
    display: grid;
    grid-template-columns: 270px 1fr;
    grid-template-rows: 1fr auto;
    flex-direction: unset; position: static;
  }
  #script-list-wrap {
    position: static; grid-row: 1 / 3; max-height: none;
    transform: none !important; border-radius: 0; border-top: none;
    border-right: 1px solid var(--border); box-shadow: none; z-index: auto;
  }
  #sheet-handle { display: none; }
  #script-list { padding: 8px; }
  #script-toggle-btn { display: none; }
  #sheet-overlay { display: none !important; }

  #rehearsal-main { padding: 24px; gap: 16px; }
  .current-text { font-size: 1.4rem; }
  .rehearsal-controls .nav-btn { width: 44px; height: 44px; }
  #play-btn { width: 56px; height: 56px; }
  #mic-bar { grid-column: 2; padding: 10px 20px; }

  #start-rehearsal-btn { width: auto; padding: 10px 28px; font-size: .9rem; margin-top: 0; }
}

@media (min-width: 1024px) {
  .import-grid { grid-template-columns: 1fr 360px; }
  #tab-rehearsal { grid-template-columns: 300px 1fr; }
  .current-text { font-size: 1.5rem; }
}
