:root {
    --page: #f6f7f2;
    --surface: #ffffff;
    --surface-2: #edf1e8;
    --ink: #17231d;
    --muted: #66746a;
    --line: #d9e0d5;
    --filled: #17231d;
    --filled-text: #ffffff;
    --filled-muted: rgba(255, 255, 255, 0.7);
    --brand: #1f7a6d;
    --brand-dark: #13564c;
    --coral: #e95f48;
    --gold: #d8a829;
    --blue: #486db0;
    --violet: #7059a7;
    --danger: #b64036;
    --danger-bg: #fff0ed;
    --danger-border: #e6b4ad;
    --topbar-bg: rgba(246, 247, 242, 0.92);
    --nav-bg: rgba(255, 255, 255, 0.94);
    --sticky-bg: rgba(246, 247, 242, 0.92);
    --scrim: rgba(23, 35, 29, 0.42);
    --focus-ring: rgba(31, 122, 109, 0.16);
    --history-parent-bg: #e4f5ec;
    --history-parent-text: #13564c;
    --history-ref-bg: #fff1ec;
    --history-ref-text: #9b3d2d;
    --status-open-bg: #e8f4ff;
    --status-done-bg: #e4f5ec;
    --status-done-text: #176139;
    --shadow: 0 18px 50px rgba(26, 39, 32, 0.12);
    --nav-shadow: 0 14px 40px rgba(26, 39, 32, 0.16);
    --home-hero-layer: linear-gradient(135deg, rgba(31, 122, 109, 0.92), rgba(23, 35, 29, 0.94));
    --radius: 8px;
    color-scheme: light;
}

:root[data-theme="dark"] {
    --page: #0f1412;
    --surface: #171d1a;
    --surface-2: #222b26;
    --ink: #eef6f1;
    --muted: #9aa99f;
    --line: #344039;
    --filled: #e6f0ea;
    --filled-text: #0d1712;
    --filled-muted: rgba(13, 23, 18, 0.68);
    --brand: #28c5b2;
    --brand-dark: #159284;
    --coral: #ff806a;
    --gold: #e7c75f;
    --blue: #88a9ff;
    --violet: #b096ef;
    --danger: #ff9a90;
    --danger-bg: #3a1e1b;
    --danger-border: #6b312b;
    --topbar-bg: rgba(15, 20, 18, 0.92);
    --nav-bg: rgba(23, 29, 26, 0.96);
    --sticky-bg: rgba(15, 20, 18, 0.9);
    --scrim: rgba(0, 0, 0, 0.66);
    --focus-ring: rgba(40, 197, 178, 0.24);
    --history-parent-bg: rgba(40, 197, 178, 0.16);
    --history-parent-text: #54e0cb;
    --history-ref-bg: rgba(255, 128, 106, 0.16);
    --history-ref-text: #ffab99;
    --status-open-bg: rgba(136, 169, 255, 0.18);
    --status-done-bg: rgba(40, 197, 178, 0.16);
    --status-done-text: #54e0cb;
    --shadow: 0 18px 50px rgba(0, 0, 0, 0.38);
    --nav-shadow: 0 14px 40px rgba(0, 0, 0, 0.42);
    --home-hero-layer: linear-gradient(135deg, rgba(19, 22, 27, 0.96), rgba(34, 25, 35, 0.95) 52%, rgba(46, 38, 30, 0.92));
    color-scheme: dark;
}

* {
    box-sizing: border-box;
}

html,
body {
    min-height: 100%;
}

body {
    margin: 0;
    background: var(--page);
    color: var(--ink);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    letter-spacing: 0;
}

.svg-sprite {
    position: absolute;
    width: 0;
    height: 0;
    overflow: hidden;
}

button,
input,
select,
textarea {
    font: inherit;
}

button {
    cursor: pointer;
}

.app-shell {
    min-height: 100dvh;
    display: grid;
    grid-template-rows: auto auto 1fr auto;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    display: grid;
    grid-template-columns: minmax(160px, 1fr) auto minmax(120px, 1fr);
    align-items: center;
    gap: 16px;
    padding: 12px clamp(14px, 3vw, 28px);
    background: var(--topbar-bg);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(16px);
}

.brand-lockup,
.role-tab,
.account-button,
.icon-button,
.bottom-nav-item {
    border: 0;
    background: transparent;
    color: inherit;
}

.brand-lockup {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    justify-self: start;
    text-align: left;
    padding: 4px;
}

.brand-badge {
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    border-radius: 8px;
    background: var(--surface);
    color: var(--ink);
    border: 1px solid var(--line);
    font-weight: 900;
    letter-spacing: 0;
}

.brand-logo svg {
    width: 36px;
    height: 36px;
    display: block;
    filter: drop-shadow(0 2px 8px rgba(0, 212, 255, 0.2));
}

.brand-lockup strong {
    display: block;
    font-size: 17px;
}

.brand-lockup small {
    display: block;
    color: var(--muted);
    font-size: 12px;
    margin-top: 1px;
}

.role-tabs {
    display: inline-flex;
    gap: 4px;
    padding: 4px;
    border: 1px solid var(--line);
    background: var(--surface);
    border-radius: 8px;
    justify-self: center;
}

.role-tab {
    min-height: 38px;
    min-width: 92px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    border-radius: 6px;
    padding: 0 12px;
    color: var(--muted);
}

.role-tab svg,
.account-button svg,
.icon-button svg,
.bottom-nav-item svg,
button svg {
    width: 18px;
    height: 18px;
    stroke-width: 2.2;
}

.role-tab.active {
    background: var(--filled);
    color: var(--filled-text);
}

.top-actions {
    justify-self: end;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.beta-notice {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 8px clamp(14px, 3vw, 28px);
    background: rgba(112, 89, 167, 0.16);
    border-bottom: 1px solid rgba(112, 89, 167, 0.34);
    color: var(--ink);
    font-size: 13px;
    line-height: 1.25;
    font-weight: 700;
    text-align: center;
}

.beta-notice strong {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    padding: 0 9px;
    border-radius: 999px;
    background: rgba(112, 89, 167, 0.24);
    color: var(--violet);
    font-size: 11px;
    font-weight: 900;
    text-transform: uppercase;
}

.account-button {
    min-height: 46px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 0 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--filled);
    color: var(--filled-text);
    font-weight: 900;
    white-space: nowrap;
}

.account-button span {
    display: inline-block;
}

.sync-pill {
    display: inline-flex;
    align-items: center;
    min-height: 32px;
    padding: 0 10px;
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--muted);
    border: 1px solid var(--line);
    font-size: 12px;
    white-space: nowrap;
}

.sync-pill[hidden] {
    display: none !important;
}

.sync-pill.online {
    background: var(--status-done-bg);
    color: var(--status-done-text);
    border-color: var(--line);
}

.sync-pill.offline {
    background: var(--history-ref-bg);
    color: var(--history-ref-text);
    border-color: var(--line);
}

.status-pill.canceled {
    background: var(--danger-bg);
    color: var(--danger);
}

