/* ──────────────────────────────────────────────────────────────────────────
   Crimson Desert Dye Recipe Table — Stylesheet
   Theme: dark game UI with crimson accent
   Fonts: Cabinet Grotesk (display), Satoshi (body)
────────────────────────────────────────────────────────────────────────── */

/* ── Design Tokens ── */
:root {
  --text-xs:   clamp(0.75rem,  0.7rem  + 0.25vw, 0.875rem);
  --text-sm:   clamp(0.875rem, 0.8rem  + 0.35vw, 1rem);
  --text-base: clamp(1rem,     0.95rem + 0.25vw, 1.125rem);
  --text-lg:   clamp(1.125rem, 1rem    + 0.75vw, 1.5rem);
  --text-xl:   clamp(1.5rem,   1.2rem  + 1.25vw, 2.25rem);
  --text-2xl:  clamp(2rem,     1.2rem  + 2.5vw,  3.5rem);

  --space-1: 0.25rem; --space-2: 0.5rem;  --space-3: 0.75rem;
  --space-4: 1rem;    --space-5: 1.25rem; --space-6: 1.5rem;
  --space-8: 2rem;    --space-10: 2.5rem; --space-12: 3rem;
  --space-16: 4rem;   --space-20: 5rem;

  --radius-sm: 0.25rem; --radius-md: 0.5rem;
  --radius-lg: 0.75rem; --radius-full: 9999px;

  --transition: 160ms cubic-bezier(0.16, 1, 0.3, 1);

  --content-wide: 1360px;
  --font-display: 'Cabinet Grotesk', 'Helvetica Neue', sans-serif;
  --font-body:    'Satoshi', 'Inter', sans-serif;
}

/* ── Light Mode ── */
:root, [data-theme="light"] {
  --bg:         #f5f4f0;
  --surface:    #faf9f7;
  --surface-2:  #ffffff;
  --surface-off:#edeae4;
  --border:     #d8d5ce;
  --divider:    #e5e2db;

  --text:       #1e1c18;
  --text-muted: #6b6963;
  --text-faint: #b0aea9;

  --accent:        #b91c1c;
  --accent-hover:  #991b1b;
  --accent-light:  rgba(185, 28, 28, 0.1);

  --tab-active-bg: #b91c1c;
  --tab-active-text: #ffffff;

  --row-hover: rgba(0,0,0,0.025);
  --group-border: rgba(0,0,0,0.08);

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.07);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.09);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.12);
}

/* ── Dark Mode ── */
[data-theme="dark"] {
  --bg:         #111010;
  --surface:    #191817;
  --surface-2:  #1e1d1b;
  --surface-off:#242220;
  --border:     #2e2c2a;
  --divider:    #252422;

  --text:       #e0dedd;
  --text-muted: #888580;
  --text-faint: #545250;

  --accent:        #ef4444;
  --accent-hover:  #dc2626;
  --accent-light:  rgba(239, 68, 68, 0.12);

  --tab-active-bg: #b91c1c;
  --tab-active-text: #ffffff;

  --row-hover: rgba(255,255,255,0.03);
  --group-border: rgba(255,255,255,0.05);

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.4);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.5);
}

/* ── System dark pref fallback ── */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #111010; --surface: #191817; --surface-2: #1e1d1b;
    --surface-off:#242220; --border: #2e2c2a; --divider: #252422;
    --text: #e0dedd; --text-muted: #888580; --text-faint: #545250;
    --accent: #ef4444; --accent-hover: #dc2626; --accent-light: rgba(239,68,68,0.12);
    --tab-active-bg: #b91c1c; --tab-active-text: #ffffff;
    --row-hover: rgba(255,255,255,0.03); --group-border: rgba(255,255,255,0.05);
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.3); --shadow-md: 0 4px 16px rgba(0,0,0,0.4);
    --shadow-lg: 0 12px 40px rgba(0,0,0,0.5);
  }
}

/* ── Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; -webkit-font-smoothing: antialiased; }
body {
  min-height: 100dvh;
  font-family: var(--font-body);
  font-size: var(--text-base);
  color: var(--text);
  background: var(--bg);
  line-height: 1.55;
}
img { display: block; max-width: 100%; }
button { cursor: pointer; background: none; border: none; font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
a:hover { color: var(--accent-hover); }
table { border-collapse: collapse; width: 100%; }

/* ── Site Header ── */
.site-header {
  position: sticky; top: 0; z-index: 100;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.header-inner {
  max-width: var(--content-wide);
  margin: 0 auto;
  padding: var(--space-3) var(--space-6);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
}
.logo-group {
  display: flex; align-items: center; gap: var(--space-3);
}
.logo-icon { flex-shrink: 0; }
.logo-title {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 800;
  color: var(--text);
  line-height: 1.1;
  letter-spacing: -0.01em;
}
.logo-sub {
  font-size: var(--text-xs);
  color: var(--accent);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.header-actions { display: flex; align-items: center; gap: var(--space-2); }
.theme-toggle {
  display: flex; align-items: center; justify-content: center;
  width: 36px; height: 36px;
  border-radius: var(--radius-md);
  color: var(--text-muted);
  border: 1px solid var(--border);
  transition: color var(--transition), background var(--transition), border-color var(--transition);
}
.theme-toggle:hover {
  color: var(--text);
  background: var(--surface-off);
  border-color: var(--border);
}

/* ── Hero ── */
.hero {
  background: linear-gradient(135deg, var(--surface) 0%, var(--surface-off) 100%);
  border-bottom: 1px solid var(--border);
  padding: var(--space-10) var(--space-6);
}
.hero-inner {
  max-width: var(--content-wide);
  margin: 0 auto;
}
.hero h1 {
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  font-weight: 800;
  letter-spacing: -0.025em;
  line-height: 1.05;
  color: var(--text);
  margin-bottom: var(--space-3);
}
.hero-sub {
  font-size: var(--text-base);
  color: var(--text-muted);
  max-width: 52ch;
  line-height: 1.6;
  margin-bottom: var(--space-8);
}
.stat-bar {
  display: flex;
  align-items: center;
  gap: var(--space-6);
  flex-wrap: wrap;
}
.stat { display: flex; flex-direction: column; gap: 2px; }
.stat-num {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 800;
  color: var(--accent);
  line-height: 1;
}
.stat-label {
  font-size: var(--text-xs);
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.stat-sep {
  width: 1px;
  height: 40px;
  background: var(--border);
  flex-shrink: 0;
}

/* ── Controls ── */
.controls-section {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: var(--space-4) var(--space-6);
  position: sticky;
  top: 57px;
  z-index: 90;
  box-shadow: var(--shadow-sm);
}
.controls-inner {
  max-width: var(--content-wide);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

/* Search */
.search-wrap {
  position: relative;
  display: flex;
  align-items: center;
  max-width: 480px;
}
.search-icon {
  position: absolute;
  left: var(--space-3);
  color: var(--text-faint);
  pointer-events: none;
  flex-shrink: 0;
}
.search-input {
  width: 100%;
  padding: var(--space-2) var(--space-3) var(--space-2) calc(var(--space-3) + 24px);
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-family: var(--font-body);
  color: var(--text);
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}
.search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}
.search-input::placeholder { color: var(--text-faint); }
.search-clear {
  position: absolute; right: var(--space-3);
  color: var(--text-faint);
  display: flex; align-items: center; justify-content: center;
  transition: color var(--transition);
}
.search-clear:hover { color: var(--text); }

/* Filter tabs */
.filter-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
}
.tab {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 600;
  font-family: var(--font-body);
  border: 1.5px solid var(--border);
  color: var(--text-muted);
  background: var(--surface-2);
  cursor: pointer;
  transition: color var(--transition), background var(--transition), border-color var(--transition);
  white-space: nowrap;
}
.tab:hover { color: var(--text); border-color: var(--text-faint); }
.tab.active {
  background: var(--tab-active-bg);
  border-color: var(--tab-active-bg);
  color: var(--tab-active-text);
}
.dot {
  width: 8px; height: 8px;
  border-radius: var(--radius-full);
  flex-shrink: 0;
  display: inline-block;
}

/* Results count */
.results-count {
  font-size: var(--text-xs);
  color: var(--text-faint);
  font-weight: 500;
}

/* ── Table Section ── */
.table-section {
  max-width: var(--content-wide);
  margin: var(--space-6) auto;
  padding: 0 var(--space-6) var(--space-16);
}
.table-outer {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-md);
  overflow-x: auto;
}

/* ── Table ── */
#dyeTable {
  font-size: var(--text-sm);
  min-width: 900px;
}

thead {
  background: var(--surface-off);
  border-bottom: 2px solid var(--border);
}
thead th {
  padding: var(--space-3) var(--space-4);
  text-align: left;
  font-size: var(--text-xs);
  font-weight: 700;
  font-family: var(--font-display);
  color: var(--text-muted);
  letter-spacing: 0.07em;
  text-transform: uppercase;
  white-space: nowrap;
  user-select: none;
}

