/* ═══════════════════════════════════════════════════════════
   Chess Vision Coach — Stylesheet v2.0
   Modern Dark Theme with Cyber-Emerald & Amber Accents
   ═══════════════════════════════════════════════════════════ */

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

:root {
  color-scheme: light dark;
  --bg-deep:       #090b0e;
  --bg-card:       #12161f;
  --bg-card2:      #1a202c;
  --bg-card-hover: #222938;
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-focus:  rgba(16, 185, 129, 0.5);
  
  --accent:        #10b981;
  --accent-light:  #34d399;
  --accent-glow:   rgba(16, 185, 129, 0.25);
  
  --accent2:       #f59e0b;
  --accent2-glow:  rgba(245, 158, 11, 0.2);
  
  --primary:       #6366f1;
  --danger:        #ef4444;
  --text:          #f9fafb;
  --text-dim:      #9ca3af;
  --text-muted:    #6b7280;
  
  --radius-lg:     14px;
  --radius-md:     10px;
  --radius-sm:     6px;
  --gap:           16px;
  
  accent-color:    var(--accent);
  scrollbar-color: var(--bg-card2) transparent;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: 'Space Grotesk', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg-deep);
  background-image: 
    radial-gradient(circle at 15% 15%, rgba(16, 185, 129, 0.05) 0%, transparent 40%),
    radial-gradient(circle at 85% 85%, rgba(99, 102, 241, 0.04) 0%, transparent 40%);
  background-attachment: fixed;
  color: var(--text);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  line-height: 1.5;
}

/* ── Accessibility ───────────────────────────────── */
.visually-hidden {
  position: absolute !important;
  clip-path: inset(50%) !important;
  overflow: hidden !important;
  width: 1px !important;
  height: 1px !important;
  margin: -1px !important;
  padding: 0 !important;
  border: 0 !important;
  white-space: nowrap !important;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ── Header ─────────────────────────────────────── */
.header {
  background: rgba(18, 22, 31, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-subtle);
  padding: 0 24px;
  height: 64px;
  position: sticky;
  top: 0;
  z-index: 100;
}

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

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

.logo-icon {
  font-size: 1.8rem;
  line-height: 1;
  filter: drop-shadow(0 0 8px var(--accent-glow));
}

.logo-titles {
  display: flex;
  flex-direction: column;
}

.logo-text {
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
  color: var(--text);
}

.logo-badge {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
}

/* Status Pill */
.status-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-card2);
  border: 1px solid var(--border-subtle);
  border-radius: 999px;
  padding: 6px 16px;
  font-size: 0.82rem;
  font-family: inherit;
  color: var(--text-dim);
  cursor: pointer;
  transition: all 0.2s ease;
}

.status-pill:hover {
  border-color: var(--accent);
  background: var(--bg-card-hover);
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #6b7280;
  transition: all 0.3s ease;
}

.status-pill.online .status-dot {
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent);
}
.status-pill.online .status-label {
  color: var(--accent-light);
  font-weight: 600;
}

.status-pill.offline .status-dot {
  background: var(--danger);
  box-shadow: 0 0 8px rgba(239, 68, 68, 0.4);
}
.status-pill.offline .status-label {
  color: var(--danger);
}

.status-pill.connecting .status-dot {
  background: var(--accent2);
  animation: pulse 1s infinite alternate;
}

/* ── Main Layout ────────────────────────────────── */
.main {
  flex: 1;
  max-width: 1140px;
  width: 100%;
  margin: 0 auto;
  padding: var(--gap);
  display: grid;
  grid-template-columns: 1.05fr 0.95fr;
  gap: var(--gap);
  align-items: start;
}

@media (max-width: 820px) {
  .main {
    grid-template-columns: 1fr;
    padding: 12px;
  }
}

.col {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

/* ── Universal Cards ────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
  transition: border-color 0.2s ease;
}

.card:hover {
  border-color: rgba(255, 255, 255, 0.12);
}

.card-label {
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* ── Input Mode Tabs ────────────────────────────── */
.mode-tabs-card {
  padding: 8px;
}

.tab-group {
  display: flex;
  gap: 6px;
  background: var(--bg-deep);
  padding: 4px;
  border-radius: var(--radius-md);
}

.tab-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 10px 8px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.tab-btn:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
}

.tab-btn.active {
  background: var(--bg-card2);
  color: var(--accent);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

/* ── Camera Card ────────────────────────────────── */
.camera-wrapper {
  position: relative;
  background: #000;
  border-radius: var(--radius-md);
  overflow: hidden;
  aspect-ratio: 4 / 3;
  box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.8);
}

#cameraFeed {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.live-indicator {
  font-size: 0.68rem;
  font-weight: 700;
  color: #ef4444;
  letter-spacing: 0.05em;
  animation: pulse 1s infinite alternate;
}

