/* Free tools (/tools/*): the in-page tool panel. v2 (2026-10-21): the spaced repetition calculator
   (.pl-*) and text to flashcards (.x-*); sides are logical (inline-start/end) so right-to-left text works.
   Free tools (/tools/*): the in-page tool panel. Loaded only by the tool pages, after
   styles.css, whose colour tokens it uses (so light and dark follow the system). */
.tool {
  margin-block: clamp(28px, 4vw, 48px) 0;
  padding: clamp(20px, 3vw, 36px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow-sm);
}
.tool > h2 {
  font-size: clamp(1.5rem, 2.6vw, 2.1rem);
  margin-bottom: var(--space-3);
}
.t-private {
  position: relative;
  max-width: var(--reading);
  margin-top: var(--space-3);
  padding-inline-start: 30px;
  color: var(--ink-2);
  font-size: var(--fs-small);
}
.t-private::before {
  content: "";
  position: absolute;
  inset-inline-start: 0;
  top: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 5px var(--accent);
}
.t-drop {
  margin-top: var(--space-5);
  padding: clamp(18px, 3vw, 28px);
  border: 2px dashed var(--accent-line);
  border-radius: var(--radius-sm);
  background: var(--sunk);
  transition: background-color 0.2s, border-color 0.2s;
}
.t-drop.is-over {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.t-drop > p {
  margin-top: var(--space-2);
  color: var(--dim);
  font-size: var(--fs-small);
}
.t-file-label {
  display: block;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: var(--space-3);
}
.t-file {
  max-width: 100%;
  font: inherit;
  font-size: var(--fs-small);
  color: var(--ink-2);
}
.t-file::file-selector-button {
  margin-inline-end: 14px;
  min-height: 48px;
  padding: 10px 22px;
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: var(--accent);
  color: var(--on-accent);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.t-status {
  min-height: 1.5em;
  margin-top: var(--space-4);
  font-size: var(--fs-small);
  color: var(--ink);
  max-width: 820px;
}
.t-status.is-error {
  color: var(--coral-strong);
  font-weight: 600;
}
.t-nojs {
  margin-top: var(--space-4);
  color: var(--coral-strong);
  font-weight: 600;
}
/* Filters and options */
.t-bar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4) var(--space-5);
  align-items: flex-end;
  margin-top: var(--space-5);
  padding-top: var(--space-5);
  border-top: 1px solid var(--line-soft);
}
.t-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: var(--fs-small);
  color: var(--ink-2);
  font-weight: 600;
  min-width: 0;
}
.t-field[hidden] {
  display: none;
}
.t-field.is-check {
  flex-direction: row;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  font-weight: 500;
}
.t-field input[type="search"],
.t-field input[type="text"],
.t-field select {
  min-height: 44px;
  min-width: 0;
  max-width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  font-weight: 400;
}
.t-field select {
  max-width: min(320px, 100%);
}
.tool input[type="checkbox"] {
  flex: none;
  width: 22px;
  height: 22px;
  margin: 0;
  accent-color: var(--accent);
}
.t-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  align-items: center;
  margin-top: var(--space-4);
}
.t-row .button {
  min-height: 44px;
  padding: 10px 18px;
  font-size: var(--fs-small);
  cursor: pointer;
  font-family: inherit;
}
.t-row .button[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}
.t-count {
  font-size: var(--fs-small);
  color: var(--dim);
  font-variant-numeric: tabular-nums;
}
/* The word list (Kindle) */
.t-list {
  list-style: none;
  margin: var(--space-4) 0 0;
  padding: 0;
  max-height: min(70vh, 640px);
  overflow-y: auto;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  background: var(--paper);
}
.t-list li + li {
  border-top: 1px solid var(--line-soft);
}
.t-list label {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  padding: 14px 16px;
  cursor: pointer;
}
.t-list label:hover {
  background: var(--accent-soft);
}
.t-list input[type="checkbox"] {
  margin-top: 2px;
}
.t-item {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  align-items: baseline;
  min-width: 0;
}
.t-word {
  color: var(--ink);
  font-size: 1.05rem;
  overflow-wrap: anywhere;
}
.t-form,
.t-meta {
  color: var(--dim);
  font-size: var(--fs-micro);
}
.t-tag {
  font-size: 0.75rem;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--amber-soft);
  color: var(--ink);
}
.t-sentence {
  flex-basis: 100%;
  color: var(--ink-2);
  font-size: var(--fs-small);
  overflow-wrap: anywhere;
}
.t-meta {
  flex-basis: 100%;
}
.t-empty {
  padding: 16px;
  color: var(--dim);
}
/* The text box and preview (export fixer) */
.t-input {
  display: block;
  width: 100%;
  min-height: 180px;
  margin-top: var(--space-2);
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--paper);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 0.875rem;
  line-height: 1.5;
  resize: vertical;
  tab-size: 4;
}
.t-preview-wrap {
  margin-top: var(--space-4);
  max-height: min(70vh, 560px);
  overflow: auto;
}
.t-preview-wrap .data-table th,
.t-preview-wrap .data-table td {
  padding: 10px 16px;
  white-space: normal;
  overflow-wrap: anywhere;
}
.t-preview-wrap .data-table tbody th {
  white-space: normal;
  min-width: 8em;
}
.t-preview-wrap .data-table td {
  color: var(--ink-2);
}
.t-preview-wrap .data-table td.is-empty::after {
  content: "(no meaning)";
  color: var(--dim);
  font-style: italic;
}
.t-preview-wrap thead th {
  position: sticky;
  top: 0;
  z-index: 1;
}
.t-more {
  margin-top: var(--space-2);
  font-size: var(--fs-micro);
  color: var(--dim);
}
.t-next {
  margin-top: var(--space-6);
  padding: clamp(18px, 3vw, 26px);
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  border: 1px solid var(--accent-line);
}
.t-next h3 {
  font-size: var(--fs-h3);
  color: var(--ink);
}
.t-next p {
  margin-top: var(--space-2);
  max-width: var(--reading);
  color: var(--ink-2);
}
.t-next .button-row {
  margin-top: var(--space-4);
}
/* The panel is shown before the script runs; the controls that only work with it wait. */
.tool:not(.is-ready) .t-needs-js {
  display: none;
}
@media (max-width: 640px) {
  .t-bar {
    flex-direction: column;
    align-items: stretch;
  }
  .t-field select,
  .t-field input[type="search"],
  .t-field input[type="text"] {
    max-width: none;
    width: 100%;
  }
  .t-row .button {
    flex: 1 1 auto;
  }
  /* styles.css stacks tables on phones: the word above its meaning, tight. */
  .t-preview-wrap .data-table th,
  .t-preview-wrap .data-table td {
    padding: 2px 0;
  }
  .t-file::file-selector-button {
    display: block;
    margin: 0 0 10px;
  }
}

