:root {
  color-scheme: light;
  --paper: #f4f2ed;
  --sheet: #fffefa;
  --ink: #202127;
  --muted: #777982;
  --cobalt: #4969ff;
  --coral: #ff6b57;
  --lavender: #c9beff;
  --line: rgba(32, 33, 39, 0.1);
  --shadow: 0 18px 50px rgba(47, 42, 35, 0.08);
  --ease: cubic-bezier(.22, 1, .36, 1);
}

* { box-sizing: border-box; }
html { background: var(--paper); scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  color: var(--ink);
  font: 16px/1.55 ui-rounded, "Avenir Next", "Trebuchet MS", sans-serif;
  background:
    radial-gradient(circle at 8% 38%, rgba(201, 190, 255, .28), transparent 25rem),
    radial-gradient(circle at 92% 74%, rgba(255, 107, 87, .12), transparent 27rem),
    var(--paper);
}
button, input { font: inherit; }
button { touch-action: manipulation; }
.aurora, .portal-mark { display: none; }
.skip {
  position: fixed;
  left: 20px;
  top: -64px;
  z-index: 500;
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--ink);
  color: white;
}
.skip:focus { top: 20px; }
header {
  position: relative;
  z-index: 100;
  width: min(1180px, calc(100% - 40px));
  height: 72px;
  margin: 18px auto 0;
  padding: 0 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: 1px solid rgba(255, 255, 255, .7);
  border-radius: 24px;
  background: rgba(255, 254, 250, .88);
  box-shadow: 0 8px 28px rgba(47, 42, 35, .07);
  backdrop-filter: blur(18px);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .08em;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; letter-spacing: -.02em; font-size: 17px; }
