/* ─── Font ─────────────────────────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

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

:root {
  --bg:           #070b12;
  --surface:      #0c1220;
  --surface2:     #111a2e;
  --surface3:     #162240;
  --border:       #1a2840;
  --border-hover: #243a5c;
  --accent:       #3b82f6;
  --accent-dim:   rgba(59, 130, 246, 0.16);
  --accent-glow:  rgba(59, 130, 246, 0.08);
  --accent-light: #93c5fd;
  --text:         #e2e8f4;
  --text-dim:     #64748b;
  --text-faint:   #263348;
  --red:          #ef4444;
  --red-dim:      rgba(239, 68, 68, 0.1);
  --green:        #10b981;
  --green-dim:    rgba(16, 185, 129, 0.1);
  --yellow:       #f59e0b;
  --yellow-dim:   rgba(245, 158, 11, 0.1);
  --radius:       14px;
  --radius-sm:    10px;
  --font:         'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono:    'JetBrains Mono', 'Fira Code', Consolas, monospace;
}

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

/* ─── Auth Screen ──────────────────────────────────────────────────────────── */
.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

.auth-card {
  text-align: center;
  padding: 48px 40px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  width: 100%;
  max-width: 380px;
}

.auth-icon {
  margin-bottom: 20px;
}

.auth-icon img {
  width: 80px;
  height: 80px;
  border-radius: 18px;
}

.auth-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 6px;
}

.auth-subtitle {
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 28px;
}

.auth-input-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.auth-input {
  flex: 1;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

.auth-input:focus {
  border-color: rgba(59, 130, 246, 0.5);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.06);
}

.auth-btn {
  width: 100%;
  padding: 12px 20px;
  background: var(--accent);
  color: #0a0a0c;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: opacity 0.15s;
}

.auth-btn:hover { opacity: 0.85; }

.auth-error {
  color: var(--red);
  font-size: 12px;
  margin-top: 12px;
  min-height: 18px;
}

/* ─── App Container ────────────────────────────────────────────────────────── */
.app {
  max-width: 800px;
  margin: 0 auto;
  padding: 0 24px 40px;
  min-height: 100vh;
}

/* ─── Top Bar ──────────────────────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 20px 0 24px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.topbar-brand { flex-shrink: 0; }
.topbar-actions { flex-shrink: 0; }

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.topbar-logo {
  width: 26px;
  height: 26px;
  border-radius: 6px;
}

.topbar-actions {
  display: flex;
  gap: 4px;
  background: var(--surface2);
  border-radius: var(--radius-sm);
  padding: 3px;
}

.tab-btn {
  padding: 7px 16px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-dim);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

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

.tab-btn.active {
  background: var(--surface3);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

/* ─── Status Bar ───────────────────────────────────────────────────────────── */
.status-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 20px;
  transition: background 0.25s, border-color 0.25s;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-faint);
  flex-shrink: 0;
  transition: background 0.2s;
}

.status-text {
  font-size: 13px;
  color: var(--text-dim);
  flex: 1;
}

.status-duration {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}

/* Status states */
.status-bar[data-state="recording"]  { background: var(--red-dim); border-color: rgba(248,113,113,0.2); }
.status-bar[data-state="recording"] .status-dot { background: var(--red); animation: pulse-dot 0.85s ease-in-out infinite; }
.status-bar[data-state="recording"] .status-text { color: var(--red); font-weight: 500; }

.status-bar[data-state="processing"] .status-dot { background: var(--yellow); animation: pulse-dot 0.5s ease-in-out infinite; }
.status-bar[data-state="processing"] .status-text { color: var(--yellow); }

.status-bar[data-state="done"] .status-dot { background: var(--green); }
.status-bar[data-state="done"] .status-text { color: var(--green); }

.status-bar[data-state="error"] .status-dot { background: var(--red); }
.status-bar[data-state="error"] .status-text { color: var(--red); }

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.3; transform: scale(1.5); }
}