.icon-button {
    width: 46px;
    height: 46px;
    display: inline-grid;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
}

.screen-stack {
    width: min(1180px, 100%);
    margin: 0 auto;
    padding: clamp(16px, 4vw, 32px) clamp(14px, 4vw, 28px) 92px;
}

.screen {
    display: none;
}

.screen.active {
    display: block;
}

.home-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.45fr) minmax(320px, 0.55fr);
    gap: 20px;
    align-items: stretch;
}

.home-main {
    min-height: 0;
    padding: clamp(18px, 3vw, 30px);
    border-radius: 8px;
    background:
        var(--home-hero-layer),
        url("data:image/svg+xml,%3Csvg width='520' height='520' viewBox='0 0 520 520' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' stroke='%23ffffff' stroke-opacity='.12' stroke-width='2'%3E%3Cpath d='M20 70h480M20 190h480M20 310h480M20 430h480M70 20v480M190 20v480M310 20v480M430 20v480'/%3E%3Ccircle cx='260' cy='260' r='84'/%3E%3C/g%3E%3C/svg%3E");
    background-size: cover;
    color: #ffffff;
    display: grid;
    align-content: start;
    gap: 22px;
}

.home-main h1 {
    margin: 4px 0 0;
    max-width: 680px;
    font-size: clamp(24px, 2.1vw, 32px);
    line-height: 1.18;
    letter-spacing: 0;
}

.eyebrow {
    margin: 0 0 6px;
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
    font-weight: 800;
    letter-spacing: 0.08em;
}

.home-main .eyebrow {
    color: rgba(255, 255, 255, 0.72);
}

.home-brand-row {
    display: flex;
    align-items: center;
    gap: clamp(12px, 3vw, 22px);
}

.home-logo-mark {
    width: clamp(48px, 6vw, 72px);
    height: clamp(48px, 6vw, 72px);
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    filter: drop-shadow(0 0 24px rgba(0, 212, 255, 0.38));
}

.home-logo-mark svg {
    width: 100%;
    height: 100%;
    display: block;
}

.home-sports-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    max-width: 720px;
    color: rgba(255, 255, 255, 0.76);
    font-size: 12px;
    font-weight: 800;
}

.home-sports-row span {
    color: rgba(255, 255, 255, 0.58);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.home-sports-row b {
    min-height: 24px;
    display: inline-flex;
    align-items: center;
    padding: 0 9px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.16);
    color: rgba(255, 255, 255, 0.88);
}

.guide-callout {
    width: fit-content;
    min-height: 42px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 0 14px;
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.1);
    color: #ffffff;
    font-weight: 900;
    text-decoration: none;
}

.guide-callout:hover,
.guide-callout:focus-visible {
    background: rgba(255, 255, 255, 0.16);
    outline: 0;
}

.guide-callout svg {
    width: 18px;
    height: 18px;
}

.role-card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(190px, 100%), 1fr));
    gap: 12px;
}

.role-card,
.panel,
.data-card,
.entity-card,
.history-item,
.schedule-item,
.assignment-item,
.settings-row {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
}

.role-card {
    display: grid;
    gap: 16px;
    padding: 16px;
    color: var(--ink);
    min-height: 176px;
    min-width: 0;
}

.role-card-copy {
    margin: -4px 0 0;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.35;
    font-weight: 700;
}

.parent-accent {
    border-top: 5px solid var(--brand);
}

.org-accent {
    border-top: 5px solid var(--gold);
}

.ref-accent {
    border-top: 5px solid var(--coral);
}

.role-card-head {
    display: flex;
    align-items: center;
    gap: 10px;
}

.role-card-head h2 {
    margin: 0;
    font-size: 20px;
    min-width: 0;
}

.role-card-metrics {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    color: var(--muted);
}

.role-card-metrics strong {
    color: var(--ink);
}

.today-panel,
.panel {
    padding: 18px;
    border-radius: 8px;
    background: var(--surface);
    border: 1px solid var(--line);
}

.today-panel {
    box-shadow: var(--shadow);
}

.section-title-row,
.workspace-heading,
.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.workspace-heading {
    margin-bottom: 18px;
}

.workspace-heading.compact {
    margin-bottom: 12px;
}

.workspace-heading h1,
.section-title-row h2,
.modal-head h2 {
    margin: 0;
}

.workspace-heading h1 {
    font-size: clamp(26px, 4vw, 42px);
    line-height: 1;
}

.button-cluster {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.primary-button,
.secondary-button,
.soft-button,
.danger-button,
.mini-button,
.icon-command {
    min-height: 46px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border-radius: 8px;
    border: 1px solid transparent;
    padding: 0 14px;
    font-weight: 800;
    letter-spacing: 0;
}

.primary-button {
    background: var(--brand);
    color: #ffffff;
    border-color: var(--brand-dark);
}

.secondary-button {
    background: var(--surface);
    color: var(--ink);
    border-color: var(--line);
}

.secondary-button.active,
.code-mode-option.active {
    background: var(--filled);
    color: var(--filled-text);
    border-color: var(--filled);
}

.soft-button {
    background: var(--surface-2);
    color: var(--ink);
    border-color: var(--line);
}

.danger-button {
    background: var(--danger-bg);
    color: var(--danger);
    border-color: var(--danger-border);
}

.full-width {
    width: 100%;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
}

.dashboard-grid .wide {
    grid-column: span 2;
}

.pilot-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.35fr) minmax(300px, 0.65fr);
    gap: 14px;
    align-items: start;
}

.pilot-notes-panel {
    grid-column: 1 / -1;
}

.form-grid .form-span,
.pilot-form .form-span {
    grid-column: 1 / -1;
}

.readiness-score {
    font-size: 28px;
}

.readiness-meter {
    height: 10px;
    overflow: hidden;
    border-radius: 999px;
    background: var(--surface-2);
    border: 1px solid var(--line);
}

.readiness-meter i {
    width: var(--usage-width, 0%);
    height: 100%;
    display: block;
    border-radius: inherit;
    background: var(--brand);
}

.readiness-list {
    display: grid;
    gap: 10px;
    margin-top: 14px;
}

.readiness-item {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 10px;
    align-items: start;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-2);
}

.readiness-item svg {
    color: var(--muted);
}

.readiness-item.ready svg {
    color: var(--brand);
}

.pilot-rule-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
}

.pilot-rule-grid > div {
    display: grid;
    gap: 5px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-2);
}

.pilot-rule-grid span {
    color: var(--muted);
}

.today-list,
.athlete-strip,
.entity-grid,
.history-list,
.schedule-list,
.assignment-list,
.settings-list {
    display: grid;
    gap: 10px;
}

.athlete-strip {
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
}

.entity-grid {
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
}

.org-access-banner {
    margin-bottom: 14px;
}

.access-banner-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
}

.access-banner-card h2 {
    margin: 0 0 4px;
}

.compact-select {
    width: auto;
    min-width: 210px;
    min-height: 46px;
}

.org-people-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.35fr) minmax(280px, 0.65fr);
    gap: 14px;
    align-items: start;
}

