/* ── Reset & base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Light editorial — Apple.com is light, so is this */
  --bg:           #fafaf8;        /* warm off-white, not clinical */
  --surface:      #ffffff;
  --surface2:     #f3f3f1;
  --surface-card: #ffffff;

  /* Borders — ink on paper */
  --border:       rgba(0, 0, 0, 0.08);
  --border2:      rgba(0, 0, 0, 0.16);

  /* Text */
  --text:         #141414;
  --text-dim:     #6a6a6a;
  --text-mute:    #9a9a9a;

  /* Semantic */
  --win:          #1a6e44;        /* deep forest green — not the AI neon */
  --win-dim:      rgba(26, 110, 68, 0.10);
  --lose:         rgba(0, 0, 0, 0.18);
  --danger-text:  #a02020;

  /* Radius */
  --r:            16px;
  --r-sm:         8px;
  --r-pill:       980px;
}

/* Screen-reader only */
.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

html { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Geist', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

main { display: flex; flex-direction: column; flex: 1; }

/* ── Focus ────────────────────────────────────────────────────────────────── */
:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 3px;
  border-radius: 4px;
}

/* ── Nav ──────────────────────────────────────────────────────────────────── */
nav {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 32px;
  height: 52px;
  border-bottom: 1px solid var(--border);
  background: rgba(250, 250, 248, 0.9);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 200;
}

.brand {
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
  flex-shrink: 0;
}

.nav-tabs { display: flex; gap: 0; }

.tab {
  display: flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 500;
  padding: 0 14px;
  height: 52px;
  cursor: pointer;
  transition: color 0.18s;
  position: relative;
  white-space: nowrap;
}
.tab svg { width: 13px; height: 13px; flex-shrink: 0; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); }
.tab.active::after {
  content: '';
  position: absolute;
  bottom: 0; left: 14px; right: 14px;
  height: 1.5px;
  background: var(--text);
}

.nav-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 16px;
}

.fetch-status { font-size: 0.75rem; color: var(--text-mute); }
.fetch-status.has-error { color: var(--danger-text); font-weight: 600; }

.nav-battles {
  font-size: 0.75rem;
  color: var(--text-mute);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
}

/* ── Views ────────────────────────────────────────────────────────────────── */
.view {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 48px 20px 64px;
}
.hidden { display: none !important; }

/* Battle view: overflow visible so card hover shadows aren't clipped */
#viewBattle {
  overflow: visible;
  padding: 28px 20px 24px;
}

/* ── Battle header ────────────────────────────────────────────────────────── */
.battle-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
  flex-shrink: 0;
}

.instruction {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-mute);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.session-counter {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-mute);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
}

/* ── Arena ────────────────────────────────────────────────────────────────── */
.arena {
  display: flex;
  align-items: stretch;      /* both cards always same height */
  width: 100%;
  max-width: 960px;
  gap: 0;
  position: relative;
  perspective: 1100px;
  /* Size to content, but never exceed the viewport.
     overflow: visible lets box-shadows breathe past the arena edge. */
  max-height: calc(100dvh - 52px - 130px);
  overflow: visible;
  /* Padding gives the hover shadow physical room before being cut by any ancestor */
  padding: 10px;
  margin: -10px;              /* cancel the padding's effect on outer layout */
}

.battle-canvas {
  position: absolute;
  inset: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: 200;
  display: none;
}

/* ── Card entry animations ────────────────────────────────────────────────── */
@keyframes card-enter-left {
  from { opacity: 0; transform: translateX(-22px) translateZ(-10px); }
  to   { opacity: 1; transform: translateX(0) translateZ(0); }
}
@keyframes card-enter-right {
  from { opacity: 0; transform: translateX(22px) translateZ(-10px); }
  to   { opacity: 1; transform: translateX(0) translateZ(0); }
}

