/* Kokoro Studio, styles
   Palette: base #0f0f10, surface #181819, accent #f59e0b, text #e8e8ea
   Author: CC-OPS-MOTHERSHIP */

:root {
  --bg: #0f0f10;
  --surface: #181819;
  --surface-2: #1f1f21;
  --surface-3: #26262a;
  --border: #2a2a2e;
  --border-strong: #3a3a3f;
  --text: #e8e8ea;
  --text-muted: #a0a0a8;
  --text-dim: #6e6e78;
  --accent: #f59e0b;
  --accent-hover: #fbb03d;
  --accent-dim: #7a4f08;
  --danger: #ef4444;
  --success: #10b981;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.4);
  --shadow-md: 0 6px 20px rgba(0,0,0,0.35);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --pane-gap: 14px;
  --pane-pad: 16px;
}

[data-theme="light"] {
  --bg: #f7f7f8;
  --surface: #ffffff;
  --surface-2: #f0f0f2;
  --surface-3: #e6e6e9;
  --border: #dcdce0;
  --border-strong: #c0c0c6;
  --text: #17171a;
  --text-muted: #55555c;
  --text-dim: #8b8b93;
  --accent: #d97706;
  --accent-hover: #b45309;
  --accent-dim: #fde8c4;
  --shadow-sm: 0 1px 2px rgba(20,20,30,0.06);
  --shadow-md: 0 8px 24px rgba(20,20,30,0.1);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

#app {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

button, input, textarea, select {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

::selection { background: var(--accent); color: #17171a; }

/* Header */
.app-header {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  color: var(--text);
}

.brand img { display: block; height: 34px; width: auto; }

.header-spacer { flex: 1; }

.engine-switch {
  display: inline-flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
}

.engine-switch button {
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 6px 16px;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 500;
  font-size: 13px;
  letter-spacing: 0.2px;
  transition: color 120ms ease, background 120ms ease;
}

.engine-switch button.active {
  background: var(--accent);
  color: #17171a;
  box-shadow: var(--shadow-sm);
}

.engine-switch button:not(.active):hover { color: var(--text); }

.header-actions { display: flex; gap: 8px; align-items: center; }

.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
}
.icon-btn:hover { color: var(--text); border-color: var(--border-strong); background: var(--surface-2); }
.icon-btn svg { width: 18px; height: 18px; }

.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
  margin-right: 8px;
}
.status-dot.ok { background: var(--success); box-shadow: 0 0 0 2px rgba(16,185,129,0.15); }
.status-dot.bad { background: var(--danger); box-shadow: 0 0 0 2px rgba(239,68,68,0.15); }

.status-pill {
  display: inline-flex;
  align-items: center;
  padding: 5px 10px 5px 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12px;
  color: var(--text-muted);
}

/* Main workspace */
.workspace {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr) 340px;
  grid-template-rows: minmax(0, 1fr);
  gap: var(--pane-gap);
  padding: var(--pane-gap);
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.pane {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.pane-header {
  padding: 14px var(--pane-pad) 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.pane-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1.4px;
}

.pane-body {
  padding: var(--pane-pad);
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.pane-body::-webkit-scrollbar { width: 10px; }
.pane-body::-webkit-scrollbar-track { background: transparent; }
.pane-body::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 5px; border: 2px solid var(--surface); }
.pane-body::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

/* Voice browser */
.filter-bar {
  padding: 12px var(--pane-pad);
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.input {
  width: 100%;
  padding: 8px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  outline: none;
  transition: border-color 120ms ease, background 120ms ease;
}
.input::placeholder { color: var(--text-dim); }
.input:focus { border-color: var(--accent); background: var(--bg); }

.input-search {
  padding-left: 34px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23a0a0a8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><circle cx='11' cy='11' r='7'/><line x1='21' y1='21' x2='16.65' y2='16.65'/></svg>");
  background-repeat: no-repeat;
  background-position: 10px center;
  background-size: 16px;
}

.filter-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.select {
  appearance: none;
  padding: 7px 26px 7px 10px;
  background-color: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  cursor: pointer;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23a0a0a8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat;
  background-position: right 6px center;
  background-size: 14px;
  font-size: 13px;
}
.select:focus { outline: none; border-color: var(--accent); }

.voice-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.voice-card {
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: background 100ms ease, border-color 100ms ease;
}
.voice-card:hover { background: var(--surface-3); }
.voice-card.selected {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, var(--surface-2));
}

.voice-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--accent) 0%, #b45309 100%);
  color: #17171a;
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
  letter-spacing: 0.5px;
}

