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

:root {
  --bg: #f0f2f5;
  --surface: #ffffff;
  --surface2: #f8f9fb;
  --border: #dde1e8;
  --primary: #4361ee;
  --primary-dark: #3451d1;
  --accent: #e94560;
  --text: #1e2433;
  --text2: #5a6478;
  --text3: #9aa3b4;
  --green: #22c55e;
  --yellow: #f59e0b;
  --red: #ef4444;
  --radius: 10px;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.12);
  --nav-height: 56px;
}

/* ── Dark Theme ──────────────────────────────────────────── */
[data-theme="dark"] {
  --bg: #1a1b23;
  --surface: #23252d;
  --surface2: #2a2d35;
  --border: #3a3d47;
  --primary: #6b8aff;
  --primary-dark: #5a7af0;
  --accent: #ff6b81;
  --text: #e4e6eb;
  --text2: #9aa3b4;
  --text3: #6b7280;
  --green: #34d399;
  --yellow: #fbbf24;
  --red: #f87171;
  --shadow: 0 2px 12px rgba(0,0,0,0.3);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.4);
  --tool-menu-bg: rgba(35,37,45,0.95);
}

[data-theme="dark"] .viewer-canvas-container {
  background: #1e2028;
}

[data-theme="dark"] #canvas-container {
  background: #1e2028;
}

[data-theme="dark"] .color-swatch,
[data-theme="dark"] .color-row .color-swatch {
  border-color: rgba(255,255,255,0.15);
}

[data-theme="dark"] .card-delete-btn {
  background: rgba(0,0,0,0.7);
}

[data-theme="dark"] #log {
  background: #0d1117;
}

[data-theme="dark"] .color-row:hover {
  background: rgba(255,255,255,0.06);
}

[data-theme="dark"] .color-row.active {
  background: rgba(250, 204, 21, 0.12);
  outline-color: rgba(250, 204, 21, 0.5);
}

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

.hidden { display: none !important; }

#app {
  min-height: 100vh;
}

/* ── Top Navigation ──────────────────────────────────────── */
#top-nav {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

.nav-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  height: var(--nav-height);
  padding: 0 20px;
  gap: 24px;
}

.nav-brand {
  font-size: 18px;
  font-weight: 700;
  color: var(--primary);
  text-decoration: none;
  white-space: nowrap;
}

.nav-links {
  display: flex;
  gap: 16px;
  flex: 1;
}

.nav-link {
  font-size: 14px;
  font-weight: 500;
  color: var(--text2);
  text-decoration: none;
  padding: 4px 0;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}

.nav-link:hover {
  color: var(--text);
  border-bottom-color: var(--primary);
}

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

.nav-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  display: none;
}

.hamburger {
  display: none;
  flex-direction: column;
  gap: 4px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
}

.hamburger span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--text);
  border-radius: 1px;
  transition: transform 0.2s;
}

/* Theme toggle */
.theme-toggle {
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  padding: 0;
}

.theme-icon-dark { display: none; }

[data-theme="dark"] .theme-icon-light { display: none; }
[data-theme="dark"] .theme-icon-dark { display: inline; }

@media (max-width: 768px) {
  .hamburger { display: flex; }
  .nav-links, .nav-user {
    display: none;
  }
  #top-nav.nav-open .nav-links,
  #top-nav.nav-open .nav-user {
    display: flex;
  }
  .nav-inner {
    flex-wrap: wrap;
    height: auto;
    padding: 12px 20px;
  }
  .nav-links {
    width: 100%;
    flex-direction: column;
    padding: 8px 0;
  }
  .nav-user {
    width: 100%;
    padding: 8px 0;
  }
}

/* ── View Sections ───────────────────────────────────────── */
.view-section { display: none; }
.view-section.active { display: block; }

/* ── Layout (for parse view) ─────────────────────────────── */
.parse-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}

/* ── Landing View ────────────────────────────────────────── */
.landing-container {
  max-width: 480px;
  margin: 0 auto;
  padding: 80px 20px;
  text-align: center;
}

.landing-container h1 {
  font-size: 36px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.5px;
  margin-bottom: 8px;
}

.landing-subtitle {
  font-size: 16px;
  color: var(--text2);
  margin-bottom: 40px;
}

.landing-features {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 40px;
  text-align: left;
}

.feature {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  color: var(--text2);
}

.feature-icon {
  font-size: 20px;
  width: 32px;
  text-align: center;
  flex-shrink: 0;
}

.btn-google {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 12px 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  transition: box-shadow 0.15s, background 0.15s;
  box-shadow: var(--shadow);
}

.btn-google:hover {
  background: var(--surface2);
  box-shadow: var(--shadow-lg);
}

.google-icon {
  flex-shrink: 0;
}

