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

:root {
  --bg-primary:     #0f1117;
  --bg-secondary:   #1a1d27;
  --bg-card:        #22263a;
  --accent:         #4f8ef7;
  --accent-glow:    rgba(79, 142, 247, 0.25);
  --text-primary:   #e8eaf6;
  --text-secondary: #8b92b8;
  --success:        #4caf82;
  --error:          #e05c5c;
  --border:         rgba(255, 255, 255, 0.08);
  --radius:         12px;
}

body {
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---- Header ---- */
header {
  text-align: center;
  padding: 2rem 1rem 1rem;
  border-bottom: 1px solid var(--border);
}

header h1 {
  font-size: 1.8rem;
  font-weight: 700;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, var(--text-primary), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.subtitle {
  color: var(--text-secondary);
  margin-top: 0.3rem;
  font-size: 0.95rem;
}

/* ---- Main Layout ---- */
main {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  flex: 1;
  padding: 1.5rem 2rem;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}

/* ---- Video Panel ---- */
.video-panel {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.video-wrapper {
  position: relative;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 4 / 3;
  border: 1px solid var(--border);
}

#video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1); /* Mirror display — natural for webcam */
}

.progress-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0, 0, 0, 0.65);
  padding: 0.6rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.progress-bar-track {
  height: 4px;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 2px;
}

.progress-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.1s linear;
  width: 0%;
}

#seq-progress-label {
  font-size: 0.72rem;
  color: var(--text-secondary);
}

.connection-status {
  font-size: 0.82rem;
  color: var(--text-secondary);
  text-align: center;
  padding: 0.2rem;
}

.connection-status.connected { color: var(--success); }
.connection-status.error     { color: var(--error); }

/* ---- Output Panel ---- */
.output-panel {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.sentence-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  min-height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 40px var(--accent-glow);
  transition: box-shadow 0.3s ease;
}

.sentence-placeholder {
  color: var(--text-secondary);
  font-style: italic;
  text-align: center;
}

.sentence-text {
  font-size: 2.4rem;
  font-weight: 700;
  letter-spacing: 2px;
  text-align: center;
  word-break: break-word;
  line-height: 1.25;
  text-transform: uppercase;
}

.clear-btn {
  align-self: flex-end;
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 1.25rem;
  cursor: pointer;
  font-size: 0.9rem;
  transition: background 0.15s, border-color 0.15s;
}

.clear-btn:hover {
  background: var(--bg-secondary);
  border-color: var(--accent);
}

/* ---- Predictions Panel ---- */
.predictions-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  flex: 1;
}

.predictions-panel h2 {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-secondary);
  margin-bottom: 1rem;
}

.prediction-bar-item {
  display: grid;
  grid-template-columns: 90px 1fr 52px;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.8rem;
}

.pred-label {
  font-size: 0.82rem;
  font-weight: 600;
  text-align: right;
  color: var(--text-primary);
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pred-track {
  height: 10px;
  background: rgba(255, 255, 255, 0.07);
  border-radius: 5px;
  overflow: hidden;
}

.pred-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 5px;
  transition: width 0.15s ease-out;
}

.pred-fill.top {
  background: var(--success);
}

.pred-pct {
  font-size: 0.78rem;
  color: var(--text-secondary);
  text-align: right;
}

/* ---- Footer ---- */
footer {
  text-align: center;
  padding: 1rem;
  font-size: 0.75rem;
  color: var(--text-secondary);
  border-top: 1px solid var(--border);
}

/* ---- Responsive ---- */
@media (max-width: 768px) {
  main {
    grid-template-columns: 1fr;
    padding: 1rem;
  }

  .sentence-text {
    font-size: 1.8rem;
  }

  header h1 {
    font-size: 1.4rem;
  }
}
