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

:root {
  --bg: #0a0e17;
  --bg-card: #121826;
  --bg-elevated: #1a2235;
  --border: rgba(255, 255, 255, 0.08);
  --text: #e8edf7;
  --text-muted: #8b95a8;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --accent-glow: rgba(59, 130, 246, 0.35);
  --success: #22c55e;
  --danger: #ef4444;
  --record: #f43f5e;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  --font: "Noto Sans SC", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  line-height: 1.6;
  background-image:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(59, 130, 246, 0.15), transparent),
    radial-gradient(ellipse 60% 40% at 100% 100%, rgba(99, 102, 241, 0.08), transparent);
}

.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 {
  max-width: 640px;
  margin: 0 auto;
  padding: 24px 20px 32px;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* Header */
.header {
  text-align: center;
  padding: 16px 0 28px;
  position: relative;
}

.header-glow {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 200px;
  height: 80px;
  background: radial-gradient(circle, var(--accent-glow), transparent 70%);
  pointer-events: none;
}

.title {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  background: linear-gradient(135deg, #fff 30%, #93c5fd 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.subtitle {
  margin-top: 8px;
  font-size: 0.875rem;
  color: var(--text-muted);
  letter-spacing: 0.12em;
}

/* Cards */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.script-input {
  width: 100%;
  min-height: 180px;
  padding: 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.8;
  resize: vertical;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.script-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.script-input::placeholder {
  color: var(--text-muted);
}

/* Toolbar */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: transform 0.15s, background 0.2s, box-shadow 0.2s, opacity 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.btn svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
  flex-shrink: 0;
}

.btn:active {
  transform: scale(0.96);
}

.btn-ghost {
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-ghost:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.15);
}

.btn-accent {
  background: rgba(59, 130, 246, 0.15);
  color: #93c5fd;
  border: 1px solid rgba(59, 130, 246, 0.3);
}

.btn-accent:hover {
  background: rgba(59, 130, 246, 0.25);
}

/* Stats */
.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

.stat {
  text-align: center;
  padding: 12px 8px;
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
}

.stat-value {
  display: block;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.stat-label {
  display: block;
  margin-top: 2px;
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Settings */
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.setting-label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
  white-space: nowrap;
}

.segmented {
  display: flex;
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
  padding: 3px;
  border: 1px solid var(--border);
}

.segment {
  padding: 8px 14px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 0.8125rem;
  font-weight: 500;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.segment:hover {
  color: var(--text);
}

.segment.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 8px var(--accent-glow);
}

/* Record button */
.btn-record {
  background: rgba(244, 63, 94, 0.12);
  color: var(--record);
  border: 1px solid rgba(244, 63, 94, 0.3);
  padding: 8px 16px;
}

.btn-record:hover {
  background: rgba(244, 63, 94, 0.2);
}

.btn-record.recording {
  background: var(--record);
  color: #fff;
  border-color: var(--record);
  animation: pulse-record 1.5s ease-in-out infinite;
}

.record-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}

.btn-record.recording .record-dot {
  animation: blink 1s step-end infinite;
}

@keyframes pulse-record {
  0%, 100% { box-shadow: 0 0 0 0 rgba(244, 63, 94, 0.4); }
  50% { box-shadow: 0 0 0 8px rgba(244, 63, 94, 0); }
}

@keyframes blink {
  50% { opacity: 0; }
}

/* Sliders */
.slider-group {
  margin-bottom: 18px;
}

.slider-group:last-child {
  margin-bottom: 0;
}

.slider-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.slider-header label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
}

.slider-value {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  min-width: 2.5em;
  text-align: right;
}

.slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: var(--bg-elevated);
  outline: none;
}

.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  box-shadow: 0 2px 8px var(--accent-glow);
  transition: transform 0.15s;
}

.slider::-webkit-slider-thumb:hover {
  transform: scale(1.1);
}

.slider::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  box-shadow: 0 2px 8px var(--accent-glow);
}

.slider::-moz-range-track {
  height: 6px;
  border-radius: 3px;
  background: var(--bg-elevated);
}

/* Actions */
.actions {
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 12px;
  margin-top: 4px;
}

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 14px 20px;
  font-size: 1rem;
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.06);
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #6366f1);
  color: #fff;
  padding: 14px 20px;
  font-size: 1rem;
  font-weight: 600;
  box-shadow: 0 4px 20px var(--accent-glow);
}

.btn-primary:hover {
  background: linear-gradient(135deg, var(--accent-hover), #4f46e5);
  box-shadow: 0 6px 28px var(--accent-glow);
}

.footer {
  text-align: center;
  padding-top: 24px;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.footer a {
  color: var(--accent);
  text-decoration: none;
}

.footer a:hover {
  text-decoration: underline;
}

/* Prompter overlay */
.prompter {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: #000;
  display: flex;
  flex-direction: column;
}

.prompter[hidden] {
  display: none !important;
}

.prompter-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
}

.prompter-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  cursor: pointer;
  transition: background 0.2s;
}

.prompter-btn svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

.prompter-btn:hover {
  background: rgba(255, 255, 255, 0.15);
}

.prompter-exit {
  width: auto;
  padding: 0 16px;
  font-family: var(--font);
  font-size: 0.875rem;
  font-weight: 500;
}

.prompter-status {
  font-size: 0.8125rem;
  color: rgba(255, 255, 255, 0.6);
}

.prompter-viewport {
  flex: 1;
  overflow: hidden;
  position: relative;
}

.prompter-content {
  padding: 40vh 8vw 60vh;
  color: #fff;
  line-height: 1.8;
  white-space: pre-wrap;
  word-break: break-word;
  will-change: transform;
}

.prompter-guide {
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, rgba(59, 130, 246, 0.6), transparent);
  pointer-events: none;
  transform: translateY(-50%);
}

.prompter-guide::before,
.prompter-guide::after {
  content: "";
  position: absolute;
  top: 50%;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  transform: translateY(-50%);
}

.prompter-guide::before { left: 16px; }
.prompter-guide::after { right: 16px; }

/* Orientation classes */
.prompter.orient-landscape .prompter-content {
  writing-mode: horizontal-tb;
}

.prompter.orient-portrait .prompter-content {
  writing-mode: vertical-rl;
  text-orientation: mixed;
  padding: 8vw 40vh 8vw 60vh;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  padding: 12px 24px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.875rem;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: transform 0.3s, opacity 0.3s;
  z-index: 2000;
  pointer-events: none;
  white-space: nowrap;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.toast.success {
  border-color: rgba(34, 197, 94, 0.4);
  color: var(--success);
}

.toast.error {
  border-color: rgba(239, 68, 68, 0.4);
  color: var(--danger);
}

/* Responsive */
@media (max-width: 480px) {
  .title {
    font-size: 1.625rem;
  }

  .toolbar {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .toolbar .btn-accent {
    grid-column: span 2;
  }

  .segment {
    padding: 8px 10px;
    font-size: 0.75rem;
  }

  .actions {
    grid-template-columns: 1fr;
  }
}

@media (orientation: landscape) and (max-height: 500px) {
  .app {
    padding: 12px 16px 20px;
  }

  .header {
    padding: 8px 0 16px;
  }

  .script-input {
    min-height: 120px;
  }
}
