:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f0f1f4;
  --text: #1c2128;
  --text-dim: #59636e;
  --border: #d4d8de;
  --accent: #e60012;          /* hinomaru red, used sparingly */
  --pokefuta: #3b82f6;
  --manhole_card: #f59e0b;
  --personal: #16a34a;
  --osm: #8957e5;
  --shadow: 0 6px 24px rgba(20, 24, 31, 0.14);
  --radius: 14px;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
}
:root[data-theme="dark"] {
  --bg: #0d1117;
  --surface: #161b22;
  --surface-2: #1c2128;
  --text: #e6edf3;
  --text-dim: #8b949e;
  --border: #2d333b;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
#map { position: absolute; inset: 0; }
.maplibregl-ctrl-attrib { font-size: 10px; }

/* ---------- sidebar ---------- */
#sidebar {
  position: absolute;
  top: 14px;
  left: 14px;
  width: 340px;
  max-height: calc(100dvh - 28px);
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 18px;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow-y: auto;
  z-index: 5;
  transition: transform .25s ease, opacity .2s ease;
}
#sidebar.collapsed { transform: translateX(calc(-100% - 20px)); opacity: 0; pointer-events: none; }

.brand h1 { margin: 0 0 4px; font-size: 18px; letter-spacing: .2px; }
.brand h1 span { color: var(--text-dim); font-weight: 400; font-size: 13px; }
.brand p { margin: 0; font-size: 12.5px; line-height: 1.5; color: var(--text-dim); }

/* ---------- stats ---------- */
.stats { display: flex; gap: 10px; }
.stats .stat {
  flex: 1;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 8px;
  text-align: center;
}
.stats .stat b { display: block; font-size: 22px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stats .stat span { font-size: 10.5px; text-transform: uppercase; letter-spacing: .6px; color: var(--text-dim); }

/* ---------- filters ---------- */
.filters { display: flex; flex-direction: column; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--text-dim); }
.field input, .field select {
  font: inherit; font-size: 13px; text-transform: none; letter-spacing: 0;
  color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px;
}
.field input:focus, .field select:focus { outline: 2px solid var(--pokefuta); outline-offset: 1px; }

#categories { border: 0; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
#categories legend { font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--text-dim); padding: 0 0 4px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; padding: 5px 9px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface); cursor: pointer; user-select: none;
}
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip .dot { width: 9px; height: 9px; border-radius: 50%; }
.chip:has(input:checked) { background: var(--surface-2); border-color: currentColor; }
.chip:has(input:not(:checked)) { opacity: .5; }

.reset {
  align-self: flex-start; font: inherit; font-size: 12px; cursor: pointer;
  background: none; border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 10px; color: var(--text-dim);
}

/* ---------- prefecture bars ---------- */
.prefbars { display: flex; flex-direction: column; gap: 3px; font-size: 11px; }
.prefbars .row { display: grid; grid-template-columns: 68px 1fr 26px; align-items: center; gap: 6px; cursor: pointer; }
.prefbars .row:hover .track { filter: brightness(1.1); }
.prefbars .name { color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.prefbars .track { height: 9px; border-radius: 3px; background: var(--pokefuta); }
.prefbars .num { text-align: right; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.prefbars .row[aria-current="true"] .name { color: var(--text); font-weight: 600; }

/* ---------- footer ---------- */
.credits { font-size: 10.5px; color: var(--text-dim); line-height: 1.5; }
.credits p { margin: 8px 0 0; }
#theme-toggle {
  font: inherit; font-size: 12px; cursor: pointer; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; color: var(--text);
}

/* ---------- sidebar toggle ---------- */
#sidebar-toggle {
  position: absolute; top: 14px; left: 14px; z-index: 4;
  width: 40px; height: 40px; border-radius: 10px; cursor: pointer;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
  color: var(--text); font-size: 17px; display: none;
}
#sidebar.collapsed ~ #sidebar-toggle { display: block; }

/* ---------- detail panel ---------- */
#detail {
  position: absolute; top: 14px; right: 14px; width: 320px;
  max-height: calc(100dvh - 28px); overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); z-index: 6;
}
#detail-close {
  position: absolute; top: 8px; right: 8px; width: 28px; height: 28px;
  border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text); font-size: 16px; cursor: pointer;
}
#detail-body { padding: 16px; }
#detail-body img { width: 100%; border-radius: 10px; display: block; background: var(--surface-2); }
#detail-body h2 { margin: 12px 0 2px; font-size: 15px; }
#detail-body .ja { color: var(--text-dim); font-size: 12.5px; }
#detail-body dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 12px 0 0; font-size: 12.5px; }
#detail-body dt { color: var(--text-dim); }
#detail-body .tags { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 10px; }
#detail-body .tags button {
  font: inherit; font-size: 11px; cursor: pointer; padding: 3px 8px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
}
#detail-body .nophoto { padding: 28px 12px; text-align: center; color: var(--text-dim); font-size: 12px;
  border: 1px dashed var(--border); border-radius: 10px; }
