/*
 * opentranscription.org web viewer
 *
 * Copyright (C) 2026 opentranscription.org
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published
 * by the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
 *
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */

:root {
	color-scheme: light;
	--background: #ffffff;
	--surface: #f2f2f2;
	--text: #111111;
	--muted: #5c5c5c;
	--border: #cfcfcf;
	--accent: #0b57d0;
	--on-accent: #ffffff;
	--live: #c62828;
	/* One per speaker, told from the page behind them in either theme. */
	--speaker-1: #1a73e8;
	--speaker-2: #c2570a;
	--speaker-3: #188038;
	--speaker-4: #d93025;
	--speaker-5: #9334e6;
	--speaker-6: #0b7c8c;
	--speaker-7: #d01884;
	--speaker-8: #8d6e00;
	--text-size: 1.5rem;
}

/* The device setting applies until the reader picks a theme. */
@media (prefers-color-scheme: dark) {
	:root:not([data-theme="light"]) {
		color-scheme: dark;
		--background: #000000;
		--surface: #1c1c1c;
		--text: #ffffff;
		--muted: #a8a8a8;
		--border: #3d3d3d;
		--accent: #a8c7fa;
		--on-accent: #062e6f;
		--live: #ff5252;
		--speaker-1: #8ab4f8;
		--speaker-2: #fcad70;
		--speaker-3: #81c995;
		--speaker-4: #f28b82;
		--speaker-5: #c58af9;
		--speaker-6: #78d9ec;
		--speaker-7: #ff8bcb;
		--speaker-8: #fdd663;
	}
}

:root[data-theme="dark"] {
	color-scheme: dark;
	--background: #000000;
	--surface: #1c1c1c;
	--text: #ffffff;
	--muted: #a8a8a8;
	--border: #3d3d3d;
	--accent: #a8c7fa;
	--on-accent: #062e6f;
	--live: #ff5252;
	--speaker-1: #8ab4f8;
	--speaker-2: #fcad70;
	--speaker-3: #81c995;
	--speaker-4: #f28b82;
	--speaker-5: #c58af9;
	--speaker-6: #78d9ec;
	--speaker-7: #ff8bcb;
	--speaker-8: #fdd663;
}

* {
	box-sizing: border-box;
}

[hidden] {
	display: none !important;
}

body {
	/* The page fills the screen and never scrolls: only what is under the
	   header does. When the page itself scrolled to each new line, Firefox
	   on Android, its address bar showing, drew the header off screen. */
	display: flex;
	flex-direction: column;
	height: 100vh;
	height: 100dvh;
	overflow: hidden;
	margin: 0;
	background: var(--background);
	color: var(--text);
	font-family: system-ui, sans-serif;
}

/* The way back is at the start, the menu of how the page looks at the end,
   the title between them: it gives way, they do not. */
header {
	position: relative;
	flex: none;
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 0.5rem;
	padding: 0.5rem 1rem;
	padding-top: calc(0.5rem + env(safe-area-inset-top));
	background: var(--background);
	border-bottom: 1px solid var(--border);
}

#logo {
	flex: none;
	max-width: 6rem;
	height: 2rem;
	object-fit: contain;
}

.heading {
	display: flex;
	flex: 1;
	align-items: center;
	gap: 0.5rem;
	min-width: 0;
}

/* A name and its description on a single line, cut off when too long. */
.name-line {
	display: block;
	min-width: 0;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.description {
	margin-inline-start: 0.35em;
	color: var(--muted);
	font-size: 0.8em;
	font-weight: 400;
}

h1 {
	min-width: 0;
	margin: 0;
	font-size: 1rem;
	font-weight: 600;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

/* In the bar, the talk being given has a line of its own under the name of
   the room. */
h1 .description {
	display: block;
	margin-inline-start: 0;
	overflow: hidden;
	text-overflow: ellipsis;
}

.dot {
	flex: none;
	width: 0.6rem;
	height: 0.6rem;
	border-radius: 50%;
	background: var(--muted);
}

.dot[data-status="live"] {
	background: var(--live);
}

.controls {
	display: flex;
	flex: none;
	gap: 0.5rem;
}

button,
.picker {
	min-height: 2.5rem;
	min-width: 2.5rem;
	padding: 0 0.75rem;
	border: 1px solid var(--border);
	border-radius: 0.5rem;
	background: var(--surface);
	color: var(--text);
	font: inherit;
	cursor: pointer;
}

/* The language button: the real list lies invisible over the language code,
   so that a tap opens the device's own picker. */
.picker {
	position: relative;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	font-weight: 600;
	white-space: nowrap;
}

.picker select {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	opacity: 0;
	font: inherit;
	cursor: pointer;
}

.picker:focus-within {
	outline: 2px solid var(--accent);
	outline-offset: 2px;
}

/* On a phone, tighter controls leave more of the line to the title. */
@media (max-width: 30rem) {
	header {
		gap: 0.25rem;
		padding-inline: 0.5rem;
	}

	.heading,
	.controls {
		gap: 0.25rem;
	}

	header button,
	.picker {
		min-width: 2.25rem;
		padding: 0 0.5rem;
	}

	#logo {
		max-width: 4rem;
	}
}

/* How the page looks: the size of the text and the theme. It hangs under
   the button that opens it, over what scrolls. */
#settings {
	position: absolute;
	top: 100%;
	inset-inline-end: 0.5rem;
	z-index: 2;
	width: min(20rem, calc(100vw - 1rem));
	margin-top: 0.4rem;
	padding: 1rem;
	border: 1px solid var(--border);
	border-radius: 0.75rem;
	background: var(--background);
	box-shadow: 0 0.75rem 2rem -0.5rem rgb(0 0 0 / 35%);
}

