:root {
  --floor: #edeff3;
  --card: #ffffff;
  --ink: #1c1e2b;
  --muted: #6b6f80;
  --line: #d5d9e2;
  --pink: #e4007f;
  --pink-soft: #fde6f2;
  --tape: #f4c20d;

  --font-ui: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  --font-jp: "Zen Kaku Gothic New", "Hiragino Sans", "Yu Gothic", "Meiryo", var(--font-ui);
  --font-display: "Dela Gothic One", "Zen Kaku Gothic New", var(--font-ui);

  --radius: 10px;
  --tray-h: 112px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--floor);
  color: var(--ink);
  font: 15px/1.6 var(--font-ui);
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--pink); outline-offset: 2px; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

main { max-width: 1040px; margin: 0 auto; padding: 0 16px; }

/* ---------- masthead ---------- */
.masthead {
  max-width: 1040px;
  margin: 0 auto;
  padding: 36px 16px 20px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}
.masthead-main { min-width: 0; position: relative; z-index: 0; }
.seg-lang {
  position: relative;
  z-index: 20;
  flex: none;
  margin-top: 6px;
}
.seg-lang button { pointer-events: auto; }
.eyebrow {
  margin: 0;
  font: 700 13px/1 var(--font-jp);
  letter-spacing: .2em;
  color: var(--muted);
}
.masthead h1 {
  margin: 10px 0 8px;
  display: flex;
  align-items: baseline;
  gap: 14px;
  flex-wrap: wrap;
}
.kami {
  font: 400 clamp(56px, 11vw, 96px)/.9 var(--font-display);
  letter-spacing: -.02em;
  color: var(--ink);
  position: relative;
  padding-bottom: 6px;
}
.kami.long { font-size: clamp(40px, 8vw, 72px); }
.kami::after {
  /* stage position tape under the headline */
  content: "";
  position: absolute; left: 4px; right: 8%; bottom: -4px;
  height: 12px;
  background: var(--pink);
  transform: rotate(-1.2deg);
}
.masthead .sub {
  font: 700 18px/1 var(--font-ui);
  color: var(--muted);
}
/* ---------- toolbar ---------- */
.toolbar {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 12px;
}
.seg {
  display: inline-flex;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px;
}
.seg button {
  border: 0;
  background: transparent;
  padding: 6px 14px;
  border-radius: 999px;
  color: var(--muted);
  font-weight: 700;
}
.seg button[aria-checked="true"] { background: var(--ink); color: #fff; }
.search { flex: 1 1 240px; }
.search input {
  width: 100%;
  padding: 9px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
}

#phase-pick:not([hidden]) {
  display: flex;
  flex-direction: column;
  min-height: calc(100dvh - 200px);
}
#phase-pick.pick-16:not([hidden]) {
  min-height: calc(100dvh - 168px);
}

