/* ===========================================================================
   RandomTools365 — main.css
   Design tokens, layout shell, and every shared component.
   Light and dark themes are driven by CSS custom properties on :root.
   =========================================================================== */

/* --- Tokens -------------------------------------------------------------- */
:root {
  color-scheme: light;

  --primary: #2563eb;
  --primary-strong: #1d4ed8;
  --primary-soft: #dbeafe;
  --secondary: #7c3aed;
  --secondary-soft: #ede9fe;

  --bg: #f6f7fb;
  --bg-alt: #eef1f8;
  --surface: #ffffff;
  --surface-alt: #f9fafb;
  --text: #111827;
  --muted: #5b6478;
  --border: #d8dee9;
  --border-strong: #b6c0d1;

  --success: #047857;
  --success-soft: #d1fae5;
  --warning: #b45309;
  --warning-soft: #fef3c7;
  --error: #b91c1c;
  --error-soft: #fee2e2;

  --radius-sm: 6px;
  --radius: 12px;
  --radius-lg: 18px;
  --shadow-sm: 0 1px 2px rgba(17, 24, 39, .06), 0 1px 3px rgba(17, 24, 39, .05);
  --shadow: 0 4px 14px rgba(17, 24, 39, .08);
  --shadow-lg: 0 18px 40px rgba(17, 24, 39, .16);

  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial,
    "Noto Sans", "Apple Color Emoji", "Segoe UI Emoji", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
    "Liberation Mono", monospace;

  --wrap: 1200px;
  --wrap-narrow: 760px;
  --header-h: 60px;
  --space: 1rem;
  --focus: 0 0 0 3px rgba(37, 99, 235, .45);
}

:root[data-theme='dark'] {
  color-scheme: dark;

  --primary: #60a5fa;
  --primary-strong: #93c5fd;
  --primary-soft: #1e3a5f;
  --secondary: #a78bfa;
  --secondary-soft: #332b57;

  --bg: #0f141c;
  --bg-alt: #141b26;
  --surface: #182131;
  --surface-alt: #1f293a;
  --text: #eef2f8;
  --muted: #a5b0c2;
  --border: #2c3849;
  --border-strong: #3d4d63;

  --success: #34d399;
  --success-soft: #08352a;
  --warning: #fbbf24;
  --warning-soft: #3a2a06;
  --error: #f87171;
  --error-soft: #3d1414;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .5);
  --shadow: 0 4px 14px rgba(0, 0, 0, .5);
  --shadow-lg: 0 18px 40px rgba(0, 0, 0, .6);
  --focus: 0 0 0 3px rgba(96, 165, 250, .55);
}

/* --- Reset --------------------------------------------------------------- */
*,
*::before,
*::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.65;
  color: var(--text);
  background: var(--bg);
  overflow-x: hidden;
}

img, svg, canvas { max-width: 100%; }
img { height: auto; display: block; }

h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 .5em; font-weight: 700; letter-spacing: -.01em; }
h1 { font-size: clamp(1.75rem, 1.2rem + 2vw, 2.6rem); }
h2 { font-size: clamp(1.35rem, 1.1rem + 1.1vw, 1.85rem); margin-top: 2rem; }
h3 { font-size: 1.15rem; margin-top: 1.5rem; }
p { margin: 0 0 1rem; }
ul, ol { margin: 0 0 1rem; padding-left: 1.35rem; }
li { margin-bottom: .35rem; }
small { font-size: .85rem; }

a { color: var(--primary-strong); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--primary); }
:root[data-theme='dark'] a { color: var(--primary); }

code, kbd { font-family: var(--font-mono); font-size: .9em; }
code { background: var(--surface-alt); border: 1px solid var(--border); border-radius: 4px; padding: .1em .35em; }
kbd {
  background: var(--surface-alt); border: 1px solid var(--border-strong);
  border-bottom-width: 2px; border-radius: 4px; padding: .05em .4em; font-size: .8em;
}

:focus-visible {
  outline: 2px solid transparent;
  box-shadow: var(--focus);
  border-radius: 4px;
}

hr { border: 0; border-top: 1px solid var(--border); margin: 2rem 0; }

