:root {
  --bg: #121518;
  --surface: #1b2026;
  --surface-2: #232a32;
  --border: #2f3843;
  --text: #eef2f6;
  --text-muted: #9aa7b8;
  --accent: #4ec95b;
  --accent-dim: rgba(78, 201, 91, 0.14);
  --accent-2: #58a6ff;
  --kbd-bg: #2a323c;
  --kbd-border: #434f5e;
  --shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
  --radius: 10px;
}

[data-theme="light"] {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef2f5;
  --border: #dce2e8;
  --text: #1b222c;
  --text-muted: #5a6675;
  --accent: #229635;
  --accent-dim: rgba(34, 150, 53, 0.11);
  --accent-2: #0969da;
  --kbd-bg: #f3f5f7;
  --kbd-border: #c9d1d9;
  --shadow: 0 4px 14px rgba(15, 23, 42, 0.06);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Header & Navigation */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.topbar-inner {
  max-width: 1240px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 220px;
}

.brand-logo {
  width: 38px;
  height: 38px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), #2e8b57);
  color: #fff;
  font-weight: 800;
  font-size: 16px;
  display: grid;
  place-items: center;
  letter-spacing: -0.5px;
  flex-shrink: 0;
}

.brand h1 {
  margin: 0;
  font-size: 17px;
  line-height: 1.2;
}

.subtitle {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--text-muted);
}

.search-wrap {
  flex: 1;
  min-width: 240px;
  position: relative;
}

.search-wrap input {
  width: 100%;
  padding: 9px 34px 9px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}

.search-wrap input:focus {
  border-color: var(--accent);
}

.clear-btn {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  padding: 2px 6px;
}

.controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-pill,
.btn-icon,
.pill,
.tab {
  font-family: inherit;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 8px;
  transition: all 0.15s;
}

.btn-pill {
  padding: 7px 12px;
  font-size: 13px;
}

.btn-icon {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  font-size: 15px;
}

.btn-pill:hover,
.btn-icon:hover {
  border-color: var(--accent);
}

.btn-link {
  background: none;
  border: none;
  color: var(--accent-2);
  font-size: 13px;
  cursor: pointer;
  padding: 4px 6px;
}

.btn-link:hover {
  text-decoration: underline;
}

.tabs {
  max-width: 1240px;
  margin: 0 auto;
  padding: 0 20px 10px;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: thin;
}

.tab {
  padding: 6px 12px;
  font-size: 13px;
  white-space: nowrap;
  background: transparent;
}

.tab.active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

/* Main Container */
.container {
  max-width: 1240px;
  margin: 0 auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.section-block[hidden],
.favorites-card[hidden],
.empty-state[hidden] {
  display: none;
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}

.section-head h2 {
  margin: 0;
  font-size: 19px;
}

.hint {
  font-size: 13px;
  color: var(--text-muted);
}

.filter-pills {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.pill {
  padding: 4px 10px;
  font-size: 12px;
  border-radius: 999px;
}

.pill.active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

/* Cards & Grids */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.favorites-card {
  border-color: var(--accent);
  background: linear-gradient(180deg, var(--accent-dim), var(--surface) 40%);
}

.hotkey-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 10px;
}

.hotkey-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 10px 12px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  transition: border-color 0.15s;
}

.hotkey-item:hover {
  border-color: var(--accent);
}

.hotkey-info {
  min-width: 0;
}

.hotkey-title {
  font-weight: 600;
  font-size: 14px;
}

.hotkey-desc {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.hotkey-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.fav-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 15px;
  padding: 2px;
  line-height: 1;
}

.fav-btn.active {
  color: #f5b942;
}

/* Keycaps */
kbd {
  display: inline-block;
  padding: 2px 7px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  background: var(--kbd-bg);
  border: 1px solid var(--kbd-border);
  border-bottom-width: 2px;
  border-radius: 5px;
  white-space: nowrap;
}

/* Align visual */
.align-layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 16px;
  align-items: start;
}

.align-visual {
  display: flex;
  justify-content: center;
  padding: 12px;
}

.align-svg {
  width: 100%;
  max-width: 280px;
}

.svg-frame {
  fill: var(--surface-2);
  stroke: var(--border);
  stroke-width: 1.5;
}

.svg-guide {
  stroke: var(--border);
  stroke-dasharray: 4 3;
}

.svg-target {
  fill: var(--accent-dim);
  stroke: var(--accent);
  stroke-width: 2;
}

.svg-label-main {
  fill: var(--text);
  font-size: 12px;
  font-weight: 700;
}

.svg-kbd {
  fill: var(--accent);
  font-size: 14px;
  font-weight: 800;
}

.svg-sub {
  fill: var(--text-muted);
  font-size: 10px;
}

/* Tools & Recipes cards */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  gap: 12px;
}

.info-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.info-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.info-card h3 {
  margin: 0;
  font-size: 15px;
}