/* ---------------------------------------------------------------- spaced repetition calculator */
.pl {
  display: grid;
  gap: clamp(20px, 3vw, 36px);
  margin-top: var(--space-5);
}
@media (min-width: 900px) {
  .pl {
    grid-template-columns: minmax(270px, 330px) minmax(0, 1fr);
    align-items: start;
  }
}
.pl-inputs {
  display: grid;
  gap: var(--space-5);
  padding: clamp(18px, 2.4vw, 24px);
  border-radius: var(--radius-sm);
  background: var(--sunk);
  border: 1px solid var(--line-soft);
}
.pl-field {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}
.pl-field[hidden] {
  display: none;
}
.pl-field > legend,
.pl-label {
  display: block;
  padding: 0;
  margin-bottom: 8px;
  font-size: var(--fs-small);
  font-weight: 650;
  color: var(--ink);
}
.pl-hint {
  margin-top: 8px;
  font-size: var(--fs-micro);
  color: var(--dim);
  line-height: 1.45;
}
.pl-field input[type="number"],
.pl-field input[type="date"] {
  width: 100%;
  min-height: 48px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-size: 1.05rem;
}
.pl-field input:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 1px;
}
.pl-stepper {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) 48px;
  gap: 6px;
}
.tool:not(.is-ready) .pl-stepper {
  grid-template-columns: minmax(0, 1fr);
}
.pl-stepper input[type="number"] {
  text-align: center;
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  -moz-appearance: textfield;
  appearance: textfield;
}
.pl-stepper input::-webkit-outer-spin-button,
.pl-stepper input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.pl-step {
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
}
.pl-step:hover {
  background: var(--accent-soft);
  border-color: var(--accent-line);
}
.pl-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}
.pl-chip {
  min-width: 44px;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--ink-2);
  font: inherit;
  font-size: var(--fs-small);
  font-weight: 600;
  cursor: pointer;
}
.pl-chip:hover {
  border-color: var(--accent-line);
  color: var(--ink);
}
.pl-chip[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-ink);
}
/* A segmented control made of native radio buttons. */
.pl-seg {
  display: flex;
  gap: 4px;
  padding: 4px;
  border-radius: 14px;
  background: var(--card);
  border: 1px solid var(--line);
}
.pl-opt {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
}
.pl-opt input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}
.pl-opt span {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 6px 10px;
  border-radius: 10px;
  color: var(--ink-2);
  font-size: var(--fs-small);
  font-weight: 600;
  text-align: center;
  line-height: 1.2;
  transition: background-color 0.15s, color 0.15s;
}
.pl-opt span small {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--amber-soft);
  color: var(--ink);
}
.pl-opt input:hover + span {
  background: var(--accent-soft);
  color: var(--ink);
}
.pl-opt input:checked + span {
  background: var(--accent);
  color: var(--on-accent);
}
.pl-opt input:checked + span small {
  background: color-mix(in oklch, var(--on-accent) 22%, transparent);
  color: inherit;
}
.pl-opt input:focus-visible + span {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}
/* The result */
.pl-out {
  min-width: 0;
}
.pl-headline {
  font-size: var(--fs-small);
  font-weight: 650;
  color: var(--accent-ink);
  letter-spacing: 0.01em;
}
.pl-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(128px, 1fr));
  gap: 10px;
  margin: 12px 0 0;
}
.pl-stats > div,
.pl-goal > div {
  min-width: 0;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-soft);
  background: var(--paper);
}
.pl-stats > div.is-key {
  border-color: var(--accent-line);
  background: var(--accent-soft);
}
.pl-stats dt,
.pl-goal dt {
  font-size: var(--fs-micro);
  font-weight: 600;
  color: var(--dim);
}
.pl-stats dd,
.pl-goal dd {
  margin: 4px 0 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: var(--fs-micro);
  color: var(--ink-2);
  line-height: 1.35;
}
.pl-stats dd b {
  font-size: clamp(1.7rem, 2.6vw, 2.2rem);
  line-height: 1.05;
  font-weight: 750;
  letter-spacing: -0.02em;
  color: var(--ink);
}
.pl-stats .is-key dd b {
  color: var(--accent-ink);
}
.pl-goal {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
  margin: 10px 0 0;
}
.pl-goal dd b {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--ink);
}
.pl-chart {
  margin: 18px 0 0;
}
.pl-chart-wrap {
  position: relative;
  padding: 8px 4px 2px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-soft);
  background: var(--paper);
  touch-action: pan-y;
}
#p-chart {
  display: block;
  width: 100%;
  height: 240px;
}
@media (max-width: 640px) {
  #p-chart {
    height: 200px;
  }
}
.pl-bars {
  fill: var(--accent);
  opacity: 0.42;
}
.pl-avg {
  fill: none;
  stroke: var(--accent-ink);
  stroke-width: 2;
  stroke-linejoin: round;
}
.pl-grid {
  stroke: var(--line-soft);
  stroke-width: 1;
}
.pl-tick {
  stroke: var(--line);
}
.pl-axis {
  fill: var(--dim);
  font-size: 11px;
  font-family: inherit;
}
.pl-goal-line {
  stroke: var(--coral-strong);
  stroke-width: 1.5;
  stroke-dasharray: 4 4;
}
.pl-goal-label {
  fill: var(--coral-strong);
  font-size: 12px;
  font-weight: 700;
}
.pl-cursor {
  stroke: var(--ink);
  stroke-width: 1;
  opacity: 0.5;
}
.pl-tip {
  position: absolute;
  top: 6px;
  left: 0;
  margin: 0;
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--ink);
  color: var(--paper);
  font-size: var(--fs-micro);
  white-space: nowrap;
  pointer-events: none;
  box-shadow: var(--shadow-sm);
}
.pl-chart figcaption {
  margin-top: 8px;
  font-size: var(--fs-micro);
  color: var(--dim);
}
.pl-table {
  margin-top: var(--space-3);
  max-height: min(60vh, 480px);
  overflow: auto;
}
.pl-table[hidden] {
  display: none;
}
.pl-model {
  margin-top: var(--space-4);
  padding-inline-start: 12px;
  border-inline-start: 3px solid var(--amber);
  font-size: var(--fs-small);
  color: var(--ink-2);
}
.pl-out[aria-busy="true"] .pl-stats,
.pl-out[aria-busy="true"] .pl-chart {
  opacity: 0.55;
  transition: opacity 0.2s 0.15s;
}
.tool:not(.is-ready) .pl-out {
  display: none;
}
.tool:not(.is-ready) .pl {
  grid-template-columns: minmax(0, 1fr);
}