/* ─── Record Zone (Mic + Hotkeys side by side) ────────────────────────────── */
.record-zone {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
  transition: border-color 0.2s, background 0.2s;
}

body[data-state="recording"] .record-zone {
  border-color: rgba(248, 113, 113, 0.25);
  background: rgba(248, 113, 113, 0.03);
}

.mic-ring {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--surface2);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-faint);
  flex-shrink: 0;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

body[data-state="recording"] .mic-ring {
  background: var(--red-dim);
  border-color: var(--red);
  color: var(--red);
  box-shadow: 0 0 0 8px rgba(248, 113, 113, 0.06), 0 0 30px rgba(248, 113, 113, 0.1);
  animation: mic-breathe 1.5s ease-in-out infinite;
}

body[data-state="processing"] .mic-ring {
  background: var(--yellow-dim);
  border-color: rgba(251, 191, 36, 0.4);
  color: var(--yellow);
}

body[data-state="done"] .mic-ring {
  background: var(--green-dim);
  border-color: rgba(52, 211, 153, 0.4);
  color: var(--green);
}

@keyframes mic-breathe {
  0%, 100% { box-shadow: 0 0 0 8px rgba(248, 113, 113, 0.06), 0 0 30px rgba(248, 113, 113, 0.08); }
  50% { box-shadow: 0 0 0 14px rgba(248, 113, 113, 0.03), 0 0 50px rgba(248, 113, 113, 0.12); }
}

/* ─── Visualizer ───────────────────────────────────────────────────────────── */
.viz-wrap {
  height: 6px;
  margin: 0 0 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
  transition: height 0.28s cubic-bezier(0.34, 1.56, 0.64, 1),
              border-radius 0.2s, border-color 0.2s;
}

body[data-state="recording"] .viz-wrap {
  height: 56px;
  border-radius: var(--radius-sm);
  border-color: rgba(248, 113, 113, 0.15);
}

#viz-canvas {
  display: block;
  width: 100%;
  height: 100%;
  opacity: 0;
  transition: opacity 0.2s;
}

body[data-state="recording"] #viz-canvas { opacity: 1; }

/* ─── Hotkey Section (inside record-zone) ──────────────────────────────────── */
.hotkey-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}

.hotkey-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.setting-hint {
  font-size: 11px;
  color: var(--text-faint);
  line-height: 1.5;
}

.hotkey-badge {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  padding: 3px 10px;
  background: var(--surface3);
  border: 1px solid var(--border);
  border-bottom: 2px solid var(--accent-dim);
  border-radius: 6px;
  color: var(--accent);
  white-space: nowrap;
  flex-shrink: 0;
}

.hotkey-badge--translate {
  color: var(--green);
  border-bottom-color: var(--green-dim);
}

.hotkey-hint {
  font-size: 12px;
  color: var(--text-faint);
  flex: 1;
}

body.capturing-hotkey .hotkey-badge:not(.hotkey-badge--translate) {
  border-color: var(--accent);
  animation: badge-blink 0.65s step-end infinite;
}

body.capturing-hotkey-translate .hotkey-badge--translate {
  border-color: var(--green);
  animation: badge-blink 0.65s step-end infinite;
}

@keyframes badge-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.2; }
}

/* ─── Output Card ──────────────────────────────────────────────────────────── */
.output-card {
  margin-bottom: 16px;
}

.output-textarea {
  width: 100%;
  min-height: 200px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.7;
  padding: 14px 16px;
  resize: vertical;
  outline: none;
  transition: border-color 0.2s;
}

.output-textarea:focus { border-color: var(--accent-dim); }
.output-textarea::placeholder { color: var(--text-faint); }

.output-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-top: 8px;
}

.copy-feedback {
  font-size: 12px;
  color: var(--green);
  opacity: 0;
  transition: opacity 0.3s;
}

.copy-feedback.visible { opacity: 1; }

/* ─── History ──────────────────────────────────────────────────────────────── */
.history-body {
  padding: 8px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 300px;
  overflow-y: auto;
  border-top: 1px solid var(--border);
}

