:root {
  color-scheme: dark;
  --bg: #0f1720;
  --panel: #17212b;
  --panel-2: #1f2d3a;
  --panel-3: #243445;
  --text: #f4f7fb;
  --muted: #9fb1c2;
  --border: #34495a;
  --accent: #69a7ff;
  --accent-2: #8b5cf6;
  --danger: #ff6b6b;
  --ok: #4ade80;
  --warning: #fbbf24;
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.35);
  --radius: 18px;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 20% 0%, rgba(105, 167, 255, 0.18), transparent 35%),
    radial-gradient(circle at 80% 10%, rgba(139, 92, 246, 0.16), transparent 30%),
    var(--bg);
  color: var(--text);
}

button,
input {
  font: inherit;
}

button {
  min-height: 44px;
}

a {
  color: inherit;
}

.app-shell {
  width: min(1160px, 100%);
  margin: 0 auto;
  padding: 16px;
  padding-bottom: max(24px, env(safe-area-inset-bottom));
}

.app-shell.wide-shell {
  width: 100%;
  max-width: none;
  padding-left: 10px;
  padding-right: 10px;
}

.app-shell.wide-shell .card-inner {
  padding-left: 10px;
  padding-right: 10px;
}

.loading-screen {
  padding: 28px;
  color: var(--muted);
}

.header {
  display: grid;
  gap: 14px;
  margin: 4px 0 18px;
}

.header-title h1 {
  margin: 0;
  font-size: clamp(30px, 7vw, 54px);
  line-height: 0.95;
  letter-spacing: -0.05em;
}

.header-title p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.nav {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  position: sticky;
  top: 0;
  z-index: 10;
  padding: 8px 0;
  background: transparent;
  backdrop-filter: none;
}

.nav a {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(23, 33, 43, 0.88);
  text-decoration: none;
  color: var(--muted);
  font-weight: 700;
}

.nav a.active {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white;
  border-color: transparent;
}

.grid {
  display: grid;
  gap: 14px;
}

