:root {
  --bg: #f6f6f4;
  --card: #ffffff;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --line: #e3e3e0;
  --accent: #2f6fde;
  --accent-text: #ffffff;
  --danger: #c4372f;
  --soft: #eef2fb;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161618;
    --card: #1f1f22;
    --text: #f2f2f3;
    --muted: #9b9ba1;
    --line: #2e2e33;
    --accent: #5b8ff0;
    --danger: #ef6b62;
    --soft: #23293a;
  }
}

* { 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.45 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}
h1 { font-size: 1.35rem; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 28px 0 10px; font-weight: 600; }
p { margin: 0.5em 0; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.error { color: var(--danger); min-height: 1.2em; font-size: 0.9rem; }

.center { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 24px; }
.narrow { width: 100%; max-width: 380px; }
.narrow h1 { margin-bottom: 8px; }
.stack { display: grid; gap: 10px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

input, select, textarea, button {
  font: inherit;
  color: inherit;
}
input, select, textarea {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
label { display: grid; gap: 4px; font-size: 0.9rem; color: var(--muted); }

button {
  padding: 9px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--card);
  cursor: pointer;
}
button:hover { border-color: var(--muted); }
button:disabled { opacity: 0.5; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button.danger { color: var(--danger); }
button.big { width: 100%; padding: 14px; font-size: 1.05rem; margin-top: 12px; }
button.icon { padding: 6px 10px; font-size: 0.85rem; }

.code {
  display: block;
  font: 600 1.05rem ui-monospace, "SF Mono", Menlo, monospace;
  letter-spacing: 0.04em;
  padding: 14px;
  margin: 14px 0 4px;
  background: var(--soft);
  border-radius: 10px;
  text-align: center;
  word-break: break-all;
  user-select: all;
}
.recover { margin-top: 18px; font-size: 0.9rem; }
.recover summary { color: var(--muted); cursor: pointer; }
.recover form { margin-top: 10px; }

/* ── App shell ───────────────────────────────── */
.top {
  position: sticky; top: 0; z-index: 5;
  background: var(--bg);
  padding: calc(env(safe-area-inset-top) + 14px) 16px 0;
  border-bottom: 1px solid var(--line);
}
.top > * { max-width: 760px; margin-left: auto; margin-right: auto; }
.title-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.meter { height: 4px; background: var(--line); border-radius: 4px; margin-top: 10px; overflow: hidden; }
.meter span { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.3s; }
.meter span.warn { background: var(--danger); }
.tabs { display: flex; gap: 4px; margin-top: 10px; overflow-x: auto; }
.tabs button {
  border: none; background: none; border-radius: 0;
  padding: 10px 12px; color: var(--muted); font-weight: 500;
  border-bottom: 2px solid transparent;
}
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }

.content { max-width: 760px; margin: 0 auto; padding: 16px 16px calc(env(safe-area-inset-bottom) + 40px); }
.banner { background: var(--soft); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 14px; font-size: 0.92rem; }

.dropzone {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 16px; border: 1.5px dashed var(--line); border-radius: var(--radius);
  background: var(--card);
}
.dropzone.over { border-color: var(--accent); background: var(--soft); }
@media (hover: none) { .hide-touch { display: none; } }

.progress { margin: 10px 0; height: 22px; background: var(--line); border-radius: 6px; position: relative; overflow: hidden; }
.progress span { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--accent); opacity: 0.35; }
.progress em { position: relative; font-style: normal; font-size: 0.8rem; padding: 0 8px; line-height: 22px; }

.list { list-style: none; margin: 14px 0 0; padding: 0; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.list:empty { display: none; }
.list li { display: flex; align-items: center; gap: 10px; padding: 11px 12px; border-top: 1px solid var(--line); }
.list li:first-child { border-top: none; }
.list .main { flex: 1; min-width: 0; }
.list .name { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); text-decoration: none; font-weight: 500; }
.list a.name:hover { color: var(--accent); }
.list .meta { font-size: 0.8rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .actions { display: flex; gap: 6px; flex-shrink: 0; }
.empty { text-align: center; padding: 30px 0; }
.badge { display: inline-block; font-size: 0.7rem; font-weight: 600; padding: 1px 7px; border-radius: 999px; background: var(--soft); color: var(--accent); margin-left: 6px; vertical-align: 2px; }

#tab-links form { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }

textarea#notes {
  min-height: 60vh;
  resize: vertical;
  background: var(--card);
  line-height: 1.55;
  padding: 14px;
}

.limits { margin: 0; padding-left: 18px; font-size: 0.9rem; color: var(--muted); }
.limits li { margin: 3px 0; }

/* ── Selection ──────────────────────────────── */
.check { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 0.9rem; cursor: pointer; }
.check input, .list input[type="checkbox"] { width: 20px; height: 20px; margin: 0; padding: 0; accent-color: var(--accent); flex-shrink: 0; cursor: pointer; }
.select-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin: 14px 0 -4px; padding: 10px 12px;
  background: var(--soft); border: 1px solid var(--line); border-radius: var(--radius);
}
.select-bar .actions { display: flex; gap: 6px; }
.list li.selected { background: var(--soft); }

/* ── Short-name field ───────────────────────── */
.slug-field { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); overflow: hidden; }
.slug-field span { padding-left: 12px; white-space: nowrap; font-size: 0.85rem; }
.slug-field input { border: none; background: transparent; padding-left: 2px; min-width: 0; }
.slug-field:focus-within { outline: 2px solid var(--accent); outline-offset: -1px; }
.slug-field input:focus { outline: none; }
.hint { font-size: 0.78rem; color: var(--muted); }

/* ── Stats ──────────────────────────────────── */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.stat .label { font-size: 0.8rem; color: var(--muted); }
.stat .big { font-size: 1.6rem; font-weight: 650; letter-spacing: -0.02em; margin: 2px 0; font-variant-numeric: tabular-nums; }
.stat .sub { font-size: 0.8rem; color: var(--muted); }
.stat .meter { margin: 8px 0 6px; }
.small-cards { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); }
.small-cards .big { font-size: 1.3rem; }
.list .bar { height: 4px; background: var(--line); border-radius: 4px; margin-top: 5px; overflow: hidden; }
.list .bar span { display: block; height: 100%; background: var(--accent); }
.list .num { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 0.85rem; flex-shrink: 0; }
.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.table { width: 100%; border-collapse: collapse; font-size: 0.88rem; font-variant-numeric: tabular-nums; }
.table th, .table td { padding: 9px 12px; text-align: right; border-top: 1px solid var(--line); white-space: nowrap; }
.table th:first-child, .table td:first-child { text-align: left; }
.table tr:first-child th { border-top: none; color: var(--muted); font-weight: 500; }

dialog {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--card);
  color: var(--text);
  width: min(420px, calc(100vw - 32px));
  padding: 20px;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.35); }
dialog h2 { margin-top: 0; color: var(--text); text-transform: none; letter-spacing: 0; font-size: 1.1rem; }
dialog .row { justify-content: flex-end; }