.camera-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  background: rgba(10, 14, 20, 0.88);
  color: var(--text);
  transition: opacity 0.3s;
}

.camera-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.overlay-icon {
  font-size: 2.8rem;
  margin-bottom: 8px;
  color: var(--accent);
}

.overlay-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 4px;
}

.overlay-sub {
  font-size: 0.82rem;
  color: var(--text-dim);
  max-width: 320px;
}

/* ── Drag & Drop Photo Upload ───────────────────── */
.upload-dropzone {
  border: 2px dashed rgba(255, 255, 255, 0.15);
  border-radius: var(--radius-md);
  padding: 36px 20px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  background: var(--bg-deep);
  transition: all 0.2s ease;
}

.upload-dropzone:hover,
.upload-dropzone.dragover {
  border-color: var(--accent);
  background: rgba(16, 185, 129, 0.04);
}

.upload-icon {
  font-size: 2.4rem;
  color: var(--accent);
}

.upload-text {
  font-size: 0.92rem;
  color: var(--text);
}

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

.upload-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ── Presets & Quick Test ───────────────────────── */
.presets-intro {
  font-size: 0.84rem;
  color: var(--text-dim);
  margin-bottom: 12px;
}

.preset-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
}

@media (max-width: 500px) {
  .preset-buttons {
    grid-template-columns: 1fr;
  }
}

.preset-chip {
  background: var(--bg-card2);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 10px 12px;
  text-align: left;
  cursor: pointer;
  transition: all 0.2s ease;
}

.preset-chip:hover {
  border-color: var(--accent);
  background: var(--bg-card-hover);
}

.preset-chip.active {
  border-color: var(--accent);
  background: rgba(16, 185, 129, 0.12);
  color: var(--accent-light);
}

.custom-fen-row {
  display: flex;
  gap: 8px;
}

.custom-fen-input {
  flex: 1;
  background: var(--bg-deep);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: 'Space Mono', monospace;
  font-size: 0.8rem;
  padding: 10px 12px;
  outline: none;
  transition: border-color 0.2s;
}

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

/* ── Board preview card ─────────────────────────── */
.board-wrapper {
  border-radius: var(--radius-md);
  overflow: hidden;
  background: #000;
  border: 1px solid var(--border-subtle);
}

.board-wrapper img {
  width: 100%;
  display: block;
}

.conf-badge {
  font-size: 0.75rem;
  background: var(--bg-card2);
  border: 1px solid rgba(16, 185, 129, 0.3);
  border-radius: 999px;
  padding: 3px 10px;
  color: var(--accent-light);
  font-family: 'Space Mono', monospace;
  font-weight: 700;
}

/* ── Config card ────────────────────────────────── */
.control-group {
  margin-bottom: 20px;
}

.ctrl-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 8px;
}

.elo-hint {
  font-family: 'Space Mono', monospace;
  font-size: 0.82rem;
  color: var(--accent2);
  font-weight: 700;
}

/* Toggle buttons */
.toggle-group {
  display: flex;
  gap: 8px;
}

.toggle-btn {
  flex: 1;
  background: var(--bg-card2);
  border: 1.5px solid var(--border-subtle);
  border-radius: var(--radius-md);
  color: var(--text-dim);
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  padding: 10px 8px;
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.toggle-btn:hover {
  border-color: rgba(255, 255, 255, 0.2);
  color: var(--text);
}

.toggle-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #062b1a;
  font-weight: 700;
  box-shadow: 0 2px 12px var(--accent-glow);
}

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

/* Depth slider */
.depth-row {
  display: flex;
  align-items: center;
  gap: 14px;
}

input[type="range"] {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  border-radius: 3px;
  background: var(--bg-card2);
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  box-shadow: 0 0 10px var(--accent-glow);
  transition: transform 0.1s;
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}

.depth-val {
  font-family: 'Space Mono', monospace;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--accent2);
  min-width: 28px;
  text-align: right;
}

.elo-note {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 6px;
}

/* Action Buttons */
.btn-row {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}

.btn {
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 700;
  padding: 12px 18px;
  border-radius: var(--radius-md);
  border: none;
  cursor: pointer;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn-start {
  flex: 1.4;
  background: var(--accent);
  color: #062b1a;
  box-shadow: 0 4px 14px var(--accent-glow);
}

.btn-start:hover:not(:disabled) {
  background: var(--accent-light);
  transform: translateY(-1px);
}

.btn-stop {
  flex: 1;
  background: var(--bg-card2);
  color: var(--danger);
  border: 1.5px solid var(--danger);
}

.btn-stop:hover:not(:disabled) {
  background: var(--danger);
  color: #fff;
}

.btn-secondary {
  background: var(--bg-card2);
  color: var(--text);
  border: 1px solid var(--border-subtle);
  font-size: 0.85rem;
}

.btn-secondary:hover {
  background: var(--bg-card-hover);
  border-color: rgba(255, 255, 255, 0.2);
}

.btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  transform: none !important;
}

