/* ToolLamp shared styles. Tokens first; every color comes from a token. */
:root {
  --bg: #F1F3EC;
  --surface: #FFFFFF;
  --field: #FAFBF7;
  --text: #26221C;
  --muted: #5E5A50;
  --line: #D3D7C9;
  --accent: #46622F;
  --accent-ink: #FFFFFF;
  --lamp: #9A6F1E;
  --danger: #B3362A;
  --radius-sm: 6px;
  --radius-lg: 14px;
  --font-display: "Bricolage Grotesque", "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  --font-body: system-ui, -apple-system, "Segoe UI", "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1C1A16; --surface: #25221D; --field: #2C2923; --text: #ECE7DC;
    --muted: #A9A396; --line: #3A362E; --accent: #9DBE7A; --accent-ink: #1C1A16;
    --lamp: #D9AE52; --danger: #F08A7E;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1C1A16; --surface: #25221D; --field: #2C2923; --text: #ECE7DC;
  --muted: #A9A396; --line: #3A362E; --accent: #9DBE7A; --accent-ink: #1C1A16;
  --lamp: #D9AE52; --danger: #F08A7E;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.7 var(--font-body); }
img, svg { max-width: 100%; }
a { color: var(--accent); text-underline-offset: 3px; }
:focus-visible { outline: 3px solid var(--lamp); outline-offset: 2px; }

.wrap { width: min(100% - 2.5rem, 52rem); margin-inline: auto; }

/* Header */
.site-header { border-bottom: 1px solid var(--line); }
.site-header .wrap { display: flex; align-items: center; gap: 1rem; min-height: 4rem; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: .55rem; color: var(--text); text-decoration: none;
  font: 700 1.25rem/1 var(--font-display); letter-spacing: -.01em; }
.brand svg { width: 1.9rem; height: 1.9rem; flex: none; }
.site-nav { display: flex; gap: 1.1rem; margin-left: auto; align-items: center; font-size: .95rem; }
.site-nav a { color: var(--muted); text-decoration: none; }
.site-nav a:hover, .site-nav a[aria-current="page"] { color: var(--text); }
.theme-toggle { background: none; border: 1px solid var(--line); color: var(--muted); border-radius: 999px;
  width: 2.2rem; height: 2.2rem; cursor: pointer; font-size: 1rem; line-height: 1; }
.theme-toggle:hover { color: var(--text); }

/* Page heading */
.page-head { padding: 2.5rem 0 1.5rem; }
.page-head h1 { font: 700 clamp(1.8rem, 5vw, 2.6rem)/1.15 var(--font-display); margin: 0 0 .6rem; letter-spacing: -.02em; }
.page-head p { margin: 0; color: var(--muted); max-width: 40rem; }
.crumbs { font-size: .85rem; color: var(--muted); margin-bottom: .8rem; }
.crumbs a { color: var(--muted); }

/* Tool panel */
.tool { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg);
  padding: clamp(1.1rem, 4vw, 1.8rem); }
