/* Rally uses TNQ's shared header, panels, buttons, ranges and checkboxes. */
body.rally-page { font-family: Inter, system-ui, sans-serif; }
.rally-page [hidden] { display: none !important; }
.rally-page button, .rally-page input, .rally-page select { font: inherit; }
.rally-page :focus-visible { outline: 3px solid var(--color-secondary); outline-offset: 4px; }
.rally-page [tabindex="-1"]:focus { outline: none; }
#app-container.study-shell { position: relative; padding: 0 1rem; min-height: 100vh; }
.study-logo-link { position: absolute; top: 1.5rem; left: 50%; transform: translateX(-50%); display: inline-flex; align-items: center; gap: 9px; text-decoration: none; color: var(--color-text-primary); z-index: 50; }
.rally-wordmark { font-size: 1.35rem; font-weight: 700; letter-spacing: -.04em; }
#app-container #theme-toggle-button { position: absolute; top: 1.5rem; right: 1.5rem; padding: 8px; border: 0; border-radius: 50%; background: transparent; cursor: pointer; z-index: 50; }
#settings-button svg { width: 24px; height: 24px; }
.study-header { padding-top: 5rem; margin-bottom: 1.5rem; }
.study-header h1 { font-size: 1.875rem; line-height: 2.25rem; margin: 1rem 0 1.5rem; }
.study-header nav { display: flex; justify-content: center; align-items: center; padding: .5rem; gap: 0; }
.study-header nav > * + * { margin-left: .5rem; }
.setup-panel { padding: 1.5rem; }
.setup-panel h2 { font-size: 1.5rem; font-weight: 800; margin: 0 0 1.5rem; }
.rally-page fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
.rally-page legend, .set-picker > label, .field-heading > label, .inline-field > label, #discussion-settings > label { font-size: .9rem; font-weight: 700; margin-bottom: .7rem; display: block; }
.rally-page .setup-field { margin-top: 1.5rem; }
.rally-page select, .rally-page input[type=number], .rally-page input[readonly]:not(.tnq-sr-only) { min-width: 0; border: 1px solid var(--color-border); border-radius: 12px; background: var(--color-bg); color: var(--color-text-primary); padding: 10px 12px; }
#deck-select, #discussion-seconds { width: 100%; }
/* Dropdowns match the print page: custom chevron with room from the edge, blue focus ring */
.rally-page { --field-chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%23aab4e0' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); }
body.light-mode.rally-page { --field-chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%23586380' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); }
.rally-page select { -webkit-appearance: none; -moz-appearance: none; appearance: none; padding-right: 44px; background-image: var(--field-chevron); background-repeat: no-repeat; background-position: right 16px center; background-size: 12px 8px; text-overflow: ellipsis; cursor: pointer; transition: border-color .15s ease, box-shadow .15s ease; }
.rally-page select option { background: var(--color-card-bg); color: var(--color-text-primary); }
.rally-page select:hover:not(:disabled) { border-color: color-mix(in srgb, var(--color-primary) 45%, var(--color-border)); }
.rally-page select:focus, .rally-page select:focus-visible { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-primary) 22%, transparent); }
.rally-page select:disabled { cursor: default; }
#deck-select, #discussion-seconds { min-height: 46px; padding-left: 14px; }
.set-links { display: flex; flex-wrap: wrap; align-items: center; gap: 14px; font-size: .78rem; margin-top: 8px; }
.set-links .helper { margin: 0; }
.setup-panel a, .classroom-link a { color: var(--color-primary); text-underline-offset: 3px; }
body.rally-page:not(.light-mode) .text-button, body.rally-page:not(.light-mode) .set-links a, body.rally-page:not(.light-mode) .classroom-link a { color: #aab8ff; }
.text-button { border: 0; background: none; color: var(--color-primary); padding: 6px 0; font-weight: 600; font-size: .8rem; cursor: pointer; text-decoration: none; }
.choice-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.choice { display: flex; align-items: flex-start; gap: 10px; border: 1px solid var(--color-border); border-radius: 14px; padding: 14px; cursor: pointer; background: var(--color-bg); }
.choice:has(input:checked) { border-color: var(--color-primary); box-shadow: inset 0 0 0 1px var(--color-primary); background: var(--color-primary-light); }
.mode-choice { position: relative; display: grid; min-width: 0; }
.mode-choice .choice { padding-right: 46px; }
.mode-info, .modes-info { display: inline-grid; place-items: center; padding: 0; border: 0; border-radius: 50%; background: transparent; color: var(--color-text-secondary); cursor: pointer; transition: color .15s ease, background-color .15s ease; }
.mode-info:hover, .modes-info:hover, .mode-info[aria-expanded=true] { color: var(--color-text-primary); background: var(--color-border); }
.mode-info { position: absolute; top: 50%; right: 10px; width: 28px; height: 28px; transform: translateY(-50%); }
.mode-info svg, .modes-info svg { width: 20px; height: 20px; }
.modes-info { display: none; width: 44px; height: 44px; margin: -14px 0 -14px -6px; vertical-align: middle; }
.modes-info:hover { background: transparent; }
.mode-tooltip { position: fixed; z-index: 1000; left: 0; top: 0; width: min(300px, calc(100vw - 24px)); padding: 10px 12px; border: 1px solid var(--color-border); border-radius: 8px; background: var(--color-card-bg); color: var(--color-text-primary); font-size: .8rem; line-height: 1.5; box-shadow: var(--shadow-lg); visibility: hidden; opacity: 0; translate: 0 4px; pointer-events: none; transition: opacity .15s ease, translate .15s ease, visibility 0s linear .15s; }
.mode-tooltip.below { translate: 0 -4px; }
.mode-tooltip.visible { visibility: visible; opacity: 1; translate: 0 0; pointer-events: auto; transition-delay: 0s; }
.mode-tooltip strong { display: block; margin-bottom: 3px; font-weight: 700; }
.mode-tooltip::after { content: ''; position: absolute; left: var(--caret-x, 50%); bottom: -6px; width: 10px; height: 10px; margin-left: -5px; background: var(--color-card-bg); border: solid var(--color-border); border-width: 0 1px 1px 0; rotate: 45deg; }
.mode-tooltip.below::after { bottom: auto; top: -6px; border-width: 1px 0 0 1px; }
.modes-list h3 { margin: 1.1rem 0 .25rem; font-size: .95rem; font-weight: 700; }
.modes-list h3:first-child { margin-top: 0; }
.modes-list p { margin: 0; color: var(--color-text-secondary); font-size: .88rem; line-height: 1.5; }
@media (max-width: 650px), (max-height: 500px) {
  .mode-info { display: none; }
  .mode-choice .choice { padding-right: 11px; }
  .modes-info { display: inline-grid; }
}
.choice input[type=radio] { width: 17px; height: 17px; margin: 3px 0 0; accent-color: var(--color-primary); flex-shrink: 0; }
.choice strong { display: block; font-size: .86rem; font-weight: 700; }
.choice small { display: block; color: var(--color-text-secondary); font-size: .75rem; line-height: 1.5; margin-top: 3px; }
.inline-field { display: flex; align-items: center; gap: 14px; margin-top: 12px; }
.inline-field > label { margin: 0; }
.inline-field select { font-size: .8rem; padding-right: 34px; background-position: right 12px center; background-size: 10px 7px; }
.field-heading, .duration-notes { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.field-heading > label { margin: 0; }
#length-result { font-size: .8rem; color: var(--color-text-secondary); text-align: right; }
#game-length { display: block; width: 100%; margin: 16px 0 12px; }
.duration-notes .helper { margin: 0; max-width: 80%; }
.rally-page .helper { color: var(--color-text-secondary); font-size: .78rem; line-height: 1.5; }
.rally-page .helper:empty, .rally-page .error:empty { display: none; }
.error { padding: 10px 12px; border: 1px solid var(--color-incorrect); border-radius: 10px; background: var(--color-incorrect-light); font-size: .8rem; }
#setup-warnings, #ai-status, [data-storage-status] { margin: 14px 0 0; }
.setup-actions { display: flex; justify-content: space-between; align-items: center; gap: 14px; margin-top: 1.5rem; padding-top: 1.25rem; border-top: 1px solid var(--color-border); }
.setup-secondary { display: flex; align-items: center; gap: 10px; }
.setup-actions button { min-height: 42px; }
.setup-actions .main-action-button, .setup-actions .secondary-action-button { font-size: .85rem; padding: 10px 16px; }
.create-action { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.create-action .helper { font-size: .7rem; }
.rally-page button:disabled { cursor: not-allowed; opacity: .5; }
.rally-page .modal-close-button { font-size: 1.5rem; line-height: 1; }
.fullscreen-button svg, .host-topbar svg, #lock-joins svg { width: 1.375rem; height: 1.375rem; }
.host-start-actions .fullscreen-button { flex: 0 0 3rem; width: 3rem; height: 3rem; min-height: 3rem; padding: 0; }
.host-start-actions .fullscreen-button svg { width: 1.75rem; height: 1.75rem; }
.classroom-link { text-align: center; font-size: .8rem; margin: 22px 0; }
.rally-dialog { border: 0; background: transparent; padding: 0; color: var(--color-text-primary); width: min(440px, calc(100vw - 32px)); max-width: 100%; max-height: calc(100dvh - 32px); overflow-y: auto; border-radius: var(--border-radius-card); }
.rally-dialog::backdrop { background: rgba(0, 0, 0, .6); backdrop-filter: blur(5px); }
.rally-dialog[open] { animation: shared-modal-enter .2s ease both; }
.dialog-panel { position: relative; padding: 28px; }
.dialog-panel h2 { margin: 0 0 24px; font-size: 1.4rem; font-weight: 800; }
.checkbox-list { display: grid; grid-template-columns: 1fr; gap: 15px; }
.checkbox-list input { flex-shrink: 0; }
.dialog-actions { display: flex; justify-content: flex-end; margin-top: 24px; }
.rules-details { font-size: .8rem; }
.rules-details summary { cursor: pointer; font-weight: 700; }
.rules-details p { margin-bottom: 0; }
#media-estimate, #options-status { margin: 18px 0 0; }
#share-set-link { width: 100%; }
.busy { display: inline-block; width: 12px; height: 12px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; vertical-align: middle; animation: rally-spin .7s linear infinite; }

/* Classroom screens fill the viewport. Roster pagination keeps even 40 players usable.
   Rally is usually hosted on a TV or projector, so from the lobby to the final results the host's text
   grows with the screen: 1rem stays 16px up to about 1280×728, then follows whichever of width and
   height is tighter (about 24px on a 1080p TV). Host sizes below use rem so they grow with it. */
html.rally-host { font-size: clamp(1rem, min(1.25vw, 2.2vh), 2.5rem); }
html.rally-host, html.rally-host body { overflow: hidden; height: 100%; }
body.rally-host { background: var(--color-bg); --tnq-btn-height: 2.875rem; }
#host-view { position: fixed; inset: 0; height: 100dvh; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; gap: 1.375rem; padding: 1.25rem 2rem; }
.host-topbar { display: grid; grid-template-columns: 44px 1fr 44px; align-items: center; }
.host-topbar .icon-button { width: 44px; height: 44px; }
.rally-logo { display: inline-flex; align-items: center; justify-content: center; justify-self: center; gap: 10px; text-decoration: none; color: var(--color-text-primary) !important; }
.rally-logo img { height: 38px; width: auto; display: block; }
.rally-logo span { font-size: 1.45rem; letter-spacing: -.04em; font-weight: 700; }
.host-content { min-height: 0; display: grid; grid-template-columns: minmax(15.625rem, 1fr) minmax(0, 1.4fr); gap: 2rem; }
/* The code and QR code size to this column (cqi) and the screen height, so they fill a TV, not just a laptop. */
.join-board { min-height: 0; display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 1.25rem; text-align: center; container-type: inline-size; }
.join-info { min-width: 0; max-width: 100%; }
.join-info .helper { margin: 0 0 .5rem; overflow-wrap: anywhere; }
@media (min-width: 651px) and (min-height: 501px) { .rally-page .join-info .helper { font-size: 1rem; } }
#join-address { color: var(--color-text-primary); }
.room-code { font-size: clamp(2.2rem, min(17cqi, 12vh), 9rem); font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: .08em; color: var(--color-secondary); line-height: 1.3; margin: .75rem 0 1.25rem; }
.share-actions { display: flex; align-items: center; justify-content: center; gap: 1rem; }
.share-actions .secondary-action-button { font-size: .8rem; padding: .5rem .75rem; }
.qr { width: clamp(110px, min(56cqi, 34vh), 28rem); height: auto; aspect-ratio: 1; background: white; border-radius: .75rem; image-rendering: pixelated; }
#copy-status { margin: .625rem 0 0; }
.roster-board { min-width: 0; min-height: 0; padding: 1.375rem; display: flex; flex-direction: column; gap: .875rem; }
.roster-heading { display: flex; align-items: center; justify-content: space-between; gap: .75rem; }
.roster-heading > div { min-width: 0; }
.roster-heading h1 { font-size: 1.3rem; font-weight: 700; margin: 0 0 .375rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.roster-heading .helper { margin: 0; }
#lock-joins { flex-shrink: 0; width: 2.5rem; height: 2.5rem; }
#lock-joins[aria-pressed=true] { background: var(--color-primary-light); color: var(--color-secondary); }
.lobby-teams { display: flex; align-items: center; gap: .625rem; flex-wrap: wrap; font-size: .8rem; }
#lobby-team-count { width: 4.0625rem; padding: .375rem .5rem; }
.lobby-teams .helper { flex: 1; min-width: 5rem; font-size: .7rem; }
#roster-region { min-height: 0; flex: 1; overflow: hidden; position: relative; }
#roster { padding: 0; margin: 0; list-style: none; display: grid; gap: .5rem; grid-auto-rows: 3.5rem; }
.player { min-width: 0; display: flex; align-items: center; gap: .5625rem; padding: .5rem; background: var(--color-bg); border: 1px solid var(--color-border); border-radius: .75rem; }
.avatar { width: 1.875rem; height: 1.875rem; display: grid; place-items: center; background: var(--color-primary-light); border-radius: .5625rem; font-size: .8rem; font-weight: 800; flex-shrink: 0; }
.player-name { min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .875rem; }
.player select { font-size: .72rem; max-width: 5.75rem; padding: .3125rem 1.5rem .3125rem .5rem; background-position: right .5rem center; background-size: .5625rem .375rem; }
.player .remove-player { width: 2rem; height: 2.25rem; padding: .4375rem; flex-shrink: 0; }
.remove-player svg { width: 1rem; height: 1rem; }
.empty-roster { color: var(--color-text-secondary); position: absolute; inset: 0; display: grid; place-items: center; font-size: .9rem; }
.roster-pagination { display: flex; align-items: center; justify-content: center; gap: .75rem; height: 2.25rem; }
.roster-pagination button { width: 2.25rem; height: 2.25rem; }
.roster-pagination .tnq-arrow { width: 1.125rem; height: 1.125rem; }
.host-footer { display: flex; align-items: center; justify-content: flex-end; gap: .875rem; min-height: 2.75rem; }
.host-footer .helper, .host-footer .error { margin: 0 auto 0 0; }
.host-footer .error { max-width: 55%; }
.host-start-actions { display: flex; gap: .75rem; align-items: center; flex-shrink: 0; }
.host-start-actions button { font-size: .85rem; min-height: 2.625rem; }
@keyframes rally-spin { to { transform: rotate(360deg); } }
@media (min-width: 768px) {
  #app-container #theme-toggle-button { top: 2rem; right: 2.5rem; }
  .study-logo-link { top: 2rem; }
  .setup-panel { padding: 1.75rem; }
}
@media (max-width: 767px) {
  .study-header nav { min-height: 0; }
  .study-logo-link #header-logo { height: 32px; }
  .rally-wordmark { font-size: 1.1rem; }
  .setup-panel { padding: 20px; }
  .choice { padding: 11px; gap: 8px; }
  .choice strong { font-size: .79rem; }
  .choice small { font-size: .7rem; }
  .setup-actions { gap: 10px; }
  .setup-secondary { gap: 3px; }
  .setup-actions .main-action-button, .setup-actions .secondary-action-button { padding: 10px 12px; font-size: .78rem; }
  .field-heading { align-items: flex-start; }
  #length-result { max-width: 60%; font-size: .75rem; }
}
@media (max-width: 650px) {
  #host-view { gap: 12px; padding: 12px 16px; }
  .host-content { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); gap: 14px; }
  .join-board { flex-direction: row; justify-content: space-between; gap: 16px; text-align: left; }
  .room-code { font-size: 2.4rem; margin: 4px 0 8px; }
  .join-info .helper { font-size: .68rem; margin-bottom: 4px; }
  .share-actions { justify-content: flex-start; gap: 12px; }
  .share-actions .secondary-action-button { font-size: .72rem; padding: 6px 10px; }
  .qr { flex-shrink: 0; width: 100px; }
  .roster-board { padding: 14px; gap: 10px; border-radius: 18px; }
  .roster-heading h1 { font-size: 1rem; }
  .rally-logo img { height: 30px; }
  .rally-logo span { font-size: 1.2rem; }
  .host-footer { gap: 8px; align-items: flex-end; }
  .host-footer .helper { font-size: .7rem; }
  .host-start-actions button { font-size: .74rem; padding: 10px 12px; }
  #join-status { display: none; }
  .lobby-teams { gap: 6px; }
  #lobby-team-helper { font-size: .65rem; }
  .player .avatar { display: none; }
  #roster { grid-auto-rows: 50px; }
  .player { padding: 6px 8px; }
}
@media (max-height: 500px) and (min-width: 651px) {
  #host-view { padding: 10px 20px; gap: 8px; }
  .host-content { gap: 24px; grid-template-columns: minmax(230px, .7fr) minmax(0, 1.3fr); }
  .join-board { flex-direction: row; gap: 12px; }
  .qr { width: 100px; }
  .room-code { font-size: 2rem; margin: 6px 0 10px; }
  .roster-board { padding: 14px; gap: 8px; }
  .roster-heading h1 { font-size: 1rem; }
  .rally-logo img { height: 28px; }
}
@media (max-height: 500px) and (min-width: 480px) and (max-width: 650px) {
  #host-view { padding: 8px 12px; gap: 8px; }
  .host-topbar, .host-topbar .icon-button { height: 36px; }
  .host-content { grid-template-columns: minmax(180px, .75fr) minmax(0, 1.25fr); grid-template-rows: minmax(0, 1fr); gap: 12px; }
  .join-board { flex-direction: column; justify-content: center; gap: 8px; text-align: center; }
  .join-info .helper { font-size: .64rem; }
  .room-code { font-size: 1.9rem; margin: 3px 0 5px; }
  .share-actions { justify-content: center; gap: 10px; }
  .share-actions .secondary-action-button { padding: 5px 8px; }
  .qr { width: 64px; border-radius: 6px; }
  .roster-board { padding: 10px; gap: 6px; }
  .roster-heading h1 { font-size: .85rem; }
  .roster-heading .helper { font-size: .65rem; }
  #lobby-team-helper { min-width: 0; font-size: .6rem; }
  .lobby-teams { gap: 5px; }
  #lobby-team-count { width: 50px; padding: 4px; }
  .host-footer { min-height: 36px; }
  .host-start-actions button { min-height: 36px; padding: 8px; font-size: .7rem; }
}
@media (max-width: 360px) { .study-logo-link { gap: 5px; } .study-logo-link #header-logo { height: 26px; } .rally-wordmark { font-size: 1rem; } .choice-grid { gap: 7px; } .choice-grid:not(.scoring-grid) { grid-template-columns: 1fr; } .choice { padding: 10px; } .choice small { font-size: .68rem; } .setup-panel { padding: 16px; } .qr { width: 86px; } }
@media (max-width: 479px) {
  .host-footer { flex-direction: column; align-items: stretch; gap: 8px; }
  .host-footer .helper, .host-footer .error { width: 100%; max-width: none; text-align: center; margin: 0; }
  .host-start-actions { justify-content: center; gap: 8px; width: 100%; }
  .host-start-actions button { flex: 1; padding: 10px 8px; }
  #start-preview:not([hidden]) { flex: 0 1 auto; }
}
@media (prefers-reduced-motion: reduce) { .rally-page *, .rally-page *::before, .rally-page *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; } }

.rally-team-badge { display: inline-flex; align-items: center; gap: .4375rem; vertical-align: middle; font-weight: 700; }
.rally-team-dot { display: inline-block; flex: 0 0 auto; width: .6875rem; height: .6875rem; border-radius: 50%; box-shadow: 0 0 0 1px #ffffff33; print-color-adjust: exact; -webkit-print-color-adjust: exact; }

:is(.rally-page,.rally-game) summary { list-style: none; }
:is(.rally-page,.rally-game) summary::-webkit-details-marker { display: none; }
:is(.rally-page,.rally-game) summary::before { content: ''; display: inline-block; vertical-align: -.15em; width: 16px; height: 16px; margin-right: 7px; background: currentColor; mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m9 5 7 7-7 7'/%3E%3C/svg%3E") center/contain no-repeat; }
:is(.rally-page,.rally-game) details[open] > summary::before { transform: rotate(90deg); }

.rally-team-assignment { display: inline-flex; align-items: center; gap: 5px; min-width: 0; flex-shrink: 0; }
.player .rally-team-assignment select { max-width: 7rem; }
/* The lobby's sound button looks and reacts like the fullscreen button beside it (TNQ's .icon-button). */
.host-start-actions .rally-sound-toggle { flex: 0 0 3rem; width: 3rem; height: 3rem; min-height: 3rem; padding: 0; display: grid; place-items: center; border-radius: 50%; color: var(--color-text-primary); transition: all .2s ease; }
.host-start-actions .rally-sound-toggle:hover { color: var(--color-primary); background-color: var(--color-card-bg); }
.host-start-actions .rally-sound-toggle svg { width: 1.75rem; height: 1.75rem; }
