/* ============================================================================
   Regex Cookbook & Tester — tool layer.

   base.css is loaded immediately before this file and owns everything
   structural: reset, body, links, focus rings, headings, forms, .panel,
   .btn, .chip, tables, details, header, footer, .wrap, .badge, .stat.

   This file sets the tool's accent and styles only what is specific to a
   regex workbench: the pattern row, the flag chips, the highlighted match
   view, the match/explain/replace tabs, and the pattern-library cards.

   Accent — fuchsia. Measured against the shared palette (base.css):
     dark   #e879f9 on --bg      7.69:1    on --surface     7.09:1
            #e879f9 on --bg-sunk 7.95:1    on --accent-dim  5.68:1
     light  #a21caf on --surface 6.32:1    on --bg          6.06:1
            #a21caf on --accent-dim        5.36:1
   All eight clear 4.5:1, so the accent is safe for body-sized text, not
   just large/bold text, in both themes.
   ========================================================================= */

:root {
  --accent:     #e879f9;
  --accent-dim: rgba(232, 121, 249, 0.14);
}

@media (prefers-color-scheme: light) {
  :root {
    --accent:     #a21caf;
    --accent-dim: rgba(162, 28, 175, 0.10);
  }
}

/* --------------------------------------------------------------- utility -- */

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

[hidden] { display: none !important; }

/* base.css only styles lists inside .prose; these pages use bare <ul>/<ol> */
main ul, main ol { padding-left: 1.25em; margin: 0 0 1.1em; }
main li { margin-bottom: 0.4em; }

/* -------------------------------------------------------- the instrument -- */
/* .tool carries .panel */

.tool { margin-bottom: 2rem; }

.tool-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.4rem 1rem;
  margin-bottom: 0.4rem;
}

/* ------------------------------------------------------------ pattern row -- */

.pattern-row {
  display: flex;
  align-items: center;
  gap: 0.15rem;
  background: var(--bg-sunk);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 0.15rem 0.6rem;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
.pattern-row:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
.pattern-row.is-invalid { border-color: var(--err); }

.pattern-delim {
  font-family: var(--mono);
  font-size: 1.05rem;
  color: var(--text-faint);
  user-select: none;
  flex: 0 0 auto;
}

input.pattern-input {
  flex: 1 1 auto;
  min-width: 4rem;
  width: auto;
  background: transparent;
  border: 0;
  padding: 0.55rem 0.2rem;
  font-family: var(--mono);
  font-size: 0.9375rem;
}
input.pattern-input:focus-visible { outline: none; box-shadow: none; }

.pattern-flags-display {
  font-family: var(--mono);
  font-size: 0.9375rem;
  color: var(--accent);
  flex: 0 0 auto;
  min-width: 1.2em;
}

.flag-chips { margin-top: 0.6rem; }
.flag-chips .chip { font-weight: 700; min-width: 1.9rem; text-align: center; }

/* ------------------------------------------------------------ diagnostics -- */

.warn-panel {
  margin-top: 1rem;
  padding: 0.8rem 1rem;
  border: 1px solid var(--warn);
  border-radius: var(--radius-sm);
  background: var(--warn-bg);
  font-size: 0.9375rem;
  color: var(--text);
}
.warn-panel p { margin: 0 0 0.6rem; }
.warn-panel p:last-child { margin-bottom: 0; }

.timeout-panel {
  margin-top: 1rem;
  padding: 0.8rem 1rem;
  border: 1px solid var(--err);
  border-radius: var(--radius-sm);
  background: var(--err-bg);
  font-size: 0.9375rem;
}

/* ------------------------------------------------------------- controls -- */

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem 1.2rem;
  margin-top: 0.9rem;
}
.control-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
}
.control-group > .field-label { margin-right: 0.15rem; }
.actions { margin-left: auto; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; filter: none; }

.copy-status {
  font-family: var(--mono);
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ok);
  min-width: 4.5rem;
}
.copy-status.is-err { color: var(--err); }

/* ------------------------------------------------------------- verdict --- */

.verdict {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem 1rem;
  margin-top: 1.1rem;
}
.status-note {
  margin: 0;
  font-size: 0.9375rem;
  color: var(--text-dim);
  max-width: 62ch;
}

/* ----------------------------------------------------------------- tabs -- */

.tabs {
  display: inline-flex;
  gap: 0.2rem;
  margin: 1.2rem 0 1rem;
  padding: 0.2rem;
  background: var(--bg-sunk);
  border: 1px solid var(--line);
  border-radius: 999px;
}
.tab {
  font-family: var(--mono);
  font-size: 0.78125rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text-dim);
  background: none;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 0.35rem 0.85rem;
  white-space: nowrap;
  cursor: pointer;
  transition: color 0.12s ease, background-color 0.12s ease;
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-dim);
}

/* -------------------------------------------------------- highlight view -- */

