/* Shared styles for the single-page tools in /tools. Mirrors home.css tokens. */
:root {
  --bg: #f8f7f4;
  --bg-raise: #ffffff;
  --bg-sunk: #f0eee9;
  --ink: #16171b;
  --muted: #5a5d66;
  --line: #e4e2dc;
  --line-strong: #8f8c84;
  --accent: #4338ca;
  --accent-soft: #eceafd;
  --accent-ink: #ffffff;
  --focus: #1d4ed8;
  --ok: #17734a;
  --ok-bg: #e6f4ec;
  --warn: #8a5300;
  --warn-bg: #fbf0dc;
  --bad: #b42318;
  --bad-bg: #fdeceb;
  --info: #2f5c8f;
  --info-bg: #e8f0f9;
  --tag-local: #17734a;
  --tag-saved: #2f5c8f;
  --tag-key: #8a5300;
  --tag-server: #b4381f;
  --tag-demo: #6b45b8;
  --glow: rgba(67, 56, 202, 0.07);
  --glow-2: rgba(23, 115, 74, 0.05);
  --swash: #dcd9fb;
  --cut: #b42318;
  --cut-bg: #fdeceb;
  --shadow-sm: 0 1px 2px rgba(22, 23, 27, 0.04), 0 1px 1px rgba(22, 23, 27, 0.03);
  --shadow-md: 0 1px 2px rgba(22, 23, 27, 0.04), 0 8px 24px -12px rgba(22, 23, 27, 0.14);
  --shadow-lg: 0 2px 4px rgba(22, 23, 27, 0.04), 0 24px 48px -20px rgba(22, 23, 27, 0.22);
  color-scheme: light;
  --serif: "Iowan Old Style", Palatino, "Palatino Linotype", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --measure: 76rem;
}