.brand img { border-radius: 10px; }
.brand b { color: var(--cobalt); }
main { width: min(1480px, calc(100% - 40px)); margin: auto; }
.setup {
  max-width: 1040px;
  margin: clamp(64px, 10vh, 112px) auto;
  padding: clamp(36px, 7vw, 88px);
  border: 1px solid rgba(255, 255, 255, .8);
  border-radius: 36px;
  background: rgba(255, 254, 250, .86);
  box-shadow: var(--shadow);
  text-align: center;
  animation: arrive .55s var(--ease) both;
}
.eyebrow {
  display: inline-flex;
  margin: 0;
  padding: 8px 14px;
  border: 1px solid rgba(73, 105, 255, .2);
  border-radius: 999px;
  color: var(--cobalt);
  background: rgba(73, 105, 255, .06);
  font-size: 12px;
  font-weight: 750;
  letter-spacing: .06em;
}
.setup h1, .results h1 {
  margin: 26px auto 24px;
  max-width: 860px;
  font-size: clamp(46px, 7.2vw, 88px);
  line-height: .98;
  letter-spacing: -.065em;
  text-wrap: balance;
}
.setup h1 em { color: var(--cobalt); font-style: normal; font-weight: 650; }
.lede { max-width: 660px; margin: 0 auto 42px; color: var(--muted); font-size: 18px; }
button {
  border: 0;
  border-radius: 13px;
  padding: 13px 22px;
  background: var(--cobalt);
  color: white;
  font-weight: 750;
  cursor: pointer;
  transition: transform .22s var(--ease), filter .22s, box-shadow .22s;
}
button:hover { transform: translateY(-2px); filter: brightness(.96); box-shadow: 0 12px 24px rgba(73, 105, 255, .2); }
button:active { transform: translateY(1px) scale(.99); }
button:focus-visible { outline: 2px solid var(--cobalt); outline-offset: 3px; }
button:disabled { cursor: wait; opacity: .65; }
.undo-choice:disabled { cursor: not-allowed; }
.html-import { display: grid; justify-items: center; gap: 14px; }
.html-import .file { padding: 15px 24px; border-radius: 13px; background: var(--cobalt); color: white; font-weight: 750; cursor: pointer; transition: transform .22s var(--ease), filter .22s, box-shadow .22s; }
.html-import input { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.html-import .file:hover { transform: translateY(-2px); filter: brightness(.96); box-shadow: 0 12px 24px rgba(73, 105, 255, .2); }
.html-import .file:active { transform: translateY(1px) scale(.99); }
.html-import .file:focus-within { outline: 2px solid var(--cobalt); outline-offset: 3px; }
#message { min-height: 24px; margin: 0; color: var(--muted); font-size: 13px; }
.arena { padding: 20px 0 32px; animation: arrive .42s var(--ease) both; }
.progress { display: flex; align-items: center; gap: 16px; margin: 0 4px 12px; color: var(--muted); font-size: 13px; font-weight: 650; }
.round-status { display: grid; min-width: 132px; gap: 2px; }
.round-status b { color: var(--ink); font-size: 15px; }
.round-status small { font-size: 11px; font-weight: 600; font-variant-numeric: tabular-nums; }
.progress i { height: 6px; flex: 1; overflow: hidden; border-radius: 999px; background: rgba(32, 33, 39, .08); }
.progress b { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--cobalt); transition: width .35s var(--ease); }
.progress .round-status b { width: auto; height: auto; background: none; }
.bracket-open { padding: 10px 15px; white-space: nowrap; }
.undo-choice { padding: 10px 15px; white-space: nowrap; }
.duel { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; }
.game {
  position: relative;
  min-width: 0;
  user-select: none;
  -webkit-user-select: none;
  padding: 0;
  overflow: hidden;
  border: 7px solid var(--sheet);
  border-radius: 30px;
  background: var(--sheet);
  color: var(--ink);
  text-align: left;
  box-shadow: var(--shadow);
  animation: card-in .46s var(--ease) both;
}
.game:last-child { animation-delay: .08s; }
.game:hover { transform: translateY(-7px) scale(1.012); box-shadow: 0 28px 70px rgba(47, 42, 35, .15); }
.game-select { display: block; width: 100%; padding: 0; border: 0; border-radius: 23px; background: var(--sheet); color: var(--ink); text-align: left; box-shadow: none; }
.game-select:hover, .game-select:active { transform: none; filter: none; box-shadow: none; }
.game img { display: block; width: 100%; height: auto; aspect-ratio: 3 / 4; object-fit: contain; border-radius: 23px 23px 0 0; background: #e9e7e1; pointer-events: none; -webkit-user-drag: none; }
.game-select > span { display: block; padding: 14px 20px 16px; background: var(--sheet); }
.game strong { display: block; font-size: clamp(20px, 2.4vw, 30px); line-height: 1.1; letter-spacing: -.025em; text-wrap: balance; }
.game-link { position: absolute; top: 14px; right: 14px; z-index: 2; display: flex; min-height: 40px; align-items: center; padding: 8px 13px; border-radius: 999px; background: rgba(255, 254, 250, .9); color: var(--ink); font-size: 12px; font-weight: 800; text-decoration: none; box-shadow: 0 6px 20px rgba(32, 33, 39, .16); backdrop-filter: blur(12px); }
.game-link:hover { transform: translateY(-2px); }
.game-link:focus-visible { outline: 2px solid var(--cobalt); outline-offset: 3px; }
.game small, .versus, .hint { display: none; }
.results { max-width: 980px; margin: 64px auto; animation: arrive .45s var(--ease) both; }
.results .eyebrow { margin-left: 0; }
.results h1 { margin-left: 0; font-size: clamp(46px, 6vw, 76px); }
.result-actions { display: flex; gap: 10px; margin: 28px 0; }
.secondary { border: 1px solid var(--line); background: var(--sheet); color: var(--ink); }
#ranking { padding: 12px; list-style: none; counter-reset: rank; border-radius: 28px; background: rgba(255, 254, 250, .76); box-shadow: var(--shadow); }
#ranking li { counter-increment: rank; display: grid; grid-template-columns: 54px 64px 1fr auto; align-items: center; gap: 18px; padding: 12px; border-bottom: 1px solid var(--line); animation: arrive .38s var(--ease) both; animation-delay: calc(var(--i, 0) * 55ms); }
#ranking li:last-child { border-bottom: 0; }
#ranking li:before { content: counter(rank, decimal-leading-zero); color: var(--cobalt); font-weight: 800; font-variant-numeric: tabular-nums; }
#ranking img { width: 64px; height: 84px; border-radius: 12px; object-fit: contain; }
#ranking a { color: var(--ink); font-size: 18px; font-weight: 700; text-decoration: none; }
.bracket-panel { margin: 38px 0; padding: 26px; overflow-x: auto; border-radius: 28px; background: rgba(255, 254, 250, .76); box-shadow: var(--shadow); }
.bracket-panel .eyebrow { margin-bottom: 8px; }
.bracket-hint { display: block; margin: 0 0 22px; color: var(--muted); font-size: 12px; }
.bracket { display: grid; grid-auto-columns: minmax(260px, 1fr); grid-auto-flow: column; align-items: stretch; gap: 42px; min-width: max-content; }
.bracket section { display: flex; min-width: 260px; flex-direction: column; justify-content: flex-start; gap: 12px; }
.bracket h3 { margin: 0 0 4px; color: var(--muted); font-size: 12px; letter-spacing: .12em; text-transform: uppercase; }
.bracket-lane { display: grid; gap: 10px; padding: 10px; border-radius: 20px; background: rgba(255, 254, 250, .58); box-shadow: inset 0 0 0 1px var(--line); }
.bracket-lane h4 { display: flex; align-items: center; gap: 7px; margin: 0 2px 2px; color: var(--muted); font-size: 11px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; }
.bracket-lane h4:before { display: grid; width: 22px; height: 22px; place-items: center; font-size: 16px; line-height: 1; }
.bracket-lane.upper h4:before { content: "👑"; }
.bracket-lane.lower h4:before { content: "💀"; }
.bracket-lane.opening h4:before { content: "🎲"; }
.bracket article { position: relative; overflow: visible; border: 1px solid var(--line); border-radius: 16px; background: var(--sheet); box-shadow: 0 8px 24px rgba(47, 42, 35, .07); }
.bracket article:after { content: ""; position: absolute; top: 50%; left: 100%; width: 43px; border-top: 1px solid var(--line); }
.bracket section:last-child article:after { display: none; }
.bracket-game { display: grid; width: 100%; grid-template-columns: 38px minmax(0, 1fr); align-items: center; gap: 10px; min-height: 52px; padding: 8px 11px; border: 0; border-radius: 0; background: transparent; color: var(--muted); font-size: 13px; font-weight: 650; text-align: left; box-shadow: none; transition: opacity .16s var(--ease); }
.bracket-game:hover, .bracket-game:active { transform: none; filter: none; box-shadow: none; }
.bracket article .bracket-game + .bracket-game { border-top: 1px solid var(--line); }
.bracket article img { width: 38px; height: 52px; border-radius: 7px; object-fit: contain; background: #e9e7e1; }
.bracket article span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bracket article .winner { color: var(--ink); background: rgba(82, 104, 255, .09); }
.bracket article .winner span:after { content: " ✓"; color: var(--cobalt); }
.bracket article.current { outline: 2px solid rgba(82, 104, 255, .35); outline-offset: 2px; }
.bracket.tracing article:not(.path-active) { opacity: .2; }
.bracket article.path-active { box-shadow: 0 0 0 2px var(--ink), 0 12px 30px rgba(47, 42, 35, .14); }
.bracket article.path-active:after { border-top: 3px solid var(--ink); }
.bracket-game.path-active { color: var(--ink); background: rgba(32, 33, 39, .08); }
dialog { width: min(1240px, calc(100vw - 32px)); max-width: none; height: min(820px, calc(100vh - 32px)); padding: 0; overflow: hidden; border: 0; border-radius: 28px; background: var(--paper); color: var(--ink); box-shadow: 0 34px 100px rgba(32, 33, 39, .24); }
dialog::backdrop { background: rgba(32, 33, 39, .42); backdrop-filter: blur(8px); }
.bracket-dialog-head { display: flex; align-items: center; justify-content: space-between; width: auto; max-width: none; height: auto; margin: 0; padding: 24px 28px; border-bottom: 1px solid var(--line); border-radius: 0; background: rgba(255, 254, 250, .92); box-shadow: none; }
.bracket-dialog-head .eyebrow { margin: 0 0 4px; }
.bracket-dialog-head h2 { margin: 0; font-size: 28px; letter-spacing: -.025em; }
.bracket-dialog-head form { margin: 0; }
.bracket-canvas { height: calc(100% - 106px); padding: 28px; overflow: auto; overscroll-behavior: contain; }
.round-dialog { width: min(520px, calc(100vw - 32px)); height: fit-content; max-height: calc(100vh - 32px); padding: 32px; overflow: auto; }
.round-dialog .eyebrow { margin: 0 0 12px; }
.round-dialog h2 { margin: 0; font-size: 32px; line-height: 1.05; letter-spacing: -.035em; text-wrap: balance; }
.round-dialog > p:not(.eyebrow) { margin: 16px 0 28px; color: var(--muted); line-height: 1.5; }
.round-actions { display: flex; justify-content: flex-end; gap: 10px; }
[hidden] { display: none !important; }

@keyframes arrive { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: translateY(0); } }
@keyframes card-in { from { opacity: 0; transform: translateY(22px) scale(.985); } to { opacity: 1; transform: translateY(0) scale(1); } }

@media (max-width: 768px) {
  header { width: calc(100% - 24px); height: 62px; margin-top: 12px; padding: 0 18px; }
  header > span { display: none; }
  main { width: calc(100% - 24px); }
  .setup { margin-top: 36px; padding: 30px 20px; border-radius: 28px; }
  .setup h1 { font-size: clamp(42px, 13vw, 64px); }
  .progress { flex-wrap: wrap; gap: 10px; }
  .progress i { order: 3; flex-basis: 100%; }
  .bracket-open { margin-left: auto; }
  .undo-choice { margin-left: auto; }
  .undo-choice + .bracket-open { margin-left: 0; }
  .bracket-dialog-head { width: auto; height: auto; margin: 0; padding: 20px; }
  .bracket-dialog-head h2 { font-size: 22px; }
  .bracket-dialog-head button { width: auto; }
  .round-dialog { padding: 24px; }
  .round-actions { align-items: stretch; flex-direction: column-reverse; }
  .duel { gap: 8px; }
  .game { border-width: 4px; border-radius: 18px; }
  .game img { border-radius: 14px 14px 0 0; }
  .game-select > span { padding: 11px 10px 12px; }
  .game-link { top: 8px; right: 8px; }
  .game strong { font-size: 16px; }
  #ranking li { grid-template-columns: 34px 48px 1fr; }
  #ranking img { width: 48px; height: 64px; }
  #ranking span { display: none; }
}

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