/* ==========================================================================
   Tokens
   ========================================================================== */
:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f1f3f8;
  --border: #e3e7ee;
  --border-strong: #cdd4e0;
  --text: #0f172a;
  --muted: #5b6577;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-text: #4338ca;
  --primary-soft: #eef0ff;
  --on-primary: #ffffff;
  --success: #15803d;
  --success-soft: #e8f7ee;
  --danger: #dc2626;
  --danger-soft: #fdecec;
  --warning: #b45309;
  --tile-mix: 12%;
  --tile-fg: 0%;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow-sm: 0 1px 2px rgb(15 23 42 / .05);
  --shadow: 0 1px 3px rgb(15 23 42 / .06), 0 6px 20px -8px rgb(15 23 42 / .12);
  --shadow-lg: 0 20px 50px -12px rgb(15 23 42 / .35);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0f17;
    --surface: #121825;
    --surface-2: #19212f;
    --border: #252f40;
    --border-strong: #354156;
    --text: #e6ebf2;
    --muted: #96a1b4;
    --primary: #6366f1;
    --primary-hover: #7c7ff5;
    --primary-text: #a5b4fc;
    --primary-soft: #1d2145;
    --success: #4ade80;
    --success-soft: #11291c;
    --danger: #f87171;
    --danger-soft: #331617;
    --warning: #fbbf24;
    --tile-mix: 18%;
    --tile-fg: 35%;
    --shadow: 0 1px 3px rgb(0 0 0 / .3), 0 6px 20px -8px rgb(0 0 0 / .5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b0f17;
  --surface: #121825;
  --surface-2: #19212f;
  --border: #252f40;
  --border-strong: #354156;
  --text: #e6ebf2;
  --muted: #96a1b4;
  --primary: #6366f1;
  --primary-hover: #7c7ff5;
  --primary-text: #a5b4fc;
  --primary-soft: #1d2145;
  --success: #4ade80;
  --success-soft: #11291c;
  --danger: #f87171;
  --danger-soft: #331617;
  --warning: #fbbf24;
  --tile-mix: 18%;
  --tile-fg: 35%;
  --shadow: 0 1px 3px rgb(0 0 0 / .3), 0 6px 20px -8px rgb(0 0 0 / .5);
  color-scheme: dark;
}

/* ==========================================================================
   Base
   ========================================================================== */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
main { flex: 1; }
a { color: var(--primary-text); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.2; margin: 0; letter-spacing: -.015em; }
p { margin: 0; }
img { max-width: 100%; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.icon { width: 1.15em; height: 1.15em; flex: none; vertical-align: -.2em; }
.container { width: 100%; max-width: 1200px; margin: 0 auto; padding: 0 16px; }
@media (min-width: 720px) { .container { padding: 0 24px; } }

.skip-link { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; border-radius: 8px; z-index: 100; }
.skip-link:focus { left: 8px; }

/* Color comes from --c, set on the tile or inherited from a card/section (category color). */
.tile {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  flex: none;
  background: color-mix(in srgb, var(--c, var(--primary)) var(--tile-mix), transparent);
  color: color-mix(in srgb, var(--c, var(--primary)), #fff var(--tile-fg));
}
.tile .icon { width: 22px; height: 22px; }
.tile-sm { width: 32px; height: 32px; border-radius: 9px; }
.tile-sm .icon { width: 17px; height: 17px; }
.tile-lg { width: 56px; height: 56px; border-radius: 15px; }
.tile-lg .icon { width: 28px; height: 28px; }

/* ==========================================================================
   Header
   ========================================================================== */
.site-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.6) blur(12px);
  -webkit-backdrop-filter: saturate(1.6) blur(12px);
  border-bottom: 1px solid var(--border);
}
.header-row { display: flex; align-items: center; gap: 12px; height: 60px; }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--text); font-weight: 700; font-size: 1.1rem; }
.brand:hover { text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; background: var(--primary); color: #fff; }
.brand-mark .icon { width: 19px; height: 19px; }
.search-trigger {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  width: min(360px, 100%);
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--muted);
  font: inherit;
  font-size: .95rem;
  cursor: pointer;
}
.search-trigger:hover { border-color: var(--border-strong); }
.search-trigger span { flex: 1; text-align: left; }
.search-trigger kbd { font: 12px var(--mono); border: 1px solid var(--border-strong); border-radius: 5px; padding: 1px 6px; }
@media (max-width: 600px) {
  .search-trigger { width: 40px; padding: 0; justify-content: center; }
  .search-trigger span, .search-trigger kbd { display: none; }
  .brand-name { max-width: 50vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}
.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  flex: none;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-sun { display: none; }
:root[data-theme="dark"] .icon-sun { display: block; }
:root[data-theme="dark"] .icon-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .icon-sun { display: block; }
  :root:not([data-theme="light"]) .icon-moon { display: none; }
}

