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

:root {
  --bg: #0e0e12;
  --surface: #18181e;
  --surface-2: #22222a;
  --border: #2e2e38;
  --text: #e4e4e8;
  --text-muted: #888894;
  --accent: #6c63ff;
  --accent-hover: #7b73ff;
  --green: #22c55e;
  --green-bg: rgba(34, 197, 94, 0.12);
  --yellow: #eab308;
  --yellow-bg: rgba(234, 179, 8, 0.12);
  --blue: #3b82f6;
  --blue-bg: rgba(59, 130, 246, 0.12);
  --red: #ef4444;
  --red-bg: rgba(239, 68, 68, 0.12);
  --purple: #a855f7;
  --purple-bg: rgba(168, 85, 247, 0.12);
  --radius: 10px;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", "Fira Code", "Cascadia Code", monospace;
}

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

header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 16px 24px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

h1 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.muted {
  color: var(--text-muted);
  font-size: 13px;
}

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}

.badge--ok {
  background: var(--green-bg);
  color: var(--green);
}

.badge--error {
  background: var(--red-bg);
  color: var(--red);
}

.badge--unknown {
  background: var(--yellow-bg);
  color: var(--yellow);
}

main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* Status cards */
.cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.card__label {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
}

.card__value {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.card--queued .card__value { color: var(--yellow); }
.card--processing .card__value { color: var(--blue); }
.card--completed .card__value { color: var(--green); }
.card--failed .card__value { color: var(--red); }

/* Upload section */
.upload-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.upload-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
}

.tab {
  flex: 1;
  padding: 12px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
  border-bottom: 2px solid transparent;
}

.tab:hover { color: var(--text); }
.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.tab-panel {
  display: none;
  padding: 20px;
}

.tab-panel.active { display: block; }

.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 32px;
  text-align: center;
  transition: border-color 0.2s, background 0.2s;
  margin-bottom: 16px;
}

.drop-zone.dragover {
  border-color: var(--accent);
  background: rgba(108, 99, 255, 0.06);
}

.drop-zone p {
  margin-bottom: 4px;
}

.link-label {
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
}

.link-label input {
  display: none;
}

.url-input-row {
  display: flex;
  gap: 12px;
  margin-bottom: 12px;
}

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

.text-input:focus {
  border-color: var(--accent);
}

.btn {
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, background 0.15s;
  font-family: var(--font);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn--primary {
  background: var(--accent);
  color: #fff;
}

.btn--primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

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

.btn--ghost:hover {
  background: var(--border);
}

.upload-result {
  margin-top: 12px;
}

.upload-result .toast {
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 6px;
}

.toast--ok {
  background: var(--green-bg);
  color: var(--green);
  border: 1px solid rgba(34, 197, 94, 0.2);
}

.toast--error {
  background: var(--red-bg);
  color: var(--red);
  border: 1px solid rgba(239, 68, 68, 0.2);
}

.toast--info {
  background: var(--blue-bg);
  color: var(--blue);
  border: 1px solid rgba(59, 130, 246, 0.2);
}

/* Table */
.table-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.table-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.table-header h2 {
  font-size: 16px;
  font-weight: 600;
}

.table-controls {
  display: flex;
  gap: 8px;
  align-items: center;
}

.select {
  padding: 6px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  font-family: var(--font);
  outline: none;
  cursor: pointer;
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead th {
  padding: 10px 20px;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
}

tbody td {
  padding: 12px 20px;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
}

tbody tr:hover {
  background: var(--surface-2);
}

tbody tr:last-child td {
  border-bottom: none;
}

.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}

.status-dot--queued { background: var(--yellow); }
.status-dot--processing { background: var(--blue); }
.status-dot--completed { background: var(--green); }
.status-dot--failed { background: var(--red); }
.status-dot--pending_upload { background: var(--text-muted); }

.id-cell {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-muted);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.action-cell {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Chart section */
.chart-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.chart-section.hidden { display: none; }

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

.chart-header h2 {
  font-size: 16px;
  font-weight: 600;
}

/* 2×2 result grid */
.result-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 10px;
  height: 76vh;
  margin-bottom: 14px;
}

.grid-cell {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* Top-left: video */
.grid-cell--video {
  background: #000;
  align-items: center;
  justify-content: center;
}

.video-player {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

/* Chart cells */
.grid-cell--chart {
  background: var(--surface-2);
  padding: 12px 14px;
}

.cell-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 8px;
  flex-shrink: 0;
}

.chart-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
}

.chart-wrap canvas {
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
}

/* Moving playhead line */
.chart-playhead {
  position: absolute;
  width: 2px;
  background: rgba(239, 68, 68, 0.75);
  pointer-events: none;
  opacity: 0;
  border-radius: 1px;
  box-shadow: 0 0 4px rgba(239, 68, 68, 0.4);
  transition: left 0.08s linear;
}

/* Transcript cell */
.grid-cell--transcript {
  background: var(--surface-2);
  padding: 14px;
}

.transcript-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  flex-shrink: 0;
}

.transcript-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.transcript-words {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  line-height: 2;
  font-size: 13px;
  word-wrap: break-word;
  overflow-wrap: break-word;
  white-space: normal;
  scroll-behavior: smooth;
}

.transcript-speaker {
  display: block;
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-top: 10px;
  margin-bottom: 2px;
}

.transcript-word {
  display: inline;
  padding: 1px 2px;
  border-radius: 3px;
  cursor: pointer;
  transition: background 0.1s, color 0.1s;
}

.transcript-word:hover {
  background: rgba(108, 99, 255, 0.18);
  color: #a5a0ff;
}

