/* ========================================
   SHARED DESIGN TOKENS
   ======================================== */
:root {
  /* Type scale — major third (1.25) */
  --text-xs: 0.64rem;
  --text-sm: 0.8rem;
  --text-base: 1rem;
  --text-md: 1.125rem;
  --text-lg: 1.25rem;
  --text-xl: 1.563rem;
  --text-2xl: 1.953rem;
  --text-3xl: 2.441rem;
  --text-4xl: 3.052rem;

  /* Spacing scale — 4px base */
  --sp-1: 0.25rem;
  --sp-2: 0.5rem;
  --sp-3: 0.75rem;
  --sp-4: 1rem;
  --sp-5: 1.25rem;
  --sp-6: 1.5rem;
  --sp-8: 2rem;
  --sp-10: 2.5rem;
  --sp-12: 3rem;
  --sp-16: 4rem;
  --sp-20: 5rem;
  --sp-24: 6rem;

  /* Colors — warm neutrals with chromatic depth */
  --stone-50: #faf9f7;
  --stone-100: #f3f1ed;
  --stone-150: #eae7e1;
  --stone-200: #ddd9d0;
  --stone-300: #c4bfb3;
  --stone-400: #a39e90;
  --stone-500: #817b6d;
  --stone-600: #656055;
  --stone-700: #4d4941;
  --stone-800: #36332d;
  --stone-900: #222019;

  /* Brand colors */
  --apple: #1d1d1f;
  --apple-accent: #0071e3;
  --apple-light: #e8f0fe;
  --samsung: #1428a0;
  --samsung-accent: #1428a0;
  --samsung-light: #e8eaf6;
  --google: #ea4335;
  --google-accent: #4285f4;
  --google-light: #fce8e6;

  /* Scatter brand colors — vivid for matched */
  --dot-apple: #0071e3;
  --dot-samsung: #1428a0;
  --dot-google: #ea4335;
  --dot-dell: #007db8;
  --dot-lenovo: #e2231a;
  --dot-microsoft: #00a4ef;
  --dot-hp: #0096d6;
  --dot-oneplus: #eb0029;
  --dot-xiaomi: #ff6900;
  --dot-nothing: #000000;
  --dot-motorola: #5c2d91;
  --dot-generic: #6b7280;
  --dot-unmatched: #c4bfb3;

  /* Functional */
  --bg: var(--stone-50);
  --surface: #ffffff;
  --surface-raised: #ffffff;
  --border: var(--stone-200);
  --border-subtle: var(--stone-150);
  --text-primary: var(--stone-900);
  --text-secondary: var(--stone-600);
  --text-tertiary: var(--stone-400);
  --focus-ring: rgba(0, 113, 227, 0.4);
  --query-region: rgba(0, 113, 227, 0.06);
  --query-region-stroke: rgba(0, 113, 227, 0.25);

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(34, 32, 25, 0.04);
  --shadow-md: 0 2px 8px rgba(34, 32, 25, 0.06), 0 1px 2px rgba(34, 32, 25, 0.04);
  --shadow-lg: 0 8px 24px rgba(34, 32, 25, 0.08), 0 2px 8px rgba(34, 32, 25, 0.04);
  --shadow-tooltip: 0 8px 32px rgba(34, 32, 25, 0.14), 0 2px 6px rgba(34, 32, 25, 0.06);

  /* Radii */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;

  /* Transitions */
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-in-out: cubic-bezier(0.45, 0, 0.55, 1);
  --duration-fast: 120ms;
  --duration-normal: 200ms;
  --duration-slow: 350ms;

  /* Layout */
  --sidebar-width: 380px;
  --max-width: 1600px;
}

@media (prefers-reduced-motion: reduce) {
  :root {
    --duration-fast: 0ms;
    --duration-normal: 0ms;
    --duration-slow: 0ms;
  }
}

/* ========================================
   RESET & BASE
   ======================================== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  scroll-behavior: smooth;
}

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

::selection {
  background: rgba(0, 113, 227, 0.15);
  color: var(--stone-900);
}

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

/* ========================================
   SHARED HEADER
   ======================================== */
.app-header {
  padding: var(--sp-8) var(--sp-8) var(--sp-6);
  border-bottom: 1px solid var(--border-subtle);
  background: var(--surface);
}

.header-inner {
  display: flex;
  align-items: baseline;
  gap: var(--sp-4);
  flex-wrap: wrap;
}

.app-title {
  font-size: var(--text-2xl);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.1;
  color: var(--stone-900);
}

