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

:root {
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --success: #22c55e;
  --warning: #f59e0b;
  --error: #ef4444;
  --bg: #0f172a;
  --bg-secondary: #1e293b;
  --bg-tertiary: #334155;
  --text: #f8fafc;
  --text-secondary: #94a3b8;
  --border: #475569;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
}

.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 20px;
}

header {
  text-align: center;
  margin-bottom: 30px;
}

header h1 {
  font-size: 2.5rem;
  background: linear-gradient(135deg, var(--primary), #a855f7);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.subtitle {
  color: var(--text-secondary);
  margin-top: 5px;
}

/* Camera Section */
.camera-section {
  background: var(--bg-secondary);
  border-radius: 16px;
  padding: 20px;
  margin-bottom: 20px;
}

.video-container {
  position: relative;
  width: 100%;
  border-radius: 12px;
  overflow: hidden;
  background: #000;
  aspect-ratio: 16/9;
}

#video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.scanning-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  border: 3px solid var(--primary);
  border-radius: 12px;
}

.scanning-overlay.hidden {
  display: none;
}

.scanning-line {
  position: absolute;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, transparent, var(--primary), transparent);
  animation: scan 2s ease-in-out infinite;
}

@keyframes scan {
  0%, 100% { top: 0; }
  50% { top: calc(100% - 3px); }
}

.controls {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-top: 20px;
  flex-wrap: wrap;
}

.control-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.control-group label {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

select {
  background: var(--bg-tertiary);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 10px 15px;
  border-radius: 8px;
  font-size: 1rem;
  cursor: pointer;
}

select:focus {
  outline: none;
  border-color: var(--primary);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 24px;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

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

.btn-primary.active {
  background: var(--error);
}

.btn-icon {
  font-size: 0.8rem;
}

.btn-icon-only {
  padding: 10px;
  background: var(--bg-tertiary);
  color: var(--text);
  border: 1px solid var(--border);
}

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

.status {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  padding: 8px 16px;
  background: var(--bg-tertiary);
  border-radius: 20px;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--text-secondary);
}

.status.ready .status-dot {
  background: var(--text-secondary);
}

.status.scanning .status-dot {
  background: var(--success);
  animation: pulse 1s ease-in-out infinite;
}

.status.processing .status-dot {
  background: var(--warning);
  animation: pulse 0.5s ease-in-out infinite;
}

.status.error .status-dot {
  background: var(--error);
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.status-text {
  font-size: 0.9rem;
  color: var(--text-secondary);
}

/* Answer Section */
.answer-section {
  background: var(--bg-secondary);
  border-radius: 16px;
  padding: 20px;
  display: none;
}

.answer-section.visible {
  display: block;
}

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

.answer-header h2 {
  font-size: 1.3rem;
}

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

.answer-actions .divider {
  width: 1px;
  height: 24px;
  background: var(--border);
  margin: 0 4px;
}

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

.btn-icon-only.active {
  background: var(--primary);
  border-color: var(--primary);
}

/* Guided Mode Section */
.guided-mode-section {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg-tertiary);
  border-radius: 8px;
  margin-bottom: 15px;
}

.guided-label {
  font-weight: 500;
}

.guided-hint {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-left: auto;
}

/* Toggle Switch */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 50px;
  height: 26px;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--border);
  transition: 0.3s;
  border-radius: 26px;
}

.toggle-slider:before {
  position: absolute;
  content: "";
  height: 20px;
  width: 20px;
  left: 3px;
  bottom: 3px;
  background: white;
  transition: 0.3s;
  border-radius: 50%;
}

.toggle-switch input:checked + .toggle-slider {
  background: var(--primary);
}

.toggle-switch input:checked + .toggle-slider:before {
  transform: translateX(24px);
}

/* Guided Status */
.guided-status {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.1), rgba(168, 85, 247, 0.1));
  border: 1px solid var(--primary);
  border-radius: 8px;
  padding: 15px;
  margin-bottom: 15px;
}

.guided-status.hidden {
  display: none;
}

.guided-status.error {
  background: rgba(239, 68, 68, 0.1);
  border-color: var(--error);
}

.guided-status.success {
  background: rgba(34, 197, 94, 0.1);
  border-color: var(--success);
}

.guided-progress {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.guided-icon {
  font-size: 1.2rem;
}

#guidedText {
  font-weight: 500;
}