.org-people-layout .wide {
    grid-row: span 2;
}

.org-switch-list,
.member-list,
.invite-list {
    display: grid;
    gap: 10px;
    margin-top: 12px;
}

.org-switch-list {
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.member-row,
.invite-row {
    display: grid;
    gap: 10px;
    align-items: center;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-2);
}

.member-row {
    grid-template-columns: auto minmax(0, 1fr) auto auto;
}

.invite-row {
    grid-template-columns: minmax(0, 1fr) auto auto auto;
}

.role-pill {
    min-height: 30px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 10px;
    border-radius: 999px;
    background: var(--surface);
    color: var(--muted);
    border: 1px solid var(--line);
    font-weight: 900;
    font-size: 12px;
    white-space: nowrap;
}

.role-pill.owner {
    background: var(--status-open-bg);
    color: var(--blue);
}

.role-pill.admin {
    background: var(--history-parent-bg);
    color: var(--history-parent-text);
}

.role-pill.referee {
    background: var(--history-ref-bg);
    color: var(--history-ref-text);
}

.member-controls {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.compact-form {
    margin-top: 10px;
}

.divider-line {
    height: 1px;
    margin: 16px 0;
    background: var(--line);
}

.data-card,
.entity-card,
.history-item,
.schedule-item,
.assignment-item {
    padding: 14px;
}

.data-card.empty,
.empty-state {
    color: var(--muted);
    background: var(--surface-2);
}

.entity-card {
    display: grid;
    gap: 12px;
}

.entity-card-head,
.history-main,
.schedule-main,
.assignment-main {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: flex-start;
}

.history-main {
    align-items: center;
}

.entity-avatar {
    width: 48px;
    height: 48px;
    display: grid;
    place-items: center;
    border-radius: 8px;
    background: var(--filled);
    color: var(--filled-text);
    font-weight: 900;
}

.card-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.metric-stack {
    display: grid;
    gap: 8px;
}

.metric-line {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    padding: 9px 0;
    border-bottom: 1px solid var(--line);
}

.metric-line:last-child {
    border-bottom: 0;
}

.metric-line strong {
    font-size: 22px;
}

.score-adjust-line {
    align-items: center;
}

.compact-stepper {
    grid-template-columns: 38px 42px 38px;
}

.compact-stepper button {
    min-height: 38px;
}

.usage-card {
    display: grid;
    gap: 8px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-2);
}

.usage-card .metric-line {
    padding: 0;
    border-bottom: 0;
}

.usage-meter {
    height: 9px;
    overflow: hidden;
    border-radius: 999px;
    background: var(--surface);
    border: 1px solid var(--line);
}

.usage-meter i {
    width: var(--usage-width, 0%);
    height: 100%;
    display: block;
    border-radius: inherit;
    background: var(--brand);
}

.usage-card.limit-hit {
    background: var(--danger-bg);
    border-color: var(--danger-border);
}

.usage-card.limit-hit .usage-meter i {
    background: var(--danger);
}

.handoff-note {
    display: grid;
    gap: 6px;
    padding: 12px;
    border: 1px solid rgba(245, 158, 11, 0.35);
    border-radius: 8px;
    background: rgba(245, 158, 11, 0.1);
}

.handoff-note strong {
    color: var(--ink);
}

.handoff-note span {
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
}

.primary-button.limit-hit {
    background: var(--danger);
    border-color: var(--danger-border);
}

.tracker-shell {
    display: grid;
    gap: 14px;
}

.tracker-top {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 16px;
}

.tracker-top h1 {
    margin: 0;
    font-size: clamp(26px, 5vw, 46px);
}

.tracker-selects {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.field-control,
.score-ribbon input,
.score-ribbon select,
.notes-area {
    width: 100%;
    min-height: 46px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--ink);
    padding: 0 12px;
    outline: none;
}

.field-control:focus,
.score-ribbon input:focus,
.notes-area:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 3px var(--focus-ring);
}

.score-ribbon {
    display: grid;
    grid-template-columns: minmax(160px, 1fr) 110px 110px 110px;
    gap: 10px;
    align-items: end;
}

.score-ribbon label {
    display: grid;
    gap: 5px;
    color: var(--muted);
    font-weight: 700;
    font-size: 13px;
}

.score-chip {
    min-height: 62px;
    display: grid;
    place-items: center;
    padding: 8px;
    border-radius: 8px;
    background: var(--filled);
    color: var(--filled-text);
}

.score-chip span {
    font-size: 12px;
    color: var(--filled-muted);
}

.score-chip strong {
    font-size: 30px;
    line-height: 1;
}

.stat-button-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(118px, 1fr));
    gap: 10px;
    --stat-columns: 3;
    --stat-rows: 3;
}

.stat-button {
    min-height: 96px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--ink);
    display: grid;
    gap: 6px;
    align-content: center;
    padding: 12px;
    text-align: left;
}

.stat-button strong {
    font-size: 24px;
}

.stat-button span {
    color: var(--muted);
    font-weight: 800;
}

.stat-button.scoring {
    border-left: 5px solid var(--brand);
}

.stat-button.defense {
    border-left: 5px solid var(--blue);
}

.stat-button.misc {
    border-left: 5px solid var(--gold);
}

.stat-button.custom {
    border-left: 5px solid var(--coral);
}

.stat-help-list {
    display: grid;
    gap: 10px;
}

.stat-help-item {
    display: grid;
    grid-template-columns: minmax(88px, 0.25fr) minmax(0, 1fr);
    gap: 12px;
    align-items: center;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-2);
}

.stat-help-item strong {
    display: block;
    font-size: 24px;
    line-height: 1;
}

.stat-help-item span {
    color: var(--muted);
    font-weight: 800;
}

.stat-help-item p {
    margin: 0;
    color: var(--ink);
}

.sticky-command-bar {
    position: sticky;
    bottom: 76px;
    z-index: 20;
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--sticky-bg);
    backdrop-filter: blur(16px);
}

.icon-command {
    background: var(--surface);
    border-color: var(--line);
    color: var(--ink);
}

.history-filters {
    display: grid;
    grid-template-columns: minmax(150px, 190px) minmax(150px, 220px);
    gap: 8px;
}

.history-type-pill {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    width: fit-content;
    padding: 0 8px;
    border-radius: 999px;
    margin-bottom: 5px;
    font-size: 11px;
    font-weight: 900;
    background: var(--surface-2);
    color: var(--muted);
}

.history-type-pill.parent {
    background: var(--history-parent-bg);
    color: var(--history-parent-text);
}

.history-type-pill.referee {
    background: var(--history-ref-bg);
    color: var(--history-ref-text);
}

.history-pager {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 8px;
    align-items: center;
}

.history-pager span {
    color: var(--muted);
    font-weight: 900;
    min-width: 54px;
    text-align: center;
}

.history-pager button:disabled {
    opacity: 0.45;
    cursor: default;
}

.compact-stat-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
}

.compact-stat-grid > div {
    min-height: 68px;
    display: grid;
    align-content: center;
    gap: 4px;
    padding: 10px;
    border-radius: 8px;
    background: var(--surface-2);
}

