@font-face {
  font-family: "Apfel Grotezk";
  src: url("/apfel-grotezk-main/ApfelGrotezk-Regular.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}

@font-face {
  font-family: "Apfel Grotezk";
  src: url("/apfel-grotezk-main/ApfelGrotezk-Mittel.woff2") format("woff2");
  font-weight: 500;
  font-display: swap;
}

@font-face {
  font-family: "Apfel Grotezk";
  src: url("/apfel-grotezk-main/ApfelGrotezk-Fett.woff2") format("woff2");
  font-weight: 700;
  font-display: swap;
}

:root {
  color-scheme: dark;
  --bg: #14181c;
  --panel: #1c2228;
  --panel-2: #222a31;
  --line: #303941;
  --text: #f2f5f0;
  --muted: #8f9aa3;
  --soft: #c5ced4;
  --accent: #00c070;
  --accent-ink: #071511;
  --warning: #d8b85f;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.42);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Apfel Grotezk", system-ui, sans-serif;
  font-size: 17px;
  line-height: 1.45;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100svh;
  padding: max(22px, env(safe-area-inset-top)) 20px calc(94px + env(safe-area-inset-bottom));
}

.topbar {
  align-items: center;
  display: flex;
  justify-content: space-between;
  margin: 0 auto 30px;
  max-width: 980px;
}

#compare-surface {
  min-height: calc(100svh - 190px);
}

/* The compare surface is a working screen: trade headline size for cover space. */
body:has(#compare-surface.is-active) h1 {
  font-size: clamp(1.7rem, 7vw, 2.6rem);
}

body:has(#compare-surface.is-active) .topbar {
  margin-bottom: 18px;
}

.eyebrow {
  color: var(--muted);
  font-size: 0.82rem;
  letter-spacing: 0;
  margin: 0 0 5px;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  font-size: clamp(2.35rem, 12vw, 4.9rem);
  font-weight: 700;
  line-height: 0.9;
  margin-bottom: 0;
}

main {
  margin: 0 auto;
  max-width: 980px;
}

.surface {
  display: none;
}

.surface.is-active {
  display: block;
}

.icon-button {
  align-items: center;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text);
  display: inline-flex;
  height: 42px;
  justify-content: center;
  width: 42px;
}

.session-meter {
  align-items: center;
  color: var(--muted);
  display: flex;
  font-size: 1rem;
  justify-content: space-between;
  margin-bottom: 16px;
}

.pair-stage {
  align-items: center;
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(0, 1fr) 26px minmax(0, 1fr);
  height: min(640px, calc(100svh - 300px));
  min-height: 360px;
}

.vs {
  color: var(--muted);
  font-size: 0.8rem;
  text-align: center;
  text-transform: uppercase;
}

.choice-card {
  appearance: none;
  background: transparent;
  border: 0;
  color: inherit;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto auto;
  height: 100%;
  min-width: 0;
  padding: 0;
  text-align: left;
}

