:root {
  color-scheme: light;
  --bg: #edf1f5;
  --panel: #ffffff;
  --ink: #101828;
  --muted: #667085;
  --line: #d8e0ea;
  --accent: #0b63ce;
  --accent-strong: #063d82;
  --accent-soft: #e7f0ff;
  --red: #d92d20;
  --red-strong: #9e241b;
  --blue: #155eef;
  --blue-strong: #123a91;
  --gold: #d99a16;
  --gold-soft: #fff5d6;
  --navy: #0b1727;
  --navy-2: #13243a;
  --mat: #f7f9fc;
  --shadow: 0 18px 48px rgba(11, 23, 39, 0.12);
  --tight-shadow: 0 8px 22px rgba(11, 23, 39, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    linear-gradient(135deg, rgba(217, 45, 32, 0.08), transparent 24%),
    linear-gradient(225deg, rgba(21, 94, 239, 0.1), transparent 28%),
    repeating-linear-gradient(90deg, rgba(11, 23, 39, 0.025) 0 1px, transparent 1px 42px),
    var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

.app {
  min-height: 100vh;
  padding: 24px;
  position: relative;
}

.app::before {
  background:
    linear-gradient(90deg, var(--red) 0 33.333%, #ffffff 33.333% 66.666%, var(--blue) 66.666% 100%);
  content: "";
  height: 6px;
  left: 0;
  position: fixed;
  right: 0;
  top: 0;
  z-index: 10;
}

.topbar,
.tabs {
  align-items: center;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin: 0 auto 18px;
  max-width: 1280px;
}

.topbar {
  background:
    linear-gradient(135deg, rgba(217, 45, 32, 0.18), transparent 30%),
    linear-gradient(225deg, rgba(21, 94, 239, 0.24), transparent 34%),
    linear-gradient(120deg, var(--navy), var(--navy-2));
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  box-shadow: var(--shadow);
  color: #ffffff;
  overflow: hidden;
  padding: 18px;
  position: relative;
}

.topbar::after {
  background: repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.08) 0 2px, transparent 2px 14px);
  bottom: 0;
  content: "";
  opacity: 0.55;
  pointer-events: none;
  position: absolute;
  right: -80px;
  top: 0;
  width: 360px;
}

.brand {
  align-items: center;
  display: flex;
  gap: 14px;
  min-width: 0;
  position: relative;
  z-index: 1;
}

.brand-mark {
  align-items: center;
  background:
    linear-gradient(135deg, var(--red) 0 48%, #ffffff 48% 52%, var(--blue) 52% 100%);
  border: 2px solid rgba(255, 255, 255, 0.82);
  border-radius: 8px;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.22);
  color: #fff;
  display: grid;
  font-size: 24px;
  font-weight: 950;
  height: 58px;
  place-items: center;
  text-shadow: 0 2px 7px rgba(0, 0, 0, 0.28);
  width: 58px;
}

.eyebrow {
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  letter-spacing: 0;
  margin: 0 0 4px;
  text-transform: uppercase;
}

.topbar .eyebrow {
  color: #c9d8ee;
}

h1,
h2,
p {
  margin: 0;
}

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

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

.header-actions {
  align-items: center;
  display: flex;
  gap: 10px;
  position: relative;
  z-index: 1;
}

.fullscreen-btn {
  align-items: center;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.26);
  color: #eaf2ff;
  display: inline-flex;
  gap: 8px;
  min-width: 138px;
  padding: 0 13px;
}

.fullscreen-btn:hover,
.fullscreen-btn.active {
  background: linear-gradient(135deg, rgba(231, 240, 255, 0.96), rgba(255, 255, 255, 0.9));
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.18);
  color: var(--accent-strong);
}

.fullscreen-icon {
  border: 2px solid currentColor;
  border-radius: 4px;
  height: 18px;
  position: relative;
  width: 18px;
}

.fullscreen-icon::before,
.fullscreen-icon::after {
  background: currentColor;
  content: "";
  position: absolute;
}

.fullscreen-icon::before {
  height: 2px;
  left: 3px;
  right: 3px;
  top: 7px;
}

.fullscreen-icon::after {
  bottom: 3px;
  left: 7px;
  top: 3px;
  width: 2px;
}