/* ── Move Output Card ───────────────────────────── */
.move-card {
  position: relative;
  overflow: hidden;
}

.engine-badge {
  font-family: 'Space Mono', monospace;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text-dim);
  background: var(--bg-card2);
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
}

.move-display {
  background: linear-gradient(145deg, var(--bg-card2), var(--bg-deep));
  border-radius: var(--radius-md);
  padding: 24px 20px;
  min-height: 128px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 14px;
  border: 1.5px solid rgba(255, 255, 255, 0.06);
  position: relative;
}

.move-waiting {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  color: var(--text-dim);
  font-size: 0.9rem;
  text-align: center;
}

.wait-icon {
  font-size: 2rem;
  animation: pulse 1.5s infinite alternate;
}

.move-result {
  text-align: center;
  width: 100%;
}

.move-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 8px;
}

.move-san {
  font-family: 'Space Mono', monospace;
  font-size: 1.7rem;
  color: var(--accent);
  font-weight: 700;
  letter-spacing: 0.05em;
  text-shadow: 0 0 16px var(--accent-glow);
}

.move-uci-badge {
  font-family: 'Space Mono', monospace;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--accent2);
  background: var(--bg-deep);
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
}

.move-text {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.3;
  letter-spacing: -0.01em;
}

/* Recent Suggestions Trail */
.recent-moves-container {
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.recent-label {
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
}

.recent-pills {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.recent-chip {
  font-family: 'Space Mono', monospace;
  font-size: 0.78rem;
  background: var(--bg-card2);
  border: 1px solid var(--border-subtle);
  border-radius: 999px;
  padding: 2px 10px;
  color: var(--text-dim);
}

/* Status Bar */
.status-bar {
  background: var(--bg-card2);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 0.82rem;
  color: var(--text-dim);
  min-height: 40px;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border-subtle);
}

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

.status-bar.error .status-indicator-dot { background: var(--danger); }
.status-bar.error { color: var(--danger); border-color: rgba(239, 68, 68, 0.3); }

.status-bar.ok .status-indicator-dot { background: var(--accent); }
.status-bar.ok { color: var(--accent-light); border-color: rgba(16, 185, 129, 0.3); }

/* ── Mode info card ─────────────────────────────── */
.info-card {
  padding: 14px 18px;
}

.mode-info {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  font-size: 0.84rem;
}

.mode-icon {
  font-size: 1.6rem;
  flex-shrink: 0;
}

.mode-info strong {
  display: block;
  margin-bottom: 2px;
  color: var(--text);
  font-size: 0.92rem;
}

.mode-info p {
  color: var(--text-dim);
  line-height: 1.45;
}

/* ── Modal Dialog ───────────────────────────────── */
.modal-dialog {
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  color: var(--text);
  padding: 0;
  max-width: 480px;
  width: 90%;
  margin: auto;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.7);
}

.modal-dialog::backdrop {
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
}

.modal-content {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-title {
  font-size: 1.15rem;
  font-weight: 700;
}

.modal-desc {
  font-size: 0.85rem;
  color: var(--text-dim);
}

.modal-input {
  background: var(--bg-deep);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: 'Space Mono', monospace;
  font-size: 0.85rem;
  padding: 12px;
  width: 100%;
  outline: none;
}

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

.modal-status {
  font-size: 0.8rem;
  font-family: 'Space Mono', monospace;
  color: var(--text-dim);
  padding: 6px 0;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 8px;
}

/* ── Footer ─────────────────────────────────────── */
.footer {
  font-size: 0.78rem;
  color: var(--text-muted);
  padding: 20px;
  border-top: 1px solid var(--border-subtle);
  margin-top: auto;
}

.footer-inner {
  max-width: 1140px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.footer-links {
  display: flex;
  align-items: center;
  gap: 8px;
}

.footer-link-btn,
.footer-link {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: inherit;
  font-family: inherit;
  cursor: pointer;
  text-decoration: underline;
  transition: color 0.15s;
}

.footer-link-btn:hover,
.footer-link:hover {
  color: var(--accent);
}

/* ── Animations ─────────────────────────────────── */
@keyframes pulse {
  0%   { opacity: 1; }
  100% { opacity: 0.4; }
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.move-anim {
  animation: slideIn 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

@media (prefers-reduced-motion: reduce) {
  .move-anim,
  .live-indicator,
  .wait-icon {
    animation: none;
  }
}
