/* Deliberately minimal — the design premise for this project was
   explicitly "not cluttered/ad-heavy like the competition". */

/* These are the "classic-blue" theme's values, duplicated in
   assets/template.json (id: classic-blue) — that JSON file is the
   editable source of the color SCHEMES (for the theme switcher, see
   assets/js/theme-switcher.js); this :root block is what renders before
   any JS runs (default theme, and the only theme a no-JS visitor sees). */
:root {
  --fg: #1a1a1a;
  --bg: #ffffff;
  --muted: #666666;
  --border: #e0e0e0;
  --accent: #2563eb;
  --accent-soft: #eef2f9;
  --surface: #fafafa;
  --surface-hover: #ececec;
  --error-bg: #fef2f2;
  --error-fg: #991b1b;
  /* Separate from --accent on purpose: some themes (e.g. "Shadows", a
     monochrome dark scheme) use a low-contrast/neutral accent color that
     would make an unreadable button if buttons just inherited it with
     hardcoded white text. Buttons get their own explicit colors instead. */
  --button-bg: #2563eb;
  --button-fg: #ffffff;
  /* Also separate on purpose — see .tool textarea/input rule in this file
     for why textboxes need their own background instead of inheriting
     --bg or --surface. */
  --input-bg: #ffffff;
  /* Separate from --accent: plain content links (e.g. the back-link on
     the Dev Tools hub) previously had no color rule at all and fell back
     to the browser default blue/purple, which is low-contrast and
     unreadable on some dark themes ("Shadows" especially — its neutral
     gray accent isn't distinct enough to double as a link color). */
  --link-fg: #2563eb;
  --link-hover: #1e40af;
  --link-visited: #6d28d9;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--fg);
  background: var(--bg);
  line-height: 1.5;
}

/* Base link colors — deliberately a low-specificity element selector so
   any anchor with a more specific class (site-footer, tool-category,
   portal-category-card, regexbuilder tabs, ...) keeps its own intentional
   color; this only fills in the ones that had no color rule at all. */
a {
  color: var(--link-fg);
}

a:visited {
  color: var(--link-visited);
}

a:hover {
  color: var(--link-hover);
}

.site-header-sticky {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  padding: 1rem 1.5rem;
}

.site-header__nav {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.site-header__logo {
  /* Same height as the 24px SVG, so the logo doesn't grow the sticky
     header row (the skyscraper ad slot assumes ~62px, see .ad-slot--skyscraper). */
  display: flex;
  align-items: center;
  border-radius: 6px;
}

.site-header__logo:hover svg {
  opacity: 0.85;
}

.breadcrumb {
  font-size: 0.8rem;
  color: var(--muted);
}

.breadcrumb__sep {
  margin: 0 0.4rem;
}

.breadcrumb__current {
  color: var(--muted);
}

.site-header__theme {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.site-header__theme label {
  font-size: 0.8rem;
  color: var(--muted);
}

.site-header__theme select {
  font-size: 0.85rem;
  padding: 0.3rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
}

.site-header__theme input[type="range"] {
  width: 100px;
  accent-color: var(--accent);
}

.tool {
  max-width: 640px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

.tool h1 {
  font-size: 1.5rem;
  margin-bottom: 0.5rem;
}

.tool textarea,
.tool input[type="text"],
.tool input[type="number"] {
  width: 100%;
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  font-size: 0.9rem;
  padding: 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  /* Previously unset — fell back to the browser default (white bg, black
     text) regardless of theme, so a dark theme got a glaring white box.
     --input-bg is deliberately its own variable, not reused from
     --surface/--bg, so each theme can tune it independently (e.g. an
     inset-looking dark field vs. the page's own background). */
  background: var(--input-bg);
  color: var(--fg);
}

.tool button {
  margin-top: 0.5rem;
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--button-bg);
  color: var(--button-fg);
  cursor: pointer;
}

.tool button:hover {
  opacity: 0.9;
}

.tool-error {
  margin-top: 0.5rem;
  padding: 0.6rem;
  border-radius: 6px;
  background: var(--error-bg);
  color: var(--error-fg);
  font-size: 0.9rem;
}

.tool-error[hidden] {
  display: none;
}

.tool section {
  margin-top: 2rem;
}

.tool section h2 {
  font-size: 1.1rem;
}

.tool section h3 {
  font-size: 0.95rem;
  margin-top: 1.25rem;
  margin-bottom: 0.4rem;
}

.tool table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.tool table th,
.tool table td {
  text-align: left;
  padding: 0.35rem 0.5rem;
  border-bottom: 1px solid var(--border);
}

.site-footer {
  max-width: 640px;
  margin: 2rem auto 1rem;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
  color: var(--muted);
}

.site-footer a {
  color: var(--muted);
  margin-right: 1rem;
}

.site-footer__privacy {
  margin: 0 0 0.75rem;
  font-weight: 600;
  color: var(--fg);
}

.tool-category {
  margin-top: 2rem;
}

.tool-category h2 {
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 0.5rem;
}

.tool-category ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.tool-category li {
  border-bottom: 1px solid var(--border);
}

.tool-category a {
  display: block;
  padding: 0.6rem 0;
  color: var(--fg);
  text-decoration: none;
  font-size: 0.95rem;
}

.tool-category a:hover {
  color: var(--accent);
}

.portal-categories {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
  margin-top: 2rem;
}

.portal-category-card {
  display: block;
  padding: 1.25rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--fg);
  text-decoration: none;
  transition: background 0.15s ease;
}

a.portal-category-card:hover {
  background: var(--surface-hover);
  border-color: var(--accent);
}

.portal-category-card h2 {
  margin: 0 0 0.4rem;
  font-size: 1.1rem;
}

.portal-category-card p {
  margin: 0;
  font-size: 0.9rem;
  color: var(--muted);
}

.portal-category-card--soon {
  opacity: 0.55;
  cursor: default;
}

.color-input-row {
  display: flex;
  gap: 0.5rem;
  align-items: stretch;
}

.color-input-row #color-input {
  flex: 1;
}