.expected-next {
  background: var(--bg-secondary);
  padding: 8px 12px;
  border-radius: 6px;
  font-family: 'SF Mono', 'Fira Code', monospace;
}

.expected-next strong {
  color: var(--success);
  margin-right: 8px;
}

.question-display {
  background: var(--bg-tertiary);
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 15px;
  font-size: 0.95rem;
}

.question-display strong {
  color: var(--primary);
}

.code-container {
  background: #0d1117;
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 15px;
}

.code-container pre {
  margin: 0;
  padding: 20px;
  overflow-x: auto;
}

.code-container code {
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 0.9rem;
  line-height: 1.5;
}

.explanation {
  background: var(--bg-tertiary);
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 0.95rem;
}

.explanation strong {
  color: var(--success);
}

.explanation p {
  margin-top: 5px;
  color: var(--text-secondary);
}

/* Error Display */
.error-display {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid var(--error);
  border-radius: 8px;
  padding: 15px 20px;
  margin-top: 20px;
}

.error-display.hidden {
  display: none;
}

.error-display p {
  color: var(--error);
}

/* Mode Toggles Row */
.mode-toggles {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 15px;
  padding: 12px 16px;
  background: var(--bg-tertiary);
  border-radius: 8px;
  flex-wrap: wrap;
}

.toggle-label {
  font-weight: 500;
  margin-right: 5px;
}

.toggle-hint {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-right: 20px;
}

/* Context Indicator */
.context-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 15px;
  padding: 12px 16px;
  background: linear-gradient(135deg, rgba(34, 197, 94, 0.1), rgba(99, 102, 241, 0.1));
  border: 1px solid var(--success);
  border-radius: 8px;
}

.context-indicator.hidden {
  display: none;
}

.context-icon {
  font-size: 1.2rem;
}

.btn-small {
  padding: 6px 12px;
  font-size: 0.85rem;
  background: var(--bg-secondary);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
}

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

.btn-primary-small {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

.btn-primary-small:hover {
  background: var(--primary-hover);
}

/* Capture Flash */
.capture-flash {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: white;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.1s ease;
}

.capture-flash.flash {
  opacity: 0.3;
}

.capture-flash.hidden {
  display: none;
}

/* Answer Meta */
.answer-meta {
  display: flex;
  gap: 8px;
  margin-left: 15px;
}

.badge {
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  background: var(--primary);
  color: white;
}

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

.badge-warning {
  background: var(--warning);
}

.badge-success {
  background: var(--success);
}

/* Files Indicator */
.files-indicator {
  background: var(--bg-tertiary);
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 15px;
}

.files-indicator.hidden {
  display: none;
}

.files-indicator strong {
  color: var(--warning);
}

.files-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.files-list .file-badge {
  padding: 4px 10px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: 'SF Mono', monospace;
  font-size: 0.8rem;
}

/* Error Detection Section */
.error-section {
  background: var(--bg-secondary);
  border-radius: 16px;
  padding: 20px;
  margin-top: 20px;
  display: none;
  border: 2px solid var(--error);
}

.error-section.visible {
  display: block;
}

.error-header {
  display: flex;
  align-items: center;
  gap: 15px;
  margin-bottom: 15px;
}

.error-header h2 {
  font-size: 1.3rem;
}

.error-message-box {
  background: rgba(239, 68, 68, 0.1);
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 15px;
  font-family: 'SF Mono', monospace;
}

.error-message-box strong {
  color: var(--error);
}

.error-message-box code {
  display: block;
  margin-top: 8px;
  white-space: pre-wrap;
  word-break: break-all;
}

.error-diagnosis {
  background: var(--bg-tertiary);
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 15px;
}

.error-diagnosis strong {
  color: var(--warning);
}

.error-diagnosis p {
  margin-top: 5px;
  color: var(--text-secondary);
}

.error-fix {
  margin-bottom: 15px;
}

.error-fix strong {
  color: var(--success);
  display: block;
  margin-bottom: 8px;
}

.error-explanation {
  background: var(--bg-tertiary);
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 15px;
}

.error-explanation strong {
  color: var(--primary);
}

.error-explanation p {
  margin-top: 5px;
  color: var(--text-secondary);
}

/* Footer */
footer {
  text-align: center;
  margin-top: 40px;
  padding: 20px;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

/* Responsive */
@media (max-width: 600px) {
  .controls {
    flex-direction: column;
    align-items: stretch;
  }

  .status {
    margin-left: 0;
    justify-content: center;
  }

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