.info-card p,
.info-card li {
  margin: 0;
  font-size: 13px;
  color: var(--text-muted);
}

.info-card ul,
.info-card ol {
  margin: 0;
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.tag {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 5px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

/* Shaping SVG grid */
.shaping-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.shape-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  text-align: center;
}

.shape-card svg {
  width: 96px;
  height: 60px;
  margin-bottom: 6px;
}

.shape-card h3 {
  margin: 0 0 4px;
  font-size: 14px;
}

.shape-card p {
  margin: 0;
  font-size: 12px;
  color: var(--text-muted);
}

/* Nodes */
.nodes-card h3 {
  margin: 0 0 12px;
  font-size: 15px;
}

.nodes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px;
}

.node-item {
  display: flex;
  align-items: center;
  gap: 12px;
}

.node-item strong {
  display: block;
  font-size: 13px;
}

.node-item p {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--text-muted);
}

.node-svg {
  width: 76px;
  height: 48px;
  flex-shrink: 0;
  color: var(--accent-2);
}

.node-dot {
  fill: var(--accent);
}

.node-handle {
  stroke: var(--text-muted);
  stroke-width: 1.5;
  stroke-dasharray: 2 2;
}

/* Prepress checklist */
.checklist {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 10px;
}

.check-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--surface-2);
  cursor: pointer;
}

.check-item input {
  margin-top: 3px;
  accent-color: var(--accent);
  width: 16px;
  height: 16px;
  cursor: pointer;
}

.check-item.checked span {
  text-decoration: line-through;
  color: var(--text-muted);
}

.check-title {
  display: block;
  font-size: 13px;
  font-weight: 600;
}

.check-desc {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
}

/* Formats Grid & Laser Checklist */
.laser-checklist {
  margin-top: 12px;
}

.formats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(185px, 1fr));
  gap: 10px;
}

.format-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.format-name {
  font-weight: 700;
  font-size: 14px;
}

.format-size {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  color: var(--accent);
  font-weight: 600;
}

.format-note {
  font-size: 12px;
  color: var(--text-muted);
}

.empty-state {
  text-align: center;
  padding: 40px 20px;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.footer {
  text-align: center;
  padding: 20px;
  font-size: 12px;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  margin-top: 20px;
}

@media (max-width: 820px) {
  .align-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .topbar {
    position: static;
  }

  .topbar-inner {
    padding: 10px 12px;
    gap: 10px;
  }

  .brand {
    min-width: 0;
    flex: 1;
  }

  .brand-logo {
    width: 34px;
    height: 34px;
    font-size: 14px;
  }

  .brand h1 {
    font-size: 15px;
  }

  .subtitle {
    display: none;
  }

  .controls {
    gap: 6px;
  }

  .btn-pill {
    padding: 6px 10px;
    font-size: 12px;
  }

  .btn-icon {
    width: 36px;
    height: 36px;
  }

  .search-wrap {
    order: 3;
    flex: 1 0 100%;
    min-width: 0;
  }

  /* 16px prevents iOS Safari auto-zoom on input focus */
  .search-wrap input {
    font-size: 16px;
    padding: 10px 36px 10px 12px;
  }

  .tabs {
    padding: 0 12px 10px;
    gap: 6px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .tabs::-webkit-scrollbar {
    display: none;
  }

  .tab {
    padding: 8px 12px;
    font-size: 13px;
  }

  .container {
    padding: 14px 12px;
    gap: 20px;
  }

  .section-head h2 {
    font-size: 17px;
  }

  .hotkey-grid,
  .cards-grid,
  .checklist {
    grid-template-columns: 1fr;
  }

  .shaping-grid,
  .formats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .hotkey-item {
    padding: 10px;
    flex-wrap: wrap;
  }

  .hotkey-right {
    margin-left: auto;
  }

  .fav-btn {
    min-width: 32px;
    min-height: 32px;
    display: grid;
    place-items: center;
    font-size: 17px;
  }

  .check-item {
    padding: 10px;
  }

  .check-item input {
    width: 20px;
    height: 20px;
  }

  .info-card {
    padding: 12px;
  }

  .card {
    padding: 12px;
  }
}

@media (max-width: 380px) {
  .shaping-grid,
  .formats-grid {
    grid-template-columns: 1fr;
  }
}

/* Print stylesheet */
@media print {
  :root {
    --bg: #ffffff;
    --surface: #ffffff;
    --surface-2: #f8f9fa;
    --border: #d0d7de;
    --text: #000000;
    --text-muted: #444444;
    --kbd-bg: #f1f3f5;
    --kbd-border: #999999;
  }
  .topbar,
  .filter-pills,
  .fav-btn,
  .footer,
  #clearFavorites,
  #resetChecklist {
    display: none !important;
  }
  .container {
    padding: 0;
    gap: 14px;
  }
  .section-block {
    break-inside: avoid;
  }
}