/* ---------------------------------------------------------------- text to flashcards */
.x-input {
  min-height: 200px;
  font-family: inherit;
  font-size: 1rem;
  line-height: 1.6;
}
.x-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px 16px;
  margin-top: var(--space-5);
}
.x-head h3 {
  font-size: var(--fs-h3);
}
.x-note {
  margin-top: var(--space-2);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--amber-soft);
  font-size: var(--fs-small);
  color: var(--ink);
}
.x-words {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: var(--space-3);
  padding: 14px;
  max-height: min(56vh, 520px);
  overflow-y: auto;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  background: var(--paper);
}
.x-word {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 6px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-size: 1rem;
  line-height: 1.2;
  cursor: pointer;
  unicode-bidi: plaintext;
  transition: background-color 0.12s, border-color 0.12s, color 0.12s;
}
.x-word:hover {
  border-color: var(--accent-line);
  background: var(--accent-soft);
}
.x-word[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--on-accent);
}
.x-word[aria-pressed="true"]::before {
  content: "✓";
  font-size: 0.85em;
  font-weight: 700;
}
.x-word:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}
.x-take {
  margin-top: var(--space-6);
  padding-top: var(--space-5);
  border-top: 1px solid var(--line-soft);
}
.x-take h3 {
  font-size: var(--fs-h3);
}
.x-options {
  border-top: 0;
  padding-top: 0;
  margin-top: var(--space-4);
}
.x-options .t-field:not(.is-check) {
  flex: 1 1 260px;
}
.x-options input[type="text"] {
  width: 100%;
}
.x-open.is-off {
  opacity: 0.55;
}
.x-open .g {
  flex: none;
}
@media (prefers-reduced-motion: reduce) {
  .x-word,
  .pl-opt span {
    transition: none;
  }
}
@media (max-width: 899px) {
  .pl-stats > div:last-child:nth-child(odd) {
    grid-column: 1 / -1;
  }
}
@media (max-width: 640px) {
  .x-options .t-field:not(.is-check) {
    flex: none;
  }
}
