/* Match scorecard (/match/).
   Mobile first, and landscape matters as much as portrait: a phone propped on
   the rail is usually turned sideways. The stage fills the screen below the nav
   and is the only thing a player touches during a frame. Timing and frame
   history sit below it; settings are in a panel from the nav bar. */

.match-page { width: 100%; }

/* ── The stage ───────────────────────────────────────────────────── */
/* body already carries padding-top: 60px for the fixed nav (nav.css), so the
   stage takes exactly what is left of the viewport. dvh keeps it right while
   mobile browser chrome slides in and out. */
.stage {
	display: grid;
	grid-template-rows: 1fr auto 1fr;
	height: calc(100dvh - 60px);
	position: relative;
	overflow: hidden;
}
/* No min-height: the stage is exactly one screen, never more. On a very short
   viewport a half scrolls inside itself rather than pushing the stage past the
   fold, so the halves always stay side by side (or stacked) as designed. */

@media (orientation: landscape) {
	.stage {
		grid-template-rows: none;
		grid-template-columns: 1fr auto 1fr;
	}
}

/* ── A side's half: header, score, buttons ───────────────────────── */
.half {
	display: grid;
	grid-template-rows: auto 1fr auto;
	gap: 0.4rem;
	padding: 0.6rem 0.75rem;
	min-height: 0;
	min-width: 0;
	overflow-y: auto;
	-webkit-overflow-scrolling: touch;
	text-align: center;
}
.half.breaking {
	background: color-mix(in srgb, var(--color-primary) 7%, transparent);
}

/* Band 1: who is at the table. */
.half-head {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 0.6rem;
	text-align: left;
	min-width: 0;
}
.avatar {
	flex: 0 0 auto;
	width: 2.5rem;
	height: 2.5rem;
	border-radius: 50%;
	object-fit: cover;
	border: 1px solid var(--border-color);
}
.avatar.placeholder {
	display: flex;
	align-items: center;
	justify-content: center;
	background: var(--bg-surface);
	color: var(--text-muted);
	font-size: 0.85rem;
	font-weight: 600;
	letter-spacing: 0.03em;
}
.half.breaking .avatar { border-color: var(--color-primary); }

.half-head-text { min-width: 0; }
.half-title-row {
	display: flex;
	align-items: baseline;
	gap: 0.45rem;
	flex-wrap: wrap;
}
.half-name {
	font-size: 1.15rem;
	margin: 0;
	overflow-wrap: anywhere;
}
.half-sub {
	display: block;
	font-size: 0.78rem;
	color: var(--text-muted);
	overflow-wrap: anywhere;
	margin-top: 0.1rem;
}
/* In a team match the lineup is a button: tap it to change who is at the table. */
button.half-sub {
	background: none;
	border: none;
	padding: 0;
	cursor: pointer;
	font: inherit;
	color: var(--text-muted);
	text-align: left;
	text-decoration: underline dotted;
	text-underline-offset: 3px;
}
.break-flag {
	font-size: 0.6rem;
	text-transform: uppercase;
	letter-spacing: 0.08em;
	color: var(--color-primary);
	border: 1px solid var(--color-primary);
	border-radius: 999px;
	padding: 0.1rem 0.4rem;
	white-space: nowrap;
}

/* Band 2: the score, which is what you read from across the table. */
.half-mid {
	display: flex;
	align-items: center;
	justify-content: center;
	min-height: 0;
}
.half-score {
	font-size: clamp(2.5rem, 12vmin, 5rem);
	font-weight: 700;
	line-height: 0.95;
	font-variant-numeric: tabular-nums;
}
.half.leading .half-score { color: var(--color-primary); }

/* Band 3: the buttons. */
.half-foot {
	display: flex;
	flex-direction: column;
	gap: 0.5rem;
	align-items: center;
}

/* ── Buttons inside a half ───────────────────────────────────────── */
.half-group {
	width: 100%;
	max-width: 22rem;
}
.half-group-label {
	font-size: 0.65rem;
	text-transform: uppercase;
	letter-spacing: 0.08em;
	color: var(--text-muted);
	margin-bottom: 0.3rem;
}
.half-row {
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	gap: 0.35rem;
}

.mbtn {
	flex: 1 1 auto;
	min-width: 4.2rem;
	min-height: 2.75rem;
	padding: 0.45rem 0.6rem;
	border-radius: 8px;
	border: 1px solid var(--border-color);
	background: var(--bg-surface);
	color: var(--text-primary);
	font-family: inherit;
	font-size: 0.85rem;
	font-weight: 600;
	cursor: pointer;
	line-height: 1.15;
}
.mbtn:disabled {
	opacity: 0.35;
	cursor: default;
}
.mbtn.on {
	border-color: var(--color-primary);
	background: color-mix(in srgb, var(--color-primary) 28%, transparent);
}
/* Result buttons end the frame, so they read as the committing action. */
.mbtn.result {
	border-color: color-mix(in srgb, var(--color-primary) 45%, var(--border-color));
}
.mbtn.more {
	flex: 0 0 auto;
	min-width: 2.75rem;
	font-size: 1rem;
	font-weight: 400;
	color: var(--text-muted);
}

/* ── Divider between the halves ──────────────────────────────────── */
.stage-mid {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 0.75rem;
	padding: 0.3rem 0.75rem;
	border-top: 1px solid var(--border-color);
	border-bottom: 1px solid var(--border-color);
	background: var(--bg-surface);
	font-size: 0.7rem;
	text-transform: uppercase;
	letter-spacing: 0.08em;
	color: var(--text-muted);
	white-space: nowrap;
}
@media (orientation: landscape) {
	.stage-mid {
		flex-direction: column;
		border-top: none;
		border-bottom: none;
		border-left: 1px solid var(--border-color);
		border-right: 1px solid var(--border-color);
		padding: 0.75rem 0.3rem;
		writing-mode: vertical-rl;
	}
}
.mid-frame { font-weight: 700; color: var(--text-primary); }

/* ── Overlay: asked before the halves mean anything ──────────────── */
.stage-overlay {
	position: absolute;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 1rem;
	background: color-mix(in srgb, var(--bg-base) 96%, transparent);
	z-index: 5;
}
.overlay-card {
	width: 100%;
	max-width: 22rem;
	text-align: center;
}
.overlay-q {
	font-size: 1.05rem;
	font-weight: 600;
	margin: 0 0 0.75rem;
	font-family: var(--font-display);
}
.overlay-row {
	display: flex;
	gap: 0.5rem;
	justify-content: center;
	flex-wrap: wrap;
}
.overlay-row .mbtn { flex: 1 1 8rem; }
.overlay-hint {
	font-size: 0.78rem;
	color: var(--text-muted);
	margin: 0.75rem 0 0;
}

.stage-status {
	position: absolute;
	left: 0;
	right: 0;
	bottom: 0;
	text-align: center;
	font-size: 0.78rem;
	padding: 0.2rem 0.75rem;
	pointer-events: none;
	min-height: 1.2em;
}
.stage-status.error   { color: var(--color-error); }
.stage-status.success { color: var(--color-success); }

