:root {
  --bg: #fff8f0;
  --ink: #2b2118;
  --muted: #7a6a5c;
  --line: #eadccb;
  --card: #ffffff;
  --ok: #2f9e6b;
  --nope: #d4524a;
  --accent: #e8743b;
  --accent-ink: #ffffff;
  --radius: 22px;
  --shadow: 0 10px 30px rgba(60, 35, 10, .16);
  /* 写真なしカードの色面（ジャンル別） */
  --g-wa: #c8553d;
  --g-yo: #3d7ea6;
  --g-chu: #b8862b;
  --g-kan: #a63d6b;
  --g-eth: #4f8a3c;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic", sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

button { font: inherit; color: inherit; }

#app {
  max-width: 480px;
  height: 100dvh;
  margin: 0 auto;
  position: relative;
  overflow: hidden;
}

.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  padding: calc(16px + env(safe-area-inset-top)) 20px calc(20px + env(safe-area-inset-bottom));
  gap: 16px;
}
.screen.is-active { display: flex; }

/* ---------- ボタン ---------- */
.btn {
  border: 0;
  border-radius: 999px;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}
.btn-xl { width: 100%; min-height: 64px; font-size: 1.35rem; }
.btn-primary { background: var(--accent); color: var(--accent-ink); box-shadow: 0 6px 16px rgba(232, 116, 59, .35); }
.btn-primary:disabled { opacity: .5; box-shadow: none; }
.btn-secondary { background: #f1e6d8; color: var(--ink); }
.btn:active { transform: scale(.98); }

.btn-link {
  align-self: center;
  background: none;
  border: 0;
  padding: 12px 8px;
  color: var(--muted);
  font-size: 1rem;
  text-decoration: underline;
  cursor: pointer;
}

/* ---------- スタート ---------- */
.start-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 22px;
}
.badge {
  align-self: flex-start;
  margin: 0;
  padding: 2px 10px;
  border: 1px solid var(--muted);
  border-radius: 6px;
  font-size: .85rem;
  color: var(--muted);
}
.app-title { margin: 0; font-size: 2.6rem; line-height: 1.2; letter-spacing: .02em; }
.kari { display: block; font-size: 1.1rem; font-weight: 500; color: var(--muted); }
.rules { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; font-size: 1.25rem; font-weight: 600; }
.rules li { display: flex; align-items: center; gap: 14px; }
.rule-key {
  flex: none;
  width: 48px; height: 48px;
  display: grid; place-items: center;
  border-radius: 14px;
  color: #fff;
  font-size: 1.15rem;
}
.rule-right { background: var(--ok); }
.rule-left { background: var(--nope); }
.rule-stop { background: var(--accent); }
.deck-note { margin: 0; color: var(--muted); font-size: 1rem; }
.start-actions { display: flex; flex-direction: column; gap: 4px; }