/* ── Quote card ───────────────────────────────────────────────────────────── */
.quote-card {
  appearance: none;
  -webkit-appearance: none;
  font-family: inherit;
  text-align: left;

  flex: 1;
  position: relative;
  border-radius: var(--r);
  border: 1px solid var(--border);
  background: var(--surface-card);
  cursor: pointer;
  overflow: hidden;
  user-select: none;
  transition:
    border-color 0.18s ease,
    transform    0.22s cubic-bezier(0.25, 0.46, 0.45, 0.94),
    box-shadow   0.22s ease;
  min-height: 200px;        /* minimum so very short quotes don't collapse */
  display: flex;
  flex-direction: column;
  will-change: transform;
  touch-action: manipulation;
  contain: layout style;
}

.quote-card:focus { outline: none; }
.quote-card:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 2px;
  border-radius: var(--r);
}

.quote-card:hover {
  border-color: var(--border2);
  transform: translateY(-5px);
  box-shadow:
    0  2px  4px rgba(0, 0, 0, 0.04),
    0  8px 24px rgba(0, 0, 0, 0.07),
    0 20px 48px rgba(0, 0, 0, 0.05);
}
.quote-card:active {
  transform: translateY(-2px) scale(0.997);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.06);
}

.quote-card.winner {
  border-color: var(--win);
  box-shadow:
    0 0 0 1px var(--win),
    0 16px 48px rgba(26, 110, 68, 0.12);
  /* Keyframe overshoot — no bounce cubic-bezier needed */
  animation: win-clash 0.52s ease-out forwards;
}
.quote-card.loser {
  animation: lose-fall 0.42s ease-in forwards;
}
.quote-card.disabled { cursor: default; pointer-events: none; }

@keyframes win-clash {
  0%   { transform: translateZ(0)    scale(1); }
  32%  { transform: translateZ(46px) scale(1.072); }
  68%  { transform: translateZ(20px) scale(1.026); }
  100% { transform: translateZ(14px) scale(1.015); }
}
@keyframes lose-fall {
  0%   { opacity: 1;    filter: saturate(1)   brightness(1);   transform: scale(1);     }
  100% { opacity: 0.12; filter: saturate(0)   brightness(0.9); transform: scale(0.965); }
}

.card-inner {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  flex: 1;
  padding: 28px 32px;
  /* Push footer to bottom, center quote body in remaining space */
  justify-content: space-between;
}

.card-meta-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0;
  flex-shrink: 0;
}

.side-label {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.10em;
  color: var(--text-mute);
  text-transform: uppercase;
}