#settings p {
	margin: 0 0 0.5rem;
	color: var(--muted);
	font-size: 0.9375rem;
}

/* Five sizes, each button showing its own. */
#text-sizes {
	display: grid;
	grid-template-columns: repeat(5, 1fr);
	gap: 0.4rem;
	margin-bottom: 1rem;
}

#text-sizes button {
	min-height: 3rem;
	padding: 0;
	font-weight: 600;
}

#text-sizes button:nth-child(1) {
	font-size: 0.85rem;
}

#text-sizes button:nth-child(2) {
	font-size: 1.05rem;
}

#text-sizes button:nth-child(3) {
	font-size: 1.3rem;
}

#text-sizes button:nth-child(4) {
	font-size: 1.6rem;
}

#text-sizes button:nth-child(5) {
	font-size: 2rem;
}

/* The size in use is framed. */
#text-sizes button[aria-pressed="true"] {
	outline: 3px solid var(--text);
	outline-offset: 2px;
}

#theme {
	width: 100%;
	min-height: 3rem;
	text-align: start;
}

/* A drawn icon, in the colour of the label of its button. */
.icon {
	display: block;
	width: 1.4rem;
	height: 1.4rem;
	margin: 0 auto;
	fill: none;
	stroke: currentColor;
	stroke-width: 1.8;
	stroke-linecap: round;
	stroke-linejoin: round;
}

.icon .days {
	stroke-width: 2.4;
}

button:disabled {
	color: var(--muted);
	cursor: default;
}

/* An event can give clickable items its own two colours: one fills them,
   the other draws their label. Text and backgrounds of the page keep the
   colours of the theme. */
.branded button,
.branded .picker {
	border-color: var(--button);
	background: var(--button);
	color: var(--on-button);
}

.branded button:disabled {
	opacity: 0.5;
}

.branded .session .description,
.branded .session .session-status {
	color: inherit;
	opacity: 0.85;
}

#scroll {
	flex: 1;
	min-height: 0;
	overflow-y: auto;
	/* Earlier lines are added above while the reader scrolls back, and the
	   script keeps the text in place itself: the browser must not also do it. */
	overflow-anchor: none;
}

#notice {
	margin: 0;
	padding: 1rem;
	color: var(--muted);
}

#notice:empty {
	display: none;
}

/* Shown while the page waits for the server. It only appears after a moment,
   so that an answer that comes at once does not make it flash.
   The three blocks and their movement are "blocks-shuffle-3" of SVG Spinners,
   https://github.com/n3r4zzurr0/svg-spinners

   The MIT License (MIT)

   Copyright (c) Utkarsh Verma

   Permission is hereby granted, free of charge, to any person obtaining a copy
   of this software and associated documentation files (the "Software"), to deal
   in the Software without restriction, including without limitation the rights
   to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
   copies of the Software, and to permit persons to whom the Software is
   furnished to do so, subject to the following conditions:

   The above copyright notice and this permission notice shall be included in
   all copies or substantial portions of the Software.

   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
   AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
   THE SOFTWARE. */
.spinner {
	padding: 2rem 1rem;
	text-align: center;
	animation: spinner-appear 0.2s 0.3s both;
}

.spinner svg {
	width: 2.5rem;
	height: 2.5rem;
	fill: var(--muted);
}

.spinner rect {
	animation: spinner-shuffle 2.4s linear infinite;
}

.spinner rect:nth-child(2) {
	animation-delay: -1.6s;
}

.spinner rect:nth-child(3) {
	animation-delay: -0.8s;
}

/* Shown over the top of the transcript while earlier lines are on their way.
   It takes no room, so that the text does not move when it comes and goes. */
