@media (max-width: 920px), (pointer: coarse) {
  body:not(:has(#setupDialog[open])) {
    overflow: hidden;
  }

  body:not(:has(#setupDialog[open])) .app {
    position: fixed;
    inset: 0;
    width: 100dvw;
    height: 100dvh;
    max-width: none;
    min-height: 0;
    margin: 0;
    display: grid;
    container-type: size;
    background: var(--bg);
  }

  body:not(:has(#setupDialog[open])) .topbar {
    flex-wrap: nowrap;
    gap: 12px;
    padding-right: 10px;
  }

  body:not(:has(#setupDialog[open])) .game-badge {
    min-width: 0;
    flex: 0 1 auto;
    gap: 3px;
    padding: 5px 10px;
  }

  body:not(:has(#setupDialog[open])) .game-progress {
    padding: 0;
    font-size: 8px;
  }

  body:not(:has(#setupDialog[open])) .game-progress strong {
    font-size: 11px;
  }

  body:not(:has(#setupDialog[open])) .history-panel {
    min-height: 0;
    overflow: hidden;
  }

  body:not(:has(#setupDialog[open])) .text-button {
    min-height: 26px;
    padding: 3px;
    font-size: 9px;
  }

  body:not(:has(#setupDialog[open])) .desktop-history {
    display: flex;
    flex: 1;
    min-height: 0;
    padding-top: 5px;
  }

  body:not(:has(#setupDialog[open])) .history-player-group:not([hidden]) {
    display: flex;
    flex-direction: column;
    min-height: 0;
    width: 100%;
  }

  body:not(:has(#setupDialog[open])) .history-player-group[hidden] {
    display: none;
  }

  body:not(:has(#setupDialog[open])) .history-player-heading {
    flex-shrink: 0;
    margin: 0 0 4px;
    padding-bottom: 4px;
    font-size: 10px;
    color: var(--player);
    border-bottom: 1px solid var(--player);
    overflow-wrap: anywhere;
  }

  body:not(:has(#setupDialog[open])) .history-player-rounds {
    min-height: 0;
    overflow: auto;
  }

  body:not(:has(#setupDialog[open])) .history-round {
    padding: 5px 2px;
    border-bottom: 1px solid var(--line);
  }

  body:not(:has(#setupDialog[open])) .scoreboard {
    min-height: 0;
    display: grid;
    --closed-mark-size: clamp(22px, 7cqh, 42px);
  }

  body:not(:has(#setupDialog[open])) .marks-table {
    height: 100%;
    min-height: 0;
  }

  body:not(:has(#setupDialog[open])) .marks-table tbody tr {
    height: auto;
  }

  body:not(:has(#setupDialog[open])) .marks-table tbody .target-number {
    padding: 1px;
    font-size: clamp(20px, 6cqh, 42px);
    line-height: 1;
  }

  body:not(:has(#setupDialog[open])) .target-number span {
    display: none;
  }

  body:not(:has(#setupDialog[open])) .mark-icon {
    width: var(--closed-mark-size);
    height: var(--closed-mark-size);
  }

  body:not(:has(#setupDialog[open])) .dart-slots {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  body:not(:has(#setupDialog[open])) .dart-slot {
    min-height: clamp(28px, 9cqh, 46px);
    gap: 3px;
    padding: 4px;
  }

  body:not(:has(#setupDialog[open])) .dart-slot > span {
    font-size: 7px;
  }

  body:not(:has(#setupDialog[open])) .dart-slot strong {
    font-size: 14px;
  }

  body:not(:has(#setupDialog[open])) .match-footer {
    min-height: 0;
    grid-template-columns: minmax(0, 1fr) 90px minmax(0, 1fr);
    padding: 0 10px;
    gap: 8px;
  }

  body:not(:has(#setupDialog[open])) .footer-player {
    padding: 5px 8px;
    gap: 6px;
    overflow: hidden;
  }

  body:not(:has(#setupDialog[open])) .footer-player > div {
    gap: 3px;
  }

  body:not(:has(#setupDialog[open])) .footer-player > div > strong {
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  body:not(:has(#setupDialog[open])) .player-label {
    font-size: 7px;
  }

  body:not(:has(#setupDialog[open])) .player-mpr {
    font-size: 8px;
  }

  body:not(:has(#setupDialog[open])) .player-mpr b {
    font-size: 12px;
  }

  body:not(:has(#setupDialog[open])) .footer-score {
    font-size: clamp(30px, 12cqh, 65px);
    line-height: 1;
  }

  body:not(:has(#setupDialog[open])) .leg-score {
    gap: 4px;
  }

  body:not(:has(#setupDialog[open])) .leg-score > span {
    font-size: 8px;
  }

  body:not(:has(#setupDialog[open])) .leg-score strong {
    font-size: 23px;
  }

  body:not(:has(#setupDialog[open])) .leg-score div span {
    font-size: 7px;
  }

  body:not(:has(#setupDialog[open])) .message {
    display: none;
  }

  body:not(:has(#setupDialog[open])) .storage-warning {
    margin: 0;
    padding: 2px;
    font-size: 9px;
  }

}

@media (orientation: portrait) and (max-width: 920px),
       (orientation: portrait) and (pointer: coarse) {
  body:not(:has(#setupDialog[open])) .app {
    inset: auto;
    top: 50%;
    left: 50%;
    width: 100dvh;
    height: 100dvw;
    transform: translate(-50%, -50%) rotate(90deg);
  }

  body:not(:has(#setupDialog[open])) dialog:not(#setupDialog) {
    position: fixed;
    inset: auto;
    top: 50%;
    left: 50%;
    margin: 0;
    width: min(580px, calc(100dvh - 28px));
    max-height: calc(100dvw - 24px);
    transform: translate(-50%, -50%) rotate(90deg);
  }

}

@media(pointer:coarse),(max-width:920px) {
  #setupDialog {
    width: calc(100% - 12px);
    height: calc(100dvh - 12px);
    max-height: none;
    margin: auto;
  }

  #setupDialog .dialog-card {
    height: 100%;
    min-height: 0;
    padding: 8px;
    display: grid;
    grid-template-rows: 24px minmax(0,1fr) clamp(32px,5.5dvh,44px);
    gap: 6px;
    overflow: hidden;
  }

  #setupDialog .dialog-heading {
    margin: 0;
    min-height: 0;
  }

  #setupDialog .dialog-heading h2 {
    font-size: 12px;
  }

  #setupDialog .close-button {
    min-width: 24px;
    min-height: 24px;
    font-size: 22px;
    line-height: 1;
  }

  #setupDialog .form-grid {
    margin: 0;
    min-height: 0;
    grid-template-columns: minmax(0,1fr);
    grid-template-rows: repeat(2,minmax(0,2fr)) repeat(2,minmax(0,1fr)) minmax(0,1.2fr);
    gap: clamp(3px,.7dvh,7px);
  }

  #setupDialog .field {
    min-width: 0;
    min-height: 0;
    gap: 3px;
    align-content: stretch;
    grid-template-rows: auto minmax(0,1fr);
  }

  #setupDialog .setup-player {
    grid-template-rows: 24px minmax(0,.8fr) minmax(0,1.1fr);
    gap: 4px;
  }

  #setupDialog .player-setup-heading {
    font-size: 10px;
    gap: 4px;
  }

  #setupDialog .player-setup-heading > label {
    font-size: 10px;
    letter-spacing: 0;
    white-space: nowrap;
  }

  #setupDialog .field .setup-switch {
    font-size: 10px;
    min-height: 24px;
    gap: 5px;
    font-weight: 900;
  }

  #setupDialog .com-options {
    grid-template-columns: minmax(0,1fr) 64px;
    min-height: 0;
    gap: 6px;
  }

  #setupDialog .field > label {
    font-size: clamp(10px,1.6dvh,12px);
    line-height: 1.2;
    letter-spacing: 0;
  }

  #setupDialog .field input:not([type="checkbox"]), #setupDialog .field select:not([hidden]) {
    min-height: 0;
    height: 100%;
    padding: 3px 7px;
    font-size: 12px;
  }

  #setupDialog .setup-choice, #setupDialog .numeric-choices .setup-choice {
    min-height: 0;
    height: 100%;
    padding: 2px 1px;
    font-size: clamp(10px,2.8vw,13px);
    line-height: 1.2;
  }

  #setupDialog [data-setup-choice="roundLimit"] .setup-choice, #setupDialog [data-setup-choice="legLimit"] .setup-choice {
    font-size: clamp(16px,4.5vw,22px);
    font-weight: 700;
  }

  #setupDialog .setup-choice-field {
    grid-template-rows: auto minmax(0,1fr);
  }

  #setupDialog .setup-choice-field:has(small) {
    grid-template-rows: auto minmax(0,1fr) auto;
  }

  #setupDialog .setup-choice-field small {
    font-size: 9px;
  }

  #setupDialog .primary-button {
    height: 100%;
    min-height: 0;
    padding: 4px 8px;
    font-size: 13px;
  }

}

@media (max-width:920px), (pointer:coarse) {
  body:not(:has(#setupDialog[open])) .history-panel {
    grid-column: 1;
    grid-row: 1;
    order: 0;
  }

  body:not(:has(#setupDialog[open])) .scoreboard {
    grid-column: 2;
    grid-row: 1;
    order: 1;
    grid-template-rows: minmax(0,1fr);
  }

  body:not(:has(#setupDialog[open])) .board-input {
    padding: 2px;
  }

  body:not(:has(#setupDialog[open])) .board-hit-buttons button {
    min-height: 0;
    padding: 0;
    font-size: 13px;
  }

  body:not(:has(#setupDialog[open])) .board-miss {
    min-height: 0;
    font-size: 8px;
  }

}

@media (max-width:920px), (pointer:coarse) {
  body:not(:has(#setupDialog[open])) .marks-table .board-input.player-one {
    padding: 2px 10px 2px 0;
  }

  body:not(:has(#setupDialog[open])) .marks-table .board-input.player-two {
    padding: 2px 0 2px 10px;
  }

  body:not(:has(#setupDialog[open])) .marks-table .target-number {
    text-align: center;
    padding-inline: 0;
  }

}

@media (max-width:920px), (pointer:coarse) {
  body:not(:has(#setupDialog[open])) .board-hit-buttons {
    --hit-gap: 3px;
    gap: var(--hit-gap);
  }

}

@media (max-width:920px), (pointer:coarse) {
  body:not(:has(#setupDialog[open])) .history-player-rounds .history-round {
    gap: 2px;
    padding: 5px 0;
  }

}

@media (max-width:920px), (pointer:coarse) {
  body:not(:has(#setupDialog[open])) .topbar {
    min-height: 0;
  }

  body:not(:has(#setupDialog[open])) .game-badge {
    padding-block: 4px;
  }

  body:not(:has(#setupDialog[open])) .game-progress {
    display: flex;
    align-items: center;
  }

  body:not(:has(#setupDialog[open])) #nextBtn {
    text-align: center;
  }

}

body:not(:has(#setupDialog[open])) .app {
  --side-width: clamp(90px,13vw,170px);
  --layout-gap: 8px;
  display: grid;
  grid-template-columns: var(--side-width) minmax(0,1fr);
  grid-template-rows: 44px minmax(0,1fr) clamp(74px,11.5dvh,110px) auto;
  column-gap: var(--layout-gap);
  padding: 0 6px;
  container-type: size;
}

body:not(:has(#setupDialog[open])) .topbar {
  grid-column: 1 / -1;
  grid-row: 1;
  display: grid;
  grid-template-columns: var(--side-width) minmax(0,1fr);
  column-gap: var(--layout-gap);
  padding: 0;
  min-height: 0;
  position: relative;
}

body:not(:has(#setupDialog[open])) .game-badge {
  grid-column: 1;
  grid-row: 1;
  min-width: 0;
  padding: 4px;
}

body:not(:has(#setupDialog[open])) .game-badge strong {
  font-size: 12px;
}

body:not(:has(#setupDialog[open])) .game-progress {
  grid-column: 2;
  grid-row: 1;
  justify-self: start;
  gap: 10px;
}

body:not(:has(#setupDialog[open])) .topbar .dart-slots {
  grid-column: 2;
  grid-row: 1;
  justify-self: center;
  display: grid;
  grid-template-columns: repeat(3,minmax(0,1fr));
  width: 22%;
  height: 32px;
  gap: 5px;
}

body:not(:has(#setupDialog[open])) .topbar .dart-slot {
  min-height: 0;
  height: 100%;
  padding: 1px 2px;
  gap: 1px;
  flex-direction: column;
}

body:not(:has(#setupDialog[open])) .topbar .dart-slot > span {
  font-size: 7px;
}

body:not(:has(#setupDialog[open])) .topbar .dart-slot strong {
  font-size: min(26px,40cqw);
  line-height: 1;
}

body:not(:has(#setupDialog[open])) .history-panel {
  grid-column: 1;
  grid-row: 2 / 5;
  min-height: 0;
  padding: 6px 0 6px;
  overflow: hidden;
}

body:not(:has(#setupDialog[open])) .history-panel .desktop-history {
  display: flex;
  flex: 1;
  min-height: 0;
}

body:not(:has(#setupDialog[open])) .scoreboard {
  grid-column: 2;
  grid-row: 2;
  padding-top: 6px;
}

body:not(:has(#setupDialog[open])) .match-footer {
  grid-column: 2;
  grid-row: 3;
  min-width: 0;
  padding: 0;
  grid-template-columns: minmax(0,1fr) clamp(65px,10vw,140px) minmax(0,1fr);
  position: relative;
  --score-edge: min(31.5%,304px);
}

body:not(:has(#setupDialog[open])) .message {
  grid-column: 2;
  grid-row: 4;
  min-height: 0;
  padding: 5px 2px;
}

body:not(:has(#setupDialog[open])) .storage-warning {
  grid-column: 2;
}

body:not(:has(#setupDialog[open])) .history-player-rounds .history-round {
  height: 30px;
  min-height: 30px;
  max-height: 30px;
  padding: 0;
  grid-template-columns: 28px repeat(3,minmax(0,1fr));
}

body:not(:has(#setupDialog[open])) .history-round > span:first-child {
  font-size: 14px;
}

body:not(:has(#setupDialog[open])) .history-dart-symbol {
  height: 20px;
  font-size: 17px;
  overflow: hidden;
}

body:not(:has(#setupDialog[open])) .history-dart-symbol .mark-icon {
  width: 16px;
  height: 16px;
  max-width: 100%;
}

@media (max-width:920px), (pointer:coarse) {
  body:not(:has(#setupDialog[open])) .app {
    --side-width: clamp(76px,12vw,120px);
    --layout-gap: 8px;
    padding-inline: 8px;
    grid-template-rows: 36px minmax(0,1fr) clamp(56px,16vmin,100px) auto;
  }

  body:not(:has(#setupDialog[open])) .game-badge strong {
    font-size: 10px;
  }

  body:not(:has(#setupDialog[open])) .game-progress strong, body:not(:has(#setupDialog[open])) .game-progress > span {
    font-size: 10px;
  }

  body:not(:has(#setupDialog[open])) .game-progress {
    gap: 7px;
  }

  body:not(:has(#setupDialog[open])) .topbar .dart-slots {
    height: 28px;
    gap: 3px;
  }

  body:not(:has(#setupDialog[open])) .topbar .dart-slot strong {
    font-size: min(20px,40cqw);
  }

  body:not(:has(#setupDialog[open])) .history-controls {
    gap: 4px;
  }

  body:not(:has(#setupDialog[open])) .history-controls button {
    min-height: 27px;
    font-size: 10px;
    padding: 4px 1px;
  }

  body:not(:has(#setupDialog[open])) .history-player-rounds .history-round {
    height: 25px;
    min-height: 25px;
    max-height: 25px;
    grid-template-columns: 23px repeat(3,minmax(0,1fr));
  }

  body:not(:has(#setupDialog[open])) .history-round > span:first-child {
    font-size: 12px;
  }

  body:not(:has(#setupDialog[open])) .history-dart-symbol .mark-icon {
    width: 13px;
    height: 13px;
  }

}

/* Scores face the inner edge of each MISS control. */
body:not(:has(#setupDialog[open])) .match-footer .footer-score {
  position: absolute;
  top: 50%;
}
body:not(:has(#setupDialog[open])) #footerScore0 {
  left: calc(var(--score-edge) + 1ch);
  transform: translate(-100%,-50%);
}
body:not(:has(#setupDialog[open])) #footerScore1 {
  right: calc(var(--score-edge) + 1ch);
  transform: translate(100%,-50%);
}
body:not(:has(#setupDialog[open])) .footer-player.player-two {
  justify-content: flex-end;
}
@media (max-width:920px), (pointer:coarse) {
  body:not(:has(#setupDialog[open])) .match-footer {
    --score-edge: min(25%,200px);
  }
}


body:not(:has(#setupDialog[open])) .topbar .dart-slot {
  container-type: inline-size;
}
body:not(:has(#setupDialog[open])) .topbar .dart-slot .throw-placeholder {
  color: var(--muted);
  opacity: .35;
  font-weight: 400;
}

.table-player-heading { display: none; }
@media (orientation: landscape) and (pointer: coarse), (orientation: landscape) and (hover: none) {
  body:not(:has(#setupDialog[open])) .topbar .table-player-heading { display: block; position: relative; grid-area: 1 / 2; align-self: stretch; pointer-events: none; }
  body:not(:has(#setupDialog[open])) .table-player-heading span { position: absolute; top: 50%; transform: translate(-50%, -50%); font-size: 10px; line-height: 14px; white-space: nowrap; }
  body:not(:has(#setupDialog[open])) .table-player-heading span:first-child { left: 28%; }
  body:not(:has(#setupDialog[open])) .table-player-heading span:last-child { left: 72%; }
  body:not(:has(#setupDialog[open])) .scoreboard { padding-bottom: 6px; }
  body:not(:has(#setupDialog[open])) .marks-table tbody :is(td, th) { padding-block: 0; }
  body:not(:has(#setupDialog[open])) .marks-table tbody :is(.board-input.player-one, .board-input.player-two) { padding-block: 0; }
  body:not(:has(#setupDialog[open])) .marks-table tbody td { line-height: 0; }
  body:not(:has(#setupDialog[open])) .board-hit-buttons button { line-height: 1; }
  body:not(:has(#setupDialog[open])) .marks-table .mark-icon { vertical-align: middle; }
}
