:root {
  color-scheme: light;
  --ink: #252d35;
  --muted: #606a70;
  --paper: #fffdf6;
  --border: #d8d3c7;
  --accent: #aa4426;
  font-family: "Instrument Sans", system-ui, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; color: var(--ink); background: #efece4; }
button, select { font: inherit; }
button, select, summary { cursor: pointer; }
:focus-visible { outline: 3px solid #146f97; outline-offset: 3px; }
.mast, main { max-width: 1440px; margin: auto; padding-inline: clamp(16px, 4vw, 56px); }
.mast { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding-block: 29px 24px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 14px; }
.flag { display: grid; place-items: center; width: 50px; height: 50px; border-radius: 12px; background: #26323a; color: #fff8e6; font-size: 30px; }
h1, h2, p { margin: 0; }
h1 { font-family: "Instrument Serif", Georgia, serif; font-size: clamp(35px, 4vw, 55px); line-height: .99; letter-spacing: -.055em; }
.brand p, .eyebrow, .sheet-head { font-size: .73rem; font-weight: 750; letter-spacing: .13em; text-transform: uppercase; }
.brand p { margin-top: 6px; color: var(--accent); }
form { display: flex; flex-wrap: wrap; gap: 8px; }
select, .new, .pass { border: 1px solid var(--border); border-radius: 7px; padding: 10px 12px; font-weight: 650; }
select { background: var(--paper); color: var(--ink); }
.new, .pass { background: #26323a; color: #fffdf6; border-color: #26323a; }
.new:disabled { opacity: .6; cursor: default; }
.new:not(:disabled):hover, .pass:hover { background: #415461; }
main { display: grid; grid-template-columns: minmax(0, 1fr) minmax(252px, 295px); align-items: start; gap: 20px; padding-bottom: 30px; }
.sheet, .card { background: var(--paper); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 2px 5px #24291e0b; }
.sheet { padding: clamp(10px, 1.65vw, 22px); }
.sheet-head, .sheet-foot { display: flex; justify-content: space-between; gap: 8px 18px; flex-wrap: wrap; }
.sheet-head { margin-bottom: 13px; }
.sheet-head > span { color: var(--muted); }
.track-actions { display: none; align-items: center; gap: 8px; margin-bottom: 10px; }
.sheet:has(.track-tool:not([hidden])) .track-actions { display: flex; }
.track-scroll { overflow: auto; overscroll-behavior: contain; }
.track-turn:not([hidden]) { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px; }
#track-status { font-weight: 650; }
.board { position: relative; aspect-ratio: 50 / 33; isolation: isolate; background: #faf8ee; border: 1px solid #cbd4cc; overflow: hidden; }
canvas { display: block; width: 100%; height: 100%; }
.target { position: absolute; display: block; width: clamp(10px, 1.65vw, 21px); aspect-ratio: 1; padding: 0; border-radius: 50%; transform: translate(-50%, -50%); border: 2px solid currentColor; background: var(--paper); }
.target:hover, .target.preview { background: currentColor; z-index: 1; }
.sheet-foot { justify-content: flex-start; margin-top: 13px; font-size: .78rem; color: var(--muted); }
.sheet-foot span { display: flex; align-items: center; gap: 5px; }
.key { display: inline-block; width: 13px; height: 10px; }
.key.finish { background: conic-gradient(#343b41 25%, #fff 0 50%, #343b41 0 75%, #fff 0) 0 0 / 8px 8px; border: 1px solid #343b41; }
.key.option { border: 2px solid var(--accent); border-radius: 50%; width: 10px; }
aside { display: grid; gap: 12px; }
.card { padding: 16px; }
.eyebrow { color: var(--accent); }
#turn-title { margin-top: 4px; font-size: 1.45rem; }
#turn-message { margin-top: 5px; font-size: .86rem; line-height: 1.45; color: var(--muted); }
.move-table:not(:empty) { margin-top: 14px; display: grid; grid-template-columns: 1fr repeat(3, .8fr); gap: 5px; align-items: center; text-align: center; }
.move-table span { font-size: .72rem; }
.move-table .speed { text-align: left; font-weight: 650; }
.move-table button { min-width: 34px; min-height: 36px; border-radius: 5px; border: 1px solid #d1c9bb; background: #f6f2e7; color: var(--ink); font-size: 1rem; }
.move-table button:hover, .move-table .preview { color: white; background: #34434b; }
.move-table button:disabled { cursor: default; color: #77776f; background: transparent; border-color: #e6e1d8; }
.pass { margin-top: 14px; width: 100%; }
.lineup h2, summary { font-size: .91rem; font-weight: 750; }
.lineup ul { margin: 10px 0 0; padding: 0; list-style: none; }
.lineup li { display: flex; align-items: center; gap: 8px; padding: 6px 5px; font-size: .84rem; border-radius: 5px; }
.lineup li.active { background: #efece2; font-weight: 700; }
.lineup li span:last-child { margin-left: auto; color: var(--muted); }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--player); }
.rules ul { padding-left: 18px; margin: 10px 0 0; font-size: .84rem; line-height: 1.5; }
.rules li + li { margin-top: 5px; }
.sr-only { position: absolute; clip-path: inset(50%); width: 1px; height: 1px; overflow: hidden; white-space: nowrap; }
.site-footer {
  max-width: 1440px;
  margin: auto;
  padding: 0 clamp(16px, 4vw, 56px) 20px;
  color: var(--muted);
  font-size: .83rem;
}
.site-footer nav { display: flex; flex-wrap: wrap; column-gap: 16px; }
.site-footer a { display: inline-flex; align-items: center; min-height: 44px; color: inherit; }
.site-information { display: block; max-width: 760px; margin: auto; padding: 24px 16px 40px; line-height: 1.55; }
.site-information a { color: #17658b; }
.site-information h1 { margin: 16px 0 24px; }
.site-information section + section { margin-top: 28px; }
.site-information h2 { font-size: 1.36rem; margin-bottom: 12px; }
.site-information h3 { font-size: 1rem; margin: 18px 0 6px; }
.site-information p + p { margin-top: 8px; }
#track-dialog[open] {
  position: fixed;
  inset: 0;
  margin: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  padding: 0;
  border: 0;
  background: var(--paper);
  color: var(--ink);
}
#track-dialog .sheet {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right))
    max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  border: 0;
  border-radius: 0;
}
#track-dialog .track-actions { display: flex; }
#track-dialog .track-scroll { flex: 1; min-height: 0; }
#track-dialog .board { min-width: 1600px; }
#track-dialog .sheet-foot { margin-block: 8px; }
#track-dialog .target { width: 30px; }
body:has(#track-dialog[open]) { overflow: hidden; }
@media (max-width: 860px) {
  main { grid-template-columns: minmax(0, 1fr); }
  aside { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; }
  .rules { grid-column: 2; }
}
@media (max-width: 860px), (pointer: coarse) {
  .track-actions { display: flex; }
  .track-actions .new, .track-turn .new { min-height: 44px; }
  .track-scroll { max-height: 52dvh; }
  .board { min-width: 1200px; }
  .target { width: 22px; }
  #track-dialog .track-scroll { max-height: none; }
}
@media (max-width: 510px) {
  aside { grid-template-columns: minmax(0, 1fr); }
  .rules { grid-column: auto; }
}

.setup-field { position: relative; min-width: 0; }
.setup-field select { width: 100%; }
.control-icon, .compact-value { display: none; }
.action > span + span { margin-left: 5px; }
.track-actions { justify-content: flex-end; }
.track-tool {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  font-size: 1.45rem;
  line-height: 1;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
}
.track-tool[hidden], .setup-field[hidden] { display: none; }
.track-tool:hover, .track-tool[aria-pressed="true"] { background: #e9e5d9; }
#stop-track { color: var(--accent); }
#track-dialog .sheet-head { margin-bottom: 6px; }
#track-dialog .sheet-foot { display: none; }
#track-dialog .track-turn { padding-top: 8px; font-size: .84rem; }
#track-status { flex: 1 1 96px; min-width: 0; }
#track-map {
  display: block;
  margin-left: auto;
  width: clamp(92px, 32vw, 132px);
  height: auto;
  aspect-ratio: 50 / 33;
  border: 1px solid var(--border);
  border-radius: 6px;
}
#track-dialog .overview .board {
  min-width: 0;
  width: min(100%, calc((100dvh - 150px) * 50 / 33));
  margin: auto;
}
.sheet.overview .target { display: none; }
#track-dialog .track-scroll { touch-action: pan-x pan-y; }

@media (max-width: 860px), (pointer: coarse) {
  .mast { display: block; padding-block: 14px 12px; }
  .brand { gap: 9px; margin-bottom: 12px; }
  .brand .flag { width: 39px; height: 39px; font-size: 23px; border-radius: 8px; }
  .brand h1 { font-size: clamp(28px, 7vw, 37px); }
  .brand p { margin-top: 3px; font-size: .63rem; }
  #setup { display: flex; flex-wrap: wrap; gap: 4px; }
  #setup.race-locked .setup-field { display: none; }
  .setup-field { flex: 1 1 52px; height: 44px; }
  #field-count:has(select option[value="solo"]:checked) { flex-basis: 62px; }
  #field-difficulty { flex: 1.4 1 73px; }
  .setup-field select {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    font-size: 16px;
    z-index: 1;
  }
  .setup-field:has(select:focus-visible) { outline: 3px solid #146f97; outline-offset: 2px; border-radius: 7px; }
  .setup-field:has(select:disabled) { opacity: .6; }
  .control-icon, .compact-value { display: block; pointer-events: none; }
  .control-icon { position: absolute; left: 6px; top: 50%; transform: translateY(-50%); color: var(--accent); }
  #field-difficulty .control-icon { display: none; }
  .compact-value {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 3px;
    height: 100%;
    padding: 0 6px 0 22px;
    border: 1px solid var(--border);
    border-radius: 7px;
    background: var(--paper);
    font-size: .82rem;
    font-weight: 700;
  }
  #field-difficulty .compact-value { padding-left: 7px; }
  .compact-value::after {
    content: "";
    width: 5px;
    height: 5px;
    flex: 0 0 5px;
    border-right: 1px solid;
    border-bottom: 1px solid;
    transform: translateY(-2px) rotate(45deg);
  }
  .action { width: 44px; min-height: 44px; padding: 0; font-size: 1.1rem; }
  .action > .action-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
  main { gap: 10px; }
  .sheet { min-width: 0; }
  .sheet-head { margin-bottom: 7px; font-size: .67rem; }
  .track-actions:not(:has(button:not([hidden]))) { display: none; }
  .sheet:not(.racing) .board { min-width: 0; }
  .sheet:not(.racing) .track-scroll { max-height: none; }
  #track-dialog .racing:not(.overview) .board { min-width: 1800px; }
  #track-dialog .target { width: 34px; }
  .move-table button { min-height: 44px; }
}

.racing .track-scroll { max-height: min(60dvh, 680px); }
.racing:not(.overview) .board { min-width: 1350px; }
.large-track.racing:not(.overview) .board { min-width: 2160px; }
.sheet.overview .board { min-width: 0; }
.sheet.overview .track-scroll { max-height: none; }
#track-dialog .track-scroll { max-height: none; }
#track-dialog .large-track.racing:not(.overview) .board { min-width: 2560px; }
@media (max-width: 860px), (pointer: coarse) {
  .racing:not(.overview) .board { min-width: 1200px; }
  .large-track.racing:not(.overview) .board { min-width: 1920px; }
  .racing .track-scroll { max-height: 52dvh; }
}

.license-text { white-space: pre-wrap; overflow-wrap: anywhere; font: inherit; }
