:root {
  --purple: #4b207d;
  --purple-dark: #2d0d50;
  --purple-light: #8a5ec0;
  --ink: #1b1422;
  --paper: #fbf9fd;
  --line: #ded4e8;
  --pink: #ef7fab;
  --white: #fff;
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", "Noto Sans JP", system-ui, sans-serif;
  color: var(--ink);
  background: #ece6f2;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: #ece6f2; }
body { margin: 0; min-height: 100vh; background: radial-gradient(circle at 20% -10%, #fff 0, transparent 34%), #ece6f2; }
button { font: inherit; }
button:focus-visible { outline: 3px solid #ffb5d2; outline-offset: 3px; }
.hidden { display: none !important; }
.ambient { position: fixed; inset: 0; pointer-events: none; opacity: .16; background-image: linear-gradient(90deg, transparent 49.7%, #4b207d 50%, transparent 50.3%), linear-gradient(0deg, transparent 49.7%, #4b207d 50%, transparent 50.3%); background-size: 72px 72px; mask-image: linear-gradient(to bottom, #000, transparent 75%); }
.app-shell { position: relative; width: min(100%, 780px); min-height: 100vh; margin: 0 auto; background: var(--paper); box-shadow: 0 0 70px rgba(45,13,80,.14); overflow: hidden; }
.app-shell::before { content: ""; position: absolute; top: 0; right: -110px; width: 260px; height: 180px; background: var(--purple); transform: skewX(-28deg); opacity: .08; pointer-events: none; }
.topbar { min-height: 76px; padding: 16px 20px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); position: relative; z-index: 2; }
.brand { display: inline-flex; align-items: center; gap: 10px; border: 0; background: transparent; padding: 0; color: var(--purple); cursor: pointer; text-align: left; }
.brand-mark { display: grid; place-items: center; width: 38px; height: 38px; background: var(--purple); color: #fff; font: 800 22px/1 Georgia, serif; transform: rotate(-5deg); }
.brand b { display: block; font: 800 14px/1.05 Georgia, serif; letter-spacing: .12em; }
.brand small { display: block; margin-top: 4px; font-size: 9px; letter-spacing: .13em; }
.unofficial { font-size: 9px; letter-spacing: .12em; color: #776d7f; }
.view { padding: 34px 20px 46px; min-height: 680px; animation: enter .36s ease both; }
@keyframes enter { from { opacity: 0; transform: translateY(8px); } }
.home-view { padding-top: 48px; text-align: center; }
.eyebrow, .stage-kicker { color: var(--purple); font: 800 12px/1 Georgia, serif; letter-spacing: .22em; }
h1 { margin: 16px 0 22px; font-size: clamp(42px, 11vw, 74px); line-height: .94; letter-spacing: -.06em; color: var(--purple-dark); }
h1 > span:first-child { font-size: .48em; letter-spacing: .12em; display: inline-block; margin-bottom: 10px; }
h1 .nine { display: inline-grid; place-items: center; margin: 0 .05em; width: .95em; height: .95em; border-radius: 50%; background: var(--purple); color: #fff; font-family: Georgia, serif; transform: rotate(-7deg); }
.lead { margin: 0 auto; font-size: 16px; line-height: 1.9; color: #524a58; }
.flow-strip { display: grid; grid-template-columns: 1fr auto 1fr auto 1fr; align-items: center; gap: 8px; margin: 34px auto; max-width: 620px; padding: 20px 14px; border-block: 1px solid var(--line); }
.flow-strip div { min-width: 0; }
.flow-strip b { display: block; color: var(--pink); font: 700 13px Georgia, serif; }
.flow-strip span { display: block; margin: 5px 0; font-weight: 800; font-size: 15px; }
.flow-strip small { color: #746a7c; font-size: 11px; line-height: 1.45; }
.flow-strip i { color: #b6a8c4; font-style: normal; }
.primary-button, .secondary-button, .resume-button { border: 0; min-height: 54px; padding: 0 24px; font-weight: 800; letter-spacing: .04em; cursor: pointer; }
.primary-button { min-width: min(100%, 330px); background: var(--purple); color: #fff; box-shadow: 7px 7px 0 #d8cae5; transition: transform .16s, box-shadow .16s; }
.primary-button:hover { transform: translate(2px,2px); box-shadow: 5px 5px 0 #d8cae5; }
.primary-button span { margin-left: 28px; }
.resume-button { display: block; margin: 18px auto 0; min-width: min(100%,330px); background: transparent; color: var(--purple); border: 1px solid var(--purple); }
.microcopy { margin-top: 22px; color: #8c8392; font-size: 11px; }
.stage-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; }
.stage-head h2 { margin: 7px 0 0; font-size: clamp(24px, 6vw, 38px); letter-spacing: -.04em; }
.counter { white-space: nowrap; color: var(--purple); }
.counter strong { font: 700 34px Georgia, serif; }
.counter span { font: 700 16px Georgia, serif; color: #8e8298; }
.instruction { margin: 12px 0 18px; color: #6c6273; font-size: 14px; }
.progress { height: 4px; background: #e9e1ef; margin-bottom: 24px; overflow: hidden; }
.progress span { display: block; height: 100%; width: 0; background: linear-gradient(90deg,var(--purple),var(--pink)); transition: width .3s ease; }
.member-grid { display: grid; grid-template-columns: repeat(2,1fr); gap: 12px; }
.member-card { position: relative; border: 1px solid var(--line); background: #fff; padding: 0; overflow: hidden; cursor: pointer; color: var(--ink); text-align: left; transition: transform .18s, border-color .18s, box-shadow .18s; }
.member-card::after { content: "♡"; position: absolute; top: 8px; right: 8px; display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: rgba(255,255,255,.88); color: var(--purple); font-size: 19px; box-shadow: 0 2px 9px rgba(0,0,0,.08); }
.member-card.selected { border-color: var(--purple); box-shadow: inset 0 0 0 2px var(--purple), 6px 6px 0 #dfd2eb; transform: translate(-2px,-2px); }
.member-card.selected::after { content: "♥"; color: #fff; background: var(--purple); }
.member-photo { display: block; width: 100%; aspect-ratio: 4/5; object-fit: cover; object-position: center top; background: #e8e0ed; }
.member-meta { display: flex; align-items: center; justify-content: space-between; gap: 5px; padding: 11px 10px 12px; }
.member-meta strong { font-size: 15px; letter-spacing: .02em; }
.member-meta small { padding: 3px 5px; color: var(--purple); background: #f1eaf7; font-size: 10px; white-space: nowrap; }
.selection-status { text-align: center; color: var(--purple); font-size: 13px; font-weight: 700; }
.inline-error { margin: 10px 0; padding: 10px 12px; color: #8b204b; background: #fff0f5; border-left: 3px solid var(--pink); font-size: 13px; }
.nav-row { display: grid; grid-template-columns: 1fr 1.6fr; gap: 12px; margin-top: 18px; }
.secondary-button { background: #eee8f2; color: var(--purple-dark); }
.secondary-button:disabled { opacity: .38; cursor: default; }
.primary-button.compact { min-width: 0; width: 100%; box-shadow: 5px 5px 0 #d8cae5; }
.duel-progress { margin-bottom: 30px; }
.duel-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: stretch; }
.duel-card { position: relative; border: 0; padding: 0; background: #fff; color: var(--ink); cursor: pointer; box-shadow: 0 10px 30px rgba(45,13,80,.12); transition: transform .18s, box-shadow .18s; overflow: hidden; }
.duel-card:hover { transform: translateY(-4px); box-shadow: 0 14px 34px rgba(45,13,80,.2); }
.duel-card img { width: 100%; aspect-ratio: 4/5.25; object-fit: cover; object-position: center top; display: block; }
.duel-card div { min-height: 74px; padding: 14px 8px; display: grid; place-items: center; }
.duel-card strong { font-size: clamp(15px,4vw,20px); }
.duel-card small { color: var(--purple); }
.duel-grid::after { content: "VS"; position: absolute; left: 50%; top: 49%; transform: translate(-50%,-50%) rotate(-7deg); width: 46px; height: 46px; display: grid; place-items: center; border-radius: 50%; background: var(--purple); color: #fff; border: 3px solid var(--paper); font: 700 14px Georgia,serif; pointer-events: none; }
.duel-grid { position: relative; }
.text-button { display: block; margin: 26px auto 0; border: 0; background: transparent; color: #776d80; text-decoration: underline; cursor: pointer; font-size: 13px; }
.text-button:disabled { opacity: .3; cursor: default; }
.result-heading { text-align: center; }
.result-heading h2 { margin: 10px 0 5px; color: var(--purple-dark); font-size: clamp(34px,9vw,58px); line-height: 1.05; letter-spacing: -.05em; }
.result-heading em { color: var(--purple); font-style: normal; }
.result-heading p { color: #7a7081; font-size: 12px; }
.result-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: 7px; margin-top: 28px; }
.result-card { position: relative; background: var(--purple-dark); color: #fff; overflow: hidden; }
.result-card img { display: block; width: 100%; aspect-ratio: 1/1.24; object-fit: cover; object-position: center top; }
.result-card .rank { position: absolute; top: 5px; left: 5px; display: grid; place-items: center; width: 30px; height: 30px; background: var(--purple); border-radius: 50%; border: 2px solid white; font: 700 14px Georgia,serif; }
.result-card div:last-child { min-height: 54px; padding: 8px 4px 9px; display: grid; place-content: center; text-align: center; }
.result-card strong { font-size: clamp(11px,2.7vw,16px); line-height: 1.3; overflow-wrap: anywhere; }
.result-card small { display: block; margin-top: 3px; color: #d8cbe5; font-size: 9px; }
.result-actions { margin-top: 30px; text-align: center; }
.result-actions #restartButton { display: block; width: min(100%,330px); margin: 18px auto 0; }
#shareButton:disabled { opacity: .65; cursor: wait; }
#shareStatus { font-size: 14px; line-height: 1.6; color: var(--purple); }
#shareStatus:empty { display: none; }
#shareFallback { margin-top: 16px; font-size: 14px; text-align: left; }
#shareLink { display: block; width: 100%; margin-top: 6px; padding: 12px; font-size: 16px; border: 1px solid var(--line); border-radius: 4px; }
footer { padding: 18px 20px 30px; border-top: 1px solid var(--line); color: #958b9b; font-size: 10px; line-height: 1.7; text-align: center; }
footer a { color: var(--purple); }

@media (min-width: 680px) {
  .view { padding-inline: 42px; }
  .member-grid { grid-template-columns: repeat(4,1fr); gap: 14px; }
  .member-grid.is-three { grid-template-columns: repeat(3,1fr); max-width: 560px; margin-inline: auto; }
  .duel-grid { gap: 28px; max-width: 620px; margin-inline: auto; }
  .result-grid { gap: 11px; }
  .result-card div:last-child { padding-block: 12px; }
}

@media (max-width: 430px) {
  .topbar { padding-inline: 14px; }
  .unofficial { max-width: 74px; text-align: right; line-height: 1.4; }
  .flow-strip { padding-inline: 0; gap: 3px; }
  .flow-strip small { display: none; }
  .view { min-height: 640px; }
  .member-meta { align-items: flex-start; flex-direction: column; }
  .member-meta strong { font-size: 14px; }
}

/* Keep the complete mobile selection task inside the viewport even while
   Safari's address bar is expanded. Allow scrolling on very short screens
   or with enlarged text instead of clipping controls. */
@media (max-width: 679px) {
  .topbar { min-height: 52px; height: 52px; padding: 8px 14px; }
  .brand-mark { width: 30px; height: 30px; font-size: 20px; }
  #prelimView, #duelView {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 52px);
    height: calc(100svh - 52px);
    min-height: 440px;
    padding: 12px 14px max(16px, env(safe-area-inset-bottom));
  }
  #prelimView .stage-head, #duelView .stage-head { gap: 8px; flex-shrink: 0; }
  #prelimView .stage-kicker { display: none; }
  #prelimView h2, #duelView h2 { margin: 0; font-size: 22px; }
  #duelView .stage-kicker { display: block; margin-bottom: 6px; letter-spacing: .03em; }
  #prelimView .counter strong, #duelView .counter strong { font-size: 26px; }
  #duelView .stage-head { flex-wrap: wrap; }
  #duelView .counter span { font-size: 14px; }
  #prelimView .instruction, #duelView .instruction { margin: 8px 0; font-size: 14px; line-height: 1.5; }
  #prelimView .progress, #duelView .progress { flex-shrink: 0; margin-bottom: 10px; }
  #prelimGrid {
    flex: 1;
    min-height: 200px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }
  #prelimGrid .member-card { display: grid; grid-template-rows: minmax(0, 1fr) auto; min-height: 0; }
  #prelimGrid .member-photo { height: 100%; min-height: 0; aspect-ratio: auto; object-position: center 20%; }
  #prelimGrid .member-meta { flex-direction: row; align-items: center; padding: 7px 8px; gap: 4px; min-height: 38px; }
  #prelimGrid .member-meta strong { font-size: 14px; line-height: 1.3; overflow-wrap: anywhere; }
  #prelimGrid .member-meta small { font-size: 12px; padding: 2px 3px; }
  #prelimGrid .member-card::after { top: 6px; right: 6px; width: 28px; height: 28px; }
  #prelimGrid .member-card.selected { transform: none; box-shadow: inset 0 0 0 2px var(--purple); }
  #prelimView .selection-status { margin: 8px 0 0; font-size: 14px; }
  #prelimView .nav-row { flex-shrink: 0; margin-top: 8px; }
  #prelimView .nav-row button { min-height: 44px; padding: 0 12px; }
  #prelimView .inline-error { margin: 6px 0 0; padding: 6px 8px; }
  #duelGrid { flex: 1; min-height: 180px; width: 100%; gap: 10px; }
  #duelGrid .duel-card { display: grid; grid-template-rows: minmax(0, 1fr) auto; min-height: 0; }
  #duelGrid img { height: 100%; min-height: 0; aspect-ratio: auto; object-position: center 20%; }
  #duelGrid .duel-card div { min-height: 60px; padding: 8px; }
  #duelBack { flex-shrink: 0; min-height: 44px; margin: 8px auto 0; font-size: 14px; }
}

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