.history-empty {
  font-size: 12px;
  color: var(--text-faint);
  padding: 4px 0;
}

.history-item {
  display: flex;
  gap: 12px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.history-item:hover {
  border-color: var(--border-hover);
  background: var(--surface2);
}

.history-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex-shrink: 0;
}

.history-date {
  font-size: 10px;
  color: var(--text-faint);
  font-family: var(--font-mono);
  white-space: nowrap;
}

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

.history-mode {
  font-size: 9px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--accent);
  margin-top: 2px;
}

.history-mode--translate { color: var(--green); }

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

/* ─── Settings Panel ───────────────────────────────────────────────────────── */
.settings-panel {
  margin-top: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.settings-toggle {
  display: block;
  padding: 12px 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-dim);
  cursor: pointer;
  list-style: none;
  transition: color 0.15s, background 0.15s;
}

.settings-toggle:hover { color: var(--text); background: var(--surface); }
.settings-toggle::-webkit-details-marker { display: none; }

.settings-body {
  padding: 4px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  border-top: 1px solid var(--border);
}

.setting-row { display: flex; flex-direction: column; gap: 6px; }

.setting-row-inline {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
}

.setting-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
}

.select-input {
  width: 100%;
  padding: 8px 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  outline: none;
  cursor: pointer;
  transition: border-color 0.2s;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M3 5l3 3 3-3' fill='none' stroke='%2364748b' stroke-width='1.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

.select-input:focus { border-color: rgba(59, 130, 246, 0.5); }

.select-input option {
  background: #111a2e;
  color: #e2e8f4;
  padding: 8px;
}

/* ─── Toggle ───────────────────────────────────────────────────────────────── */
.toggle-row { display: flex; align-items: center; cursor: pointer; }
.toggle-row input { display: none; }

.toggle-track {
  width: 38px;
  height: 21px;
  background: var(--surface3);
  border: 1px solid var(--border);
  border-radius: 999px;
  position: relative;
  transition: background 0.2s, border-color 0.2s;
}

.toggle-track::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--text-faint);
  transition: transform 0.2s, background 0.2s;
}

.toggle-row input:checked + .toggle-track {
  background: var(--accent-dim);
  border-color: var(--accent);
}

.toggle-row input:checked + .toggle-track::after {
  transform: translateX(17px);
  background: var(--accent);
}

/* ─── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface2);
  color: var(--text-dim);
  font-family: var(--font);
  font-size: 12px;
  font-weight: 500;
  padding: 6px 14px;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.btn:hover { border-color: var(--border-hover); color: var(--text); }
.btn:disabled { opacity: 0.8; cursor: default; }

.btn-sm { padding: 5px 12px; font-size: 11px; }

.btn-ghost {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text-dim);
}
.btn-ghost:hover { background: var(--surface3); border-color: var(--border-hover); color: var(--text); }

.btn-link {
  background: transparent;
  border-color: transparent;
  color: var(--text-faint);
  margin-left: auto;
}
.btn-link:hover { color: var(--text-dim); background: transparent; border-color: transparent; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #0a0a0c;
  font-weight: 600;
}
.btn-primary:hover { opacity: 0.85; }

/* ─── Text Workshop ────────────────────────────────────────────────────────── */
.text-card {
  margin-bottom: 16px;
}

.card-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 8px;
}

.text-textarea {
  width: 100%;
  min-height: 300px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.65;
  padding: 14px 16px;
  resize: vertical;
  outline: none;
  transition: border-color 0.2s;
}

.text-textarea:focus { border-color: var(--accent-dim); }
.text-textarea::placeholder { color: var(--text-faint); }

.text-textarea--output {
  background: var(--surface2);
  min-height: 300px;
}

/* ── Action Buttons ── */
.text-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
}

.btn-action {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--surface2);
  border: 1px solid var(--border-hover);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  width: 100%;
  text-align: left;
}

.btn-action:hover {
  background: var(--surface3);
  border-color: var(--accent-dim);
  color: var(--text);
}