.highlight-view {
  margin: 0 0 1rem;
  max-height: 22rem;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 0.8125rem;
  line-height: 1.6;
}
.highlight-view mark {
  background: var(--accent-dim);
  color: var(--text);
  border-radius: 2px;
  box-shadow: 0 0 0 1px var(--accent);
  padding: 0 0.05em;
}
.highlight-view mark.is-current { background: var(--accent); color: var(--on-accent); }
/* a zero-length match (e.g. \b) has nothing to shade, so mark it with a
   thin caret instead of an invisible empty <mark> */
.highlight-view mark:empty {
  display: inline-block;
  width: 0;
  border-left: 2px solid var(--accent);
  margin-left: -1px;
}

/* ---------------------------------------------------------- match list --- */

.match-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 22rem;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.match-list li { margin: 0; border-bottom: 1px solid var(--line); padding: 0.6rem 0.8rem; }
.match-list li:last-child { border-bottom: 0; }

.match-head {
  display: flex;
  flex-wrap: wrap;
  gap: 0.2rem 0.9rem;
  align-items: baseline;
  font-family: var(--mono);
  font-size: 0.8125rem;
}
.match-head .match-num { color: var(--text-faint); }
.match-head .match-text { color: var(--accent); overflow-wrap: anywhere; }
.match-head .match-pos { color: var(--text-dim); margin-left: auto; }

.group-list {
  list-style: none;
  margin: 0.4rem 0 0;
  padding: 0 0 0 0.9rem;
  border-left: 2px solid var(--line);
  font-family: var(--mono);
  font-size: 0.78125rem;
  color: var(--text-dim);
}
.group-list li { margin-bottom: 0.15rem; }
.group-list .group-label { color: var(--text-faint); }
.group-list .group-val { color: var(--text); overflow-wrap: anywhere; }
.group-list .group-null { color: var(--text-faint); font-style: italic; }

/* -------------------------------------------------------------- explain -- */

.explain-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  overflow: hidden;
}
.explain-list li {
  display: flex;
  flex-wrap: wrap;
  gap: 0.2rem 1rem;
  padding: 0.55rem 0.8rem;
  border-bottom: 1px solid var(--line);
}
.explain-list li:last-child { border-bottom: 0; }
.explain-token {
  font-family: var(--mono);
  font-size: 0.8125rem;
  color: var(--accent);
  flex: 0 0 auto;
  min-width: 3.5rem;
  overflow-wrap: anywhere;
}
.explain-desc { color: var(--text-dim); font-size: 0.9375rem; flex: 1 1 14rem; }

/* -------------------------------------------------------------- replace -- */

.sub-output {
  margin: 0;
  min-height: 6rem;
  max-height: 20rem;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 0.8125rem;
}

/* -------------------------------------------------------- privacy callout -- */

.callout {
  margin: 1.4em 0;
  padding: 0.9rem 1.1rem;
  border-left: 2px solid var(--accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: var(--accent-dim);
  font-size: 0.9375rem;
  color: var(--text-dim);
}
.callout > :last-child { margin-bottom: 0; }
.callout strong { color: var(--text); }

/* -------------------------------------------------------- content layer --- */

.content p, .content ul, .content ol { max-width: 68ch; }
.content .card-links, .content .library-grid { max-width: none; }
.content h2:first-child { margin-top: 0; }

.example { margin-bottom: 1rem; }
.example h3 { margin-top: 0; }
.example > :last-child { margin-bottom: 0; }
.example pre { background: var(--surface); }

details .answer > :last-child { margin-bottom: 0; }

.sources { font-size: 0.9375rem; }
.sources li { margin-bottom: 0.6em; }
.source-note { color: var(--text-dim); }

/* ------------------------------------------------------------ card links -- */

.card-links {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(14rem, 100%), 1fr));
  gap: 0.75rem;
  list-style: none;
  margin: 0 0 1.5rem;
  padding: 0;
}
.card-links li { margin: 0; }
.card-links a {
  display: block;
  height: 100%;
  padding: 0.7rem 0.9rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  text-decoration: none;
  transition: border-color 0.12s ease, background-color 0.12s ease;
}
.card-links a:hover { border-color: var(--accent); background: var(--surface-2); }
.card-links strong { display: block; font-size: 0.9375rem; }
.card-links span { display: block; margin-top: 0.1rem; font-size: 0.8125rem; color: var(--text-dim); }
.card-links a:hover span { color: var(--accent); }

/* --------------------------------------------------------- cheatsheet --- */

.cheat-table code { white-space: nowrap; }

/* ------------------------------------------------------------ library --- */

.library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(19rem, 100%), 1fr));
  gap: 1rem;
  margin: 1.5rem 0 2rem;
}

.lib-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.lib-card h3 { margin: 0; font-size: 1rem; }

.lib-flavor {
  font-family: var(--mono);
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.lib-pattern {
  margin: 0;
  padding: 0.55rem 0.7rem;
  font-size: 0.8125rem;
  overflow-x: auto;
  white-space: pre;
  background: var(--bg-sunk);
}

.lib-desc { margin: 0; font-size: 0.875rem; color: var(--text-dim); }

.lib-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: auto; }

@media (max-width: 30rem) {
  .actions { margin-left: 0; }
  .match-head .match-pos { margin-left: 0; }
}
