:root {
  color-scheme: light;
  --brand: #5b5fef;
  --brand-dark: #3e42c8;
  --magenta: #d946ef;
  --ink: #151a33;
  --muted: #68708a;
  --paper: #f2f4fb;
  --card: #fff;
  --line: #dce0ef;
  --gold: #f5bd45;
  --shadow: 0 13px 36px rgba(31, 37, 92, 0.14);
  font-family: Pretendard, system-ui, -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  background:
    radial-gradient(circle at 8% 2%, rgba(126, 93, 255, 0.18), transparent 27rem),
    radial-gradient(circle at 96% 72%, rgba(217, 70, 239, 0.12), transparent 29rem),
    var(--paper);
  color: var(--ink);
}

body {
  min-height: 100dvh;
  overscroll-behavior-y: contain;
}

button,
a {
  font: inherit;
  -webkit-tap-highlight-color: transparent;
}

button {
  touch-action: manipulation;
}

button:focus-visible,
a:focus-visible {
  outline: 3px solid #9ba8ff;
  outline-offset: 3px;
}

button:disabled {
  cursor: default;
}

.app {
  width: min(100%, 1120px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(8px, env(safe-area-inset-top)) 10px max(18px, env(safe-area-inset-bottom));
}

.playbar {
  display: flex;
  min-height: 48px;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.exit-button,
.ghost-button,
.icon-button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.9);
  color: var(--ink);
  cursor: pointer;
  font-weight: 850;
}

.exit-button {
  display: inline-flex;
  min-width: 94px;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 14px;
}

.exit-button > span:first-child {
  font-size: 19px;
}

.ghost-button {
  padding: 0 14px;
  color: #3f4770;
}

.icon-button {
  display: grid;
  width: 44px;
  min-width: 44px;
  padding: 0;
  place-items: center;
  font-size: 17px;
}

.screen {
  animation: screen-in 180ms ease-out both;
}

.match-screen {
  display: grid;
  gap: 9px;
}

.match-head {
  display: grid;
  gap: 7px;
  padding: 5px 2px 0;
}

.round-row,
.progress-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.round-row strong {
  font-size: clamp(21px, 6vw, 30px);
  letter-spacing: -0.04em;
}

.round-row span,
.progress-row span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-align: right;
}

.progress-row span:first-child {
  overflow: hidden;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.progress-track {
  overflow: hidden;
  height: 8px;
  border-radius: 999px;
  background: #dfe3f1;
}

.progress-fill {
  width: var(--progress, 0%);
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--brand), var(--magenta));
  transition: width 240ms ease;
}

.versus {
  display: flex;
  align-items: center;
  gap: 9px;
  color: #717a9a;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.1em;
}

.versus::before,
.versus::after {
  height: 1px;
  flex: 1;
  background: var(--line);
  content: "";
}

.candidate-grid {
  display: grid;
  gap: 10px;
}

.candidate {
  position: relative;
  overflow: hidden;
  border: 2px solid transparent;
  border-radius: 20px;
  background: var(--card);
  box-shadow: var(--shadow);
  transition: border-color 150ms ease, opacity 150ms ease, transform 150ms ease;
}

.candidate-choice {
  display: grid;
  width: 100%;
  padding: 0;
  overflow: hidden;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  text-align: left;
}

.candidate-choice:hover .candidate-art img {
  transform: scale(1.018);
}

.candidate-choice:active {
  background: #f8f8fe;
}

.candidate-art {
  position: relative;
  display: block;
  height: 152px;
  overflow: hidden;
  background: #0f1636;
}

.candidate-art::after {
  position: absolute;
  inset: auto 0 0;
  height: 44%;
  background: linear-gradient(transparent, rgba(4, 8, 28, 0.44));
  content: "";
  pointer-events: none;
}

.candidate-art img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 220ms ease;
}

.key-hint,
.year-badge {
  position: absolute;
  z-index: 1;
  top: 9px;
  display: grid;
  min-height: 28px;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 9px;
  background: rgba(8, 13, 38, 0.78);
  color: #fff;
  font-size: 11px;
  font-weight: 900;
  backdrop-filter: blur(7px);
}

.key-hint {
  left: 9px;
  width: 28px;
}

.year-badge {
  right: 9px;
  padding: 0 9px;
}

.candidate-copy {
  display: flex;
  min-width: 0;
  min-height: 150px;
  flex-direction: column;
  justify-content: center;
  padding: 13px 14px 12px;
}

.candidate-artist {
  margin-bottom: 3px;
  color: var(--brand-dark);
  font-size: 12px;
  font-weight: 900;
}

.candidate h2 {
  margin: 0;
  font-size: clamp(23px, 7vw, 36px);
  line-height: 1.08;
  letter-spacing: -0.045em;
  overflow-wrap: anywhere;
}

