/* Shared landscape canvas. Mobile setup stays upright; games rotate in portrait. */
html, body { min-width: 0; width: 100%; height: 100%; overflow: hidden; background: #090a0b; }
.game-viewport {
  position: fixed; inset: 0; width: 100dvw; height: 100dvh;
  container-type: size; background: #090a0b;
  --footer-height: clamp(76px, 14cqh, 148px);
  --score-size: min(25cqw, 42cqh, 420px);
  --rail-width: 20%;
}
@media (orientation: portrait) {
  .game-viewport {
    inset: auto; top: 50%; left: 50%; width: 100dvh; height: 100dvw;
    transform: translate(-50%, -50%) rotate(90deg);
  }
}
body, button, input, select, textarea,
.score-value strong, .score-value.to-go strong,
.match-heading .match-leg-count, .match-player-heading .footer-remaining,
.com-throw-dart strong, .com-throw-total strong {
  font-family: Meiryo, "メイリオ", "Noto Sans JP", sans-serif;
}
.app { width: 100%; max-width: none; height: 100%; padding: 0; }
.compact-game {
  position: relative; display: block; width: 100%; max-width: none;
  height: 100%; min-height: 0; margin: 0; gap: 0;
  background: radial-gradient(ellipse at 52% 25%, #292b2c, #0b0d0e 65%, #050607);
}
.scoreboard { position: static; display: block; height: 100%; overflow: visible; border: 0; background: transparent; }
.score-menu { display: contents; }
.score-menu .game-title {
  position: absolute; top: 0; left: 0; z-index: 3; width: var(--rail-width);
  padding: clamp(6px, 1.2cqh, 14px); white-space: normal;
  color: #fff; background: #4089ee; font-size: 12px; font-weight: 700; line-height: 1.5;
}
.desktop-round {
  position: absolute; display: flex; top: clamp(62px, 10cqh, 96px); left: 0;
  width: var(--rail-width); padding: 0 clamp(6px, 1cqw, 14px);
  color: #eee; font-size: clamp(13px, 1.8cqw, 30px); gap: 4px;
}
#editHistoryBtn { font-size: clamp(11px, 1.2cqw, 16px); padding: 5px 8px; }
.history-panel {
  position: absolute; width: var(--rail-width); left: 0; top: clamp(98px, 16cqh, 158px);
  bottom: calc(var(--footer-height) + 8px); padding-inline: clamp(6px, 1cqw, 14px);
  background: transparent; overflow: visible; isolation: auto;
}
.history-panel .score-sheet-wrap { height: 100%; max-height: none; overflow: auto; }
.player-history { min-width: 0; color: #eee; }
.player-history-heading {
  display: flex; align-items: baseline; gap: 6px; justify-content: space-between;
  border-bottom: 3px solid #D20A13; padding-bottom: 5px;
}
.player-history[data-player="1"] .player-history-heading { border-color: #1853B5; }
.player-history .player-history-heading h3 {
  flex: 1; min-width: 0; margin: 0; padding: 0; border: 0;
  font-size: clamp(12px, 1.5cqw, 24px);
}
.history-average { display: block; flex-shrink: 0; font-size: clamp(10px, 1.25cqw, 21px); color: #ddd; white-space: nowrap; }
.player-history-row { min-height: clamp(26px, 4.4cqh, 44px); font-size: clamp(13px, 1.7cqw, 28px); padding: 2px 4px; }
.player-history-row strong { font-size: clamp(18px, 2.6cqw, 42px); }
.score-head-grid, .score-head-grid.single-player {
  position: absolute; inset: 0 0 calc(var(--footer-height) + 14cqh);
  display: flex; align-items: center; justify-content: center; padding: 0;
  background: transparent; pointer-events: none;
}
.score-head-grid #gameRule {
  position: absolute; left: 50%; bottom: calc(50% + min(15cqw, 25cqh, 250px) + 8px);
  z-index: 2; width: 52%; min-width: 0; height: auto; flex: none;
  transform: translateX(-50%); overflow: visible; text-overflow: clip;
  color: #bfc5c7; font-size: clamp(10px, 1.2cqw, 16px);
  font-weight: 600; line-height: 1.2; text-align: center; white-space: normal;
}
.score-head-grid .score-player, .score-head-grid .score-player.active, .score-head-grid .score-player.player-one {
  flex: 0 0 52%; padding: 0; border: 0; background: transparent;
}
.score-head-grid .score-player:not(.active) { display: none; }
.score-head-grid .score-player .score-values { display: block; width: 100%; margin: 0; }
.score-head-grid .score-value.to-go { width: 100%; text-align: center; }
.score-head-grid .score-value.to-go span { display: none; }
.score-head-grid .score-player .score-value.to-go strong,
.score-head-grid .score-player.active .score-value.to-go strong {
  font-family: Meiryo, "メイリオ", "Noto Sans JP", sans-serif;
  font-size: var(--score-size); font-weight: 600 !important; line-height: 1.2;
  color: #f4f4f0; letter-spacing: .015em; text-indent: .015em; font-variant-numeric: tabular-nums;
  text-shadow: 0 3px 6px rgba(170,170,170,.24);
}
.match-heading {
  position: absolute; left: 0; right: 0; bottom: 0; height: var(--footer-height);
  padding: 0 clamp(4px, 1cqw, 20px); gap: clamp(3px, .6cqw, 12px); border: 0; background: #050505; color: #fff;
  grid-template-columns: minmax(0,1fr) clamp(26px,4cqw,72px) auto clamp(26px,4cqw,72px) minmax(0,1fr);
}
.match-player-heading {
  display: flex; align-items: center; justify-content: space-between; align-self: stretch;
  min-width: 0; padding: clamp(4px,1cqw,14px); gap: clamp(4px,1cqw,16px); background: #050505;
}
#playerHeading0.throwing { background: #D20A13; }
#playerHeading1.throwing { background: #1853B5; }
.match-heading .score-player-name { flex: 1; min-width: 0; color: #fff; text-align: center; font-size: clamp(14px,2.6cqw,44px); }
.match-heading .match-leg-count { color: #fff; font-size: clamp(22px,3.6cqw,60px); }
.match-heading .match-leg-title { color: #fff; font-size: clamp(10px,1.5cqw,24px); }
.match-player-heading .footer-remaining {
  display: block; flex-shrink: 0; color: #aaa; font-size: clamp(30px,6cqw,110px);
  font-weight: 600 !important; line-height: 1.2; letter-spacing: -.04em;
}
#playerHeading1 .footer-remaining { order: -1; }
.match-player-heading.throwing .footer-remaining { color: #fff; }
.compact-input { display: none; }
.keypad-toggle { display: none; }
.score-menu #newGameBtn { color: #eee; }
.live-history { color: #fff; background: #ffffff18; }
.score-menu-actions {
  position: absolute; top: auto; bottom: calc(var(--footer-height) + 12px); right: clamp(6px,1cqw,18px);
  display: flex; flex-direction: column; align-items: stretch; flex-wrap: nowrap;
  width: clamp(94px,15cqw,210px); gap: clamp(4px,.9cqh,10px);
  max-height: calc(100cqh - var(--footer-height) - 24px); overflow-y: auto; z-index: 4;
}
.score-menu .score-menu-actions .btn, .score-menu .score-menu-actions .mic-btn.compact {
  width: 100%; min-height: clamp(32px,4.5cqh,44px); flex-shrink: 0;
  justify-content: center; padding: 6px; border: 1px solid #454748;
  color: #eee; background: #191b1dcc; font-size: clamp(11px,1cqw,14px); text-align: center;
}
.history-panel .history-checkout {
  position: fixed; top: auto;
  bottom: calc(50cqh + var(--footer-height)/2 + 7cqh + var(--score-size)/2);
  left: 50%; right: auto; transform: translateX(-50%);
  width: 50cqw; height: auto; min-height: 32px; padding: 0; z-index: 3;
  border: 0; background: transparent; backdrop-filter: none; gap: 3px;
}
.history-checkout span { color: #aaa; font-size: clamp(8px,1cqw,12px); }
.history-checkout strong { color: #fff; font-size: clamp(16px,2.6cqw,40px); }
.com-throw-overlay {
  inset: auto auto calc(28.5cqh + var(--footer-height)*.75 - var(--score-size)*.2 - clamp(25px,5cqh,54px)) 50%;
  transform: translateX(-50%);
  width: 48%; height: clamp(50px,10cqh,108px); padding: 0; z-index: 10;
}
.com-throw-card { display: flex; align-items: stretch; gap: 10px; width: 100%; height: 100%; margin: 0; padding: 0; border: 0; background: transparent; animation: none; }
.com-throw-heading { display: none; }
.com-throw-darts, .com-throw-darts[data-visible] { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); flex: 3; min-width: 0; margin: 0; gap: 8px; }
.com-throw-dart { position: relative; height: 100%; min-width: 0; border: 0; border-bottom: 2px solid #888; padding: 0; background: transparent; }
.com-throw-dart.step-hidden { display: block; }
.com-throw-dart.step-hidden > * { visibility: hidden; }
.com-throw-dart.step-show { animation: none; }
.com-throw-dart strong, .com-throw-total strong { color: #fff; font-size: clamp(22px,3.6cqw,58px); }
.com-throw-dart span, .com-throw-dart small, .com-throw-total span { color: #bfc5c7; font-size: clamp(8px,.8cqw,12px); }
.com-throw-dart small { min-height: 0; margin-top: 0; }
.com-throw-total { display: flex; flex: 1; min-width: 0; flex-direction: column; align-items: center; justify-content: center; margin: 0; padding: 0; border: 0; border-bottom: 2px solid #ddd; gap: 2px; }
.com-throw-total.step-hidden { visibility: visible; }
.com-throw-total.step-hidden > * { visibility: hidden; }
.modal { position: absolute; max-width: 100%; padding: 10px; }
.modal > form, .modal > .stats-card, .modal > .result-card { max-height: calc(100cqh - 20px); overflow: auto; }
.form-grid { grid-template-columns: repeat(6,minmax(0,1fr)); }
.field.half { grid-column: span 3; }
@media (pointer: coarse), (max-width: 920px) {
  #setupModal .setup {
    width: 100%; max-width: 520px;
  }
  #setupModal .form-grid {
    grid-template-columns: minmax(0, 1fr);
  }
  #setupModal .field {
    grid-column: 1 / -1;
  }
  .pc-only { display: none; }
  .game-viewport {
    --footer-height: clamp(56px,18cqh,76px);
    --mobile-button-height: clamp(18px,6cqh,26px);
    --mobile-menu-height: calc(5 * var(--mobile-button-height) + 12px);
    --mobile-title-height: clamp(36px,10cqh,48px);
    --mobile-history-row-height: clamp(12px,4.2cqh,24px);
    --mobile-history-heading-height: 18px;
  }
  .score-menu .game-title {
    height: var(--mobile-title-height); overflow: auto;
    padding: 3px 6px; font-size: 10px; line-height: 1.2;
  }
  .desktop-round {
    top: calc(var(--mobile-title-height) + 2px); height: 20px;
    font-size: clamp(11px,1.35cqw,16px); padding-inline: 6px;
  }
  #editHistoryBtn {
    min-height: 20px; height: 20px; padding: 1px 6px;
    font-size: clamp(10px,1.2cqw,13px);
  }
  .score-menu-actions {
    left: clamp(6px,1cqw,14px); right: auto;
    bottom: calc(var(--footer-height) + 6px);
    width: calc(var(--rail-width) - clamp(12px,2cqw,28px));
    display: grid; grid-template-columns: minmax(0,1fr);
    gap: 3px; height: var(--mobile-menu-height);
    max-height: none; grid-auto-rows: var(--mobile-button-height); overflow: visible;
  }
  .score-menu .score-menu-actions .btn, .score-menu .score-menu-actions .mic-btn.compact {
    min-width: 0; min-height: 0; height: var(--mobile-button-height); padding: 1px 2px;
    font-size: clamp(9px,1.15cqw,13px); line-height: 1.2;
    white-space: normal;
  }
  .history-panel {
    top: calc(var(--mobile-title-height) + 26px); bottom: auto;
    height: calc(var(--mobile-history-heading-height) + 5 * var(--mobile-history-row-height));
  }
  .player-history-heading {
    position: sticky; top: 0; z-index: 2; height: var(--mobile-history-heading-height);
    box-sizing: border-box; background: #121415; padding-bottom: 2px;
  }
  .player-history-row {
    height: var(--mobile-history-row-height); min-height: 0; padding: 0 4px;
    font-size: clamp(11px,1.5cqw,20px); align-items: center;
  }
  .player-history-row strong { font-size: clamp(13px,1.8cqw,25px); line-height: 1; }
  .compact-input {
    position: absolute; display: flex; flex-direction: column;
    right: clamp(6px,1cqw,14px); top: clamp(8px,2cqh,20px);
    bottom: calc(var(--footer-height) + 8px);
    width: 24%; height: auto; padding: 0; overflow: auto;
    border: 0; background: transparent; z-index: 4;
  }
  .compact-input .checkout-actions { gap: 4px; margin-bottom: 6px; flex-shrink: 0; }
  .compact-input .checkout-actions .player-action-btn { min-height: 28px; padding: 3px; font-size: clamp(10px,1.2cqw,15px); }
  .voice-input .keypad-toggle {
    display: block; align-self: flex-end; flex-shrink: 0;
    width: calc((100% - 8px) / 3); min-height: 28px; margin-bottom: 6px;
    padding: 2px; border: 1px solid #4a5053; background: #24282a;
    color: #eee; font-size: clamp(9px,1.1cqw,13px); cursor: pointer;
  }
  .voice-input:not(.keypad-expanded) {
    --score-size: min(28cqw, 46cqh, 460px);
  }
  .voice-input:not(.keypad-expanded) .compact-input { bottom: auto; overflow: visible; }
  .voice-input:not(.keypad-expanded) .compact-input .keypad,
  .voice-input:not(.keypad-expanded) .compact-input .quick-score { display: none; }
  .voice-input:not(.keypad-expanded) .score-head-grid .score-player { flex-basis: 60%; }
  .compact-input .keypad {
    flex: 1; min-height: 120px; display: grid;
    grid-template-columns: repeat(3,minmax(0,1fr)); grid-template-rows: repeat(4,minmax(0,1fr));
    border: 0; gap: 4px; width: 100%;
  }
  .compact-input .keypad button {
    min-height: 0; padding: 3px; color: #eee; background: #24282a;
    border: 1px solid #4a5053; font-size: clamp(19px,2.7cqw,34px);
  }
  .compact-input .keypad .key-enter { font-size: clamp(10px,1.3cqw,17px); color: #17252c; background: #c3d825; }
  .compact-input .quick-score { margin-top: 6px; padding: 0; border: 0; background: transparent; flex-shrink: 0; }
  .compact-input .quick-score > div { gap: 4px; }
  .compact-input .quick-score button {
    min-height: 28px; padding: 2px; font-size: clamp(11px,1.4cqw,17px);
    color: #eee; background: #24282a; border-color: #4a5053;
  }
}
/* Phone setup uses one upright viewport; each option group stays on one line. */
@media (pointer: coarse), (max-width: 920px) {
  #setupModal {
    padding: max(6px, env(safe-area-inset-top)) max(6px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left));
    grid-template-rows: minmax(0, 1fr);
    place-items: stretch center;
    overflow: hidden;
  }
  #setupModal .setup {
    width: 100%; max-width: 520px; height: 100%; max-height: none;
    min-height: 0; margin: 0; padding: 8px;
    display: grid; grid-template-rows: minmax(0, 1fr) clamp(32px, 5.5dvh, 44px);
    gap: 6px; overflow: hidden;
  }
  #setupModal .setup .form-grid {
    min-height: 0; margin: 0;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: repeat(6, minmax(0, 1fr)) 1px repeat(2, minmax(0, 1.15fr)) minmax(0, 1fr);
    gap: clamp(3px, .7dvh, 7px) 8px;
  }
  #setupModal .setup .field,
  #setupModal .setup .field.half {
    grid-column: 1 / -1; min-width: 0; min-height: 0;
    grid-template-rows: auto minmax(0, 1fr); align-content: stretch; gap: 3px;
  }
  #setupModal .setup .field.com-avg-field { grid-column: span 1; }
  #setupModal .setup .field > label {
    margin: 0; font-size: clamp(10px, 1.6dvh, 12px); line-height: 1.2; letter-spacing: 0;
  }
  #setupModal .setup .setup-choices {
    min-width: 0; min-height: 0; display: flex; flex-wrap: nowrap; gap: 3px;
  }
  #setupModal .setup .setup-choice {
    flex: 1 1 0; width: 0; min-width: 0; min-height: 0; height: 100%;
    padding: 2px 1px; font-size: clamp(10px, 2.8vw, 13px); line-height: 1.2;
    white-space: nowrap; letter-spacing: 0;
  }
  #setupModal .setup [data-choice-group="startScore"] .setup-choice,
  #setupModal .setup [data-choice-group="roundLimit"] .setup-choice,
  #setupModal .setup [data-choice-group="legLimit"] .setup-choice {
    font-size: clamp(16px, 4.5vw, 22px);
    font-weight: 700;
  }
  #setupModal .setup .setup-section-divider { margin: 0; }
  #setupModal .setup .player-name-heading {
    min-height: 0; margin: 0; flex-wrap: nowrap; gap: 6px;
  }
  #setupModal .setup .player-name-heading > label { font-size: 10px; }
  #setupModal .setup .com-toggle { min-height: 24px; gap: 5px; font-size: 10px; }
  #setupModal .setup .field input:not([type="checkbox"]),
  #setupModal .setup .field select:not([hidden]) {
    min-height: 0; height: 100%; padding: 3px 7px; font-size: 12px;
  }
  #setupModal .setup > .start-btn {
    margin: 0; padding: 4px 8px; min-height: 0; height: 100%; font-size: 13px;
  }
}

