@font-face {
  font-family: "Instrument Serif";
  src: url("./fonts/instrument-serif-italic.woff2") format("woff2");
  font-style: italic;
  font-weight: 400;
  font-display: swap;
}

:root {
  --paper: #f2f1ed;
  --ink: #171816;
  --muted: #686b66;
  --line: #c9cac4;
  --accent: #c7392f;
  --accent-dark: #8f241e;
  --white: #fdfdfb;
  --frame: #222420;
  --shadow: 0 18px 50px rgba(29, 31, 27, 0.12);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background: var(--paper);
  font-family: "PingFang SC", "Hiragino Sans GB", sans-serif;
}

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

.grain {
  position: fixed;
  inset: 0;
  z-index: 20;
  pointer-events: none;
  opacity: 0.035;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.75' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.65'/%3E%3C/svg%3E");
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  min-height: 68px;
  padding: 10px clamp(18px, 3vw, 48px);
  border-bottom: 1px solid var(--line);
  background: rgba(242, 241, 237, 0.94);
  backdrop-filter: blur(16px);
}

.round-status { display: flex; align-items: center; gap: 14px; font-size: 12px; font-weight: 600; }
.round-track { display: flex; gap: 5px; }
.round-track i { width: 32px; height: 3px; background: #d4d5cf; transition: background 260ms ease; }
.round-track i.is-done, .round-track i.is-current { background: var(--accent); }

.view-switch {
  justify-self: end;
  display: flex;
  padding: 3px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.45);
}

.view-button {
  min-width: 58px;
  padding: 8px 12px;
  border: 0;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
}

.view-button.is-active { color: var(--white); background: var(--ink); }
.view-button:focus-visible, .vote-button:focus-visible, .draw-button:focus-visible, .restart-button:focus-visible, .mobile-tab:focus-visible, .frame-vote:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

main { padding: 0 clamp(18px, 3vw, 48px) 54px; }

.intro {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 390px;
  align-items: end;
  gap: 52px;
  max-width: 1520px;
  margin: 0 auto;
  padding: clamp(34px, 5vw, 66px) 0 30px;
}

h1, .result h2 { margin: 0; font-family: SimSun, "Songti SC", serif; font-weight: 400; letter-spacing: 0; }
h1 { font-size: clamp(48px, 5vw, 76px); line-height: 0.98; }
h1 span { display: block; }
h1 span + span { margin-top: 8px; }
h1 em { color: var(--accent); font-style: normal; }
.intro-note { max-width: 390px; margin: 0 0 7px; color: var(--muted); font-size: 14px; line-height: 1.85; }

.arena {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: clamp(18px, 2.2vw, 34px);
  max-width: 1520px;
  margin: 0 auto;
}

.contender { min-width: 0; will-change: transform, opacity; }
.contender-head { display: flex; align-items: center; justify-content: space-between; min-height: 42px; margin-bottom: 11px; }
.contender-head > div { display: flex; align-items: center; gap: 10px; }
.contender-index { display: grid; place-items: center; width: 29px; height: 29px; color: var(--white); background: var(--ink); font-family: SimSun, serif; font-size: 15px; }
.contender h2 { margin: 0; font-size: 14px; }
.contender-state { color: var(--muted); font-size: 10px; letter-spacing: 0.08em; }