.app-subtitle {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  font-weight: 400;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

/* ========================================
   PAGE NAVIGATION
   ======================================== */
.page-nav {
  display: flex;
  gap: var(--sp-1);
  margin-left: auto;
}

.page-nav a {
  display: inline-flex;
  align-items: center;
  padding: var(--sp-1) var(--sp-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-secondary);
  text-decoration: none;
  transition: all var(--duration-fast) var(--ease-out);
  white-space: nowrap;
}

.page-nav a:hover {
  border-color: var(--stone-400);
  color: var(--text-primary);
  background: var(--stone-100);
}

.page-nav a.current {
  background: var(--stone-900);
  color: var(--stone-50);
  border-color: var(--stone-900);
  pointer-events: none;
}

/* ========================================
   FORM CONTROLS
   ======================================== */
.control-group {
  margin-bottom: var(--sp-6);
}

.control-group:last-child {
  margin-bottom: 0;
}

.control-label {
  display: block;
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin-bottom: var(--sp-3);
}

.range-inputs {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: var(--sp-2);
  align-items: center;
}

.range-sep {
  font-size: var(--text-sm);
  color: var(--text-tertiary);
  padding: 0 var(--sp-1);
}

input[type="number"] {
  width: 100%;
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  color: var(--text-primary);
  background: var(--surface);
  transition: border-color var(--duration-fast) var(--ease-out),
              box-shadow var(--duration-fast) var(--ease-out);
  -moz-appearance: textfield;
  appearance: textfield;
}

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

input[type="number"]:hover {
  border-color: var(--stone-300);
}

input[type="number"]:focus {
  outline: none;
  border-color: var(--apple-accent);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

input[type="number"]::placeholder {
  color: var(--text-tertiary);
  font-style: italic;
}

.input-suffix {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  margin-top: var(--sp-1);
  text-align: right;
}

.control-hint {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  margin-top: var(--sp-2);
  line-height: 1.4;
}

/* Radio & checkbox groups */
.option-group {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
}

.option-pill {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  cursor: pointer;
  user-select: none;
}

.option-pill input[type="radio"],
.option-pill input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.option-pill .pill-label {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  padding: var(--sp-1) var(--sp-3);
  border: 1px solid var(--border);
  border-radius: 100px;
  font-size: var(--text-sm);
  color: var(--text-secondary);
  background: var(--surface);
  transition: all var(--duration-fast) var(--ease-out);
  white-space: nowrap;
}

.option-pill .pill-label:hover {
  border-color: var(--stone-300);
  color: var(--text-primary);
}

.option-pill input:checked + .pill-label {
  background: var(--stone-900);
  color: var(--stone-50);
  border-color: var(--stone-900);
}

.option-pill input:focus-visible + .pill-label {
  box-shadow: 0 0 0 3px var(--focus-ring);
}

/* Divider */
.control-divider {
  height: 1px;
  background: var(--border-subtle);
  margin: var(--sp-6) 0;
}

/* ========================================
   PRESETS
   ======================================== */
.presets {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
}

.preset-btn {
  display: inline-flex;
  align-items: center;
  padding: var(--sp-1) var(--sp-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-out);
  white-space: nowrap;
  font-family: inherit;
}

.preset-btn:hover {
  border-color: var(--stone-400);
  color: var(--text-primary);
  background: var(--stone-100);
}

.preset-btn:active {
  transform: scale(0.97);
}

.preset-btn.preset-reset {
  border-color: transparent;
  color: var(--text-tertiary);
}
.preset-btn.preset-reset:hover {
  color: var(--google);
  background: var(--google-light);
  border-color: transparent;
}

/* ========================================
   MEDIA QUERY / CODE PREVIEW
   ======================================== */
.query-preview {
  margin-bottom: var(--sp-6);
  padding: var(--sp-4);
  background: var(--stone-900);
  border-radius: var(--radius-md);
  overflow-x: auto;
  position: relative;
}

.query-preview code {
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  font-size: var(--text-sm);
  color: var(--stone-200);
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-all;
}

.query-preview .kw { color: #c792ea; }
.query-preview .fn { color: #82aaff; }
.query-preview .val { color: #c3e88d; }
.query-preview .punc { color: #89ddff; }

.query-preview-label {
  font-size: var(--text-xs);
  color: var(--stone-500);
  margin-bottom: var(--sp-2);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-weight: 600;
}

.query-copy-btn {
  position: absolute;
  top: var(--sp-3);
  right: var(--sp-3);
  padding: var(--sp-1) var(--sp-2);
  border: 1px solid var(--stone-700);
  border-radius: var(--radius-sm);
  background: var(--stone-800);
  color: var(--stone-400);
  font-size: var(--text-xs);
  cursor: pointer;
  font-family: inherit;
  transition: all var(--duration-fast) var(--ease-out);
}

.query-copy-btn:hover {
  background: var(--stone-700);
  color: var(--stone-200);
}

.query-copy-btn.copied {
  color: #c3e88d;
  border-color: #c3e88d44;
}

/* ========================================
   VIEW TOGGLE
   ======================================== */
.view-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.view-toggle-btn {
  padding: var(--sp-2) var(--sp-4);
  border: none;
  background: var(--surface);
  color: var(--text-secondary);
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: all var(--duration-fast) var(--ease-out);
}

.view-toggle-btn + .view-toggle-btn {
  border-left: 1px solid var(--border);
}

.view-toggle-btn:hover {
  background: var(--stone-100);
}

.view-toggle-btn.active {
  background: var(--stone-900);
  color: var(--stone-50);
}

/* ========================================
   SCROLLBAR
   ======================================== */
.scroll-panel::-webkit-scrollbar {
  width: 6px;
}
.scroll-panel::-webkit-scrollbar-track {
  background: transparent;
}
.scroll-panel::-webkit-scrollbar-thumb {
  background: var(--stone-300);
  border-radius: 3px;
}
.scroll-panel::-webkit-scrollbar-thumb:hover {
  background: var(--stone-400);
}

/* Hidden utility */
.hidden { display: none !important; }


.spaced-sm {
   margin-top: var(--sp-4);
   margin-bottom: var(--sp-4);
}
