/* ============================================
   THE GRIND GUIDE — Tools
   Shared styling for every page under /tools/.

   Built entirely on the tokens already declared in
   style.css, so light/dark mode needs no extra rules.
   ============================================ */

/* ── Tool-specific tokens ── */
:root {
  --color-tools: #7c3aed;
  --color-tools-hover: #6d28d9;
  --color-tools-light: rgba(124, 58, 237, 0.1);
  --color-word: #7c3aed;
  --color-word-light: rgba(124, 58, 237, 0.1);
  --color-run: #ea580c;
  --color-run-light: rgba(234, 88, 12, 0.1);
}

/* ============================================
   LAYOUT
   ============================================ */

/* The homepage mixes full-width blog sections with the boxed tool
   layout, so its <main> stays unconstrained and each block sets
   its own width. */
.home-main {
  display: block;
}

.tool-page {
  /* width:100% + a px cap: body is a column flex container, so without the
     explicit width a wide table stretches this past the viewport. Unlike a
     min() cap this keeps the page filling the screen. */
  width: 100%;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: var(--space-8) var(--space-6) var(--space-16);
}

.tool-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-8);
}

/* ── Breadcrumbs ── */
.tool-breadcrumb {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-5);
  font-size: var(--text-sm);
  color: var(--text-tertiary);
}

.tool-breadcrumb a {
  color: var(--text-secondary);
  text-decoration: none;
}

.tool-breadcrumb a:hover {
  color: var(--color-primary);
  text-decoration: underline;
}

.tool-breadcrumb__sep {
  opacity: 0.5;
}

/* ============================================
   TOOL HERO
   ============================================ */
.tool-hero {
  margin-bottom: var(--space-8);
}

.tool-hero__badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-3);
  margin-bottom: var(--space-4);
  border-radius: 999px;
  background: var(--color-tools-light);
  color: var(--color-tools);
  font-family: var(--font-body);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.tool-hero__badge--run {
  background: var(--color-run-light);
  color: var(--color-run);
}

.tool-hero__title {
  font-family: var(--font-heading);
  font-size: var(--text-4xl);
  font-weight: 700;
  line-height: 1.15;
  margin: 0 0 var(--space-4);
  color: var(--text-primary);
}

.tool-hero__lede {
  font-size: var(--text-lg);
  line-height: 1.7;
  color: var(--text-secondary);
  max-width: 68ch;
  margin: 0;
}

/* ============================================
   CARDS
   ============================================ */
.tool-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  box-shadow: var(--shadow-sm);
  padding: var(--space-6);
  margin-bottom: var(--space-8);
}

.tool-card__header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-5);
  padding-bottom: var(--space-4);
  border-bottom: 1px solid var(--border-color);
}

.tool-card__title {
  font-family: var(--font-heading);
  font-size: var(--text-2xl);
  font-weight: 700;
  margin: 0;
  color: var(--text-primary);
}

.tool-card__hint {
  font-size: var(--text-sm);
  color: var(--text-tertiary);
  margin: 0;
}

/* ============================================
   FORM CONTROLS
   ============================================ */
.tool-form {
  display: grid;
  gap: var(--space-5);
}

.tool-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: var(--space-4);
}

.tool-field {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  min-width: 0;
}

.tool-field__label {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-primary);
}

.tool-field__note {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  line-height: 1.5;
}

.tool-field input[type="text"],
.tool-field input[type="number"],
.tool-field select,
.tool-field textarea {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: var(--text-base);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.tool-field textarea {
  min-height: 92px;
  resize: vertical;
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  line-height: 1.6;
}

.tool-field input:focus,
.tool-field select:focus,
.tool-field textarea:focus {
  outline: none;
  border-color: var(--color-tools);
  box-shadow: 0 0 0 3px var(--color-tools-light);
}

.tool-field input.is-invalid,
.tool-field select.is-invalid {
  border-color: #dc2626;
}

/* Monospace for pattern-style inputs, so letters line up with positions. */
.tool-field input.tool-input--pattern {
  font-family: var(--font-mono);
  letter-spacing: 0.18em;
  text-transform: lowercase;
}

/* ── Segmented control (unit toggles, modes) ── */
.tool-seg {
  display: inline-flex;
  padding: 4px;
  border: 1px solid var(--border-color);
  border-radius: 999px;
  background: var(--bg-tertiary);
  gap: 2px;
}

.tool-seg button {
  padding: var(--space-2) var(--space-4);
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.tool-seg button:hover {
  color: var(--text-primary);
}

.tool-seg button.is-active {
  background: var(--bg-card);
  color: var(--color-tools);
  box-shadow: var(--shadow-sm);
}

.tool-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-5);
}