.voice-meta { min-width: 0; flex: 1; }
.voice-name {
  font-weight: 600;
  font-size: 13px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.voice-tags {
  display: flex;
  gap: 6px;
  margin-top: 3px;
  font-size: 11px;
  color: var(--text-dim);
}

.badge {
  display: inline-block;
  padding: 1px 7px;
  background: var(--surface-3);
  border-radius: 999px;
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  font-weight: 600;
}

/* Script editor */
.editor-wrap { display: flex; flex-direction: column; height: 100%; }

.script-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px var(--pane-pad);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  gap: 12px;
  flex-wrap: wrap;
}

.script-toolbar .voice-summary {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.script-toolbar .voice-summary .label {
  color: var(--text-dim);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.editor-textarea {
  width: 100%;
  height: 100%;
  min-height: 260px;
  padding: 20px 22px;
  background: var(--surface);
  border: none;
  outline: none;
  color: var(--text);
  font-size: 15px;
  line-height: 1.7;
  resize: none;
  flex: 1;
}
.editor-textarea::placeholder { color: var(--text-dim); }

.editor-footer {
  padding: 12px var(--pane-pad);
  display: flex;
  align-items: center;
  gap: 12px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.word-count {
  color: var(--text-muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.spacer { flex: 1; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  transition: background 120ms ease, color 120ms ease, border-color 120ms ease, transform 100ms ease;
}
.btn:active { transform: translateY(1px); }

.btn-primary {
  background-color: var(--accent);
  color: #17171a;
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover { background-color: var(--accent-hover); }
.btn-primary.is-disabled,
.btn-primary:disabled {
  background-color: var(--surface-3);
  color: var(--text-dim);
  cursor: not-allowed;
  box-shadow: none;
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover { color: var(--text); border-color: var(--border-strong); }

.kbd {
  display: inline-block;
  padding: 1px 6px;
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--text-muted);
  line-height: 1.4;
}

/* Player */
.player {
  padding: 16px var(--pane-pad);
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.player.hidden { display: none; }

.player-header {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--text-muted);
}
.player-header strong { color: var(--text); font-weight: 600; }

.waveform {
  width: 100%;
  height: 68px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.player-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.time-display {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  font-family: var(--mono);
  font-size: 12px;
}

/* History */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-item {
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 100ms ease, border-color 100ms ease;
}
.history-item:hover { background: var(--surface-3); border-color: var(--border); }

.history-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
  gap: 8px;
}

.history-voice { font-weight: 600; font-size: 13px; color: var(--text); }

.history-time { color: var(--text-dim); font-size: 11px; font-variant-numeric: tabular-nums; }

.history-text {
  color: var(--text-muted);
  font-size: 12px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.4;
}

.empty-state {
  text-align: center;
  padding: 32px 12px;
  color: var(--text-dim);
  font-size: 13px;
}
.empty-state svg { opacity: 0.5; margin-bottom: 12px; }

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
  backdrop-filter: blur(4px);
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 460px;
  width: 100%;
  box-shadow: var(--shadow-md);
  max-height: 90vh;
  overflow-y: auto;
}

.modal h2 {
  margin: 0 0 4px;
  font-size: 18px;
  font-weight: 600;
}
.modal .subtitle {
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 20px;
}

.field { margin-bottom: 16px; }
.field label {
  display: block;
  color: var(--text-muted);
  font-size: 12px;
  margin-bottom: 6px;
  font-weight: 500;
}
.field .hint { color: var(--text-dim); font-size: 11px; margin-top: 6px; }

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 16px;
}

/* Toasts */
.toast-tray {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 200;
}

.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  color: var(--text);
  box-shadow: var(--shadow-md);
  font-size: 13px;
  min-width: 220px;
  animation: toast-in 180ms ease;
}
.toast.error { border-left-color: var(--danger); }
.toast.ok { border-left-color: var(--success); }

@keyframes toast-in {
  from { transform: translateX(24px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* Loading spinner */
.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255,255,255,0.2);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Footer */
.app-footer {
  padding: 12px 20px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.app-footer .signature { color: var(--text-muted); }
.app-footer code {
  font-family: var(--mono);
  background: var(--surface-2);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 11px;
  border: 1px solid var(--border);
}

/* Responsive */
@media (max-width: 1100px) {
  .workspace {
    grid-template-columns: 280px minmax(0, 1fr) 300px;
  }
}

@media (max-width: 900px) {
  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
    overflow: auto;
  }
  .pane { min-height: 320px; }
  .app-header { padding: 10px 14px; flex-wrap: wrap; gap: 10px; }
  .header-spacer { flex-basis: 100%; order: 3; height: 0; }
  .engine-switch { order: 2; }
}

@media (max-width: 520px) {
  .app-footer { flex-direction: column; align-items: flex-start; gap: 4px; }
  .brand img { height: 30px; }
  .filter-row { grid-template-columns: 1fr; }
}