#color-picker {
  flex: 0 0 auto;
  width: 3rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--input-bg);
  cursor: pointer;
}

#color-eyedropper-btn {
  flex: 0 0 auto;
  margin-top: 0; /* see .color-output-row button comment — same stretch fix */
}

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

.color-output-row {
  display: flex;
  gap: 0.5rem;
  align-items: stretch;
}

.color-output-row input {
  flex: 1;
}

.color-output-row button {
  flex: 0 0 auto;
  /* Override .tool button's margin-top: 0.5rem — that's meant for a button
     stacked below an input, but here the button sits beside the input, and
     the margin was throwing off align-items: stretch (pushed the button
     down and shrank it instead of matching the input's height). */
  margin-top: 0;
}

.color-swatch {
  width: 100%;
  height: 3rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  margin: 0.75rem 0;
}

.jwt-claims {
  margin-top: 0.5rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.diff-stats {
  margin: 0.5rem 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.diff-output {
  font-family: monospace;
  font-size: 0.85rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  overflow-x: auto;
  white-space: pre;
}

.diff-line--add {
  background: var(--accent-soft);
  color: var(--fg);
}

.diff-line--remove {
  background: var(--error-bg);
  color: var(--error-fg);
}

/* --- Unit converters (length, weight, temperature, ...) --- */

.unit-converter {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.unit-row {
  display: flex;
  flex: 1;
  gap: 0.5rem;
  align-items: stretch;
}

.unit-row input {
  flex: 1;
  min-width: 0;
}

.unit-row select {
  flex: 0 0 auto;
  max-width: 45%;
  padding: 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--input-bg);
  color: var(--fg);
  font-size: 0.9rem;
}

.unit-swap-btn {
  flex: 0 0 auto;
  margin-top: 0;
  padding: 0.5rem 0.7rem;
  font-size: 1.1rem;
  line-height: 1;
}

@media (max-width: 480px) {
  .unit-converter {
    flex-direction: column;
    align-items: stretch;
  }

  .unit-swap-btn {
    align-self: center;
  }
}

/* Ad slots — placeholder boxes until a real ad network is wired in
   (see includes/ads.php). Skyscrapers (left/right) need room beside the
   640px content column; below that breakpoint there's no space for them,
   so a top banner is shown instead. Exactly one set is visible at a time. */
.ad-slot {
  background: repeating-linear-gradient(45deg, #f3f3f3, #f3f3f3 10px, #e9e9e9 10px, #e9e9e9 20px);
  border: 1px dashed var(--border);
  color: var(--muted);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  align-items: center;
  justify-content: center;
}

.ad-slot--skyscraper {
  position: fixed;
  /* Below the sticky header (~62px — brand link removed, breadcrumb now
     shares the single theme-controls row) plus a small gap. */
  top: 76px;
  width: 160px;
  height: 600px;
  display: none;
}

.ad-slot--left {
  left: 24px;
}

.ad-slot--right {
  right: 24px;
}

.ad-slot--top {
  display: flex;
  max-width: 728px;
  height: 90px;
  margin: 0 auto 1rem;
}

@media (min-width: 1200px) {
  .ad-slot--skyscraper {
    display: flex;
  }

  .ad-slot--top {
    display: none;
  }
}

/* Wide layout override — for tools that need real horizontal space
   (e.g. a reference sidebar next to an editor), set via $wideLayout in
   includes/header.php. */
.tool--wide {
  max-width: 1100px;
}

/* --- RegEx Builder --- */

.regexbuilder {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 1.5rem;
  align-items: start;
}

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

.regexbuilder-reference {
  position: sticky;
  top: 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.regexbuilder-tabs {
  display: flex;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

/* Scoped under .regexbuilder-tabs (not just .regexbuilder-tab-btn) so this
   reliably beats the generic ".tool button" rule's specificity — without
   it, tab buttons inherited the default blue-background/white-text style,
   and .is-active only overrode the text color, producing blue-on-blue. */
.regexbuilder-tabs .regexbuilder-tab-btn {
  flex: 1 1 auto;
  padding: 0.5rem 0.4rem;
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  font-size: 0.75rem;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-top: 0;
}

.regexbuilder-tabs .regexbuilder-tab-btn.is-active {
  background: var(--accent-soft); /* light tint, not the solid accent blue — theme-reactive */
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

.regexbuilder-tab-panel {
  padding: 0.75rem;
  max-height: 70vh;
  overflow-y: auto;
  font-size: 0.82rem;
}

.regexbuilder-tab-panel table {
  font-size: 0.8rem;
  margin-bottom: 0.5rem;
}

.regexbuilder-tab-panel td code,
.regexbuilder-tab-panel th code {
  font-size: 0.78rem;
}

.regexbuilder-field {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
  flex-wrap: wrap;
}

.regexbuilder-field > div {
  flex: 1 1 auto;
}

.regexbuilder-field label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.2rem;
}

#regexbuilder-flags {
  max-width: 6rem;
}

.regexbuilder-suggestion-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0.5rem 0;
}

/* Scoped under .regexbuilder-suggestion-row so this reliably beats the
   generic ".tool button" rule's specificity (same fix as the tab buttons
   above — a bare .regexbuilder-suggestion-btn selector loses to
   ".tool button" and silently falls back to solid blue/white). */
.regexbuilder-suggestion-row .regexbuilder-suggestion-btn {
  margin-top: 0;
  padding: 0.3rem 0.6rem;
  font-size: 0.78rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--fg);
}

.regexbuilder-suggestion-row .regexbuilder-suggestion-btn:hover {
  background: var(--surface-hover);
  opacity: 1;
}

.regexbuilder-pattern-view,
.regexbuilder-highlighted {
  margin-top: 0.5rem;
  padding: 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  font-size: 0.9rem;
  white-space: pre-wrap;
  word-break: break-word;
  min-height: 1.6rem;
}

.regexbuilder-token {
  border-radius: 3px;
}

.regexbuilder-placeholder {
  color: var(--muted);
  font-style: italic;
}

.regexbuilder-selection-panel {
  margin-top: 0.5rem;
  padding: 0.6rem;
  border: 1px dashed var(--accent);
  border-radius: 6px;
  background: var(--accent-soft);
}

.regexbuilder-selection-panel p {
  margin: 0 0 0.4rem;
  font-size: 0.85rem;
}

.regexbuilder-match-count {
  margin: 0.5rem 0 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.regexbuilder-explain-list {
  font-size: 0.85rem;
}

.regexbuilder-explain-list dt {
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  font-weight: 700;
  margin-top: 0.4rem;
}

.regexbuilder-explain-list dd {
  margin: 0.1rem 0 0;
  color: var(--muted);
}

.regexbuilder-snippet-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

/* Scoped under .regexbuilder-snippet-row — same specificity fix as above. */
.regexbuilder-snippet-row .regexbuilder-snippet {
  margin-top: 0;
  padding: 0.35rem 0.7rem;
  font-size: 0.82rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
}

.regexbuilder-snippet-row .regexbuilder-snippet:hover {
  background: var(--surface);
  opacity: 1;
}