.tool-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin-top: var(--space-2);
}

/* ── Status line ── */
.tool-status {
  margin: var(--space-4) 0 0;
  padding: var(--space-3) var(--space-4);
  border-radius: 10px;
  font-size: var(--text-sm);
  line-height: 1.6;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
}

.tool-status--error {
  background: rgba(220, 38, 38, 0.1);
  color: #b91c1c;
}

[data-theme="dark"] .tool-status--error {
  color: #fca5a5;
}

.tool-status--working {
  background: var(--color-tools-light);
  color: var(--color-tools);
}

/* ============================================
   RESULTS
   ============================================ */
.tool-result {
  margin-top: var(--space-6);
  padding: var(--space-6);
  border: 1px solid var(--border-color);
  border-left: 4px solid var(--color-tools);
  border-radius: 12px;
  background: var(--bg-secondary);
}

.tool-result--run {
  border-left-color: var(--color-run);
}

.tool-result__headline {
  font-family: var(--font-heading);
  font-size: var(--text-3xl);
  font-weight: 700;
  line-height: 1.2;
  margin: 0 0 var(--space-2);
  color: var(--text-primary);
}

.tool-result__sub {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  margin: 0 0 var(--space-5);
}

/* ── Stat grid ── */
.tool-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: var(--space-4);
}

.tool-stat {
  padding: var(--space-4);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  background: var(--bg-card);
}

.tool-stat__label {
  display: block;
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  margin-bottom: var(--space-2);
}

.tool-stat__value {
  display: block;
  font-family: var(--font-mono);
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

.tool-stat__note {
  display: block;
  margin-top: var(--space-1);
  font-size: var(--text-xs);
  color: var(--text-tertiary);
}

.tool-guidance {
  margin-top: var(--space-5);
  padding-top: var(--space-5);
  border-top: 1px dashed var(--border-color);
  font-size: var(--text-sm);
  line-height: 1.7;
  color: var(--text-secondary);
}

.tool-guidance p { margin: 0 0 var(--space-3); }
.tool-guidance p:last-child { margin-bottom: 0; }

/* ── Data table (splits, zones, predictions) ── */
.tool-table-wrap {
  overflow-x: auto;
  margin-top: var(--space-5);
  border: 1px solid var(--border-color);
  border-radius: 10px;
}

.tool-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
  background: var(--bg-card);
}

.tool-table th,
.tool-table td {
  padding: var(--space-3) var(--space-4);
  text-align: left;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

.tool-table th {
  background: var(--bg-tertiary);
  font-weight: 600;
  font-size: var(--text-xs);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-tertiary);
}

.tool-table tbody tr:last-child td {
  border-bottom: none;
}

.tool-table td.is-num {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.tool-table tbody tr.is-highlight {
  background: var(--color-run-light);
}

/* ============================================
   WORD RESULTS
   ============================================ */
.word-results {
  margin-top: var(--space-5);
}

.word-group {
  margin-bottom: var(--space-6);
}

.word-group__title {
  display: flex;
  align-items: baseline;
  gap: var(--space-3);
  font-family: var(--font-heading);
  font-size: var(--text-lg);
  font-weight: 700;
  margin: 0 0 var(--space-3);
  color: var(--text-primary);
}

.word-group__count {
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-tertiary);
}

.word-list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  list-style: none;
  margin: 0;
  padding: 0;
}

.word-chip {
  display: inline-flex;
  align-items: baseline;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-card);
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.word-chip:hover {
  border-color: var(--color-tools);
  transform: translateY(-1px);
}

.word-chip__word {
  font-family: var(--font-mono);
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: 0.03em;
}

.word-chip__meta {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-tertiary);
  font-variant-numeric: tabular-nums;
}

/* Everyday words get a tint so obscure dictionary entries don't dominate. */
.word-chip--common {
  background: var(--color-tools-light);
  border-color: rgba(124, 58, 237, 0.3);
}

.word-chip--common .word-chip__word {
  color: var(--color-tools);
}

[data-theme="dark"] .word-chip--common .word-chip__word {
  color: #c4b5fd;
}

/* ============================================
   WORDLE TILE GRID
   ============================================ */
.wordle-grid {
  display: grid;
  gap: var(--space-3);
  margin-bottom: var(--space-5);
}

.wordle-row {
  display: flex;
  gap: var(--space-2);
  align-items: center;
}

