/* 上に絞り込み、下に「スクロールする一覧」と「詳細」。一覧が主役なので装飾は控えめ。 */
:root {
  --bg: #f3f4f7;
  --surface: #ffffff;
  --surface-2: #eceef3;
  --line: #d8dbe3;
  --ink: #1c1f26;
  --muted: #5d6472;
  --accent: #2f5fd0;
  --accent-ink: #ffffff;
  --focus: #2f5fd0;
  --civ-light: #e2b93b;
  --civ-water: #2f80c9;
  --civ-dark: #5b4a6e;
  --civ-fire: #d2412f;
  --civ-nature: #3a9150;
  --civ-zero: #9a9fa8;
  --shadow: 0 8px 28px rgba(20, 24, 40, 0.18);
  --font: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", Meiryo, system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161b;
    --surface: #1d2027;
    --surface-2: #262a33;
    --line: #353a45;
    --ink: #e7e9ee;
    --muted: #9aa1ae;
    --accent: #6f97ff;
    --accent-ink: #0d1020;
    --focus: #8fb0ff;
    --civ-dark: #8a76a3;
    --civ-zero: #b4b9c2;
    --shadow: 0 8px 28px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--ink); font: 14px/1.5 var(--font); }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.app { display: flex; flex-direction: column; height: 100dvh; }

/* ---- 上部の絞り込み ---- */
.top {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 8px max(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left));
  padding-top: max(8px, env(safe-area-inset-top));
}
.top__title { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.top__title h1 { font-size: 16px; margin: 0; letter-spacing: 0.02em; }
.badge { font-size: 11px; padding: 1px 6px; border-radius: 4px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }
.filters { display: grid; gap: 6px; }
.filters__row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.field { display: inline-flex; align-items: center; gap: 6px; min-width: 0; }
.field--grow { flex: 1 1 260px; }
.field--grow input { width: 100%; }
.field--wide input { width: min(320px, 60vw); }
.field__label { color: var(--muted); font-size: 12px; white-space: nowrap; }
input, select {
  background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; min-width: 0;
}
input[type="number"] { width: 4.6em; }
#f-power-min, #f-power-max { width: 6.5em; }
#f-race, #f-keyword { width: 12em; }

.civs { display: inline-flex; gap: 4px; }
.civ {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 3px 10px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 5px;
}
.civ::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--c); }
.civ[data-civ="光"] { --c: var(--civ-light); }
.civ[data-civ="水"] { --c: var(--civ-water); }
.civ[data-civ="闇"] { --c: var(--civ-dark); }
.civ[data-civ="火"] { --c: var(--civ-fire); }
.civ[data-civ="自然"] { --c: var(--civ-nature); }
.civ[data-civ="ゼロ"] { --c: var(--civ-zero); }
.civ[aria-pressed="true"] { background: var(--c); border-color: var(--c); color: #fff; }
.civ[aria-pressed="true"]::before { background: #fff; }

.more summary { cursor: pointer; color: var(--accent); list-style: none; padding: 4px 2px; }
.more summary::-webkit-details-marker { display: none; }
.more summary::after { content: " ▾"; }
.more[open] summary::after { content: " ▴"; }
.more__body {
  display: flex; flex-wrap: wrap; gap: 8px 14px; padding: 8px 0 4px; width: 100%;
}
.more[open] { flex-basis: 100%; }

.filters__row--meta { gap: 6px 14px; }
.density { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.density button { border: 0; background: var(--surface); padding: 4px 10px; cursor: pointer; }
.density button + button { border-left: 1px solid var(--line); }
.density button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.check { display: inline-flex; gap: 5px; align-items: center; cursor: pointer; }
.count { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; }
.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 6px; padding: 5px 10px; cursor: pointer; }
.btn--quiet { color: var(--muted); }

/* ---- 一覧 ---- */
.main { flex: 1; min-height: 0; display: flex; position: relative; }
.grid-wrap {
  flex: 1; min-width: 0; overflow-y: auto; overscroll-behavior: contain;
  padding: 0 max(6px, env(safe-area-inset-right)) 0 max(6px, env(safe-area-inset-left));
}
.grid__spacer { position: relative; }
.grid__row {
  position: absolute; left: 0; right: 0; top: 0;
  display: grid; grid-template-columns: repeat(var(--tile-cols), var(--tile-w)); gap: 6px;
}
.status { color: var(--muted); padding: 24px 8px; margin: 0; }

.tile {
  border: 0; padding: 0; background: none; cursor: pointer; text-align: left; min-width: 0;
  display: flex; flex-direction: column; gap: 2px;
}
.tile__frame {
  position: relative; width: 100%; aspect-ratio: 63 / 88; border-radius: 5px; overflow: hidden;
  background: var(--surface-2); border: 1px solid var(--line);
}
.tile__img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }
.tile__band { position: absolute; left: 0; top: 0; bottom: 0; width: 5px; }
.tile__text { display: none; position: absolute; inset: 0; padding: 6px 5px 6px 10px; overflow: hidden; font-size: 11px; line-height: 1.35; }
.tile--text .tile__text { display: flex; flex-direction: column; gap: 6px; }
.tile__face { display: flex; flex-direction: column; gap: 2px; }
.tile__face .tile__cost {
  align-self: flex-start; min-width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center;
  background: var(--ink); color: var(--bg); font-weight: 700; font-size: 11px; padding: 0 4px;
}
.tile__face .tile__name { font-weight: 700; word-break: break-all; }
.tile__sub { color: var(--muted); font-size: 10px; }
.tile__cap { display: flex; gap: 4px; font-size: 11px; line-height: 16px; height: 16px; white-space: nowrap; overflow: hidden; }
.tile__cap .tile__cost { color: var(--muted); font-variant-numeric: tabular-nums; flex: none; }
.tile__cap .tile__name { overflow: hidden; text-overflow: ellipsis; }
.tile:hover .tile__frame { border-color: var(--accent); }
.tile.is-selected .tile__frame { outline: 3px solid var(--accent); outline-offset: -1px; }

/* ---- 詳細 ---- */
.detail {
  width: 380px; flex: none; border-left: 1px solid var(--line); background: var(--surface);
  overflow-y: auto; padding: 14px 16px 24px;
}
.detail__close {
  float: right; border: 1px solid var(--line); background: var(--surface); border-radius: 50%;
  width: 32px; height: 32px; cursor: pointer; font-size: 16px; line-height: 1;
}
.detail__img { display: block; width: min(100%, 260px); aspect-ratio: 63 / 88; margin: 4px auto 12px; border-radius: 8px; background: var(--surface-2); object-fit: contain; }
.detail h2 { font-size: 17px; margin: 0 0 8px; text-wrap: balance; }
.detail h3 { font-size: 14px; margin: 16px 0 6px; padding-top: 12px; border-top: 1px solid var(--line); }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; margin: 0; font-size: 13px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; font-variant-numeric: tabular-nums; }
.ability { white-space: pre-wrap; background: var(--surface-2); border-radius: 6px; padding: 8px 10px; margin: 8px 0 0; font-size: 13px; }
.flavor { color: var(--muted); font-style: italic; font-size: 12px; margin: 6px 0 0; }
.links { display: grid; gap: 6px; margin-top: 14px; }
.links a {
  display: block; text-align: center; text-decoration: none; padding: 9px 10px; border-radius: 8px;
  border: 1px solid var(--line); color: var(--ink); background: var(--surface-2); font-weight: 600;
}
.links a:hover { border-color: var(--accent); }
.products { margin: 6px 0 0; padding-left: 18px; font-size: 12px; color: var(--muted); }