.match-leg-summary { display: contents; }
@media (orientation: landscape) and (pointer: coarse), (orientation: landscape) and (hover: none) {
  .game-viewport {
    --rail-width: calc(24cqw + 2 * clamp(6px,1cqw,14px));
    --footer-height: max(clamp(48px,15cqh,64px), calc(clamp(30px,6cqw,110px) + clamp(4px,1cqw,14px) * 2 + 1px));
    --mobile-title-height: 20px;
    --mobile-menu-height: calc(3 * var(--mobile-button-height) + 6px);
  }
  .score-menu .game-title { left: clamp(6px,1cqw,14px); width: calc(var(--rail-width) - clamp(12px,2cqw,28px)); padding: 3px 4px; overflow: hidden; }
  .desktop-round { padding: 0 clamp(6px,1cqw,14px); align-items: center; gap: 4px; line-height: 20px; }
  #editHistoryBtn { display: grid; place-items: center; flex-shrink: 0; line-height: 1; white-space: nowrap; }
  .score-menu-actions { bottom: 6px; }
  .history-panel { width: var(--rail-width); height: auto; bottom: calc(var(--mobile-menu-height) + 12px); }
  .score-head-grid #gameRule { top: 8px; bottom: auto; left: var(--rail-width); right: var(--rail-width); width: auto; transform: none; }
  .match-heading { left: var(--rail-width); right: calc(24% + 2 * clamp(6px,1cqw,14px)); padding-inline: 0; grid-template-columns: repeat(2, minmax(0,1fr)); }
  .match-leg-summary { position: absolute; display: flex; align-items: center; justify-content: center; gap: 8px; left: calc(50cqw - var(--rail-width)); bottom: calc(100% + 4px); transform: translateX(-50%); white-space: nowrap; }
  .score-menu .score-menu-actions #micBtn { position: fixed; right: clamp(6px,1cqw,14px); bottom: 6px; width: 24%; height: calc((var(--footer-height) - 12px) / 2); min-height: 0; padding: 2px; }

  .match-player-heading { display: grid; grid-template-columns: minmax(max-content,1fr) auto minmax(0,1fr); padding: 4px; gap: 2px; }
  #playerHeading1 { grid-template-columns: minmax(0,1fr) auto minmax(max-content,1fr); }
  .match-player-heading .footer-remaining { grid-column: 2; grid-row: 1; }
  #playerHeading0 .score-player-name { grid-column: 1; text-align: left; }
  #playerHeading1 .score-player-name { grid-column: 3; text-align: right; }
  .match-player-heading .footer-remaining { line-height: 1; }
  .match-heading .score-player-name { grid-row: 1; font-size: clamp(10px,1.6cqw,14px); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .compact-input { bottom: calc((var(--footer-height) - 12px) / 2 + 14px); }
  .score-menu-actions #micLabel { font-size: 0; }
  .score-menu-actions #micLabel::after { content: "音声入力"; font-size: clamp(9px,1.15cqw,13px); }
  .compact-input .quick-score { display: none; }
}
