:root {
  --bg: #fff7f0;
  --surface: #ffffff;
  --surface-2: #fff0e8;
  --text: #3a2a28;
  --text-muted: #8a7a76;
  --accent: #ff6e82;
  --accent-2: #ffb648;
  --border: #f0ddd4;
  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-sm: 10px;
  --anchor-ad-space: 96px;
  --shadow: 0 6px 16px rgba(120, 70, 60, 0.12);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #221a1c;
    --surface: #2c2224;
    --surface-2: #362a2c;
    --text: #f5e9e6;
    --text-muted: #bfa9a4;
    --accent: #ff8595;
    --accent-2: #ffc161;
    --border: #453538;
    --shadow: 0 6px 18px rgba(0, 0, 0, 0.4);
  }
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "M PLUS Rounded 1c", "Hiragino Maru Gothic ProN", "BIZ UDGothic", system-ui, sans-serif;
  line-height: 1.7;
  overflow-x: hidden;
  padding-bottom: var(--anchor-ad-space);
}

a {
  color: var(--accent);
}

button {
  font-family: inherit;
}

h1, h2, h3 {
  line-height: 1.4;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.site-header .brand {
  font-weight: 700;
  text-decoration: none;
  color: var(--text);
  font-size: 15px;
}

.site-header nav {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.site-header nav a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 14px;
  border-radius: 999px;
  background: var(--surface-2);
  text-decoration: none;
  color: var(--text);
  font-weight: 700;
  font-size: 14px;
}

.site-header nav a.site-share {
  background: var(--accent);
  color: #fff;
}

.site-header nav a[aria-current="page"] {
  background: var(--text);
  color: var(--bg);
}

main#app {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px;
}

.howto {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px 16px 0;
}

.howto ol {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 16px 16px 16px 36px;
  box-shadow: var(--shadow);
}

.howto li {
  margin-bottom: 6px;
}

.make-ad-slot {
  max-width: 720px;
  margin: 40px auto 0;
  padding: 0 16px;
}

.site-footer {
  max-width: 720px;
  margin: 24px auto 0;
  padding: 16px;
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
}

.site-footer a {
  color: var(--text-muted);
}

/* --- entry step --- */
.entry-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 12px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.entry-count {
  font-weight: 700;
  white-space: nowrap;
}

.entry-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  flex: 1 1 auto;
}

.entry-chip {
  position: relative;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  overflow: visible;
  background: var(--surface-2);
  flex-shrink: 0;
  border: none;
  padding: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.entry-chip img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  border-radius: 50%;
  overflow: hidden;
}

.entry-chip-x {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  line-height: 20px;
  pointer-events: none;
}

.start-battle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 52px;
  border: none;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 17px;
  font-weight: 700;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  margin: 8px 0 20px;
  box-sizing: border-box;
}

.start-battle:disabled {
  background: var(--border);
  color: var(--text-muted);
  cursor: not-allowed;
}

.entry-bar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-left: auto;
}

.entry-clear-mode,
.entry-clear-all {
  min-height: 32px;
  padding: 4px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
}

