:root {
  --bg-primary: #0f1117;
  --bg-surface: #1a1d27;
  --bg-surface-hover: #242736;
  --border: #2a2e3a;
  --text-primary: #e4e6eb;
  --text-secondary: #8b8fa3;
  --text-muted: #5c6072;
  --accent: #4fc3f7;
  --accent-hover: #39b8ed;
  --green: #66bb6a;
  --red: #ef5350;
  --orange: #ffa726;
  --radius: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

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

body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.5;
}

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px 16px 48px;
}

/* Header */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;
}
.header h1 {
  font-size: 1.35em;
  color: var(--accent);
  font-weight: 700;
}
.header .version {
  font-size: 0.7em;
  color: var(--text-muted);
  font-weight: 400;
}

/* Status badge */
.connection-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.85em;
  font-weight: 600;
  background: var(--bg-surface);
  border: 1px solid var(--border);
}
.connection-status .dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.connection-status.connected .dot { background: var(--green); box-shadow: 0 0 6px var(--green); }
.connection-status.connecting .dot { background: var(--orange); box-shadow: 0 0 6px var(--orange); }
.connection-status.disconnected .dot { background: var(--red); box-shadow: 0 0 6px var(--red); }

/* Panels */
.panel {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}
.panel-header {
  font-size: 0.85em;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 14px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

/* Controls row */
.controls-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}
.controls-row.full { justify-content: stretch; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9em;
  font-weight: 600;
  font-family: var(--font);
  transition: background 0.15s, opacity 0.15s;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-record { background: var(--red); color: #fff; }
.btn-record:hover:not(:disabled) { background: #d32f2f; }
.btn-record.active { animation: pulse-record 1.8s infinite; }
@keyframes pulse-record {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 83, 80, 0.5); }
  50% { box-shadow: 0 0 0 8px rgba(239, 83, 80, 0); }
}
.btn-pause { background: var(--orange); color: #1a1a2e; }
.btn-pause:hover:not(:disabled) { background: #f57c00; }
.btn-stop { background: var(--text-muted); color: #fff; }
.btn-stop:hover:not(:disabled) { background: #7a7e94; }
.btn-mute { background: var(--bg-primary); color: var(--text-primary); border: 1px solid var(--border); }
.btn-mute:hover:not(:disabled) { background: var(--bg-surface-hover); }
.btn-mute.active { background: var(--red); border-color: var(--red); color: #fff; }

/* Volume bar */
.volume-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 140px;
}
.vol-bar-bg {
  flex: 1; height: 10px; background: var(--bg-primary);
  border-radius: 5px; overflow: hidden; min-width: 60px;
}
.vol-bar-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--green), var(--orange), var(--red));
  transition: width 0.08s ease-out;
}
.vol-text { font-size: 0.8em; color: var(--text-secondary); min-width: 36px; }

input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 100px; height: 6px;
  background: var(--bg-primary); border-radius: 3px;
  outline: none; cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 16px; height: 16px;
  background: var(--accent); border-radius: 50%;
  cursor: pointer;
}

/* Sub-row (mic + STT selector) */
.sub-row {
  display: flex; align-items: center; gap: 8px; margin-top: 12px; flex-wrap: wrap;
}
.inline-label {
  font-size: 0.8em; color: var(--text-secondary); font-weight: 600; white-space: nowrap;
}
.ml-8 { margin-left: 8px; }
.select-box.short { max-width: 170px; }

/* Stats grid */
.stats-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px; margin-top: 14px;
}
.stat-item {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
}
.stat-label {
  font-size: 0.72em; color: var(--text-muted); margin-bottom: 3px;
  text-transform: uppercase; letter-spacing: 0.03em;
}
.stat-value {
  font-size: 1em; font-weight: 700; color: var(--text-primary);
}
.stat-value.good { color: var(--green); }
.stat-value.warn { color: var(--orange); }
.stat-value.bad { color: var(--red); }
.stat-bar {
  width: 100%; height: 4px; background: var(--bg-surface);
  border-radius: 2px; overflow: hidden; margin-top: 4px;
}
.stat-bar-fill {
  height: 100%; border-radius: 2px; transition: width 0.15s ease-out;
}
.stat-bar-fill.good { background: var(--green); }
.stat-bar-fill.warn { background: var(--orange); }
.stat-bar-fill.bad { background: var(--red); }

/* Language selectors */
.lang-row {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
  align-items: flex-start;
}
.lang-group { flex: 1; min-width: 180px; }
.lang-group label {
  display: block; font-size: 0.82em; color: var(--text-secondary);
  margin-bottom: 6px; font-weight: 600;
}
.select-box {
  width: 100%; padding: 8px 12px;
  background: var(--bg-primary); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: 6px;
  font-size: 0.9em; font-family: var(--font); cursor: pointer;
}
.select-box:focus { outline: none; border-color: var(--accent); }

