:root { color-scheme: dark; font-family: system-ui, -apple-system, sans-serif; background: #080c10; color: #fff; }
* { box-sizing: border-box; }
body { margin: 0; -webkit-text-size-adjust: 100%; }
#remotePage main { max-width: 540px; margin: auto; padding: 12px; padding: max(12px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(20px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left)); }
[hidden] { display: none !important; }
h1 { font-size: 20px; margin: 4px 0; }
header, footer, #rc_auth, #remoteStatus { text-align: center; }
p { margin: 8px 0; overflow-wrap: anywhere; }
#remoteStatus { font-size: 13px; color: #c5e6dc; }
#remoteStatus:empty { display: none; }
#remotePage button, #remotePage nav a, #remotePage summary { font: inherit; min-height: 44px; padding: 10px; border-radius: 16px; border: 1px solid #486066; background: #203338; color: white; touch-action: manipulation; }
#remotePage button { width: 100%; margin: 4px 0; cursor: pointer; }
#remotePage #codeDisplay { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 2px; max-width: 280px; margin: 8px auto; padding: 8px 2px; border: 1px solid #486066; border-radius: 12px; background: #111a20; color: #91e6bd; font-size: 22px; font-variant-numeric: tabular-nums; }
#remotePage #codeKeypad { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px 8px; max-width: 280px; margin: 0 auto 12px; }
#remotePage #codeKeypad button { min-height: 44px; margin: 0; padding: 6px 2px; font-size: 22px; user-select: none; -webkit-user-select: none; }
#remotePage #codeKeypad [data-code-key="clear"] { font-size: 12px; }
#remotePage #codeKeypad button:active { background: #37605c; }
#remotePage #connectCode { max-width: 280px; background: #28644e; }
#remotePage #rc_auth button:disabled { opacity: .4; cursor: default; }
@media (max-width: 192px) { #remotePage.round #codeKeypad { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 184px) { #remotePage #codeKeypad { column-gap: 6px; } }
#remotePage nav { display: grid; gap: 8px; margin: 16px 0; }
#remotePage nav a { text-decoration: none; }
#remotePage footer { font-size: 12px; margin-top: 16px; }
#remotePage .shape { display: flex; min-height: 44px; align-items: center; justify-content: center; gap: 6px; }
#remotePage .shape input { width: 22px; height: 22px; }
#remotePage details p { line-height: 1.5; }
/* Shared-pad overrides live here so both platforms use the same spacing rules. */
#remotePage.connected header { display: none; }
#remotePage #rcShell { --remote-gap-x: 10px; --remote-gap-y: 14px; width: 100%; min-width: 0; padding: 6px; border-radius: 14px; }
#remotePage #rcShell .rcBar { display: grid; grid-template-columns: repeat(auto-fit, minmax(88px, 1fr)); gap: 10px; margin-bottom: 16px; align-items: center; }
#remotePage #rcShell .rcStatus { min-width: 0; max-width: 100%; justify-content: center; white-space: normal; text-align: center; font-size: 11px; padding: 8px 5px; }
#remotePage #rcShell #rcStatusText { white-space: normal; overflow-wrap: anywhere; }
#remotePage #rcShell .rcStatusDot { flex: 0 0 8px; }
#remotePage #rcShell #rcDisconnect { width: 100%; height: auto; min-height: 44px; padding: 8px; margin: 0; font: 12px system-ui; text-align: center; }
#remotePage #rcShell #rcFullscreen, #remotePage #rcShell #rcKeepAwake, #remotePage #rcShell .rcWatching { display: none; }

/* Keep generous gaps and let columns wrap before touch targets become too small. */
#remotePage #rcShell .rcGrid { grid-template-columns: repeat(2, minmax(0, 1fr)); grid-template-columns: repeat(auto-fit, minmax(max(56px, calc((100% - 30px) / 4)), 1fr)); }
#remotePage[data-platform="billiardon"] #rcShell .rcGrid { grid-template-columns: repeat(auto-fit, minmax(max(68px, calc((100% - 30px) / 4)), 1fr)); }
#remotePage #rcShell .rcGrid, #remotePage #rcShell .rcRowTransport,
#remotePage #rcShell .rcCardScore, #remotePage #rcShell .rcCardFlags,
#remotePage #rcShell .rcRowMenu, #remotePage #rcShell .rcShotRow,
#remotePage #rcShell .rcBreakKeys, #remotePage #rcShell .rcBallGrid,
#remotePage #rcShell .rcShotStepper, #remotePage #rcShell .rcBreakActions {
    display: grid; gap: var(--remote-gap-y) var(--remote-gap-x);
}
#remotePage #rcShell .rcRowTransport, #remotePage #rcShell .rcCardScore,
#remotePage #rcShell .rcCardFlags, #remotePage #rcShell .rcRowMenu,
#remotePage #rcShell .rcShotRow, #remotePage #rcShell .rcBreakKeys,
#remotePage #rcShell .rcBallGrid, #remotePage #rcShell .rcShotStepper {
    grid-template-columns: repeat(auto-fit, minmax(44px, 1fr));
}
#remotePage #rcShell .rcCardFlags { grid-template-columns: repeat(auto-fit, minmax(56px, 1fr)); }
#remotePage #rcShell .rcRowMenu, #remotePage #rcShell .rcShotRow { grid-template-columns: repeat(auto-fit, minmax(64px, 1fr)); }
#remotePage #rcShell .rcBtn { min-width: 0; min-height: 52px; height: auto; aspect-ratio: auto; padding: 7px 3px; border-radius: 12px; text-align: center; }
#remotePage #rcShell .rcBtn img { width: 30px; height: 30px; max-width: 100%; object-fit: contain; }
#remotePage #rcShell .rcBallStep { height: 32px; }
#remotePage #rcShell .rcBtnLabel { font-size: 11px; line-height: 1.3; letter-spacing: 0; overflow-wrap: anywhere; }
#remotePage #rcShell .rcBtnLabelLg { font-size: 12px; }
#remotePage #rcShell .rcRowTransport { margin: 18px 0 22px; }
#remotePage #rcShell .rcRowMatchClock { margin: 20px 0; }
#remotePage #rcShell .rcRowMenu { margin-top: 18px; }
#remotePage #rcShell .rcSectionHead { margin: 20px 2px 10px; color: #c1d0d2; letter-spacing: .7px; text-align: center; }
#remotePage #rcShell .rcSwitch[button="20"] { margin: 24px 0 16px; min-height: 52px; height: auto; padding: 12px 4px; font-size: 12px; letter-spacing: .5px; text-align: center; }