#detail-body .src { display: inline-block; margin-top: 12px; font-size: 12px; }
#detail-body .stack-hint { font-size: 11.5px; color: var(--text-dim); margin: 0 0 12px; }
#detail-body .detail-card + .detail-card {
  margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border);
}

/* ---------- contribute panel ---------- */
#contribute {
  position: absolute; top: 14px; right: 14px; width: 340px;
  max-height: calc(100dvh - 28px); overflow-y: auto; z-index: 7;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px;
}
#contribute h2 { margin: 0 0 4px; font-size: 15px; }
#contribute .hint { font-size: 11.5px; color: var(--text-dim); margin: 0 0 10px; }
#contribute-close {
  position: absolute; top: 8px; right: 8px; width: 28px; height: 28px;
  border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text); font-size: 16px; cursor: pointer;
}
#contribute input[type="file"] { font-size: 12px; margin-bottom: 10px; }
#contribute .field { margin-bottom: 8px; }
#contribute pre {
  white-space: pre-wrap; word-break: break-word; font-size: 11px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px; margin: 8px 0;
}
#contribute .c-actions { display: flex; gap: 8px; }
.analysis { font-size: 12px; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px; margin-bottom: 10px; }
.analysis .verdict { font-weight: 600; }
.analysis .sig { color: var(--text-dim); margin-top: 4px; }

/* ---------- batch add covers ---------- */
#batch {
  position: absolute; top: 14px; right: 14px; width: 380px;
  max-height: calc(100dvh - 28px); overflow-y: auto; z-index: 8;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px;
}
#batch h2 { margin: 0 0 4px; font-size: 15px; }
#batch .hint { font-size: 11.5px; color: var(--text-dim); margin: 0 0 10px; }
#batch-close {
  position: absolute; top: 8px; right: 8px; width: 28px; height: 28px;
  border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text); font-size: 16px; cursor: pointer;
}
#b-progress { font-size: 12px; color: var(--text-dim); }
.b-row {
  display: grid; grid-template-columns: 56px 1fr; gap: 8px;
  border: 1px solid var(--border); border-radius: 8px; padding: 8px; margin-bottom: 8px;
}
.b-row img { width: 56px; height: 56px; object-fit: cover; border-radius: 6px; background: var(--surface-2); }
.b-row .b-fields { display: flex; flex-direction: column; gap: 4px; font-size: 12px; }
.b-row input, .b-row select { font: inherit; font-size: 12px; padding: 4px 6px;
  border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text); }
.b-row .b-verdict { font-size: 11px; color: var(--text-dim); }
.b-row .b-dup { font-size: 11px; color: #b45309; }
#batch pre { white-space: pre-wrap; word-break: break-word; font-size: 11px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 8px; margin: 8px 0; }
@media (max-width: 640px) {
  #batch { top: auto; bottom: 0; right: 0; left: 0; width: 100%;
    max-height: 82dvh; border-radius: var(--radius) var(--radius) 0 0; }
}

/* ---------- help classify unidentified covers ---------- */
#unclassify {
  position: absolute; top: 14px; right: 14px; width: 380px;
  max-height: calc(100dvh - 28px); overflow-y: auto; z-index: 8;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px;
}
#unclassify h2 { margin: 0 0 4px; font-size: 15px; }
#unclassify .hint { font-size: 11.5px; color: var(--text-dim); margin: 0 0 10px; }
#unclassify-close {
  position: absolute; top: 8px; right: 8px; width: 28px; height: 28px;
  border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text); font-size: 16px; cursor: pointer;
}
.u-card {
  display: grid; grid-template-columns: 56px 1fr; gap: 8px;
  border: 1px solid var(--border); border-radius: 8px; padding: 8px; margin-bottom: 8px;
}
.u-card img { width: 56px; height: 56px; object-fit: cover; border-radius: 6px; background: var(--surface-2); }
.u-fields { display: flex; flex-direction: column; gap: 4px; font-size: 12px; }
.u-desc { font-size: 12px; }
.u-note { font-size: 11px; color: var(--text-dim); }
.u-form { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; }
.u-form input, .u-form select { font: inherit; font-size: 12px; padding: 4px 6px;
  border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text); }
