:root {
  --bg: #f6f4ee;
  --panel: #ffffff;
  --ink: #1e2528;
  --muted: #667075;
  --line: #d8ded9;
  --accent: #0f766e;
  --accent-strong: #115e59;
  --warn: #b45309;
  --danger: #b91c1c;
  --blue: #2563eb;
  --shadow: 0 18px 45px rgba(31, 41, 55, 0.14);
  --btn-bg: #ffffff;
  --input-bg: #ffffff;
  --dropzone-bg: rgba(255, 255, 255, 0.7);
  --notice-bg: #fff7ed;
  --notice-info-bg: #eff6ff;
  --badge-muted-bg: #eef1ef;
  --slot-bg: #f7f8f6;
  --slot-winner-bg: #dcfce7;
  --slot-winner-color: #064e3b;
  --slot-loser-bg: #fee2e2;
  --slot-loser-color: #7f1d1d;
  --embed-bg: #111;
  --result-hero-bg: #ffffff;
}

[data-theme="dark"] {
  --bg: #131517;
  --panel: #1e2022;
  --ink: #e8e4de;
  --muted: #8a9297;
  --line: #33383c;
  --accent: #14b8a6;
  --accent-strong: #0d9488;
  --warn: #f59e0b;
  --danger: #ef4444;
  --blue: #3b82f6;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.35);
  --btn-bg: #282b2e;
  --input-bg: #282b2e;
  --dropzone-bg: rgba(40, 43, 46, 0.7);
  --notice-bg: #432806;
  --notice-info-bg: #1e3a8a;
  --badge-muted-bg: #2a2e31;
  --slot-bg: #25282b;
  --slot-winner-bg: #064e3b;
  --slot-winner-color: #6ee7b7;
  --slot-loser-bg: #7f1d1d;
  --slot-loser-color: #fca5a5;
  --embed-bg: #0a0a0a;
  --result-hero-bg: #1e2022;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(145deg, rgba(15, 118, 110, 0.08), transparent 36%),
    linear-gradient(315deg, rgba(185, 28, 28, 0.08), transparent 38%),
    var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  transition: background 300ms ease, color 300ms ease;
}

[data-theme="dark"] body {
  background:
    linear-gradient(145deg, rgba(20, 184, 166, 0.06), transparent 36%),
    linear-gradient(315deg, rgba(239, 68, 68, 0.06), transparent 38%),
    var(--bg);
}

button,
textarea,
select,
input {
  font: inherit;
}

button {
  border: 0;
}

.app {
  width: min(1180px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 28px 0 44px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  color: white;
  background: var(--ink);
  border-radius: 8px;
  font-weight: 800;
}

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

h1 {
  margin-bottom: 2px;
  font-size: clamp(1.75rem, 3vw, 2.6rem);
  line-height: 1.05;
}

.subtitle {
  margin: 0;
  color: var(--muted);
}

.screen {
  display: grid;
  gap: 18px;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(320px, 0.95fr);
  gap: 18px;
  align-items: start;
}

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

.panel-body {
  padding: 18px;
}

.section-title {
  margin-bottom: 12px;
  font-size: 1.05rem;
}

.input-mode {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 14px;
}

.segmented {
  border: 1px solid var(--line);
  color: var(--ink);
  background: var(--input-bg);
  border-radius: 8px;
  padding: 10px 12px;
  cursor: pointer;
}

.segmented.active {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

textarea {
  width: 100%;
  min-height: 260px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: var(--input-bg);
  color: var(--ink);
  line-height: 1.45;
}

.drop-zone {
  display: grid;
  min-height: 220px;
  place-items: center;
  border: 1px dashed var(--muted);
  border-radius: 8px;
  background: var(--dropzone-bg);
  text-align: center;
  padding: 22px;
}

.file-input {
  max-width: 280px;
}

.controls {
  display: grid;
  gap: 12px;
}

.field label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.92rem;
}

select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--input-bg);
  color: var(--ink);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--ink);
  background: var(--btn-bg);
  border: 1px solid var(--line);
  cursor: pointer;
  transition: transform 160ms ease, background 160ms ease, color 160ms ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn.primary {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

.btn.primary:hover {
  background: var(--accent-strong);
}

.btn.danger {
  color: #fff;
  background: var(--danger);
  border-color: var(--danger);
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.48;
  transform: none;
}

.notice {
  border: 1px solid var(--warn);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--warn);
  background: var(--notice-bg);
}

