* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

:root {
  --ui-zoom: 0.94;
  --void: #060910;
  --ink: #d7f6ff;
  --muted: #7f9eb0;
  --line: rgba(62, 224, 255, 0.38);
  --cyan: #3ee0ff;
  --danger: #ff5d73;
  --font-ui: "Share Tech Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --font-display: "Orbitron", "Avenir Next", "Segoe UI", sans-serif;
  color-scheme: dark;
}

body {
  zoom: var(--ui-zoom);
  margin: 0;
  min-height: calc(100vh / var(--ui-zoom));
  font-family: var(--font-ui);
  color: var(--ink);
  background:
    radial-gradient(1000px 520px at 8% -10%, rgba(62, 224, 255, 0.16), transparent 55%),
    radial-gradient(800px 480px at 100% 0%, rgba(255, 77, 141, 0.1), transparent 48%),
    linear-gradient(180deg, #0c1526 0%, var(--void) 42%);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(62, 224, 255, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(62, 224, 255, 0.045) 1px, transparent 1px);
  background-size: 40px 40px;
  mask-image: radial-gradient(circle at 40% 20%, #000 20%, transparent 78%);
}

.app,
.login-screen {
  position: relative;
  z-index: 1;
}

:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

.app {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: calc(100vh / var(--ui-zoom));
}

.mobile-bar,
.sidebar-backdrop {
  display: none;
}

.sidebar {
  display: flex;
  flex-direction: column;
  height: calc(100vh / var(--ui-zoom));
  position: sticky;
  top: 0;
  padding: 32px 20px 20px;
  background: rgba(4, 10, 18, 0.92);
  color: var(--ink);
  border-right: 1px solid var(--line);
  box-shadow: inset -20px 0 40px rgba(62, 224, 255, 0.03);
}

.brand {
  display: block;
  width: 100%;
  margin: 0 0 32px;
  padding: 0 12px;
  border: 0;
  background: transparent;
  color: var(--cyan);
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 700;
  letter-spacing: 0.06em;
  line-height: 1.35;
  text-align: left;
  text-transform: uppercase;
  text-decoration: none;
  cursor: pointer;
}

.sidebar nav {
  flex: 1 1 auto;
}

nav ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 4px;
}

nav a,
nav button,
.section-label {
  display: block;
  width: 100%;
  padding: 10px 12px;
  border: 0;
  background: transparent;
  color: inherit;
  font-family: var(--font-ui);
  font-size: 16px;
  letter-spacing: 0.04em;
  text-align: left;
  text-decoration: none;
}

.section-label {
  color: var(--muted);
}

nav a,
nav button {
  cursor: pointer;
}

nav a[aria-current="page"],
nav button[aria-current="page"] {
  color: var(--cyan);
  background: rgba(62, 224, 255, 0.08);
  box-shadow: inset 3px 0 0 var(--cyan);
}

.nav-link {
  display: block;
  width: 100%;
  padding: 10px 12px;
  color: inherit;
  font-family: var(--font-ui);
  font-size: 16px;
  letter-spacing: 0.04em;
  text-decoration: none;
}

.nav-link.active {
  color: var(--cyan);
  background: rgba(62, 224, 255, 0.08);
  box-shadow: inset 3px 0 0 var(--cyan);
}

.nav-link.disabled {
  color: var(--muted);
  pointer-events: none;
}

.quick-links {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
  gap: 16px;
  margin-top: 28px;
  max-width: 48rem;
}

.quick-card {
  display: grid;
  gap: 6px;
  padding: 18px;
  border: 1px solid var(--line);
  background: rgba(8, 18, 32, 0.72);
  color: inherit;
  text-decoration: none;
}

.quick-card small {
  color: var(--muted);
}

.account {
  margin-top: auto;
  padding-top: 16px;
}

#account-role {
  margin: 18px 0 0;
}

.account p {
  margin: 0 0 10px;
  padding: 0 12px;
  font-family: var(--font-ui);
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.account-pfp {
  display: block;
  width: 40px;
  height: 40px;
  margin: 0 12px 10px;
  border-radius: 50%;
  object-fit: cover;
}

.login-screen {
  min-height: calc(100vh / var(--ui-zoom));
  display: grid;
  place-items: center;
  padding: 32px 20px;
}

.login-card {
  width: min(100%, 28rem);
  padding: 36px 32px 28px;
  border: 1px solid var(--line);
  background: rgba(6, 14, 26, 0.82);
  box-shadow:
    0 0 48px rgba(62, 224, 255, 0.08),
    inset 0 0 0 1px rgba(62, 224, 255, 0.06);
}

.login-card h1 {
  font-size: 48px;
}

#login-submit:disabled {
  opacity: 0.6;
  cursor: wait;
}

.account button {
  margin-left: 12px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--cyan);
  font-family: var(--font-ui);
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
}

main {
  min-width: 0;
  padding: 56px 64px;
  overflow-x: auto;
}

main > section {
  min-width: 0;
  max-width: 100%;
}

.eyebrow {
  margin: 0 0 8px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  font-family: var(--font-ui);
  font-size: 12px;
  color: var(--cyan);
}