/* Names and scores share the same centre line, including wrapped names. */
#remotePage #rcShell .rcScore { gap: 12px 10px; }
#remotePage #rcShell .rcSide { min-width: 0; min-height: 84px; padding: 6px 2px; row-gap: 5px; text-align: center; }
#remotePage #rcShell .rcSideName, #remotePage #rcShell .rcCardName, #remotePage #rcShell .rcFlagName {
    display: block; width: 100%; min-width: 0; white-space: normal; overflow-wrap: anywhere; text-align: center; line-height: 1.3;
}
#remotePage #rcShell .rcSideName { font-size: 13px; }
#remotePage #rcShell .rcSidePoints { font-size: 32px; }
#remotePage #rcShell .rcSidePoints.rcSidePointsWide { font-size: 26px; }
#remotePage #rcShell .rcBreak { height: auto; min-height: 16px; line-height: 1.3; font-size: 11px; white-space: normal; overflow-wrap: anywhere; text-align: center; }
#remotePage #rcShell .rcMiddle { min-width: 0; padding: 4px 2px; gap: 4px; text-align: center; }
#remotePage #rcShell .rcFrames { font-size: 16px; white-space: normal; overflow-wrap: anywhere; }
#remotePage #rcShell .rcFramesOf { font-size: 10px; vertical-align: baseline; margin: 0 2px; }
#remotePage #rcShell .rcFramesLabel { font-size: 9px; color: #aab5b8; }
#remotePage #rcShell .rcSides, #remotePage #rcShell .rcFlagSides { gap: 16px 12px; margin-bottom: 16px; }
#remotePage #rcShell .rcCard { gap: 12px; padding: 6px; }
#remotePage #rcShell .rcCardHead { min-height: 52px; width: 100%; justify-content: center; gap: 5px; text-align: center; }
#remotePage #rcShell .rcCardName { font-size: 15px; color: #e0e5e8; }
#remotePage #rcShell .rcCardPoints { font-size: 40px; text-align: center; max-width: 100%; overflow-wrap: anywhere; }
#remotePage #rcShell .rcCardSep { line-height: 1.4; color: #c1d0d2; }
#remotePage #rcShell .rcRace { max-width: 100%; text-align: center; }