.cat-nav { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; padding-bottom: 10px; }
.cat-nav::-webkit-scrollbar { display: none; }
.cat-nav a {
  flex: none;
  padding: 6px 12px;
  border-radius: 999px;
  color: var(--muted);
  font-size: .9rem;
  font-weight: 500;
  white-space: nowrap;
}
.cat-nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.cat-nav a.active { background: var(--primary-soft); color: var(--primary-text); }

/* ==========================================================================
   Search modal
   ========================================================================== */
.search-modal { position: fixed; inset: 0; z-index: 90; display: flex; justify-content: center; align-items: flex-start; padding: 10vh 16px 16px; }
.search-backdrop { position: absolute; inset: 0; background: rgb(8 12 20 / .55); }
.search-panel {
  position: relative;
  width: 100%;
  max-width: 600px;
  max-height: 70vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.search-input-row { display: flex; align-items: center; gap: 10px; padding: 10px 10px 10px 16px; border-bottom: 1px solid var(--border); }
.search-input-row > .icon { color: var(--muted); }
.search-input-row input { flex: 1; border: 0; background: none; color: var(--text); font: inherit; font-size: 1.05rem; outline: none; min-width: 0; height: 40px; }
.search-input-row input::-webkit-search-cancel-button { display: none; }
.search-input-row .icon-btn { border: 0; }
.search-results { overflow-y: auto; padding: 8px; }
.search-item { display: flex; align-items: center; gap: 12px; padding: 8px 10px; border-radius: 10px; color: var(--text); }
.search-item:hover, .search-item.is-active { background: var(--surface-2); text-decoration: none; }
.search-item-text { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.search-item-text small { color: var(--muted); }
.search-item .chevron { color: var(--muted); }
.search-empty { padding: 24px; text-align: center; color: var(--muted); }

/* ==========================================================================
   Home
   ========================================================================== */
.hero { padding: 56px 0 32px; text-align: center; }
.hero h1 { font-size: clamp(2rem, 5vw, 3rem); font-weight: 800; }
.hero-sub { margin-top: 10px; color: var(--muted); font-size: clamp(1rem, 2.2vw, 1.2rem); }
.hero-search {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 560px;
  margin: 28px auto 0;
  padding: 0 18px;
  height: 56px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  cursor: text;
}
.hero-search:focus-within { border-color: var(--primary); }
.hero-search > .icon { color: var(--muted); width: 20px; height: 20px; }
.hero-search input { flex: 1; min-width: 0; border: 0; outline: none; background: none; font: inherit; font-size: 1.05rem; color: var(--text); }
.hero-points { list-style: none; display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 22px; padding: 0; margin: 20px 0 0; color: var(--muted); font-size: .92rem; }
.hero-points li { display: inline-flex; align-items: center; gap: 6px; }
.hero-points .icon { color: var(--success); }

.home { padding-bottom: 48px; }
.tool-section { margin-top: 36px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.section-title { display: flex; align-items: center; gap: 10px; font-size: 1.25rem; font-weight: 700; margin-bottom: 14px; }
.section-head .section-title { margin-bottom: 14px; }
.section-title > .icon { color: #f59e0b; }
.section-link { display: inline-flex; align-items: center; gap: 4px; font-size: .92rem; font-weight: 500; margin-bottom: 14px; white-space: nowrap; }

.tool-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
@media (max-width: 560px) { .tool-grid { grid-template-columns: 1fr; gap: 10px; } }
.tool-card {
  display: flex;
  gap: 14px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  box-shadow: var(--shadow-sm);
  transition: border-color .15s, box-shadow .15s, transform .15s;
}
.tool-card:hover { text-decoration: none; border-color: color-mix(in srgb, var(--c) 45%, var(--border)); box-shadow: var(--shadow); transform: translateY(-2px); }
.tool-card-body { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.tool-card-body strong { font-weight: 650; }
.tool-card-body span { color: var(--muted); font-size: .9rem; line-height: 1.45; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.empty-state { text-align: center; color: var(--muted); padding: 48px 0; }

/* ==========================================================================
   Pages
   ========================================================================== */
.page { padding-top: 20px; padding-bottom: 56px; }
.breadcrumb { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; font-size: .88rem; color: var(--muted); margin-bottom: 18px; }
.breadcrumb a { color: var(--muted); }
.breadcrumb .icon { width: 14px; height: 14px; }
.breadcrumb span { color: var(--text); }
.page-head { display: flex; align-items: center; gap: 16px; margin-bottom: 22px; }
.page-head h1 { font-size: clamp(1.5rem, 3.5vw, 2rem); font-weight: 800; }
.page-head p { color: var(--muted); margin-top: 4px; }

.tool-layout { display: grid; gap: 24px; }
.tool-page.has-sidebar .tool-layout { grid-template-columns: minmax(0, 1fr); }
@media (min-width: 1024px) {
  .tool-page.has-sidebar .tool-layout { grid-template-columns: minmax(0, 1fr) 300px; }
  .tool-aside { position: sticky; top: 120px; align-self: start; }
}
.tool-main { min-width: 0; }
.related { margin-top: 48px; }
.tool-about { margin-top: 28px; color: var(--muted); line-height: 1.7; }
.tool-about h2 { color: var(--text); font-size: 1.2rem; margin: 22px 0 8px; }

.not-found { text-align: center; padding: 72px 16px; display: flex; flex-direction: column; align-items: center; gap: 14px; }
.not-found p { color: var(--muted); }

.ad-slot { margin: 20px auto; text-align: center; overflow: hidden; max-width: 100%; }
.tool-aside .ad-slot { margin-top: 0; }

/* ==========================================================================
   Footer
   ========================================================================== */
.site-footer { border-top: 1px solid var(--border); background: var(--surface); padding: 40px 0; margin-top: 24px; }
.footer-grid { display: grid; gap: 32px 48px; grid-template-columns: minmax(0, 300px) minmax(0, 1fr); }
@media (max-width: 760px) { .footer-grid { grid-template-columns: minmax(0, 1fr); } }
.footer-cols { display: grid; gap: 24px; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
@media (max-width: 560px) { .footer-cols { grid-template-columns: 1fr 1fr; } }
.footer-brand p { color: var(--muted); font-size: .9rem; margin-top: 12px; }
.footer-col h3 { font-size: .9rem; margin-bottom: 10px; }
.footer-col h3 a { color: var(--text); }
.footer-col ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.footer-col li a { color: var(--muted); font-size: .9rem; }

/* ==========================================================================
   Tool UI kit — use these classes inside app/tools/{slug}/view.php
   ========================================================================== */
.tool { display: grid; gap: 16px; }
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow-sm);
  min-width: 0;
}
@media (max-width: 560px) { .panel { padding: 14px; } }
.panel-title { font-size: 1rem; font-weight: 650; margin-bottom: 12px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.grid-2 { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); }
.grid-3 { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr)); }
.stack { display: grid; gap: 12px; align-content: start; }

.field { display: grid; gap: 6px; min-width: 0; }
.label { font-size: .88rem; font-weight: 600; color: var(--text); display: flex; justify-content: space-between; gap: 8px; }
.label small { font-weight: 400; color: var(--muted); }
.hint { font-size: .85rem; color: var(--muted); }

.input, .select, .textarea {
  width: 100%;
  min-width: 0;
  font: inherit;
  font-size: 1rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  transition: border-color .15s, box-shadow .15s;
}
.input, .select { height: 44px; }
.select { appearance: none; padding-right: 36px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238893a6' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; background-size: 18px; }
.textarea { min-height: 180px; resize: vertical; line-height: 1.5; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 22%, transparent); }
.mono, .textarea.mono { font-family: var(--mono); font-size: .9rem; }
.input[type="color"] { flex: none; padding: 4px; width: 56px; height: 44px; cursor: pointer; }
.is-invalid { border-color: var(--danger) !important; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 42px;
  padding: 0 16px;
  font: inherit;
  font-size: .95rem;
  font-weight: 600;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { color: var(--danger); }
.btn-sm { height: 34px; padding: 0 12px; font-size: .88rem; }
.btn.is-done { color: var(--success); border-color: var(--success); }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.toolbar .spacer { flex: 1; }

.seg { display: inline-flex; flex-wrap: wrap; gap: 4px; padding: 4px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 11px; }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.seg span { display: block; padding: 6px 12px; border-radius: 8px; font-size: .9rem; font-weight: 500; color: var(--muted); cursor: pointer; }
.seg input:checked + span { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.seg input:focus-visible + span { outline: 2px solid var(--primary); }

.check { display: inline-flex; align-items: center; gap: 8px; font-size: .95rem; cursor: pointer; user-select: none; }
.check input[type="checkbox"], .check input[type="radio"] { width: 18px; height: 18px; accent-color: var(--primary); margin: 0; }
.checks { display: flex; flex-wrap: wrap; gap: 10px 20px; }

.range { width: 100%; accent-color: var(--primary); }

.stats { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
.stat { background: var(--surface-2); border-radius: 11px; padding: 12px 14px; min-width: 0; }
.stat b { display: block; font-size: 1.5rem; font-weight: 750; letter-spacing: -.02em; overflow-wrap: anywhere; }
.stat span { font-size: .85rem; color: var(--muted); }

.result { text-align: center; padding: 22px 14px; background: var(--surface-2); border-radius: 12px; }
.result b { display: block; font-size: clamp(1.8rem, 6vw, 2.6rem); font-weight: 800; letter-spacing: -.02em; overflow-wrap: anywhere; }
.result span { color: var(--muted); }

.copy-row { display: flex; gap: 8px; align-items: center; }
.copy-row .input:not([type="color"]) { flex: 1; font-family: var(--mono); font-size: .9rem; }

.kv { width: 100%; border-collapse: collapse; font-size: .95rem; }
.kv th, .kv td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.kv th { color: var(--muted); font-weight: 500; width: 36%; }
.kv td { font-family: var(--mono); font-size: .88rem; overflow-wrap: anywhere; }
.kv tr:last-child th, .kv tr:last-child td { border-bottom: 0; }
.table-wrap { overflow-x: auto; }

.alert { padding: 10px 14px; border-radius: 10px; font-size: .92rem; display: flex; gap: 8px; align-items: flex-start; }
.alert-error { background: var(--danger-soft); color: var(--danger); }
.alert-ok { background: var(--success-soft); color: var(--success); }

.dropzone {
  display: grid;
  place-items: center;
  gap: 8px;
  text-align: center;
  padding: 36px 16px;
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--muted);
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.is-over { border-color: var(--primary); background: var(--primary-soft); }
.dropzone .icon { width: 34px; height: 34px; color: var(--primary-text); }
.dropzone strong { color: var(--text); }
.dropzone input { display: none; }

.muted { color: var(--muted); }
.text-ok { color: var(--success); }
.text-bad { color: var(--danger); }
.text-warn { color: var(--warning); }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 20px);
  background: var(--text);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 10px;
  font-size: .92rem;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 100;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