.candidate-context {
  display: -webkit-box;
  overflow: hidden;
  margin: 7px 0 9px;
  color: #4f5875;
  font-size: 12px;
  line-height: 1.48;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.tag {
  padding: 4px 7px;
  border-radius: 999px;
  background: #eef0fb;
  color: #545f83;
  font-size: 10px;
  font-weight: 850;
}

.candidate-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
  padding: 0 10px 10px;
}

.preview-button,
.choose-button {
  min-height: 46px;
  border-radius: 13px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 900;
}

.preview-button {
  border: 1px solid #cfd5eb;
  background: #f8f9fe;
  color: #3d476e;
}

.choose-button {
  border: 0;
  background: linear-gradient(135deg, var(--brand), #784fe8);
  box-shadow: 0 7px 16px rgba(91, 95, 239, 0.2);
  color: #fff;
}

.candidate.is-winner {
  z-index: 1;
  border-color: var(--gold);
  box-shadow: 0 0 0 4px rgba(245, 189, 69, 0.22), var(--shadow);
  transform: scale(1.008);
}

.candidate.is-loser {
  opacity: 0.43;
  filter: saturate(0.55);
}

.candidate.is-winner::after {
  position: absolute;
  z-index: 4;
  top: 12px;
  left: 50%;
  padding: 6px 10px;
  transform: translateX(-50%);
  border-radius: 999px;
  background: #f5bd45;
  color: #493300;
  content: "선택";
  font-size: 11px;
  font-weight: 950;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #fff;
  box-shadow: var(--shadow);
}

.primary-button,
.secondary-button {
  min-height: 52px;
  padding: 10px 13px;
  border-radius: 15px;
  cursor: pointer;
  font-weight: 900;
}

.primary-button {
  border: 0;
  background: linear-gradient(135deg, var(--brand), #784fe8);
  box-shadow: 0 10px 20px rgba(91, 95, 239, 0.23);
  color: #fff;
}

.secondary-button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

.result-screen {
  display: grid;
  gap: 13px;
  padding-top: 6px;
}

.winner-card {
  overflow: hidden;
  border: 1px solid #e8d18b;
  border-radius: 24px;
  background: #fff;
  box-shadow: 0 16px 46px rgba(86, 66, 15, 0.16);
}

.winner-art {
  position: relative;
}

.winner-art img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 3 / 2;
  object-fit: cover;
}

.crown-badge {
  position: absolute;
  right: 13px;
  bottom: 13px;
  padding: 7px 11px;
  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: 999px;
  background: rgba(245, 189, 69, 0.92);
  color: #4a3500;
  font-size: 12px;
  font-weight: 950;
  backdrop-filter: blur(8px);
}

.winner-copy {
  padding: 17px;
}

.winner-pack,
.winner-kicker,
.winner-artist {
  margin: 0;
  font-weight: 900;
}

.winner-pack {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 11px;
}

.winner-kicker {
  color: #946900;
  font-size: 12px;
}

.winner-artist {
  margin-top: 9px;
  color: var(--brand-dark);
  font-size: 14px;
}

.winner-copy h2 {
  margin: 2px 0 0;
  font-size: clamp(32px, 10vw, 52px);
  line-height: 1;
  letter-spacing: -0.05em;
}

.winner-copy > p:last-of-type {
  margin: 11px 0 0;
  color: #4f5875;
  font-size: 14px;
  line-height: 1.55;
}

.winner-preview {
  width: 100%;
  margin-top: 14px;
}

.result-side {
  display: grid;
  gap: 10px;
}

.result-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.result-actions .primary-button {
  grid-column: 1 / -1;
}

.result-actions button {
  font-size: 13px;
}

.result-seed {
  margin: -1px 2px 0;
  color: var(--muted);
  font-size: 11px;
  text-align: center;
}

.result-seed strong {
  color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.journey {
  padding: 16px;
}

.journey h3 {
  margin: 0 0 12px;
  font-size: 17px;
}

.journey-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.journey-item {
  display: grid;
  grid-template-columns: 53px 1fr;
  gap: 9px;
  padding: 9px 10px;
  border-radius: 12px;
  background: #f5f6fc;
}

.journey-item strong {
  color: var(--brand-dark);
  font-size: 12px;
}

.journey-item span {
  font-size: 12px;
  line-height: 1.45;
}

.drawer-backdrop,
.preview-backdrop {
  position: fixed;
  z-index: 80;
  inset: 0;
  display: grid;
  background: rgba(6, 10, 29, 0.62);
  backdrop-filter: blur(4px);
}

.drawer-backdrop {
  align-items: end;
}

.drawer {
  max-height: min(80dvh, 760px);
  overflow: auto;
  border-radius: 24px 24px 0 0;
  background: #fff;
  box-shadow: 0 -18px 52px rgba(6, 10, 29, 0.26);
}

.drawer-head,
.preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.drawer-head {
  position: sticky;
  z-index: 1;
  top: 0;
  padding: 13px 14px 11px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.97);
}

.drawer-head p,
.preview-head p {
  margin: 0 0 2px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.drawer-head h2,
.preview-head h2 {
  margin: 0;
  font-size: 19px;
  letter-spacing: -0.03em;
}

.history-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 12px 14px max(24px, env(safe-area-inset-bottom));
  list-style: none;
}

.history-item {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 4px 8px;
  align-items: center;
  padding: 11px 12px;
  border-radius: 13px;
  background: #f5f6fc;
}

.history-item small {
  grid-column: 1 / -1;
  color: var(--muted);
  font-weight: 800;
}

.history-item span:not(.history-versus) {
  font-size: 12px;
  line-height: 1.35;
}

.history-versus {
  color: #9298ad;
  font-size: 10px;
  font-weight: 900;
}

.history-item strong {
  grid-column: 1 / -1;
  margin-top: 3px;
  color: var(--brand-dark);
  font-size: 12px;
}

.empty-history {
  padding: 30px 16px;
  color: var(--muted);
  text-align: center;
}

.preview-backdrop {
  align-items: center;
  padding: max(12px, env(safe-area-inset-top)) 10px max(12px, env(safe-area-inset-bottom));
  overflow-y: auto;
}

.preview-dialog {
  width: min(100%, 680px);
  margin: auto;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 22px;
  background: #fff;
  box-shadow: 0 24px 72px rgba(2, 4, 18, 0.42);
}

.preview-head {
  min-height: 64px;
  padding: 10px 12px 10px 15px;
}

.youtube-frame {
  width: 100%;
  min-height: 200px;
  aspect-ratio: 16 / 9;
  background: #050713;
}

.youtube-frame iframe {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 200px;
  border: 0;
}

.preview-foot {
  padding: 12px 14px 14px;
}

.preview-foot p {
  margin: 0;
  color: #565e78;
  font-size: 11px;
  line-height: 1.5;
}

.preview-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}

