/* The Toolbox — workshop theme.
   Dark walnut by default, a daylight version for bright rooms.
   Tools hang on a pegboard; each drawer (group) has its own paint colour. */

@font-face { font-family: 'Bricolage'; src: url(fonts/bricolage.woff2) format('woff2'); font-weight: 200 800; font-display: swap; }
@font-face { font-family: 'JetBrains Mono'; src: url(fonts/jetbrains-mono.woff2) format('woff2'); font-weight: 100 800; font-display: swap; }

:root {
  --bg: #16120f;
  --bg-2: #1e1915;
  --panel: #251f1a;
  --panel-2: #2e2620;
  --line: #3b3129;
  --ink: #f1e7da;
  --ink-2: #c3b4a3;
  --ink-3: #8f8070;
  --peg: rgba(0, 0, 0, .38);
  --peg-hi: rgba(255, 235, 210, .05);
  --accent: #e8a33d;
  --accent-ink: #1b1309;
  --good: #7fc28a;
  --bad: #ef7b67;
  --mark: rgba(232, 163, 61, .32);
  --ins: rgba(127, 194, 138, .22);
  --del: rgba(239, 123, 103, .22);
  --g-crypto: #e8a33d;
  --g-convert: #5fb8b0;
  --g-dev: #e0764f;
  --g-everyday: #a6b86a;
  --g-fav: #f0c95c;
  --g-recent: #b9a48d;
  --shadow: 0 1px 0 rgba(255, 240, 220, .04) inset, 0 6px 18px rgba(0, 0, 0, .35);
  --radius: 14px;
  --font: 'Bricolage', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f3ece1; --bg-2: #ebe2d4; --panel: #fffaf3; --panel-2: #f6eee2; --line: #ddd0bd;
    --ink: #2a211a; --ink-2: #5c4f43; --ink-3: #8a7b6c;
    --peg: rgba(80, 55, 30, .22); --peg-hi: rgba(255, 255, 255, .5);
    --accent: #c27a12; --accent-ink: #fffaf3; --good: #2f8a43; --bad: #c4432c;
    --mark: rgba(232, 163, 61, .35); --ins: rgba(47, 138, 67, .16); --del: rgba(196, 67, 44, .14);
    --g-crypto: #c27a12; --g-convert: #23847b; --g-dev: #c2512a; --g-everyday: #6f8330; --g-fav: #b8900f; --g-recent: #8a7259;
    --shadow: 0 1px 0 rgba(255, 255, 255, .7) inset, 0 4px 14px rgba(90, 60, 30, .10);
    color-scheme: light;
  }
}
:root[data-theme="light"] {
  --bg: #f3ece1; --bg-2: #ebe2d4; --panel: #fffaf3; --panel-2: #f6eee2; --line: #ddd0bd;
  --ink: #2a211a; --ink-2: #5c4f43; --ink-3: #8a7b6c;
  --peg: rgba(80, 55, 30, .22); --peg-hi: rgba(255, 255, 255, .5);
  --accent: #c27a12; --accent-ink: #fffaf3; --good: #2f8a43; --bad: #c4432c;
  --mark: rgba(232, 163, 61, .35); --ins: rgba(47, 138, 67, .16); --del: rgba(196, 67, 44, .14);
  --g-crypto: #c27a12; --g-convert: #23847b; --g-dev: #c2512a; --g-everyday: #6f8330; --g-fav: #b8900f; --g-recent: #8a7259;
  --shadow: 0 1px 0 rgba(255, 255, 255, .7) inset, 0 4px 14px rgba(90, 60, 30, .10);
  color-scheme: light;
}

[data-group="crypto"] { --g: var(--g-crypto); }
[data-group="convert"] { --g: var(--g-convert); }
[data-group="dev"] { --g: var(--g-dev); }
[data-group="everyday"] { --g: var(--g-everyday); }
[data-group="fav"] { --g: var(--g-fav); }
[data-group="recent"] { --g: var(--g-recent); }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 18px/1.5 var(--font);
  min-height: 100vh;
}
a { color: inherit; }
h1, h2, h3 { line-height: 1.15; letter-spacing: -.01em; }
h3 { margin: 0 0 .6rem; font-size: 1.1rem; }
code, .mono { font-family: var(--mono); font-size: .92em; }
.icon { display: inline-flex; flex: none; }
[hidden] { display: none !important; }