@media (max-width: 899px) {
  .detail {
    position: fixed; left: 0; right: 0; bottom: 0; width: auto; max-height: 78dvh; z-index: 20;
    border-left: 0; border-top: 1px solid var(--line); border-radius: 14px 14px 0 0; box-shadow: var(--shadow);
    padding-bottom: max(24px, env(safe-area-inset-bottom));
  }
  .field--wide input { width: 12em; }
}

/* ---- フッター ---- */
.foot {
  border-top: 1px solid var(--line); background: var(--surface); color: var(--muted); font-size: 11px;
  padding: 4px max(12px, env(safe-area-inset-right)) max(4px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
}
.foot { display: flex; flex-wrap: wrap; gap: 0 12px; }
.foot p { margin: 1px 0; }
@media (min-width: 1100px) {
  .top { display: flex; gap: 16px; align-items: flex-start; }
  .top__title { flex-direction: column; align-items: flex-start; gap: 2px; margin: 4px 0 0; flex: none; }
  .top__title h1 { white-space: nowrap; font-size: 15px; }
  .filters { flex: 1; min-width: 0; }
}
.foot__short { display: none; }
.foot__rights:empty { display: none; }
.toggle-filters, .count--mobile { display: none; }

/* ---- スマホ：一覧を広く見せるため、絞り込みは折りたたむ ---- */
@media (max-width: 599px) {
  .top__title { margin-bottom: 4px; }
  .top__title h1 { font-size: 14px; }
  .toggle-filters { display: inline-flex; }
  .toggle-filters[aria-expanded="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
  .count--mobile { display: inline; margin-left: 0; font-size: 12px; }
  .filters__row--main .field--grow { flex-basis: 150px; }
  .filters:not(.is-open) .filters__row:not(.filters__row--main),
  .filters:not(.is-open) .filters__row--main .civs,
  .filters:not(.is-open) .filters__row--main .field--range { display: none; }
  .filters__row--meta .count { display: none; }
  .foot__about, .foot #updated { display: none; }
  .foot__line { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 10px; }
  .foot__short { display: inline; margin-right: 6px; }
}

@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }
