/* =============================================================================
   Nerd Tools section styles
   =============================================================================
   Layered on top of /static/site.css (which carries chrome + the .game-card
   grid we reuse for the tools index). This file only adds what is new: the
   per-tool workbench layout, form controls, output panes, the copy affordance,
   and the toast. Everything uses the shared design tokens.
   ============================================================================= */

/* --- Tool page header / intro ------------------------------------------- */
.tool-head {
  margin-bottom: var(--space-5);
}
.tool-head h1 {
  font-size: clamp(1.8rem, 5vw, 2.6rem);
  line-height: 1.1;
  margin: 0 0 var(--space-2);
  letter-spacing: -0.02em;
}
.tool-head p.lede {
  color: var(--text-secondary);
  max-width: 42rem;
  margin: 0;
}
.tool-back {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: var(--font-size-sm);
  color: var(--text-muted);
  margin-bottom: var(--space-4);
}

/* --- Workbench: a card that holds the controls + output ------------------ */
.tool-panel {
  background: rgba(19, 19, 25, 0.7);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

/* Two-column split for tools with a clear input/output divide. Stacks on
   narrow screens (mobile-first: single column is the default). */
.tool-split {
  display: grid;
  gap: var(--space-4);
  grid-template-columns: 1fr;
}
@media (min-width: 46rem) {
  .tool-split {
    grid-template-columns: 1fr 1fr;
  }
}

/* --- Form controls ------------------------------------------------------- */
.tool-field {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.tool-field > label,
.tool-label {
  font-family: var(--font-mono);
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
}
.tool-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  align-items: center;
}
.tool-row.tight {
  gap: var(--space-2);
}

input[type='text'],
input[type='number'],
input[type='password'],
input[type='search'],
input[type='datetime-local'],
select,
textarea {
  font: inherit;
  color: var(--text-primary);
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-3);
  min-height: var(--hit-target-min);
  width: 100%;
}
textarea {
  font-family: var(--font-mono);
  font-size: var(--font-size-sm);
  line-height: 1.5;
  resize: vertical;
  min-height: 9rem;
}
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  border-color: var(--accent-cyan);
}

/* Range + checkbox/radio groups */
input[type='range'] {
  width: 100%;
  accent-color: var(--accent-cyan);
}
.tool-checks {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-4);
}
.tool-checks label {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
  min-height: var(--hit-target-min);
  cursor: pointer;
}
.tool-checks input {
  width: auto;
  min-height: 0;
  accent-color: var(--accent-cyan);
}

/* Primary action button reuses the brand gradient sparingly. */
.tool-go {
  background: var(--brand-gradient);
  color: #0a0a0f;
  border: none;
  font-weight: 600;
}
.tool-go:hover,
.tool-go:focus-visible {
  filter: brightness(1.08);
}

/* --- Output pane --------------------------------------------------------- */
.tool-output {
  position: relative;
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  font-family: var(--font-mono);
  font-size: var(--font-size-sm);
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  min-height: 3rem;
}
.tool-output.empty {
  color: var(--text-muted);
}
.tool-output ul,
.tool-output ol {
  margin: 0;
  padding-left: 1.2rem;
}

/* Copy button: compact, sits inline with output headers. */
.tool-copy {
  min-height: 0;
  padding: var(--space-1) var(--space-3);
  font-family: var(--font-mono);
  font-size: var(--font-size-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
}
.tool-copy:hover,
.tool-copy:focus-visible {
  color: var(--text-primary);
  border-color: var(--accent-cyan);
}
.tool-output-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

/* A small monospace stat / hint line. */
.tool-hint {
  font-family: var(--font-mono);
  font-size: var(--font-size-xs);
  color: var(--text-muted);
}
.tool-hint.warn {
  color: var(--accent-amber);
}
.tool-hint.error {
  color: var(--accent-red);
}

/* --- Toast (shared via tool-shell.js) ------------------------------------ */
.tool-toast {
  position: fixed;
  left: 50%;
  bottom: var(--space-5);
  transform: translateX(-50%) translateY(1rem);
  background: var(--bg-overlay);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-pill);
  padding: var(--space-2) var(--space-5);
  font-family: var(--font-mono);
  font-size: var(--font-size-sm);
  color: var(--text-primary);
  z-index: var(--z-toast);
  opacity: 0;
  pointer-events: none;
  transition:
    opacity var(--duration-medium) var(--ease-emphasized),
    transform var(--duration-medium) var(--ease-emphasized);
}
.tool-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.tool-toast[data-kind='warn'] {
  border-color: var(--accent-amber);
}