/* --- top bar ------------------------------------------------------------ */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 14px;
  padding: calc(10px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 750; font-size: 1.2rem; text-decoration: none; white-space: nowrap;
  color: var(--accent);
}
.brand span:last-child { color: var(--ink); }
.searchbox {
  flex: 1; max-width: 560px; margin-left: auto;
  display: flex; align-items: center; gap: 8px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 0 12px; height: 46px; color: var(--ink-3);
}
.searchbox:focus-within { border-color: var(--accent); }
.searchbox input {
  flex: 1; min-width: 0; border: 0; background: none; color: var(--ink);
  font: inherit; font-size: 1rem; outline: none; height: 100%;
}
.searchbox input::-webkit-search-cancel-button { display: none; }
kbd {
  font: 600 .8rem var(--mono); color: var(--ink-3);
  border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 6px; padding: 1px 7px;
}

/* --- layout -------------------------------------------------------------- */
.layout { display: grid; grid-template-columns: 260px minmax(0, 1fr); max-width: 1400px; margin: 0 auto; }
.sidebar {
  position: sticky; top: 67px; align-self: start;
  height: calc(100vh - 67px); overflow-y: auto;
  padding: 18px 12px 40px 16px;
  border-right: 1px solid var(--line);
}
.nav-group { margin-bottom: 18px; }
.nav-title { display: block; font-size: .78rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); margin: 0 10px 6px; }
.sidebar a {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 10px; border-radius: 9px;
  text-decoration: none; color: var(--ink-2); font-size: .95rem;
}
.sidebar a .icon { color: var(--g); opacity: .9; }
.sidebar a:hover { background: var(--panel); color: var(--ink); }
.sidebar a.on { background: var(--panel-2); color: var(--ink); box-shadow: inset 3px 0 0 var(--g); }
.sidebar .fav-dot { margin-left: auto; color: var(--g-fav); font-size: .8rem; }
main { padding: 26px clamp(16px, 3vw, 40px) 80px; min-width: 0; }

/* --- home: the pegboard -------------------------------------------------- */
.hero { margin: 4px 0 26px; }
.hero h1 { font-size: clamp(2.2rem, 5vw, 3.4rem); font-weight: 800; margin: 0 0 8px; }
.hero p { margin: 0; color: var(--ink-2); max-width: 46ch; font-size: 1.08rem; }
.search-sum { color: var(--ink-2); margin: 0 0 16px; }
.shelf { margin-bottom: 30px; }
.shelf header { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin: 0 0 10px; }
.shelf h2 { margin: 0; font-size: 1.3rem; display: flex; align-items: center; gap: 10px; }
.shelf h2::before { content: ''; width: 12px; height: 12px; border-radius: 3px; background: var(--g); }
.shelf header p { margin: 0; color: var(--ink-3); font-size: .95rem; }
.board {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px;
  padding: 16px; border-radius: 18px;
  background-color: var(--bg-2);
  background-image:
    radial-gradient(circle at center, var(--peg) 0 2.6px, transparent 3.2px),
    radial-gradient(circle at center, var(--peg-hi) 0 3.4px, transparent 3.8px);
  background-size: 26px 26px, 26px 26px;
  background-position: 13px 13px, 13px 14px;
  border: 1px solid var(--line);
}
.tool-card {
  position: relative;
  display: flex; gap: 14px; align-items: flex-start;
  padding: 18px 16px 16px; border-radius: var(--radius);
  background: var(--panel); border: 1px solid var(--line);
  border-top: 4px solid var(--g);
  box-shadow: var(--shadow);
  text-decoration: none;
  transition: transform .15s ease, border-color .15s ease;
}
.tool-card:hover, .tool-card:focus-visible { transform: translateY(-2px) rotate(-.4deg); border-color: var(--g); outline: none; }
.tool-card .hook {
  position: absolute; top: -10px; left: 50%; width: 14px; height: 14px; margin-left: -7px;
  border-radius: 50%; background: var(--bg-2); border: 3px solid var(--line);
}
.tool-icon {
  display: grid; place-items: center; flex: none;
  width: 48px; height: 48px; border-radius: 12px;
  background: color-mix(in srgb, var(--g) 16%, transparent); color: var(--g);
}
.tool-icon.big { width: 60px; height: 60px; border-radius: 15px; }
.tool-text { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.tool-text strong { font-size: 1.06rem; font-weight: 650; }
.tool-text span { color: var(--ink-3); font-size: .9rem; line-height: 1.35; }
.tool-card .fav-dot { position: absolute; top: 8px; right: 10px; color: var(--g-fav); font-size: .85rem; }
.empty { padding: 40px; text-align: center; color: var(--ink-3); }

/* --- tool page ----------------------------------------------------------- */
.tool-head { margin-bottom: 20px; }
.back { display: inline-block; color: var(--ink-3); text-decoration: none; font-size: .95rem; margin-bottom: 12px; padding: 4px 0; }
.back:hover { color: var(--accent); }
.title-row { display: flex; align-items: center; gap: 16px; }
.title-row h1 { margin: 0; font-size: clamp(1.7rem, 4vw, 2.3rem); font-weight: 780; }
.eyebrow { font-size: .78rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--g); }
.lede { color: var(--ink-2); margin: 10px 0 0; max-width: 60ch; }
.star {
  margin-left: auto; width: 46px; height: 46px; border-radius: 12px; flex: none;
  display: grid; place-items: center;
  background: var(--panel); border: 1px solid var(--line); color: var(--ink-3); cursor: pointer;
}
.star.on { color: var(--g-fav); border-color: var(--g-fav); }
.star.on svg { fill: currentColor; }
.tool-body { display: flex; flex-direction: column; gap: 16px; max-width: 1000px; }