.fullscreen-btn.active .fullscreen-icon::before,
.fullscreen-btn.active .fullscreen-icon::after {
  transform: rotate(45deg);
}

.save-state {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 8px;
  color: #eaf2ff;
  font-weight: 850;
  min-width: 150px;
  padding: 11px 14px;
  position: relative;
  text-align: center;
  z-index: 1;
}

.save-state.saved {
  background: linear-gradient(135deg, rgba(255, 245, 214, 0.98), rgba(255, 255, 255, 0.9));
  border-color: rgba(217, 154, 22, 0.45);
  color: #7a4a00;
}

.toolbar,
.custom-panel,
.content,
.tabs,
.page-panel {
  margin: 0 auto;
  max-width: 1280px;
}

.tabs {
  background: rgba(255, 255, 255, 0.74);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--tight-shadow);
  justify-content: flex-start;
  margin-bottom: 18px;
  padding: 5px;
}

.tab {
  background: transparent;
  color: #475467;
  min-height: 42px;
  padding: 0 18px;
  position: relative;
}

.tab.active {
  background: var(--navy);
  box-shadow: 0 8px 20px rgba(11, 23, 39, 0.16);
  color: #fff;
}

.tab.active::after {
  background: linear-gradient(90deg, var(--red), #fff, var(--blue));
  border-radius: 999px;
  bottom: 5px;
  content: "";
  height: 3px;
  left: 18px;
  position: absolute;
  right: 18px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.toolbar,
.custom-panel,
.summary,
.participants,
.page-panel {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.toolbar {
  align-items: end;
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  padding: 16px;
  position: relative;
}

.toolbar::before,
.custom-panel::before,
.participants::before,
.summary::before,
.page-panel::before {
  background: linear-gradient(90deg, var(--red), #ffffff, var(--blue));
  content: "";
  height: 4px;
  left: 0;
  position: absolute;
  right: 0;
  top: 0;
}

.field {
  display: grid;
  gap: 6px;
  min-width: 220px;
}

.field-grow {
  flex: 1;
}

.field-wide {
  flex-basis: 100%;
}

label {
  color: #53627a;
  font-size: 13px;
  font-weight: 850;
}

select,
input {
  background: #fff;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  color: var(--ink);
  min-height: 46px;
  outline: none;
  padding: 10px 12px;
  width: 100%;
}

select:focus,
input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 4px rgba(21, 94, 239, 0.14);
}

button {
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 900;
  min-height: 42px;
  transition: transform 150ms ease, box-shadow 150ms ease, background 150ms ease;
}

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

button:active {
  transform: translateY(0);
}

button.secondary {
  background: #eef2f7;
  color: #233244;
  padding: 0 15px;
}

button.secondary:hover {
  box-shadow: 0 8px 18px rgba(11, 23, 39, 0.12);
}

button.primary {
  background: linear-gradient(135deg, var(--blue), var(--accent-strong));
  box-shadow: 0 10px 22px rgba(21, 94, 239, 0.24);
  color: #fff;
  padding: 0 14px;
}

button.danger {
  background: #fee4e2;
  color: var(--red-strong);
}

button.small {
  font-size: 12px;
  min-height: 34px;
  padding: 0 10px;
}

.custom-panel {
  align-items: end;
  display: grid;
  gap: 14px;
  grid-template-columns: 260px minmax(0, 1fr);
  margin-bottom: 16px;
  overflow: hidden;
  padding: 18px 16px 16px;
  position: relative;
}

.custom-form {
  align-items: end;
  display: flex;
  gap: 12px;
}

.content {
  align-items: start;
  display: grid;
  gap: 16px;
  grid-template-columns: 320px minmax(0, 1fr);
}

.summary {
  overflow: hidden;
  padding: 18px 16px 16px;
  position: sticky;
  top: 16px;
}

.summary h2 {
  align-items: center;
  display: flex;
  gap: 8px;
}

.summary h2::before {
  background: linear-gradient(135deg, var(--gold), #ffe39a);
  border-radius: 999px;
  content: "";
  height: 12px;
  width: 12px;
}

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

.podium-place {
  background:
    linear-gradient(90deg, rgba(217, 154, 22, 0.16), transparent 44%),
    #fff;
  border: 1px solid var(--line);
  border-left: 5px solid var(--gold);
  border-radius: 8px;
  min-height: 76px;
  padding: 11px 12px;
}

.podium-place strong {
  color: #9a5c00;
  display: block;
  font-size: 13px;
  margin-bottom: 5px;
}

.podium-place span {
  color: var(--muted);
  display: block;
  font-size: 13px;
  margin-top: 3px;
}

.participants {
  overflow: hidden;
  position: relative;
}

.list-header {
  align-items: center;
  background:
    linear-gradient(90deg, rgba(11, 23, 39, 0.04), transparent),
    #fff;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 18px 16px;
}

.list-header h2 {
  font-size: 20px;
}

.count {
  background: linear-gradient(135deg, #f4f7fb, #e8eef7);
  border: 1px solid #d8e0ea;
  border-radius: 999px;
  color: #233244;
  font-size: 13px;
  font-weight: 900;
  padding: 7px 11px;
  white-space: nowrap;
}

.chips {
  background: #f8fafc;
  border-bottom: 1px solid var(--line);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 16px;
}

.chips:empty {
  display: none;
}

.chip {
  background: #eef2f7;
  border: 1px solid transparent;
  color: #344054;
  min-height: 34px;
  padding: 0 11px;
}

.chip.active {
  background: linear-gradient(135deg, var(--accent-soft), #fff);
  border-color: #9fc5ff;
  color: var(--accent-strong);
}

.participant-list {
  background:
    linear-gradient(90deg, rgba(217, 45, 32, 0.025), transparent 35%, rgba(21, 94, 239, 0.025)),
    var(--mat);
  display: grid;
}

.participant {
  align-items: center;
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 14px;
  grid-template-columns: minmax(0, 1fr) auto;
  min-height: 88px;
  padding: 13px 18px;
  position: relative;
}

.participant::before {
  background: linear-gradient(180deg, var(--red), var(--blue));
  bottom: 12px;
  content: "";
  left: 0;
  opacity: 0;
  position: absolute;
  top: 12px;
  transition: opacity 150ms ease;
  width: 4px;
}

.participant:hover {
  background: #ffffff;
}

.participant:hover::before {
  opacity: 1;
}

.participant:last-child {
  border-bottom: 0;
}

.name-line {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.name {
  font-size: 16px;
  font-weight: 900;
  line-height: 1.25;
}

.meta {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
  margin-top: 5px;
}

.tag {
  border-radius: 999px;
  color: #fff;
  font-size: 12px;
  font-weight: 950;
  padding: 4px 8px;
}

.tag.red {
  background: var(--red);
}

.tag.blue {
  background: var(--blue);
}

.tag.custom {
  background: #7a3ff2;
}

.rank-buttons {
  display: grid;
  gap: 7px;
  grid-template-columns: repeat(4, 44px);
}

.rank-buttons button {
  background: #eef2f7;
  color: #233244;
  min-height: 44px;
}

.rank-buttons button:nth-child(1) {
  border-bottom: 3px solid var(--gold);
}

.rank-buttons button:nth-child(2) {
  border-bottom: 3px solid #98a2b3;
}

.rank-buttons button:nth-child(3) {
  border-bottom: 3px solid #b76e2b;
}

.rank-buttons button:nth-child(4) {
  border-bottom: 3px solid #64748b;
}

.rank-buttons button.active {
  background: linear-gradient(135deg, var(--gold), #f7c948);
  box-shadow: 0 10px 22px rgba(217, 154, 22, 0.28);
  color: #1f2937;
}

.page-panel {
  overflow: hidden;
  position: relative;
}

.page-heading {
  align-items: center;
  background:
    linear-gradient(90deg, rgba(11, 23, 39, 0.04), transparent),
    #fff;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 18px 16px 16px;
}

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

.table-wrap {
  overflow-x: auto;
}

table {
  border-collapse: collapse;
  font-size: 14px;
  min-width: 1180px;
  width: 100%;
}

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

th {
  background: var(--navy);
  color: #eaf2ff;
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.table-title {
  color: var(--ink);
  font-weight: 900;
  line-height: 1.3;
}

.table-sub {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
}

.table-input,
.compact-select {
  min-height: 38px;
}

.saved-slot {
  display: grid;
  gap: 8px;
  min-width: 220px;
}

.saved-slot.empty-slot {
  border: 1px dashed var(--line);
  border-radius: 8px;
  min-height: 126px;
  padding: 10px;
}

.saved-slot-head,
.saved-slot-actions {
  align-items: center;
  display: flex;
  gap: 8px;
  justify-content: space-between;
}

.saved-slot-actions .compact-select {
  flex: 1;
  min-width: 92px;
}

.text-danger {
  background: transparent;
  color: var(--red-strong);
  font-size: 12px;
  min-height: 28px;
  padding: 0;
}

.row-actions {
  display: flex;
  gap: 8px;
}

.place-pill {
  background: var(--gold-soft);
  border: 1px solid rgba(217, 154, 22, 0.3);
  border-radius: 999px;
  color: #8a5300;
  display: inline-flex;
  font-weight: 900;
  justify-content: center;
  min-width: 44px;
  padding: 5px 8px;
}

.empty-cell {
  color: var(--muted);
  padding: 28px 16px;
  text-align: center;
}

.ranking-grid {
  align-items: end;
  background:
    linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  min-height: 260px;
  padding: 28px 22px 18px;
}

.ranking-filters {
  align-items: end;
  background: #f8fafc;
  border-bottom: 1px solid var(--line);
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding: 14px 16px;
}

.check-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.check-chips label {
  align-items: center;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  cursor: pointer;
  display: inline-flex;
  gap: 8px;
  min-height: 40px;
  padding: 8px 12px;
}

.check-chips input {
  accent-color: var(--blue);
}

.check-chips label:has(input:checked) {
  background: #eef4ff;
  border-color: rgba(44, 91, 210, 0.5);
}

.ranking-card {
  align-content: start;
  background: #fff;
  border: 1px solid rgba(152, 162, 179, 0.32);
  border-radius: 8px;
  box-shadow: 0 12px 28px rgba(11, 23, 39, 0.1);
  display: grid;
  min-height: 150px;
  overflow: hidden;
  padding: 16px;
  position: relative;
}

.ranking-card::before {
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.78), transparent);
  content: "";
  height: 52px;
  left: -24px;
  position: absolute;
  top: 10px;
  transform: rotate(-16deg);
  width: 180px;
}

.podium-1 {
  background:
    linear-gradient(135deg, #fff7d8, #ffffff 54%),
    #fff;
  border-color: rgba(217, 154, 22, 0.45);
  min-height: 230px;
  order: 2;
  transform: translateY(-12px);
}

.podium-2 {
  background:
    linear-gradient(135deg, #f3f5f8, #ffffff 58%),
    #fff;
  border-color: rgba(148, 163, 184, 0.48);
  min-height: 190px;
  order: 1;
}

.podium-3 {
  background:
    linear-gradient(135deg, #fff1e5, #ffffff 58%),
    #fff;
  border-color: rgba(183, 110, 43, 0.38);
  min-height: 170px;
  order: 3;
}

.podium-medal {
  align-items: center;
  background: var(--gold-soft);
  border: 1px solid rgba(217, 154, 22, 0.38);
  border-radius: 999px;
  color: #8a5300;
  display: inline-flex;
  font-size: 16px;
  font-weight: 950;
  height: 42px;
  justify-content: center;
  position: relative;
  width: 64px;
  z-index: 1;
}

.podium-2 .podium-medal {
  background: #f2f4f7;
  border-color: #cbd5e1;
  color: #475467;
}

.podium-3 .podium-medal {
  background: #fff0df;
  border-color: #e6b98e;
  color: #9a4f15;
}

.ranking-card strong {
  display: block;
  font-size: 19px;
  line-height: 1.18;
  margin-top: 12px;
  position: relative;
  z-index: 1;
}

.ranking-card p {
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
  margin-top: 8px;
  position: relative;
  z-index: 1;
}

.podium-step {
  align-items: center;
  background: linear-gradient(135deg, var(--navy), #1b3351);
  color: rgba(255, 255, 255, 0.95);
  display: flex;
  font-size: 34px;
  font-weight: 950;
  height: calc(54px + (4 - var(--podium-rank)) * 18px);
  justify-content: center;
  margin: 18px -16px -16px;
}

.podium-1 .podium-step {
  background: linear-gradient(135deg, var(--gold), #f7c948);
  color: #382100;
}

.podium-2 .podium-step {
  background: linear-gradient(135deg, #98a2b3, #e4e7ec);
  color: #243044;
}

.podium-3 .podium-step {
  background: linear-gradient(135deg, #b76e2b, #f0b77c);
  color: #341b08;
}

.empty {
  color: var(--muted);
  padding: 28px 16px;
}

.winner-list {
  display: grid;
  gap: 14px;
  padding: 0 18px 18px;
}

.winner-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

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

.winner-placements {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  padding: 14px 16px;
}

.winner-placements[data-place-count="1"] {
  grid-template-columns: minmax(0, 1fr);
}

.winner-placements[data-place-count="2"] {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.winner-placements[data-place-count="3"] {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.missing-bouts {
  background: #f8fafc;
  border-top: 1px solid var(--line);
  display: grid;
  gap: 10px;
  padding: 14px 16px;
}

.missing-bout {
  align-items: end;
  background: #fff;
  border: 1px solid #f4c7c3;
  border-left: 5px solid var(--red);
  border-radius: 8px;
  display: grid;
  gap: 10px;
  grid-template-columns: 190px minmax(0, 1fr) auto;
  padding: 12px;
}

.missing-bout strong,
.missing-bout span {
  display: block;
}

.missing-bout span {
  color: var(--muted);
  font-size: 13px;
  margin-top: 3px;
}

.manual-placement {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.manual-placement-editor {
  margin-top: 10px;
}

.manual-placement-editor summary {
  background: #eef3fb;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  cursor: pointer;
  display: inline-block;
  font-size: 13px;
  font-weight: 800;
  padding: 6px 10px;
}

.manual-placement-select {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  font: inherit;
  min-width: 0;
  padding: 8px 10px;
  width: 100%;
}

.hidden {
  display: none;
}

@media (max-width: 860px) {
  .app {
    padding: 14px;
  }

  .topbar,
  .tabs,
  .toolbar,
  .list-header,
  .participant,
  .heading-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar,
  .toolbar,
  .custom-panel,
  .custom-form,
  .ranking-filters,
  .content,
  .list-header,
  .participant,
  .heading-actions,
  .winner-card-head,
  .winner-placements,
  .missing-bout,
  .ranking-grid {
    display: grid;
    grid-template-columns: 1fr;
  }

  .topbar {
    padding: 16px;
  }

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

  .fullscreen-btn,
  .save-state {
    min-width: 0;
    width: 100%;
  }

  h1 {
    font-size: 28px;
  }

  .field {
    min-width: 0;
  }

  .summary {
    position: static;
  }

  .rank-buttons {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .ranking-grid {
    min-height: 0;
  }

  .ranking-card {
    min-height: 0;
    order: var(--podium-rank);
    transform: none;
  }

  .podium-step {
    height: 48px;
  }
}

@media print {
  @page {
    margin: 10mm;
    size: landscape;
  }

  body {
    background: #fff;
  }

  .topbar,
  .tabs,
  .toolbar,
  .custom-panel,
  .content,
  .heading-actions,
  .ranking-filters,
  .ranking-grid {
    display: none !important;
  }

  .app {
    padding: 0;
  }

  .view {
    display: none !important;
  }

  body.print-saved #savedView,
  body.print-ranking #rankingView {
    display: block !important;
  }

  .page-panel {
    border: 0;
    box-shadow: none;
    max-width: none;
  }

  .page-panel::before {
    display: none;
  }

  .page-heading {
    display: block;
    padding: 0 0 10px;
  }

  .table-wrap {
    overflow: visible;
  }

  table {
    font-size: 10px;
    min-width: 0;
  }

  th,
  td {
    padding: 6px;
  }

  button,
  .text-danger,
  .saved-slot-actions {
    display: none !important;
  }

  input {
    border: 0;
    box-shadow: none;
    min-height: 0;
    padding: 1px 0;
  }

  .saved-slot {
    min-width: 0;
  }

  .saved-slot::after {
    color: var(--muted);
    content: "";
  }
}