.transcript-word.active {
  background: rgba(108, 99, 255, 0.28);
  color: #c4c0ff;
}

.transcript-event {
  display: inline;
  color: var(--text-muted);
  font-style: italic;
  font-size: 12px;
  padding: 0 3px;
}

/* Gesture labels inside gesture cell */
.chart-gestures {
  margin-top: 8px;
  padding: 6px 10px;
  background: var(--surface);
  border-radius: 6px;
  font-size: 12px;
  flex-shrink: 0;
}

.chart-gestures.hidden { display: none; }

.chart-gestures h4 {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

/* WPM panel */
.wpm-panel {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 14px;
}

.wpm-panel.hidden { display: none; }

.wpm-panel__header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.wpm-badge {
  font-size: 12px;
  font-weight: 700;
  padding: 2px 10px;
  border-radius: 20px;
  background: var(--blue-bg);
  color: var(--blue);
}

.wpm-score-badge {
  font-size: 12px;
  font-weight: 700;
  padding: 2px 10px;
  border-radius: 20px;
  background: var(--green-bg);
  color: var(--green);
}

.wpm-score-badge--low {
  background: var(--yellow-bg);
  color: var(--yellow);
}

.wpm-score-badge--poor {
  background: var(--red-bg);
  color: var(--red);
}

.wpm-feedback {
  font-size: 13px;
  color: var(--text-muted);
  flex: 1;
}

.wpm-chart-wrap {
  position: relative;
  height: 160px;
}

.wpm-chart-wrap canvas {
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
}

.chart-raw {
  margin-top: 12px;
}

.chart-raw summary {
  cursor: pointer;
  font-size: 13px;
  color: var(--text-muted);
  user-select: none;
}

.chart-raw pre {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  margin-top: 8px;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.6;
  color: var(--text-muted);
  max-height: 240px;
}

/* Settings section */
.settings-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  cursor: pointer;
  user-select: none;
}

.settings-header:hover {
  background: var(--surface-2);
}

.settings-header h2 {
  font-size: 16px;
  font-weight: 600;
}

.settings-chevron {
  color: var(--text-muted);
  font-size: 14px;
  transition: transform 0.2s;
}

.settings-chevron.open {
  transform: rotate(90deg);
}

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

.settings-body.hidden {
  display: none;
}

.settings-field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.settings-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.settings-textarea {
  width: 100%;
  padding: 12px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  font-family: var(--mono);
  line-height: 1.6;
  resize: vertical;
  outline: none;
  transition: border-color 0.15s;
}

.settings-textarea:focus {
  border-color: var(--accent);
}

.settings-actions {
  display: flex;
  align-items: center;
  gap: 14px;
}

.settings-status {
  font-size: 13px;
}

.settings-status--ok {
  color: var(--green);
}

.settings-status--error {
  color: var(--red);
}

.settings-radio-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 6px 0;
}

.settings-radio {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  cursor: pointer;
}

.settings-hint-inline {
  font-size: 11px;
  color: var(--text-muted);
}

/* Smile behavior panel */
.smile-analysis-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.smile-metrics-row {
  display: flex;
  gap: 28px;
  margin: 10px 0 12px;
}

.smile-metric {
  display: flex;
  flex-direction: column;
}

.smile-metric__value {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
}

.smile-metric__label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.smile-feedback {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
  margin: 4px 0;
}

.smile-backend-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--surface-2);
  color: var(--text-muted);
  text-transform: uppercase;
}

/* Prosody panel */
.prosody-panel {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 14px;
}

.prosody-panel.hidden { display: none; }

.prosody-charts-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-top: 16px;
}

.prosody-chart-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px 14px;
}

.prosody-chart-panel__header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.prosody-chart-panel__name {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.prosody-chart-wrap {
  position: relative;
  height: 140px;
}

.prosody-chart-wrap canvas {
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
}

.loading-skeleton {
  display: none;
  height: 140px;
  border-radius: 6px;
}

.loading-skeleton--visible {
  display: block;
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--border) 50%, var(--surface-2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}

.no-data-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 140px;
  border-radius: 6px;
  border: 1px dashed var(--border);
  font-size: 12px;
  color: var(--text-muted);
}

@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.prosody-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.prosody-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.prosody-card__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.prosody-card__name {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.prosody-card__score {
  font-size: 12px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 20px;
  white-space: nowrap;
  background: var(--green-bg);
  color: var(--green);
}

.prosody-card__score--low {
  background: var(--yellow-bg);
  color: var(--yellow);
}

.prosody-card__score--poor {
  background: var(--red-bg);
  color: var(--red);
}

.prosody-card__score--error {
  background: rgba(136, 136, 148, 0.12);
  color: var(--text-muted);
}

.prosody-card__value {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

.prosody-card__feedback {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.4;
}

/* Empty state */
.empty-row td {
  text-align: center;
  padding: 40px;
  color: var(--text-muted);
}

/* Responsive */
@media (max-width: 768px) {
  .cards {
    grid-template-columns: repeat(2, 1fr);
  }

  .result-grid {
    grid-template-columns: 1fr;
    grid-template-rows: repeat(4, 40vh);
    height: auto;
  }

  .header-inner {
    flex-direction: column;
    gap: 8px;
    align-items: flex-start;
  }

  main {
    padding: 16px;
  }

  .table-header {
    flex-direction: column;
    gap: 12px;
    align-items: flex-start;
  }

  table {
    font-size: 13px;
  }

  thead th,
  tbody td {
    padding: 8px 12px;
  }
}
