:root {
  --bg: #111417;
  --bg-2: #161a1e;
  --card: #1a1f24;
  --card-hi: #20262c;
  --line: #2a3138;
  --line-soft: #222930;
  --text: #e8ecef;
  --muted: #8d979f;
  --faint: #5d6770;
  --accent: #86b8c4;
  --accent-dim: #86b8c41f;
  --shiny: #f2c66d;
  --shiny-dim: #f2c66d1f;
  --danger: #e48a8a;
  --radius: 14px;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: "Bricolage Grotesque", system-ui, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--sans); font-size: 16px; line-height: 1.5;
  min-height: 100vh; display: flex; flex-direction: column; overflow-x: hidden;
}
main { flex: 1; }
body::before {
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: -1;
  background-image:
    linear-gradient(var(--line-soft) 1px, transparent 1px),
    linear-gradient(90deg, var(--line-soft) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(ellipse 80% 55% at 50% 0%, #000 30%, transparent 75%);
  -webkit-mask-image: radial-gradient(ellipse 80% 55% at 50% 0%, #000 30%, transparent 75%);
  opacity: .5;
}
body::after {
  content: ""; position: fixed; top: -30vh; left: 50%; width: 900px; height: 600px;
  transform: translateX(-50%); pointer-events: none; z-index: -1;
  background: radial-gradient(closest-side, #f2c66d0d, transparent);
}

a { color: inherit; text-decoration: none; }
p a, .muted a { color: var(--accent); }
::selection { background: var(--accent); color: var(--bg); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 6px; }
code { font-family: var(--mono); font-size: .9em; background: var(--bg-2); padding: 1px 6px; border-radius: 5px; border: 1px solid var(--line-soft); }
.muted { color: var(--muted); }
.small { font-size: 13.5px; }
.mono { font-family: var(--mono); }
.star { width: 1em; height: 1em; flex: none; }

.wrap { max-width: 1200px; margin: 0 auto; padding: 0 20px; width: 100%; }
.wrap.narrow { max-width: 440px; padding-top: 72px; }

/* ---------- nav ---------- */
nav {
  position: sticky; top: 0; z-index: 10;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  border-bottom: 1px solid var(--line-soft);
}
nav .wrap { display: flex; align-items: center; justify-content: space-between; height: 60px; gap: 12px; }
.logo { font-family: var(--mono); font-size: 14px; color: var(--muted); display: flex; align-items: center; gap: 10px; }
.logo img { width: 22px; height: 22px; }
.logo b { color: var(--text); font-weight: 500; }
.logo:hover b { color: var(--accent); }
.nav-right { display: flex; align-items: center; gap: 8px; }
form.inline { display: inline; margin: 0; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-family: var(--mono); font-size: 13.5px; font-weight: 500;
  padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line);
  background: transparent; color: var(--text); cursor: pointer;
  transition: background .15s, border-color .15s, color .15s, transform .15s;
}
.btn:hover { transform: translateY(-1px); }
.btn-ghost { color: var(--muted); border-color: transparent; }
.btn-ghost:hover { color: var(--text); border-color: var(--line); }
.btn-shiny { border-color: #f2c66d55; background: var(--shiny-dim); color: var(--shiny); }
.btn-shiny:hover { background: #f2c66d2e; border-color: var(--shiny); }
.btn-shiny .star { width: 13px; height: 13px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #0d1316; padding: 10px 18px; }
.btn-primary:hover { background: #9fcad4; }
.btn-danger { color: var(--danger); border-color: #e48a8a55; }
.btn-danger:hover { background: #e48a8a1a; border-color: var(--danger); }

.flash { margin-top: 18px; padding: 11px 16px; border-radius: 10px; font-size: 14.5px; border: 1px solid var(--accent); background: var(--accent-dim); }
.flash.err { border-color: var(--danger); background: #e48a8a14; color: #f1b4b4; }

/* ---------- hero ---------- */
.hero { padding: 72px 0 36px; display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 28px; }
.hero h1 {
  font-size: clamp(52px, 9vw, 96px); line-height: .9; margin: 0;
  font-weight: 800; letter-spacing: -.035em; display: flex; align-items: flex-start; gap: 12px;
}
.hero h1 .star { width: .3em; height: .3em; color: var(--shiny); margin-top: .08em; animation: twinkle 3.2s ease-in-out infinite; }
@keyframes twinkle { 0%,100% { opacity: .4; transform: scale(.85) rotate(0); } 50% { opacity: 1; transform: scale(1) rotate(45deg); } }
.stats { display: flex; gap: 32px; flex-wrap: wrap; }
.stats div { display: flex; flex-direction: column; }
.stats b { font-size: 30px; font-weight: 800; letter-spacing: -.02em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stats div:first-child b { color: var(--shiny); }
.stats span { font-family: var(--mono); font-size: 12px; color: var(--faint); text-transform: uppercase; letter-spacing: .08em; }

.page-title { font-size: clamp(34px, 6vw, 52px); font-weight: 800; letter-spacing: -.03em; margin: 48px 0 20px; line-height: 1; }
.wrap.narrow .page-title { margin-top: 0; }

/* ---------- toolbar ---------- */
.toolbar { display: grid; grid-template-columns: 1fr 220px 180px; gap: 10px; margin-bottom: 8px; }
input, select, textarea {
  font: inherit; font-size: 15px; color: var(--text);
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; width: 100%; min-width: 0;
}
input[type=search], select, input[type=date], .affix input, #sprite, #dex, #tid, #encounters { font-family: var(--mono); font-size: 14px; }
select { appearance: none; -webkit-appearance: none; padding-right: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' fill='none' stroke='%238d979f' stroke-width='1.6'%3E%3Cpath d='M1 1.5l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
input[type=date] { color-scheme: dark; }
textarea { resize: vertical; }
.count { min-height: 20px; margin: 0 0 10px; font-family: var(--mono); }

/* ---------- gallery ---------- */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; padding-bottom: 72px; }
.shiny {
  position: relative; display: flex; flex-direction: column;
  background: var(--card); border: 1px solid var(--line-soft); border-radius: var(--radius);
  cursor: pointer; overflow: hidden;
  transition: border-color .2s, transform .2s, background .2s;
}
.shiny[hidden] { display: none; }
.shiny:hover, .shiny:focus-visible { border-color: #f2c66d66; transform: translateY(-2px); background: var(--card-hi); }
.shiny.fav { border-color: #f2c66d40; }
.sprite {
  position: relative; aspect-ratio: 1.25; display: grid; place-items: center;
  background: radial-gradient(circle at 50% 60%, #f2c66d10, transparent 65%), var(--bg-2);
  border-bottom: 1px solid var(--line-soft);
}
.sprite img { width: 70%; height: 90%; object-fit: contain; transition: transform .25s; }
.shiny:hover .sprite img { transform: scale(1.06); }
img.missing { visibility: hidden; }
.badge-photo, .badge-fav {
  position: absolute; top: 10px; font-family: var(--mono); font-size: 11.5px; color: var(--muted);
  background: color-mix(in srgb, var(--bg) 70%, transparent); border: 1px solid var(--line-soft);
  padding: 2px 8px; border-radius: 999px; display: inline-flex; align-items: center; gap: 4px;
}
.badge-photo { right: 10px; }
.badge-fav { left: 10px; color: var(--shiny); border-color: #f2c66d40; }
.badge-fav .star { width: 11px; height: 11px; }
.badge-photo svg { width: 12px; height: 12px; }

.shiny .body { padding: 14px 16px 16px; display: flex; flex-direction: column; flex: 1; }
.shiny h3 { margin: 0; font-size: 19px; font-weight: 700; letter-spacing: -.01em; line-height: 1.2; }
.nick { margin: 2px 0 0; color: var(--muted); font-size: 14px; font-style: italic; }
.shiny .game { margin: 8px 0 12px; font-family: var(--mono); font-size: 12px; color: var(--accent); }
.shiny dl { margin: auto 0 0; display: grid; gap: 4px; }
.shiny dl div { display: flex; justify-content: space-between; gap: 10px; font-size: 13.5px; }
.shiny dt { font-family: var(--mono); font-size: 11.5px; color: var(--faint); text-transform: uppercase; letter-spacing: .06em; padding-top: 2px; }
.shiny dd { margin: 0; color: var(--text); text-align: right; font-variant-numeric: tabular-nums; }
.shiny .edit {
  position: absolute; bottom: 10px; right: 10px; font-family: var(--mono); font-size: 11.5px;
  padding: 3px 9px; border-radius: 999px; border: 1px solid var(--line); background: var(--bg-2); color: var(--muted);
  opacity: 0; transition: opacity .15s;
}
.shiny:hover .edit, .shiny .edit:focus-visible { opacity: 1; }
.shiny .edit:hover { color: var(--accent); border-color: var(--accent); }
@media (hover: none) { .shiny .edit { opacity: 1; top: 10px; bottom: auto; right: auto; left: 10px; } }

.no-results { text-align: center; padding: 40px 0 80px; }
.empty-state { text-align: center; padding: 56px 24px; margin-bottom: 72px; }
.empty-state p { color: var(--muted); font-size: 18px; margin: 0 0 18px; }

/* ---------- detail dialog ---------- */
dialog {
  width: min(680px, calc(100vw - 24px)); max-height: calc(100vh - 48px);
  padding: 28px; border: 1px solid var(--line); border-radius: 18px;
  background: var(--card); color: var(--text); overflow-y: auto;
}
dialog::backdrop { background: #07090bcc; backdrop-filter: blur(4px); }
dialog[open] { animation: pop .18s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }
dialog .close {
  position: absolute; top: 14px; right: 14px; width: 34px; height: 34px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--bg-2); color: var(--muted); font-size: 20px; line-height: 1; cursor: pointer;
}
dialog .close:hover { color: var(--text); border-color: var(--accent); }
.d-head { display: flex; gap: 22px; align-items: center; flex-wrap: wrap; margin-bottom: 22px; }
.d-sprites, .preview-sprites { display: flex; gap: 10px; }
.d-sprites figure, .preview-sprites figure {
  margin: 0; width: 132px; display: flex; flex-direction: column; align-items: center;
  background: var(--bg-2); border: 1px solid var(--line-soft); border-radius: 12px; padding: 10px 8px 6px;
}
.d-sprites figure:first-child, .preview-sprites figure:first-child { border-color: #f2c66d40; background: radial-gradient(circle at 50% 55%, #f2c66d14, transparent 70%), var(--bg-2); }
.d-sprites img, .preview-sprites img { width: 110px; height: 110px; object-fit: contain; }
.d-sprites figure.dim img, .preview-sprites figure.dim img { opacity: .7; }
figcaption { font-family: var(--mono); font-size: 11px; color: var(--faint); text-transform: uppercase; letter-spacing: .08em; }
.d-dex { margin: 0; font-family: var(--mono); font-size: 13px; color: var(--faint); }
.d-head h2 { margin: 0; font-size: 34px; font-weight: 800; letter-spacing: -.02em; line-height: 1.05; }
.d-facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 1px; margin: 0;
  background: var(--line-soft); border: 1px solid var(--line-soft); border-radius: 12px; overflow: hidden; }
.d-facts div { background: var(--bg-2); padding: 10px 14px; }
.d-facts dt { font-family: var(--mono); font-size: 11px; color: var(--faint); text-transform: uppercase; letter-spacing: .08em; }
.d-facts dd { margin: 2px 0 0; font-size: 15px; }
.d-ribbons { list-style: none; margin: 16px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.d-ribbons li { font-size: 13px; padding: 4px 11px; border-radius: 999px; border: 1px solid #f2c66d40; background: var(--shiny-dim); color: var(--shiny); }
.tag { display: inline-block; margin-left: 6px; padding: 0 7px; border-radius: 999px; border: 1px solid var(--line);
  font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; vertical-align: 1px; }
.d-notes { margin: 18px 0 0; color: var(--muted); white-space: pre-wrap; }
.d-photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; margin-top: 20px; }
.d-photos a { display: block; border-radius: 10px; overflow: hidden; border: 1px solid var(--line-soft); aspect-ratio: 16/10; background: var(--bg-2); }
.d-photos img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .25s; }
.d-photos a:hover img { transform: scale(1.04); }

/* ---------- forms ---------- */
.card { background: var(--card); border: 1px solid var(--line-soft); border-radius: var(--radius); padding: 22px; margin-bottom: 14px; }
.wrap.narrow .card { display: grid; gap: 12px; }
.card-h { font-family: var(--mono); font-size: 12.5px; font-weight: 500; text-transform: uppercase; letter-spacing: .1em; color: var(--faint); margin: 0 0 16px; }
.lbl { display: block; font-size: 13.5px; color: var(--muted); margin-bottom: 6px; }
.hint { font-family: var(--mono); font-size: 12px; color: var(--faint); margin: 6px 0 0; }

.editor { display: grid; grid-template-columns: 300px 1fr; gap: 0 14px; align-items: start; }
.editor > .card:not(.editor-preview), .editor-actions { grid-column: 2; }
.editor-preview { grid-row: 1 / span 8; position: sticky; top: 76px; }
.preview-sprites { justify-content: center; }
.editor-preview .muted { text-align: center; margin: 12px 0 0; }
.fgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.f.span2 { grid-column: span 2; }
.f.check { display: flex; align-items: flex-end; }
.f.check label { display: flex; gap: 10px; align-items: center; cursor: pointer; font-size: 15px; padding-bottom: 10px; }
.f.check input { width: 18px; height: 18px; accent-color: var(--shiny); }
.affix { display: flex; align-items: stretch; }
.affix input { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.affix span { display: grid; place-items: center; padding: 0 12px; font-family: var(--mono); font-size: 13px; color: var(--faint);
  border: 1px solid var(--line); border-left: 0; border-radius: 0 10px 10px 0; background: var(--card-hi); }

.drop {
  display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center;
  padding: 26px 16px; border: 1.5px dashed var(--line); border-radius: 12px; cursor: pointer;
  color: var(--muted); transition: border-color .15s, background .15s;
}
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-dim); }
.drop input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.drop b { color: var(--accent); font-weight: 600; }
.drop small { font-family: var(--mono); font-size: 12px; color: var(--faint); }
.photo-edit { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.photo-edit:not(:empty) { margin: 0 0 14px; }
#newPhotos:not(:empty) { margin: 14px 0 0; }
.ph { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; color: var(--muted); cursor: pointer; min-width: 0; }
.ph img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 9px; border: 1px solid var(--line-soft); }
.ph span { display: flex; gap: 6px; align-items: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--mono); }
.ph input { width: auto; accent-color: var(--danger); }
.ph:has(input:checked) img { opacity: .3; border-color: var(--danger); }

.editor-actions { display: flex; justify-content: flex-end; gap: 10px; padding: 4px 0 20px; }
.danger-zone { display: flex; justify-content: flex-end; padding: 0 0 72px; border-top: 1px solid var(--line-soft); padding-top: 20px; margin-left: 314px; }

/* ---------- footer ---------- */
footer { border-top: 1px solid var(--line-soft); padding: 22px 0 32px; font-family: var(--mono); font-size: 12px; color: var(--faint); }
footer .wrap { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

/* ---------- responsive ---------- */
@media (max-width: 860px) {
  .editor { grid-template-columns: 1fr; }
  .editor > .card:not(.editor-preview), .editor-actions { grid-column: 1; }
  .editor-preview { grid-row: auto; position: static; }
  .danger-zone { margin-left: 0; }
}
@media (max-width: 640px) {
  .wrap { padding: 0 16px; }
  .hero { padding: 44px 0 24px; }
  .stats { gap: 22px; }
  .stats b { font-size: 24px; }
  .toolbar { grid-template-columns: 1fr 1fr; }
  .toolbar input[type=search] { grid-column: 1 / -1; }
  .gallery { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .shiny .body { padding: 12px; }
  .shiny h3 { font-size: 16px; }
  .shiny dl div { font-size: 12.5px; }
  .fgrid { grid-template-columns: 1fr; }
  .f.span2 { grid-column: auto; }
  dialog { padding: 22px 18px; }
  .d-sprites figure { width: 110px; }
  .d-sprites img { width: 90px; height: 90px; }
  .d-head h2 { font-size: 28px; }
  .nav-right .btn-shiny span { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