.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; display: flex; flex-direction: column; gap: 14px; min-width: 0;
  box-shadow: var(--shadow);
}
.card.center { align-items: center; }
details.card { display: block; }
details.card > summary { cursor: pointer; font-weight: 600; color: var(--ink-2); }
details.card[open] > summary { margin-bottom: 12px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); gap: 16px; }
.row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; }
.row > .field { flex: 1 1 140px; }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-label { font-size: .85rem; font-weight: 650; color: var(--ink-2); }
.field-hint { font-size: .85rem; color: var(--ink-3); margin: 0; }
.input {
  width: 100%; font: inherit; font-size: 1rem; color: var(--ink);
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 11px 12px; min-height: 46px; outline: none;
}
.input.mono { font-family: var(--mono); font-size: .92rem; }
textarea.input { resize: vertical; line-height: 1.5; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.input[readonly] { background: color-mix(in srgb, var(--bg-2) 60%, var(--panel)); }
select.input { appearance: none; padding-right: 36px; cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-3) 50%), linear-gradient(135deg, var(--ink-3) 50%, transparent 50%);
  background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%; background-size: 6px 6px; background-repeat: no-repeat; }
input[type="range"] { accent-color: var(--accent); width: 100%; height: 30px; }
input[type="number"].input { max-width: 100%; }

.checks { display: flex; flex-wrap: wrap; gap: 8px 18px; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; min-height: 36px; }
.check input { width: 22px; height: 22px; accent-color: var(--accent); margin: 0; }

.btn {
  font: inherit; font-weight: 600; font-size: .98rem;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 0 18px; border-radius: 11px; cursor: pointer;
  background: var(--panel-2); color: var(--ink); border: 1px solid var(--line);
}
.btn:hover { border-color: var(--ink-3); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.small { min-height: 32px; padding: 0 12px; font-size: .85rem; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: wait; }
.icon-btn { width: 46px; padding: 0; flex: none; }

.output { display: flex; flex-direction: column; gap: 6px; }
.output-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; min-height: 32px; }
.output-head h3 { margin: 0; }