.card {
  background: rgba(23, 33, 43, 0.92);
  border: 1px solid rgba(52, 73, 90, 0.78);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card-inner {
  padding: 16px;
}

.card-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.card-title h2,
.card-title h3 {
  margin: 0;
  letter-spacing: -0.03em;
}

.help-text,
.small-muted {
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.42;
}

.form-row {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

label {
  color: var(--muted);
  font-weight: 700;
  font-size: 0.92rem;
}

input[type="text"],
input[type="search"] {
  width: 100%;
  min-height: 48px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: #0b1118;
  color: var(--text);
  padding: 12px 14px;
  outline: none;
}

input[type="text"]:focus,
input[type="search"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(105, 167, 255, 0.18);
}

.pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 7px 10px;
  background: rgba(105, 167, 255, 0.13);
  border: 1px solid rgba(105, 167, 255, 0.26);
  color: #d9e9ff;
  font-weight: 800;
  font-size: 0.9rem;
}

.pill.warning {
  color: #ffe6a6;
  border-color: rgba(251, 191, 36, 0.35);
  background: rgba(251, 191, 36, 0.12);
}

.pill.ok {
  color: #c8ffd8;
  border-color: rgba(74, 222, 128, 0.35);
  background: rgba(74, 222, 128, 0.12);
}

.selected-list,
.available-list,
.ballot-list {
  display: grid;
  gap: 10px;
}

.empty-state {
  color: var(--muted);
  border: 1px dashed var(--border);
  border-radius: 16px;
  padding: 16px;
  background: rgba(15, 23, 32, 0.55);
}

.selected-card,
.entry-card {
  display: grid;
  gap: 10px;
  align-items: center;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 10px;
}

.selected-card {
  grid-template-columns: auto auto 1fr auto;
}

.entry-card {
  grid-template-columns: 1fr auto;
}

.selected-card.dragging {
  opacity: 0.45;
  border-color: var(--accent);
}

.drag-handle {
  width: 44px;
  height: 44px;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: #111b24;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  touch-action: none;
  user-select: none;
  cursor: grab;
}

.drag-handle:active {
  cursor: grabbing;
}

.rank-badge {
  width: 48px;
  min-width: 48px;
  display: grid;
  place-items: center;
  align-self: stretch;
  border-radius: 14px;
  background: linear-gradient(135deg, rgba(105, 167, 255, 0.24), rgba(139, 92, 246, 0.24));
  border: 1px solid rgba(105, 167, 255, 0.24);
}

.rank-badge strong {
  font-size: 1.08rem;
  line-height: 1;
}

.rank-badge span {
  color: var(--muted);
  font-size: 0.77rem;
  font-weight: 800;
  margin-top: 2px;
}

.entry-main {
  min-width: 0;
}

.entry-country {
  display: flex;
  gap: 8px;
  align-items: center;
  min-width: 0;
  font-weight: 900;
  letter-spacing: -0.02em;
}

.flag {
  display: inline-flex;
  width: 1.8em;
  min-width: 1.8em;
  font-size: 1.28em;
  line-height: 1;
}

.entry-meta {
  margin-top: 3px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.entry-song {
  color: #dbe7f3;
}

.row-actions {
  display: grid;
  grid-template-columns: repeat(3, 44px);
  gap: 6px;
}

.icon-btn,
.add-btn,
.primary-btn,
.secondary-btn {
  border: 0;
  border-radius: 13px;
  font-weight: 900;
}

.icon-btn {
  color: var(--text);
  background: #101923;
  border: 1px solid var(--border);
  font-size: 1.45rem;
  line-height: 1;
}

.icon-btn.danger {
  font-size: 1.7rem;
  color: white;
  background: rgba(255, 107, 107, 0.14);
  border-color: rgba(255, 107, 107, 0.35);
}

.add-btn {
  min-width: 56px;
  color: white;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}

button:disabled,
.add-btn:disabled,
.primary-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.primary-btn,
.secondary-btn {
  width: 100%;
  min-height: 54px;
  padding: 14px 16px;
}

.primary-btn {
  color: white;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}

.secondary-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  color: var(--text);
  background: #101923;
  border: 1px solid var(--border);
}

.actions-row {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.message {
  margin-top: 12px;
  padding: 12px;
  border-radius: 14px;
  display: none;
  line-height: 1.35;
}

.message.show {
  display: block;
}

.message.error {
  background: rgba(255, 107, 107, 0.14);
  border: 1px solid rgba(255, 107, 107, 0.35);
}

.message.success {
  background: rgba(74, 222, 128, 0.12);
  border: 1px solid rgba(74, 222, 128, 0.35);
}

.toolbar {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
}

.results-bottom {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid rgba(52, 73, 90, 0.72);
}

.results-bottom .toolbar {
  margin-bottom: 0;
}

.results-card .stats-grid {
  margin-top: 14px;
  margin-bottom: 0;
}

.results-card .card-title:first-child {
  margin-top: 0 !important;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}

.stat {
  padding: 14px;
  border-radius: 16px;
  background: rgba(31, 45, 58, 0.78);
  border: 1px solid var(--border);
}

.stat-value {
  display: block;
  font-size: 1.55rem;
  font-weight: 950;
  letter-spacing: -0.04em;
}

.stat-label {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
}

.table-wrap {
  overflow-x: auto;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: #101923;
}

table {
  width: 100%;
  border-collapse: collapse;
  white-space: nowrap;
}

th,
td {
  padding: 10px 11px;
  border-bottom: 1px solid rgba(52, 73, 90, 0.72);
  text-align: left;
  vertical-align: middle;
}

th {
  color: #dbeafe;
  background: #111d27;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

td {
  color: var(--text);
}

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

.leader-country {
  min-width: 230px;
}

.leader-country small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.85rem;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 500;
}

.points-big {
  font-weight: 950;
  font-size: 1.15rem;
}

.matrix-wrap {
  max-height: 74vh;
  width: 100%;
  overflow: auto;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: #101923;
}

.matrix th:first-child,
.matrix td:first-child {
  position: sticky;
  left: 0;
  z-index: 2;
  background: #111d27;
}

.matrix th:first-child {
  z-index: 3;
}

.matrix th:not(:first-child),
.matrix td:not(:first-child) {
  min-width: 74px;
  text-align: center;
}

.matrix .country-head {
  display: grid;
  justify-items: center;
  gap: 4px;
}

.matrix .country-head span:last-child {
  font-size: 0.72rem;
  color: var(--muted);
  max-width: 62px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.zero-cell {
  color: rgba(159, 177, 194, 0.36);
}

.score-cell {
  font-weight: 950;
  color: white;
}

.ballot-card {
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(31, 45, 58, 0.7);
}

.ballot-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.ballot-head strong {
  font-size: 1.12rem;
}

.ballot-grid {
  display: grid;
  gap: 7px;
}

.ballot-row {
  display: grid;
  grid-template-columns: 42px 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 8px;
  border-radius: 12px;
  background: rgba(15, 23, 32, 0.5);
}

.score-pill {
  min-width: 36px;
  text-align: center;
  font-weight: 950;
  padding: 5px 7px;
  border-radius: 999px;
  background: rgba(105, 167, 255, 0.17);
  border: 1px solid rgba(105, 167, 255, 0.28);
}

.footer-note {
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.4;
}

@media (min-width: 820px) {
  .app-shell {
    padding: 28px;
  }

  .app-shell.wide-shell {
    padding-left: 14px;
    padding-right: 14px;
  }

  .header {
    grid-template-columns: 1fr auto;
    align-items: end;
  }

  .nav {
    position: static;
    min-width: 410px;
  }

  .vote-layout {
    grid-template-columns: 1fr 1fr;
    align-items: start;
  }

  .toolbar {
    grid-template-columns: 1fr auto auto;
    align-items: center;
  }

  .actions-row {
    grid-template-columns: 1fr 1fr;
  }

  .stats-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

@media (max-width: 420px) {
  .selected-card {
    grid-template-columns: auto auto 1fr;
  }

  .selected-card .row-actions {
    grid-column: 1 / -1;
    grid-template-columns: repeat(3, 1fr);
  }

  .entry-card {
    grid-template-columns: 1fr auto;
  }

  .drag-handle {
    width: 40px;
  }

  .rank-badge {
    width: 42px;
    min-width: 42px;
  }
}