/* Type dot */
.type-dot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }
.type-dot.dot-movie  { background: #2a6da8; }
.type-dot.dot-tv     { background: #603898; }
.type-dot.dot-book   { background: #7a5418; }
.type-dot.dot-person { background: #1e6038; }
.type-dot.dot-music  { background: #922858; }
.type-dot.dot-quote  { background: #404070; }

.quote-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  /* Vertically center the quote text within available space */
  display: flex;
  flex-direction: column;
  justify-content: center;
  /* invisible scrollbar — page stays still, quote scrolls if huge */
  scrollbar-width: none;
  -ms-overflow-style: none;
  padding: 16px 0;          /* breathing room above/below the text */
}
.quote-body::-webkit-scrollbar { display: none; }

blockquote {
  font-family: 'EB Garamond', Georgia, 'Times New Roman', serif;
  font-size: clamp(1.18rem, 2.4vw, 1.6rem);
  font-weight: 400;
  font-style: normal;
  line-height: 1.66;
  color: var(--text);
  letter-spacing: 0.01em;
}

.card-footer {
  flex-shrink: 0;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}

cite {
  font-size: 0.78rem;
  color: var(--text-dim);
  font-style: normal;
  font-weight: 400;
  letter-spacing: 0.01em;
  display: block;
}

/* ── Card overlay ─────────────────────────────────────────────────────────── */
.card-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.90);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s;
  border-radius: var(--r);
  z-index: 10;
}
.card-overlay.show { opacity: 1; }

.overlay-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.win-label {
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--win);
  min-height: 14px;
}
.win-label.stamp {
  /* ease-out-quart — no bounce */
  animation: label-stamp 0.34s cubic-bezier(0.25, 0.46, 0.45, 0.94) both 0.06s;
}
@keyframes label-stamp {
  from { opacity: 0; letter-spacing: 0.38em; transform: scale(1.08); }
  to   { opacity: 1; letter-spacing: 0.16em; transform: scale(1);    }
}

.elo-delta {
  font-size: 2.8rem;
  font-weight: 700;
  letter-spacing: -0.04em;
  color: var(--win);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
}
.elo-delta.neg { color: var(--text-mute); }

/* ── VS divider — just a line + "or" ─────────────────────────────────────── */
.vs-divider {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 40px;
  flex-shrink: 0;
}

.vs-line {
  flex: 1;
  width: 1px;
  background: var(--border);
  /* No max-height — lines extend to match full card height */
}

.vs-circle {
  padding: 10px 0;
  font-size: 0.65rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--text-mute);
}

/* ── Battle footer ────────────────────────────────────────────────────────── */
.battle-footer {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-top: 16px;
  width: 100%;
  max-width: 960px;
  justify-content: center;
  flex-shrink: 0;
}

.skip-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-mute);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 500;
  padding: 8px 20px;
  border-radius: var(--r-pill);
  cursor: pointer;
  transition: color 0.18s, border-color 0.18s;
  touch-action: manipulation;
  min-height: 36px;
}
.skip-btn:hover { color: var(--text-dim); border-color: var(--border2); }

.key-hint {
  font-size: 0.75rem;
  color: var(--text-mute);
  display: flex;
  align-items: center;
  gap: 5px;
}

kbd {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 0.65rem;
  font-family: inherit;
  color: var(--text-dim);
}

.footer-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
}

.pool-label {
  font-size: 0.75rem;
  color: var(--text-mute);
}

.share-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  background: none;
  border: none;
  padding: 0;
  color: var(--text-mute);
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 400;
  letter-spacing: 0.01em;
  cursor: pointer;
  white-space: nowrap;
  touch-action: manipulation;
  /* Hidden until a vote is cast */
  opacity: 0;
  pointer-events: none;
  transform: translateY(2px);
  transition: opacity 0.28s ease, transform 0.28s ease, color 0.16s;
}
.share-btn.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}
.share-btn:hover { color: var(--text-dim); }
.share-btn svg { flex-shrink: 0; }

/* ── Rankings ─────────────────────────────────────────────────────────────── */
@keyframes rank-item-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.rank-header { width: 100%; max-width: 820px; margin-bottom: 24px; }

.rank-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  flex-wrap: wrap;
  gap: 12px;
}

.rank-title-row h2 {
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text);
}

.rank-controls { display: flex; align-items: center; gap: 8px; }

.rank-controls select {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 400;
  padding: 7px 12px;
  border-radius: var(--r-pill);
  cursor: pointer;
  outline: none;
  transition: border-color 0.18s;
  min-height: 34px;
}
.rank-controls select:hover { border-color: var(--border2); }
.rank-controls select:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }

.reset-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-mute);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 400;
  padding: 7px 14px;
  border-radius: var(--r-pill);
  cursor: pointer;
  transition: border-color 0.18s, color 0.18s;
  min-height: 34px;
}
.reset-btn:hover { border-color: var(--danger-text); color: var(--danger-text); }

.rank-sub-info { font-size: 0.78rem; color: var(--text-mute); }