/* --- Utilities ----------------------------------------------------------- */
.wrap { width: 100%; max-width: var(--wrap); margin-inline: auto; padding-inline: 1rem; }
.wrap--narrow { max-width: var(--wrap-narrow); }
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: .5rem; top: -100px; z-index: 200;
  background: var(--primary); color: #fff; padding: .6rem 1rem;
  border-radius: 0 0 var(--radius) var(--radius); font-weight: 600;
}
.skip-link:focus { top: 0; color: #fff; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.text-center { text-align: center; }
.stack > * + * { margin-top: var(--space); }
.row { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.row--end { justify-content: flex-end; }
.grow { flex: 1 1 auto; min-width: 0; }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }

/* --- Header -------------------------------------------------------------- */
.site-header {
  position: sticky; top: 0; z-index: 60;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(140%) blur(8px);
  border-bottom: 1px solid var(--border);
}
.site-header__inner {
  display: flex; align-items: center; gap: .75rem;
  min-height: var(--header-h); padding-block: .35rem;
}
.brand {
  display: inline-flex; align-items: center; gap: .5rem;
  font-weight: 800; font-size: 1.05rem; color: var(--text); text-decoration: none;
  letter-spacing: -.02em; flex: 0 0 auto;
}
.brand:hover { color: var(--text); }
.brand__mark {
  width: 30px; height: 30px; border-radius: 50%;
  background: conic-gradient(var(--primary) 0 25%, var(--secondary) 0 50%, #f59e0b 0 75%, #059669 0);
  box-shadow: inset 0 0 0 3px var(--surface);
  flex: 0 0 auto;
}
.brand__text span { color: var(--primary-strong); }
:root[data-theme='dark'] .brand__text span { color: var(--primary); }

.site-nav { display: flex; align-items: center; gap: .25rem; margin-left: auto; }
.site-nav a {
  color: var(--text); text-decoration: none; font-weight: 600; font-size: .93rem;
  padding: .5rem .6rem; border-radius: var(--radius-sm);
}
.site-nav a:hover { background: var(--surface-alt); color: var(--primary-strong); }
.site-nav a[aria-current='page'] { color: var(--primary-strong); background: var(--primary-soft); }

.header-tools { display: flex; align-items: center; gap: .4rem; }

.nav-toggle { display: none; }

@media (max-width: 900px) {
  .site-header__inner { flex-wrap: wrap; }
  .nav-toggle { display: inline-flex; }
  .site-nav {
    order: 5; width: 100%; display: none; flex-direction: column; align-items: stretch;
    padding-bottom: .5rem; gap: 0;
  }
  .site-nav.is-open { display: flex; }
  .site-nav a { padding: .7rem .5rem; border-radius: var(--radius-sm); }
  .search { order: 4; width: 100%; }
}

/* --- Search -------------------------------------------------------------- */
.search { position: relative; flex: 1 1 260px; max-width: 340px; margin-left: auto; }
@media (max-width: 900px) { .search { max-width: none; margin-left: 0; } }

.search__input {
  width: 100%; padding: .5rem .75rem .5rem 2.1rem;
  border: 1px solid var(--border-strong); border-radius: 999px;
  background: var(--surface-alt) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%235b6478' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='M20 20l-3.5-3.5'/%3E%3C/svg%3E") no-repeat .6rem center / 1.05rem;
  color: var(--text); font: inherit; font-size: .92rem;
}
.search__results {
  position: absolute; inset-inline: 0; top: calc(100% + .35rem);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); padding: .3rem; margin: 0; list-style: none;
  max-height: min(70vh, 420px); overflow-y: auto; z-index: 80;
}
.search__results[hidden] { display: none; }
.search__results li { margin: 0; }
.search__results a {
  display: block; padding: .5rem .6rem; border-radius: var(--radius-sm);
  color: var(--text); text-decoration: none;
}
.search__results a strong { display: block; font-size: .95rem; }
.search__results a span { display: block; font-size: .8rem; color: var(--muted); }
.search__results a:hover,
.search__results [aria-selected='true'] a,
.search__results a:focus { background: var(--primary-soft); color: var(--text); }
.search__empty { padding: .7rem .6rem; color: var(--muted); font-size: .9rem; }

/* --- Buttons ------------------------------------------------------------- */
/* Colours are set directly rather than through an intermediate --btn-* custom
   property: an element-level `--x: var(--theme-token)` is not reliably
   invalidated when the theme token changes on :root, which left buttons
   showing the previous theme's colours after a toggle. */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  min-height: 44px; padding: .55rem 1rem;
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; font-size: .95rem; line-height: 1.2;
  cursor: pointer; text-decoration: none; text-align: center;
  transition: background-color .15s ease, border-color .15s ease, transform .1s ease;
}
.btn:hover:not(:disabled) { background: var(--surface-alt); color: var(--text); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled='true'] { opacity: .55; cursor: not-allowed; }

