/* Keep the live court visible while the modal owns focus and navigation. */
body:has(#cup-dialog[open]) > :not(#cup-dialog, #court) { visibility:hidden; }
#cup-dialog {
  --cup-left:max(var(--safe-left),clamp(20px,4vw,52px));
  --cup-muted:#bdcbbf; --cup-rule:#597060; --cup-light:var(--button-face); --cup-rival:#b1d6e3;
  position:fixed; inset:0; width:100vw; height:var(--page-height); max-width:none; max-height:none;
  box-sizing:border-box; border:0; border-radius:0; margin:0; padding:0;
  background:transparent; color:var(--ink); text-align:left; color-scheme:dark;
  font-family:'Rally UI','PingFang SC','Microsoft YaHei',sans-serif;
}
#cup-dialog[open] { display:block; }
#cup-dialog::backdrop { background:linear-gradient(90deg,#08130ff7 0%,#0b1914ef 38%,#0b1914d9 57%,#0b191426 71%,transparent 81%); }
#cup-dialog[data-page=draw]::backdrop { background:#091713c9; }
#cup-dialog *,#cup-dialog *::before,#cup-dialog *::after { box-sizing:border-box; }
#cup-dialog button { font:inherit; color:inherit; cursor:pointer; touch-action:manipulation; }
#cup-dialog button:focus-visible,#cup-dialog input:focus-visible,#cup-dialog summary:focus-visible { outline:2px solid #d6efac !important; outline-offset:2px; }
.cup-sr-only { position:absolute; width:1px; height:1px; margin:-1px; padding:0; overflow:hidden; clip-path:inset(50%); white-space:nowrap; border:0; }
#cup-dialog .cup-back {
  position:absolute; top:max(6px,var(--safe-top)); left:var(--cup-left);
  z-index:1; min-height:44px; padding:0; border:0; background:transparent; font-size:12px; font-weight:600;
}
#cup-body {
  position:absolute; inset:max(52px,calc(var(--safe-top) + 46px)) auto max(12px,var(--safe-bottom)) var(--cup-left);
  display:flex; flex-direction:column; align-items:stretch;
  width:min(460px,54vw); padding:3px; margin-left:-3px; min-height:0;
  overflow:auto; overscroll-behavior:contain; scrollbar-width:thin; scrollbar-color:#8da792 #10271c;
}
#cup-body::before,#cup-body::after { content:""; flex:1 0 0; }
#cup-body > * { flex:none; }
#cup-body > :is(#cup-registration,#cup-growth,.cup-scroll) { flex:0 1 auto; min-height:0; }
#cup-body:focus { outline:0; }
#cup-title { font:600 clamp(23px,3.25vw,38px)/1.18 'Rally UI',sans-serif; letter-spacing:.065em; color:inherit; margin:0 0 6px; }
.cup-note,.cup-next,.cup-arrival,.cup-rival-meta { color:var(--cup-muted); font-size:13px; line-height:1.45; margin:0 0 7px; overflow-wrap:anywhere; }
.cup-events { max-width:390px; }
#cup-dialog .cup-event {
  display:flex; align-items:center; justify-content:space-between; gap:14px;
  width:100%; min-height:66px; padding:10px 14px; background:transparent; text-align:left;
  border:0; border-radius:0; border-block-start:1px solid var(--cup-rule); letter-spacing:.05em;
}
#cup-dialog .cup-event:last-child { border-block-end:1px solid var(--cup-rule); }
.cup-event strong,.cup-event small { display:block; }
.cup-event strong { font-size:clamp(18px,2.4vw,25px); font-weight:550; }
.cup-event small { margin-top:4px; font-size:12px; color:var(--cup-muted); font-weight:400; }
.cup-event > span:last-child { color:var(--cup-light); font-size:14px; white-space:nowrap; }
#cup-dialog .cup-event:hover,#cup-dialog .cup-event:focus-visible { background:#b3d78b17; }
#cup-registration,#cup-growth { display:flex; flex-direction:column; min-width:0; }
.cup-scroll { min-height:0; overflow:auto; padding:3px; margin-inline:-3px; overscroll-behavior:contain; touch-action:pan-y; scrollbar-width:thin; scrollbar-color:#79917f transparent; }
.cup-tabs,.cup-presets { display:flex; gap:4px; flex:none; border-bottom:1px solid var(--cup-rule); }
#cup-dialog .cup-tabs button,#cup-dialog .cup-presets button {
  position:relative; min-width:0; min-height:44px; padding:3px 10px; border:0;
  color:var(--cup-muted); background:transparent; font-size:13px; font-weight:550; white-space:nowrap;
}
#cup-dialog .cup-tabs button { flex:1; }
.cup-tabs [aria-selected=true]::after,.cup-presets [aria-pressed=true]::after { content:''; position:absolute; inset:auto 8px 0; height:2px; background:var(--cup-light); }
#cup-dialog .cup-tabs [aria-selected=true],#cup-dialog .cup-presets [aria-pressed=true] { color:#e3f2c9; text-decoration:none; }
#cup-registration .cup-scroll { padding-top:8px; }
.cup-fields { display:grid; grid-template-columns:minmax(0,1fr) minmax(76px,.42fr); gap:10px; margin-bottom:3px; }
.cup-fields label,.cup-choice-label { display:block; font-size:13px; font-weight:550; line-height:1.3; }
.cup-fields small,.cup-choice-label small { font-size:11px; font-weight:400; color:var(--cup-muted); }
#cup-dialog .cup-fields input {
  display:block; width:100%; min-width:0; min-height:44px; padding:6px 9px; margin:4px 0 0;
  background:#102019ed; border:1px solid #738675; border-radius:3px; font:inherit; font-size:16px; color:#f2f2e9;
}
.cup-choice { min-inline-size:0; padding:0; border:0; margin:0; }
.cup-choice-line { display:grid; grid-template-columns:clamp(55px,8vw,78px) minmax(0,1fr); gap:4px; align-items:center; }
.cup-choice-label small { display:block; }
.cup-score-options,.cup-color-options { display:flex; min-width:0; }
.cup-choice label { position:relative; flex:1; min-width:0; }
.cup-choice input { position:absolute; z-index:1; inset:0; width:100%; height:100%; margin:0; opacity:0; cursor:pointer; }
.cup-choice label > span { display:grid; place-items:center; min-height:44px; }
.cup-score-options span { padding:0 4px; white-space:nowrap; color:#d3dfcf; background:#14231cb8; border-bottom:1px solid #657966; font-size:13px; }
.cup-score-options input:checked + span { background:var(--soft); box-shadow:inset 0 -2px var(--cup-light); color:var(--ink); }
.cup-color-options label { max-width:56px; }
.cup-color-options i,.cup-kit-mark i { display:inline-block; border-radius:50%; background:var(--kit-color); box-shadow:inset 0 0 0 1px #ffffff4d; }
.cup-color-options i { width:22px; height:22px; }
.cup-color-options input:checked + span i { outline:2px solid #f2f5e9; outline-offset:3px; }
.cup-choice input:focus-visible + span { outline:2px solid var(--cup-light); outline-offset:-2px; }
.cup-actions { display:flex; flex-wrap:wrap; align-items:center; gap:6px; margin:8px 0; }
.cup-footer { flex:none; margin:6px 0 0; }
#cup-dialog .cup-actions button {
  min-height:44px; padding:6px 10px; background:transparent; color:#e4eddf;
  border:0; border-radius:0; font-size:14px; font-weight:550; white-space:nowrap;
}
#cup-dialog .cup-actions .cup-primary {
  color:#edf5db; padding-inline:3px 12px; margin-right:3px; font-size:16px;
  border-block:1px solid #acc4988a !important;
}
#cup-dialog .cup-actions .cup-growth-action { color:#d7efb4; }
.cup-bank,#cup-score-rule { margin-left:auto; font-size:12px; color:var(--cup-muted); }
.cup-bank b { color:var(--cup-light); font-variant-numeric:tabular-nums; }
.cup-bank small { display:block; margin-top:2px; font-size:11px; }
#cup-registration[data-tab=entry] .cup-adjust-hint,
#cup-registration[data-tab=entry][data-allocated=true] .cup-bank,
#cup-registration:is([data-tab=stats],[data-allocated=false]) #cup-score-rule { display:none; }
#cup-dialog .cup-presets button { flex:1; padding-inline:1px; }
.cup-presets { margin-bottom:5px; border-bottom-color:#71857180; }
.cup-comparison,.cup-editor-table,.cup-recap { width:100%; table-layout:fixed; border-collapse:collapse; font-size:13px; font-variant-numeric:tabular-nums; }
.cup-comparison th,.cup-comparison td,.cup-editor-table th,.cup-editor-table td,.cup-recap th,.cup-recap td { padding:4px; }
.cup-comparison th:first-child,.cup-editor-table th:first-child,.cup-recap th:first-child { padding-left:0; text-align:left; }
.cup-comparison thead,.cup-editor-table thead,.cup-recap thead { border-bottom:1px solid var(--cup-rule); }
.cup-comparison tbody tr,.cup-editor-table tbody tr,.cup-recap tbody tr { border-bottom:1px solid #82998636; }
.cup-comparison thead th,.cup-editor-table thead th,.cup-recap thead th { font-size:12px; font-weight:500; color:var(--cup-muted); }
.cup-comparison thead th { text-align:left; vertical-align:bottom; overflow-wrap:anywhere; }
.cup-comparison thead th:first-child { width:3.25em; }
.cup-comparison thead small { display:block; margin-bottom:3px; font-size:11px; line-height:1.3; }
.cup-comparison thead strong { color:var(--ink); font-size:clamp(16px,2.25vw,22px); line-height:1.25; }
.cup-kit-mark { display:inline-flex; align-items:center; gap:4px; margin-left:5px; color:var(--cup-muted); font-size:11px; white-space:nowrap; }
.cup-kit-mark i { width:9px; height:9px; }
.cup-stat-reading { display:flex; align-items:center; gap:7px; min-height:20px; }
.cup-stat-reading b,.cup-editor-table [data-stat-value],.cup-recap [data-value] { font:600 18px/1.15 'Rally Numerals',sans-serif; font-variant-numeric:tabular-nums; }
.cup-stat-reading b { flex:none; width:2.4ch; text-align:right; }
.cup-stat-track { flex:1; height:4px; background:#788b7b55; }
.cup-stat-track i { display:block; height:100%; background:var(--cup-light); }
.cup-comparison [data-side=opponent] .cup-stat-track i { background:var(--cup-rival); }
.cup-rival-meta { margin:7px 0; font-size:12px; }
.cup-rival-meta b { color:var(--cup-rival); font-weight:550; margin-right:4px; }
.cup-editor-table th,.cup-editor-table td { text-align:center; }
.cup-editor-table thead th:first-child { width:24%; }
.cup-editor-table thead th:nth-child(3) { width:44%; }
.cup-editor-table tbody td { padding:0; }
.cup-editor-table tbody th small { display:block; font-size:11px; line-height:1.25; color:var(--cup-muted); font-weight:400; }
.cup-editor-table [data-stat-floor] { color:var(--cup-muted); }
#cup-growth .cup-editor-table thead th:first-child { width:12%; }
#cup-growth .cup-editor-table [data-side=opponent] { color:var(--cup-rival); }
.cup-editor-table [data-stat-value] { color:#e1efc9; }
.cup-stepper { display:inline-grid; grid-template-columns:minmax(34px,44px) minmax(24px,32px) minmax(34px,44px); justify-content:center; align-items:center; width:100%; }
#cup-dialog .cup-stepper button {
  min-height:44px; padding:0; border:1px solid #738675 !important; border-radius:5px;
  background:#253a2d; color:#e5f4c9; font:500 21px/1 'Rally Numerals',sans-serif;
}
#cup-dialog .cup-stepper button:active { transform:none; }
#cup-dialog .cup-stepper button[aria-disabled=false]:active { background:#475e45; }
#cup-dialog .cup-stepper button[aria-disabled=true] { opacity:.48; cursor:default; }
.cup-increment { color:var(--ink); text-align:center; }
.cup-recap caption { padding:4px 0 6px; text-align:left; font-size:16px; font-weight:600; }
.cup-recap :is(th,td):not(:first-child) { text-align:right; }
.cup-recap tbody :is(td,th) { padding-block:7px; }
.cup-gain { color:var(--cup-light); }
#cup-dialog .cup-event { border-block-start-color:var(--cup-rule) !important; }
#cup-dialog .cup-event:last-child { border-block-end-color:var(--cup-rule) !important; }
#cup-dialog .cup-quiet { display:block; min-width:44px; min-height:44px; padding:4px 0; border:0; background:transparent; text-align:left; font-size:12px; color:#c8d1c7; }
.cup-arrival { margin:0 0 7px; color:#d2e5b6; }
.cup-next { margin:1px 0; font-size:12px; }
.cup-next strong { color:var(--cup-light); margin-right:5px; font-weight:550; }
.cup-road summary { min-height:44px; padding:12px 0; cursor:pointer; font-size:13px; }
.cup-road ul { list-style:none; margin:0; padding:0; }
.cup-road li { display:grid; grid-template-columns:5em minmax(0,1fr) 1.5em; gap:8px; border-top:1px solid var(--cup-rule); padding:6px 0; font-size:13px; }
.cup-road li span { color:var(--cup-muted); }
.cup-road li b { color:var(--cup-light); }
#cup-dialog[data-page=draw] #cup-body { right:var(--cup-left); width:auto; padding-right:0; touch-action:pan-x pan-y; }
body[data-cup-award="true"] > :not(#court,#skip-cup-award) { display:none !important; }
#skip-cup-award { position:fixed; z-index:80; right:max(16px,var(--safe-right)); bottom:max(16px,var(--safe-bottom)); min-height:44px; padding:8px 18px; color:#f0f4e8; background:#17251edc; border:1px solid #91a384; border-radius:3px; font:inherit; cursor:pointer; touch-action:manipulation; }
#skip-cup-award[hidden] { display:none; }
@media (orientation:portrait) {
  #cup-body { width:calc(100% - 2 * var(--cup-left)); max-width:520px; }
  #cup-dialog::backdrop { background:linear-gradient(90deg,#08140fef,#08140fcf 78%,#08140f84); }
  #cup-dialog:not([data-event=""]):not([data-page=draw]) #cup-body { top:clamp(144px,42dvh,410px); }
  #cup-dialog:not([data-event=""]):not([data-page=draw])::backdrop {
    background:radial-gradient(ellipse 125px 60px at 43px 20px,#08140fd6,transparent),
      linear-gradient(180deg,#08140f32,transparent 12%,transparent 32%,#0a1915e8 42%,#0a1915fa 54%,#0a1915fc);
  }
  #cup-dialog[data-page=draw] #cup-body { max-width:none; }
}
@media (max-height:350px) and (orientation:landscape) {
  #cup-body { top:max(42px,var(--safe-top)); bottom:max(5px,var(--safe-bottom)); width:min(450px,60vw); }
  #cup-dialog .cup-back { top:0; min-height:42px; }
  #cup-title { font-size:22px; margin-bottom:5px; }
  .cup-note { font-size:12px; margin-bottom:3px; }
  #cup-dialog .cup-tabs button { min-height:40px; }
  #cup-dialog .cup-actions { gap:3px; }
  #cup-dialog .cup-actions button { padding-inline:6px; }
  #cup-dialog .cup-actions .cup-primary { padding-inline:3px 9px; }
  #cup-dialog:not([data-page=draw])::backdrop { background:linear-gradient(90deg,#08130ff7,#0b1914ed 44%,#0b1914d4 63%,#0b191422 74%,transparent 82%); }
}
/* Share the back rail with the event heading on a phone. Keeping presets
   beside the table leaves three full, touch-sized rows in view. */
@media (orientation:landscape) and (max-height:500px) {
  #cup-dialog:not([data-event=""]):not([data-page=draw]) #cup-body { top:max(4px,var(--safe-top)); }
  #cup-dialog:not([data-event=""]):not([data-page=draw]) #cup-body::before,
  #cup-dialog:not([data-event=""]):not([data-page=draw]) #cup-body::after { display:none; }
  #cup-dialog:not([data-event=""]):not([data-page=draw]) #cup-title {
    margin:1px 0 0; padding-left:90px; font-size:clamp(18px,2.7vw,25px); line-height:1.18;
  }
  #cup-dialog:not([data-event=""]):not([data-page=draw]) #cup-title + .cup-note {
    padding-left:90px; margin:2px 0 7px; font-size:11px; line-height:1.3;
  }
  #cup-dialog[data-event]:not([data-event=""])[data-page=hub] :is(#cup-title,#cup-title + .cup-note) { padding-left:100px; }
  #cup-dialog:not([data-event=""]):not([data-page=draw]) .cup-back { top:max(1px,var(--safe-top)); }
  #cup-body > :is(#cup-registration,#cup-growth,.cup-scroll),:is(#cup-registration,#cup-growth) > .cup-scroll { flex:1 1 0; }
  #cup-panel-stats { display:grid; grid-template-columns:clamp(52px,7.25vw,66px) minmax(0,1fr); gap:6px; align-items:start; }
  #cup-dialog .cup-presets { flex-direction:column; align-self:stretch; gap:0; padding-right:4px; margin:0; border:0; border-right:1px solid var(--cup-rule); }
  #cup-dialog .cup-presets button { flex:1; min-height:38px; padding:2px 0; font-size:12px; }
  .cup-presets [aria-pressed=true]::after { inset:8px -4px 8px auto; width:2px; height:auto; }
  #cup-registration .cup-scroll { padding-top:4px; }
  #cup-registration .cup-editor-table thead th { white-space:nowrap; padding-inline:1px; }
  #cup-registration .cup-editor-table thead th:first-child { width:27%; }
}
#cup-dialog[data-page=draw] #cup-body {
  top:max(8px,var(--safe-top)); bottom:max(8px,var(--safe-bottom)); overflow:hidden;
}
#cup-dialog[data-page=draw] #cup-body::before,#cup-dialog[data-page=draw] #cup-body::after { display:none; }
#cup-dialog[data-page=draw] #cup-title { min-height:34px; padding:5px 0 0 100px; margin:0 0 3px; font-size:clamp(17px,2.7vw,27px); }
#cup-dialog[data-page=draw] .cup-bracket { display:flex; flex:1; flex-direction:column; min-height:0; }
#cup-dialog[data-page=draw] .cb-scroll { height:auto; flex:1; min-height:0; }