#older {
	position: sticky;
	top: 0;
	z-index: 1;
	height: 0;
	padding: 0;
}

#older svg {
	margin-top: 0.5rem;
	padding: 0.5rem;
	border-radius: 0.5rem;
	background: var(--background);
}

@keyframes spinner-appear {
	from {
		opacity: 0;
	}
}

@keyframes spinner-shuffle {
	8.33%, 25% {
		transform: translate(12px, 0);
	}

	33.3%, 50% {
		transform: translate(12px, 12px);
	}

	58.33%, 75% {
		transform: translate(0, 12px);
	}

	83.33% {
		transform: translate(0, 0);
	}
}

#event {
	max-width: 40rem;
	margin: 0 auto;
	padding: 1rem;
}

#dates {
	margin: 0 0 1.5rem;
	color: var(--muted);
}

h2 {
	margin: 0 0 1rem;
	font-size: 1.25rem;
}

#sessions {
	display: flex;
	flex-direction: column;
	gap: 0.75rem;
}

.session {
	display: grid;
	grid-template-columns: minmax(0, 1fr) auto;
	gap: 0.25rem 1rem;
	align-items: baseline;
	width: 100%;
	padding: 1rem;
	text-align: start;
}

.session .name {
	font-size: 1.125rem;
	font-weight: 600;
}

.session-status {
	color: var(--muted);
	font-size: 0.875rem;
	white-space: nowrap;
}

/* On its own white label: the colours of an event may be anything, red
   included. */
.session[data-status="live"] .session-status {
	padding: 0.15rem 0.6rem;
	border-radius: 1rem;
	background: #fff;
	color: #c62828;
	font-weight: 600;
	opacity: 1;
}

#to-schedule {
	width: 100%;
	margin-bottom: 1.5rem;
	padding: 1rem;
	font-size: 1.125rem;
	font-weight: 600;
	text-align: start;
}

/* The programme of one room. */
#schedule {
	max-width: 40rem;
	margin: 0 auto;
	padding: 1rem;
	/* The reader's text size applies here too: the sizes below are told
	   from it, and are what they were at the size the page starts with. */
	font-size: calc(var(--text-size) / 1.5);
	padding-bottom: calc(2rem + env(safe-area-inset-bottom));
}

#rooms {
	display: flex;
	align-items: center;
	gap: 0.75rem;
	margin-bottom: 1rem;
}

#rooms h2 {
	flex: 1;
	font-size: 1.25em;
	min-width: 0;
	margin: 0;
	text-align: center;
	overflow-wrap: anywhere;
}

#room-transcript {
	margin-bottom: 1.5rem;
}

#schedule .session {
	font-size: inherit;
}

#schedule .session .name {
	font-size: 1.125em;
}

#schedule .session-status {
	font-size: 0.875em;
}

#talks h3 {
	margin: 1.5rem 0 0.75rem;
	color: var(--muted);
	font-size: 1em;
	font-weight: 600;
}

.talk {
	margin: 0 0 0.75rem;
	padding: 0.75rem 1rem;
	border: 1px solid var(--border);
	border-inline-start-width: 0.3rem;
	border-radius: 0.5rem;
}

.talk p,
.talk h4 {
	margin: 0;
}

.talk h4 {
	margin: 0.2rem 0;
	font-size: 1.125em;
	overflow-wrap: anywhere;
}

.talk-time,
.talk-speakers {
	color: var(--muted);
	font-size: 0.9375em;
}

/* The picture of a talk: at its end, as high as the talk. */
.talk.pictured {
	position: relative;
	padding-inline-end: 7.5rem;
	overflow: hidden;
}

.talk-image {
	position: absolute;
	inset-block: 0;
	inset-inline-end: 0;
	width: 6.5rem;
	height: 100%;
	object-fit: cover;
}

.talk.past .talk-image {
	opacity: 0.6;
}

/* The links of a talk: its transcript at the start, its page at the end. */
.talk-links {
	display: flex;
	flex-wrap: wrap;
	gap: 0.25rem 1rem;
	margin-top: 0.4rem;
	font-size: 0.9375em;
}

.talk-links a {
	color: inherit;
}

.talk-links.first {
	margin: 0 0 0.5rem;
}

.talk-page {
	margin-inline-start: auto;
}

/* The transcript of the talk being given: framed in red, with the full
   circle of a recording. */
.talk-links a.live {
	display: inline-flex;
	align-items: center;
	gap: 0.45em;
	padding: 0.15em 0.75em;
	border: 1px solid var(--live);
	border-radius: 999px;
	text-decoration: none;
}

.talk-links a.live::before {
	content: "";
	flex: none;
	width: 0.65em;
	height: 0.65em;
	border-radius: 50%;
	background: var(--live);
}