.btn--primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn--primary:hover:not(:disabled) { background: var(--primary-strong); border-color: var(--primary-strong); color: #fff; }
:root[data-theme='dark'] .btn--primary { color: #0b1220; }
:root[data-theme='dark'] .btn--primary:hover:not(:disabled) { color: #0b1220; }

.btn--ghost { background: transparent; border-color: transparent; color: var(--text); }
.btn--ghost:hover:not(:disabled) { background: var(--surface-alt); color: var(--text); }

.btn--danger { background: transparent; color: var(--error); border-color: var(--error); }
.btn--danger:hover:not(:disabled) { background: var(--error-soft); color: var(--error); }
.btn--sm { min-height: 36px; padding: .3rem .65rem; font-size: .85rem; border-radius: var(--radius-sm); }
.btn--lg { min-height: 56px; padding: .8rem 1.8rem; font-size: 1.1rem; }
.btn--block { width: 100%; }
.btn--icon { min-width: 44px; padding: .5rem; }
.btn svg { width: 1.15em; height: 1.15em; flex: 0 0 auto; }
.btn.is-busy { position: relative; color: transparent !important; }
.btn.is-busy::after {
  content: ''; position: absolute; width: 1.1em; height: 1.1em; border-radius: 50%;
  border: 2px solid currentColor; border-top-color: transparent;
  color: var(--text); animation: rt-spin .7s linear infinite;
}
.btn--primary.is-busy::after { color: #fff; }
:root[data-theme='dark'] .btn--primary.is-busy::after { color: #0b1220; }
@keyframes rt-spin { to { transform: rotate(360deg); } }

.btn-group { display: flex; flex-wrap: wrap; gap: .5rem; }

/* --- Forms --------------------------------------------------------------- */
label { font-weight: 600; font-size: .9rem; display: inline-block; margin-bottom: .25rem; }
.field { margin-bottom: 1rem; }
.field__hint { display: block; font-size: .82rem; color: var(--muted); margin-top: .25rem; font-weight: 400; }
.field__error { display: block; font-size: .85rem; color: var(--error); margin-top: .25rem; font-weight: 600; }
.field__error:empty { display: none; }

input[type='text'], input[type='number'], input[type='search'], input[type='date'],
input[type='time'], input[type='email'], select, textarea {
  width: 100%; padding: .55rem .7rem; min-height: 44px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font: inherit; font-size: .95rem;
}
textarea { min-height: 180px; resize: vertical; line-height: 1.5; font-family: var(--font); }
input[aria-invalid='true'], textarea[aria-invalid='true'] { border-color: var(--error); }
input[type='color'] { width: 46px; height: 40px; min-height: 40px; padding: 2px; }
input[type='range'] { width: 100%; accent-color: var(--primary); min-height: 44px; }
select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%235b6478' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right .55rem center; background-size: 1.1rem;
  padding-right: 2.1rem;
}
.check {
  display: flex; align-items: flex-start; gap: .5rem; font-weight: 500;
  font-size: .92rem; margin-bottom: .5rem; cursor: pointer; min-height: 32px;
}
.check input { width: 20px; height: 20px; margin: .2rem 0 0; accent-color: var(--primary); flex: 0 0 auto; }
.check span { flex: 1; }
.inline-fields { display: flex; flex-wrap: wrap; gap: .75rem; }
.inline-fields > * { flex: 1 1 130px; min-width: 0; }

fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: .85rem 1rem; margin: 0 0 1rem; }
legend { font-weight: 700; font-size: .9rem; padding-inline: .35rem; }

/* --- Cards & panels ------------------------------------------------------ */
.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 1.1rem; box-shadow: var(--shadow-sm);
}
.panel + .panel { margin-top: 1rem; }
.panel__head {
  display: flex; align-items: center; justify-content: space-between; gap: .5rem;
  margin-bottom: .75rem; flex-wrap: wrap;
}
.panel__head h2, .panel__head h3 { margin: 0; font-size: 1.05rem; }

details.panel > summary {
  cursor: pointer; font-weight: 700; list-style: none; display: flex;
  align-items: center; justify-content: space-between; gap: .5rem; min-height: 32px;
}
details.panel > summary::-webkit-details-marker { display: none; }
details.panel > summary::after {
  content: '▾'; color: var(--muted); transition: transform .2s ease;
}
details.panel[open] > summary::after { transform: rotate(180deg); }
details.panel > summary + * { margin-top: .85rem; }

.card-grid {
  display: grid; gap: .9rem; padding: 0; margin: 0; list-style: none;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
}
.card {
  display: flex; flex-direction: column; gap: .35rem; height: 100%;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem; text-decoration: none; color: var(--text);
  box-shadow: var(--shadow-sm); transition: border-color .15s ease, transform .15s ease, box-shadow .15s ease;
}
.card:hover { border-color: var(--primary); transform: translateY(-2px); box-shadow: var(--shadow); color: var(--text); }
.card__icon {
  width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center;
  background: var(--primary-soft); color: var(--primary-strong); margin-bottom: .3rem;
}
:root[data-theme='dark'] .card__icon { color: var(--primary); }
.card__icon svg { width: 22px; height: 22px; }
.card__title { font-weight: 700; font-size: 1rem; }
.card__desc { font-size: .88rem; color: var(--muted); margin: 0; }
.card__tag {
  font-size: .72rem; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); font-weight: 700;
}

/* --- Notices ------------------------------------------------------------- */
.notice {
  border: 1px solid var(--border); border-left: 4px solid var(--primary);
  background: var(--surface-alt); border-radius: var(--radius-sm);
  padding: .7rem .9rem; font-size: .9rem; margin: 0 0 1rem;
}
.notice p:last-child { margin-bottom: 0; }
.notice--info { border-left-color: var(--primary); }
.notice--success { border-left-color: var(--success); background: var(--success-soft); }
.notice--warning { border-left-color: var(--warning); background: var(--warning-soft); }
.notice--error { border-left-color: var(--error); background: var(--error-soft); }
.notice__title { font-weight: 700; display: block; }

.badge {
  display: inline-flex; align-items: center; gap: .3rem;
  font-size: .75rem; font-weight: 700; padding: .15rem .5rem; border-radius: 999px;
  background: var(--surface-alt); border: 1px solid var(--border); color: var(--muted);
}
.badge--ok { background: var(--success-soft); border-color: transparent; color: var(--success); }
.badge--warn { background: var(--warning-soft); border-color: transparent; color: var(--warning); }

/* --- Breadcrumb ---------------------------------------------------------- */
.breadcrumb { font-size: .85rem; color: var(--muted); padding: .8rem 0 0; }
.breadcrumb ol { list-style: none; display: flex; flex-wrap: wrap; gap: .3rem; padding: 0; margin: 0; }
.breadcrumb li { margin: 0; display: flex; gap: .3rem; align-items: center; }
.breadcrumb li + li::before { content: '/'; color: var(--border-strong); }
.breadcrumb a { color: var(--muted); }

/* --- Hero ---------------------------------------------------------------- */
.hero {
  background: linear-gradient(160deg, var(--primary-soft), var(--bg) 65%);
  border-bottom: 1px solid var(--border); padding: 2.5rem 0 2rem;
}
:root[data-theme='dark'] .hero { background: linear-gradient(160deg, #1b2740, var(--bg) 70%); }
.hero h1 { margin-bottom: .6rem; max-width: 20ch; }
.hero__lead { font-size: 1.1rem; color: var(--muted); max-width: 62ch; }
.hero__grid { display: grid; gap: 1.75rem; grid-template-columns: minmax(0, 1fr); align-items: start; }
@media (min-width: 960px) { .hero__grid { grid-template-columns: minmax(0, 1fr) minmax(0, 420px); } }
.value-list { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: .5rem; margin: 1.1rem 0 0; }
.value-list li {
  display: inline-flex; align-items: center; gap: .35rem; margin: 0;
  background: var(--surface); border: 1px solid var(--border); border-radius: 999px;
  padding: .3rem .75rem; font-size: .85rem; font-weight: 600;
}
.value-list li::before { content: '✓'; color: var(--success); font-weight: 800; }

/* --- Tool page layout ---------------------------------------------------- */
.tool-header { padding: 1rem 0 .5rem; }
.tool-header h1 { margin-bottom: .35rem; }
.tool-header__lead { font-size: 1.05rem; color: var(--muted); max-width: 70ch; margin-bottom: .75rem; }
.tool-meta { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: 1rem; }

.tool-layout { display: grid; gap: 1rem; grid-template-columns: minmax(0, 1fr); align-items: start; }
@media (min-width: 900px) {
  .tool-layout { grid-template-columns: minmax(300px, 380px) minmax(0, 1fr); }
  .tool-layout--wide { grid-template-columns: minmax(0, 1fr); }
}
.tool-layout__aside { display: flex; flex-direction: column; gap: 1rem; min-width: 0; }
.tool-layout__main { display: flex; flex-direction: column; gap: 1rem; min-width: 0; }

/* Mobile source order: title, list, action, result, options, history */
@media (max-width: 899px) {
  .tool-layout { display: flex; flex-direction: column; }
}

/* --- Results ------------------------------------------------------------- */
.result-card {
  background: var(--surface); border: 2px solid var(--primary);
  border-radius: var(--radius-lg); padding: 1.25rem; text-align: center;
  box-shadow: var(--shadow);
}
.result-card__label {
  font-size: .8rem; text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted); font-weight: 700; margin-bottom: .35rem;
}
.result-card__value {
  font-size: clamp(1.5rem, 1rem + 3vw, 2.6rem); font-weight: 800; line-height: 1.2;
  overflow-wrap: anywhere; margin: 0;
}
.result-card__meta { color: var(--muted); font-size: .88rem; margin: .5rem 0 0; }
.result-card.is-empty { border-style: dashed; border-color: var(--border-strong); }
.result-card.is-empty .result-card__value { font-size: 1.1rem; color: var(--muted); font-weight: 600; }

.result-list { list-style: none; padding: 0; margin: 0; display: grid; gap: .4rem; }
.result-list li {
  display: flex; align-items: center; gap: .6rem; margin: 0;
  background: var(--surface-alt); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: .45rem .65rem;
}
.result-list__rank {
  min-width: 1.9rem; height: 1.9rem; border-radius: 50%; display: grid; place-items: center;
  background: var(--primary); color: #fff; font-weight: 700; font-size: .82rem; flex: 0 0 auto;
}
:root[data-theme='dark'] .result-list__rank { color: #0b1220; }
.result-list__name { flex: 1; overflow-wrap: anywhere; font-weight: 600; }
.result-list__note { color: var(--muted); font-size: .82rem; }

.chip-list { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: .4rem; }
.chip-list li { margin: 0; }
.chip {
  display: inline-flex; align-items: center; gap: .4rem;
  background: var(--surface-alt); border: 1px solid var(--border); border-radius: 999px;
  padding: .25rem .7rem; font-size: .88rem; overflow-wrap: anywhere;
}
.chip--muted { opacity: .55; text-decoration: line-through; }

/* --- Tables -------------------------------------------------------------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.data th, table.data td {
  text-align: left; padding: .45rem .6rem; border-bottom: 1px solid var(--border);
  overflow-wrap: anywhere;
}
table.data th { font-weight: 700; background: var(--surface-alt); white-space: nowrap; }
table.data tr:last-child td { border-bottom: 0; }
table.data td input[type='number'], table.data td input[type='text'] { min-height: 36px; padding: .25rem .4rem; }

/* --- History ------------------------------------------------------------- */
.history-list { list-style: none; padding: 0; margin: 0; max-height: 320px; overflow-y: auto; }
.history-list li {
  display: flex; gap: .6rem; align-items: flex-start; margin: 0;
  padding: .5rem .25rem; border-bottom: 1px solid var(--border); font-size: .88rem;
}
.history-list li:last-child { border-bottom: 0; }
.history-list__body { flex: 1; min-width: 0; }
.history-list__result { font-weight: 600; overflow-wrap: anywhere; }
.history-list__meta { color: var(--muted); font-size: .78rem; }
.history-empty { color: var(--muted); font-size: .9rem; margin: 0; }

/* --- Toast / live region ------------------------------------------------- */
.toast-stack {
  position: fixed; left: 50%; bottom: 1rem; transform: translateX(-50%);
  z-index: 300; display: flex; flex-direction: column; gap: .4rem;
  width: min(92vw, 420px); pointer-events: none;
}
.toast {
  background: var(--text); color: var(--bg); border-radius: var(--radius);
  padding: .6rem .9rem; font-size: .9rem; box-shadow: var(--shadow-lg);
  animation: rt-toast-in .18s ease-out;
}
.toast--error { background: var(--error); color: #fff; }
@keyframes rt-toast-in { from { opacity: 0; transform: translateY(8px); } }

/* --- Modal --------------------------------------------------------------- */
dialog.modal {
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  background: var(--surface); color: var(--text); padding: 0;
  width: min(94vw, 520px); box-shadow: var(--shadow-lg);
}
dialog.modal::backdrop { background: rgba(9, 13, 20, .55); }
.modal__head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: 1rem 1rem .25rem; }
.modal__head h2 { margin: 0; font-size: 1.15rem; }
.modal__body { padding: .5rem 1rem 1rem; }
.modal__foot { display: flex; flex-wrap: wrap; gap: .5rem; justify-content: flex-end; padding: 0 1rem 1rem; }

/* --- Ads ----------------------------------------------------------------- */
.ad-slot {
  display: grid; place-items: center; margin: 1.5rem auto; width: 100%;
  border: 1px dashed var(--border-strong); border-radius: var(--radius);
  background: var(--surface-alt); color: var(--muted);
  font-size: .72rem; letter-spacing: .12em; text-transform: uppercase;
  /* Height is reserved up front to avoid layout shift when ads load. */
}
.ad-slot--leaderboard { min-height: 90px; max-width: 970px; }
.ad-slot--in-content { min-height: 250px; max-width: 728px; }
.ad-slot--sidebar { min-height: 600px; max-width: 300px; }
.ad-slot--footer { min-height: 250px; max-width: 970px; }
.ad-slot[hidden] { display: none; }

/* --- Content sections ---------------------------------------------------- */
.content { padding: 1rem 0 2rem; }
.content h2 { scroll-margin-top: calc(var(--header-h) + 1rem); }
.content > section { margin-bottom: 2rem; }
.prose { max-width: 72ch; }
.faq details {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); padding: .75rem 1rem; margin-bottom: .6rem;
}
.faq summary { cursor: pointer; font-weight: 700; }
.faq details[open] summary { margin-bottom: .5rem; }
.faq p:last-child { margin-bottom: 0; }

.toc { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .85rem 1rem; }
.toc ul { margin: 0; padding-left: 1.1rem; }
.toc li { margin-bottom: .2rem; font-size: .92rem; }

/* --- Footer -------------------------------------------------------------- */
.site-footer {
  background: var(--surface); border-top: 1px solid var(--border);
  margin-top: 2.5rem; padding: 2rem 0 1.5rem; font-size: .9rem;
}
.site-footer h2 { font-size: .95rem; margin: 0 0 .5rem; }
.footer-grid { display: grid; gap: 1.5rem; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.site-footer ul { list-style: none; padding: 0; margin: 0; }
.site-footer li { margin-bottom: .3rem; }
.site-footer a { color: var(--muted); text-decoration: none; }
.site-footer a:hover { color: var(--primary-strong); text-decoration: underline; }
.footer-bottom {
  border-top: 1px solid var(--border); margin-top: 1.5rem; padding-top: 1rem;
  color: var(--muted); display: flex; flex-wrap: wrap; gap: .5rem; justify-content: space-between;
}

/* --- Full screen --------------------------------------------------------- */
body.is-fullscreen .site-header,
body.is-fullscreen .site-footer,
body.is-fullscreen .ad-slot,
body.is-fullscreen .content,
body.is-fullscreen .breadcrumb,
body.is-fullscreen .tool-header__lead,
body.is-fullscreen .tool-layout__aside,
body.is-fullscreen [data-fs-hide] { display: none !important; }

body.is-fullscreen .tool-layout { grid-template-columns: minmax(0, 1fr); }
body.is-fullscreen .fs-stage {
  position: fixed; inset: 0; z-index: 150; background: var(--bg);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 1rem; padding: 1rem; overflow: auto;
}
.fs-exit { position: fixed; top: 1rem; right: 1rem; z-index: 160; }
.fs-exit[hidden] { display: none; }

/* --- Misc ---------------------------------------------------------------- */
.count-pill {
  font-variant-numeric: tabular-nums; font-weight: 700; font-size: .82rem;
  background: var(--primary-soft); color: var(--primary-strong);
  border-radius: 999px; padding: .1rem .55rem;
}
:root[data-theme='dark'] .count-pill { color: var(--primary); }

.stat-grid { display: grid; gap: .6rem; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); }
.stat {
  background: var(--surface-alt); border: 1px solid var(--border);
  border-radius: var(--radius); padding: .6rem; text-align: center;
}
.stat__value { font-size: 1.4rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat__label { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }

.sr-status { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); }