/* Column widths */
.col-family { width: 100px; }
.col-name   { width: 200px; }
.col-shade  { width: 90px; }
.col-herb   { width: 160px; }
.col-qty    { width: 52px; text-align: center; }
.col-bug    { width: 160px; }
.col-notes  { width: auto; min-width: 140px; }

tbody tr {
  border-bottom: 1px solid var(--divider);
  transition: background var(--transition);
}
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--row-hover); }

tbody td {
  padding: var(--space-3) var(--space-4);
  vertical-align: middle;
  color: var(--text);
}

/* Family cell */
.family-cell {
  vertical-align: middle;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  border-right: 2px solid var(--group-border);
  white-space: nowrap;
}
.family-swatch {
  display: inline-block;
  width: 9px; height: 9px;
  border-radius: var(--radius-full);
  margin-right: var(--space-2);
  vertical-align: middle;
  flex-shrink: 0;
}

/* Group separators */
tr.group-start td { border-top: 2px solid var(--group-border); }
tr.group-start:first-child td { border-top: none; }

/* Dye name */
.col-name { font-weight: 600; color: var(--text); }

/* Shade badges */
.shade-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px var(--space-2);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
}
.shade-bright   { background: rgba(250,220,100,0.15); color: #d4ac0d; border: 1px solid rgba(212,172,13,0.3); }
.shade-rich     { background: rgba(100,200,120,0.12); color: #27ae60; border: 1px solid rgba(39,174,96,0.3); }
.shade-standard { background: rgba(150,150,150,0.12); color: var(--text-muted); border: 1px solid var(--border); }
.shade-dark     { background: rgba(80,50,150,0.15);   color: #9b59b6; border: 1px solid rgba(155,89,182,0.3); }
.shade-deep     { background: rgba(30,30,30,0.3);     color: var(--text-faint); border: 1px solid var(--border); }

/* Qty */
.qty {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 26px; height: 22px;
  border-radius: var(--radius-sm);
  background: var(--surface-off);
  border: 1px solid var(--border);
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--text);
  font-family: var(--font-display);
}
.qty.muted { color: var(--text-faint); background: transparent; border-color: transparent; }

/* Extra ingredient */
.extra-ing {
  display: inline-block;
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-light);
  border: 1px solid rgba(239,68,68,0.2);
  border-radius: var(--radius-sm);
  padding: 1px var(--space-2);
  margin-bottom: var(--space-1);
  white-space: nowrap;
}

/* Notes */
.col-notes { font-size: var(--text-xs); }
.note-text {
  color: var(--text-faint);
  display: block;
  line-height: 1.4;
}

/* ── Empty State ── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  padding: var(--space-20);
  color: var(--text-faint);
  text-align: center;
}
.empty-state p { font-size: var(--text-base); }

/* ── Footer ── */
.site-footer {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: var(--space-8) var(--space-6);
}
.footer-inner {
  max-width: var(--content-wide);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.site-footer p { font-size: var(--text-xs); color: var(--text-muted); max-width: none; }
.footer-note { color: var(--text-faint); }

/* ── Responsive ── */
@media (max-width: 768px) {
  .controls-section { top: 52px; }
  .hero { padding: var(--space-8) var(--space-4); }
  .controls-inner, .header-inner, .footer-inner { padding-left: 0; padding-right: 0; }
  .controls-section { padding: var(--space-3) var(--space-4); }
  .table-section { padding: 0 var(--space-4) var(--space-12); margin-top: var(--space-4); }
  .stat-bar { gap: var(--space-4); }
  .stat-sep { display: none; }
}

@media (max-width: 480px) {
  .hero h1 { font-size: var(--text-xl); }
  .filter-tabs { gap: 4px; }
  .tab { padding: var(--space-1) var(--space-2); font-size: 0.7rem; }
}

/* ── Focus visible ── */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ── Scrollbar (dark mode) ── */
[data-theme="dark"] {
  scrollbar-color: var(--surface-off) var(--bg);
  scrollbar-width: thin;
}
[data-theme="dark"] ::-webkit-scrollbar { width: 8px; height: 8px; }
[data-theme="dark"] ::-webkit-scrollbar-track { background: var(--bg); }
[data-theme="dark"] ::-webkit-scrollbar-thumb { background: var(--surface-off); border-radius: 4px; }
