/* ==========================================================================
   Word Counter — editor workspace
   Loaded only on /tools/word-counter.

   Same principle as the image converter: no outer panel, no frame. The editor
   sits on the page background; elevation is reserved for the analytics cards
   and the controls you can actually press.
   ========================================================================== */

/* ------------------------------------------------------------------- hero */

.tool-hero {
  text-align: center;
  padding-block: var(--space-7) var(--space-4);
  max-width: 46rem;
  margin-inline: auto;
}

.tool-hero h1 {
  margin-bottom: var(--space-3);
  font-size: clamp(2rem, 1.4rem + 2.4vw, 2.75rem);
}

.tool-hero__sub { margin: 0; font-size: var(--text-lg); color: var(--fg-muted); }

.tool-hero__trust {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-4);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--success);
}

/* -------------------------------------------------------------- workspace */

.wc { margin-bottom: var(--space-8); }

.wc__grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-5);
  align-items: start;
}

@media (min-width: 960px) {
  .wc__grid { grid-template-columns: minmax(0, 65fr) minmax(0, 35fr); }
}

.wc__main { min-width: 0; }

.wc__side {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

@media (min-width: 960px) {
  .wc__side {
    position: sticky;
    top: calc(var(--header-h) + var(--space-4));
    max-height: calc(100dvh - var(--header-h) - var(--space-6));
    overflow-y: auto;
    /* Room for the scrollbar so cards do not shift when it appears. */
    padding-inline-end: var(--space-1);
  }
}

/* ------------------------------------------------- mobile quick stat bar */

.quickbar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-2);
  margin-bottom: var(--space-4);
  padding: var(--space-3);
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

@media (min-width: 960px) { .quickbar { display: none; } }

.quickstat { text-align: center; }
.quickstat b {
  display: block;
  font-size: var(--text-xl);
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
  /* Fixed line box: the number changes on every keystroke. */
  min-height: 1.15em;
}
.quickstat span {
  display: block;
  margin-top: 2px;
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--fg-muted);
}

/* ---------------------------------------------------------------- toolbar */

.editor-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}

.tool-group {
  display: flex;
  align-items: center;
  /* Buttons must wrap inside the group, not just between groups — four
     case buttons on one line overflow a phone-width container. */
  flex-wrap: wrap;
  gap: var(--space-1);
  max-width: 100%;
  padding: var(--space-1);
  background: var(--surface-2);
  border-radius: var(--radius);
}

.tool-btn {
  min-height: 34px;
  padding: 0 var(--space-3);
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--fg-muted);
  font: inherit;
  font-size: var(--text-xs);
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.tool-btn:hover { background: var(--surface); color: var(--fg); box-shadow: var(--shadow-sm); }
.tool-btn:active { transform: translateY(1px); }

.tool-group__label {
  padding-inline: var(--space-2) var(--space-1);
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--fg-subtle);
}

/* ----------------------------------------------------------------- editor */

.editor {
  display: block;
  width: 100%;
  min-height: 340px;
  padding: var(--space-5);
  background: var(--surface);
  color: var(--fg);
  /* Hairline, not a frame — the focus ring does the signalling. */
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  font: inherit;
  font-size: var(--text-lg);
  line-height: 1.75;
  resize: none;
  overflow: hidden;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.editor::placeholder { color: var(--fg-subtle); }
.editor:focus {
  outline: none;
  border-color: var(--ring);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--ring) 18%, transparent);
}

/* ---------------------------------------------------------- quick actions */

.editor-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-3);
}

.editor-actions .spacer { flex: 1; }

.autosave {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
  color: var(--fg-subtle);
  /* Reserved so the row never reflows when the label appears. */
  min-width: 8.5rem;
  justify-content: flex-end;
  transition: opacity var(--dur) var(--ease);
}
.autosave[data-state="saved"] { color: var(--success); }
.autosave[data-state="idle"] { opacity: 0.65; }

/* --------------------------------------------------------------- zen mode */

.wc--zen .wc__side,
.wc--zen .wc__keywords,
.wc--zen .quickbar { display: none; }

.wc--zen .wc__main {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  flex-direction: column;
  padding: var(--space-4) var(--space-5) var(--space-5);
  background: var(--bg);
}

.wc--zen .editor {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  max-width: 900px;
  width: 100%;
  margin-inline: auto;
}

.wc--zen .editor-toolbar,
.wc--zen .editor-actions {
  max-width: 900px;
  width: 100%;
  margin-inline: auto;
}

/* ----------------------------------------------------------------- panels */

.panel {
  padding: var(--space-4);
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.panel__title {
  margin: 0 0 var(--space-3);
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--fg-subtle);
}

/* Primary counters: one dominant figure, two supporting. */
.counters { display: grid; gap: var(--space-3); }