.entry-clear-mode[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.entry-clear-all:disabled {
  color: var(--text-muted);
  cursor: not-allowed;
}

.entry-chips.clear-mode .entry-chip {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  animation: chip-wiggle 0.5s ease-in-out infinite;
}

@keyframes chip-wiggle {
  0%, 100% { transform: rotate(0deg); }
  25% { transform: rotate(-6deg); }
  75% { transform: rotate(6deg); }
}

@media (prefers-reduced-motion: reduce) {
  .entry-chips.clear-mode .entry-chip {
    animation: none;
  }
}

.add-form {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.add-form h3, .browse h3 {
  margin-top: 0;
}

.add-form .row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.add-form input[type="text"],
.add-form select,
.browse input[type="text"],
.browse select {
  flex: 1 1 160px;
  min-height: 44px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 15px;
}

.add-form button,
.browse button {
  min-height: 44px;
  padding: 0 18px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--accent-2);
  color: #3a2a28;
  font-weight: 700;
  cursor: pointer;
}

.form-error {
  color: var(--accent);
  font-size: 13px;
  margin-top: 8px;
}

.gender-row {
  align-items: center;
  margin-bottom: 8px;
}

.gender-row input[type="radio"] {
  width: 20px;
  height: 20px;
  margin: 0;
  flex: 0 0 auto;
}

.gender-row label {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  margin-right: 12px;
  font-size: 14px;
}

.browse {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.browse-toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

/* Explicit, so the free picker's <dialog> button { flex: 1 1 auto } rule
   never stretches these toolbar buttons - they must size to their content,
   same as in the entry page's browse section. */
.browse-toolbar button {
  flex: 0 1 auto;
}

.browse-empty {
  color: var(--text-muted);
  text-align: center;
  padding: 20px 0;
}

.girl-grid {
  display: grid;
  /* minmax(0, 1fr), not plain 1fr: a long unbroken name must never force a
     column (and the whole grid) wider than the viewport. */
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.girl-card {
  border: 2px solid transparent;
  border-radius: var(--radius-md);
  background: var(--surface-2);
  padding: 8px;
  text-align: center;
  cursor: pointer;
  min-height: 44px;
  min-width: 0;
  overflow: hidden;
  font-family: inherit;
}

.girl-card.selected {
  border-color: var(--accent);
}

.girl-card img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 50%;
  background: var(--border);
}

.girl-card .name {
  font-size: 12px;
  margin-top: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.girl-card .category {
  font-size: 11px;
  color: var(--text-muted);
}

/* Explicit, so the generic `dialog div { display: flex }` rule (for the
   free picker's own <dialog>) never turns this into a row alongside the
   "more" button below it - it must always stack as a normal block, same
   as in the entry page's browse section. */
.browse-result {
  display: block;
  margin-top: 0;
}

.browse-more {
  display: block;
  width: 100%;
  min-height: 44px;
  margin-top: 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
}

/* --- battle step --- */
.battle-progress {
  text-align: center;
  margin-bottom: 12px;
  color: var(--text-muted);
  font-size: 14px;
}

.battle-progress .bar {
  height: 8px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
  margin-top: 6px;
}

.battle-progress .bar-fill {
  height: 100%;
  background: var(--accent);
}

.battle-cards {
  display: flex;
  gap: 14px;
  padding-bottom: 24px;
}

.battle-card {
  flex: 1 1 0;
  min-width: 0;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
  border: none;
  cursor: pointer;
  padding: 0 0 14px;
  min-height: 260px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.battle-card img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
}

.battle-card .name {
  margin-top: 10px;
  font-weight: 700;
  font-size: 15px;
  padding: 0 8px;
  text-align: center;
  width: 100%;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.battle-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-bottom: 16px;
}

.battle-actions button {
  min-height: 44px;
  padding: 0 16px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
}

/* --- decide / result --- */
.decide-list, .result-list, .ranking-list {
  list-style: none;
  margin: 0;
  padding: 0;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.decide-list li, .result-list li, .ranking-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  min-width: 0;
}

.row-info {
  min-width: 0;
  flex: 1 1 auto;
  overflow: hidden;
}

.decide-list li:last-child, .result-list li:last-child, .ranking-list li:last-child {
  border-bottom: none;
}

/* CLAUDE.md「広告枠をボタンの近くに置かない」: ランキング行内の広告(.ranking-ad)を
   前後のリンクっぽい行（アイコンリンク付きの行）から離す。 */
.ranking-list li.ranking-ad {
  /* block, not the rows' flex: a flex item shrinks to its content, which
     hands AdSense a zero-width slot and no ad is served */
  display: block;
  padding: 32px 0;
}

/* 同じ理由（CLAUDE.md「広告枠をボタンの近くに置かない」）: 結果ページの広告は
   9位の行のリンクアイコンのすぐ下に来るので、上に余白を空けて離す。 */
.result-ad {
  margin-top: 32px;
}

.rank-badge {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent-2);
  color: #3a2a28;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
}

.result-list img, .decide-list img, .ranking-list img {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--surface-2);
}

.result-list img.placeholder, .decide-list img.placeholder, .ranking-list img.placeholder {
  background: var(--border);
}

.row-links {
  display: flex;
  gap: 8px;
  flex: 0 0 auto;
  width: 88px;
  justify-content: flex-start;
}

.row-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  min-height: 40px;
}

.row-link img {
  width: 24px;
  height: 24px;
  border-radius: 0;
  background: none;
}