.tabs { display: inline-flex; flex-wrap: wrap; gap: 4px; padding: 4px; background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px; align-self: flex-start; }
.tabs button {
  font: inherit; font-size: .92rem; font-weight: 600; color: var(--ink-2);
  border: 0; background: none; border-radius: 9px; padding: 0 14px; min-height: 38px; cursor: pointer;
}
.tabs button.on { background: var(--panel-2); color: var(--ink); box-shadow: inset 0 -2px 0 var(--accent); }

.note { font-size: .9rem; color: var(--ink-3); padding: 8px 12px; border-radius: 9px; background: var(--bg-2); }
.note.error { color: var(--bad); background: color-mix(in srgb, var(--bad) 12%, transparent); }
.verdict { font-weight: 700; font-size: 1.1rem; }
.verdict:empty { display: none; }
.verdict.good { color: var(--good); }
.verdict.bad { color: var(--bad); }

.meter { height: 8px; border-radius: 99px; background: var(--bg-2); overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--bad); transition: width .2s; }
.meter[data-level="ok"] i { background: var(--accent); }
.meter[data-level="strong"] i { background: var(--good); }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; margin: 0; }
.kv:empty { display: none; }
.kv dt { color: var(--ink-3); font-size: .92rem; }
.kv dd { margin: 0; font-family: var(--mono); font-size: .9rem; word-break: break-all; }

.table { border-collapse: collapse; width: 100%; font-size: .95rem; }
.table:empty { display: none; }
.table th, .table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.table td { font-family: var(--mono); font-size: .88rem; word-break: break-all; }
.table th { color: var(--ink-3); font-weight: 600; }
.perm td, .perm th { text-align: center; }
.perm tr > th:first-child { text-align: left; }
.cell { display: grid; place-items: center; min-height: 44px; cursor: pointer; }
.cell input { width: 26px; height: 26px; accent-color: var(--accent); margin: 0; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  font: inherit; font-size: .88rem; color: var(--ink-2);
  border: 1px solid var(--line); background: var(--bg-2); border-radius: 99px;
  padding: 0 14px; min-height: 36px; cursor: pointer;
}
.chip:hover { border-color: var(--accent); color: var(--ink); }
.pill {
  display: inline-block; font-size: .82rem; font-family: var(--mono);
  padding: 3px 10px; border-radius: 99px; background: var(--bg-2); border: 1px solid var(--line); color: var(--ink-2);
}
.pill:empty { display: none; }

