:root {
  color-scheme: light;
  --ink: #17212b;
  --muted: #617083;
  --line: #d7dee8;
  --line-soft: #e7edf3;
  --panel: #ffffff;
  --page: #eef3f8;
  --page-top: #f7fafc;
  --accent: #166f67;
  --accent-strong: #0d554e;
  --accent-soft: #e8f5f1;
  --warn: #b25e10;
  --danger: #a83232;
  --ok: #1f7a45;
  --shadow: 0 14px 34px rgba(24, 42, 58, 0.08);
  --shadow-soft: 0 8px 22px rgba(24, 42, 58, 0.06);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Inter, "Segoe UI", system-ui, sans-serif;
  background:
    linear-gradient(180deg, var(--page-top) 0, var(--page) 260px),
    var(--page);
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 42px;
  border: 0;
  border-radius: 6px;
  padding: 0 14px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-weight: 800;
  transition: background-color 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease;
}

button:hover {
  background: var(--accent-strong);
  transform: translateY(-1px);
  box-shadow: var(--shadow-soft);
}

button.ghost {
  min-height: 32px;
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--line);
}

button.ghost:hover {
  border-color: #a9c7c0;
  background: var(--accent-soft);
  box-shadow: none;
}

input,
select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  background: #fff;
  color: var(--ink);
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
}

input:focus,
select:focus,
button:focus-visible,
a:focus-visible,
summary:focus-visible {
  outline: 3px solid rgba(22, 111, 103, 0.22);
  outline-offset: 2px;
}

input:focus,
select:focus {
  border-color: #8bb8b1;
  box-shadow: 0 0 0 3px rgba(22, 111, 103, 0.1);
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px 8px;
  text-align: left;
}

th {
  background: #f8fafc;
  color: #536174;
  font-size: 13px;
  font-weight: 800;
}

tbody tr:hover td {
  background: #fbfdff;
}

.payout-total td {
  border-bottom: 0;
  font-weight: 750;
}

.payout-total td:first-child {
  color: var(--ink);
}

.shell {
  width: min(1280px, calc(100vw - 28px));
  margin: 0 auto;
  padding: 16px 0 40px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 114px;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line-soft);
}

.brand-title {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  margin: 0;
  line-height: 1;
}

.brand-title a {
  display: inline-flex;
  text-decoration: none;
}

.brand-title img {
  display: block;
  width: auto;
  height: 96px;
  max-width: 72vw;
  object-fit: contain;
}

.topbar h1 {
  margin: 0;
  font-size: 34px;
  line-height: 1.1;
}

.topbar p {
  margin: 6px 0 0;
  color: var(--muted);
}

.game-context {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  width: fit-content;
  max-width: 100%;
  margin-top: 8px;
  border: 1px solid var(--line-soft);
  border-radius: 999px;
  padding: 6px 10px 6px 7px;
  background: rgba(255, 255, 255, 0.72);
  box-shadow: 0 4px 18px rgba(24, 42, 58, 0.04);
  color: var(--muted);
  font-size: 14px;
}

