* {
  box-sizing: border-box;
}

:root {
  color-scheme: dark;
  --bg: #050505;
  --surface: #0c0f17;
  --surface-2: #121824;
  --ink: #f3f4f6;
  --muted: #9ca3af;
  --line: rgba(255, 255, 255, 0.08);
  --accent: #14b8a6; /* Teal accent */
  --accent-hover: #2dd4bf;
  --accent-ink: #0f172a;
  --accent-glow: rgba(20, 184, 166, 0.15);
  --gold: #f59e0b;
  --control-bg: #0f131f;
  --control-hover: #161d2e;
  --shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
  --soft-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
  --radius: 12px;
  --font: Inter, ui-sans-serif, system-ui, -apple-system, sans-serif;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --ink: #0f172a;
  --muted: #64748b;
  --line: rgba(0, 0, 0, 0.08);
  --accent: #0d9488;
  --accent-hover: #0f766e;
  --accent-ink: #ffffff;
  --accent-glow: rgba(13, 148, 136, 0.12);
  --gold: #d97706;
  --control-bg: #f8fafc;
  --control-hover: #f1f5f9;
  --shadow: 0 20px 50px rgba(15, 23, 42, 0.08);
  --soft-shadow: 0 8px 30px rgba(15, 23, 42, 0.04);
}

html {
  scroll-behavior: smooth;
  background: var(--bg);
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button, input, select {
  font: inherit;
  color: inherit;
}

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

img {
  display: block;
  max-width: 100%;
}

[hidden] {
  display: none !important;
}

.iv-shell {
  min-height: 100vh;
  padding: 30px;
}

.iv-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 28px;
  width: min(1400px, 100%);
  margin: 0 auto;
}

/* Hero Header */
.iv-hero {
  margin-bottom: 24px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--line);
}

.iv-hero-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: 2.8rem;
  font-weight: 800;
  line-height: 1.1;
}

.iv-hero p:not(.eyebrow) {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 1rem;
  max-width: 600px;
}

/* Theme Toggle */
.iv-theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--control-bg);
  color: var(--ink);
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 700;
  padding: 0 14px 0 10px;
  transition: all 150ms ease;
}

.iv-theme-toggle:hover {
  background: var(--control-hover);
  transform: translateY(-1px);
}

.iv-theme-toggle-icon {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--gold);
  position: relative;
  box-shadow: 0 0 0 4px rgba(245, 158, 11, 0.15);
}

.iv-theme-toggle-icon::after {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--control-bg);
  transform: translate(5px, -3px);
  transition: background 150ms ease;
}

.iv-theme-toggle:hover .iv-theme-toggle-icon::after {
  background: var(--control-hover);
}

:root[data-theme="light"] .iv-theme-toggle-icon {
  background: #f59e0b;
  box-shadow: 0 0 0 4px rgba(245, 158, 11, 0.2);
}

:root[data-theme="light"] .iv-theme-toggle-icon::after {
  display: none;
}

/* Left Workspace Panel */
.iv-workspace {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  min-height: 520px;
  overflow: hidden;
  position: relative;
}

/* Dropzone styling */
.iv-dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  padding: 40px;
  border: 2px dashed rgba(20, 184, 166, 0.3);
  border-radius: calc(var(--radius) - 2px);
  margin: 12px;
  background: rgba(255, 255, 255, 0.01);
  cursor: pointer;
  transition: all 200ms ease;
  text-align: center;
}

.iv-dropzone * {
  pointer-events: none;
}

.iv-dropzone:hover, .iv-dropzone.dragover {
  border-color: var(--accent);
  background: rgba(20, 184, 166, 0.03);
  box-shadow: inset 0 0 30px var(--accent-glow);
}

.iv-dropzone-icon {
  width: 64px;
  height: 64px;
  color: var(--accent);
  margin-bottom: 20px;
  opacity: 0.8;
  transition: transform 200ms ease;
}

.iv-dropzone:hover .iv-dropzone-icon {
  transform: translateY(-4px) scale(1.05);
  opacity: 1;
}

.iv-dropzone h3 {
  font-size: 1.25rem;
  font-weight: 700;
  margin: 0 0 8px;
}

.iv-dropzone p {
  color: var(--muted);
  margin: 0;
  font-size: 0.9rem;
}

.iv-dropzone .browse-btn {
  margin-top: 18px;
  padding: 8px 20px;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-weight: 600;
  font-size: 0.85rem;
  transition: all 150ms ease;
}

.iv-dropzone:hover .browse-btn {
  border-color: var(--accent);
  color: var(--ink);
}

/* Workspace Header / View Controls */
.iv-workspace-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.15);
}

.iv-file-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.iv-file-name {
  font-weight: 600;
  font-size: 0.95rem;
}

.iv-file-size {
  color: var(--muted);
  font-size: 0.8rem;
  background: var(--surface-2);
  padding: 2px 6px;
  border-radius: 4px;
}

.iv-tab-group {
  display: flex;
  gap: 6px;
  background: var(--control-bg);
  padding: 4px;
  border-radius: 8px;
  border: 1px solid var(--line);
}

.iv-tab {
  background: transparent;
  border: none;
  border-radius: 6px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 6px 14px;
  cursor: pointer;
  transition: all 120ms ease;
}

.iv-tab:hover {
  color: var(--ink);
}