/* ── Dashboard View ──────────────────────────────────────── */
.dashboard-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}

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

.dashboard-header h2 {
  font-size: 24px;
  font-weight: 700;
}

.dashboard-count {
  font-size: 14px;
  color: var(--text2);
  font-weight: 500;
  padding: 4px 12px;
  background: var(--surface2);
  border-radius: 20px;
  border: 1px solid var(--border);
}

.dashboard-actions {
  display: flex;
  gap: 10px;
  margin-bottom: 24px;
}

.patterns-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
}

.pattern-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  overflow: hidden;
}

.pattern-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.card-thumbnail {
  width: 100%;
  height: 180px;
  object-fit: contain;
  background: var(--surface2);
  display: block;
}

.card-thumbnail-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 700;
  color: var(--text3);
}

.card-info {
  padding: 14px 16px;
}

.card-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-meta {
  display: flex;
  gap: 12px;
  font-size: 12px;
  color: var(--text2);
  flex-wrap: wrap;
}

.card-date {
  font-size: 12px;
  color: var(--text3);
  margin-top: 6px;
}

.card-delete-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,0.5);
  color: white;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s;
}

.pattern-card:hover .card-delete-btn { opacity: 1; }

.card-delete-btn:hover { background: var(--red); }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text2);
  font-size: 15px;
}

.loading-spinner {
  text-align: center;
  padding: 40px;
  color: var(--text2);
}

/* ── Pattern Viewer ──────────────────────────────────────── */
#view-pattern.active {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

.viewer-layout {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.viewer-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.viewer-title {
  font-size: 16px;
  font-weight: 600;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin: 0;
}

.viewer-toolbar-right {
  display: flex;
  gap: 6px;
  align-items: center;
}

.viewer-body {
  display: flex;
  flex: 1;
  min-height: 0;
}

.viewer-canvas-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  position: relative;
}

.viewer-canvas-container {
  flex: 1;
  overflow: auto;
  background: #e5e7eb;
}

.viewer-tool-menu {
  position: absolute;
  top: 10px;
  left: 10px;
  display: flex;
  gap: 2px;
  background: var(--tool-menu-bg, rgba(255,255,255,0.92));
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.18);
  padding: 3px;
  z-index: 20;
}

.tool-btn {
  padding: 6px 14px;
  border: none;
  border-radius: 6px;
  background: transparent;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  color: var(--text2);
  transition: background 0.15s, color 0.15s;
}

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

.tool-btn.active {
  background: var(--primary);
  color: #fff;
}

.markup-color-picker {
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: 4px;
  display: flex;
  gap: 2px;
  background: var(--tool-menu-bg, rgba(255,255,255,0.95));
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.18);
  padding: 4px;
}

.markup-color-picker.hidden {
  display: none;
}

.markup-color-opt {
  width: 32px;
  height: 32px;
  border: 2px solid transparent;
  border-radius: 6px;
  background: var(--surface2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: bold;
  padding: 0;
}

.markup-color-opt:hover {
  background: var(--border);
}

.markup-color-opt.selected {
  border-color: var(--text);
}

.viewer-canvas-inner {
  /* Spacer div — sized by JS to pattern dimensions + viewport padding.
     Provides scroll extent for the container. */
  position: relative;
}

.viewer-canvas-inner canvas {
  position: absolute;
  top: 0;
  left: 0;
  display: block;
  cursor: crosshair;
  user-select: none;
  /* touch-action: none so browser doesn't handle pen/finger pan on canvas.
     Finger pan is handled manually in JS; pen is purely for markup. */
  touch-action: none;
}

.viewer-progress-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.progress-track {
  flex: 1;
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--green);
  border-radius: 4px;
  transition: width 0.3s;
  width: 0%;
}

.progress-text {
  font-size: 12px;
  font-weight: 500;
  color: var(--text2);
  white-space: nowrap;
}

.save-indicator {
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
}
.save-indicator.unsaved { color: var(--yellow); }
.save-indicator.saving { color: var(--text3); }
.save-indicator.saved { color: var(--green); }
.save-indicator.error { color: var(--red); }

/* Panel toggle button */
.panel-toggle-btn {
  width: 24px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: none;
  border-left: 1px solid var(--border);
  cursor: pointer;
  color: var(--text3);
  font-size: 10px;
  padding: 0;
  transition: background 0.15s, color 0.15s;
}

.panel-toggle-btn:hover {
  background: var(--bg);
  color: var(--text);
}

.panel-toggle-icon {
  display: block;
  transition: transform 0.2s;
}

/* Side panel */
.viewer-panel {
  width: 280px;
  background: var(--surface);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  flex-shrink: 0;
  padding: 16px;
  transition: width 0.2s, padding 0.2s;
}