.btn-action:active {
  transform: scale(0.98);
}

.btn-action-icon {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface3);
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
}

.btn-action--rewrite .btn-action-icon { color: var(--accent-light); background: var(--accent-dim); border-color: var(--accent-dim); }
.btn-action--translate .btn-action-icon { color: var(--green); background: var(--green-dim); border-color: var(--green-dim); }

.btn-action--rewrite:hover { border-color: rgba(59, 130, 246, 0.35); }
.btn-action--translate:hover { border-color: rgba(16, 185, 129, 0.35); }

/* ── Action Group (button + dropdown together) ── */
.action-group {
  display: flex;
  align-items: stretch;
  gap: 0;
  margin-bottom: 10px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border-hover);
}

.action-group .btn-action {
  border: none;
  border-radius: 0;
  flex: 1;
}

.action-group .btn-action:hover {
  border: none;
}

.action-select {
  width: 180px;
  padding: 0 12px;
  background: var(--surface3);
  border: none;
  border-left: 1px solid var(--border);
  color: var(--text-dim);
  font-family: var(--font);
  font-size: 12px;
  font-weight: 500;
  outline: none;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 12 12'%3E%3Cpath d='M3 5l3 3 3-3' fill='none' stroke='%2364748b' stroke-width='1.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
  transition: background 0.15s, color 0.15s;
}

.action-select:hover {
  background: var(--surface2);
  color: var(--text);
}

.action-select option {
  background: #111a2e;
  color: #e2e8f4;
}

/* ── Summary Controls ── */
.summary-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.summary-controls .select-input {
  flex-shrink: 0;
}

.summary-controls .btn-action {
  flex-shrink: 0;
}

.btn-action--summary .btn-action-icon {
  background: var(--accent-dim);
  color: var(--accent-light);
  border-color: var(--accent-dim);
}

.btn-action--summary:hover { border-color: rgba(59, 130, 246, 0.35); }

/* ── Processing ── */
.text-processing {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 16px;
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ─── Scrollbar ────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent-dim); }

/* ─── App Footer ───────────────────────────────────────────────────────────── */
.app-footer {
  display: flex;
  justify-content: center;
  padding: 24px 0 0;
  margin-top: 12px;
  border-top: 1px solid var(--border);
}

/* ─── Light Theme ──────────────────────────────────────────────────────────── */
body.theme-light {
  --bg:           #f0f4fa;
  --surface:      #ffffff;
  --surface2:     #e8eef8;
  --surface3:     #dce4f0;
  --border:       #c8d5e8;
  --border-hover: #a8bbd4;
  --accent:       #3b82f6;
  --accent-dim:   rgba(59, 130, 246, 0.12);
  --accent-glow:  rgba(59, 130, 246, 0.06);
  --accent-light: #1e40af;
  --text:         #0f172a;
  --text-dim:     #475569;
  --text-faint:   #94a3b8;
  --red:          #dc2626;
  --red-dim:      rgba(220, 38, 38, 0.06);
  --green:        #059669;
  --green-dim:    rgba(5, 150, 105, 0.06);
  --yellow:       #d97706;
  --yellow-dim:   rgba(217, 119, 6, 0.06);
}

body.theme-light .auth-screen { background: var(--bg); }

body.theme-light .auth-card {
  background: #ffffff;
  border-color: var(--border);
}

body.theme-light .topbar { border-bottom-color: var(--border); }

body.theme-light .select-input option {
  background: #ffffff;
  color: #0f172a;
}

body.theme-light .select-input {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M3 5l3 3 3-3' fill='none' stroke='%23475569' stroke-width='1.5'/%3E%3C/svg%3E");
}

/* ─── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .app { padding: 0 14px 30px; }
  .topbar { flex-direction: column; gap: 12px; align-items: flex-start; }
  .text-actions { grid-template-columns: 1fr; }
  .action-group { flex-direction: column; }
  .action-select { width: 100%; border-left: none; border-top: 1px solid var(--border); }
  .record-zone { flex-direction: column; align-items: flex-start; }
}