.counter-main {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
}
.counter-main b {
  font-size: clamp(2.25rem, 1.6rem + 1.6vw, 3rem);
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--primary);
  min-height: 1em;
}
.counter-main span { font-size: var(--text-sm); font-weight: 600; color: var(--fg-muted); }

.counter-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px solid var(--border);
}

.metric b {
  display: block;
  font-size: var(--text-xl);
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
  min-height: 1.15em;
}
.metric span {
  display: block;
  margin-top: 2px;
  font-size: var(--text-xs);
  color: var(--fg-muted);
}

/* Time + structure rows */
.metric-rows { display: flex; flex-direction: column; gap: var(--space-2); }

.metric-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  font-size: var(--text-sm);
}
.metric-row dt { color: var(--fg-muted); }
.metric-row dd {
  margin: 0;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------------ readability */

.readability { display: flex; align-items: center; gap: var(--space-4); }

.score-ring {
  --score: 0;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 76px;
  height: 76px;
  border-radius: 50%;
  /* The arc doubles as a non-numeric cue for the score. */
  background: conic-gradient(var(--score-color, var(--primary)) calc(var(--score) * 1%), var(--surface-2) 0);
  position: relative;
}
.score-ring::after {
  content: "";
  position: absolute;
  inset: 7px;
  border-radius: 50%;
  background: var(--surface);
}
.score-ring b {
  position: relative;
  z-index: 1;
  font-size: var(--text-xl);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--score-color, var(--primary));
}

.readability__body { min-width: 0; }
.readability__label { font-weight: 700; font-size: var(--text-sm); }
.readability__grade { margin: 2px 0 0; font-size: var(--text-xs); color: var(--fg-muted); }

/* ------------------------------------------------------- length trackers */

.targets { display: flex; flex-direction: column; gap: var(--space-3); }

.target__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
  font-size: var(--text-xs);
  margin-bottom: var(--space-1);
}
.target__name { font-weight: 600; color: var(--fg-muted); }
.target__count { font-variant-numeric: tabular-nums; color: var(--fg-subtle); }

.target__track {
  height: 6px;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  overflow: hidden;
}
.target__fill {
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: var(--primary);
  transition: width var(--dur) var(--ease), background-color var(--dur) var(--ease);
}

/* Over-limit is signalled by colour AND the "over by N" text, never colour alone. */
.target[data-state="near"] .target__fill { background: var(--warning); }
.target[data-state="over"] .target__fill { background: var(--danger); }
.target[data-state="near"] .target__count { color: var(--warning); font-weight: 700; }
.target[data-state="over"] .target__count { color: var(--danger); font-weight: 700; }

/* --------------------------------------------------------------- keywords */

.wc__keywords { margin-top: var(--space-6); }

.keywords__head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}
.keywords__head h2 { margin: 0 0 2px; font-size: var(--text-xl); }
.keywords__head p { margin: 0; font-size: var(--text-sm); color: var(--fg-muted); }

.tabs {
  display: inline-flex;
  gap: var(--space-1);
  padding: var(--space-1);
  background: var(--surface-2);
  border-radius: var(--radius);
}
.tab {
  min-height: 38px;
  padding: 0 var(--space-4);
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--fg-muted);
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.tab:hover { color: var(--fg); }
.tab[aria-selected="true"] {
  background: var(--surface);
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

.keyword-table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }

.keyword-table th {
  padding: 0 var(--space-3) var(--space-2);
  text-align: left;
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--fg-subtle);
  border-bottom: 1px solid var(--border);
}
.keyword-table td {
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.keyword-table tr:last-child td { border-bottom: 0; }
.keyword-table td:nth-child(2),
.keyword-table td:nth-child(3) { font-variant-numeric: tabular-nums; white-space: nowrap; }

.keyword-term { font-weight: 600; word-break: break-word; }

.keyword-bar {
  display: block;
  height: 6px;
  min-width: 3px;
  border-radius: var(--radius-pill);
  background: var(--primary);
}
.keyword-table td:last-child { width: 34%; }

.keywords__empty {
  padding: var(--space-6) var(--space-4);
  text-align: center;
  color: var(--fg-muted);
  font-size: var(--text-sm);
}

@media (max-width: 599px) {
  /* The bar column is decorative — drop it before the numbers wrap. */
  .keyword-table td:last-child,
  .keyword-table th:last-child { display: none; }

  /* Each toolbar group takes a full row, buttons share it evenly. */
  .tool-group { width: 100%; }
  .tool-btn { flex: 1 1 auto; text-align: center; }

  .keywords__head { align-items: flex-start; }
  .tabs { width: 100%; }
  .tab { flex: 1; padding-inline: var(--space-2); }
}