.compact-stat-grid span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 900;
}

.compact-stat-grid strong {
    font-size: 28px;
}

.stat-chart {
    display: grid;
    gap: 8px;
    margin-top: 12px;
}

.stat-chart-title {
    color: var(--muted);
    font-size: 12px;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 0;
}

.stat-chart-row {
    display: grid;
    grid-template-columns: minmax(82px, 1fr) minmax(90px, 2fr) 34px;
    gap: 8px;
    align-items: center;
    min-height: 30px;
}

.stat-chart-row span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.stat-chart-row strong {
    text-align: right;
}

.stat-bar-track {
    height: 10px;
    overflow: hidden;
    border-radius: 999px;
    background: var(--surface-2);
}

.stat-bar-track i {
    display: block;
    width: var(--bar-width, 0%);
    height: 100%;
    border-radius: inherit;
    background: var(--brand);
}

.parent-live-top {
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr) 42px;
    gap: 10px;
    align-items: center;
}

.parent-live-top h1 {
    margin: 0;
    font-size: clamp(22px, 5vw, 34px);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.parent-scoreboard {
    display: grid;
    grid-template-columns: 1fr minmax(112px, 0.5fr) 1fr;
    gap: 10px;
}

.parent-score-card {
    min-height: 118px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: var(--surface);
    display: grid;
    place-items: center;
    text-align: center;
    padding: 10px;
}

.parent-score-card.team-card {
    border-top: 5px solid var(--blue);
}

.parent-score-card.player-card {
    border-top: 5px solid var(--brand);
}

.parent-score-card.opponent-card {
    border-top: 5px solid var(--coral);
}

.parent-score-card span,
.parent-game-fields span {
    color: var(--muted);
    font-weight: 900;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.parent-score-card strong,
.parent-score-card input {
    width: 100%;
    border: 0;
    background: transparent;
    color: var(--ink);
    text-align: center;
    font-size: clamp(48px, 11vw, 86px);
    line-height: 0.9;
    font-weight: 900;
    outline: none;
}

.parent-score-card input::-webkit-outer-spin-button,
.parent-score-card input::-webkit-inner-spin-button {
    margin: 0;
    -webkit-appearance: none;
}

.score-control {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-areas:
        "score score"
        "minus plus";
    gap: 4px;
    align-items: center;
}

.score-control button {
    min-width: 46px;
    min-height: 46px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: var(--surface-2);
    color: var(--ink);
    font-size: 24px;
    font-weight: 900;
}

.score-control button:first-child {
    grid-area: minus;
}

.score-control button:last-child {
    grid-area: plus;
}

.score-control input {
    grid-area: score;
    font-size: clamp(32px, 7.5vw, 56px);
    min-height: 38px;
}

.parent-game-fields {
    display: grid;
    grid-template-columns: minmax(150px, 1fr) minmax(150px, 1fr) 150px;
    gap: 8px;
}

.parent-game-fields label,
.parent-timer-panel {
    display: grid;
    gap: 4px;
}

.parent-game-fields .field-control,
.parent-game-fields input {
    min-height: 46px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--ink);
    padding: 0 10px;
}

.tracker-date-hidden {
    display: none;
}

.parent-timer-panel {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    padding: 6px;
    align-content: center;
    text-align: center;
}

.parent-timer-panel strong {
    font-size: 24px;
    line-height: 1;
}

.parent-timer-panel .mini-button {
    min-height: 46px;
    padding: 0 8px;
    font-size: 12px;
}

.parent-timer-panel .mini-button.running {
    background: var(--coral);
}

body[data-screen="tracker"] .topbar,
body[data-screen="tracker"] .beta-notice,
body[data-screen="tracker"] .bottom-nav {
    display: none;
}

body[data-screen="tracker"] .app-shell {
    grid-template-rows: 1fr;
}

body[data-screen="tracker"] .screen-stack {
    width: 100%;
    max-width: 980px;
    padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
}

body[data-screen="tracker"] .parent-live-screen.active {
    min-height: calc(100dvh - 16px);
    display: grid;
}

body[data-screen="tracker"] .tracker-shell {
    min-height: calc(100dvh - 16px);
    grid-template-rows: auto auto auto 1fr auto;
    gap: 10px;
}

body[data-screen="tracker"] .stat-button-grid {
    grid-template-columns: repeat(var(--stat-columns), minmax(0, 1fr));
    gap: 8px;
    align-content: stretch;
}

body[data-screen="tracker"] .stat-button {
    min-height: 70px;
    background: var(--surface);
    align-content: center;
    text-align: center;
    padding: 8px;
}

body[data-screen="tracker"] .stat-button span {
    font-size: 13px;
}

body[data-screen="tracker"] .stat-button strong {
    font-size: clamp(24px, 6vw, 38px);
}

body[data-screen="tracker"] .sticky-command-bar {
    position: static;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    bottom: auto;
    padding: 0;
    border: 0;
    background: transparent;
    backdrop-filter: none;
}

body[data-screen="tracker"] .sticky-command-bar > * {
    width: 100%;
}

.review-layout,
.summary-grid,
.player-detail-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(260px, 0.45fr);
    gap: 14px;
}

.review-stat-list,
.summary-stat-list,
.mini-table {
    display: grid;
    gap: 8px;
}

.review-stat-row,
.summary-stat-row,
.mini-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 12px;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--line);
}

.review-stat-row:last-child,
.summary-stat-row:last-child,
.mini-row:last-child {
    border-bottom: 0;
}

.stepper {
    display: inline-grid;
    grid-template-columns: 46px 42px 46px;
    align-items: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
}

.stepper button {
    min-height: 46px;
    border: 0;
    background: var(--surface-2);
    color: var(--ink);
    font-weight: 900;
}

.stepper span {
    text-align: center;
    font-weight: 900;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.form-grid label,
.stacked-form label {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-weight: 800;
    font-size: 13px;
}

.form-actions {
    grid-column: 1 / -1;
}

.stacked-form {
    display: grid;
    gap: 12px;
}

.inline-message {
    min-height: 20px;
    color: var(--danger);
    font-weight: 700;
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 80;
    display: none;
    place-items: center;
    padding: 16px;
    background: var(--scrim);
}

.modal.active {
    display: grid;
}

.modal-panel {
    width: min(680px, 100%);
    max-height: min(760px, calc(100dvh - 32px));
    overflow: auto;
    padding: 18px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.modal-panel.narrow {
    width: min(440px, 100%);
}

.modal-copy {
    margin: 0 0 14px;
    color: var(--muted);
    font-weight: 700;
}

.resume-summary-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    margin: 12px 0;
}

.resume-summary-grid > div {
    display: grid;
    gap: 4px;
    min-height: 74px;
    align-content: center;
    justify-items: center;
    padding: 10px 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-2);
}

.resume-summary-grid span {
    color: var(--muted);
    font-size: 11px;
    font-weight: 900;
    text-transform: uppercase;
}

.resume-summary-grid strong {
    font-size: 26px;
    line-height: 1;
}