.tool + .tool { margin-top: 1.2rem; }
.tool h2 { font: 650 1.15rem/1.3 var(--font-display); margin: 0 0 1rem; }
.row { display: flex; flex-wrap: wrap; gap: 1rem; align-items: end; }
.row + .row { margin-top: 1rem; }
.field { display: flex; flex-direction: column; gap: .3rem; flex: 1 1 12rem; min-width: 0; }
.field label { font-size: .9rem; color: var(--muted); }
input, select, button { font: inherit; }
input, select { width: 100%; padding: .6rem .75rem; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--field); color: var(--text); }
input:focus, select:focus { border-color: var(--accent); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; padding: 3px; gap: 3px; margin-bottom: 1rem; }
.seg button { border: 0; background: none; color: var(--muted); padding: .35rem .9rem; border-radius: 999px; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
/* A labelled .seg below the inputs: <div class="choice"><span id=…>label</span><div class="seg" aria-labelledby=…></div></div> */
.choice { margin-top: 1rem; }
.choice > span { display: block; font-size: .9rem; color: var(--muted); }
.choice .seg { margin: .3rem 0 0; }
.choice + .row { margin-top: 1rem; }

.result { margin-top: 1.2rem; padding-top: 1.2rem; border-top: 1px dashed var(--line); }
.result-main { font: 700 clamp(1.6rem, 6vw, 2.3rem)/1.2 var(--font-display); letter-spacing: -.01em; overflow-wrap: anywhere; }
.result-sub { color: var(--muted); margin-top: .3rem; }
.result-list { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1.2rem; margin: .8rem 0 0; }
.result-list dt { color: var(--muted); }
.result-list dd { margin: 0; min-width: 0; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.copy-btn { border: 1px solid var(--line); background: none; color: var(--muted); border-radius: var(--radius-sm);
  padding: .05rem .5rem; margin-left: .5rem; cursor: pointer; font-size: .8rem; vertical-align: middle; }
.notice { color: var(--lamp); font-size: .92rem; margin-top: .6rem; }
.error { color: var(--danger); }

/* Affiliate slot: rendered by affiliates.js, hidden while empty (see AGENTS.md) */
/* One line under the tool panels, linking to the feedback form with this page prefilled. */
.feedback { margin: .8rem 0 0; color: var(--muted); font-size: .9rem; }

.affiliate { margin-top: 1.2rem; border: 1px solid var(--line); border-left: 4px solid var(--lamp);
  border-radius: var(--radius-sm); padding: .9rem 1.1rem; background: var(--surface); font-size: .95rem; }
.affiliate h2 { font: 650 1rem/1.3 var(--font-display); margin: 0 0 .5rem; }
.affiliate ul { list-style: none; padding: 0; margin: 0; }
.affiliate li + li { margin-top: .5rem; }
.affiliate li a { font-weight: 650; }
.affiliate li span { display: block; color: var(--muted); }
.affiliate small { display: block; color: var(--muted); margin-top: .4rem; font-size: .8rem; }

/* Article content */
.article { padding: 2.5rem 0 1rem; max-width: 40rem; }
.article h2 { font: 650 1.35rem/1.3 var(--font-display); margin: 2.2rem 0 .6rem; }
.article h3 { font-size: 1.05rem; margin: 1.4rem 0 .3rem; }
.article ul { padding-left: 1.3rem; }
.page-head + .article { padding-top: 0; }
.page-head + .article > h2:first-child { margin-top: 1rem; }
.article li + li { margin-top: .3rem; }
.table-scroll { overflow-x: auto; }
.article table { border-collapse: collapse; width: 100%; font-size: .95rem; }
.article th, .article td { border-bottom: 1px solid var(--line); padding: .45rem .6rem; text-align: left; white-space: nowrap; }
.article th { color: var(--muted); font-weight: 600; }

/* Tool index (home pages) */
/* Each group (my favorites, a category, related tools) is a card, so the groups read as separate blocks. */
.tool-group { margin: 1.5rem 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg);
  padding: 1.1rem clamp(1rem, 3vw, 1.5rem) .3rem; }
.tool-group h2 { font: 650 1.2rem/1.3 var(--font-display); margin: 0 0 .4rem; color: var(--accent); }
.tool-list { list-style: none; padding: 0; margin: 0; }
.tool-list li + li { border-top: 1px solid var(--line); }
.tool-list a { display: grid; grid-template-columns: auto 1fr auto; column-gap: .9rem; align-items: center;
  padding: .75rem .2rem; text-decoration: none; color: var(--text); }
.tool-list a:hover .tool-name { color: var(--accent); }
.tool-name { font-weight: 650; }
.tool-desc { color: var(--muted); font-size: .92rem; text-align: right; }

/* Tool icons: a tinted tile holding a line icon from /assets/icons.svg (id = the tool's slug).
   Green for electronics, gold (.warm) for everyday and finance. The line color comes from the tile's color. */
.tile { flex: none; display: inline-grid; place-items: center; width: 2.5rem; height: 2.5rem; border-radius: 11px;
  color: var(--accent); background: var(--field); background: color-mix(in srgb, var(--accent) 15%, transparent); }
.tile.warm { color: var(--lamp); background: var(--field); background: color-mix(in srgb, var(--lamp) 18%, transparent); }
.ico { width: 1.5rem; height: 1.5rem; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.page-head h1 { display: flex; align-items: center; gap: .7rem; }
.page-head h1 .tile { width: 2.9rem; height: 2.9rem; border-radius: 13px; }
.page-head h1 .ico { width: 1.75rem; height: 1.75rem; }

/* Circuit diagram next to a panel's inputs (inline SVG, drawn in the text color) */
.with-schematic { display: flex; gap: 1.2rem; align-items: center; flex-wrap: wrap; }
.with-schematic .row { flex: 1 1 16rem; }
.schematic { flex: 0 0 7.5rem; width: 7.5rem; color: var(--text); }
.schematic .wire { stroke: currentColor; stroke-width: 2; fill: none; }
.schematic .part { stroke: currentColor; stroke-width: 2; fill: var(--surface); }
.schematic text { fill: currentColor; font: 600 13px var(--font-body); }
.schematic .dot { fill: currentColor; }
.schematic .unknown { fill: var(--lamp); }
.schematic-wide { display: block; width: 100%; max-width: 30rem; height: auto; margin: 1rem 0; }

/* Tables inside tool panels (results such as E24 options or baud rate tables) */
.tool table { border-collapse: collapse; width: 100%; font-size: .95rem; margin-top: 1rem; font-variant-numeric: tabular-nums; }
.tool th, .tool td { border-bottom: 1px solid var(--line); padding: .4rem .5rem .4rem 0; text-align: left; }
.tool th { color: var(--muted); font-weight: 600; }
.tool tr.best td { font-weight: 700; }

/* Favorites (filled by /assets/favorites.js) */
.fav-btn { margin: 0 0 .8rem; border: 1px solid var(--line); background: none; color: var(--muted); border-radius: 999px;
  padding: .3rem .9rem; cursor: pointer; font-size: .9rem; }
.fav-btn:hover { color: var(--text); border-color: var(--muted); }
.fav-btn[aria-pressed="true"] { color: var(--lamp); border-color: var(--lamp); }
.fav-list li { display: flex; align-items: center; }
.fav-list li a { flex: 1; min-width: 0; }
.fav-remove { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 1.2rem; line-height: 1; padding: .3rem .5rem; }
.fav-remove:hover { color: var(--danger); }
.fav-share { margin: .5rem 0 .9rem; }
.fav-group { border-left: 4px solid var(--lamp); }
.fav-group h2 { color: var(--lamp); }
.fav-empty { margin: 0 0 .9rem; color: var(--muted); font-size: .95rem; }
.fav-link { margin: 0 0 .9rem; font-size: .9rem; color: var(--muted); }
.fav-link input { margin-top: .3rem; font-size: .85rem; }
.fav-offer { margin: 1.5rem 0 0; padding: .7rem 1rem; background: var(--surface); border: 1px solid var(--line);
  border-left: 4px solid var(--lamp); border-radius: var(--radius-sm); font-size: .95rem; }
.fav-offer button { margin: .4rem .5rem 0 0; border: 1px solid var(--line); background: none; color: var(--text);
  border-radius: 999px; padding: .3rem .9rem; cursor: pointer; }
.fav-offer .fav-accept { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

/* Home hero */
.hero { padding: 3.5rem 0 1rem; display: grid; grid-template-columns: auto 1fr; gap: 1.6rem; align-items: center; }
.hero svg { width: clamp(4.5rem, 14vw, 7rem); height: auto; }
.hero h1 { font: 800 clamp(2.4rem, 8vw, 4rem)/1 var(--font-display); margin: 0; letter-spacing: -.035em; }
.hero p { margin: .7rem 0 0; color: var(--muted); }

/* Footer */
.site-footer { border-top: 1px solid var(--line); margin-top: 3rem; padding: 1.6rem 0 2.4rem; color: var(--muted); font-size: .85rem; }
.site-footer p { margin: .3rem 0; }
.footer-links { display: flex; flex-wrap: wrap; gap: .3rem 1.1rem; }
.footer-links span { display: contents; }
.site-footer a { color: var(--muted); }
.site-footer a:hover { color: var(--text); }

@media (max-width: 560px) {
  .tool-list a { grid-template-columns: auto 1fr; row-gap: .1rem; }
  .tool-list .tile { grid-row: span 2; }
  .tool-desc { grid-column: 2; text-align: left; }
  .hero { grid-template-columns: 1fr; padding-top: 2.2rem; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* Offer to switch to the reader's language (added by site.js) */
.lang-offer { background: var(--surface); border-bottom: 1px solid var(--line); font-size: .92rem; }
.lang-offer .wrap { display: flex; align-items: center; gap: .4rem 1rem; flex-wrap: wrap; padding-block: .55rem; }
.lang-offer span { color: var(--muted); }
.lang-offer a { font-weight: 600; }
.lang-offer button { margin-left: auto; background: none; border: 0; color: var(--muted); cursor: pointer;
  font-size: 1.2rem; line-height: 1; padding: .2rem .4rem; }
.lang-offer button:hover { color: var(--text); }

/* Ad slot, reserved for later (see AGENTS.md "Ad slots"). No page uses it yet.
   The fixed height keeps the layout from jumping when an ad loads:
   a 20px label + 280px, the tallest common responsive ad on phones. */
.ad-slot { display: block; min-height: 300px; margin: 2rem 0; text-align: center; }
.ad-slot::before { content: attr(data-label); display: block; height: 20px; line-height: 20px;
  font-size: .75rem; color: var(--muted); letter-spacing: .04em; }
