:root {
  --bg: #130725;
  --panel: #21123a;
  --panel-2: #2b184a;
  --text: #f8f5ff;
  --muted: #c9bedc;
  --line: rgba(255, 255, 255, 0.14);
  --accent: #ffe34e;
  --hot: #ec3da2;
  --ok: #39d98a;
  --danger: #ff6b6b;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: radial-gradient(circle at top left, #8f2dcf 0, transparent 26rem), linear-gradient(145deg, #15131c, #102033 62%, #22112b);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body.ranking-mode {
  overflow: hidden;
}

body.ranking-mode .topbar,
body.ranking-mode .tabs,
body.ranking-mode .notice {
  display: none;
}

body.ranking-mode .shell {
  width: 100%;
  height: 100vh;
  padding: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  padding: 0 18px;
  color: #160a24;
  background: var(--accent);
  font-weight: 800;
  cursor: pointer;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.ghost {
  color: var(--text);
  border: 1px solid var(--line);
  background: transparent;
}

.shell {
  width: min(1180px, calc(100% - 28px));
  margin: 0 auto;
  padding: 26px 0 44px;
}

.topbar,
.section-head,
.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.eyebrow,
.hint {
  color: var(--muted);
}

.eyebrow {
  margin: 0 0 3px;
  text-transform: uppercase;
  letter-spacing: 0;
  font-size: 0.78rem;
}

h1,
h2 {
  margin: 0;
  line-height: 1.05;
}

h1 {
  font-size: 3.4rem;
}

h2 {
  font-size: 1.15rem;
}

.notice,
.login-card,
.selection-panel,
.admin-card,
.user-table {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(20, 9, 40, 0.82);
  backdrop-filter: blur(14px);
}

.notice {
  margin: 18px 0;
  padding: 12px 14px;
}

.success {
  border-color: rgba(57, 217, 138, 0.45);
}

.error {
  border-color: rgba(255, 107, 107, 0.55);
}

.login-panel {
  display: grid;
  min-height: 56vh;
  place-items: center;
}

.login-card,
.admin-card {
  display: grid;
  gap: 14px;
  width: min(420px, 100%);
  padding: 22px;
}

.danger-card {
  border-color: rgba(255, 107, 107, 0.55);
}

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

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-weight: 700;
}

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

.tabs {
  display: flex;
  gap: 8px;
  margin: 24px 0 18px;
  overflow-x: auto;
}

.tab {
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
}

.tab.active {
  color: #160a24;
  background: var(--accent);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.contestant-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.contestant,
.rank-item,
.result-row,
.user-table div {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 64px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: rgba(255, 255, 255, 0.08);
}

.contestant {
  position: relative;
  width: 100%;
  min-height: 0;
  cursor: pointer;
  padding: 5px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
  touch-action: manipulation;
}

.contestant.selected {
  border-color: var(--accent);
  background: rgba(255, 227, 78, 0.15);
}

.contestant.dragging,
.rank-item.dragging {
  opacity: 0.42;
}

.rank-item img,
.result-row img {
  width: 100%;
  aspect-ratio: 3 / 1;
  height: auto;
  border-radius: 6px;
  object-fit: cover;
}

.contestant img {
  display: block;
  width: auto;
  aspect-ratio: 3 / 1;
  height: auto;
  min-width: 0;
  flex: 1 1 0;
  border-radius: 6px;
  object-fit: cover;
}

.rank-item img {
  width: auto;
  min-width: 0;
  flex: 1 1 auto;
  object-fit: contain;
  background: rgba(255, 255, 255, 0.04);
}

.result-row img {
  width: 96px;
  flex: 0 0 96px;
}

.order,
.place,
.points-pill {
  display: inline-grid;
  min-width: 28px;
  height: 28px;
  place-items: center;
  border-radius: 999px;
  color: #160a24;
  background: var(--accent);
  font-weight: 900;
}

.ranking-list {
  display: grid;
  gap: 7px;
}

.icon-button {
  width: 36px;
  min-height: 36px;
  margin-left: auto;
  padding: 0;
}

.checkmark {
  display: grid;
  width: 26px;
  height: 26px;
  flex: 0 0 26px;
  place-items: center;
  border: 2px solid rgba(255, 255, 255, 0.65);
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.22);
}