/* Dark theme: chosen with the toggle (stored), never forced by default. */
:root[data-theme="dark"] {
  --bg: #141518;
  --bg-raise: #1c1d21;
  --bg-sunk: #101114;
  --ink: #edece9;
  --muted: #a7a8ae;
  --line: #2c2d33;
  --line-strong: #6a6c75;
  --accent: #a5b4fc;
  --accent-soft: #23264a;
  --accent-ink: #14151a;
  --focus: #93c5fd;
  --ok: #6fd4a0;
  --ok-bg: #15291f;
  --warn: #f0c06a;
  --warn-bg: #2e2412;
  --bad: #ff9b8f;
  --bad-bg: #35191a;
  --info: #9cc0ec;
  --info-bg: #172234;
  --tag-local: #6fd4a0;
  --tag-saved: #9cc0ec;
  --tag-key: #f0c06a;
  --tag-server: #ff9f80;
  --tag-demo: #c9b8f5;
  --glow: rgba(165, 180, 252, 0.07);
  --glow-2: rgba(111, 212, 160, 0.04);
  --swash: #3b3f8f;
  --cut: #ff9b8f;
  --cut-bg: #35191a;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px -12px rgba(0, 0, 0, 0.6);
  --shadow-lg: 0 2px 4px rgba(0, 0, 0, 0.3), 0 24px 48px -20px rgba(0, 0, 0, 0.7);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: radial-gradient(1000px 420px at 90% -10%, var(--glow), transparent 60%), var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 1rem;
  line-height: 1.55;
}
a { color: inherit; text-underline-offset: 0.18em; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
main:focus { outline: none; }
code, kbd { font-family: var(--mono); font-size: 0.92em; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip {
  position: absolute; left: 1rem; top: -4rem; z-index: 10;
  background: var(--ink); color: var(--bg);
  padding: 0.6rem 0.9rem; border-radius: 6px; font-weight: 600;
}
.skip:focus { top: 0.5rem; }

.tool-top, .tool-main, .tool-foot {
  width: min(var(--measure), calc(100% - 2rem));
  margin-inline: auto;
}
.tool-top {
  display: flex; justify-content: space-between; align-items: center;
  flex-wrap: wrap; gap: 0 1rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--line);
}
.tool-top a {
  display: inline-flex; align-items: center; min-height: 44px;
  text-decoration: none; color: var(--muted);
}
.tool-top a:hover { color: var(--accent); text-decoration: underline; }
.tool-top .site { font-family: var(--serif); font-weight: 600; color: var(--ink); }
.top-right { display: flex; align-items: center; gap: 0.75rem; }
.theme-toggle {
  display: inline-grid; place-items: center; width: 44px; height: 44px;
  border-radius: 999px; border: 1px solid var(--line); background: var(--bg-raise); color: var(--ink);
  cursor: pointer; box-shadow: var(--shadow-sm);
}
.theme-toggle:hover { border-color: var(--accent); }
.theme-toggle svg { width: 20px; height: 20px; grid-area: 1 / 1; }
.icon-moon { fill: currentColor; }
.icon-sun { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; display: none; }
.icon-sun circle { fill: currentColor; stroke: none; }
:root[data-theme="dark"] .icon-sun { display: block; }
:root[data-theme="dark"] .icon-moon { display: none; }

.tool-main { padding: 1.75rem 0 1rem; }
.tool-intro { max-width: 46rem; margin-bottom: 1.5rem; }
.tool-intro h1 {
  font-family: var(--serif); font-weight: 600;
  font-size: clamp(1.8rem, 4vw, 2.5rem); line-height: 1.1;
  letter-spacing: -0.02em; margin: 0 0 0.6rem;
}
.lede { margin: 0 0 0.75rem; font-size: 1.08rem; color: var(--muted); }
.tags { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0 0 0.75rem; }
.tag {
  display: inline-block; font-family: var(--mono); font-size: 0.8rem; font-weight: 500;
  line-height: 1.4; padding: 0.1rem 0.55rem;
  border: 1px solid currentColor; border-radius: 999px; white-space: nowrap;
}
.tag-local { color: var(--tag-local); }
.tag-saved { color: var(--tag-saved); }
.tag-key { color: var(--tag-key); }
.tag-server { color: var(--tag-server); }
.tag-demo { color: var(--tag-demo); }
.tag-local::before { content: "● "; }
.tag-saved::before { content: "◆ "; }
.tag-key::before { content: "▲ "; }
.tag-server::before { content: "■ "; }
.tag-demo::before { content: "○ "; }

details.how {
  background: var(--bg-raise); border: 1px solid var(--line); border-radius: 0.75rem;
  padding: 0 1rem;
}
details.how summary { cursor: pointer; font-weight: 600; padding: 0.7rem 0; }
details.how ol, details.how ul { margin: 0 0 0.9rem; padding-left: 1.3rem; color: var(--muted); }
details.how li + li { margin-top: 0.3rem; }

/* Layout helpers */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; align-items: start; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; align-items: start; }
.stack { display: grid; gap: 1rem; align-content: start; }
.row { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.row-between { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; justify-content: space-between; }

.panel {
  background: var(--bg-raise); border: 1px solid var(--line); border-radius: 0.9rem;
  padding: 1rem 1.1rem 1.1rem; min-width: 0; box-shadow: var(--shadow-sm);
}
.panel > h2, .panel-title {
  font-size: 1.05rem; font-weight: 650; margin: 0 0 0.6rem; letter-spacing: -0.005em;
}
.hint { color: var(--muted); font-size: 0.92rem; margin: 0 0 0.6rem; }
.meta { font-family: var(--mono); font-size: 0.85rem; color: var(--muted); }

/* Forms */
label { font-weight: 600; }
.field { display: grid; gap: 0.3rem; margin-bottom: 0.85rem; }
.field > span.hint { margin: 0; font-weight: 400; }
textarea, input[type="text"], input[type="password"], input[type="search"], select {
  width: 100%; font: inherit; color: var(--ink);
  background: var(--bg); border: 1px solid var(--line-strong); border-radius: 0.5rem;
  padding: 0.55rem 0.7rem; min-height: 44px;
}
textarea { font-family: var(--mono); font-size: 0.92rem; line-height: 1.5; resize: vertical; min-height: 9rem; }
textarea:focus, input:focus, select:focus { border-color: var(--focus); }
input[type="range"] { width: 100%; accent-color: var(--accent); min-height: 32px; }
.check { display: flex; gap: 0.55rem; align-items: flex-start; font-weight: 400; padding: 0.3rem 0; cursor: pointer; }
.check input { width: 1.15rem; height: 1.15rem; margin: 0.15rem 0 0; accent-color: var(--accent); flex: none; }
.check small { display: block; color: var(--muted); font-size: 0.88rem; }
fieldset { border: 0; padding: 0; margin: 0 0 0.85rem; min-width: 0; }
legend { font-weight: 650; padding: 0; margin-bottom: 0.3rem; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  min-height: 44px; padding: 0.5rem 1rem;
  font: inherit; font-weight: 600; cursor: pointer;
  background: var(--ink); color: var(--bg-raise);
  border: 1px solid var(--ink); border-radius: 999px;
  text-decoration: none;
}
.btn:hover { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-quiet { background: transparent; color: var(--ink); border-color: var(--line-strong); }
.btn-quiet:hover { background: var(--bg-sunk); color: var(--ink); border-color: var(--ink); }
.btn-small { min-height: 36px; padding: 0.3rem 0.75rem; font-size: 0.92rem; }
.btn[disabled] { opacity: 0.55; cursor: not-allowed; }
.btn[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

/* Output */
.output {
  font-family: var(--mono); font-size: 0.92rem; line-height: 1.55;
  white-space: pre-wrap; overflow-wrap: anywhere;
  background: var(--bg); border: 1px solid var(--line); border-radius: 0.5rem;
  padding: 0.75rem; min-height: 6rem; max-height: 32rem; overflow: auto; margin: 0;
}
.output.empty { color: var(--muted); font-family: var(--sans); }
.log { max-height: 20rem; }
.log li { list-style: none; }
.log { padding-left: 0.75rem; }
.log time { color: var(--muted); margin-right: 0.5rem; }

.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(8rem, 1fr)); gap: 0.6rem; margin: 0 0 0.75rem; }
.stat { background: var(--bg); border: 1px solid var(--line); border-radius: 0.6rem; padding: 0.55rem 0.7rem; }
.stat dt { font-size: 0.85rem; color: var(--muted); font-weight: 400; }
.stat dd { margin: 0; font-family: var(--mono); font-size: 1.25rem; font-weight: 600; }

.meter { height: 14px; background: var(--bg-sunk); border: 1px solid var(--line); border-radius: 999px; overflow: hidden; display: flex; }
.meter > span { display: block; height: 100%; }

.badge {
  display: inline-block; font-family: var(--mono); font-size: 0.82rem; font-weight: 600;
  padding: 0.1rem 0.5rem; border-radius: 0.35rem; border: 1px solid currentColor; white-space: nowrap;
}
.badge-ok { color: var(--ok); background: var(--ok-bg); }
.badge-warn { color: var(--warn); background: var(--warn-bg); }
.badge-bad { color: var(--bad); background: var(--bad-bg); }
.badge-info { color: var(--info); background: var(--info-bg); }
.badge-idle { color: var(--muted); background: var(--bg); }

.notice { border-left: 4px solid var(--warn); background: var(--warn-bg); padding: 0.6rem 0.8rem; border-radius: 0.4rem; margin: 0 0 0.85rem; }
.notice.info { border-color: var(--info); background: var(--info-bg); }
.notice.bad { border-color: var(--bad); background: var(--bad-bg); }
.notice p { margin: 0; }

.tool-foot {
  margin-top: 2.5rem; padding: 1.25rem 0 2rem; border-top: 1px solid var(--line);
  color: var(--muted); font-size: 0.95rem;
}
.tool-foot p { margin: 0 0 0.4rem; max-width: 60ch; }
.tool-foot a { color: var(--ink); }

@media (max-width: 860px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
@media (forced-colors: active) {
  .tag, .badge, .panel, .meter { border: 1px solid CanvasText; }
  .meter > span { background: Highlight !important; }
}