.modal-action-stack {
    display: grid;
    gap: 10px;
    margin-top: 14px;
}

.segmented-control {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    padding: 4px;
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: 8px;
    margin: 16px 0;
}

.segmented-control button {
    min-height: 46px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--muted);
    font-weight: 900;
}

.segmented-control button.active {
    background: var(--surface);
    color: var(--ink);
}

.notes-area {
    min-height: 180px;
    padding: 12px;
    resize: vertical;
}

.history-item,
.schedule-item,
.assignment-item {
    display: grid;
    gap: 10px;
}

.item-meta {
    color: var(--muted);
    font-size: 13px;
}

.warning-text {
    color: var(--gold);
    font-weight: 800;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    padding: 0 9px;
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--muted);
    font-size: 12px;
    font-weight: 900;
}

.status-pill.open {
    background: var(--status-open-bg);
    color: var(--blue);
}

.status-pill.live {
    background: var(--brand-soft);
    color: var(--brand-strong);
}

.status-pill.warning {
    background: rgba(245, 158, 11, 0.16);
    color: var(--gold);
}

.status-pill.done {
    background: var(--status-done-bg);
    color: var(--status-done-text);
}

.history-score-card {
    min-width: 94px;
    display: grid;
    justify-items: center;
    gap: 2px;
    padding: 8px 10px;
    border-radius: 8px;
    background: var(--surface-2);
    border: 1px solid var(--line);
}

.history-score-card span {
    color: var(--muted);
    font-size: 11px;
    font-weight: 900;
    text-transform: uppercase;
}

.history-score-card strong {
    font-size: 28px;
    line-height: 1;
}

.history-score-card.win {
    border-color: var(--brand);
}

.history-score-card.loss {
    border-color: var(--coral);
}

.history-score-card.tie,
.history-score-card.final {
    border-color: var(--blue);
}

.history-score-card.no-score strong {
    color: var(--muted);
}

.public-scoreboard {
    min-height: 420px;
    display: grid;
    place-items: center;
    border-radius: 8px;
    background: var(--filled);
    color: var(--filled-text);
    padding: clamp(20px, 5vw, 44px);
}

.public-board-inner {
    width: min(760px, 100%);
    display: grid;
    gap: 20px;
}

.public-score-row {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 18px;
    align-items: center;
}

.public-team-score {
    display: grid;
    gap: 8px;
    justify-items: center;
}

.public-score-row strong {
    font-size: clamp(48px, 12vw, 130px);
    line-height: 0.9;
}

.public-timeouts,
.timeout-mini {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    color: var(--filled-text);
    font-size: 12px;
    font-weight: 900;
}

.timeout-mini {
    color: var(--muted);
}

.timeout-mini b,
.public-timeouts b {
    display: inline-flex;
    gap: 4px;
}

.timeout-mark {
    width: 10px;
    height: 10px;
    border-radius: 999px;
    border: 1px solid currentColor;
    opacity: 0.45;
}

.timeout-mark.used {
    background: currentColor;
    opacity: 1;
}

.public-action-row {
    display: grid;
    grid-template-columns: auto minmax(180px, 1fr) auto;
    gap: 10px;
    align-items: center;
}

.qr-card {
    min-height: 54px;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.12);
    color: var(--filled-text);
    font-weight: 900;
}

.qr-mark {
    width: 38px;
    height: 38px;
    border-radius: 6px;
    background:
        linear-gradient(90deg, currentColor 3px, transparent 3px) 0 0 / 9px 9px,
        linear-gradient(currentColor 3px, transparent 3px) 0 0 / 9px 9px,
        var(--filled);
    box-shadow: inset 0 0 0 5px currentColor;
}

.scan-code-box {
    width: var(--qr-size, 112px);
    height: var(--qr-size, 112px);
    display: inline-grid;
    place-items: center;
    position: relative;
    flex: 0 0 auto;
}

.scan-code-box > * {
    grid-area: 1 / 1;
}

.scan-code-box .qr-mark,
.qr-render,
.qr-image {
    width: 100%;
    height: 100%;
}

.qr-render,
.qr-image {
    border-radius: 8px;
    background: #ffffff;
    box-shadow: 0 0 0 1px rgba(13, 23, 18, 0.12);
}

.qr-render {
    display: none;
    padding: 5px;
}

.qr-render img,
.qr-render canvas {
    width: 100% !important;
    height: 100% !important;
    display: block;
}

.qr-render[data-ready="true"] {
    display: block;
}

.qr-image {
    display: block;
    object-fit: contain;
    opacity: 0;
}

.qr-image[data-ready="true"] {
    opacity: 1;
}

.qr-render[data-ready="true"] ~ .qr-image,
.qr-render[data-ready="true"] ~ .qr-mark,
.qr-image[data-ready="true"] + .qr-mark {
    display: none;
}

.code-sheet-list {
    display: grid;
    gap: 12px;
}

.lobby-code-board {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 330px), 1fr));
    gap: 14px;
    align-items: stretch;
}

.lobby-code-card {
    min-height: 360px;
    display: grid;
    gap: 16px;
    align-content: space-between;
    padding: clamp(14px, 2vw, 22px);
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.lobby-code-top {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: flex-start;
}

.lobby-code-top h2 {
    margin: 8px 0 6px;
    font-size: clamp(24px, 3vw, 34px);
    line-height: 1.05;
}

.lobby-scan-row {
    display: grid;
    grid-template-columns: minmax(180px, auto) minmax(0, 1fr);
    gap: 16px;
    align-items: end;
}

.lobby-qr {
    display: grid;
    gap: 8px;
    justify-items: center;
    text-align: center;
    color: var(--ink);
}

.lobby-qr strong {
    font-size: 20px;
}

.lobby-qr > span:not(.scan-code-box),
.mini-ref-code > span:not(.scan-code-box) {
    color: var(--muted);
    font-weight: 800;
}

.lobby-actions {
    display: grid;
    gap: 8px;
}

.mini-ref-code {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    justify-content: center;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-2);
}

.code-sheet-card,
.print-code-card {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
}

.code-sheet-card {
    display: grid;
    gap: 12px;
    padding: 14px;
}

.code-sheet-head {
    display: flex;
    justify-content: space-between;
    gap: 12px;
}

.print-code-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.print-code-card {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 10px;
    align-items: center;
    padding: 10px;
}

.print-code-art {
    display: grid;
    gap: 6px;
    justify-items: center;
}

.barcode-mark {
    width: 54px;
    height: 18px;
    border-radius: 3px;
    background:
        linear-gradient(90deg, currentColor 0 3px, transparent 3px 6px, currentColor 6px 8px, transparent 8px 12px, currentColor 12px 17px, transparent 17px 20px, currentColor 20px 22px, transparent 22px 27px, currentColor 27px 33px, transparent 33px 37px, currentColor 37px 40px, transparent 40px 44px, currentColor 44px 54px);
    color: var(--ink);
}

.print-code-card code {
    display: inline-block;
    margin-top: 4px;
    color: var(--muted);
    font-size: 11px;
}