.contestant.selected .checkmark {
  border-color: var(--accent);
  background: var(--accent);
}

.contestant.selected .checkmark::after {
  content: "";
  width: 8px;
  height: 14px;
  border: solid #160a24;
  border-width: 0 3px 3px 0;
  transform: rotate(45deg) translateY(-1px);
}

.vote-actions {
  position: sticky;
  bottom: 0;
  z-index: 5;
  display: flex;
  justify-content: flex-end;
  margin-top: 14px;
  padding: 12px 0;
  background: linear-gradient(180deg, transparent, rgba(19, 7, 37, 0.92) 36%);
}

.ranking-screen {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: 100vh;
  padding: 8px;
  gap: 6px;
}

.ranking-screen[hidden] {
  display: none;
}

.ranking-topbar {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
}

.ranking-topbar h2 {
  font-size: 1.05rem;
}

.ranking-topbar span {
  color: var(--muted);
  font-weight: 800;
}

.ranking-topbar button,
.ranking-bottom-actions button {
  min-height: 36px;
  padding: 0 12px;
}

.ranking-full-list {
  min-height: 0;
  overflow: auto;
  align-content: start;
  padding: 2px 0;
  touch-action: none;
}

.ranking-bottom-actions {
  display: flex;
}

.ranking-bottom-actions button {
  width: 100%;
}

dialog {
  width: min(560px, calc(100% - 18px));
  max-height: min(96vh, 760px);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: var(--panel);
  overflow: auto;
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.68);
}

.dialog-form {
  display: grid;
  gap: 12px;
}

.rank-item {
  cursor: grab;
  min-height: 42px;
  padding: 4px 5px;
  touch-action: none;
}

.rank-controls {
  display: flex;
  gap: 6px;
  margin-left: auto;
}

.rank-controls button {
  min-height: 30px;
  padding: 0 8px;
}

.points-pill {
  min-width: 36px;
  height: 30px;
  border-radius: 8px;
}

.results-list,
.user-table {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.result-row {
  grid-template-columns: 42px 96px minmax(0, 1fr) auto;
}

.admin-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}

.user-table {
  margin-top: 18px;
  padding: 16px;
}

.user-table div {
  display: grid;
  grid-template-columns: minmax(100px, 1fr) minmax(100px, 1fr) 80px auto;
}

.user-table button {
  min-height: 36px;
  padding: 0 12px;
}

@media (max-width: 820px) {
  .contestant-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  }
}

@media (max-width: 520px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  h1 {
    font-size: 2.2rem;
  }

  .contestant,
  .rank-item,
  .result-row {
    min-height: 0;
  }

  .shell {
    width: min(100% - 16px, 1180px);
    padding-top: 16px;
  }

  .tabs {
    margin: 16px 0 12px;
  }

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

  .contestant {
    gap: 5px;
    padding: 3px;
  }

  .checkmark {
    width: 20px;
    height: 20px;
    flex-basis: 20px;
    border-radius: 5px;
  }

  .contestant.selected .checkmark::after {
    width: 7px;
    height: 12px;
    border-width: 0 3px 3px 0;
  }

  .vote-actions {
    padding: 10px 0;
  }

  .vote-actions button {
    width: 100%;
  }

  .ranking-list {
    gap: 3px;
  }

  .rank-item {
    min-height: 0;
    gap: 4px;
    padding: 3px;
  }

  .rank-item img {
    height: clamp(28px, 6.1vh, 42px);
    max-height: none;
    flex: 1 1 auto;
  }

  .points-pill {
    min-width: 28px;
    height: 24px;
    font-size: 0.72rem;
  }

  .rank-controls {
    gap: 3px;
  }

  .rank-controls button {
    min-height: 24px;
    padding: 0 6px;
    font-size: 0.68rem;
  }

  .result-row {
    grid-template-columns: 32px 76px minmax(0, 1fr) auto;
  }

  .result-row img {
    width: 76px;
    flex-basis: 76px;
  }

  .user-table div {
    grid-template-columns: 1fr;
    align-items: start;
  }
}