.notice.info {
  border-color: var(--blue);
  color: var(--blue);
  background: var(--notice-info-bg);
}

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

.option-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--input-bg);
}

.option-name {
  overflow-wrap: anywhere;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 3px 8px;
  color: #fff;
  background: var(--blue);
  font-size: 0.78rem;
  white-space: nowrap;
}

.badge.warn {
  background: var(--warn);
}

.badge.muted {
  color: var(--muted);
  background: var(--badge-muted-bg);
}

.bracket {
  overflow-x: auto;
  overflow-y: auto;
  max-height: 75vh;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel);
}

.bracket canvas {
  display: block;
}

.match-screen {
  min-height: calc(100vh - 72px);
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 16px;
}

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

.progress {
  color: var(--muted);
  font-size: 0.95rem;
}

.arena {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: clamp(14px, 4vw, 42px);
  align-items: center;
  min-height: 560px;
  perspective: 1200px;
}

.choice-wrap {
  display: grid;
  gap: 10px;
  justify-items: center;
  transition: transform 520ms ease, opacity 520ms ease, filter 520ms ease;
}

.choice-title {
  min-height: 1.5em;
  color: var(--muted);
  text-align: center;
  overflow-wrap: anywhere;
}

.choice-card {
  position: relative;
  display: grid;
  width: min(100%, 380px);
  aspect-ratio: 3 / 4;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  cursor: pointer;
  isolation: isolate;
}

.choice-card.wide {
  aspect-ratio: 16 / 10;
  width: min(100%, 520px);
}

.choice-card.square {
  aspect-ratio: 1;
}

.choice-card.interactive {
  cursor: default;
}

.choice-card img,
.choice-card video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.choice-card audio {
  align-self: center;
  width: calc(100% - 28px);
  margin: auto;
}

.text-choice {
  display: grid;
  place-items: center;
  padding: 22px;
  text-align: center;
  font-size: clamp(1.1rem, 3vw, 1.9rem);
  font-weight: 700;
  line-height: 1.18;
  overflow-wrap: anywhere;
}

.url-fallback {
  display: grid;
  place-items: center;
  gap: 18px;
  padding: 26px;
  text-align: center;
}

.url-fallback img {
  width: 86px;
  height: 86px;
  object-fit: contain;
}

.url-host {
  color: var(--muted);
  overflow-wrap: anywhere;
}

.embed-frame {
  width: 100%;
  height: 100%;
  border: 0;
  background: var(--embed-bg);
}

.vote-button {
  width: min(100%, 380px);
}

.choice-wrap.picked-left,
.choice-wrap.picked-right {
  z-index: 4;
}

.choice-wrap.picked-left {
  transform: translateX(calc(50% + 21px)) scale(1.06);
}

.choice-wrap.picked-right {
  transform: translateX(calc(-50% - 21px)) scale(1.06);
}

.choice-wrap.rejected-left {
  opacity: 0;
  filter: blur(2px);
  transform: translateX(-10vw) translateZ(-360px) rotateY(28deg) scale(0.7);
}

.choice-wrap.rejected-right {
  opacity: 0;
  filter: blur(2px);
  transform: translateX(10vw) translateZ(-360px) rotateY(-28deg) scale(0.7);
}

.result-hero {
  display: grid;
  gap: 14px;
  justify-items: start;
  padding: 26px;
  background: var(--result-hero-bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.winner-name {
  margin: 0;
  font-size: clamp(2rem, 6vw, 4.5rem);
  line-height: 0.98;
  overflow-wrap: anywhere;
}

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

@media (max-width: 860px) {
  .layout,
  .restore-grid {
    grid-template-columns: 1fr;
  }

  .topbar,
  .match-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .arena {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .choice-wrap.picked-left,
  .choice-wrap.picked-right {
    transform: scale(1.03);
  }

  .choice-wrap.rejected-left,
  .choice-wrap.rejected-right {
    transform: translateY(10vh) translateZ(-300px) scale(0.7);
  }
}

.theme-toggle {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--btn-bg);
  color: var(--ink);
  cursor: pointer;
  transition: transform 160ms ease, background 160ms ease;
  flex-shrink: 0;
}

.theme-toggle:hover {
  transform: translateY(-1px);
}

.theme-toggle svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

[data-theme="dark"] .theme-toggle .icon-light {
  display: none;
}

.theme-toggle .icon-dark {
  display: none;
}

[data-theme="dark"] .theme-toggle .icon-dark {
  display: block;
}