.game-context .game-type {
  display: inline-grid;
  place-items: center;
  min-width: 50px;
  height: 24px;
  border-radius: 3px;
  padding: 0 9px;
  background: linear-gradient(180deg, var(--game-color-light, var(--game-color, #7bb9df)), var(--game-color, #449fdc));
  color: #fff;
  font-weight: 800;
  line-height: 1;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.18);
}

.game-context .game-track {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--ink);
  font-weight: 800;
}

.game-context .game-detail {
  color: var(--muted);
  font-size: 13px;
}

.track-flag {
  flex: 0 0 auto;
  width: 22px;
  height: 16px;
  border: 1px solid rgba(23, 33, 43, 0.18);
  border-radius: 2px;
  overflow: hidden;
  box-shadow: 0 1px 1px rgba(23, 33, 43, 0.08);
}

.fi {
  display: inline-block;
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
}

.fi-se { background-image: url("/vendor/flag-icons/flags/4x3/se.svg"); }
.fi-dk { background-image: url("/vendor/flag-icons/flags/4x3/dk.svg"); }
.fi-fi { background-image: url("/vendor/flag-icons/flags/4x3/fi.svg"); }
.fi-no { background-image: url("/vendor/flag-icons/flags/4x3/no.svg"); }
.fi-fr { background-image: url("/vendor/flag-icons/flags/4x3/fr.svg"); }
.fi-de { background-image: url("/vendor/flag-icons/flags/4x3/de.svg"); }
.fi-it { background-image: url("/vendor/flag-icons/flags/4x3/it.svg"); }
.fi-nl { background-image: url("/vendor/flag-icons/flags/4x3/nl.svg"); }
.fi-hk { background-image: url("/vendor/flag-icons/flags/4x3/hk.svg"); }
.fi-us { background-image: url("/vendor/flag-icons/flags/4x3/us.svg"); }
.fi-ca { background-image: url("/vendor/flag-icons/flags/4x3/ca.svg"); }
.fi-gb { background-image: url("/vendor/flag-icons/flags/4x3/gb.svg"); }
.fi-za { background-image: url("/vendor/flag-icons/flags/4x3/za.svg"); }

.game-context .schedule-v4,
.game-context .schedule-v5 {
  --game-color: rgb(68, 159, 220);
  --game-color-light: rgb(116, 190, 236);
}

.game-context .schedule-v64 {
  --game-color: rgb(234, 98, 6);
  --game-color-light: rgb(255, 137, 61);
}

.game-context .schedule-v65 {
  --game-color: rgb(192, 10, 38);
  --game-color-light: rgb(226, 54, 80);
}

.game-context .schedule-v85 {
  --game-color: rgb(0, 79, 159);
  --game-color-light: rgb(50, 125, 199);
}

.game-context .schedule-v86 {
  --game-color: rgb(128, 44, 126);
  --game-color-light: rgb(169, 79, 166);
}

.game-context .schedule-gs75 {
  --game-color: rgb(21, 97, 78);
  --game-color-light: rgb(43, 139, 114);
}

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

.home-link {
  color: var(--accent-strong);
  font-size: 14px;
  font-weight: 700;
  text-decoration-thickness: 1px;
  text-underline-offset: 4px;
}

.status-pill {
  min-width: 120px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.86);
  text-align: center;
  color: var(--muted);
  box-shadow: var(--shadow-soft);
  font-weight: 750;
}

.workspace {
  display: grid;
  grid-template-columns: 330px 1fr;
  gap: 16px;
  align-items: start;
}

.panel,
.metric {
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow-soft);
}

.controls {
  display: grid;
  gap: 14px;
  padding: 16px;
  position: sticky;
  top: 14px;
  align-self: start;
}

.dropzone {
  display: grid;
  place-items: center;
  min-height: 170px;
  border: 2px dashed #9fb3c8;
  border-radius: 8px;
  padding: 18px;
  text-align: center;
  cursor: pointer;
  background: linear-gradient(180deg, #fbfdff, #f3f7fa);
  transition: border-color 0.16s ease, background-color 0.16s ease, transform 0.16s ease;
}

.dropzone:hover {
  border-color: #789ab5;
  transform: translateY(-1px);
}

.dropzone.dragging {
  border-color: var(--accent);
  background: #edf8f5;
}

.dropzone input {
  display: none;
}

.dropzone small {
  color: var(--muted);
  line-height: 1.35;
}

.drop-icon {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  margin-bottom: 10px;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 800;
}

.save-system {
  display: grid;
  gap: 6px;
}

.save-system > label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.save-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 82px;
  gap: 8px;
}

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

.field-row {
  display: grid;
  gap: 6px;
}

.field-row label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.advanced {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafc;
}