.preview-actions a {
  display: grid;
  min-height: 46px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 13px;
  color: #3d476e;
  font-size: 12px;
  font-weight: 900;
  text-decoration: none;
}

.recovery-screen {
  display: grid;
  min-height: calc(100dvh - 64px);
  place-items: center;
}

.recovery-card {
  width: min(100%, 460px);
  padding: 24px;
  text-align: center;
}

.recovery-card > span {
  display: block;
  color: var(--brand);
  font-size: 42px;
}

.recovery-card h2 {
  margin: 8px 0 0;
  font-size: 24px;
}

.recovery-card p {
  margin: 10px 0 18px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.recovery-card button {
  width: 100%;
}

.toast {
  position: fixed;
  z-index: 110;
  right: 14px;
  bottom: max(18px, env(safe-area-inset-bottom));
  left: 14px;
  max-width: 560px;
  margin: auto;
  padding: 12px 14px;
  border-radius: 13px;
  background: #141a35;
  box-shadow: 0 13px 36px rgba(6, 10, 29, 0.3);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.45;
  text-align: center;
  animation: toast-in 180ms ease-out both;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

@keyframes screen-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

@media (min-width: 760px) {
  .app {
    padding-right: 22px;
    padding-left: 22px;
  }

  .match-screen {
    min-height: calc(100dvh - 58px);
    grid-template-rows: auto auto minmax(0, 1fr);
  }

  .candidate-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
  }

  .candidate-art {
    height: clamp(210px, 29vh, 310px);
  }

  .candidate-copy {
    min-height: 156px;
    padding: 16px 17px 14px;
  }

  .candidate-context {
    font-size: 13px;
    -webkit-line-clamp: 3;
  }

  .candidate-actions {
    padding: 0 13px 13px;
  }

  .result-screen {
    grid-template-columns: minmax(0, 1.08fr) minmax(330px, 0.92fr);
    align-items: start;
  }

  .winner-card {
    position: sticky;
    top: 10px;
  }

  .winner-copy {
    padding: 22px;
  }

  .drawer {
    width: min(620px, 100%);
    margin: 0 auto;
    border-radius: 24px 24px 0 0;
  }
}

@media (max-width: 390px) {
  .app {
    padding-right: 9px;
    padding-left: 9px;
  }

  .round-row span {
    max-width: 54%;
  }

  .candidate-art {
    height: 120px;
  }

  .candidate-copy {
    min-height: 119px;
    padding: 10px 13px 9px;
  }

  .candidate h2 {
    font-size: clamp(23px, 7.4vw, 30px);
  }

  .candidate-actions {
    gap: 6px;
    padding: 0 9px 9px;
  }

  .candidate-context {
    margin-top: 5px;
    margin-bottom: 7px;
    -webkit-line-clamp: 1;
  }

  .preview-button,
  .choose-button {
    padding-inline: 7px;
    font-size: 11px;
  }

  .result-actions button {
    padding-inline: 8px;
    font-size: 11px;
    line-height: 1.3;
  }
}

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