.settings-list {
    max-width: 820px;
}

.settings-row {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: center;
    padding: 14px;
}

.settings-row strong,
.settings-row span {
    display: block;
}

.settings-row span {
    color: var(--muted);
    margin-top: 3px;
}

.theme-toggle {
    min-width: min(360px, 100%);
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
}

.theme-toggle .soft-button {
    padding: 0 10px;
}

.theme-toggle .soft-button.active {
    background: var(--filled);
    color: var(--filled-text);
    border-color: var(--filled);
}

.bottom-nav {
    position: fixed;
    left: 50%;
    bottom: max(10px, env(safe-area-inset-bottom));
    transform: translateX(-50%);
    z-index: 40;
    width: min(620px, calc(100% - 22px));
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 4px;
    padding: 6px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: var(--nav-bg);
    box-shadow: var(--nav-shadow);
    backdrop-filter: blur(16px);
}

.bottom-nav-item {
    min-height: 50px;
    display: grid;
    place-items: center;
    gap: 2px;
    border-radius: 6px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 900;
}

.bottom-nav-item.active {
    background: var(--filled);
    color: var(--filled-text);
}

.toast {
    position: fixed;
    right: 18px;
    bottom: 86px;
    z-index: 100;
    max-width: 360px;
    display: none;
    padding: 12px 14px;
    border-radius: 8px;
    background: var(--filled);
    color: var(--filled-text);
    box-shadow: var(--shadow);
    font-weight: 800;
}

.toast.active {
    display: block;
}

@media print {
    body {
        background: #ffffff;
        color: #111111;
        overflow: visible;
    }

    .topbar,
    .bottom-nav,
    .workspace-heading .button-cluster,
    .screen:not(#org-codes-screen) {
        display: none !important;
    }

    .app-shell,
    .screen-stack,
    #org-codes-screen,
    #org-codes-screen.screen.active {
        display: block !important;
        height: auto !important;
        overflow: visible !important;
        padding: 0 !important;
    }

    .code-sheet-card,
    .print-code-card {
        break-inside: avoid;
        color: #111111;
        background: #ffffff;
        border-color: #999999;
    }
}

.ref-live-shell {
    display: grid;
    gap: 10px;
}

.ref-live-top {
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr) 42px;
    gap: 10px;
    align-items: center;
}