.check-row {
  display: flex; gap: 14px; flex-wrap: wrap; margin-top: 4px;
}
.check-label {
  display: flex; align-items: center; gap: 6px;
  font-size: 0.9em; cursor: pointer; color: var(--text-primary);
}
.check-label input[type="checkbox"] { accent-color: var(--accent); width: 16px; height: 16px; }

/* Text input */
.textarea {
  width: 100%; padding: 10px 14px;
  background: var(--bg-primary); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: 6px;
  font-size: 0.9em; font-family: var(--font); resize: vertical;
  min-height: 60px; line-height: 1.5;
}
.textarea:focus { outline: none; border-color: var(--accent); }
.textarea::placeholder { color: var(--text-muted); }

/* Transcription area */
.transcript-area {
  min-height: 80px; max-height: 240px; overflow-y: auto;
  padding: 14px; background: var(--bg-primary);
  border: 1px solid var(--border); border-radius: 6px;
  font-size: 1.05em; line-height: 1.6; word-break: break-word;
}
.transcript-placeholder {
  color: var(--text-muted); font-style: italic;
}
.transcript-partial {
  color: var(--text-secondary); font-style: italic; opacity: 0.8;
}
.transcript-final {
  color: var(--text-primary);
}
.transcript-entry {
  margin-bottom: 6px; padding-bottom: 6px; border-bottom: 1px solid var(--bg-surface);
}
.transcript-entry:last-child { border-bottom: none; }

/* Translation panels grid */
.translation-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
}
.translation-card {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 14px;
  min-height: 80px;
}
.translation-card .tl-lang {
  font-size: 0.75em; font-weight: 700; color: var(--accent);
  text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 8px;
}
.translation-card .tl-text {
  font-size: 0.95em; line-height: 1.5; word-break: break-word;
}
.translation-card .tl-empty {
  color: var(--text-muted); font-style: italic; font-size: 0.85em;
}

/* Preset buttons */
.preset-row {
  display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px;
}
.btn-preset {
  font-size: 0.78em; padding: 5px 12px;
  background: var(--bg-primary); color: var(--text-secondary);
  border: 1px solid var(--border); border-radius: 14px;
  cursor: pointer; font-family: var(--font);
  transition: background 0.15s, color 0.15s;
}
.btn-preset:hover { background: var(--accent); color: #000; border-color: var(--accent); }

/* Context + rules side by side */
.context-rule-row {
  display: grid; grid-template-columns: 1fr 220px; gap: 12px;
}
@media (max-width: 600px) {
  .context-rule-row { grid-template-columns: 1fr; }
}
.context-textarea { min-height: 140px; }

.correction-rules-box {
  background: var(--bg-primary); border: 1px solid var(--border);
  border-radius: 6px; padding: 10px; max-height: 200px; overflow-y: auto;
}
.rules-header {
  font-size: 0.75em; font-weight: 700; color: var(--text-secondary);
  text-transform: uppercase; margin-bottom: 6px;
}
.rules-empty { color: var(--text-muted); font-size: 0.8em; font-style: italic; }
.rule-item { font-size: 0.82em; margin-bottom: 3px; color: var(--text-primary); }
.rule-wrong { color: var(--red); text-decoration: line-through; }
.rule-right { color: var(--green); }

/* Phrase hints */
.phrase-hints-section { margin-top: 6px; }
.hints-tools { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.hints-btn {
  font-size: 0.8em; padding: 6px 14px; border-radius: 4px;
  border: none; cursor: pointer; font-family: var(--font); font-weight: 600;
}
.hints-btn.auto { background: #e8f5e9; color: #145c2e; border: 1px solid #9fd4ae; }
.hints-btn.apply { background: var(--green); color: #fff; }
.hints-btn.clear { background: var(--text-muted); color: #fff; }
.hints-status {
  margin-top: 6px; font-size: 0.78em; color: var(--text-secondary);
}

/* Viewer link */
#viewer-panel .viewer-url-wrap {
  display: flex; gap: 8px; align-items: center;
}
.viewer-url-input {
  flex: 1; padding: 10px 14px;
  background: var(--bg-primary); color: var(--accent);
  border: 1px solid var(--border); border-radius: 6px;
  font-size: 0.85em; font-family: monospace; cursor: text;
}
.viewer-url-input:focus { outline: none; border-color: var(--accent); }
.btn-copy {
  background: var(--accent); color: #000;
  padding: 10px 16px; border: none; border-radius: 6px;
  cursor: pointer; font-size: 0.85em; font-weight: 600; font-family: var(--font);
  white-space: nowrap; transition: opacity 0.15s;
}
.btn-copy:hover { opacity: 0.85; }
.btn-copy.copied { background: var(--green); color: #fff; }

/* Responsive */
@media (max-width: 600px) {
  .controls-row { flex-direction: column; align-items: stretch; }
  .btn { width: 100%; }
  .lang-row { flex-direction: column; gap: 12px; }
  .translation-grid { grid-template-columns: 1fr; }
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