.rank-list {
  width: 100%;
  max-width: 820px;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

/* Apple grouped list style */
.rank-item {
  display: grid;
  grid-template-columns: 52px 1fr auto auto;
  align-items: center;
  gap: 14px;
  background: var(--surface);
  border: none;
  padding: 14px 20px;
  transition: background 0.14s;
  content-visibility: auto;
  contain-intrinsic-size: 0 68px;
  animation: rank-item-in 0.26s ease forwards;
  animation-delay: calc(var(--i, 0) * 14ms);
  opacity: 0;
}

.rank-item:first-child { border-radius: var(--r-sm) var(--r-sm) 0 0; }
.rank-item:last-child  { border-radius: 0 0 var(--r-sm) var(--r-sm); }
.rank-item:only-child  { border-radius: var(--r-sm); }
.rank-item:not(:last-child) { border-bottom: 1px solid var(--border); }
.rank-item:hover { background: var(--surface2); }

/* Rank position conveyed by number color — no border-left */
.rank-num {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-mute);
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
}
.rank-item.rank-gold   .rank-num { color: #8a6200; font-size: 1.2rem; }
.rank-item.rank-silver .rank-num { color: #505a68; font-size: 1.1rem; }
.rank-item.rank-bronze .rank-num { color: #6e4020; font-size: 1.0rem; }

.rank-quote {
  font-family: 'EB Garamond', Georgia, 'Times New Roman', serif;
  font-size: 0.98rem;
  font-style: normal;
  color: var(--text);
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 4px;
}

.rank-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.rank-author { font-size: 0.75rem; color: var(--text-dim); }

.rank-type-dot { width: 5px; height: 5px; border-radius: 50%; flex-shrink: 0; }
.dot-movie  { background: #2a6da8; }
.dot-tv     { background: #603898; }
.dot-book   { background: #7a5418; }
.dot-person { background: #1e6038; }
.dot-music  { background: #922858; }
.dot-quote  { background: #404070; }

.rank-wl { font-size: 0.75rem; color: var(--text-mute); text-align: right; white-space: nowrap; }

.rank-score { text-align: right; white-space: nowrap; min-width: 54px; }
.rank-score-main {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
  display: block;
}
.rank-score-sub { font-size: 0.6rem; color: var(--text-mute); display: block; margin-top: 1px; }

/* ── Rankings empty state ─────────────────────────────────────────────────── */
.rank-empty {
  text-align: center;
  padding: 72px 24px;
  color: var(--text-mute);
}
.rank-empty .rank-empty-head {
  font-family: 'EB Garamond', Georgia, serif;
  font-size: 1.2rem;
  color: var(--text-dim);
  margin-bottom: 10px;
  display: block;
}
.rank-empty p { font-size: 0.82rem; line-height: 1.7; }

/* ── Responsive — tablet ──────────────────────────────────────────────────── */
@media (max-width: 860px) {
  .card-inner { padding: 24px 26px 22px; }
  blockquote  { font-size: clamp(1.05rem, 3vw, 1.32rem); }
}

/* ── Responsive — mobile ──────────────────────────────────────────────────── */
@media (max-width: 640px) {
  nav { padding: 0 16px; }
  .nav-battles { display: none; }
  .key-hint    { display: none; }
  .pool-label  { display: none; }
  /* Keep footer-right visible so share-btn works on mobile, just no gap */
  .footer-right { gap: 0; }

  .arena { flex-direction: column; }
  .vs-divider { flex-direction: row; width: 100%; height: 40px; }
  .vs-line { flex: 1; width: auto; height: 1px; max-height: unset; }
  .vs-circle { padding: 0 12px; }

  .quote-card { min-height: 160px; }
  .arena { max-height: none; }           /* stacked on mobile — let height flow */
  .card-inner { padding: 20px 22px 18px; }
  blockquote  { font-size: 1.05rem; }

  .rank-item  { grid-template-columns: 40px 1fr auto; }
  .rank-wl    { display: none; }
  .battle-footer { justify-content: space-between; }
}

/* ── Reduced motion ───────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration:        0.01ms !important;
    transition-duration:       0.01ms !important;
    animation-iteration-count: 1     !important;
  }
}