/* What stands before the first line of a session. It follows the reader's
   text size, as the talks announced below it do. */
.opening {
	max-width: 40rem;
	margin: 0 0 1.5rem;
	padding-bottom: 1rem;
	border-bottom: 1px solid var(--border);
	font-size: calc(var(--text-size) / 1.5);
	line-height: 1.35;
}

.opening img {
	display: block;
	max-width: 12em;
	max-height: 6em;
	margin-bottom: 0.75em;
	object-fit: contain;
}

.opening h2 {
	margin: 0 0 0.3em;
	font-size: 1.5em;
}

.opening p {
	margin: 0;
	color: var(--muted);
}

.opening .room {
	color: var(--text);
	font-size: 1.15em;
	font-weight: 600;
}

/* A talk announced in the transcript, where it begins. */
main .talk {
	max-width: 40rem;
	margin: 1.5rem 0 1rem;
	background: var(--surface);
	font-size: calc(var(--text-size) / 1.5);
	line-height: normal;
	/* The bar leaves room for it when the reader is brought to it. */
	scroll-margin-top: 0.5rem;
}

/* What is over is greyed; what is being given stands out. */
.talk.past {
	border-color: transparent;
	background: var(--surface);
	color: var(--muted);
}

.talk.past h4 {
	font-weight: 400;
}

.talk.current {
	border-color: var(--live);
	background: var(--surface);
}

.talk.current .talk-time {
	color: var(--text);
	font-weight: 600;
}

.now {
	margin-inline-start: 0.5rem;
	padding: 0.1rem 0.6rem;
	border-radius: 1rem;
	background: var(--live);
	color: #fff;
	font-size: 0.8667em;
	font-weight: 600;
}

main {
	padding: 1rem;
	font-size: var(--text-size);
	line-height: 1.4;
	overflow-wrap: break-word;
}

/* The part of a line being typed that is still to come: it holds its place. */
.pending {
	visibility: hidden;
}

/* For screen readers only. */
.unseen {
	position: absolute;
	width: 1px;
	height: 1px;
	overflow: hidden;
	clip-path: inset(50%);
	white-space: nowrap;
}

main > p {
	max-width: 40em;
	margin: 0 0 0.6em;
}

/* A session that tells speakers apart: each line has a bar in the colour of
   its speaker. The text keeps its colour, which is the one that reads best.
   Lines nobody is named for keep the place of the bar, so that all align. */
main.speakers > p {
	padding-inline-start: 0.6rem;
	border-inline-start: 0.3rem solid transparent;
	border-radius: 0;
}

main > p[data-speaker="1"] {
	border-inline-start-color: var(--speaker-1);
}

main > p[data-speaker="2"] {
	border-inline-start-color: var(--speaker-2);
}

main > p[data-speaker="3"] {
	border-inline-start-color: var(--speaker-3);
}

main > p[data-speaker="4"] {
	border-inline-start-color: var(--speaker-4);
}

main > p[data-speaker="5"] {
	border-inline-start-color: var(--speaker-5);
}

main > p[data-speaker="6"] {
	border-inline-start-color: var(--speaker-6);
}

main > p[data-speaker="7"] {
	border-inline-start-color: var(--speaker-7);
}

main > p[data-speaker="8"] {
	border-inline-start-color: var(--speaker-8);
}

/* A bar of its own under what scrolls, like the header above it: no text
   goes behind its buttons, and it stays at the bottom of the screen whatever
   the browser does with its own bars. */
#jumps {
	flex: none;
	display: grid;
	grid-template-columns: 1fr auto 1fr;
	align-items: center;
	gap: 0.5rem;
	padding: 0.5rem;
	border-top: 1px solid var(--border);
	background: var(--background);
}

/* Room for the bar a phone draws over the bottom of the screen, only where
   the page really reaches under it: installed as an app. In its browser,
   Firefox for Android reports such a bar although the page stops above it,
   which left a blank strip under the buttons. */
@media (display-mode: standalone) {
	#jumps {
		padding-bottom: calc(0.5rem + env(safe-area-inset-bottom));
	}
}

/* Each has its place, whether the others are shown or not. */
#agenda {
	grid-column: 1;
	justify-self: start;
}

#places {
	grid-column: 2;
	display: flex;
	gap: 0.5rem;
}

#language {
	grid-column: 3;
	justify-self: end;
}

#jumps button,
#jumps .picker {
	white-space: nowrap;
}

#jump {
	display: inline-grid;
	align-items: center;
	justify-items: center;
}

#jump span {
	grid-area: 1 / 1;
}

#jump[data-goes="next"] .latest,
#jump[data-goes="latest"] .next {
	visibility: hidden;
}