.advanced summary {
  padding: 10px 12px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.advanced[open] summary {
  border-bottom: 1px solid var(--line);
}

.advanced-fields {
  display: grid;
  gap: 12px;
  padding: 12px;
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.live-countdown {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  background: #f8fafc;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.3;
}

.live-countdown.active {
  border-color: #9cc9c1;
  background: #edf8f5;
  color: var(--accent-strong);
}

.share-box {
  display: grid;
  gap: 6px;
}

.share-box label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.share-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 92px;
  gap: 8px;
}

.share-row input {
  min-width: 0;
}

.meta {
  border-top: 1px solid var(--line-soft);
  padding-top: 12px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.results {
  display: grid;
  gap: 16px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.metric {
  position: relative;
  overflow: hidden;
  padding: 16px;
}

.metric::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 4px;
  background: #c7d3de;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.metric strong {
  display: block;
  margin-top: 4px;
  font-size: 26px;
  line-height: 1.1;
}

.metric-results {
  border-color: #b5d9d1;
  background: linear-gradient(180deg, #f7fffc, #f2faf7);
}

.metric-results::before {
  background: linear-gradient(90deg, var(--accent), #65b7dd);
}

.section-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line-soft);
  background: linear-gradient(180deg, #fff, #fbfcfe);
}

.section-head h2 {
  margin: 0;
  font-size: 17px;
}

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

.payout-tools {
  display: flex;
  align-items: center;
  justify-content: end;
  gap: 12px;
  flex-wrap: wrap;
}

.check-row {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.2;
  white-space: nowrap;
}

.check-row input {
  width: 16px;
  min-height: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--accent);
}

.adjusted-tag {
  display: inline-block;
  margin-left: 6px;
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 650;
}

.legs {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1px;
  background: var(--line-soft);
}

.leg {
  min-height: 126px;
  padding: 14px;
  background: #fff;
  border-left: 4px solid transparent;
  transition: background-color 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease;
}

.leg.is-complete {
  background: #f4fbf8;
  border-left-color: var(--accent);
}

.leg.is-next {
  position: relative;
  z-index: 1;
  background: linear-gradient(180deg, #fffaf2, #fff6e8);
  border: 2px solid #d78a32;
  box-shadow: inset 0 0 0 1px rgba(215, 138, 50, 0.22);
}

.leg-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.leg h3 {
  margin: 0 0 10px;
  font-size: 15px;
}

.leg-title h3 {
  margin: 0;
}

.next-badge {
  border-radius: 999px;
  padding: 5px 8px;
  background: linear-gradient(180deg, #d98328, var(--warn));
  color: #fff;
  font-size: 12px;
  font-weight: 700;
}

.race-clock {
  display: inline-block;
  margin-top: 12px !important;
  border-radius: 6px;
  padding: 7px 9px;
  background: #fff0dc;
  color: #87470b !important;
  font-size: 14px !important;
  font-weight: 800;
}

.winner {
  display: inline-grid;
  place-items: center;
  min-width: 36px;
  height: 36px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 800;
}

.winner.pending {
  background: #edf1f5;
  color: var(--muted);
}

.leg p {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.horse-table {
  display: grid;
  gap: 1px;
  margin-top: 12px;
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  overflow: hidden;
  background: var(--line);
  font-size: 12px;
}

.horse-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 64px 78px;
  gap: 8px;
  align-items: center;
  min-height: 34px;
  padding: 6px 8px;
  background: #fff;
}

.horse-table.with-potential .horse-row {
  grid-template-columns: minmax(110px, 1fr) 54px 68px repeat(var(--tier-column-count, 1), 56px) 86px;
  min-width: calc(340px + (var(--tier-column-count, 1) * 56px));
}

.horse-table.with-potential {
  overflow-x: auto;
}

.tier-row-value,
.potential-value {
  font-weight: 700;
}

.potential-value {
  color: var(--accent-strong);
}

.horse-head {
  min-height: 30px;
  background: #f8fafc;
  color: var(--muted);
  font-weight: 700;
}

.horse-row.is-winner {
  background: #edf8f5;
}

.horse-name {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  gap: 6px;
  align-items: center;
  min-width: 0;
}

.horse-name span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.horse-name strong {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  background: #edf1f5;
  color: var(--ink);
  font-size: 12px;
}

.horse-row.is-winner .horse-name strong {
  background: var(--accent);
  color: #fff;
}

.log-panel ol {
  max-height: 170px;
  margin: 0;
  padding: 10px 16px 14px 34px;
  overflow: auto;
  color: var(--muted);
  font-size: 13px;
}

.log-panel li {
  padding: 3px 0;
}

.ok {
  color: var(--ok);
}

.warn {
  color: var(--warn);
}

.danger {
  color: var(--danger);
}

@media (max-width: 860px) {
  .workspace,
  .summary-grid {
    grid-template-columns: 1fr;
  }

  .controls {
    position: static;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
    min-height: 0;
  }

}