.wordle-tile {
  width: 54px;
  height: 54px;
  padding: 0;
  border: 2px solid var(--border-hover);
  border-radius: 8px;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: var(--text-xl);
  font-weight: 700;
  text-align: center;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.wordle-tile:focus {
  outline: none;
  border-color: var(--color-tools);
  box-shadow: 0 0 0 3px var(--color-tools-light);
}

.wordle-tile[data-state="correct"] {
  background: #15803d;
  border-color: #15803d;
  color: #ffffff;
}

.wordle-tile[data-state="present"] {
  background: #ca8a04;
  border-color: #ca8a04;
  color: #ffffff;
}

.wordle-tile[data-state="absent"] {
  background: var(--bg-tertiary);
  border-color: var(--border-color);
  color: var(--text-tertiary);
}

.wordle-row__hint {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  margin-left: var(--space-2);
}

.wordle-legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
  margin-bottom: var(--space-5);
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

.wordle-legend span {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

.wordle-legend i {
  width: 14px;
  height: 14px;
  border-radius: 4px;
  display: inline-block;
}

.wordle-legend i.is-correct { background: #15803d; }
.wordle-legend i.is-present { background: #ca8a04; }
.wordle-legend i.is-absent  { background: var(--bg-tertiary); border: 1px solid var(--border-color); }

/* ============================================
   TOOL HUB GRID
   ============================================ */
.tools-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: var(--space-5);
}

.tool-tile {
  display: flex;
  flex-direction: column;
  padding: var(--space-5);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  background: var(--bg-card);
  box-shadow: var(--shadow-sm);
  text-decoration: none;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.tool-tile:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
  border-color: var(--color-tools);
}

.tool-tile__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}

.tool-tile__icon {
  font-size: var(--text-3xl);
  line-height: 1;
}

.tool-tile__tag {
  padding: 2px var(--space-2);
  border-radius: 999px;
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.tool-tile__tag--word {
  background: var(--color-word-light);
  color: var(--color-word);
}

.tool-tile__tag--run {
  background: var(--color-run-light);
  color: var(--color-run);
}

.tool-tile__name {
  font-family: var(--font-heading);
  font-size: var(--text-xl);
  font-weight: 700;
  margin: 0 0 var(--space-2);
  color: var(--text-primary);
}

.tool-tile__desc {
  font-size: var(--text-sm);
  line-height: 1.65;
  color: var(--text-secondary);
  margin: 0 0 var(--space-4);
  flex-grow: 1;
}

.tool-tile__cta {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-tools);
}

.tool-tile:hover .tool-tile__cta {
  text-decoration: underline;
}

/* ============================================
   TOOL + ARTICLE PAIRINGS
   Each calculator sitting next to the articles a
   visitor needs after it.
   ============================================ */
.train-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: var(--space-6);
}

.train-pair {
  padding: var(--space-5);
  border: 1px solid var(--border-color);
  border-left: 3px solid var(--color-run);
  border-radius: 12px;
  background: var(--bg-secondary);
}

.train-pair__title {
  font-family: var(--font-heading);
  font-size: var(--text-lg);
  font-weight: 700;
  margin: 0 0 var(--space-2);
}

.train-pair__title a {
  color: var(--color-run);
  text-decoration: none;
}

.train-pair__title a:hover {
  text-decoration: underline;
}

.train-pair__lede {
  font-size: var(--text-sm);
  line-height: 1.65;
  color: var(--text-secondary);
  margin: 0 0 var(--space-4);
}

.train-pair__list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: var(--space-2);
}

