:root {
  --bg: #070a12;
  --panel: #101722;
  --panel-strong: #162234;
  --line: #28354a;
  --text: #f4f7fb;
  --muted: #9aa8bd;
  --red: #ff4d57;
  --gold: #f6bd4f;
  --blue: #4f8cff;
  --green: #44d08b;
  --purple: #a979ff;
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: dark;
}

body {
  margin: 0;
  min-width: 320px;
  color: var(--text);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 16% 0%, rgba(255, 77, 87, 0.18), transparent 30rem),
    radial-gradient(circle at 86% 8%, rgba(79, 140, 255, 0.16), transparent 28rem),
    linear-gradient(180deg, #0a0f1a 0%, var(--bg) 48%, #060812 100%);
}

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

button {
  min-height: 40px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 34px;
  line-height: 1.15;
}

h2 {
  font-size: 18px;
  line-height: 1.35;
}

p {
  color: var(--muted);
  line-height: 1.7;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto auto;
  gap: 18px;
  align-items: center;
  padding: 14px 28px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(7, 10, 18, 0.86);
  backdrop-filter: blur(18px);
}

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

.brand-mark {
  display: grid;
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  color: #12080a;
  background: linear-gradient(135deg, var(--gold), var(--red));
  font-weight: 900;
}

.brand strong,
.brand span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand strong {
  font-size: 15px;
}

.brand span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.nav,
.nav-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: center;
}

.nav-item {
  min-width: 70px;
  padding: 0 12px;
  border: 1px solid transparent;
  color: var(--muted);
  background: transparent;
  text-align: center;
}

.nav-item:hover,
.nav-item.active {
  border-color: rgba(79, 140, 255, 0.36);
  color: var(--text);
  background: rgba(79, 140, 255, 0.14);
}

.user-area {
  position: relative;
  display: flex;
  min-width: max-content;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
}

.user-menu {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  width: 260px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.34);
}

.user-menu strong,
.user-menu span {
  display: block;
}

.user-menu span {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
}

.app-main {
  width: min(1180px, calc(100% - 48px));
  margin: 0 auto;
  padding: 28px 0 56px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.contest-hero,
.arena-hero {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 44%);
  gap: 24px;
  align-items: stretch;
  overflow: hidden;
  min-height: 380px;
  padding: 28px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(255, 77, 87, 0.12), rgba(79, 140, 255, 0.08)),
    var(--panel);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.28);
}

.contest-hero img {
  width: 100%;
  min-height: 320px;
  height: 100%;
  object-fit: cover;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
}

.hero-copy {
  display: flex;
  min-width: 0;
  flex-direction: column;
  justify-content: center;
  gap: 18px;
}

.hero-copy p {
  max-width: 640px;
  font-size: 16px;
}

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

.answer-panel {
  display: grid;
  gap: 12px;
  padding-top: 4px;
}

.primary,
.secondary {
  display: inline-flex;
  min-width: 116px;
  align-items: center;
  justify-content: center;
  padding: 0 16px;
  font-weight: 800;
}

.primary {
  color: #15090a;
  background: linear-gradient(135deg, var(--gold), var(--red));
}

.secondary {
  border: 1px solid var(--line);
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}

.primary:hover,
.secondary:hover {
  transform: translateY(-1px);
}

.small {
  min-height: 34px;
  min-width: 112px;
  font-size: 13px;
}

.eyebrow,
.status-pill {
  display: inline-flex;
  width: fit-content;
  align-items: center;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.eyebrow {
  color: var(--gold);
}

.status-pill {
  min-height: 28px;
  padding: 0 10px;
  border: 1px solid rgba(68, 208, 139, 0.32);
  color: var(--green);
  background: rgba(68, 208, 139, 0.11);
}

.metric-grid,
.stage-grid,
.stage-strip,
.lobster-grid,
.lobster-slots,
.question-grid,
.question-list,
.admin-grid {
  display: grid;
  gap: 14px;
}

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

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

.metric,
.stage-grid article,
.stage-strip article,
.lobster-panel,
.registration-panel,
.instruction-panel,
.leaderboard-panel,
.my-rank-panel,
.question-card,
.arena-layout section,
.arena-candidate,
.champion-spot,
.admin-grid article,
.admin-data section {
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.04), transparent),
    var(--panel);
}

.metric,
.stage-grid article,
.stage-strip article,
.question-card,
.arena-candidate,
.champion-spot,
.admin-grid article,
.admin-data section {
  padding: 18px;
}

.metric {
  min-height: 140px;
}

.metric span,
.metric small,
.stage-grid span,
.stage-strip span {
  display: block;
  color: var(--muted);
}

.metric strong {
  display: block;
  margin: 10px 0 6px;
  color: var(--text);
  font-size: 28px;
  line-height: 1.1;
}

.stage-grid article,
.stage-strip article {
  min-height: 150px;
}

.stage-grid article:first-child,
.stage-strip article:first-child {
  border-top: 4px solid var(--blue);
}

.stage-grid article:nth-child(2),
.stage-strip article:nth-child(2) {
  border-top: 4px solid var(--gold);
}

.stage-grid article:nth-child(3),
.stage-strip article:nth-child(3) {
  border-top: 4px solid var(--red);
}

.section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.section-note {
  color: var(--muted);
  font-size: 0.92rem;
  margin: 8px 0 0;
}