.iv-tab.active {
  background: var(--surface);
  color: var(--accent);
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

/* Canvas & SVG Previews */
.iv-viewer {
  display: grid;
  flex: 1;
  min-height: 400px;
  position: relative;
  background: #090b10;
  background-image: radial-gradient(rgba(255,255,255,0.03) 1px, transparent 0);
  background-size: 16px 16px;
}

.viewer-split {
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--line);
}

.viewer-single {
  grid-template-columns: 1fr;
}

.preview-pane {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  position: relative;
  overflow: hidden;
}

.pane-label {
  position: absolute;
  top: 12px;
  left: 12px;
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  color: var(--muted);
  padding: 4px 8px;
  border-radius: 4px;
  border: 1px solid var(--line);
  z-index: 5;
}

.preview-pane img, .preview-pane svg, .preview-pane canvas {
  max-width: 100%;
  max-height: 380px;
  object-fit: contain;
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
  background: #050505;
  border-radius: 4px;
}

/* Progress Overlay */
.progress-overlay {
  position: absolute;
  inset: 0;
  background: rgba(5, 5, 5, 0.85);
  backdrop-filter: blur(8px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 10;
  padding: 40px;
  text-align: center;
}

.progress-container {
  width: min(320px, 100%);
}

.progress-label {
  font-weight: 700;
  font-size: 1.1rem;
  margin-bottom: 8px;
}

.progress-bar-bg {
  width: 100%;
  height: 8px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--line);
  margin-bottom: 12px;
}

.progress-bar-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent);
  border-radius: 999px;
  transition: width 150ms ease-out;
}

.progress-subtext {
  color: var(--muted);
  font-size: 0.85rem;
}

/* Control Panel (Right) */
.iv-controls {
  position: sticky;
  top: 30px;
  align-self: start;
  display: flex;
  flex-direction: column;
  gap: 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--soft-shadow);
}

.control-section {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.control-section:last-of-type {
  border-bottom: none;
  padding-bottom: 0;
}

.control-section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0;
}

.control-section h2 {
  font-size: 1.3rem;
  font-weight: 750;
}

/* Form Controls */
.control-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.control-group label {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

/* Segmented Control / Selectors */
.segmented-control {
  display: flex;
  background: var(--control-bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 4px;
  width: 100%;
}

.segmented-control label {
  flex: 1;
  text-align: center;
  margin: 0;
  text-transform: none;
  letter-spacing: 0;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  position: relative;
}

.segmented-control input[type="radio"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.segmented-control span {
  display: block;
  padding: 8px;
  border-radius: 6px;
  color: var(--muted);
  transition: all 120ms ease;
}

.segmented-control input[type="radio"]:checked + span {
  background: var(--surface);
  color: var(--accent);
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}

/* Sliders */
.range-slider-container {
  display: flex;
  align-items: center;
  gap: 12px;
}

.range-slider-container input[type="range"] {
  flex: 1;
  height: 6px;
  background: var(--surface-2);
  border-radius: 999px;
  outline: none;
  -webkit-appearance: none;
  cursor: pointer;
}

.range-slider-container input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-glow);
  transition: transform 120ms ease;
}

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

.range-value {
  font-size: 0.85rem;
  font-weight: 700;
  width: 24px;
  text-align: right;
  color: var(--accent);
}

.remove-color-controls {
  display: grid;
  grid-template-columns: 22px 42px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
}

.remove-color-controls input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.remove-color-controls input[type="color"] {
  width: 42px;
  height: 30px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--control-bg);
  cursor: pointer;
}

.remove-color-tolerance {
  gap: 8px;
  min-width: 0;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 44px;
  border-radius: 8px;
  padding: 0 20px;
  border: 1px solid transparent;
  cursor: pointer;
  font-weight: 700;
  font-size: 0.95rem;
  transition: all 150ms ease;
  width: 100%;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
}

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

.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 4px 14px var(--accent-glow);
}

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

.btn-secondary {
  background: var(--surface-2);
  border-color: var(--line);
  color: var(--ink);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--control-hover);
  border-color: var(--muted);
}

.btn-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* SVG Info Cards */
.info-card {
  background: rgba(255,255,255,0.02);
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 12px;
  font-size: 0.8rem;
  color: var(--muted);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 16px;
}

.info-card div span:first-of-type {
  display: block;
  font-weight: 700;
  color: var(--ink);
  font-size: 0.85rem;
}

/* Footer / Source code link */
.iv-footer {
  margin-top: 30px;
  text-align: center;
  font-size: 0.8rem;
  color: var(--muted);
}

.iv-footer a {
  color: var(--accent);
  text-decoration: none;
}

.iv-footer a:hover {
  text-decoration: underline;
}

/* Responsive styles */
@media (max-width: 1024px) {
  .iv-layout {
    grid-template-columns: 1fr;
  }
  .iv-controls {
    position: static;
  }
}

@media (max-width: 640px) {
  .iv-shell {
    padding: 16px;
  }
  h1 {
    font-size: 2.2rem;
  }
  .iv-workspace-header {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }
  .viewer-split {
    grid-template-columns: 1fr;
  }
  .preview-pane img, .preview-pane svg, .preview-pane canvas {
    max-height: 280px;
  }
}

/* Checkerboard transparency pattern for light backgrounds */
.preview-pane.has-light-bg {
  background-color: #f7f8f6;
  background-image: 
    linear-gradient(45deg, #eef0ec 25%, transparent 25%),
    linear-gradient(-45deg, #eef0ec 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #eef0ec 75%),
    linear-gradient(-45deg, transparent 75%, #eef0ec 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
}

.preview-pane.has-light-bg svg {
  background: transparent;
}