.viewer-panel.panel-hidden {
  width: 0;
  padding: 0;
  overflow: hidden;
}

.viewer-panel h4 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text);
}

.viewer-color-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.color-row {
  display: grid;
  grid-template-columns: 20px 20px 60px 1fr auto auto;
  gap: 8px;
  align-items: center;
  font-size: 12px;
  cursor: pointer;
  border-radius: 4px;
  padding: 2px 4px;
  margin: 0 -4px;
}

.color-row:hover {
  background: var(--hover, rgba(0,0,0,0.05));
}

.color-row.active {
  background: rgba(250, 204, 21, 0.2);
  outline: 1px solid #facc15;
}

.color-symbol {
  font-size: 14px;
  text-align: center;
  line-height: 18px;
  color: var(--text);
}

.color-row .color-swatch {
  width: 18px;
  height: 18px;
  border-radius: 3px;
  border: 1px solid rgba(0,0,0,0.12);
}

.color-label {
  font-family: monospace;
  font-size: 11px;
  color: var(--text2);
}

.color-name {
  font-size: 11px;
  color: var(--text3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.color-progress-bar {
  width: 48px;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}

.color-progress-fill {
  height: 100%;
  background: var(--green);
  border-radius: 3px;
}

.color-count {
  font-size: 10px;
  color: var(--text3);
  font-family: monospace;
  text-align: right;
  min-width: 60px;
}

/* Tablet portrait (iPad etc.) */
@media (min-width: 769px) and (max-width: 1024px) {
  .viewer-panel { width: 240px; }
}

/* Large desktop */
@media (min-width: 1400px) {
  .viewer-panel { width: 320px; }
}

/* Mobile / small tablet */
@media (max-width: 768px) {
  .viewer-toolbar {
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 12px;
  }
  .viewer-title {
    order: -1;
    flex-basis: 100%;
    font-size: 14px;
  }
  .viewer-toolbar-right {
    flex-wrap: wrap;
  }
  .viewer-toolbar-right .btn {
    min-height: 40px;
    min-width: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .viewer-panel {
    position: fixed;
    right: 0;
    top: 0;
    bottom: 0;
    z-index: 200;
    box-shadow: var(--shadow-lg);
    width: 280px;
  }
  .viewer-panel.panel-hidden {
    width: 0;
  }
  .panel-toggle-btn {
    position: fixed;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    z-index: 201;
    width: 28px;
    height: 48px;
    border-radius: 6px 0 0 6px;
    box-shadow: var(--shadow);
    border-left: 1px solid var(--border);
  }
}

/* ── Settings Page ───────────────────────────────────────── */
.settings-container {
  max-width: 640px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}

.settings-container h2 {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 24px;
}

.settings-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 24px;
  margin-bottom: 20px;
}

.settings-section-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 0;
}

.setting-row + .setting-row {
  border-top: 1px solid var(--border);
}

.setting-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.setting-label {
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
}

.setting-desc {
  font-size: 13px;
  color: var(--text3);
}

/* Toggle switch */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 52px;
  height: 30px;
  flex-shrink: 0;
}

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

.toggle-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--border);
  border-radius: 30px;
  transition: background 0.2s;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 24px;
  height: 24px;
  left: 3px;
  bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

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

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

/* Setting colour options */
.setting-color-options {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.setting-color-opt {
  width: 36px;
  height: 36px;
  border: 2px solid transparent;
  border-radius: 8px;
  background: var(--surface2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: bold;
  padding: 0;
}

.setting-color-opt:hover {
  background: var(--border);
}

.setting-color-opt.selected {
  border-color: var(--text);
}

@media (max-width: 768px) {
  .setting-row {
    flex-wrap: wrap;
  }
  .setting-color-options {
    width: 100%;
    justify-content: flex-start;
  }
}

/* ── Toast Notifications ─────────────────────────────────── */
.toast-container {
  position: fixed;
  top: 70px;
  right: 20px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translateX(20px);
  transition: opacity 0.3s, transform 0.3s;
  color: white;
}

.toast.show {
  opacity: 1;
  transform: translateX(0);
}

.toast-info { background: var(--text); }
.toast-ok { background: var(--green); }
.toast-error { background: var(--red); }
.toast-warn { background: var(--yellow); color: var(--text); }

/* ── Step Indicator ───────────────────────────────────────── */
.step-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  margin-bottom: 32px;
}

.step-indicator .step {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text3);
  transition: all 0.2s;
}

.step-indicator .step-num {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--border);
  color: var(--text3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  transition: all 0.2s;
}

.step-indicator .step.current {
  color: var(--primary);
}
.step-indicator .step.current .step-num {
  background: var(--primary);
  color: white;
}