/* ---------- スワイプ ---------- */
.swipe-header {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.stat {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 8px 10px;
  text-align: center;
}
.stat-label { display: block; font-size: .85rem; color: var(--muted); font-weight: 600; }
.stat-value { font-size: 1.7rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat-value small { font-size: 1rem; color: var(--muted); font-weight: 600; }
.stat-right { border-color: var(--ok); }
.stat-right .stat-value { color: var(--ok); }
.stat-right.bump { animation: bump .35s ease; }
@keyframes bump { 50% { transform: scale(1.12); } }

.stack { position: relative; flex: 1; min-height: 0; }

.card {
  position: absolute;
  inset: 0;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  will-change: transform;
}
.card.is-top { cursor: grab; }
.card.is-dragging { cursor: grabbing; }
.card.is-under { transform: scale(.95) translateY(14px); filter: brightness(.97); }
.card.is-flying { transition: transform .38s ease-in, opacity .38s ease-in; }
.card.is-returning { transition: transform .25s ease-out; }

.card-visual {
  position: relative;
  flex: 1 1 55%;
  min-height: 0;
  display: flex;
  align-items: flex-end;
  padding: 22px;
  color: #fff;
}
.card-visual img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.card-visual.no-photo { align-items: center; justify-content: center; text-align: center; }
.no-photo-name {
  position: relative;
  font-size: 2.3rem;
  font-weight: 800;
  line-height: 1.25;
  text-shadow: 0 2px 8px rgba(0, 0, 0, .18);
  word-break: keep-all;
  overflow-wrap: anywhere;
}
.genre-wa { background: var(--g-wa); }
.genre-yo { background: var(--g-yo); }
.genre-chu { background: var(--g-chu); }
.genre-kan { background: var(--g-kan); }
.genre-eth { background: var(--g-eth); }
.no-photo::before {
  content: "";
  position: absolute; inset: 0;
  background:
    radial-gradient(circle at 20% 15%, rgba(255,255,255,.22) 0 18%, transparent 19%),
    radial-gradient(circle at 85% 80%, rgba(255,255,255,.14) 0 24%, transparent 25%);
}
.genre-chip {
  position: absolute;
  top: 16px; left: 16px;
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .9);
  color: var(--ink);
  font-size: .9rem;
  font-weight: 700;
}
.photo-credit {
  position: absolute;
  right: 8px; bottom: 6px;
  font-size: .65rem;
  color: rgba(255, 255, 255, .9);
  text-shadow: 0 1px 2px rgba(0,0,0,.6);
}

.card-body { flex: none; padding: 18px 22px 22px; display: grid; gap: 10px; }
.card-name { margin: 0; font-size: 1.75rem; font-weight: 800; line-height: 1.3; }
.card-ings { margin: 0; font-size: 1.1rem; color: var(--ink); line-height: 1.5; }
.card-meta { display: flex; flex-wrap: wrap; gap: 8px; }
.meta-chip {
  padding: 4px 12px;
  border-radius: 999px;
  background: #f6efe6;
  font-size: 1rem;
  font-weight: 700;
}

.stamp {
  position: absolute;
  top: 26px;
  padding: 6px 14px;
  border: 4px solid currentColor;
  border-radius: 12px;
  font-size: 1.6rem;
  font-weight: 900;
  opacity: 0;
  background: rgba(255,255,255,.85);
  pointer-events: none;
  z-index: 2;
}
.stamp-ok { left: 22px; color: var(--ok); transform: rotate(-12deg); }
.stamp-nope { right: 22px; color: var(--nope); transform: rotate(12deg); }

.swipe-actions {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 14px;
}
.btn-round {
  border: 0;
  border-radius: 24px;
  min-height: 76px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-weight: 800;
  cursor: pointer;
  touch-action: manipulation;
}
.btn-round:active { transform: scale(.96); }
.btn-round .arrow { font-size: 1.8rem; line-height: 1; }
.btn-cap { font-size: .95rem; }
.btn-nope { background: #fdecea; color: var(--nope); }
.btn-ok { background: #e3f4ec; color: var(--ok); }
.btn-undo { width: 64px; min-height: 64px; border-radius: 50%; background: #f1e6d8; color: var(--muted); }
.btn-undo .btn-cap { font-size: .75rem; }
.btn-undo:disabled { opacity: .35; }

/* ---------- 候補 ---------- */
.screen-header { text-align: center; display: grid; gap: 4px; }
.screen-title { margin: 0; font-size: 2rem; font-weight: 800; }
.sub { margin: 0; color: var(--accent); font-weight: 800; font-size: 1.15rem; }
.hint { margin: 0; color: var(--muted); font-size: 1rem; line-height: 1.5; }

.candidates { flex: 1; min-height: 0; display: grid; gap: 12px; grid-auto-rows: 1fr; }
.cand {
  display: flex;
  align-items: stretch;
  border: 0;
  padding: 0;
  border-radius: 20px;
  background: var(--card);
  box-shadow: var(--shadow);
  overflow: hidden;
  text-align: left;
  cursor: pointer;
  min-height: 0;
  animation: rise .35s ease both;
}
.cand:nth-child(2) { animation-delay: .08s; }
.cand:nth-child(3) { animation-delay: .16s; }
@keyframes rise { from { opacity: 0; transform: translateY(18px); } }
.cand:active { transform: scale(.98); }
.cand.is-chosen { outline: 4px solid var(--accent); }
.cand-visual {
  position: relative;
  flex: 0 0 38%;
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 800;
  font-size: 1.1rem;
  padding: 8px;
  text-align: center;
}
.cand-visual img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.cand-body { flex: 1; padding: 12px 14px; display: flex; flex-direction: column; justify-content: center; gap: 6px; }
.cand-name { font-size: 1.35rem; font-weight: 800; line-height: 1.3; }
.cand-ings { font-size: .95rem; color: var(--muted); line-height: 1.4; }

/* ---------- 結果 ---------- */
.match-title { color: var(--accent); font-size: 2.3rem; }
.result-card {
  flex: 1;
  min-height: 0;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  background: var(--card);
  display: flex;
  flex-direction: column;
  animation: pop .45s cubic-bezier(.2, 1.4, .4, 1) both;
}
@keyframes pop { from { opacity: 0; transform: scale(.85); } }
.result-card .card-visual { flex: 1; }
.result-card .card-name { font-size: 2rem; }
.result-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.result-stat { background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 10px; text-align: center; }
.big-num { font-size: 2.4rem; font-weight: 900; font-variant-numeric: tabular-nums; }
.big-num small { font-size: 1.1rem; margin-left: 2px; color: var(--muted); }
#result-source { padding: 4px 8px; }

.none-body { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 20px; text-align: center; }

/* ---------- クレジット ---------- */
#screen-credits { background: var(--bg); z-index: 5; }
.credits-list { flex: 1; overflow-y: auto; margin: 0; padding: 0 0 0 1.6em; display: grid; gap: 12px; align-content: start; font-size: .95rem; line-height: 1.5; }
.credits-list a { color: var(--accent); word-break: break-all; }
.credit-name { font-weight: 800; }
.credit-row { color: var(--muted); }

@media (prefers-reduced-motion: reduce) {
  .card.is-flying { transition-duration: .01s; }
  .cand, .result-card, .stat-right.bump { animation: none; }
}