pre.hl, pre.diffview, pre.mono-block {
  margin: 0; padding: 14px; border-radius: 10px; background: var(--bg-2); border: 1px solid var(--line);
  font: .9rem/1.6 var(--mono); white-space: pre-wrap; word-break: break-word; min-height: 3em;
}
pre.hl mark { background: var(--mark); color: inherit; border-radius: 3px; box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 50%, transparent); }
pre.diffview ins { background: var(--ins); color: var(--good); text-decoration: none; }
pre.diffview del { background: var(--del); color: var(--bad); }
.matches { margin: 0; padding-left: 1.4em; display: flex; flex-direction: column; gap: 6px; }
.matches:empty { display: none; }
.groups { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.runs { margin: 0; padding-left: 1.4em; font-family: var(--mono); font-size: .95rem; line-height: 1.9; }
.big-say { font-size: 1.25rem; font-weight: 650; margin: 0; color: var(--accent); }
.big-say:empty { display: none; }

.drop {
  display: grid; place-items: center; text-align: center; min-height: 130px; padding: 20px;
  border: 2px dashed var(--line); border-radius: var(--radius); color: var(--ink-3); cursor: pointer;
}
.drop.over, .drop:hover { border-color: var(--accent); color: var(--ink); }
.preview:empty { display: none; }
.preview img, .preview svg { max-width: 100%; height: auto; max-height: 360px; display: block; margin: 0 auto; border-radius: 8px; }
.swatch { height: 90px; border-radius: 12px; border: 1px solid var(--line); }
.swatch-input { width: 64px; height: 46px; padding: 3px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg-2); cursor: pointer; }
.contrast { padding: 14px 16px; border-radius: 12px; border: 1px solid var(--line); font-size: .95rem; }
.contrast strong { font-size: 1.4rem; margin-right: 6px; }
canvas.qr { width: min(100%, 340px); height: auto; aspect-ratio: 1; border-radius: 12px; border: 1px solid var(--line); image-rendering: pixelated; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.stat { display: flex; flex-direction: column; padding: 14px; border-radius: 12px; background: var(--bg-2); border: 1px solid var(--line); }
.stat strong { font-size: 1.6rem; font-weight: 750; font-variant-numeric: tabular-nums; }
.stat span { font-size: .85rem; color: var(--ink-3); }

#toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 50;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--bg); font-weight: 650;
  padding: 10px 20px; border-radius: 99px; transition: .2s ease;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* --- phone --------------------------------------------------------------- */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  main { padding-top: 18px; padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
  .board { grid-template-columns: 1fr; padding: 12px; gap: 12px; }
  .searchbox kbd { display: none; }
}
@media (max-width: 520px) {
  .brand span:last-child { display: none; }
  .tool-card { padding: 16px 14px 14px; }
  .card { padding: 14px; }
  .title-row { gap: 12px; }
  .tool-icon.big { width: 50px; height: 50px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* Phone: tighter cards so more tools fit on a screen, and results above settings. */
@media (max-width: 900px) {
  .preview-first > .card.center { order: -1; }
}
@media (max-width: 520px) {
  .tool-card { gap: 12px; align-items: center; padding: 14px 12px 12px; }
  .tool-card .tool-icon { width: 42px; height: 42px; border-radius: 11px; }
  .tool-text span { display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; }
  .board { gap: 10px; }
  .hero h1 { font-size: 2rem; }
  .hero p { font-size: 1rem; }
}

/* Field label row with an optional Paste button. */
.field-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 32px; }
.btn.ghost { background: none; color: var(--ink-3); }
.btn.ghost:hover { color: var(--ink); }
.row.tight { gap: 6px; align-items: center; flex-wrap: nowrap; }
.linkish { font: inherit; font-size: .9rem; color: var(--ink-3); background: none; border: 0; padding: 0 4px; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.linkish:hover { color: var(--accent); }

/* --- new tools ------------------------------------------------------------ */
.meter.big { height: 12px; }
.tips { margin: 0; padding-left: 1.2em; display: flex; flex-direction: column; gap: 6px; color: var(--ink-2); }
.tips:empty { display: none; }
.kv.wide { grid-template-columns: minmax(130px, max-content) 1fr; }
.output.hit .input { border-color: var(--good); box-shadow: 0 0 0 3px color-mix(in srgb, var(--good) 22%, transparent); }
.md-frame { width: 100%; height: 460px; border: 1px solid var(--line); border-radius: 10px; background: #fffaf3; resize: vertical; }
.codes { display: flex; flex-direction: column; }
.code-row { display: flex; gap: 16px; align-items: baseline; padding: 10px 4px; border-bottom: 1px solid var(--line); }
.code-row:last-child { border-bottom: 0; }
.code-num { font: 700 1.15rem var(--mono); min-width: 3.2ch; }
.code-row[data-class="1"] .code-num { color: var(--ink-3); }
.code-row[data-class="2"] .code-num { color: var(--good); }
.code-row[data-class="3"] .code-num { color: var(--g-convert); }
.code-row[data-class="4"] .code-num { color: var(--accent); }
.code-row[data-class="5"] .code-num { color: var(--bad); }
.code-name { font-weight: 650; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.scan-frame { position: relative; width: 100%; max-width: 480px; aspect-ratio: 1; margin: 0 auto; border-radius: 16px; overflow: hidden; background: var(--bg-2); border: 1px solid var(--line); }
.scan-video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scan-box { position: absolute; inset: 18%; border: 3px solid color-mix(in srgb, var(--accent) 80%, transparent); border-radius: 18px; box-shadow: 0 0 0 999px rgba(0, 0, 0, .25); opacity: 0; transition: opacity .2s; }
.scan-frame.live .scan-box { opacity: 1; }
.scan-frame:not(.live)::after { content: 'Camera is off'; position: absolute; inset: 0; display: grid; place-items: center; color: var(--ink-3); }
.scan-result .mono-block { font-size: 1rem; }