/* Input panels scroll within the same safe area as the controller. */
#remotePage #rcShell .rcShot { margin-top: 20px; padding: 6px; }
#remotePage #rcShell .rcShotHead { flex-wrap: wrap; justify-content: center; gap: 12px; text-align: center; }
#remotePage #rcShell .rcShotHeadTools { flex-wrap: wrap; justify-content: center; max-width: 100%; gap: 10px; }
#remotePage #rcShell .rcShotGear { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; min-width: 44px; padding: 8px; }
#remotePage #rcShell .rcShot .rcSwitch, #remotePage #rcShell .rcShotSheet .rcSwitch { min-height: 44px; min-width: 44px; }
#remotePage #rcShell .rcShot .rcSwitch::after, #remotePage #rcShell .rcShotSheet .rcSwitch::after { top: 12px; }
#remotePage #rcShell .rcShotRow { margin-top: 14px; }
#remotePage #rcShell .rcShotSheet, #remotePage #rcShell .rcBreakSheet { position: fixed; inset: 0; height: 100%; overflow-y: auto; overscroll-behavior: contain; padding: 16px; padding-bottom: max(24px, env(safe-area-inset-bottom)); z-index: 20; }
#remotePage #rcShell .rcShotField { margin-bottom: 22px; }
#remotePage #rcShell .rcShotFieldLabel { color: #c1d0d2; text-align: center; line-height: 1.4; }
#remotePage #rcShell .rcShotStepperValue { min-height: 48px; min-width: 0; font-size: 24px; }
#remotePage #rcShell .rcBall { min-height: 48px; min-width: 44px; }
#remotePage #rcShell .rcBreakActions { grid-template-columns: 1fr; margin-top: 20px; }
#remotePage #rcShell .rcBreakSheet .rcBreakTitle { white-space: normal; overflow-wrap: anywhere; line-height: 1.4; }
#remotePage #rcShell .rcBreakDisplay { margin-bottom: 14px; }
#remotePage #rcShell .rcBallSums { flex-wrap: wrap; justify-content: center; gap: 12px; }
#remotePage #rcShell .rcBreakRack, #remotePage #rcShell .rcBreakNote { overflow-wrap: anywhere; }
#remotePage #remoteConfirm { position: fixed; inset: 0; overflow-y: auto; padding: 20px; background: #080c10; z-index: 100; text-align: center; }
#remotePage #remoteConfirm button + button { margin-top: 12px; }
#remotePage .unavailable #rcShell { opacity: .5; }
#remotePage :focus-visible { outline: 2px solid #91e6bd; outline-offset: 2px; }

/* Round mode keeps each row within the central width, with room to scroll the
   first and last controls into the centre of a circular display. */
#remotePage.round main { width: 72%; padding: 22vh 2px; }
#remotePage.round #remoteConfirm, #remotePage.round #rcShell .rcShotSheet, #remotePage.round #rcShell .rcBreakSheet { padding: 22vh 15%; }
#remotePage.round #rcShell .rcSides, #remotePage.round #rcShell .rcFlagSides { grid-template-columns: minmax(0, 1fr); }
@media (max-width: 420px) {
    #remotePage #rcShell .rcSides, #remotePage #rcShell .rcFlagSides { grid-template-columns: minmax(0, 1fr); }
    #remotePage #rcShell .rcCardPoints { font-size: 34px; }
}
@media (max-width: 340px) {
    #remotePage #rcShell .rcScore { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    #remotePage #rcShell .rcMiddle { grid-row: 2; grid-column: 1 / -1; flex-direction: row; flex-wrap: wrap; gap: 4px; }
    #remotePage #rcShell .rcSidePoints { font-size: 26px; }
    #remotePage #rcShell .rcSidePoints.rcSidePointsWide { font-size: 22px; }
    #remotePage #rcShell .rcSideName { font-size: 12px; }
}
@media (max-width: 240px) { #remotePage #rcShell .rcBtn i { font-size: 20px; } }
@media (prefers-reduced-motion: reduce) { #remotePage * { animation: none !important; transition: none !important; } }

/* Progressive enhancement: the static inset remains the fallback without JS.
   Only transforms change during scrolling, so the scroll height stays stable. */
#remotePage.roundFlow * { transition: none !important; }
#remotePage.round.roundFlow main { width: 100%; max-width: min(540px, 100vw, 100vh); padding: calc(50vh - 24px) 8px; }
#remotePage.round.roundFlow #rcShell { padding: 0; background: transparent; border-radius: 0; }
#remotePage.round.roundFlow #rcShell .rcCard,
#remotePage.round.roundFlow #rcShell .rcShot { background: transparent; border: 0; box-shadow: none; padding-left: 0; padding-right: 0; border-radius: 0; }
#remotePage.round.roundFlow #rcShell .rcCardHead { padding: 8px 4px; border-radius: 18px; }
#remotePage.round.roundFlow #rcShell .rcSideActive .rcCardHead { background: rgba(var(--rc-side-rgb), .2); box-shadow: inset 0 0 0 1px rgba(var(--rc-side-rgb), .6); }
#remotePage.round.roundFlow #rcShell .rcShotSheet,
#remotePage.round.roundFlow #rcShell .rcBreakSheet,
#remotePage.round.roundFlow #remoteConfirm { padding: calc(50vh - 24px) max(8px, calc((100vw - min(540px, 100vh)) / 2 + 8px)); border-radius: 0; background: #080c10; }
#remotePage.round.roundFlow .roundCell { transform-origin: center; transition: none; }
/* Promote only nearby controls; a layer for every off-screen button wastes watch memory. */
#remotePage.round.roundFlow .roundCell.roundVisible { will-change: transform; }
#remotePage.round.roundFlow .roundCell.rcBtnDown { filter: brightness(1.25); }
#remotePage.round.roundFlow .roundCell.roundEdge { pointer-events: none; }
#remotePage.round.roundFlow #rcShell .rcBtn,
#remotePage.round.roundFlow #codeKeypad button { border-radius: 18px; }