.browser-shell { overflow: hidden; border: 1px solid #2d302b; background: var(--frame); box-shadow: var(--shadow); transition: border-color 180ms ease, box-shadow 180ms ease; }
.browser-bar { display: grid; grid-template-columns: 70px 1fr 70px; align-items: center; height: 35px; padding: 0 10px; color: #aeb2aa; background: var(--frame); font-size: 9px; }
.browser-dots { display: flex; gap: 5px; }
.browser-dots i { width: 7px; height: 7px; border-radius: 50%; background: #5e625a; }
.browser-address { overflow: hidden; text-align: center; text-overflow: ellipsis; white-space: nowrap; }
.browser-live { justify-self: end; color: #d7dad3; font-weight: 700; letter-spacing: 0.08em; }

.preview-stage { position: relative; height: clamp(430px, 56vw, 760px); overflow: hidden; background: #fff; isolation: isolate; }
.preview-stage iframe { width: 100%; height: 100%; border: 0; background: #fff; }
.frame-vote {
  position: absolute;
  right: 12px;
  bottom: 12px;
  z-index: 3;
  min-width: 108px;
  padding: 10px 14px;
  border: 1px solid rgba(255, 255, 255, 0.42);
  color: var(--white);
  background: rgba(23, 24, 22, 0.92);
  box-shadow: 0 8px 24px rgba(20, 21, 19, 0.22);
  backdrop-filter: blur(10px);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: color 180ms ease, background 180ms ease, transform 180ms ease;
}
.frame-vote:hover { color: var(--white); background: var(--accent); transform: translateY(-2px); }
.frame-vote:active { transform: translateY(0) scale(0.98); }
.arena.is-locked .frame-vote, .arena.is-locked .vote-button { pointer-events: none; }

.ink-wash {
  position: absolute;
  inset: -8%;
  z-index: 4;
  pointer-events: none;
  visibility: hidden;
  opacity: 0;
  background:
    linear-gradient(104deg, transparent 2%, rgba(30, 31, 29, 0.78) 32%, rgba(83, 85, 80, 0.58) 62%, transparent 98%),
    linear-gradient(14deg, rgba(35, 36, 33, 0.18), rgba(35, 36, 33, 0.72));
  mix-blend-mode: multiply;
  will-change: transform, opacity;
}

.stamp {
  position: absolute;
  left: 50%;
  top: 46%;
  z-index: 6;
  display: grid;
  place-items: center;
  width: clamp(92px, 10vw, 136px);
  aspect-ratio: 1;
  border: 6px double currentColor;
  color: var(--accent);
  font-family: SimSun, "Songti SC", serif;
  font-size: clamp(54px, 7vw, 88px);
  line-height: 1;
  visibility: hidden;
  opacity: 0;
  transform: translate(-50%, -50%) rotate(-8deg);
  box-shadow: inset 0 0 0 4px rgba(199, 57, 47, 0.2);
  text-shadow: 1px 0 currentColor;
  pointer-events: none;
  will-change: transform, opacity;
}
.stamp-lose { color: #4f524d; transform: translate(-50%, -50%) rotate(7deg); box-shadow: inset 0 0 0 4px rgba(79, 82, 77, 0.18); }
.stamp-draw { color: #535750; transform: translate(-50%, -50%) rotate(-2deg); box-shadow: inset 0 0 0 4px rgba(83, 87, 80, 0.16); }

.arena.is-mobile-preview .preview-stage { max-width: 390px; height: 680px; margin: 0 auto; border-inline: 1px solid #d7d8d3; }
.arena.is-mobile-preview .browser-shell { background: #dbdcd7; }

.versus {
  position: absolute;
  left: 50%;
  top: 48%;
  z-index: 7;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 4px solid var(--paper);
  color: var(--white);
  background: var(--accent);
  font-family: SimSun, serif;
  font-size: 17px;
  transform: translate(-50%, -50%) rotate(-7deg);
}

.vote-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  margin-top: 12px;
  padding: 17px 18px;
  border: 1px solid var(--ink);
  color: var(--ink);
  background: transparent;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: color 180ms ease, background 180ms ease, transform 180ms ease;
}
.vote-button:hover { color: var(--white); background: var(--ink); transform: translateY(-2px); }
.vote-button:active { transform: translateY(0) scale(0.99); }
.vote-key { display: grid; place-items: center; width: 25px; height: 25px; border: 1px solid currentColor; font-size: 10px; }
.mobile-tabs { display: none; }
.draw-action {
  display: grid;
  place-items: center;
  max-width: 1520px;
  margin: 16px auto 0;
}

.draw-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-width: 220px;
  padding: 13px 15px 13px 19px;
  border: 1px solid var(--line);
  color: var(--muted);
  background: rgba(255, 255, 255, 0.3);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: color 180ms ease, border-color 180ms ease, background 180ms ease, transform 180ms ease;
}
.draw-button:hover { color: var(--ink); border-color: var(--ink); background: rgba(255, 255, 255, 0.62); transform: translateY(-2px); }
.draw-button:active { transform: scale(0.985); }
.draw-button[disabled] { pointer-events: none; opacity: 0.46; }
.draw-summary { margin-top: -14px !important; color: var(--accent-dark) !important; }

.result {
  display: grid;
  grid-template-columns: minmax(310px, 0.74fr) minmax(0, 1.55fr);
  gap: clamp(46px, 7vw, 110px);
  align-items: center;
  max-width: 1360px;
  min-height: calc(100dvh - 145px);
  margin: 0 auto;
  padding: 48px 0 68px;
}

.result-copy { align-self: center; }
.result h2 { font-size: clamp(42px, 3.8vw, 56px); line-height: 1.05; white-space: nowrap; }
.identity-scroll { overflow: hidden; width: max-content; max-width: 100%; margin-top: 5px; padding: 0 12px 9px 0; border-bottom: 1px solid var(--line); }
.winner-name { display: block; color: var(--ink); font-family: "Instrument Serif", Georgia, serif; font-size: clamp(72px, 8.5vw, 126px); font-style: italic; font-weight: 400; line-height: 1.1; white-space: nowrap; }
.result-copy > p { max-width: 350px; margin: 25px 0; color: var(--muted); font-size: 13px; line-height: 1.85; }
.restart-button { padding: 13px 20px; border: 1px solid var(--line); color: var(--ink); background: transparent; font-weight: 700; cursor: pointer; transition: border-color 180ms ease, color 180ms ease, transform 180ms ease; }
.restart-button:hover { border-color: var(--accent); color: var(--accent); }
.restart-button:active { transform: scale(0.98); }

.winner-column { min-width: 0; }
.winner-card { position: relative; display: block; height: min(68vh, 720px); overflow: hidden; color: var(--white); background: #252722; box-shadow: 0 30px 80px rgba(20, 20, 18, 0.18); text-decoration: none; will-change: transform, opacity; }
.winner-card iframe { width: 100%; height: 100%; border: 0; pointer-events: none; }
.winner-overlay { position: absolute; inset: auto 0 0; display: grid; grid-template-columns: 1fr auto; align-items: end; gap: 8px 20px; padding: 28px; background: linear-gradient(transparent, rgba(12, 13, 11, 0.9)); }
.winner-overlay small { grid-column: 1 / -1; font-size: 10px; letter-spacing: 0.12em; }
.winner-overlay strong { font-family: "Instrument Serif", Georgia, serif; font-size: clamp(36px, 5vw, 68px); font-style: italic; font-weight: 400; line-height: 1.1; white-space: nowrap; }
.winner-overlay em { font-size: 11px; font-style: normal; }

.ranking { display: grid; grid-template-columns: repeat(4, 1fr); border-inline: 1px solid var(--line); }
.rank-item { padding: 17px 14px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); visibility: hidden; opacity: 0; will-change: transform, opacity; }
.rank-item:last-child { border-right: 0; }
.rank-item small, .rank-item strong { display: block; }
.rank-item small { color: var(--muted); font-size: 9px; }
.rank-item strong { margin-top: 5px; font-family: "Instrument Serif", Georgia, serif; font-size: 18px; font-style: italic; font-weight: 400; white-space: nowrap; }

.jump-toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  z-index: 15;
  padding: 13px 18px;
  color: var(--white);
  background: var(--ink);
  font-size: 12px;
  visibility: hidden;
  opacity: 0;
  transform: translate(-50%, 18px);
  pointer-events: none;
}

footer { display: flex; justify-content: space-between; gap: 20px; padding: 20px clamp(18px, 3vw, 48px); border-top: 1px solid var(--line); color: var(--muted); font-size: 9px; letter-spacing: 0.08em; }

@media (max-width: 820px) {
  .topbar { min-height: 62px; padding-inline: 14px; }
  .round-track, .view-switch { display: none; }
  main { padding-inline: 14px; }
  .intro { display: block; padding: 30px 4px 22px; }
  h1 { font-size: 48px; }
  .intro-note { max-width: 350px; margin-top: 18px; font-size: 13px; }
  .arena { display: block; }
  .arena .contender { display: none; }
  .arena[data-mobile-active="left"] .contender-left,
  .arena[data-mobile-active="right"] .contender-right { display: block; }
  .versus { display: none; }
  .preview-stage { height: 64vh; min-height: 470px; }
  .draw-action { margin-top: 12px; }
  .draw-button { width: 100%; max-width: 520px; }
  .mobile-tabs { display: grid; grid-template-columns: 1fr 1fr; max-width: 520px; margin: 14px auto 0; border: 1px solid var(--line); }
  .mobile-tab { padding: 12px; border: 0; color: var(--muted); background: transparent; font-size: 12px; }
  .mobile-tab.is-active { color: var(--white); background: var(--ink); }
  .result { display: block; padding-top: 38px; }
  .result-copy { padding-bottom: 32px; }
  .result h2 { font-size: 46px; }
  .winner-name { font-size: clamp(72px, 24vw, 96px); }
  .winner-card { height: 58vh; min-height: 450px; }
  .winner-overlay { padding: 20px; }
  .ranking { grid-template-columns: 1fr 1fr; }
  .rank-item:nth-child(2) { border-right: 0; }
  footer { display: block; line-height: 2; }
  footer span { display: block; }
}

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