/* ---------- roster (accordion) ---------- */
.roster {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  flex: 1 1 auto;
  min-height: 220px;
  height: auto;
  max-height: none;
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
}
.gen + .gen { border-top: 1px solid var(--line); }
.gen-head {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border: 0;
  background: var(--card);
  text-align: left;
}
.gen-head:hover { background: #f7f8fa; }
.gen-head .chev {
  width: 10px; height: 10px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(-45deg);
  transition: transform .18s ease;
  flex: none;
}
.gen-head[aria-expanded="true"] .chev { transform: rotate(45deg); }
.gen-head[aria-expanded="true"] { border-bottom: 1px solid var(--line); }
.gen-name { font: 700 16px/1.2 var(--font-jp); }
.gen-count { color: var(--muted); font-size: 13px; }
.gen-picked {
  margin-left: auto;
  background: var(--pink);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  padding: 1px 9px;
  border-radius: 999px;
}
.gen-picked:empty { display: none; }

.gen-body {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  gap: 12px 10px;
  padding: 14px 16px 18px;
}
.gen-body[hidden] { display: none; }

.card {
  position: relative;
  border: 0;
  padding: 0;
  background: none;
  text-align: center;
  min-width: 0;
}
.card .ph {
  display: block;
  aspect-ratio: 3 / 4;
  border-radius: 8px;
  overflow: hidden;
  background: #e4e7ee;
  outline: 3px solid transparent;
  outline-offset: -3px;
  transition: outline-color .12s, transform .12s;
}
.card img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 22%; display: block; }
.card:hover .ph { transform: translateY(-2px); }
.card .nm {
  display: block;
  margin-top: 5px;
  font: 700 13px/1.3 var(--font-jp);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card .meta {
  display: block;
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card .meta.now { color: var(--pink); font-weight: 700; }
.card[aria-pressed="true"] .ph { outline-color: var(--pink); }
.card[aria-pressed="true"]::after {
  content: attr(data-order);
  position: absolute;
  top: -5px; right: -5px;
  width: 24px; height: 24px;
  display: grid; place-items: center;
  background: var(--pink);
  color: #fff;
  border-radius: 50%;
  font: 700 12px/1 var(--font-ui);
  box-shadow: 0 0 0 2px var(--card);
}
.roster.full .card[aria-pressed="false"] { opacity: .45; }

.empty {
  padding: 48px 16px;
  text-align: center;
  color: var(--muted);
}
.search-hint {
  padding: 10px 16px;
  color: var(--muted);
  font-size: 13px;
  border-bottom: 1px solid var(--line);
}

/* ---------- tray: seven stage marks ---------- */
.tray {
  position: relative;
  z-index: 5;
  flex: none;
  margin: 12px -16px 0;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: rgba(237, 239, 243, .94);
  display: flex;
  align-items: center;
  gap: 16px;
}
.tray-main { flex: 1; min-width: 0; }
.tray-hint { margin: 6px 0 0; font-size: 12px; color: var(--muted); }
.slots {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(var(--slots, 7), minmax(36px, 1fr));
  gap: 8px;
  flex: 1;
  min-width: 0;
}
.tray.wide .slots {
  grid-template-columns: repeat(8, minmax(0, 1fr));
  max-height: none;
  overflow: visible;
}
.slot {
  position: relative;
  aspect-ratio: 3 / 4;
  max-height: 88px;
  border-radius: 6px;
}
.slot.empty-slot {
  /* an X of floor tape marks the empty position */
  background:
    linear-gradient(45deg, transparent 45%, var(--tape) 45%, var(--tape) 55%, transparent 55%) center / 46% 46% no-repeat,
    linear-gradient(-45deg, transparent 45%, var(--tape) 45%, var(--tape) 55%, transparent 55%) center / 46% 46% no-repeat,
    #e2e5ec;
}
.slot button {
  width: 100%; height: 100%;
  padding: 0;
  border: 0;
  border-radius: 6px;
  overflow: hidden;
  background: #e4e7ee;
  display: block;
}
.slot img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 22%; display: block; }
.slot button::after {
  content: "×";
  position: absolute;
  top: 2px; right: 2px;
  width: 20px; height: 20px;
  display: grid; place-items: center;
  background: rgba(28, 30, 43, .78);
  color: #fff;
  border-radius: 50%;
  font-size: 14px; line-height: 1;
  pointer-events: none;
}
.tray.shake { animation: shake .35s; }
@keyframes shake {
  25% { transform: translateX(-6px); }
  50% { transform: translateX(6px); }
  75% { transform: translateX(-3px); }
}

.primary, .ghost {
  border-radius: 999px;
  padding: 11px 22px;
  font-weight: 700;
  white-space: nowrap;
}
.primary { border: 0; background: var(--pink); color: #fff; }
.primary:disabled { background: #c9ccd6; cursor: not-allowed; }
.ghost { border: 1px solid var(--line); background: var(--card); }
.ghost:disabled { opacity: .45; cursor: not-allowed; }

/* ---------- duel ---------- */
.duel-head { text-align: center; margin-bottom: 18px; }
.duel-head h2 { margin: 0; font: 700 24px/1.3 var(--font-ui); }
.duel-progress { margin: 4px 0 8px; color: var(--muted); font-size: 13px; }
.bar { height: 4px; max-width: 320px; margin: 0 auto; background: var(--line); border-radius: 2px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--pink); transition: width .25s ease; }

.duel {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 14px;
  max-width: 720px;
  margin: 0 auto;
}
.or { font: 400 20px/1 var(--font-display); color: var(--muted); }
.fighter {
  border: 0;
  padding: 10px 10px 14px;
  background: var(--card);
  border-radius: 14px;
  box-shadow: 0 1px 0 var(--line), 0 10px 30px -18px rgba(28, 30, 43, .35);
  transition: transform .15s ease, box-shadow .15s ease;
  text-align: center;
  min-width: 0;
}
.fighter:hover { transform: translateY(-4px); box-shadow: 0 0 0 3px var(--pink), 0 14px 30px -18px rgba(28, 30, 43, .4); }
.fighter.picked { transform: scale(.97); box-shadow: 0 0 0 4px var(--pink); }
.fighter .ph { display: block; aspect-ratio: 3 / 4; border-radius: 8px; overflow: hidden; background: #e4e7ee; }
.fighter img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 22%; display: block; }
.fighter .nm { display: block; margin-top: 10px; font: 700 20px/1.2 var(--font-jp); }
.fighter .kn { display: block; font-size: 12px; color: var(--muted); }
.fighter .meta { display: block; margin-top: 2px; font-size: 12px; color: var(--muted); }

.duel-actions { display: flex; justify-content: center; gap: 10px; margin-top: 22px; }
.hint { text-align: center; color: var(--muted); font-size: 12px; }

/* ---------- result ---------- */
.result-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
  gap: 28px;
  align-items: start;
}
.poster { margin: 0; }
.poster img {
  width: 100%;
  display: block;
  border-radius: 8px;
  box-shadow: 0 18px 40px -24px rgba(28, 30, 43, .45);
  background: var(--card);
  aspect-ratio: 3 / 4;
}
.poster.tall img { aspect-ratio: 9 / 16; }
.poster figcaption { margin-top: 8px; text-align: center; color: var(--muted); font-size: 12px; }
.field { display: block; }
.field span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  font-weight: 700;
}
.rank-list { list-style: none; margin: 18px 0; padding: 0; }
.rank-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 7px 0;
  border-bottom: 1px solid var(--line);
}
.rank-list .no {
  width: 36px;
  font: 400 22px/1 var(--font-display);
  text-align: center;
}
.rank-list li:first-child .no { color: var(--pink); }
.rank-list img { width: 40px; height: 40px; object-fit: cover; object-position: 50% 20%; border-radius: 6px; }
.rank-list .nm { font: 700 15px/1.3 var(--font-jp); }
.rank-list .meta { display: block; font-size: 12px; color: var(--muted); font-weight: 400; font-family: var(--font-ui); }
.result-actions { display: flex; flex-wrap: wrap; gap: 10px; }

.colophon {
  max-width: 1040px;
  margin: 40px auto 0;
  padding: 20px 16px 40px;
  color: var(--muted);
  font-size: 12px;
}
.colophon a { color: inherit; }

/* ---------- small screens ---------- */
@media (max-width: 720px) {
  .masthead { padding-top: 24px; }
  #phase-pick:not([hidden]) { min-height: calc(100dvh - 156px); }
  .roster { min-height: 180px; }
  .gen-body { grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 10px 8px; padding: 12px; }
  .tray { flex-direction: column; align-items: stretch; gap: 10px; }
  .tray.wide .slots { grid-template-columns: repeat(8, minmax(0, 1fr)); max-height: none; }
  .slots { gap: 6px; }
  .duel { gap: 8px; }
  .fighter { padding: 6px 6px 10px; }
  .fighter .nm { font-size: 16px; }
  .result-grid { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