/* ── Panels below the stage ──────────────────────────────────────── */
.below {
	width: 100%;
	max-width: 640px;
	margin: 0 auto;
	padding: 1.25rem 1rem 3rem;
}
/* Where the data came from, and what the page can't do with it yet. */
.match-notice {
	border: 1px solid var(--border-color);
	border-left-width: 3px;
	border-radius: 6px;
	padding: 0.7rem 0.85rem;
	margin-bottom: 2rem;
	font-size: 0.85rem;
	line-height: 1.45;
	color: var(--text-muted);
	background: var(--bg-surface);
}
.match-notice strong { color: var(--text-color); font-weight: 600; }
.match-notice.warn { border-left-color: var(--warning-color, #d8a23a); }
.match-notice.error { border-left-color: var(--error-color, #d86a6a); }

.panel-block { margin-bottom: 2.25rem; }
.panel-block h2 {
	font-size: 1.05rem;
	text-transform: uppercase;
	letter-spacing: 0.06em;
	color: var(--text-muted);
	margin: 0 0 0.75rem;
	display: flex;
	align-items: baseline;
	justify-content: space-between;
	gap: 0.75rem;
}
.panel-block h3 {
	font-size: 0.9rem;
	text-transform: uppercase;
	letter-spacing: 0.06em;
	color: var(--text-muted);
	margin: 1.5rem 0 0.5rem;
}
.link-toggle {
	background: none;
	border: none;
	padding: 0;
	color: var(--color-primary);
	font-family: var(--font-body);
	font-size: 0.8rem;
	text-transform: none;
	letter-spacing: 0;
	cursor: pointer;
}

/* ── Timing readouts ─────────────────────────────────────────────── */
.time-readout {
	display: flex;
	align-items: baseline;
	justify-content: space-between;
	gap: 1rem;
	padding: 0.3rem 0;
	font-size: 0.85rem;
}
.time-key { color: var(--text-muted); }
.time-val {
	font-variant-numeric: tabular-nums;
	font-weight: 600;
}
.time-readout.live .time-val    { color: var(--color-primary); }
.time-readout.warn .time-val    { color: var(--color-owner); }
.time-readout.expired .time-val { color: var(--color-error); }

.time-actions {
	display: flex;
	gap: 0.5rem;
	margin: 0.6rem 0 0.2rem;
}
.time-actions .mbtn { flex: 1 1 0; }

.time-note {
	font-size: 0.75rem;
	color: var(--text-muted);
	margin-top: 0.5rem;
}

.ext-line {
	display: flex;
	align-items: center;
	gap: 0.75rem;
	padding: 0.35rem 0;
	font-size: 0.85rem;
}
.ext-line .time-key { flex: 1 1 auto; }
.ext-pips { display: flex; gap: 0.25rem; }
.pip {
	width: 0.55rem;
	height: 0.55rem;
	border-radius: 50%;
	border: 1px solid var(--border-color);
}
.pip.on { background: var(--color-primary); border-color: var(--color-primary); }
.mbtn.ext {
	flex: 0 0 auto;
	min-width: 0;
	min-height: 2.1rem;
	padding: 0.3rem 0.65rem;
	font-size: 0.8rem;
}

/* ── Frame history ───────────────────────────────────────────────── */
.viz-placeholder {
	display: flex;
	align-items: center;
	justify-content: center;
	height: 7rem;
	margin-bottom: 1rem;
	border: 1px dashed var(--border-color);
	border-radius: 6px;
	color: var(--text-muted);
	font-size: 0.8rem;
}

/* Portrait gets the tall table, landscape the wide one. Both are rendered from
   the same frames; only one is shown. */
.history-tall { display: table; width: 100%; }
.history-scroll { display: none; }
@media (orientation: landscape) {
	.history-tall { display: none; }
	.history-scroll {
		display: block;
		overflow-x: auto;
		-webkit-overflow-scrolling: touch;
	}
}

.history-tall,
.history-wide {
	border-collapse: collapse;
	font-size: 0.8rem;
}
.history-tall th, .history-tall td,
.history-wide th, .history-wide td {
	border: 1px solid var(--border-color);
	padding: 0.4rem 0.5rem;
	text-align: center;
	font-weight: normal;
}
.history-tall th, .history-wide th { color: var(--text-muted); }

/* Tall: a row per frame, the frame number down the middle. */
.history-tall th { overflow-wrap: anywhere; }
.history-tall .col-mid { width: 38%; }
.history-tall .side-val {
	font-size: 1.1rem;
	font-variant-numeric: tabular-nums;
}
.history-tall td.won .side-val { color: var(--color-primary); font-weight: 700; }
.history-tall .side-sub,
.history-tall .frame-break {
	font-size: 0.68rem;
	color: var(--text-muted);
	margin-top: 0.1rem;
}
.history-tall .frame-no {
	font-weight: 600;
	font-variant-numeric: tabular-nums;
}

/* Wide: frames across, what was recorded down. */
.history-wide { white-space: nowrap; }
.history-wide .row-head {
	text-align: left;
	position: sticky;
	left: 0;
	background: var(--bg-base);
	z-index: 1;
}
.history-wide td.won-home { color: var(--color-primary); font-weight: 600; }
.history-wide td.won-away { color: var(--color-owner);   font-weight: 600; }
/* A breaker set by hand, which the break rule no longer touches. */
.history-wide td.manual { text-decoration: underline dotted; }

.col-total {
	color: var(--text-primary);
	background: var(--bg-surface);
	font-weight: 600;
}

/* Every cell is a correction waiting to happen. */
td.edit { cursor: pointer; }
td.edit:hover { background: color-mix(in srgb, var(--color-primary) 15%, transparent); }

/* ── Settings panel ──────────────────────────────────────────────── */
/* Starts below the fixed nav, so the nav stays reachable with the panel open. */
.panel-scrim {
	position: fixed;
	inset: 60px 0 0 0;
	background: rgba(0, 0, 0, 0.5);
	z-index: 150;
}
.settings-panel {
	position: fixed;
	top: 60px;
	right: 0;
	bottom: 0;
	width: min(22rem, 100vw);
	z-index: 160;
	background: var(--bg-base);
	border-left: 1px solid var(--border-color);
	display: flex;
	flex-direction: column;
	overflow: hidden;
}
.panel-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 0 1rem;
	height: 48px;
	border-bottom: 1px solid var(--border-color);
	flex: 0 0 auto;
}
.panel-head h2 { font-size: 1.05rem; margin: 0; }
.panel-close {
	background: none;
	border: none;
	color: var(--text-primary);
	font-size: 1.75rem;
	line-height: 1;
	cursor: pointer;
	padding: 0 0.25rem;
}
.panel-body {
	padding: 1rem;
	overflow-y: auto;
	-webkit-overflow-scrolling: touch;
}

.context-line { margin: 0 0 0.6rem; font-size: 0.9rem; color: var(--text-muted); }
.badge-row { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-bottom: 1rem; }

/* Says what a settings change did to frames already played. */
.panel-note {
	margin: 0 0 1rem;
	padding: 0.6rem 0.75rem;
	border: 1px solid var(--color-owner);
	border-radius: 6px;
	background: color-mix(in srgb, var(--color-owner) 12%, transparent);
	font-size: 0.8rem;
}
.panel-note .note-line {
	margin-top: 0.3rem;
	color: var(--text-muted);
}

/* ── Settings cards ──────────────────────────────────────────────── */
.set-card {
	padding: 0.9rem 0.85rem 1rem;
	margin-bottom: 1rem;
	border: 1px solid var(--border-color);
	border-radius: 8px;
	background: var(--bg-surface);
	display: grid;
	gap: 0.9rem;
}
.set-card h3 {
	margin: 0;
	font-size: 0.8rem;
	font-weight: 700;
	letter-spacing: 0.1em;
	text-transform: uppercase;
	color: var(--text-muted);
}

.set-row {
	display: grid;
	grid-template-columns: 1fr auto;
	align-items: center;
	gap: 0.5rem 0.75rem;
}
/* Same small capitals in the brand colour as the account pages, so the
   settings panel reads as part of the same site. */
.set-label {
	font-size: 0.7rem;
	font-weight: 600;
	letter-spacing: 0.1em;
	text-transform: uppercase;
	color: var(--color-primary);
}
.set-hint {
	grid-column: 1 / -1;
	font-size: 0.75rem;
	color: var(--text-muted);
	margin-top: -0.2rem;
}
/* A line rather than a box, matching the account pages. */
.set-row select,
.set-row input[type="text"],
.set-row input[type="number"] {
	justify-self: end;
	width: 10rem;
	max-width: 50vw;
	padding: 0.35rem 0;
	border: none;
	border-bottom: 1px solid var(--border-color);
	border-radius: 0;
	background: transparent;
	color: var(--text-primary);
	font-family: inherit;
	font-size: 1rem; /* 16px stops iPhone zooming in on focus */
	text-align: right;
	transition: border-color 0.15s ease;
}
.set-row select:focus,
.set-row input[type="text"]:focus,
.set-row input[type="number"]:focus {
	outline: none;
	border-bottom-color: var(--color-primary);
}
.set-row select {
	appearance: none;
	-webkit-appearance: none;
	padding-right: 1.1rem;
	background-image:
		linear-gradient(45deg, transparent 50%, currentColor 50%),
		linear-gradient(135deg, currentColor 50%, transparent 50%);
	background-position: right 0.45rem center, right 0.15rem center;
	background-size: 0.3rem 0.3rem, 0.3rem 0.3rem;
	background-repeat: no-repeat;
	direction: rtl;          /* right-aligns the chosen option text */
}
.set-row select option { direction: ltr; }
.set-row input[type="number"] { width: 5.5rem; }

/* Stacked rows put the control on its own line, full width. */
.set-row.stack { grid-template-columns: 1fr; }
.set-row.stack select {
	justify-self: stretch;
	width: 100%;
	max-width: none;
}
.set-check {
	justify-self: end;
	width: 1.4rem;
	height: 1.4rem;
	accent-color: var(--color-primary);
}

/* ── The nav bar button this page injects ────────────────────────── */
.nav-match-btn {
	background: none;
	border: 1px solid var(--border-color);
	border-radius: 6px;
	color: var(--text-primary);
	font-family: inherit;
	font-size: 0.8rem;
	padding: 0.35rem 0.6rem;
	cursor: pointer;
	white-space: nowrap;
	margin-left: auto;
	margin-right: 0.6rem;
}

/* ── Short landscape (phone on its side): tighten everything ─────── */
@media (orientation: landscape) and (max-height: 460px) {
	.half { gap: 0.25rem; padding: 0.4rem 0.5rem; }
	.half-score { font-size: clamp(2rem, 18vh, 3.25rem); }
	.half-sub { display: none; }
	.avatar { width: 2rem; height: 2rem; }
	.half-name { font-size: 1rem; }
	.half-group-label { margin-bottom: 0.2rem; }
	.mbtn { min-height: 2.4rem; font-size: 0.78rem; min-width: 3.6rem; }
}

/* Read-only: a watcher sees the match but cannot change it. Dimmed rather
   than hidden — knowing it is a race to 5 is the point. */
.set-row input:disabled,
.set-row select:disabled {
	opacity: 0.5;
	cursor: not-allowed;
}

/* ── Scorecard panel ─────────────────────────────────────────────── */
.card-line { margin-bottom: 0.6rem; line-height: 1.45; }
.card-note {
	font-size: 0.82rem;
	color: var(--text-muted);
	line-height: 1.45;
	margin-bottom: 0.6rem;
}
.card-row { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0.75rem 0; }
.card-row .mbtn { flex: 1 1 auto; }
#card-body textarea {
	width: 100%;
	padding: 0.5rem 0;
	border: none;
	border-bottom: 1px solid var(--border-color);
	background: transparent;
	color: var(--text-primary);
	font-family: inherit;
	font-size: 1rem;
	resize: vertical;
}
#card-body textarea:focus { outline: none; border-bottom-color: var(--color-primary); }

/* Same as the account pages: the open dropdown list needs its own colours. */
.set-row select option {
	background: var(--bg-base);
	color: var(--text-primary);
	direction: ltr;
}

/* ── The result, once both players have agreed ───────────────────── */
.result-view {
	width: 100%;
	max-width: 640px;
	margin: 0 auto;
	padding: 2rem 1rem 3rem;
}
.result-view[hidden] { display: none; }
.result-head { text-align: center; margin-bottom: 2.5rem; }
.result-label {
	font-size: 0.7rem;
	font-weight: 600;
	letter-spacing: 0.14em;
	text-transform: uppercase;
	color: var(--color-primary);
	margin: 0 0 0.75rem;
}
.score-pair { display: flex; align-items: center; justify-content: center; gap: 0.75rem; }
.score-big {
	font-family: var(--font-display);
	font-size: 4rem;
	line-height: 1;
}
.score-dash { font-size: 2rem; color: var(--text-muted); }
.result-line { margin: 0.75rem 0 0; font-size: 1.05rem; }

.result-frames { list-style: none; margin: 0; padding: 0; }
.result-frame {
	display: grid;
	grid-template-columns: 2rem 1fr;
	gap: 0.15rem 0.75rem;
	padding: 0.55rem 0;
	border-bottom: 1px solid var(--border-color);
}
.rf-no { color: var(--text-muted); font-variant-numeric: tabular-nums; }
.rf-who { font-weight: 600; }
.rf-extra { grid-column: 2; font-size: 0.8rem; color: var(--text-muted); }

.result-facts { display: grid; gap: 0.1rem; }
.fact {
	display: flex;
	justify-content: space-between;
	gap: 1rem;
	padding: 0.45rem 0;
	border-bottom: 1px solid var(--border-color);
}
.fact-k { color: var(--text-muted); font-size: 0.9rem; }
.fact-v { font-weight: 600; }

/* Opened from the frame history, the overlay floats over the whole viewport
   rather than over a stage that has been scrolled past. */
.stage-overlay.floating {
	position: fixed;
	inset: 60px 0 0 0;   /* clears the nav */
	z-index: 40;
}

/* ── The menu that drops out of a history cell ───────────────────── */
.below { position: relative; }      /* the menu is placed against this */
.cell-menu {
	position: absolute;
	z-index: 40;
	width: max-content;
	max-width: min(20rem, calc(100vw - 2rem));
	padding: 0.75rem;
	border: 1px solid var(--border-color);
	border-radius: 10px;
	background: var(--bg-base);
	box-shadow: 0 10px 30px rgba(0, 0, 0, 0.55);
}
.cell-menu[hidden] { display: none; }
.cell-menu-q {
	margin: 0 0 0.6rem;
	font-size: 0.8rem;
	font-weight: 600;
	letter-spacing: 0.06em;
	text-transform: uppercase;
	color: var(--color-primary);
}
.cell-menu-row { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.cell-menu-row .mbtn { flex: 1 1 auto; white-space: nowrap; }
.cell-menu-hint {
	margin: 0.6rem 0 0;
	font-size: 0.78rem;
	line-height: 1.4;
	color: var(--text-muted);
}
.cell-menu-hint[hidden] { display: none; }

/* A cell you can change should look like one. */
.history-tall .edit, .history-wide .edit { cursor: pointer; }