.ref-live-top h1 {
    margin: 0;
    font-size: clamp(22px, 5vw, 34px);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ref-scoreboard {
    display: grid;
    grid-template-columns: 1fr minmax(112px, 0.45fr) 1fr;
    gap: 10px;
}

.ref-team-score,
.ref-clock-box {
    min-height: 118px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: var(--surface);
    display: grid;
    place-items: center;
    text-align: center;
    padding: 10px;
}

.ref-team-score.away {
    border-top: 5px solid var(--blue);
}

.ref-team-score.home {
    border-top: 5px solid var(--coral);
}

.ref-team-score span,
.ref-clock-box span {
    color: var(--muted);
    font-weight: 900;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ref-team-score strong {
    font-size: clamp(48px, 11vw, 86px);
    line-height: 0.9;
}

.ref-clock-box strong {
    font-size: clamp(30px, 6vw, 54px);
    line-height: 1;
}

.mini-button {
    min-height: 46px;
    background: var(--filled);
    color: var(--filled-text);
}

.ref-control-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.ref-team-column {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    padding: 10px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: var(--surface);
}

.ref-team-column button {
    min-height: 58px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-2);
    color: var(--ink);
    font-weight: 900;
}

.ref-team-column button:nth-child(4),
.ref-team-column button:nth-child(5),
.ref-team-column button:nth-child(6),
.ref-team-column button:nth-child(7),
.ref-team-column button:nth-child(8) {
    font-size: 13px;
}

.ref-team-column button:nth-child(7),
.ref-team-column button:nth-child(8) {
    grid-column: span 1;
}

.ref-live-bottom {
    display: grid;
    grid-template-columns: 0.8fr 1fr 1fr;
    gap: 10px;
}

body[data-screen="ref-live"] .topbar,
body[data-screen="ref-live"] .beta-notice,
body[data-screen="ref-live"] .bottom-nav {
    display: none;
}

body[data-screen="ref-live"] .app-shell {
    grid-template-rows: 1fr;
}

body[data-screen="ref-live"] .screen-stack {
    width: 100%;
    max-width: 980px;
    padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
}

body[data-screen="ref-live"] .ref-live-screen.active {
    min-height: calc(100dvh - 16px);
    display: grid;
}

body[data-screen="ref-live"] .ref-live-shell {
    min-height: calc(100dvh - 16px);
    grid-template-rows: auto auto 1fr auto;
}

@media (min-width: 701px) and (max-width: 1100px) {
    .home-layout {
        grid-template-columns: 1fr;
    }

    .today-panel {
        display: grid;
    }
}

@media (min-width: 701px) and (max-width: 1180px) {
    .screen-stack {
        width: min(100%, 1120px);
        padding-inline: clamp(20px, 3.5vw, 34px);
    }

    .dashboard-grid,
    .summary-grid,
    .player-detail-layout {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .dashboard-grid .wide {
        grid-column: span 2;
    }

    .lobby-code-board {
        grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    }

    body[data-screen="org-codes"] .screen-stack {
        width: min(100%, 1240px);
    }
}

@media (max-width: 900px) {
    .topbar {
        grid-template-columns: minmax(0, 1fr) auto;
    }

    .role-tabs {
        display: none;
    }

    .top-actions {
        min-width: 0;
    }
}

@media (max-width: 700px) {
    .topbar {
        grid-template-columns: 1fr auto;
    }

    .role-tabs {
        grid-column: 1 / -1;
        width: 100%;
    }

    .role-tab {
        flex: 1;
        min-width: 0;
    }

    .home-layout,
    .dashboard-grid,
    .pilot-layout,
    .org-people-layout,
    .review-layout,
    .summary-grid,
    .player-detail-layout {
        grid-template-columns: 1fr;
    }

    .dashboard-grid .wide {
        grid-column: auto;
    }

    .role-card-grid {
        grid-template-columns: 1fr;
    }

    .home-main {
        min-height: auto;
    }

    .access-banner-card {
        display: grid;
    }

    .org-people-layout .wide {
        grid-row: auto;
    }

    .member-row,
    .invite-row {
        grid-template-columns: auto minmax(0, 1fr);
    }

    .member-row .role-pill,
    .invite-row .role-pill,
    .invite-row .status-pill,
    .member-controls {
        grid-column: 1 / -1;
    }

    .member-controls {
        justify-content: stretch;
    }

    .member-controls > * {
        flex: 1;
    }

    .pilot-notes-panel,
    .pilot-form .form-span {
        grid-column: auto;
    }

    .pilot-rule-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 620px) {
    html,
    body {
        min-height: 100%;
        height: auto;
        overflow-x: hidden;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-y: auto;
    }

    .app-shell {
        min-height: 100svh;
        height: auto;
        overflow: visible;
    }

    .screen.active {
        height: auto;
        min-height: 0;
        overflow: visible;
    }

    .screen-stack {
        padding: 14px 12px calc(108px + env(safe-area-inset-bottom));
        overflow: visible;
    }

    .topbar {
        position: relative;
        grid-template-columns: 1fr auto;
        padding: 10px 12px;
        gap: 10px;
    }

    .role-tabs {
        display: none;
    }

    .top-actions {
        gap: 6px;
    }

    .beta-notice {
        gap: 7px;
        padding: 7px 10px;
        font-size: 11px;
    }

    .beta-notice strong {
        min-height: 22px;
        padding: 0 7px;
        font-size: 10px;
    }

    .account-button {
        min-height: 42px;
        padding: 0 10px;
        gap: 6px;
    }

    .sync-pill {
        display: none;
    }

    .brand-badge {
        width: 36px;
        height: 36px;
        font-size: 13px;
    }

    .brand-logo svg {
        width: 30px;
        height: 30px;
    }

    .role-tab span {
        font-size: 12px;
    }

    .workspace-heading,
    .section-title-row {
        align-items: stretch;
        flex-direction: column;
    }

    .workspace-heading {
        margin-bottom: 8px;
        gap: 8px;
    }

    .workspace-heading h1 {
        font-size: 24px;
    }

    .home-layout {
        height: 100%;
        gap: 8px;
    }

    .today-panel {
        display: none;
    }

    .home-main {
        height: 100%;
        min-height: 0;
        padding: 12px;
        gap: 8px;
    }

    .home-brand-row {
        gap: 8px;
    }

    .home-logo-mark {
        width: 46px;
        height: 46px;
    }

    .home-main h1 {
        font-size: 23px;
        line-height: 1.16;
        margin: 0 0 4px;
    }

    .home-sports-row {
        gap: 4px;
        font-size: 10px;
    }

    .home-sports-row b {
        min-height: 20px;
        padding: 0 6px;
    }

    .guide-callout {
        width: 100%;
    }

    .role-card-grid {
        gap: 7px;
    }

    .role-card {
        min-height: 0;
        padding: 10px;
        gap: 8px;
    }

    .role-card-head h2 {
        font-size: 16px;
    }

    .role-card-copy {
        font-size: 12px;
        line-height: 1.25;
    }

    .role-card-metrics {
        display: none;
    }

    .role-card .primary-button {
        min-height: 46px;
    }

    .panel,
    .today-panel {
        padding: 10px;
    }

    .dashboard-grid {
        height: calc(100% - 58px);
        gap: 8px;
        overflow: hidden;
    }

    .athlete-strip,
    .entity-grid {
        grid-template-columns: 1fr;
        gap: 8px;
        overflow: hidden;
    }

    .athlete-strip .entity-card:nth-child(n+3),
    .entity-grid .entity-card:nth-child(n+5) {
        display: none;
    }

    .entity-card,
    .history-item,
    .schedule-item,
    .assignment-item,
    .data-card {
        padding: 10px;
    }

    .history-filters {
        grid-template-columns: 1fr 1fr;
    }

    .history-list {
        gap: 7px;
        height: auto;
        overflow: visible;
    }

    .history-item {
        min-height: 0;
        gap: 10px;
    }

    .history-main {
        gap: 10px;
    }

    .history-main > div {
        min-width: 0;
    }

    .history-main strong {
        display: block;
        max-width: min(310px, calc(100vw - 128px));
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .history-item .card-actions {
        align-items: center;
        justify-content: flex-start;
    }

    .history-item .card-actions .secondary-button {
        min-height: 46px;
        min-width: 154px;
    }

    .history-pager {
        gap: 6px;
    }

    .public-scoreboard {
        min-height: 360px;
        padding: 14px;
    }

    .public-board-inner {
        gap: 12px;
    }

    .public-score-row {
        gap: 8px;
    }

    .public-action-row {
        grid-template-columns: 1fr;
    }

    .public-action-row .primary-button,
    .public-action-row .secondary-button,
    .qr-card {
        min-height: 48px;
        width: 100%;
    }

    .print-code-grid,
    .print-code-card {
        grid-template-columns: 1fr;
    }

    .lobby-code-board {
        gap: 10px;
    }

    .lobby-code-card {
        min-height: auto;
        gap: 12px;
        padding: 12px;
        box-shadow: none;
    }

    .lobby-code-top,
    .lobby-scan-row {
        grid-template-columns: 1fr;
    }

    .lobby-code-top {
        display: grid;
    }

    .lobby-code-top h2 {
        font-size: 22px;
    }

    .lobby-scan-row {
        gap: 10px;
    }

    .print-code-card {
        justify-items: stretch;
    }

    .print-code-art {
        grid-template-columns: auto 1fr;
        justify-items: start;
        align-items: center;
    }

    .compact-stat-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 6px;
    }

    .compact-stat-grid > div {
        min-height: 58px;
        padding: 8px;
    }

    .stat-chart-row {
        grid-template-columns: minmax(72px, 1fr) minmax(72px, 1.4fr) 30px;
        gap: 6px;
    }

    .stat-chart-row span {
        font-size: 11px;
    }

    #review-screen .review-layout {
        height: calc(100% - 52px);
        grid-template-columns: 1fr;
        grid-template-rows: minmax(0, 1fr) auto;
        gap: 8px;
        overflow: hidden;
    }

    #review-screen .panel {
        min-height: 0;
        overflow: hidden;
    }

    #review-screen .section-title-row {
        flex-direction: row;
        align-items: center;
        gap: 8px;
    }

    #review-screen .section-title-row h2 {
        max-width: 240px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        font-size: 16px;
    }

    #review-screen .review-stat-list {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 5px;
    }

    #review-screen .review-stat-row {
        min-height: 56px;
        grid-template-columns: 1fr;
        gap: 4px;
        padding: 6px;
        border: 0;
        border-radius: 8px;
        background: var(--surface-2);
        font-size: 11px;
        text-align: center;
    }

    #review-screen .stepper {
        grid-template-columns: 46px 30px 46px;
        margin: 0 auto;
    }

    #review-screen .compact-stepper {
        grid-template-columns: 38px 28px 38px;
    }

    #review-screen .stepper button {
        min-height: 46px;
    }

    #review-screen .compact-stepper button {
        min-height: 38px;
    }

    #review-screen aside.panel {
        display: grid;
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 6px;
    }

    #review-screen aside.panel .metric-line {
        display: grid;
        gap: 2px;
        padding: 6px;
        border: 0;
        border-radius: 8px;
        background: var(--surface-2);
        text-align: center;
    }

    #review-screen aside.panel .metric-line strong {
        font-size: 18px;
    }

    #review-screen aside.panel label,
    #review-screen aside.panel .primary-button {
        grid-column: 1 / -1;
    }

    #review-screen .notes-area {
        min-height: 46px;
        height: 46px;
        resize: none;
    }

    #ref-review-screen .workspace-heading {
        align-items: center;
        flex-direction: row;
        gap: 8px;
    }

    #ref-review-screen .workspace-heading .eyebrow {
        display: none;
    }

    #ref-review-screen .workspace-heading h1 {
        font-size: 22px;
    }

    #ref-review-screen .review-layout {
        height: calc(100% - 54px);
        grid-template-columns: 1fr;
        grid-template-rows: auto minmax(0, 1fr);
        gap: 8px;
        overflow: hidden;
    }

    #ref-review-screen .panel {
        min-height: 0;
        overflow: hidden;
        padding: 10px;
    }

    #ref-review-screen .section-title-row {
        align-items: center;
        flex-direction: row;
        gap: 8px;
        margin-bottom: 8px;
    }

    #ref-review-screen .section-title-row h2 {
        max-width: 230px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        font-size: 16px;
    }

    #ref-review-screen .review-stat-list {
        grid-template-columns: repeat(5, minmax(0, 1fr));
        gap: 5px;
    }

    #ref-review-screen .review-stat-row {
        min-height: 50px;
        grid-template-columns: 1fr;
        gap: 3px;
        padding: 5px;
        border: 0;
        border-radius: 8px;
        background: var(--surface-2);
        text-align: center;
    }

    #ref-review-screen .review-stat-row span {
        font-size: 9px;
        line-height: 1.05;
    }

    #ref-review-screen .review-stat-row strong {
        font-size: 20px;
    }

    #ref-review-screen aside.panel {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 6px;
        align-content: start;
    }

    #ref-review-screen aside.panel label {
        gap: 4px;
        font-size: 12px;
    }

    #ref-review-screen aside.panel label:nth-of-type(3),
    #ref-review-screen aside.panel .primary-button {
        grid-column: 1 / -1;
    }

    #ref-review-screen .field-control,
    #ref-review-screen .notes-area,
    #ref-review-screen .primary-button {
        min-height: 46px;
    }

    #ref-review-screen .primary-button {
        height: 46px;
    }

    #ref-review-screen .notes-area {
        height: 46px;
        padding: 8px;
        resize: none;
    }

    .button-cluster {
        justify-content: stretch;
    }

    .button-cluster > * {
        flex: 1;
    }

    .score-ribbon {
        grid-template-columns: 1fr 1fr;
    }

    .score-ribbon label:first-child {
        grid-column: 1 / -1;
    }

    .stat-button-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .sticky-command-bar {
        bottom: 74px;
        justify-content: stretch;
    }

    .sticky-command-bar > * {
        flex: 1;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }

    #ref-setup-screen .workspace-heading {
        align-items: center;
        flex-direction: row;
        gap: 8px;
    }

    #ref-setup-screen .workspace-heading .eyebrow {
        display: none;
    }

    #ref-setup-screen .workspace-heading h1 {
        font-size: 22px;
    }

    #ref-setup-form.form-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
        align-content: start;
    }

    #ref-setup-form label {
        gap: 4px;
        font-size: 12px;
    }

    #ref-setup-form .field-control {
        min-height: 46px;
        padding: 0 8px;
    }

    #ref-setup-form .form-actions {
        grid-column: 1 / -1;
    }

    #ref-setup-form .primary-button {
        min-height: 48px;
    }

    .settings-row {
        align-items: stretch;
        flex-direction: column;
        padding: 10px;
    }
}

