:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e3e6eb;
  --text: #1a1d21;
  --text-muted: #656d76;
  --accent: #3b5bdb;
  --accent-hover: #2f49b0;
  --accent-soft: #eaefff;
  --danger: #e03131;
  --ok: #2f9e44;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 6px 20px rgba(0,0,0,.04);
  --maxw: 880px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115;
    --surface: #171a1f;
    --surface-2: #1f242b;
    --border: #2a2f37;
    --text: #e6e9ee;
    --text-muted: #9aa4b0;
    --accent: #5c7cfa;
    --accent-hover: #748ffc;
    --accent-soft: #1c2436;
    --shadow: 0 1px 3px rgba(0,0,0,.4), 0 6px 20px rgba(0,0,0,.3);
  }
}
:root[data-theme="dark"] {
  --bg: #0f1115;
  --surface: #171a1f;
  --surface-2: #1f242b;
  --border: #2a2f37;
  --text: #e6e9ee;
  --text-muted: #9aa4b0;
  --accent: #5c7cfa;
  --accent-hover: #748ffc;
  --accent-soft: #1c2436;
  --shadow: 0 1px 3px rgba(0,0,0,.4), 0 6px 20px rgba(0,0,0,.3);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Header */
.site-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); font-weight: 700; }
.brand-mark { font-size: 22px; }
.brand-name { font-size: 18px; letter-spacing: -.01em; }
.theme-toggle {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  width: 38px; height: 38px; border-radius: 10px; cursor: pointer; font-size: 16px;
}
.theme-toggle:hover { border-color: var(--accent); }

main { flex: 1; width: 100%; max-width: var(--maxw); margin: 0 auto; padding: 24px 20px 48px; }

/* Home hero */
.hero { text-align: center; padding: 20px 0 10px; }
.hero h1 { font-size: clamp(26px, 5vw, 40px); margin: 0 0 8px; letter-spacing: -.02em; }
.hero p { color: var(--text-muted); margin: 0 0 22px; font-size: 16px; }
.search-wrap { position: relative; max-width: 560px; margin: 0 auto 18px; }
.search-wrap input {
  width: 100%; padding: 15px 18px 15px 46px; font-size: 17px;
  border: 1px solid var(--border); border-radius: 999px; background: var(--surface); color: var(--text);
  box-shadow: var(--shadow); outline: none;
}
.search-wrap input:focus { border-color: var(--accent); }
.search-wrap::before { content: "🔍"; position: absolute; left: 18px; top: 50%; transform: translateY(-50%); opacity: .6; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-bottom: 26px; }
.chip {
  border: 1px solid var(--border); background: var(--surface); color: var(--text-muted);
  padding: 7px 14px; border-radius: 999px; cursor: pointer; font-size: 14px;
}
.chip:hover { border-color: var(--accent); color: var(--text); }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Tool grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; }
.card {
  display: flex; flex-direction: column; gap: 6px; text-decoration: none;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; color: var(--text); transition: transform .08s ease, border-color .08s ease;
}
.card:hover { border-color: var(--accent); transform: translateY(-2px); }
.card .icon { font-size: 24px; }
.card .title { font-weight: 600; font-size: 15px; }
.card .desc { font-size: 13px; color: var(--text-muted); }
.cat-label { grid-column: 1 / -1; margin: 18px 0 2px; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); font-weight: 700; }
.empty { text-align: center; color: var(--text-muted); padding: 40px 0; }

/* Tool view */
.tool-view h1 { font-size: 26px; margin: 6px 0 4px; letter-spacing: -.01em; }
.tool-view .tool-sub { color: var(--text-muted); margin: 0 0 20px; }
.back { display: inline-flex; align-items: center; gap: 6px; color: var(--accent); text-decoration: none; font-size: 14px; margin-bottom: 8px; }
.back:hover { text-decoration: underline; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }

/* Form elements */
label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.field { margin-bottom: 16px; }
input[type=text], input[type=number], input[type=password], input[type=datetime-local], select, textarea {
  width: 100%; padding: 10px 12px; font-size: 15px; font-family: inherit;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); color: var(--text); outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 140px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 120px; }
button, .btn {
  background: var(--accent); color: #fff; border: none; padding: 10px 16px; border-radius: 10px;
  font-size: 15px; font-weight: 600; cursor: pointer; font-family: inherit;
}
button:hover, .btn:hover { background: var(--accent-hover); }
button.secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
button.secondary:hover { border-color: var(--accent); background: var(--surface-2); }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 4px; }

/* Stats / results */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 12px; margin-top: 18px; }
.stat { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 14px; text-align: center; }
.stat .n { font-size: 24px; font-weight: 700; }
.stat .l { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.result { margin-top: 16px; padding: 14px; background: var(--accent-soft); border-radius: 10px; font-size: 15px; word-break: break-word; }
.result .big { font-size: 26px; font-weight: 700; display: block; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.muted { color: var(--text-muted); font-size: 13px; }
.hint { color: var(--text-muted); font-size: 13px; margin-top: 6px; }
.hidden { display: none !important; }
.center { text-align: center; }
.big-num { font-size: 48px; font-weight: 700; letter-spacing: -.02em; }
.error { color: var(--danger); font-size: 14px; }
canvas { max-width: 100%; }
.output-img { max-width: 100%; border-radius: 10px; border: 1px solid var(--border); margin-top: 12px; }
.filelist { font-size: 14px; margin: 10px 0; }
.filelist li { margin: 2px 0; }
