:root {
  --bg: #140b1c;
  --panel: #1f1229;
  --line: #3a2848;
  --text: #f1eaf7;
  --muted: #a996b8;
  --accent: #6ff0c4;
  --accent-ink: #0d1f19;
  --plum: #7a3c8f;
  --danger: #ff6b8a;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", sans-serif; font-size: 15px; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 8px 12px; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.ghost, a.ghost { background: transparent; border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; color: var(--text); text-decoration: none; display: inline-block; }
button.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
input, select, textarea { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
[hidden] { display: none !important; }

.login-box { max-width: 320px; margin: 22vh auto 0; padding: 0 16px; display: grid; gap: 12px; }
.login-box h1 { font-size: 20px; margin: 0 0 8px; }
.error { color: var(--danger); margin: 0; }

.top { position: sticky; top: 0; z-index: 5; display: flex; gap: 8px; align-items: center; padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top)); background: var(--bg); border-bottom: 1px solid var(--line); }
.top h1 { font-size: 16px; margin: 0; white-space: nowrap; color: var(--accent); }
.top input { flex: 1; min-width: 0; }
.top .primary { width: 42px; height: 40px; padding: 0; font-size: 22px; line-height: 1; }

.bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 10px 16px; }
.bar select { width: auto; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tabs button { padding: 6px 10px; font-size: 14px; }
.tabs button[aria-pressed="true"] { background: var(--plum); border-color: var(--plum); }

.facets { padding: 0 16px 8px; display: grid; gap: 10px; }
.facet h3 { font-size: 12px; color: var(--muted); margin: 0 0 4px; font-weight: 500; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 13px; padding: 4px 9px; border-radius: 999px; }
.chip .n { color: var(--muted); margin-left: 4px; }
.active-filters { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 16px; }
.active-filters .chip { background: var(--plum); border-color: var(--plum); }

.count { color: var(--muted); font-size: 13px; padding: 0 16px; margin: 6px 0; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; padding: 0 16px 24px; }
.card { position: relative; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--panel); padding: 0; text-align: left; aspect-ratio: 3 / 4; display: block; width: 100%; }
.card img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card .text { padding: 32px 10px 10px; display: grid; gap: 6px; align-content: start; height: 100%; }
.card .src { font-size: 12px; color: var(--accent); }
.card .title { font-weight: 600; font-size: 14px; }
.card .tags { font-size: 12px; color: var(--text); opacity: .85; }
.card .good { font-size: 13px; color: var(--muted); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 6; -webkit-box-orient: vertical; }
.card .badge { position: absolute; top: 6px; left: 6px; font-size: 11px; background: rgba(20, 11, 28, .8); border-radius: 6px; padding: 2px 6px; }
.card .stars { position: absolute; bottom: 6px; right: 6px; font-size: 12px; background: rgba(20, 11, 28, .8); border-radius: 6px; padding: 2px 6px; color: var(--accent); }
.more { display: block; margin: 0 auto 32px; }

dialog { border: 1px solid var(--line); border-radius: 12px; background: var(--bg); color: var(--text); padding: 0; width: min(720px, calc(100vw - 16px)); max-height: calc(100dvh - 16px); }
dialog::backdrop { background: rgba(0, 0, 0, .7); }
.detail { padding: 16px; display: grid; gap: 12px; position: relative; }
.detail h2 { margin: 0; font-size: 17px; }
.close { position: absolute; top: 8px; right: 8px; width: 36px; height: 36px; padding: 0; font-size: 20px; z-index: 2; }
.detail-media img { width: 100%; max-height: 70dvh; object-fit: contain; border-radius: 8px; background: #000; display: block; }
.detail-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.rating { display: flex; gap: 4px; }
.rating button { font-size: 18px; padding: 4px 8px; color: var(--muted); }
.rating button[aria-pressed="true"] { color: var(--accent); border-color: var(--accent); }
.fields { display: grid; gap: 8px; grid-template-columns: 1fr 1fr; }
.fields label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
.fields label.wide { grid-column: 1 / -1; }
.file { display: block; border: 1px dashed var(--line); border-radius: 10px; padding: 18px; text-align: center; cursor: pointer; }
.file input { display: none; }
.hint { color: var(--muted); font-size: 13px; margin: 0; }

@media (max-width: 480px) {
  .grid { grid-template-columns: repeat(2, 1fr); }
  .fields { grid-template-columns: 1fr; }
}