.cover {
  align-items: center;
  aspect-ratio: 2 / 3;
  background: linear-gradient(145deg, #263039, #101316);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: flex;
  justify-content: center;
  overflow: hidden;
  position: relative;
  width: 100%;
}

.cover img {
  height: 100%;
  object-fit: cover;
  width: 100%;
}

.choice-card .cover {
  height: 100%;
  justify-self: center;
  max-width: 100%;
  width: auto;
}

/* Books share the movie 2/3 frame so pairs stay aligned; odd
   proportions letterbox inside it instead of resizing the card. */
.cover.is-book img {
  object-fit: contain;
}

.cover-fallback {
  color: var(--soft);
  font-size: clamp(1rem, 4vw, 1.8rem);
  font-weight: 700;
  line-height: 1;
  padding: 18px;
  text-align: center;
}

.choice-title {
  font-size: clamp(1.08rem, 4.5vw, 1.55rem);
  font-weight: 500;
  line-height: 1.08;
  margin: 16px 0 6px;
  /* reserve two lines so a wrapping title doesn't shrink its cover */
  min-height: 2.16em;
  overflow-wrap: anywhere;
}

.choice-meta {
  color: var(--muted);
  font-size: 0.98rem;
  line-height: 1.32;
}

.quiet-actions {
  display: flex;
  gap: 18px;
  justify-content: center;
  margin: 18px 0 2px;
}

.text-button {
  background: transparent;
  border: 0;
  color: var(--muted);
  padding: 12px;
}

.primary-button,
.secondary-button {
  border: 0;
  border-radius: 8px;
  font-weight: 500;
  min-height: 42px;
  padding: 10px 16px;
}

.primary-button {
  background: var(--accent);
  color: var(--accent-ink);
}

.secondary-button {
  background: var(--panel-2);
  color: var(--text);
  width: 100%;
}

.rank-toolbar,
.search-row {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
}

.segmented {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  grid-auto-columns: 1fr;
  grid-auto-flow: column;
  overflow: hidden;
}

.segmented button {
  background: transparent;
  border: 0;
  color: var(--muted);
  min-height: 42px;
  padding: 8px 14px;
}

.segmented button.is-selected {
  background: var(--text);
  color: var(--bg);
}

select,
input {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  min-height: 42px;
  padding: 9px 12px;
}

.search-input {
  width: 100%;
}

.ranking-list,
.result-list {
  display: grid;
  gap: 12px;
  list-style: none;
  margin: 18px 0 0;
  padding: 0;
}

.rank-row,
.result-row {
  align-items: center;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 8px;
  color: inherit;
  display: grid;
  gap: 16px;
  grid-template-columns: 62px minmax(0, 1fr) auto;
  min-height: 92px;
  padding: 12px;
  text-align: left;
  width: 100%;
}

.result-row {
  grid-template-columns: 58px minmax(0, 1fr) auto;
}

.thumb {
  aspect-ratio: 2 / 3;
  background: var(--panel-2);
  border-radius: 4px;
  overflow: hidden;
}

.thumb img {
  height: 100%;
  object-fit: cover;
  width: 100%;
}

.thumb.is-book img {
  object-fit: contain;
}

.rank-main,
.result-main {
  min-width: 0;
}

.rank-main strong,
.result-main strong {
  display: block;
  font-weight: 500;
  font-size: 1.08rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rank-main span,
.result-main span {
  color: var(--muted);
  display: block;
  font-size: 0.94rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rating-pill {
  color: var(--soft);
  font-weight: 500;
  white-space: nowrap;
}

.confidence {
  border: 1px solid currentColor;
  border-radius: 999px;
  display: inline-block;
  height: 10px;
  margin-left: 6px;
  width: 10px;
}

.confidence.high {
  background: var(--accent);
  color: var(--accent);
}

.confidence.medium {
  background: var(--warning);
  color: var(--warning);
}

.confidence.low {
  background: transparent;
  color: var(--muted);
}

.add-panel,
.settings-form,
.stats-grid {
  display: grid;
  gap: 12px;
}

.settings-form label {
  align-items: center;
  display: flex;
  gap: 14px;
  justify-content: space-between;
}

.settings-form input,
.settings-form select {
  width: 160px;
}

.stats-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 16px;
}

.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.stat strong {
  display: block;
  font-size: 1.6rem;
}

.placement {
  margin-top: 18px;
}

.reveal {
  margin: 20px 0;
  min-height: 240px;
  padding: 28px 0;
  text-align: center;
}

.reveal h2 {
  font-size: clamp(2.2rem, 12vw, 5rem);
  font-weight: 700;
  line-height: 0.92;
}

.reveal p {
  color: var(--soft);
  font-size: 1.1rem;
}

dialog {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  max-width: min(760px, calc(100vw - 28px));
  padding: 28px;
  position: relative;
  width: 100%;
}

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

.close-button {
  background: var(--panel);
  height: 48px;
  position: absolute;
  right: 14px;
  top: 14px;
  width: 48px;
  z-index: 2;
}

.detail-grid {
  display: grid;
  gap: 26px;
  grid-template-columns: minmax(150px, 220px) minmax(0, 1fr);
  align-items: start;
  padding-top: 36px;
}

.detail-grid .cover {
  box-shadow: var(--shadow);
}

.detail-grid h2 {
  font-size: clamp(1.8rem, 7vw, 3.2rem);
  font-weight: 700;
  line-height: 0.98;
  margin-bottom: 12px;
}

.detail-meta {
  color: var(--muted);
  font-size: 1.05rem;
  margin-bottom: 22px;
}

.score-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin: 0;
}

.score-grid div {
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.score-grid dt {
  color: var(--muted);
  font-size: 0.88rem;
  margin-bottom: 3px;
}

.score-grid dd {
  font-size: 1.15rem;
  font-weight: 500;
  margin: 0;
}

.toast {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  bottom: calc(104px + env(safe-area-inset-bottom));
  color: var(--text);
  font-size: 0.95rem;
  left: 50%;
  max-width: min(420px, calc(100vw - 32px));
  opacity: 0;
  padding: 10px 16px;
  pointer-events: none;
  position: fixed;
  transform: translate(-50%, 6px);
  transition: opacity 0.2s, transform 0.2s;
  z-index: 20;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.tabbar {
  background: rgba(20, 24, 28, 0.92);
  border-top: 1px solid var(--line);
  bottom: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  left: 0;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  position: fixed;
  right: 0;
  z-index: 10;
}

.tabbar button {
  background: transparent;
  border: 0;
  color: var(--muted);
  min-height: 48px;
}

.tabbar button.is-active {
  color: var(--text);
}

.plus-tab span {
  align-items: center;
  background: var(--accent);
  border-radius: 999px;
  color: var(--accent-ink);
  display: inline-flex;
  font-size: 1.45rem;
  height: 44px;
  justify-content: center;
  width: 44px;
}

@media (max-width: 620px) {
  .app-shell {
    padding-left: 16px;
    padding-right: 16px;
  }

  .pair-stage {
    gap: 9px;
    grid-template-columns: minmax(0, 1fr) 18px minmax(0, 1fr);
    height: auto;
    min-height: auto;
  }

  .choice-card {
    grid-template-rows: auto auto auto;
    height: auto;
  }

  .choice-card .cover {
    height: auto;
    width: 100%;
  }

  .rank-toolbar,
  .search-row {
    flex-wrap: wrap;
  }

  .rank-toolbar > *,
  .search-row > * {
    flex: 1 1 100%;
  }

  .rank-row {
    grid-template-columns: 58px minmax(0, 1fr) auto;
  }

  .rank-row .rating-pill {
    grid-column: 3;
  }

  .detail-grid {
    grid-template-columns: 1fr;
    gap: 20px;
    padding-top: 42px;
  }

  .detail-grid .cover {
    justify-self: start;
    max-width: min(68vw, 280px);
  }

  .score-grid {
    grid-template-columns: 1fr;
  }
}

@media (min-width: 760px) {
  body:has(#compare-surface.is-active) {
    overflow: hidden;
  }
}
