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

:root {
  --bg-0: #0b0b0c;
  --bg-1: #141517;
  --bg-2: #1c1d20;
  --bg-3: #26282c;
  --border: #2e3034;
  --border-soft: #242528;
  --text-1: #ececf0;
  --text-2: #a5a5ae;
  --text-3: #6b6d76;
  --accent: #f5a524;
  --accent-hover: #fbbf24;
  --accent-soft: rgba(245, 165, 36, 0.12);
  --danger: #ef4444;
  --r: #ef4444;
  --g: #22c55e;
  --b: #3b82f6;
  --radius: 8px;
}

html, body {
  height: 100%;
  background: var(--bg-0);
  color: var(--text-1);
  font-family: 'Inter', -apple-system, 'Segoe UI', system-ui, sans-serif;
  font-size: 14px;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

body { display: flex; flex-direction: column; }

/* ====== Top bar ====== */
.top-bar {
  display: flex; align-items: center; justify-content: space-between;
  height: 54px; padding: 0 20px;
  background: var(--bg-1);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand-dot {
  width: 22px; height: 22px; border-radius: 7px;
  background: linear-gradient(135deg, #f5a524 0%, #ec4899 70%, #8b5cf6 100%);
  box-shadow: 0 0 12px rgba(245, 165, 36, 0.3);
}
.brand-name { font-weight: 600; letter-spacing: 0.2px; }
.brand-sub {
  color: var(--text-3); font-size: 12px; font-weight: 400;
  padding-left: 8px; border-left: 1px solid var(--border); margin-left: 2px;
}

.mode-switch {
  display: flex; background: var(--bg-2);
  border-radius: var(--radius); padding: 3px;
  border: 1px solid var(--border);
}
.mode-btn {
  padding: 6px 20px; border-radius: 5px;
  background: transparent; color: var(--text-2); border: 0;
  font-size: 13px; font-weight: 500; cursor: pointer;
  transition: all 0.15s ease;
}
.mode-btn:hover:not(.active) { color: var(--text-1); }
.mode-btn.active {
  background: var(--bg-3); color: var(--text-1);
  box-shadow: 0 1px 2px rgba(0,0,0,0.35), inset 0 1px 0 rgba(255,255,255,0.04);
}
.mode-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.mode-switch.locked { position: relative; }

.top-actions { display: flex; gap: 8px; }
.ghost-btn {
  padding: 7px 14px;
  background: transparent; color: var(--text-2);
  border: 1px solid var(--border); border-radius: 6px;
  font-size: 12px; font-weight: 500; cursor: pointer;
  transition: all 0.15s ease;
}
.ghost-btn:hover { background: var(--bg-2); color: var(--text-1); border-color: var(--text-3); }

/* ====== Workspace ====== */
.workspace { display: flex; flex: 1; overflow: hidden; }

.viewport {
  flex: 1; display: flex; flex-direction: column;
  background: var(--bg-0); padding: 20px 20px 14px;
  overflow: hidden;
}

.mini-btn-group { display: flex; gap: 6px; }

.viewport-inner {
  flex: 1; position: relative;
  background:
    linear-gradient(45deg, #1a1a1c 25%, transparent 25%),
    linear-gradient(-45deg, #1a1a1c 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #1a1a1c 75%),
    linear-gradient(-45deg, transparent 75%, #1a1a1c 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
  background-color: #141416;
  border-radius: 10px; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--border-soft);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.viewport-inner.drag-over {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 2px var(--accent-soft);
}

#preview-canvas {
  max-width: 100%; max-height: 100%;
  display: block;
  border-radius: 4px;
  box-shadow: 0 12px 48px rgba(0,0,0,0.6);
}

.drop-prompt {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 10px;
  color: var(--text-2); cursor: pointer;
  transition: all 0.2s ease;
}
.drop-prompt:hover {
  background: var(--accent-soft);
  color: var(--text-1);
}
.drop-icon {
  width: 56px; height: 56px; border-radius: 16px;
  background: var(--bg-2); border: 1px dashed var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 28px; color: var(--accent); font-weight: 300;
  transition: all 0.2s ease;
}
.drop-prompt:hover .drop-icon { transform: scale(1.05); border-color: var(--accent); }
.drop-title { font-size: 15px; font-weight: 500; }
.drop-sub { font-size: 12px; color: var(--text-3); }
.drop-prompt.hidden { display: none; }

.loading-veil {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 12px;
  background: rgba(11, 11, 12, 0.6); backdrop-filter: blur(4px);
  z-index: 5; color: var(--text-2); font-size: 13px;
}
.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.viewport-badge {
  position: absolute; top: 12px; left: 12px;
  padding: 4px 10px;
  background: rgba(0,0,0,0.6); backdrop-filter: blur(8px);
  border-radius: 999px; border: 1px solid rgba(255,255,255,0.08);
  font-size: 11px; font-weight: 500;
  color: var(--accent);
  letter-spacing: 0.3px;
  pointer-events: none;
}

.viewport-footer {
  display: flex; justify-content: space-between;
  padding: 12px 4px 0;
  color: var(--text-3); font-size: 12px;
}
.hint-text { color: var(--text-2); font-weight: 500; }

/* ====== Sidebar ====== */
.sidebar {
  width: 320px; flex-shrink: 0;
  background: var(--bg-1);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  display: flex; flex-direction: column;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.sidebar::-webkit-scrollbar { width: 8px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }

.panel {
  padding: 16px;
  border-bottom: 1px solid var(--border);
}
.panel-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
}
.panel-title {
  font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.8px;
  color: var(--text-2);
}
.panel-hint {
  font-size: 12px; color: var(--text-3);
  line-height: 1.55; margin: 4px 0 12px;
}

.mini-btn {
  padding: 3px 9px;
  background: transparent; color: var(--text-2);
  border: 1px solid var(--border); border-radius: 4px;
  font-size: 11px; font-weight: 500; cursor: pointer;
  transition: all 0.15s ease;
}
.mini-btn:hover { color: var(--text-1); border-color: var(--text-3); background: var(--bg-2); }

/* ====== Channel tabs ====== */
.channel-tabs {
  display: flex; gap: 0; margin-bottom: 10px;
  background: var(--bg-2); border-radius: 6px; padding: 3px;
  border: 1px solid var(--border);
}
.channel-tab {
  flex: 1; padding: 6px 0;
  background: transparent; color: var(--text-2);
  border: 0; border-radius: 4px;
  font-size: 12px; font-weight: 600; cursor: pointer;
  transition: all 0.15s ease;
  letter-spacing: 0.3px;
}
.channel-tab:hover:not(.active) { color: var(--text-1); }
.channel-tab.active { background: var(--bg-3); color: var(--text-1); }
.channel-tab.ch-r.active { color: var(--r); }
.channel-tab.ch-g.active { color: var(--g); }
.channel-tab.ch-b.active { color: var(--b); }

/* ====== Curves ====== */
.curves-wrap {
  background: var(--bg-0); border: 1px solid var(--border);
  border-radius: 6px; overflow: hidden;
  position: relative;
  aspect-ratio: 1 / 1;
}
#curves-canvas {
  display: block; cursor: crosshair;
  width: 100%; height: 100%;
}

.curve-help {
  margin-top: 8px; font-size: 11px;
  color: var(--text-3); text-align: center;
  letter-spacing: 0.2px;
}

#histogram-canvas {
  width: 100%; height: 80px;
  display: block;
  background: var(--bg-0);
  border: 1px solid var(--border);
  border-radius: 6px;
}

/* ====== Primary button ====== */
.primary-btn {
  width: 100%; padding: 11px 14px;
  background: var(--accent);
  color: #1a1a1a;
  border: 0; border-radius: 7px;
  font-size: 13px; font-weight: 600; cursor: pointer;
  transition: all 0.15s ease;
  letter-spacing: 0.2px;
}
.primary-btn:hover:not(:disabled) {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(245, 165, 36, 0.25);
}
.primary-btn:active:not(:disabled) { transform: translateY(0); }
.primary-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.primary-btn.hidden { display: none; }

/* ====== Timer ====== */
.timer-display {
  text-align: center; padding: 18px 0 16px;
  background: var(--bg-2); border-radius: 8px; margin-bottom: 12px;
  border: 1px solid var(--border);
}
.timer-label {
  font-size: 10px; color: var(--text-2);
  text-transform: uppercase; letter-spacing: 1px;
  margin-bottom: 6px;
}
.timer-value {
  font-family: 'JetBrains Mono', 'SF Mono', monospace;
  font-size: 38px; font-weight: 300;
  color: var(--text-1);
  font-variant-numeric: tabular-nums;
  transition: color 0.3s ease;
}
.timer-value.urgent {
  color: var(--danger);
  animation: pulse 1s ease infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

.hidden { display: none !important; }

/* ====== Overlay / Modal ====== */
.overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.75);
  backdrop-filter: blur(14px);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  padding: 20px;
}

.result-card {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px;
  max-width: 560px; width: 100%;
  max-height: 90vh; overflow-y: auto;
  animation: rise 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: 0 24px 80px rgba(0,0,0,0.6);
}
@keyframes rise {
  from { opacity: 0; transform: translateY(20px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.result-title {
  font-size: 20px; font-weight: 500;
  text-align: center; margin-bottom: 20px;
  letter-spacing: 0.3px;
}

.score-ring {
  width: 150px; height: 150px; margin: 0 auto 10px;
  position: relative;
}
.score-ring svg { width: 100%; height: 100%; }
#score-arc {
  transition: stroke-dashoffset 1s cubic-bezier(0.22, 1, 0.36, 1);
}
.score-number {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 52px; font-weight: 300;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.5px;
}
.score-verdict {
  text-align: center; margin-bottom: 22px;
  color: var(--text-2); font-size: 14px;
  letter-spacing: 0.3px;
}

.compare-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 10px; margin-bottom: 20px;
}
.compare-cell {
  background: var(--bg-0); border: 1px solid var(--border);
  border-radius: 8px; overflow: hidden;
}
.compare-cell canvas { width: 100%; display: block; }
.compare-label {
  text-align: center; padding: 6px;
  font-size: 11px; color: var(--text-2);
  background: var(--bg-2);
  border-top: 1px solid var(--border);
  letter-spacing: 0.3px;
}

.result-actions { display: flex; gap: 8px; }
.result-actions .primary-btn, .result-actions .ghost-btn {
  flex: 1; padding: 10px;
}

.how-card .how-list {
  list-style: none; counter-reset: how;
  margin: 8px 0 20px;
}
.how-card .how-list li {
  counter-increment: how;
  padding: 10px 0 10px 38px; position: relative;
  color: var(--text-2); line-height: 1.6;
  border-bottom: 1px solid var(--border-soft);
}
.how-card .how-list li:last-child { border: 0; }
.how-card .how-list li::before {
  content: counter(how);
  position: absolute; left: 0; top: 10px;
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600;
}
.how-card .how-list strong { color: var(--text-1); font-weight: 600; }

/* ====== Responsive ====== */
@media (max-width: 880px) {
  .workspace { flex-direction: column; }
  .sidebar { width: 100%; border-left: 0; border-top: 1px solid var(--border); max-height: 50vh; }
  .brand-sub { display: none; }
}