/* --- Diff colors: paired with a +/- glyph so color is never the only cue - */
.diff-add {
  background: rgba(180, 255, 57, 0.12);
  color: var(--accent-lime);
}
.diff-del {
  background: rgba(255, 51, 88, 0.12);
  color: var(--accent-red);
}
.diff-line {
  display: block;
  white-space: pre-wrap;
  word-break: break-word;
}
.diff-line .gutter {
  display: inline-block;
  width: 1.4ch;
  color: var(--text-muted);
  user-select: none;
}

/* --- QR canvas ----------------------------------------------------------- */
.qr-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
}
.qr-stage canvas {
  image-rendering: pixelated;
  background: #fff;
  border-radius: var(--radius-md);
  max-width: 100%;
  height: auto;
}

/* --- Command cheat sheet ------------------------------------------------- */
.cheat-controls {
  position: sticky;
  top: var(--space-2);
  z-index: 1;
}
.cheat-chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: var(--space-3);
}
/* accent mapping mirrors the game-card system; cyan is the default. */
.cheat-chip[data-accent='lime'],
.cheat-section[data-accent='lime'] {
  --accent: var(--accent-lime);
}
.cheat-chip[data-accent='magenta'],
.cheat-section[data-accent='magenta'] {
  --accent: var(--accent-magenta);
}
.cheat-chip[data-accent='amber'],
.cheat-section[data-accent='amber'] {
  --accent: var(--accent-amber);
}
.cheat-chip[data-accent='cyan'],
.cheat-section[data-accent='cyan'] {
  --accent: var(--accent-cyan);
}
.cheat-chip {
  min-height: var(--hit-target-min);
  padding: var(--space-1) var(--space-3);
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-elevated);
  color: var(--text-muted);
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
}
.cheat-chip:hover {
  border-color: var(--accent, var(--accent-cyan));
  color: var(--text-base);
}
/* pressed state: not color alone. bold weight + filled ring + accent border. */
.cheat-chip[aria-pressed='true'] {
  border-color: var(--accent, var(--accent-cyan));
  color: var(--text-base);
  font-weight: 700;
  background: color-mix(in srgb, var(--accent, var(--accent-cyan)) 18%, var(--bg-elevated));
  box-shadow: inset 0 0 0 1px var(--accent, var(--accent-cyan));
}
.cheat-chip:focus-visible {
  outline: 2px solid var(--accent, var(--accent-cyan));
  outline-offset: 2px;
}
.cheat-count {
  margin: var(--space-3) 0 var(--space-2);
  color: var(--text-muted);
  font-size: 0.9rem;
}
.cheat-results {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}
.cheat-section {
  border-left: 3px solid var(--accent, var(--accent-cyan));
  padding-left: var(--space-3);
}
.cheat-section-title {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin: 0 0 var(--space-3);
  font-size: 1.05rem;
  color: var(--accent, var(--accent-cyan));
}
.cheat-tally {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0 var(--space-2);
}
.cheat-rows {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.cheat-row {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: 'cmd copy' 'desc copy';
  gap: var(--space-1) var(--space-3);
  align-items: center;
  padding: var(--space-2) var(--space-3);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
.cheat-cmd {
  grid-area: cmd;
  font-family: var(--font-mono);
  font-size: 0.9rem;
  color: var(--text-base);
  white-space: pre-wrap;
  word-break: break-word;
}
.cheat-desc {
  grid-area: desc;
  color: var(--text-muted);
  font-size: 0.9rem;
}
.cheat-row .tool-copy {
  grid-area: copy;
}
@media (min-width: 46rem) {
  .cheat-row {
    grid-template-columns: minmax(14rem, 22rem) 1fr auto;
    grid-template-areas: 'cmd desc copy';
    align-items: baseline;
  }
  .cheat-row .tool-copy {
    align-self: center;
  }
}