.train-pair__list a {
  display: block;
  padding: var(--space-2) var(--space-3);
  border-radius: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  font-size: var(--text-sm);
  font-weight: 500;
  text-decoration: none;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.train-pair__list a:hover {
  border-color: var(--color-run);
  color: var(--color-run);
}

/* ============================================
   PROSE / EXPLAINER
   ============================================ */
.tool-prose {
  max-width: 72ch;
}

.tool-prose h2 {
  font-family: var(--font-heading);
  font-size: var(--text-2xl);
  font-weight: 700;
  margin: var(--space-10) 0 var(--space-4);
  color: var(--text-primary);
}

.tool-prose h3 {
  font-family: var(--font-heading);
  font-size: var(--text-xl);
  font-weight: 600;
  margin: var(--space-8) 0 var(--space-3);
  color: var(--text-primary);
}

.tool-prose p,
.tool-prose li {
  font-size: var(--text-base);
  line-height: 1.8;
  color: var(--text-secondary);
}

.tool-prose p {
  margin: 0 0 var(--space-4);
}

.tool-prose ul,
.tool-prose ol {
  margin: 0 0 var(--space-5);
  padding-left: var(--space-6);
}

.tool-prose li {
  margin-bottom: var(--space-2);
}

.tool-prose strong {
  color: var(--text-primary);
  font-weight: 600;
}

.tool-prose code {
  padding: 2px 6px;
  border-radius: 5px;
  background: var(--bg-tertiary);
  font-family: var(--font-mono);
  font-size: 0.9em;
  color: var(--text-primary);
}

.tool-prose a {
  color: var(--color-primary);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.tool-callout {
  margin: var(--space-6) 0;
  padding: var(--space-5);
  border-left: 4px solid var(--color-tools);
  border-radius: 10px;
  background: var(--color-tools-light);
}

.tool-callout p {
  margin: 0;
  font-size: var(--text-sm);
  line-height: 1.7;
  color: var(--text-secondary);
}

/* ── FAQ ── */
.tool-faq {
  display: grid;
  gap: var(--space-3);
}

.tool-faq details {
  border: 1px solid var(--border-color);
  border-radius: 10px;
  background: var(--bg-card);
  overflow: hidden;
}

.tool-faq summary {
  padding: var(--space-4) var(--space-5);
  font-family: var(--font-heading);
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--text-primary);
  cursor: pointer;
  list-style: none;
}

.tool-faq summary::-webkit-details-marker { display: none; }

.tool-faq summary::after {
  content: '+';
  float: right;
  font-size: var(--text-xl);
  line-height: 1;
  color: var(--text-tertiary);
}

.tool-faq details[open] summary::after { content: '−'; }

.tool-faq details > div {
  padding: 0 var(--space-5) var(--space-5);
}

.tool-faq p {
  margin: 0 0 var(--space-3);
  font-size: var(--text-sm);
  line-height: 1.75;
  color: var(--text-secondary);
}

.tool-faq p:last-child { margin-bottom: 0; }

/* ── Related tools ── */
.tool-related {
  margin-top: var(--space-12);
  padding-top: var(--space-8);
  border-top: 1px solid var(--border-color);
}

.tool-related__title {
  font-family: var(--font-heading);
  font-size: var(--text-xl);
  font-weight: 700;
  margin: 0 0 var(--space-5);
  color: var(--text-primary);
}

.tool-related__list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  list-style: none;
  margin: 0;
  padding: 0;
}

.tool-related__list a {
  display: inline-block;
  padding: var(--space-2) var(--space-4);
  border: 1px solid var(--border-color);
  border-radius: 999px;
  background: var(--bg-card);
  color: var(--text-secondary);
  font-size: var(--text-sm);
  font-weight: 500;
  text-decoration: none;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.tool-related__list a:hover {
  border-color: var(--color-tools);
  color: var(--color-tools);
}

/* ============================================
   AD PLACEHOLDERS
   Reserved slots only. No ad code ships until
   AdSense approval, per the site's content rules.
   ============================================ */
.tool-ad {
  margin: var(--space-8) 0;
  min-height: 90px;
}

/* ============================================
   PRINT
   ============================================ */
@media print {
  .navbar,
  .footer,
  .cookie-banner,
  .tool-ad,
  .tool-actions,
  .tool-related,
  .back-to-top,
  .reading-progress {
    display: none !important;
  }

  .tool-page { padding: 0; }

  .tool-card,
  .tool-result {
    border: 1px solid #ccc;
    box-shadow: none;
    break-inside: avoid;
  }

  body { background: #fff; color: #000; }
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 768px) {
  .tool-page {
    padding: var(--space-6) var(--space-4) var(--space-12);
  }

  .tool-hero__title {
    font-size: var(--text-3xl);
  }

  .tool-card {
    padding: var(--space-5);
    border-radius: 12px;
  }

  .tool-row {
    grid-template-columns: minmax(0, 1fr);
  }

  .tool-result {
    padding: var(--space-5);
  }

  .tool-result__headline {
    font-size: var(--text-2xl);
  }

  .tool-actions .btn {
    flex: 1 1 auto;
  }

  .wordle-tile {
    width: 46px;
    height: 46px;
    font-size: var(--text-lg);
  }
}

@media (max-width: 420px) {
  .wordle-tile {
    width: 40px;
    height: 40px;
  }

  .tool-seg {
    width: 100%;
  }

  .tool-seg button {
    flex: 1 1 auto;
    padding: var(--space-2);
  }
}

/* Honour reduced-motion preferences. */
@media (prefers-reduced-motion: reduce) {
  .tool-tile,
  .word-chip,
  .tool-seg button {
    transition: none;
  }

  .tool-tile:hover,
  .word-chip:hover {
    transform: none;
  }
}