.result-name {
  display: block;
  font-weight: 700;
  text-decoration: none;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.result-meta {
  color: var(--text-muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.outs-heading {
  margin: 20px 0 4px;
  font-size: 16px;
}

.outs-note {
  margin: 0 0 8px;
  color: var(--text-muted);
  font-size: 12px;
}

.result-image {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1200 / 630;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.share-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}

.share-actions a, .share-actions button {
  flex: 1 1 auto;
  min-height: 48px;
  border-radius: 999px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  padding: 0 14px;
}

.share-actions .secondary {
  background: var(--surface-2);
  color: var(--text);
}

.deleted-note {
  color: var(--text-muted);
  font-style: normal;
}

.ranking-toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.ranking-toolbar select, .ranking-toolbar button {
  min-height: 44px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}

.ranking-toolbar button[aria-pressed="true"] {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* CLAUDE.md「広告枠をボタンの近くに置かない」: 直前の行に広告(.ranking-ad)が
   来た場合でも触れないよう、リストとの間に余白を空ける（.ranking-ad 自体は
   広告のときスキップされるが、通常行の直後でも同じ余白にしておく）。 */
.ranking-more {
  display: block;
  width: 100%;
  min-height: 48px;
  margin-top: 20px;
  border-radius: 999px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
}

.ranking-more:disabled {
  opacity: 0.6;
  cursor: default;
}

.ranking-note {
  color: var(--text-muted);
  font-size: 12px;
  margin-top: 12px;
}

/* --- ads --- */
.ad-slot {
  margin: 20px 0;
}

.ad-label {
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
  margin-bottom: 4px;
}

/* --- adblock dialog --- */
dialog {
  border: none;
  border-radius: var(--radius-lg);
  padding: 20px;
  max-width: 320px;
  color: var(--text);
  background: var(--surface);
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.4);
}

dialog:not(.free-picker-dialog) div {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}

dialog:not(.free-picker-dialog) button {
  flex: 1 1 auto;
  min-height: 44px;
  border-radius: 999px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

dialog:not(.free-picker-dialog) button + button {
  background: var(--surface-2);
  color: var(--text);
}

/* --- together (顔をタップして開くウィンドウ) --- */
.avatar-btn {
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  cursor: pointer;
  border-radius: 50%;
  flex-shrink: 0;
  line-height: 0;
}

.avatar-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.together-subject {
  font-weight: 700;
  margin: 4px 0 12px;
}

.together-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 60vh;
  overflow-y: auto;
}

.together-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.together-row:last-child {
  border-bottom: none;
}

.together-row .row-info {
  display: block;
  margin-top: 0;
  gap: 0;
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
}

.together-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--surface-2);
  flex-shrink: 0;
}

.together-row button {
  flex: 0 0 auto;
  min-height: 36px;
  padding: 0 12px;
  font-size: 13px;
  white-space: nowrap;
}

.together-row button:disabled {
  background: var(--surface-2);
  color: var(--text-muted);
  cursor: default;
}

.together-dialog > button {
  margin-top: 14px;
  width: 100%;
}

.privacy h1 {
  font-size: 20px;
}

.privacy h2 {
  font-size: 16px;
  margin-top: 24px;
}

@media (min-width: 480px) {
  .girl-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

.estimate {
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  margin: 4px 0;
}

.resume-note {
  text-align: center;
  margin-bottom: 12px;
}

.resume-note a {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  padding: 0 16px;
  border-radius: 999px;
  background: var(--accent-2);
  color: #3a2a28;
  font-weight: 700;
  text-decoration: none;
}

.add-form .note {
  font-size: 12px;
  color: var(--text-muted);
  margin: 4px 0 10px;
}

.not-found {
  text-align: center;
  padding: 40px 16px;
  font-weight: 700;
}

#ts-box {
  margin: 12px 0;
  display: flex;
  justify-content: center;
}

/* 結果の保存中（対決の最後） */
.saving {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 16px 0 4px;
}
.spinner {
  width: 22px;
  height: 22px;
  flex: none;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2.4s; }
}
.saving-slow {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9em;
  margin: 4px 0 0;
}

/* --- 自由に並べて画像をつくる (/?p=free) --- */

.free-page .note {
  color: var(--text-muted);
  font-size: 13px;
}

.free-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 16px 0;
}

.free-slot {
  background: var(--surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  padding: 8px;
  text-align: center;
  min-width: 0;
}

.free-slot-rank {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.free-slot-fill,
.free-slot-empty {
  display: block;
  width: 100%;
  border: none;
  background: none;
  padding: 0;
  cursor: pointer;
  font-family: inherit;
  color: inherit;
  min-height: 44px;
}

.free-slot-empty {
  border: 2px dashed var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-weight: 700;
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.free-slot-fill img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 50%;
  background: var(--border);
}

.free-slot-fill .name {
  font-size: 11px;
  margin-top: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.free-slot-remove,
.free-slot-image-btn {
  width: 100%;
  min-height: 32px;
  margin-top: 4px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 11px;
  padding: 2px 4px;
  cursor: pointer;
}

.free-slot-note {
  color: var(--text-muted);
  font-size: 10px;
  margin-top: 4px;
}

.free-make-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 52px;
  border: none;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
  margin: 8px 0;
}

.free-make-btn:disabled {
  background: var(--border);
  color: var(--text-muted);
  cursor: not-allowed;
}

.free-result {
  text-align: center;
  margin-top: 16px;
}

.free-result-img {
  max-width: 100%;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
}

.free-save-link {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  padding: 0 18px;
  margin-top: 12px;
  border-radius: 999px;
  background: var(--accent-2);
  color: #3a2a28;
  font-weight: 700;
  text-decoration: none;
}

.free-picker-dialog {
  max-width: 480px;
  width: calc(100vw - 32px);
  max-height: 90vh;
  overflow-y: auto;
}

.free-picker-close {
  display: block;
  width: 100%;
  min-height: 44px;
  margin-top: 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
}
