/* One web workspace: shared Score-led hierarchy for admin and scorer screens. */
:root {
    --workspace-bg: #020817;
    --workspace-surface: #071426;
    --workspace-raised: #091a33;
    --workspace-line: #19375f;
    --workspace-text: #f7f9ff;
    --workspace-muted: #8fa1bc;
    --workspace-selected: #153e75;
    --workspace-gutter: clamp(1rem, 2.5vw, 1.5rem);
    --workspace-title: clamp(1.6rem, 4vw, 2rem);
    --workspace-nav-height: 4.6rem;
    --workspace-header-height: calc(4rem + env(safe-area-inset-top));
}

/* Keep the compact app bar in flow; reserve its space for focused/anchored content. */
html:has(body.is-app-workspace > .workspace-header), html:has(.workspace-header:not(.workspace-header--root)) { scroll-padding-top: calc(var(--workspace-header-height) + 1rem); }
.workspace-header { position: sticky; top: 0; z-index: var(--z-navigation, 200); flex: 0 0 auto; height: var(--workspace-header-height); padding-top: env(safe-area-inset-top); border-bottom: 1px solid var(--workspace-line); background: var(--workspace-bg); box-sizing: border-box; }
.workspace-header--root { display: none; }
body.is-app-workspace > .workspace-header--root { display: block; }
body.is-app-workspace #app-header { display: none; }
.workspace-header-inner { width: min(72rem, 100%); height: 100%; margin-inline: auto; display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding-inline: max(var(--workspace-gutter), env(safe-area-inset-left)) max(var(--workspace-gutter), env(safe-area-inset-right)); box-sizing: border-box; }
.workspace-logo { display: block; width: 11rem; max-width: 58vw; height: 2.75rem; object-fit: contain; object-position: left center; }
.workspace-account { position: relative; flex: 0 0 auto; font-family: Aeonik, Arial, sans-serif; }
.workspace-account > summary { min-height: 2.75rem; display: flex; align-items: center; gap: .5rem; padding: .5rem .75rem; list-style: none; border: 1px solid var(--workspace-line); border-radius: .8rem; background: var(--workspace-surface); color: var(--workspace-text); font: 700 .75rem/1 Aeonik, Arial, sans-serif; cursor: pointer; touch-action: manipulation; transition: background-color .15s ease; box-sizing: border-box; }
.workspace-account > summary::-webkit-details-marker { display: none; }
.workspace-account > summary svg { width: 1.25rem; height: 1.25rem; fill: currentColor; stroke: currentColor; }
.workspace-account > summary:is(:hover, :active), .workspace-account[open] > summary { background: var(--workspace-selected); }
.workspace-account :is(summary, button, a):focus-visible { outline: 2px solid #65dcff; outline-offset: 2px; }
.workspace-menu { position: absolute; top: calc(100% + .6rem); right: 0; width: min(17rem, calc(100vw - 2 * var(--workspace-gutter))); max-height: calc(100dvh - var(--workspace-header-height) - 1rem); overflow: auto; padding: .45rem; border: 1px solid #264970; border-radius: 1rem; background: #071426; box-shadow: 0 .75rem 2rem #01071599; }
.workspace-identity { padding: .6rem .65rem .8rem; margin-bottom: .25rem; border-bottom: 1px solid var(--workspace-line); }
.workspace-identity strong { display: block; color: var(--workspace-text); font-size: .9rem; overflow-wrap: anywhere; }
.workspace-identity span { display: block; margin-top: .25rem; color: var(--workspace-muted); font-size: .7rem; }
.workspace-menu :is(button, a) { display: flex; align-items: center; width: 100%; min-height: 2.75rem; padding: .65rem; border: 0; border-radius: .6rem; background: transparent; color: #e6effb; text-align: left; text-decoration: none; font: 700 .8rem/1.3 Aeonik, Arial, sans-serif; touch-action: manipulation; cursor: pointer; box-sizing: border-box; }
.workspace-menu [hidden] { display: none; }
.workspace-menu :is(button, a):hover { background: var(--workspace-raised); }
.workspace-menu .workspace-signout { color: #ffa6b4; }
.workspace-menu .workspace-server { border-top: 1px solid var(--workspace-line); margin-top: .25rem; border-radius: 0; color: var(--workspace-muted); }
.workspace-menu-error { color: #ffa6b4; padding-inline: .65rem; font: 400 .8rem/1.4 Aeonik, Arial, sans-serif; }
body[data-app-screen="score"] .sign-out { display: none; }
body[data-app-screen="match"] .scorer-page:has(.workspace-header) { grid-template-rows: var(--workspace-header-height) auto minmax(0, 1fr); }
body[data-app-screen="match"] .mini-topbar { grid-template-columns: auto minmax(0, 1fr) auto; grid-template-areas: "back info live"; min-height: 3.5rem; background: var(--workspace-surface); padding: .4rem var(--workspace-gutter); }
body[data-app-screen="match"] .mini-info { position: static; grid-area: info; order: initial; max-width: none; align-self: center; }
body[data-app-screen="match"] .mini-info .mini-title { font-size: .85rem; }
body[data-app-screen="match"] .mini-info .mini-subtitle { font-size: .7rem; }
body[data-app-screen="match"] .mini-topbar .icon-btn { grid-area: back; }
body[data-app-screen="match"] .live-badge { grid-area: live; }

:is(body.is-app-workspace, body[data-app-screen]) {
    font-family: Aeonik, Arial, sans-serif;
    color: var(--workspace-text);
    background: radial-gradient(circle at 78% -8%, rgba(20,111,224,.12), transparent 30%), var(--workspace-bg);
    -webkit-tap-highlight-color: transparent;
}
:is(body.is-app-workspace, body[data-app-screen]) :is(button, input, select, textarea) { font-family: inherit; }
:is(body.is-app-workspace, body[data-app-screen]) :is(button, a, input, select):focus-visible { outline: 2px solid #65dcff; outline-offset: 2px; }
:is(body.is-app-workspace, body[data-app-screen]) :is(button, a) { touch-action: manipulation; }

body.is-app-workspace #app-content,
body[data-app-screen="score"] .shell,
body[data-app-screen="slides"] .slide-control-page {
    width: min(72rem, 100%);
    max-width: 72rem;
    margin-inline: auto;
    padding: max(1rem, env(safe-area-inset-top)) max(var(--workspace-gutter), env(safe-area-inset-right)) 1.5rem max(var(--workspace-gutter), env(safe-area-inset-left));
}
/* The bottom tab bar is fixed at every width, so pages and their action bars stay clear of it.
   app.js measures the space the bar covers into --app-bottom-bar. */
body.is-app-workspace:not(:has(.app-tabs)):not(:has(.app-score-view.active)) #app-content { padding-bottom: calc(var(--app-bottom-bar, calc(var(--workspace-nav-height) + env(safe-area-inset-bottom))) + 1.5rem); }
body.is-app-workspace .manual-builder-actions { bottom: calc(var(--app-bottom-bar, 0px) + .75rem); }
body.is-app-workspace #t-create-actions.create-action-dock { bottom: calc(var(--app-bottom-bar, 0px) + .65rem); }
/* Pop-up windows open above the tab bar, and confirmations (z 400) above them. */
.modal-overlay { z-index: 300; }
body[data-app-screen="score"] .shell { min-height: 0; }
body[data-app-screen="slides"] .remote { width: 100%; max-width: none; }
body.is-app-workspace :is(.section-header, .settings-hero),
body[data-app-screen] :is(.panel-heading, .remote-heading) {
    margin: 0 0 1rem;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
}
body.is-app-workspace :is(.section-header, .settings-hero) h1,
body.is-app-workspace #view-admin-tournaments > .section-header h1,
body[data-app-screen] :is(.panel-heading, .remote-heading) h1 {
    max-width: 100%;
    margin: 0;
    font-family: Aeonik, Arial, sans-serif;
    font-size: var(--workspace-title);
    font-weight: 800;
    line-height: 1.15;
    letter-spacing: -.035em;
    text-wrap: balance;
}
body.is-app-workspace :is(.section-header, .settings-hero) p,
body[data-app-screen] :is(.panel-heading p, .remote-heading .help) {
    max-width: 42rem;
    margin: .4rem 0 0;
    color: var(--workspace-muted);
    font-size: .875rem;
    line-height: 1.45;
    text-wrap: pretty;
}
body.is-app-workspace :is(.section-header .subtitle, .settings-hero .subtitle),
body[data-app-screen="slides"] .remote-kicker { display: none; }

/* Settings uses the same open heading as the other screens, not a hero card. */
body.is-app-workspace .settings-hero { grid-template-columns: minmax(0, 1fr); align-items: start; gap: .5rem; }
body.is-app-workspace .settings-hero-stat { display: flex; align-items: baseline; gap: .4rem; padding: 0; border: 0; background: transparent; }
body.is-app-workspace .settings-hero-stat strong { order: -1; font: 800 .875rem/1.15 Aeonik, Arial, sans-serif; font-variant-numeric: tabular-nums; }
body.is-app-workspace .settings-hero-stat span { font-size: .75rem; letter-spacing: 0; text-transform: none; }
body.is-app-workspace .settings-hero-stat small { display: none; }
body.is-app-workspace :is(.settings-panel, .glass-card, .admin-toolbar),
body[data-app-screen="slides"] :is(.remote-panel, .control-card) {
    border: 1px solid var(--workspace-line);
    border-radius: 1.15rem;
    background: var(--workspace-surface);
    box-shadow: none;
}
body.is-app-workspace .admin-toolbar { padding: .85rem; gap: .75rem; }
.tournament-list-card { display: block; width: 100%; padding: 1.2rem; margin-bottom: .875rem; text-align: left; color: var(--foreground); font-family: var(--font-sans); cursor: pointer; }
body.is-app-workspace .tournament-list-card { margin: 0; padding: 1.15rem; border-radius: 1.25rem; background: linear-gradient(145deg, #081b36, #051123); }
body.is-app-workspace :is(.settings-panel, .ui-surface-pad) { padding: 1rem; }
body.is-app-workspace :is(.settings-panel h2, .ui-section-heading h3),
body[data-app-screen="slides"] .settings-toolbar h2 { font: 800 1.15rem/1.25 Aeonik, Arial, sans-serif; letter-spacing: -.02em; }
body.is-app-workspace :is(.player-input, .btn),
body[data-app-screen="slides"] :is(.remote-panel select, .display-settings-shell input, .display-settings-shell select) { min-height: 3rem; border-radius: .85rem; }
/* Override legacy global primary-button colors without changing public pages. */
body.is-app-workspace .btn-primary { border: 1px solid #24558d !important; background: var(--workspace-selected) !important; color: #fff !important; box-shadow: none; }
body.is-app-workspace .btn-primary:hover { background: #1c4d89 !important; }
body[data-app-screen="score"]:has(.app-tabs) .quick-action-dock { bottom: calc(var(--workspace-nav-height) + env(safe-area-inset-bottom) + .5rem + var(--keyboard-inset)); }
body.is-app-workspace .settings-panel header > div > span { color: var(--workspace-muted); font-size: .7rem; letter-spacing: .03em; text-transform: none; }

/* Frames share the parent gutters instead of introducing another inset. */
body.is-app-workspace :is(#view-score, #view-slides) { margin: -1rem calc(-1 * var(--workspace-gutter)) -1.5rem; }
body.is-app-workspace :is(#view-score, #view-slides) .embedded-screen-shell {
    height: calc(100dvh - var(--app-top-bar, var(--workspace-header-height)) - var(--app-bottom-bar, calc(var(--workspace-nav-height) + env(safe-area-inset-bottom))));
    min-height: 0;
    margin: 0;
    border: 0;
    border-radius: 0;
}
body.is-app-workspace :is(#view-score, #view-slides) .embedded-screen-frame { height: 100%; min-height: 0; }
/* The page around an open frame is exactly one screen tall: nothing to scroll but the frame itself. */
body.is-app-workspace:has(.app-score-view.active) #app-content { min-height: 0; padding-bottom: 0; }
body.is-app-workspace :is(#view-score, #view-slides).active { min-height: 0; margin-bottom: 0; }
body[data-app-screen].is-embedded { min-height: 100dvh; }
body[data-app-screen].is-embedded .shell { min-height: 0; }

body[data-app-screen="score"] .scorer-app-screen { width: min(72rem,100%); min-height: 0; margin: 0 auto; background: transparent; }
body[data-app-screen="score"] .scorer-app-frame { height: calc(100dvh - var(--app-top-bar, var(--workspace-header-height)) - var(--app-bottom-bar, calc(var(--workspace-nav-height) + env(safe-area-inset-bottom)))); min-height: 0; background: var(--workspace-bg); }

body[data-app-screen="slides"] .remote-heading { margin-top: 0; }
body[data-app-screen="slides"] .remote-admin-header { min-height: 2.9rem; margin-bottom: .75rem; }
body[data-app-screen="slides"] .remote-admin-header div > span { display: none; }
body[data-app-screen="slides"] .remote-panel { padding: 1rem; }
body[data-app-screen="slides"] .remote-buttons { gap: .6rem; margin: .85rem 0; }
body[data-app-screen="slides"] .remote-buttons button,
body[data-app-screen="slides"] .remote-buttons button:last-child {
    min-height: 5.5rem;
    padding: .7rem .25rem;
    border: 1px solid #24558d;
    border-radius: .85rem;
    background: var(--workspace-selected);
    color: #fff;
    font-size: .8rem;
}
body[data-app-screen="slides"] .remote-buttons button:hover:not(:disabled) { background: #1c4d89; transform: none; }
body[data-app-screen="slides"] .remote-buttons .refresh-display { background: var(--workspace-raised); }
body[data-app-screen="slides"] .remote-buttons span { height: 1.8rem; font-size: 1.8rem; }
body[data-app-screen="slides"] .remote-buttons svg { width: 1.65rem; height: 1.65rem; }
body[data-app-screen="slides"] #slide-status { min-height: 1.35rem; margin: 0; color: var(--workspace-muted); font-size: .8rem; }
body[data-app-screen="slides"].is-admin .remote { margin-bottom: 1rem; }
body[data-app-screen="slides"] .display-settings-shell { padding-top: 1.25rem; }
body[data-app-screen="slides"] .settings-toolbar { position: static; padding: 0; border: 0; background: transparent; box-shadow: none; backdrop-filter: none; }
body[data-app-screen="slides"] .settings-toolbar > div > span { display: none; }
body[data-app-screen="slides"] .settings-toolbar p { color: var(--workspace-muted); font-size: .8rem; }
body[data-app-screen="slides"] .display-settings-shell .primary { border: 1px solid #24558d; background: var(--workspace-selected); box-shadow: none; }

@media(max-width:767px) {
    body[data-app-screen="slides"] .remote-panel { padding: .75rem; }
    body[data-app-screen="slides"] .remote-buttons { margin: .6rem 0; }
    body[data-app-screen="slides"] .remote-buttons button { padding-block: .5rem; }
    body[data-app-screen="slides"] .display-settings-shell .workspace { gap: .85rem; padding: 1rem 0; }
}
@media(min-width:760px) { :root { --workspace-nav-height: 5rem; } }

/* Native app layer: touch behaviour, press feedback and controls that read as an installed Android app. */
:root { color-scheme: dark; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html:has(body[data-app-screen]), html:has(body.is-app-workspace) { overscroll-behavior: none; background: var(--workspace-bg); }
:is(body.is-app-workspace, body[data-app-screen]) { overscroll-behavior: none; }
:is(body.is-app-workspace, body[data-app-screen]) :is(button, summary, label, nav, img, .btn, .back-link, [role="tab"], .tournament-list-card, .workspace-header) { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
:is(body.is-app-workspace, body[data-app-screen]) :is(input, textarea, select, [contenteditable="true"]) { -webkit-user-select: text; user-select: text; }
:is(body.is-app-workspace, body[data-app-screen]) :is(button, .btn, summary, [role="tab"], .tournament-list-card):not(:disabled) { transition: scale .12s cubic-bezier(.2, 0, 0, 1), background-color .18s ease, border-color .18s ease, color .18s ease; }
:is(body.is-app-workspace, body[data-app-screen]) :is(button, .btn, summary, [role="tab"], .tournament-list-card):not(:disabled):active { scale: .97; }
:is(body.is-app-workspace, body[data-app-screen]) .app-tabs :is(a, button):active { scale: 1; }

/* Sentence-case field labels and a compact app-bar back action instead of tracked uppercase web labels. */
:is(body.is-app-workspace, body[data-app-screen]) .form-label { color: #b8c7dc; font-size: .8125rem; font-weight: 600; letter-spacing: 0; text-transform: none; }
:is(body.is-app-workspace, body[data-app-screen]) .back-link { min-height: 2.75rem; margin-bottom: 1rem; padding: 0 1rem 0 .75rem; border: 0; border-radius: 999px; background: rgba(120, 170, 240, .08); color: #dbe8fa; font-size: .875rem; font-weight: 700; letter-spacing: 0; text-transform: none; }
:is(body.is-app-workspace, body[data-app-screen]) .back-link:active { background: rgba(120, 170, 240, .16); }
:is(body.is-app-workspace, body[data-app-screen]) select:not([multiple]) { appearance: none; -webkit-appearance: none; padding-right: 2.5rem; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2393a6c3' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right .85rem center; background-size: 1.1rem; }

/* Nested form sections read as grouped rows on one surface, not cards inside cards. */
body.is-app-workspace #tournament-create-section .create-section-card { border-color: transparent; background: rgba(120, 170, 240, .045); }
body.is-app-workspace .admin-settings > summary { display: flex; align-items: center; justify-content: space-between; gap: 1rem; min-height: 2.75rem; list-style: none; }
body.is-app-workspace .admin-settings > summary::-webkit-details-marker { display: none; }
body.is-app-workspace .admin-settings > summary::after { content: ""; flex: none; width: .55rem; height: .55rem; margin-right: .35rem; border-right: 2px solid #93a6c3; border-bottom: 2px solid #93a6c3; rotate: 45deg; translate: 0 -.15rem; transition: rotate .2s ease; }
body.is-app-workspace .admin-settings[open] > summary::after { rotate: 225deg; translate: 0 .1rem; }

/* Courts another event holds at the planned time, and players already booked elsewhere. */
body.is-app-workspace .tournament-court-option.is-booked { border-style: dashed; border-color: rgba(224, 113, 43, .45); background: rgba(224, 113, 43, .06); cursor: not-allowed; }
body.is-app-workspace .tournament-court-option.is-booked strong { color: #c5d3e8; }
body.is-app-workspace .tournament-court-option.is-booked span em { display: block; margin-top: .25rem; color: #ffbe96; font-size: .78rem; font-style: normal; font-weight: 700; }
body.is-app-workspace .tournament-court-option.is-booked i { opacity: .35; }
body.is-app-workspace .t-booking-warning { margin: .9rem 0 0; padding: .85rem 1rem; border: 1px solid rgba(224, 113, 43, .4); border-radius: .9rem; background: rgba(224, 113, 43, .1); color: #ffe0cc; font-size: .875rem; line-height: 1.45; }
body.is-app-workspace .t-booking-warning[hidden] { display: none; }
body.is-app-workspace .t-booking-warning ul { margin: .4rem 0; padding-left: 1.1rem; }
body.is-app-workspace .t-booking-warning span { color: #f2c9ad; font-size: .8rem; }

/* Same-origin page changes cross-fade like screen transitions; the app bar and navigation stay put. */
@media (prefers-reduced-motion: no-preference) {
    @view-transition { navigation: auto; }
    .workspace-header { view-transition-name: app-header; }
    ::view-transition-old(root) { animation: 140ms cubic-bezier(.4, 0, 1, 1) both app-screen-out; }
    ::view-transition-new(root) { animation: 220ms cubic-bezier(0, 0, .2, 1) both app-screen-in; }
    @keyframes app-screen-out { to { opacity: 0; } }
    @keyframes app-screen-in { from { opacity: 0; translate: 0 .75rem; } }
}