.u-msg { font-size: 11px; color: #b45309; }
#unclassify pre { white-space: pre-wrap; word-break: break-word; font-size: 11px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 8px; margin: 4px 0; }
@media (max-width: 640px) {
  #unclassify { top: auto; bottom: 0; right: 0; left: 0; width: 100%;
    max-height: 82dvh; border-radius: var(--radius) var(--radius) 0 0; }
}
.u-card img { cursor: zoom-in; }

/* ---------- lightbox (enlarged photo) ---------- */
#lightbox {
  position: fixed; inset: 0; z-index: 30;
  background: rgba(0, 0, 0, .85);
  align-items: center; justify-content: center;
  padding: 32px; cursor: zoom-out;
}
/* #lightbox[hidden] must win over the ID selector below it, or the [hidden]
   attribute's display:none never applies and the overlay stays visible. */
#lightbox:not([hidden]) { display: flex; }
#lightbox img {
  max-width: 100%; max-height: 100%;
  border-radius: 8px; box-shadow: var(--shadow);
  cursor: default;
}
#lightbox-close {
  position: absolute; top: 14px; right: 14px; width: 36px; height: 36px;
  border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text); font-size: 18px; cursor: pointer;
}

/* ---------- identify a cover ---------- */
/* ---------- gallery ---------- */
#gallery { position: absolute; inset: 0; z-index: 20; background: var(--bg);
  padding: 20px; overflow-y: auto; }
#gallery-close { position: absolute; top: 12px; right: 12px; width: 32px; height: 32px;
  border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text); font-size: 18px; cursor: pointer; }
#gallery h2 { max-width: 1100px; margin: 0 auto; padding-right: 40px; }
#gallery .hint { max-width: 1100px; margin: 4px auto 16px; color: var(--text-dim); font-size: 12.5px; }
#gallery-grid {
  max-width: 1100px; margin: 0 auto;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px;
}
.gal-card {
  border: 1px solid var(--border); border-radius: 10px; overflow: hidden;
  background: var(--surface); display: flex; flex-direction: column;
}
.gal-thumb { width: 100%; aspect-ratio: 1; object-fit: cover; cursor: zoom-in; background: var(--surface-2); }
.gal-caption {
  font: inherit; text-align: left; cursor: pointer; border: 0; background: none; color: var(--text);
  padding: 8px 10px; display: flex; flex-direction: column; gap: 2px; font-size: 12px;
}
.gal-caption span { color: var(--text-dim); font-size: 10.5px; text-transform: uppercase; letter-spacing: .4px; }
.gal-caption:hover { background: var(--surface-2); }

#identify { position: absolute; inset: 0; z-index: 20; background: var(--bg);
  padding: 20px; overflow-y: auto; }
#identify-close { position: absolute; top: 12px; right: 12px; width: 32px; height: 32px;
  border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text); font-size: 18px; cursor: pointer; }
.id-grid { display: grid; grid-template-columns: minmax(200px, 360px) 1fr; gap: 20px; max-width: 900px; margin: 40px auto 0; }
#id-preview { width: 100%; border-radius: 10px; }
.id-right .verdict { font-size: 18px; font-weight: 600; margin-bottom: 8px; }
.id-right .sig { border: 1px solid var(--border); border-radius: 8px; padding: 10px; margin-bottom: 8px; font-size: 12.5px; }

/* ---------- responsive ---------- */
@media (max-width: 640px) {
  #sidebar { top: 0; left: 0; width: 100%; max-height: 62dvh; border-radius: 0 0 var(--radius) var(--radius); }
  #sidebar.collapsed { transform: translateY(calc(-100% - 20px)); }
  /* On a phone the sidebar sits on TOP of the map (not beside it), so the
     toggle must stay reachable however wide open the sidebar is: always
     visible, and above it in stacking order. */
  #sidebar-toggle { display: block; top: 10px; left: auto; right: 10px; z-index: 6; }
  #detail { top: auto; bottom: 0; right: 0; left: 0; width: 100%; max-height: 62dvh;
    border-radius: var(--radius) var(--radius) 0 0; }
  #contribute { top: auto; bottom: 0; right: 0; left: 0; width: 100%;
    max-height: 80dvh; border-radius: var(--radius) var(--radius) 0 0; }
  .id-grid { grid-template-columns: 1fr; }
}