.step-indicator .step.done {
  color: var(--green);
}
.step-indicator .step.done .step-num {
  background: var(--green);
  color: white;
}

.step-indicator .step-sep {
  width: 40px;
  height: 2px;
  background: var(--border);
}

/* ── Cards ────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
  margin-bottom: 20px;
}

.card h2 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 6px;
}

.card p.subtitle {
  color: var(--text2);
  margin-bottom: 20px;
  font-size: 13.5px;
}

/* ── Step Sections ────────────────────────────────────────── */
.step-section { display: none; }
.step-section.active { display: block; }

/* ── Upload ───────────────────────────────────────────────── */
#drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 48px 32px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  background: var(--surface2);
}

#drop-zone:hover,
#drop-zone.drag-over {
  border-color: var(--primary);
  background: var(--surface);
}

#drop-zone.drag-over { transform: scale(1.01); }

.drop-icon {
  font-size: 48px;
  margin-bottom: 12px;
}

#drop-zone p {
  color: var(--text2);
  font-size: 15px;
  margin-bottom: 16px;
}

#upload-status {
  margin-top: 16px;
  font-size: 13px;
  color: var(--text2);
  min-height: 20px;
}

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  border: none;
  cursor: pointer;
  transition: all 0.15s;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: white;
}
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-outline:hover:not(:disabled) { background: var(--surface2); }

.btn-sm {
  padding: 6px 12px;
  font-size: 13px;
}

/* ── Page Thumbnails ──────────────────────────────────────── */
#thumb-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 24px;
}

.thumb-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.thumb-wrapper canvas {
  border-radius: 6px;
  border: 3px solid var(--border);
  box-shadow: var(--shadow);
  transition: border-color 0.15s;
}

.thumb-wrapper[data-type="grid"] canvas { border-color: var(--primary); }
.thumb-wrapper[data-type="key"] canvas { border-color: var(--green); }
.thumb-wrapper[data-type="cover"] canvas { border-color: var(--yellow); }

.thumb-label {
  font-size: 12px;
  color: var(--text2);
  font-weight: 500;
}

.thumb-type-btn {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 20px;
  border: none;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  transition: all 0.15s;
}

.thumb-type-btn.type-skip  { background: #e5e7eb; color: #6b7280; }
.thumb-type-btn.type-cover { background: #fef3c7; color: #92400e; }
.thumb-type-btn.type-grid  { background: #dbeafe; color: #1d4ed8; }
.thumb-type-btn.type-key   { background: #dcfce7; color: #166534; }

/* ── Configure Controls ───────────────────────────────────── */
.configure-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.configure-info {
  font-size: 13px;
  color: var(--text2);
}

.legend-chips {
  display: flex;
  gap: 12px;
  font-size: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.legend-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text2);
}

.chip-dot {
  width: 10px;
  height: 10px;
  border-radius: 2px;
}

/* ── Parse Step ───────────────────────────────────────────── */
#log {
  background: #0f172a;
  border-radius: 8px;
  padding: 16px;
  font-family: 'Courier New', monospace;
  font-size: 12.5px;
  max-height: 200px;
  overflow-y: auto;
  color: #94a3b8;
  margin-bottom: 20px;
}

.log-info  { color: #94a3b8; }
.log-ok    { color: #4ade80; }
.log-warn  { color: #fbbf24; }
.log-error { color: #f87171; font-weight: bold; }

/* ── Results ──────────────────────────────────────────────── */
#results-section.hidden { display: none; }

.results-grid {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 20px;
  align-items: start;
}

@media (max-width: 800px) {
  .results-grid { grid-template-columns: 1fr; }
}

/* ── Key Table ────────────────────────────────────────────── */
#key-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

#key-table th {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 2px solid var(--border);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text2);
}

#key-table td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

#key-table tbody tr:hover { background: var(--surface2); }

.color-id {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  font-size: 11px;
  font-weight: 700;
}

.color-swatch {
  display: inline-block;
  width: 24px;
  height: 24px;
  border-radius: 4px;
  border: 1px solid rgba(0,0,0,0.12);
}

.mono { font-family: monospace; font-size: 13px; }
.num  { text-align: right; color: var(--text2); }

/* ── Pattern Canvas ───────────────────────────────────────── */
.canvas-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.canvas-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface2);
}

#canvas-container {
  width: 100%;
  height: 500px;
  overflow: auto;
  background: #e5e7eb;
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
}

#pattern-canvas {
  display: block;
  cursor: crosshair;
  image-rendering: pixelated;
}

#pattern-stats {
  padding: 8px 14px;
  font-size: 12px;
  color: var(--text2);
  border-top: 1px solid var(--border);
  background: var(--surface2);
}