.register-layout,
.registration-panel,
.leaderboard-layout,
.leaderboard-panel,
.arena-layout,
.admin-data {
  display: grid;
  gap: 16px;
}

.register-layout,
.registration-panel {
  grid-template-columns: minmax(260px, 0.9fr) minmax(0, 1.3fr);
}

.leaderboard-layout,
.leaderboard-panel,
.arena-layout,
.admin-data {
  grid-template-columns: minmax(0, 1fr) 300px;
}

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

.lobster-panel,
.instruction-panel,
.my-rank-panel {
  padding: 18px;
}

.lobster-panel h2,
.instruction-panel h2,
.arena-layout h2,
.admin-data h2 {
  margin-bottom: 14px;
}

.lobster-grid,
.lobster-slots {
  grid-template-columns: 1fr;
  margin-top: 14px;
}

.lobster-slot {
  display: grid;
  width: 100%;
  min-height: 86px;
  gap: 6px;
  align-content: center;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
  text-align: left;
}

.lobster-slot:hover,
.lobster-slot.active {
  border-color: rgba(255, 77, 87, 0.56);
  background: rgba(255, 77, 87, 0.12);
}

.lobster-slot.empty {
  border-style: dashed;
  color: var(--muted);
}

.lobster-slot span {
  color: var(--muted);
  font-size: 13px;
}

label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}

input::placeholder,
textarea::placeholder {
  color: #718096;
}

textarea,
pre {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

.instruction-console,
.result-box {
  grid-column: 1 / -1;
  min-height: 190px;
  max-height: 420px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  padding: 14px;
  border: 1px solid rgba(79, 140, 255, 0.35);
  border-radius: 8px;
  color: #d7e5ff;
  background: #08101c;
}

.instruction-panel {
  display: grid;
  gap: 14px;
}

.stage-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.question-grid,
.question-list {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.question-card {
  min-height: 150px;
  border-left: 4px solid var(--purple);
}

.question-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.question-meta span {
  padding: 3px 8px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
}

.question-card small {
  color: var(--gold);
  display: block;
  font-weight: 700;
  margin-top: 12px;
}

.leaderboard-layout,
.leaderboard-panel,
.admin-data section {
  overflow-x: auto;
}

.table {
  width: 100%;
  min-width: 620px;
  border-collapse: collapse;
}

th,
td {
  padding: 13px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--gold);
  font-size: 12px;
  text-transform: uppercase;
}

td {
  color: #dbe5f2;
}

tr:last-child td {
  border-bottom: 0;
}

.my-rank-panel {
  min-height: 180px;
}

.arena-hero {
  grid-template-columns: 1fr;
  min-height: 240px;
  margin-bottom: 16px;
  background:
    linear-gradient(135deg, rgba(255, 77, 87, 0.18), rgba(169, 121, 255, 0.14)),
    var(--panel-strong);
}

.arena-layout {
  grid-template-columns: minmax(0, 1fr) 320px;
}

.arena-candidates {
  display: grid;
  gap: 10px;
}

.arena-candidate {
  display: flex;
  min-height: 64px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.arena-candidate span,
.champion-spot span {
  color: var(--muted);
}

.champion-spot {
  display: grid;
  min-height: 160px;
  place-items: center;
  text-align: center;
}

.champion-spot strong {
  color: var(--gold);
  font-size: 30px;
}

.admin-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.admin-grid article {
  min-height: 140px;
}

.admin-grid article:first-child {
  border-left: 4px solid var(--green);
}

.admin-grid article:nth-child(2) {
  border-left: 4px solid var(--blue);
}

.admin-grid article:nth-child(3) {
  border-left: 4px solid var(--purple);
}

.admin-data + .button-row,
.button-row + .result-box {
  margin-top: 16px;
}

.wide {
  grid-column: 1 / -1;
}

@media (max-width: 900px) {
  .topbar {
    position: static;
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .nav,
  .nav-links {
    justify-content: flex-start;
  }

  .user-area {
    min-width: 0;
    justify-content: flex-start;
  }

  .contest-hero,
  .register-layout,
  .registration-panel,
  .leaderboard-layout,
  .leaderboard-panel,
  .arena-layout,
  .admin-data {
    grid-template-columns: 1fr;
  }

  .contest-hero {
    min-height: 0;
  }

  .contest-hero img {
    min-height: 240px;
  }

  .metric-grid,
  .stage-grid,
  .stage-strip,
  .question-grid,
  .question-list,
  .admin-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  h1 {
    font-size: 28px;
  }

  .app-main {
    width: min(100% - 28px, 1180px);
    padding-top: 18px;
  }

  .topbar {
    padding: 12px 14px;
  }

  .brand strong,
  .brand span {
    white-space: normal;
  }

  .nav,
  .nav-links,
  .stage-tabs,
  .hero-actions,
  .button-row,
  .user-area {
    display: grid;
    grid-template-columns: 1fr;
  }

  .nav-item,
  .primary,
  .secondary,
  .small {
    width: 100%;
  }

  .contest-hero,
  .arena-hero {
    padding: 18px;
  }

  .contest-hero img {
    min-height: 180px;
  }

  .metric-grid,
  .stage-grid,
  .stage-strip,
  .question-grid,
  .question-list,
  .admin-grid {
    grid-template-columns: 1fr;
  }

  .section-heading {
    align-items: start;
    flex-direction: column;
  }

  .arena-candidate {
    align-items: flex-start;
    flex-direction: column;
  }

  .table {
    min-width: 560px;
  }
}