@media (max-width: 520px) {
    body[data-screen="tracker"] .tracker-shell {
        gap: 6px;
    }

    body[data-screen="tracker"] .parent-live-top {
        grid-template-columns: 46px minmax(0, 1fr) 46px;
        gap: 6px;
    }

    body[data-screen="tracker"] .icon-button {
        width: 46px;
        height: 46px;
    }

    body[data-screen="tracker"] .parent-scoreboard {
        grid-template-columns: 1fr 104px 1fr;
        gap: 6px;
    }

    body[data-screen="tracker"] .parent-score-card {
        min-height: 112px;
        padding: 6px;
    }

    body[data-screen="tracker"] .parent-score-card strong,
    body[data-screen="tracker"] .parent-score-card input {
        font-size: 40px;
    }

    body[data-screen="tracker"] .parent-game-fields {
        grid-template-columns: 1fr 1fr 104px;
        gap: 6px;
    }

    body[data-screen="tracker"] .parent-game-fields .field-control,
    body[data-screen="tracker"] .parent-game-fields input {
        min-height: 46px;
        padding: 0 7px;
        font-size: 13px;
    }

    body[data-screen="tracker"] .parent-game-fields span {
        font-size: 11px;
    }

    body[data-screen="tracker"] .parent-timer-panel {
        padding: 4px;
        gap: 2px;
    }

    body[data-screen="tracker"] .parent-timer-panel strong {
        font-size: 18px;
    }

    body[data-screen="tracker"] .parent-timer-panel .mini-button {
        min-height: 46px;
        font-size: 11px;
    }

    body[data-screen="tracker"] .stat-button-grid {
        gap: 5px;
    }

    body[data-screen="tracker"] .stat-button {
        min-height: 48px;
        padding: 4px;
    }

    body[data-screen="tracker"] .stat-button span {
        font-size: 11px;
    }

    body[data-screen="tracker"] .stat-button strong {
        font-size: 24px;
    }

    body[data-screen="tracker"] .sticky-command-bar {
        gap: 6px;
    }

    body[data-screen="tracker"] .primary-button,
    body[data-screen="tracker"] .icon-command {
        min-height: 46px;
        padding: 0 8px;
        font-size: 13px;
    }

    body[data-screen="ref-live"] .ref-live-shell {
        gap: 6px;
    }

    body[data-screen="ref-live"] .ref-live-top {
        grid-template-columns: 46px minmax(0, 1fr) 46px;
        gap: 6px;
    }

    body[data-screen="ref-live"] .icon-button {
        width: 46px;
        height: 46px;
    }

    body[data-screen="ref-live"] .ref-scoreboard {
        grid-template-columns: 1fr 104px 1fr;
        gap: 6px;
    }

    body[data-screen="ref-live"] .ref-team-score,
    body[data-screen="ref-live"] .ref-clock-box {
        min-height: 84px;
        padding: 6px;
    }

    body[data-screen="ref-live"] .ref-team-score strong {
        font-size: 48px;
    }

    body[data-screen="ref-live"] .ref-clock-box strong {
        font-size: 30px;
    }

    body[data-screen="ref-live"] .ref-control-grid {
        gap: 6px;
    }

    body[data-screen="ref-live"] .ref-team-column {
        gap: 5px;
        padding: 6px;
    }

    body[data-screen="ref-live"] .ref-team-column button {
        min-height: 48px;
        padding: 2px;
        font-size: 16px;
    }

    body[data-screen="ref-live"] .ref-team-column button:nth-child(n+4) {
        font-size: 11px;
    }

    body[data-screen="ref-live"] .ref-live-bottom {
        gap: 6px;
    }

    body[data-screen="ref-live"] .primary-button,
    body[data-screen="ref-live"] .secondary-button {
        min-height: 46px;
        padding: 0 8px;
        font-size: 13px;
    }
}