h1 {
  margin: 0 0 12px;
  font-family: var(--font-display);
  font-size: 40px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

h2 {
  margin: 36px 0 12px;
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.tutorial {
  max-width: 42rem;
}

.tutorial h2 {
  margin-top: 32px;
}

.tutorial p,
.tutorial li {
  max-width: 40rem;
  color: var(--muted);
  line-height: 1.5;
}

.tutorial ul {
  margin: 8px 0 16px;
  padding-left: 1.2rem;
}

.tutorial li {
  margin: 6px 0;
}

.tutorial code {
  color: var(--cyan);
}

.tutorial pre {
  margin: 0 0 8px;
  padding: 14px 16px;
  overflow: auto;
  border: 1px solid var(--line);
  background: rgba(4, 12, 22, 0.85);
  color: var(--ink);
  font: 14px/1.5 var(--font-ui);
  white-space: pre-wrap;
}

.lead {
  margin: 0;
  max-width: 36rem;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.6;
}

.create-map {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 16px;
  margin-top: 28px;
  max-width: 36rem;
}

.create-map label {
  display: grid;
  gap: 6px;
  font-family: var(--font-ui);
  font-size: 13px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.create-map input,
.create-map select,
.create-map textarea,
.problem-editor select {
  width: 7rem;
  padding: 8px 10px;
  border: 1px solid var(--line);
  background: rgba(4, 12, 22, 0.85);
  color: var(--ink);
  font: inherit;
  font-size: 16px;
}

.create-map select,
.problem-editor select,
.create-map input.contest-name,
.problem-editor input.contest-name,
.create-map input.contest-time,
.problem-editor input.contest-time,
.create-map textarea {
  width: min(18rem, 100%);
}
#login-username,
#login-password {
  width: min(16rem, 100%);
}

button[type="submit"],
.delete-map,
.add-problem,
.join-contest {
  padding: 8px 14px;
  border: 1px solid var(--cyan);
  background: rgba(62, 224, 255, 0.12);
  color: var(--cyan);
  font-family: var(--font-ui);
  font-size: 14px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
}

.delete-map {
  border-color: var(--danger);
  background: rgba(255, 93, 115, 0.08);
  color: var(--danger);
}

.save-changes {
  padding: 8px 14px;
  border: 1px solid var(--cyan);
  background: rgba(62, 224, 255, 0.12);
  color: var(--cyan);
  font-family: var(--font-ui);
  font-size: 14px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
}

.save-changes:disabled {
  opacity: 0.4;
  cursor: default;
}

.join-contest {
  margin-top: 16px;
}

.problem-list .join-contest {
  margin-top: 0;
  margin-left: auto;
}

.remove-contestant,
.joined-flag {
  font-family: var(--font-ui);
  font-size: 13px;
}

.remove-contestant {
  margin-left: auto;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  text-decoration: underline;
  cursor: pointer;
}

.joined-flag {
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.form-error {
  flex-basis: 100%;
  margin: 0;
  color: var(--danger);
}

.map-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
  max-width: 40rem;
}

.map-list li {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  background: rgba(8, 18, 32, 0.72);
  box-shadow: 0 0 24px rgba(62, 224, 255, 0.04);
}

.open-map {
  display: flex;
  align-items: center;
  gap: 16px;
  flex: 1;
  min-width: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.map-label {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.map-name {
  font-size: 22px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.map-size {
  font-family: var(--font-ui);
  font-size: 13px;
  color: var(--muted);
}

.map-counts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.map-list li.map-group-label {
  display: block;
  margin-top: 18px;
  padding: 8px 4px 0;
  border: 0;
  background: transparent;
  box-shadow: none;
  font-family: var(--font-ui);
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.map-count {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 9px;
  border: 1px solid var(--line);
  background: rgba(8, 18, 32, 0.7);
  font-family: var(--font-ui);
  font-size: 12px;
  color: var(--muted);
}

.map-count strong {
  color: var(--ink);
  font-size: 14px;
}

.map-count-problem {
  border-color: rgba(62, 224, 255, 0.45);
}

.map-count-problem strong { color: var(--cyan); }

.map-count-math strong { color: #3ee0ff; }
.map-count-oi strong { color: #4d7cff; }
.map-count-science strong { color: #ff9a1a; }
.map-count-puzzle strong { color: #ff7eb6; }
.map-count-testing strong { color: #b7ff4a; }

.place-range {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.map-count-obstacle {
  border-color: rgba(255, 90, 90, 0.4);
}

.map-count-obstacle strong { color: #ff9a9a; }

.map-count-spawnpoint {
  border-color: rgba(255, 225, 74, 0.4);
}

.map-count-spawnpoint strong { color: #ffe14a; }

.map-count-empty {
  border-color: var(--line);
}
.map-name-field {
  display: grid;
  gap: 6px;
  margin-top: 16px;
  width: fit-content;
  font-family: var(--font-ui);
  font-size: 13px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.map-name-field input {
  width: min(16rem, 100%);
  padding: 8px 10px;
  border: 1px solid var(--line);
  background: rgba(4, 12, 22, 0.85);
  color: var(--ink);
  font: inherit;
  font-size: 16px;
  text-transform: none;
  letter-spacing: 0;
}

.map-preview {
  position: relative;
  display: grid;
  gap: 2px;
}

/* Territory connections and claim feedback */
.editor-grid {
  position: relative;
}

.territory-lines {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
}

.territory-line {
  position: absolute;
  border-radius: 3px;
  background: var(--team, #3ee0ff);
  box-shadow: 0 0 7px var(--team, #3ee0ff);
  opacity: 0.85;
}

.territory-line.horizontal {
  width: calc(var(--cell, 48px) + 2px);
  height: 3px;
  transform-origin: left center;
}

.territory-line.vertical {
  width: 3px;
  height: calc(var(--cell, 48px) + 2px);
  transform-origin: center top;
}

.territory-line.recent.horizontal {
  animation: territory-line-x 0.5s ease-out;
}

.territory-line.recent.vertical {
  animation: territory-line-y 0.5s ease-out;
}

@keyframes territory-line-x {
  from { transform: scaleX(0); opacity: 0; }
  to { transform: scaleX(1); opacity: 0.85; }
}

@keyframes territory-line-y {
  from { transform: scaleY(0); opacity: 0; }
  to { transform: scaleY(1); opacity: 0.85; }
}

.grid-cell.student-cell.problem.just-taken {
  animation: enemy-claim-pulse 0.9s ease-in-out 3;
}

@keyframes enemy-claim-pulse {
  0%, 100% {
    box-shadow: inset 0 0 0 3px var(--team, #ff3b4e);
    background-color: #ff3b4e;
    color: #2a060a;
  }
  45% {
    box-shadow: inset 0 0 0 4px #ff3b4e, 0 0 20px 6px rgba(255, 59, 78, 0.75);
    background-color: #ff3b4e;
    color: #2a060a;
  }
}

.grid-cell.just-claimed {
  animation: claim-cell-glow 1s ease-out 2;
}

@keyframes claim-cell-glow {
  0% { filter: brightness(1.8); }
  100% { filter: brightness(1); }
}

.grid-cell.student-cell.problem.claim-pending {
  animation: claim-pending 0.8s ease-in-out infinite;
}

@keyframes claim-pending {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.5); }
}
.editor-grid {
  display: grid;
  gap: 2px;
}

.map-preview {
  width: 112px;
  height: 112px;
  flex-shrink: 0;
  padding: 4px;
  background: rgba(4, 12, 22, 0.9);
  border: 1px solid var(--line);
}

.preview-cell,
.grid-cell,
.swatch {
  min-width: 0;
  min-height: 0;
}

.preview-cell,
.swatch {
  background: rgba(8, 18, 32, 0.95);
}

.preview-cell.problem,
.grid-cell.problem,
.swatch.problem {
  color: #1a0610;
  box-shadow: inset 0 0 12px rgba(255, 255, 255, 0.25);
}

.preview-cell.problem.math,
.grid-cell.problem.math,
.swatch.problem.math {
  background: #3ee0ff;
}

.preview-cell.problem.oi,
.grid-cell.problem.oi,
.swatch.problem.oi {
  background: #4d7cff;
}

.preview-cell.problem.science,
.grid-cell.problem.science,
.swatch.problem.science {
  background: #ff9a1a;
}

.preview-cell.problem.puzzle,
.grid-cell.problem.puzzle,
.swatch.problem.puzzle {
  background: #ff7eb6;
}

.preview-cell.problem.testing,
.grid-cell.problem.testing,
.swatch.problem.testing {
  background: #b7ff4a;
}

.preview-cell.problem.easy { box-shadow: inset 0 0 0 2px #3ddc6a; }
.preview-cell.problem.normal { box-shadow: inset 0 0 0 2px #ffe14a; }
.preview-cell.problem.hard { box-shadow: inset 0 0 0 2px #ff3b4e; }
.preview-cell.problem.insane { box-shadow: inset 0 0 0 2px #c084fc; }

.grid-cell.problem.easy { box-shadow: inset 0 0 0 3px #3ddc6a, inset 0 0 0 6px #060910; }
.grid-cell.problem.normal { box-shadow: inset 0 0 0 3px #ffe14a, inset 0 0 0 6px #060910; }
.grid-cell.problem.hard { box-shadow: inset 0 0 0 3px #ff3b4e, inset 0 0 0 6px #060910; }
.grid-cell.problem.insane { box-shadow: inset 0 0 0 3px #c084fc, inset 0 0 0 6px #060910; }

.swatch.difficulty {
  background: #121820;
  box-shadow: inset 0 0 0 3px var(--diff, #3ddc6a);
}

.swatch.difficulty.easy { --diff: #3ddc6a; }
.swatch.difficulty.normal { --diff: #ffe14a; }
.swatch.difficulty.hard { --diff: #ff3b4e; }
.swatch.difficulty.insane { --diff: #c084fc; }

.swatch.fill.easy { background: #3ddc6a; box-shadow: none; }
.swatch.fill.normal { background: #ffe14a; box-shadow: none; }
.swatch.fill.hard { background: #ff3b4e; box-shadow: none; }
.swatch.fill.insane { background: #c084fc; box-shadow: none; }

.swatch.solved-sample {
  position: relative;
  background: #ffe14a;
  box-shadow: inset 0 0 0 2px #ff9a1a;
  color: #1a1400;
}

.swatch.solved-sample::after,
.grid-cell.student-cell.problem.taken::after {
  content: "";
  position: absolute;
  background:
    linear-gradient(currentColor, currentColor) center / 100% 3px no-repeat,
    linear-gradient(currentColor, currentColor) center / 3px 100% no-repeat;
  transform: rotate(45deg);
  pointer-events: none;
}

.swatch.solved-sample::after {
  inset: 3px;
}

.swatch.owned-sample {
  background: #101820;
  box-shadow: inset 0 0 0 3px #3ee0ff;
}

.preview-cell.spawnpoint,
.grid-cell.spawnpoint,
.swatch.spawnpoint {
  background: #121820;
  color: #f4feff;
  box-shadow: inset 0 0 0 2px #f4feff;
}

.grid-cell.spawnpoint {
  font-size: 20px;
  letter-spacing: 0;
}

.preview-cell.teleport,
.grid-cell.teleport,
.swatch.teleport {
  background:
    radial-gradient(circle at 50% 50%, rgba(244, 254, 255, 0.95) 0 16%, transparent 17%),
    #101820;
  color: #f4feff;
  box-shadow: inset 0 0 0 2px #f4feff;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0;
}

.contest-map-block {
  margin-top: 18px;
}

.contest-map-block h3 {
  margin: 0 0 8px;
  font-size: 18px;
}

.contest-map-list,
.teleport-pairs {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.contest-map-list li,
.teleport-pairs li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.preview-cell.obstacle,
.grid-cell.obstacle,
.swatch.obstacle {
  background-color: #121820;
  background-image: repeating-linear-gradient(
    -45deg,
    transparent,
    transparent 3px,
    rgba(180, 198, 214, 0.7) 3px,
    rgba(180, 198, 214, 0.7) 5px
  );
  box-shadow: inset 0 0 0 1px rgba(180, 198, 214, 0.8);
  color: #d5e2ec;
}

.preview-cell.empty,
.swatch.empty {
  background: rgba(8, 18, 32, 0.95);
  box-shadow: inset 0 0 0 1px rgba(62, 224, 255, 0.28);
}

.preview-cell {
  display: grid;
  place-items: center;
  overflow: hidden;
  font-family: var(--font-ui);
  font-size: 7px;
  line-height: 1;
}

.editor-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

#save-problem-button,
#save-map-button {
  justify-self: start;
  width: auto;
  margin-top: 20px;
}

.back-button {
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin: 20px 0 0;
  padding: 0;
  list-style: none;
  font-family: var(--font-ui);
  font-size: 14px;
}

.legend li {
  display: flex;
  align-items: center;
  gap: 8px;
}

.swatch {
  width: 16px;
  height: 16px;
}

.grid-scroll {
  margin-top: 28px;
  overflow: visible;
}

.editor-grid {
  width: max-content;
  grid-auto-flow: row;
  user-select: none;
}

.grid-cell {
  position: relative;
  width: var(--cell, 48px);
  height: var(--cell, 48px);
  padding: 0 2px;
  border: 0;
  background: rgba(6, 14, 26, 0.95);
  box-shadow: inset 0 0 0 1px rgba(62, 224, 255, 0.28);
  color: var(--cyan);
  font-family: var(--font-ui);
  font-size: 13px;
  line-height: 1;
  cursor: crosshair;
  touch-action: manipulation;
}

#editor-grid .grid-cell {
  touch-action: none;
}

@media (pointer: coarse) {
  #editor-grid .grid-cell,
  #student-grid .grid-cell,
  #contest-grid .grid-cell {
    touch-action: pan-x pan-y;
  }
}

.grid-cell.student-cell.territory-dot {
  display: grid;
  place-items: center;
}

.grid-cell.student-cell.territory-dot::after {
  content: "";
  width: 14px;
  height: 14px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--team, #3ee0ff);
  box-shadow: 0 0 10px #fff;
}

.answer-page {
  max-width: 40rem;
  margin: 0 auto;
  padding: 24px 16px 48px;
}

.answer-page form {
  display: grid;
  gap: 10px;
  margin-top: 20px;
}

.answer-page label {
  display: grid;
  gap: 6px;
  font-family: var(--font-ui);
  font-size: 13px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.answer-page input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  background: rgba(4, 12, 22, 0.85);
  color: var(--ink);
  font: inherit;
  font-size: 16px;
}

.cell-owner {
  position: absolute;
  right: 2px;
  bottom: 2px;
  padding: 1px 2px;
  background: #060910;
  font-size: 10px;
  letter-spacing: 0;
  line-height: 1;
}

.grid-cell.problem {
  font-size: 14px;
  letter-spacing: 0;
  white-space: nowrap;
}

.cell-label,
.cell-label span {
  font-size: 14px;
  line-height: 1.05;
}

.cell-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
  width: 100%;
  max-width: 100%;
  font-weight: 700;
  pointer-events: none;
}

.cell-label span {
  display: block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.grid-cell.student-cell:disabled {
  opacity: 1;
}

.grid-cell.student-cell.problem,
.grid-cell.student-cell.spawnpoint:not(:disabled) {
  cursor: pointer;
}

.grid-cell.student-cell.spawnpoint {
  background: #121820;
  color: #f4feff;
  box-shadow: inset 0 0 0 2px #f4feff;
}

.grid-cell.student-cell.problem.easy {
  background: #3ddc6a;
  color: #06210f;
  box-shadow: none;
}

.grid-cell.student-cell.problem.normal {
  background: #ffe14a;
  color: #1a1400;
  box-shadow: none;
}

.grid-cell.student-cell.problem.hard {
  background: #ff3b4e;
  color: #2a060a;
  box-shadow: none;
}

.grid-cell.student-cell.problem.insane {
  background: #c084fc;
  color: #1a0624;
  box-shadow: none;
}

.grid-cell.student-cell.problem.taken {
  color: var(--team, #f4feff);
  box-shadow:
    inset 0 0 0 3px var(--team, #f4feff),
    inset 0 0 0 5px #060910;
}

.grid-cell.student-cell.problem.taken::after {
  inset: 7px 6px 15px;
  filter: drop-shadow(0 0 1px #060910) drop-shadow(0 0 1px #060910);
}

.grid-cell.student-cell.taken .cell-owner {
  left: 1px;
  right: 1px;
  bottom: 1px;
  padding: 1px 0;
  background: rgba(6, 9, 16, 0.88);
  color: var(--team, #f4feff);
  font-size: 9px;
  font-weight: 700;
  text-align: center;
}

.grid-cell.student-cell.problem.owned,
.grid-cell.student-cell.spawnpoint.owned {
  background: color-mix(in srgb, var(--team, #3ee0ff) 78%, #ffffff);
  color: #041018;
  box-shadow:
    inset 0 0 0 4px #ffffff,
    0 0 16px var(--team, #3ee0ff);
  font-size: 13px;
}

.grid-cell.student-cell.mine {
  outline: 3px solid #ffffff;
  outline-offset: -3px;
  z-index: 1;
}

.grid-cell.student-cell.proposed {
  box-shadow: inset 0 0 0 3px var(--team, #3ee0ff);
}

.countdown {
  margin: 0 0 12px;
  font-family: var(--font-display);
  font-size: 28px;
  letter-spacing: 0.06em;
  color: var(--cyan);
}

.spawn-agreement {
  max-width: 36rem;
  margin: 16px 0;
}

.spawn-agreement h2 {
  margin-top: 0;
}

.spawn-agreement ul {
  margin: 8px 0;
  padding-left: 1.2rem;
}

#contest-grid .grid-cell:disabled {
  opacity: 1;
  cursor: default;
}

/* Team and spawn tables */
.team-member-table,
.team-table {
  width: 100%;
  max-width: 46rem;
  border-collapse: collapse;
  font-family: var(--font-ui);
  font-size: 14px;
}

.team-member-table th,
.team-member-table td,
.team-table th,
.team-table td {
  padding: 8px 10px;
  border: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.team-member-table th,
.team-table th {
  background: rgba(62, 224, 255, 0.08);
  color: var(--cyan);
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.team-member-table .member-status {
  width: 5rem;
  text-align: center;
}

.vote-yes {
  color: #3ddc6a;
  font-size: 18px;
}

.vote-no {
  color: #ffe14a;
  font-size: 18px;
}

.team-color-dot {
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-right: 8px;
  border-radius: 50%;
  background: var(--team, #3ee0ff);
  box-shadow: 0 0 8px var(--team, #3ee0ff);
  vertical-align: middle;
}

.team-members-cell {
  white-space: normal;
}

.team-member-chip {
  display: inline-block;
  margin: 2px 4px 2px 0;
  padding: 2px 7px;
  border: 1px solid var(--line);
  background: rgba(62, 224, 255, 0.06);
}

.team-roster {
  margin: 24px 0;
}

.page-toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 90;
  display: flex;
  align-items: center;
  gap: 16px;
  max-width: min(36rem, calc(100vw - 40px));
  padding: 14px 16px;
  border: 1px solid var(--line);
  background: rgba(8, 18, 32, 0.98);
  box-shadow: 0 0 30px rgba(62, 224, 255, 0.18);
}

.page-toast[data-tone="ok"] {
  border-color: #3ddc6a;
}

.page-toast[data-tone="warn"] {
  border-color: #ff9a1a;
}

.page-toast p {
  margin: 0;
  font-family: var(--font-ui);
  line-height: 1.45;
}

.page-toast[data-tone="ok"] p { color: #3ddc6a; }
.page-toast[data-tone="warn"] p { color: #ffe14a; }

.page-toast button {
  margin-left: auto;
  padding: 6px 10px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  font-family: var(--font-ui);
  cursor: pointer;
}
.leaderboard {
  margin: 12px 0 0;
  padding-left: 0;
  list-style: none;
  border: 1px solid var(--line);
  background: rgba(8, 18, 32, 0.72);
  overflow-x: auto;
  font-family: var(--font-ui);
  font-size: 15px;
}

.student-problem form {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.student-problem label {
  display: grid;
  gap: 6px;
  font-family: var(--font-ui);
  font-size: 13px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.student-problem input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  background: rgba(4, 12, 22, 0.85);
  color: var(--ink);
  font: inherit;
  font-size: 16px;
  letter-spacing: 0;
  text-transform: none;
}

.contest-schedule {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 16px;
  margin: 0;
  padding: 0;
  border: 0;
}

.create-map .contest-schedule {
  flex-basis: 100%;
}

#create-contest-form {
  max-width: 52rem;
}

#create-contest-form > .create-line,
#create-contest-form > .field-note,
#create-contest-form .schedule-line,
#create-contest-form #create-spawn-note {
  flex-basis: 100%;
}

#create-contest-form #contest-name {
  width: min(28rem, 100%);
}

#create-contest-form #contest-start {
  width: min(18rem, 100%);
}

#create-contest-form #create-spawn-mode {
  margin: 0;
}

#create-contest-form .schedule-times {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 16px;
  flex-basis: 100%;
}

#contest-energy .field-note {
  flex-basis: 100%;
  margin: 0;
}

.export-actions {
  display: flex;
  gap: 12px;
  margin: 16px 0;
}

.export-text {
  width: min(52rem, 100%);
  min-height: 24rem;
  padding: 14px 16px;
  border: 1px solid var(--line);
  background: rgba(4, 12, 22, 0.85);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.5;
  letter-spacing: 0;
  text-transform: none;
  white-space: pre-wrap;
  resize: vertical;
}

.energy-readout {
  margin: 8px 0 6px;
  font-family: var(--font-ui);
  font-size: 14px;
}

.energy-track {
  width: min(18rem, 100%);
  height: 10px;
  margin: 0 0 16px;
  background: #121820;
  border: 1px solid var(--line);
}

.energy-fill {
  height: 100%;
  width: 0%;
  background: #3ee0ff;
}

.energy-fill.low {
  background: #ff3b4e;
}

.contest-schedule legend {
  flex-basis: 100%;
  padding: 0;
  font-family: var(--font-display);
  font-size: 12px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--cyan);
}

.grid-cell.student-cell[aria-pressed="true"] {
  outline: 2px solid var(--cyan);
  outline-offset: -4px;
  box-shadow: 0 0 12px rgba(62, 224, 255, 0.7), inset 0 0 0 1px var(--cyan);
}

.student-board {
  display: grid;
  gap: 28px;
  margin-top: 28px;
}

.student-problem {
  position: fixed;
  z-index: 50;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.62);
}

.student-problem-card {
  width: min(100%, 40rem);
  max-height: min(90dvh, 800px);
  overflow: auto;
  padding: 20px 22px;
  border: 1px solid var(--line);
  background: rgba(8, 18, 32, 0.96);
  box-shadow: 0 0 48px rgba(62, 224, 255, 0.12);
}

.student-problem-close {
  position: sticky;
  top: 0;
  float: right;
  z-index: 6;
  margin: 0 0 8px 12px;
  padding: 4px 8px;
  border: 1px solid var(--line);
  background: rgba(8, 18, 32, 0.96);
  color: var(--cyan);
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
}

.student-problem h2 {
  margin: 0 0 12px;
  font-size: 28px;
}

#student-problem-prompt {
  margin: 0;
  font-size: 16px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-x: auto;
}

.isolated-statement {
  display: block;
}

.statement-frame {
  display: block;
  width: 100%;
  min-height: 60px;
  border: 0;
  background: #081220;
}
#student-problem-prompt.rich-html,
.problem-preview-content.rich-html {
  white-space: normal;
}

.kind-choices {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 20px 0 0;
}

.problem-editor .kind-choices,
.problem-types {
  margin: 0;
}

.problem-options {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px 24px;
  margin-top: 16px;
}

#editor-view:not([data-map-mode="testing"]) [data-place-type="testing"],
#editor-view:not([data-map-mode="testing"]) [data-pick-type="testing"] {
  display: none !important;
}

#place-manual,
#place-pick {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px 24px;
  flex-basis: 100%;
}

.place-types {
  margin: 0;
}

.next-number {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-ui);
  font-size: 13px;
  color: var(--muted);
}

.kind-choices button {
  padding: 8px 12px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 14px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
}

.kind-choices button[aria-pressed="true"] {
  background: var(--cyan);
  border-color: var(--cyan);
  color: #041018;
}

#problem-no-field {
  display: grid;
  gap: 6px;
  width: fit-content;
  font-family: var(--font-ui);
  font-size: 13px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

#problem-no {
  width: 7rem;
  padding: 8px 10px;
  border: 1px solid var(--line);
  background: rgba(4, 12, 22, 0.85);
  color: var(--ink);
  font: inherit;
  font-size: 16px;
  letter-spacing: 0;
  text-transform: none;
}

.add-problem {
  margin-top: 24px;
}

.problem-section {
  margin-top: 28px;
  max-width: 52rem;
}

.problem-group-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

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

#problem-select-toggle {
  padding: 8px 14px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 14px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
}

#problem-select-toggle[aria-pressed="true"] {
  background: var(--cyan);
  border-color: var(--cyan);
  color: #041018;
}

.problem-section h2 {
  margin: 0;
  font-size: 34px;
}

.problem-section .add-problem {
  margin-top: 0;
}

.problem-tag {
  margin-left: 8px;
  font-family: var(--font-ui);
  font-size: 13px;
  letter-spacing: 0.08em;
  color: var(--cyan);
}

.problem-group-empty {
  margin: 12px 0 0;
}

.problem-list {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
  display: grid;
  gap: 8px;
  width: 100%;
  min-width: 0;
  max-width: 100%;
}

.problem-list li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 16px;
  min-width: 0;
  max-width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  background: rgba(8, 18, 32, 0.72);
  overflow: hidden;
}

.problem-pages {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  margin: 16px 0 12px;
}

.problem-bulk {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 16px;
  margin-top: 16px;
}

.problem-bulk .kind-choices,
.problem-bulk .field-note,
.problem-bulk .delete-map {
  margin: 0;
}

.problem-bulk button:disabled {
  opacity: 0.4;
  cursor: default;
}

.problem-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-ui);
  font-size: 14px;
  letter-spacing: 0.04em;
  cursor: pointer;
}

.problem-list .problem-check {
  flex: 0 0 auto;
}

.open-problem {
  display: flex;
  align-items: center;
  gap: 32px;
  flex: 1 1 auto;
  min-width: 0;
  max-width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  overflow: hidden;
}

.problem-index {
  min-width: 4.5ch;
  font-size: 22px;
  white-space: nowrap;
}

.contest-name-label {
  flex: 0 1 auto;
  min-width: 0;
  max-width: 40%;
  font-size: 22px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.problem-snippet {
  flex: 1 1 0;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.problem-editor {
  display: grid;
  gap: 12px;
  max-width: 40rem;
  margin-top: 8px;
}

.problem-editor label {
  display: grid;
  gap: 6px;
  font-family: var(--font-ui);
  font-size: 13px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.problem-editor input,
.problem-editor textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  background: rgba(4, 12, 22, 0.85);
  color: var(--ink);
  font: inherit;
  font-size: 16px;
  letter-spacing: 0;
  text-transform: none;
}

.problem-editor input {
  width: 7rem;
  font-size: 18px;
}

.problem-editor textarea {
  resize: vertical;
}

#team-member-pick {
  width: min(28rem, 100%);
  letter-spacing: 0;
  text-transform: none;
}

#problem-prompt {
  min-height: 16rem;
}

#problem-solution {
  min-height: 10rem;
}

#problem-logic {
  min-height: 12rem;
  font-family: var(--font-ui);
}

.problem-preview-box {
  display: grid;
  gap: 16px;
  padding: 16px 18px;
  border: 1px solid var(--line);
  background: rgba(8, 18, 32, 0.72);
}

.version-list {
  list-style: none;
  margin: 28px 0 0;
  padding: 0;
  display: grid;
  gap: 12px;
  max-width: 40rem;
}

.version-list li {
  display: grid;
  gap: 8px;
  justify-items: start;
  padding: 14px 16px;
  border: 1px solid var(--line);
  background: rgba(8, 18, 32, 0.72);
}

.version-name {
  margin: 0;
  font-family: var(--font-display);
  font-size: 16px;
  letter-spacing: 0.06em;
  color: var(--cyan);
}

.version-message {
  margin: 0;
  white-space: pre-wrap;
  line-height: 1.5;
}

.version-time {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.problem-preview-title {
  margin-bottom: 8px;
  font-family: var(--font-ui);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.problem-preview-content {
  font-size: 16px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-x: auto;
}

.problem-test-box {
  display: grid;
  gap: 12px;
  margin-top: 18px;
  padding: 16px 18px;
  border: 1px solid var(--line);
  background: rgba(8, 18, 32, 0.72);
}

.problem-test-box h3 {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 14px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--cyan);
}

.problem-test-answer-field {
  display: grid;
  gap: 6px;
  font-family: var(--font-ui);
  font-size: 13px;
  color: var(--muted);
}

.problem-test-answer-field textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  background: rgba(4, 12, 22, 0.85);
  color: var(--ink);
  font: inherit;
  font-size: 15px;
  resize: vertical;
}

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

#problem-test-run {
  padding: 8px 14px;
  border: 1px solid var(--cyan);
  background: transparent;
  color: var(--cyan);
  font-family: var(--font-ui);
  font-weight: 700;
  cursor: pointer;
}

#problem-test-run:disabled {
  opacity: 0.55;
  cursor: wait;
}

.problem-test-result {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  background: rgba(4, 12, 22, 0.8);
}

.problem-test-badge {
  flex: 0 0 auto;
  min-width: 4.5rem;
  padding: 4px 8px;
  border: 1px solid currentColor;
  font-family: var(--font-ui);
  font-size: 13px;
  letter-spacing: 0.08em;
  text-align: center;
  text-transform: uppercase;
}

.problem-test-detail {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
  color: var(--muted);
  white-space: pre-wrap;
}

.problem-test-result[data-result="AC"] {
  border-color: #3ddc6a;
  color: #3ddc6a;
}

.problem-test-result[data-result="AC"] .problem-test-detail {
  color: #b9f5c9;
}

.problem-test-result[data-result="WA"] {
  border-color: #ff9a1a;
  color: #ffb347;
}

.problem-test-result[data-result="WA"] .problem-test-detail {
  color: #ffd39b;
}

.problem-test-result[data-result="ERROR"] {
  border-color: #ff5a5a;
  color: #ff7b7b;
}

.problem-test-result[data-result="ERROR"] .problem-test-detail {
  color: #ffb3b3;
}

.problem-test-result[data-result="RUNNING"] {
  color: var(--muted);
}
.katex {
  color: inherit;
  font-size: 1.05em;
}

.problem-snippet .katex {
  font-size: 1em;
}

.field-note {
  margin: 0;
  max-width: 36rem;
  font-family: var(--font-ui);
  font-size: 13px;
  line-height: 1.5;
  color: var(--muted);
}

.menu-button {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--cyan);
  font-family: var(--font-ui);
  font-size: 14px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
}

.menu-bars,
.menu-bars::before,
.menu-bars::after {
  display: block;
  width: 18px;
  height: 2px;
  background: currentColor;
}

.menu-bars {
  position: relative;
}

.menu-bars::before,
.menu-bars::after {
  content: "";
  position: absolute;
  left: 0;
}

.menu-bars::before {
  top: -6px;
}

.menu-bars::after {
  top: 6px;
}

/* ── Problem management ─────────────────────────────────────────── */

#problem-section-choices button[data-count]::after {
  content: attr(data-count);
  margin-left: 8px;
  padding: 1px 5px;
  border: 1px solid rgba(62, 224, 255, 0.28);
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0;
}

.problem-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 12px 20px;
  margin: 20px 0 4px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  background: rgba(8, 18, 32, 0.55);
}

.problem-search,
.problem-sort {
  display: grid;
  gap: 6px;
  font-family: var(--font-ui);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.problem-search input {
  width: min(22rem, 60vw);
  padding: 8px 10px;
  border: 1px solid var(--line);
  background: rgba(4, 12, 22, 0.85);
  color: var(--ink);
  font: inherit;
  font-size: 15px;
  letter-spacing: 0;
  text-transform: none;
}

.problem-sort select {
  padding: 8px 10px;
  border: 1px solid var(--line);
  background: rgba(4, 12, 22, 0.85);
  color: var(--ink);
  font: inherit;
  font-size: 15px;
  letter-spacing: 0;
  text-transform: none;
}

.problem-toolbar .kind-choices {
  margin: 0;
}

#problem-count {
  min-width: 12rem;
  margin: 0;
  text-align: left;
}

.problem-list li.problem-row {
  flex-direction: column;
  align-items: stretch;
  flex-wrap: nowrap;
  width: 100%;
  min-width: 32rem;
}

.problem-row-main {
  display: flex;
  align-items: center;
  gap: 12px 16px;
  min-width: 0;
  width: 100%;
}

.problem-row {
  align-items: center;
}

.problem-row .open-problem {
  gap: 14px;
}

.problem-key {
  flex: 0 0 auto;
  min-width: 4.5ch;
  font-family: var(--font-ui);
  font-size: 19px;
  font-weight: 700;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.problem-key.math { color: #3ee0ff; }
.problem-key.oi { color: #7d9dff; }
.problem-key.science { color: #ff9a1a; }
.problem-key.puzzle { color: #ff7eb6; }
.problem-key.testing { color: #b7ff4a; }

.difficulty-chip {
  flex: 0 0 auto;
  padding: 2px 7px;
  border: 1px solid currentColor;
  font-family: var(--font-ui);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
}

.difficulty-chip.easy { color: #3ddc6a; }
.difficulty-chip.normal { color: #ffe14a; }
.difficulty-chip.hard { color: #ff3b4e; }
.difficulty-chip.insane { color: #c084fc; }

.problem-usage-chip {
  align-self: flex-start;
  flex: 0 0 auto;
  margin: 6px 0 0;
  color: var(--muted);
  font-family: var(--font-ui);
  font-size: 12px;
  white-space: nowrap;
}

.problem-usage-chip.unused {
  opacity: 0.55;
}

.problem-row-second {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-width: 0;
}

.problem-row-second .problem-usage-chip {
  margin: 0;
}

.problem-row-actions {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: nowrap;
  gap: 8px;
  margin-left: auto;
}

.problem-row.selecting {
  cursor: pointer;
}

.problem-row.selecting .open-problem {
  cursor: pointer;
}

.problem-pages {
  align-items: center;
}

.problem-pages button:disabled {
  opacity: 0.35;
  cursor: default;
}

.problem-pages .page-gap {
  padding: 0 2px;
  color: var(--muted);
  font-family: var(--font-ui);
}

.problem-save-state {
  font-family: var(--font-ui);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.problem-save-state[data-state="dirty"] {
  color: #ffe14a;
}

.problem-save-state[data-state="saved"] {
  color: #3ddc6a;
}

.problem-save-state[data-state="new"] {
  color: var(--cyan);
}

.editor-toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

#problem-usage {
  margin: 0 0 12px;
}

/* Batch problem editor */
.batch-rows {
  display: grid;
  gap: 14px;
  max-width: 56rem;
  margin: 18px 0;
}

.batch-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 12px 16px;
  padding: 14px;
  border: 1px solid var(--line);
  background: rgba(8, 18, 32, 0.72);
}

.batch-row label {
  display: grid;
  gap: 5px;
  font-family: var(--font-ui);
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.batch-row .batch-index-field input {
  width: 7rem;
}

.batch-row .batch-wide {
  flex: 1 1 100%;
}

.batch-row input,
.batch-row textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  background: rgba(4, 12, 22, 0.85);
  color: var(--ink);
  font: inherit;
  font-size: 15px;
  letter-spacing: 0;
  text-transform: none;
  resize: vertical;
}

.batch-row textarea[data-batch-logic] {
  font-family: var(--font-ui);
}

.batch-row .account-action {
  margin-left: 0;
}
/* ── Account management ─────────────────────────────────────────── */

.account-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(8rem, 1fr));
  gap: 12px;
  max-width: 40rem;
  margin: 28px 0 4px;
}

.account-stat {
  display: grid;
  gap: 2px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  background: rgba(8, 18, 32, 0.72);
}

.account-stat strong {
  font-family: var(--font-display);
  font-size: 24px;
  color: var(--cyan);
}

.account-stat span {
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.account-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 12px 24px;
  max-width: 52rem;
  margin: 0 0 16px;
}

.account-search {
  display: grid;
  gap: 6px;
  font-family: var(--font-ui);
  font-size: 13px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.account-search input {
  width: min(20rem, 100%);
  padding: 8px 10px;
  border: 1px solid var(--line);
  background: rgba(4, 12, 22, 0.85);
  color: var(--ink);
  font: inherit;
  font-size: 16px;
  letter-spacing: 0;
  text-transform: none;
}

.account-filters {
  margin: 0;
}

.status-note {
  margin: 0 0 12px;
  max-width: 52rem;
  color: #3ddc6a;
  font-family: var(--font-ui);
  font-size: 14px;
}

.account-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 14px;
  max-width: 52rem;
}

.account-card {
  display: grid;
  gap: 10px;
  padding: 16px 18px;
  border: 1px solid var(--line);
  background: rgba(8, 18, 32, 0.72);
  box-shadow: 0 0 24px rgba(62, 224, 255, 0.04);
}

.account-card.suspended {
  border-color: rgba(255, 93, 115, 0.55);
  background: rgba(30, 10, 18, 0.55);
}

.account-card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.account-card-name {
  font-size: 22px;
  overflow-wrap: anywhere;
}

.account-badge {
  padding: 2px 8px;
  border: 1px solid var(--line);
  font-family: var(--font-ui);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.account-badge.role-admin {
  border-color: #ff9a1a;
  color: #ff9a1a;
}

.account-badge.role-student {
  border-color: var(--cyan);
  color: var(--cyan);
}

.account-badge.status-banned {
  border-color: var(--danger);
  color: var(--danger);
}

.account-card-meta,
.account-card-teams,
.account-protected {
  margin: 0;
  color: var(--muted);
  font-family: var(--font-ui);
  font-size: 13px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.account-card-teams {
  color: var(--ink);
}

.team-chip {
  display: inline-block;
  padding: 1px 6px;
  margin: 2px 0;
  border: 1px solid rgba(62, 224, 255, 0.3);
  background: rgba(62, 224, 255, 0.06);
  color: var(--cyan);
  font-size: 12px;
}

.account-protected {
  color: #ff9a1a;
}

.account-fields {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 10px 16px;
}

.account-field {
  display: grid;
  gap: 5px;
  font-family: var(--font-ui);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.account-field input {
  width: min(15rem, 100%);
  padding: 7px 9px;
  border: 1px solid var(--line);
  background: rgba(4, 12, 22, 0.85);
  color: var(--ink);
  font: inherit;
  font-size: 15px;
  letter-spacing: 0;
  text-transform: none;
}

.account-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.account-action {
  padding: 7px 12px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 13px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
}

.account-action:hover {
  border-color: var(--cyan);
  color: var(--cyan);
}

.account-action.danger {
  border-color: var(--danger);
  color: var(--danger);
}

.account-action:disabled {
  opacity: 0.45;
  cursor: default;
}

/* ── Contest teams ──────────────────────────────────────────────── */

.team-form-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
}

.team-list .team-detail {
  flex: 1 1 18rem;
  min-width: 0;
  color: var(--muted);
  font-family: var(--font-ui);
  font-size: 13px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.team-list li.editing {
  border-color: var(--cyan);
  box-shadow: inset 3px 0 0 var(--cyan);
}

.leaderboard-row {
  display: grid;
  grid-template-columns: 4rem minmax(10rem, 1fr) 7rem 7rem 8rem;
  align-items: stretch;
  min-width: 38rem;
  border-bottom: 1px solid rgba(62, 224, 255, 0.22);
}

.leaderboard-row:last-child {
  border-bottom: 0;
}

.leaderboard-row > span {
  padding: 10px 12px;
}

.leaderboard-head {
  background: rgba(62, 224, 255, 0.1);
  color: var(--cyan);
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.leaderboard-rank {
  color: var(--muted);
  text-align: left;
}

.leaderboard-team {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: left;
}

.leaderboard-stat {
  color: var(--muted);
  font-size: 14px;
  text-align: center;
  white-space: nowrap;
}

.leaderboard-head .leaderboard-stat,
.leaderboard-head .leaderboard-rank {
  color: var(--cyan);
  font-size: 12px;
}

@media (max-width: 1100px) {
  .account-field input,
  .account-search input,
  .problem-search input {
    width: 100%;
  }

  .problem-toolbar {
    align-items: stretch;
  }

  #problem-count {
    margin-left: 0;
    text-align: left;
  }

  .problem-row-actions {
    width: auto;
    margin-left: auto;
  }

  .problem-row .open-problem {
    flex: 1 1 auto;
    flex-basis: auto;
    min-width: 0;
  }


  .app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
  }

  .mobile-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    grid-column: 1;
    grid-row: 1;
    position: sticky;
    top: 0;
    z-index: 40;
    min-height: 44px;
    padding: 0 8px;
    padding-top: env(safe-area-inset-top);
    background: rgba(4, 10, 18, 0.96);
    border-bottom: 1px solid var(--line);
  }

  .mobile-logo {
    display: block;
    width: auto;
    margin: 0;
    padding: 0;
    font-size: 16px;
  }

  .sidebar .brand {
    display: none;
  }

  .menu-button {
    margin: 6px 0 6px auto;
  }

  .sidebar {
    padding-top: calc(56px + env(safe-area-inset-top));
  }

  .sidebar,
  .sidebar-backdrop {
    position: fixed;
    margin: 0;
  }

  .sidebar {
    z-index: 30;
    top: 0;
    left: 0;
    left: -105%;
    width: min(280px, 86vw);
    height: calc(100vh / var(--ui-zoom));
    height: calc(100dvh / var(--ui-zoom));
    transition: left 0.2s ease;
    overflow: auto;
  }

  body.menu-open .sidebar {
    left: 0;
  }

  body.menu-open .sidebar-backdrop {
    display: block;
  }

  .sidebar-backdrop {
    position: fixed;
    z-index: 25;
    inset: 0;
    border: 0;
    background: rgba(0, 0, 0, 0.55);
    cursor: pointer;
  }

  main {
    grid-column: 1;
    grid-row: 2;
    padding: 12px 16px 40px;
    padding-bottom: max(40px, env(safe-area-inset-bottom));
  }

  h1 {
    font-size: 28px;
  }

  .login-card {
    padding: 28px 18px 22px;
  }

  .login-card h1 {
    font-size: 36px;
  }

  .create-map {
    max-width: none;
  }

  .problem-section h2,
  .map-name,
  .contest-name-label,
  .problem-index {
    font-size: 18px;
  }

  .student-problem,
  .problem-preview-box,
  .student-problem-card {
    padding: 16px;
  }

  .editor-tools {
    position: sticky;
    top: calc(44px + env(safe-area-inset-top));
    z-index: 4;
    margin-top: 12px;
    padding: 8px 0;
    background: rgba(6, 9, 16, 0.94);
  }
}
/* ── Save conflict resolver ───────────────────────────────────────── */
.conflict-modal {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(2, 7, 14, 0.82);
  backdrop-filter: blur(4px);
}

.conflict-modal[hidden] {
  display: none;
}

.conflict-dialog {
  display: flex;
  flex-direction: column;
  width: min(1100px, 100%);
  max-height: 92vh;
  border: 1px solid var(--line);
  background: #07111f;
  box-shadow: 0 20px 80px rgba(0, 0, 0, 0.6);
}

.conflict-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}

.conflict-header h2 {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 18px;
  color: var(--cyan);
}

.conflict-close {
  padding: 2px 8px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}

.conflict-body {
  display: grid;
  gap: 14px;
  overflow: auto;
  padding: 18px;
}

.conflict-intro,
.conflict-empty,
.conflict-loading {
  margin: 0;
  max-width: 70ch;
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.55;
  color: var(--muted);
}

.conflict-record {
  border: 1px solid var(--line);
  background: rgba(8, 18, 32, 0.78);
}

.conflict-record-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}

.conflict-record-head h3 {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 15px;
  color: var(--ink);
}

.conflict-badge {
  flex: 0 0 auto;
  padding: 3px 7px;
  border: 1px solid currentColor;
  font-family: var(--font-ui);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.conflict-badge-added { color: #3ddc6a; }
.conflict-badge-deleted { color: #ff7b7b; }
.conflict-badge-changed { color: #ffb347; }

.conflict-record-summary {
  margin: 0;
  padding: 10px 12px;
  font-family: var(--font-ui);
  font-size: 13px;
  line-height: 1.5;
  color: var(--muted);
}

.conflict-choices {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  padding: 0 12px 12px;
}

.conflict-choice {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-ui);
  font-size: 13px;
  color: var(--ink);
  cursor: pointer;
}

.conflict-record-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}

.conflict-field {
  padding: 12px;
  border-top: 1px solid rgba(62, 224, 255, 0.14);
}

.conflict-field-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.conflict-field-head h4 {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 13px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--cyan);
}

.conflict-field-head .conflict-choices {
  padding: 0;
}

.conflict-field-meta {
  margin: 0 0 8px;
  font-family: var(--font-ui);
  font-size: 12px;
  color: var(--muted);
}

.conflict-diff {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
}

.conflict-value {
  min-width: 0;
  border: 1px solid var(--line);
}

.conflict-value-title {
  display: block;
  padding: 5px 8px;
  border-bottom: 1px solid var(--line);
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 700;
}

.conflict-value pre {
  max-height: 14rem;
  margin: 0;
  padding: 8px;
  overflow: auto;
  font-family: var(--font-ui);
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.conflict-value-server {
  border-color: rgba(255, 90, 90, 0.45);
  background: rgba(255, 70, 70, 0.06);
}

.conflict-value-server .conflict-value-title {
  color: #ff9a9a;
  background: rgba(255, 70, 70, 0.12);
}

.conflict-value-local {
  border-color: rgba(61, 220, 106, 0.45);
  background: rgba(61, 220, 106, 0.06);
}

.conflict-value-local .conflict-value-title {
  color: #7cf29b;
  background: rgba(61, 220, 106, 0.1);
}

.conflict-footer {
  padding: 12px 18px;
  border-top: 1px solid var(--line);
  background: #07111f;
}

.conflict-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 8px;
}

.conflict-footer button {
  padding: 8px 12px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  font-family: var(--font-ui);
  cursor: pointer;
}

.conflict-footer button:disabled {
  opacity: 0.5;
  cursor: wait;
}

.conflict-footer .save-changes {
  border-color: var(--cyan);
  color: var(--cyan);
}

@media (max-width: 720px) {
  .conflict-modal {
    padding: 0;
  }

  .conflict-dialog {
    max-height: 100vh;
    height: 100vh;
  }

  .conflict-diff {
    grid-template-columns: minmax(0, 1fr);
  }

  .conflict-field-head {
    align-items: flex-start;
    flex-direction: column;
  }
}
.conflict-cell-diffs {
  max-height: 10rem;
  margin: 0 0 10px;
  padding: 8px 10px;
  overflow: auto;
  border: 1px solid var(--line);
  background: rgba(4, 12, 22, 0.7);
}

.conflict-cell-diff {
  font-family: var(--font-ui);
  font-size: 12px;
  line-height: 1.7;
  color: var(--muted);
}

.conflict-cell-more {
  color: var(--cyan);
}

.map-backdrop-choices {
  margin: 0;
}

.map-photo-field {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-family: var(--font-ui);
  font-size: 13px;
}

.map-photo-field input {
  max-width: 16rem;
  color: var(--muted);
  font-family: var(--font-ui);
  font-size: 12px;
}

.grid-cell.photo-cell {
  color: #f4feff;
  text-shadow: 0 1px 2px #000;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.35);
}

.grid-cell.photo-cell.student-cell.mine::before {
  content: "";
  position: absolute;
  inset: 0;
  background: color-mix(in srgb, var(--team, #3ee0ff) 48%, transparent);
  pointer-events: none;
}

.cell-difficulty {
  position: absolute;
  right: 2px;
  bottom: 2px;
  padding: 1px 3px;
  background: rgba(6, 9, 16, 0.82);
  font-family: var(--font-ui);
  font-size: 9px;
  letter-spacing: 0;
  line-height: 1.2;
  text-shadow: none;
  pointer-events: none;
}

.cell-difficulty.easy { color: #3ddc6a; }
.cell-difficulty.normal { color: #ffe14a; }
.cell-difficulty.hard { color: #ff3b4e; }
.cell-difficulty.insane { color: #c084fc; }

.cell-tooltip {
  position: fixed;
  z-index: 40;
  max-width: 18rem;
  padding: 8px 10px;
  border: 1px solid rgba(62, 224, 255, 0.45);
  background: rgba(6, 12, 22, 0.96);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}

.cell-tooltip p {
  margin: 0;
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 13px;
  line-height: 1.45;
}

.cell-tooltip p + p {
  margin-top: 2px;
  color: var(--muted);
}

/* Brand row: logo + back-to-top button (sidebar / desktop only) */
.brand-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

/* Base look shared by both buttons */
.back-to-top {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.06);
  color: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}

.back-to-top:hover,
.back-to-top:focus-visible {
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.35);
  outline: none;
}

.back-to-top:active {
  transform: translateY(1px);
}

/* The mobile-bar variant is hidden on desktop… */
.mobile-back-to-top {
  display: none;
  margin-left: auto;
}

/* Toolbar needs to lay out the back link + button side by side */
.editor-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

/* …and the sidebar variant is hidden on mobile. Breakpoint is
   illustrative — match whatever the project already uses to
   switch .sidebar / .mobile-bar. */
@media (max-width: 768px) {
  #back-to-top {
    display: none;
  }
  .mobile-back-to-top {
    display: inline-flex;
  }
}