/* Zpevnik - minimal, responsive, no external dependencies */

@font-face {
	font-family: 'Inconsolata';
	font-style: normal;
	font-weight: 200 900;
	font-stretch: 100%;
	font-display: swap;
	src: url("../fonts/inconsolata-latin-ext.woff2") format("woff2");
	unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
	font-family: 'Inconsolata';
	font-style: normal;
	font-weight: 200 900;
	font-stretch: 100%;
	font-display: swap;
	src: url("../fonts/inconsolata-latin.woff2") format("woff2");
	unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
	--bg: #ffffff;
	--fg: #222222;
	--muted: #757575;
	--accent: #b5541a;
	--accent-contrast: #ffffff;
	--border: #e2e2e2;
	--panel: #f7f6f4;
	--danger: #b53030;
	--radius: 8px;
	--topbar-h: 54px;
	--song-font-family: 'Inconsolata', monospace;
	--song-font-weight: 400;
}

html.darkTheme {
	--bg: #1c1c1c;
	--fg: #e8e8e8;
	--muted: #a3a3a3;
	--accent: #e2823e;
	--accent-contrast: #1c1c1c;
	--border: #3a3a3a;
	--panel: #262626;
}

html.noDoubleTapZoom { touch-action: manipulation; }

* { box-sizing: border-box; }

html, body {
	height: 100%;
	margin: 0;
	background: var(--bg);
	color: var(--fg);
	color-scheme: light;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
body {
	display: flex;
	flex-direction: column;
}
html.darkTheme, html.darkTheme body { color-scheme: dark; }

a { color: var(--accent); text-decoration: none; }
.songLink, .songLink:hover, .songLink:active, .songLink:focus { text-decoration: none; }

button { font: inherit; }

/* ---------- Top bar ---------- */

.topbar {
	position: sticky;
	top: 0;
	z-index: 20;
	height: var(--topbar-h);
	min-height: var(--topbar-h);
	/* Flex items default to a content-based minimum height, which can grow
	   past our fixed height once body became a flex column (for the
	   scrollTimeBar fix) - flex-shrink/grow:0 pins it to exactly --topbar-h
	   regardless of what its content needs. */
	flex: 0 0 var(--topbar-h);
	display: flex;
	align-items: center;
	gap: 4px;
	padding: 0 6px;
	background: #3a3a3a;
	color: #ffffff;
}

.iconBtn {
	background: transparent;
	border: none;
	color: #ffffff;
	font-size: 22px;
	line-height: 22px;
	padding: 10px 12px;
	border-radius: var(--radius);
	cursor: pointer;
	display: inline-flex;
	align-items: center;
	justify-content: center;
}
a.iconBtn { display: inline-flex; align-items: center; }

.icon {
	width: 24px;
	height: 24px;
	display: block;
}

/* Editor top bar: back arrow stays left, transpose icons sit at 20% of the
   width from the left, remaining action icons are centered on the page. */
.editorTopbarLayout {
	position: relative;
	flex: 1;
	height: 100%;
}
.editorTopbarLayout .topbarLeft {
	position: absolute;
	left: 0;
	top: 50%;
	transform: translateY(-50%);
	display: flex;
	gap: 4px;
}
.editorTopbarLayout .topbarTranspose {
	position: absolute;
	left: 20%;
	top: 50%;
	transform: translate(-50%, -50%);
	display: flex;
	gap: 4px;
}
.editorTopbarLayout .topbarActions {
	position: absolute;
	left: 50%;
	top: 50%;
	transform: translate(-50%, -50%);
	display: flex;
	gap: 4px;
}
.editorTopbarLayout .topbarRight {
	position: absolute;
	right: 0;
	top: 50%;
	transform: translateY(-50%);
}

/* On narrow screens the 20% anchor gets too cramped next to the left
   navigation controls, so fall back to a simple left-to-right row. */
@media (max-width: 750px) {
	.editorTopbarLayout {
		display: flex;
		align-items: center;
		gap: 4px;
	}
	.editorTopbarLayout .topbarLeft,
	.editorTopbarLayout .topbarTranspose,
	.editorTopbarLayout .topbarActions,
	.editorTopbarLayout .topbarRight {
		position: static;
		transform: none;
		display: inline-flex;
		gap: 4px;
	}
}

.searchWrap {
	flex: 1;
	display: flex;
	align-items: center;
	min-width: 0;
	position: relative;
}
.topbarSpacer { flex: 0 0 0; width: 0; }
@media (min-width: 600px) {
	.searchWrap { flex: 0 1 25%; max-width: 25%; }
	.topbarSpacer { flex: 1 1 auto; }
}
.topbarRightIcons,
.topbarTransposeGroup {
	display: flex;
	align-items: center;
	gap: 4px;
}
.topbarTransposeGroup { gap: 24px; }
@media (max-width: 599px) {
	.topbarTransposeGroup { gap: 8px; }
}
.autoscrollSpeedControls {
	display: flex;
	align-items: center;
	gap: 20px;
	flex: 0 0 auto;
	margin: 0 8px;
}
@media (max-width: 599px) {
	body.autoscrollActive .searchWrap { display: none; }
}
.searchWrap input[type="search"] {
	width: 100%;
	padding: 8px 30px 8px 10px;
	border-radius: var(--radius);
	border: none;
	font-size: 16px;
}
/* macOS Safari draws its own built-in clear ("x in a circle") button on
   type="search" inputs, duplicating our #searchClear icon. Mobile Safari
   doesn't do this, so it only needs suppressing here. */
.searchWrap input[type="search"]::-webkit-search-cancel-button {
	-webkit-appearance: none;
	appearance: none;
	display: none;
}
#searchClear {
	position: absolute;
	top: 50%;
	right: 0;
	transform: translateY(-50%);
	color: var(--fg);
}

/* ---------- Dropdown settings menu ---------- */

.dropdown {
	position: absolute;
	top: var(--topbar-h);
	right: 6px;
	background: var(--panel);
	color: var(--fg);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	box-shadow: 0 6px 18px rgba(0,0,0,0.15);
	padding: 8px;
	width: min(340px, 92vw);
	max-height: calc(100vh - var(--topbar-h) - 12px);
	max-height: calc(100dvh - var(--topbar-h) - 12px);
	overflow-y: auto;
	z-index: 30;
}
.hidden { display: none !important; }

.dropdownHeader {
	font-size: 14px;
	color: var(--muted);
	padding: 6px 4px 2px;
}
.dropdownDivider {
	height: 1px;
	background: var(--border);
	margin: 6px 0;
}
.menuItem {
	display: block;
	width: 100%;
	text-align: left;
	background: var(--bg);
	border: 1px solid var(--border);
	color: var(--fg);
	padding: 10px 12px;
	margin: 4px 0;
	border-radius: var(--radius);
	cursor: pointer;
}
.menuItem.active { background: var(--accent); color: var(--accent-contrast); border-color: var(--accent); }
.fontSizeDisplay { display: flex; align-items: center; justify-content: center; cursor: default; }
.menuRow { display: flex; flex-wrap: nowrap; gap: 6px; }
.menuRow .menuItem { flex: 1; margin: 4px 0; }
.autoscrollBtn { font-weight: 600; }

/* ---------- Countdown overlay ---------- */

#countdownOverlay {
	position: fixed;
	inset: 0;
	background: rgba(0,0,0,0.55);
	display: flex;
	align-items: center;
	justify-content: center;
	z-index: 50;
}
#countdown {
	font-size: 64px;
	color: #fff;
	font-weight: 700;
}

/* ---------- Autoscroll "save time" bottom bar (non-blocking) ---------- */

.scrollTimeBar {
	/* Deliberately NOT position:fixed - iPadOS/iOS Safari can fail to keep
	   fixed elements correctly positioned/visible after touch/momentum
	   scrolling happens inside a nested scroll container (our song text
	   scrolls inside #mainSpace, not the page body). Being a normal flex
	   item at the end of <body> guarantees it always sits inside the real
	   visible viewport, at the cost of #mainSpace shrinking slightly while
	   it's shown. */
	flex-shrink: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 10px;
	padding: 10px 16px;
	padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
	background: var(--panel);
	border-top: 1px solid var(--border);
	box-shadow: 0 -4px 12px rgba(0,0,0,0.08);
}
#scrollTimeBarText { color: var(--fg); font-size: 15px; }

/* ---------- Layout ---------- */

.layout {
	display: flex;
	flex: 1 1 auto;
	min-height: 0;
}

.songMenu {
	width: 280px;
	max-width: 80vw;
	flex-shrink: 0;
	overflow-y: auto;
	border-right: 1px solid var(--border);
	background: var(--panel);
}
.songMenuTable { width: 100%; border-collapse: collapse; }
.songMenuTable td { padding: 0; }

.leftMenuSongButton {
	display: flex;
	flex-direction: column;
	gap: 1px;
	padding: 6px 10px;
	border-bottom: 1px solid var(--border);
	color: var(--fg);
	line-height: 20px;
	font-family: Verdana, sans-serif;
}
.leftMenuSongButton.needsFixSong { background: #fff9c4; }
.leftMenuSongRow { display: flex; align-items: baseline; gap: 8px; }
.leftMenuSongTitle { font-weight: 400; font-size: 15px; }
.leftMenuSongChord { margin-left: auto; color: var(--fg); font-weight: 600; font-size: 13px; }
.leftMenuSongAuthor { color: var(--accent); font-size: 13px; }
.leftMenuHiddenPart { display: none; }
html.darkTheme .leftMenuSongButton.needsFixSong { background: #4a4420; }

.mainSpace {
	flex: 1;
	overflow-y: auto;
	padding: 16px 20px 60px;
	line-height: 26px;
	font-size: 21px;
	font-weight: var(--song-font-weight);
}

.helpBox {
	color: var(--muted);
	max-width: 60ch;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
	font-weight: 400;
	font-size: 16px;
}

/* Song rendering */
.songTitle { margin-top: 0; }
.songAuthor { color: var(--muted); font-weight: 400; font-size: 16px; }
.songScrollTime { color: var(--muted); font-size: 14px; margin: -8px 0 12px; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
.textLine { white-space: pre; }
.songLine { position: relative; margin-bottom: 2px; }
.chordLine { position: relative; height: var(--song-chord-line-height, 25px); }
.chordTok { position: absolute; top: 0; left: 0; white-space: nowrap; color: var(--accent); font-weight: 400; font-family: var(--song-font-family); }
.chordAvailable { cursor: pointer; touch-action: manipulation; }
.chordAvailable:hover { text-decoration: underline; }
.chordAvailable:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 2px; }
.chordDialog {
	width: min(280px, calc(100vw - 32px));
	max-height: calc(100dvh - 32px);
	box-sizing: border-box;
	padding: 12px 16px 16px;
	border: 1px solid var(--border);
	border-radius: var(--radius);
	background: var(--bg);
	color: var(--fg);
	overflow: auto;
}
.chordDialog::backdrop { background: rgba(0, 0, 0, 0.35); }
.chordDialogHeader { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.chordDialogHeader h2 { margin: 0; font-size: 22px; overflow-wrap: anywhere; }
.chordDialogHeader .iconBtn { color: var(--fg); flex: 0 0 44px; width: 44px; height: 44px; padding: 10px; }
.chordDiagram { width: 100%; height: auto; aspect-ratio: 400 / 425.2; }
.darkTheme .chordDiagram { filter: invert(1); }
.chordDiagramError { font-size: 14px; }
.mainSpace, .songTitle, .songAuthor { font-family: var(--song-font-family); }
.commentLine { color: var(--muted); font-family: var(--song-font-family); font-weight: var(--song-font-weight); }

.mainSpace.twoColumns .songLyrics {
	column-count: 2;
	column-gap: 2em;
	column-rule: 1px solid var(--border);
	min-width: calc(2 * var(--song-line-width, 0px) + 2em);
}
.mainSpace.threeColumns .songLyrics {
	column-count: 3;
	column-gap: 2em;
	column-rule: 1px solid var(--border);
	min-width: calc(3 * var(--song-line-width, 0px) + 4em);
}
.songLyrics .songLine { break-inside: avoid; }
#columnsToggle[aria-pressed="true"] { background: var(--accent); }

@media (max-width: 720px) and (orientation: portrait) {
	#columnsToggle { display: none; }
	.mainSpace.twoColumns .songLyrics,
	.mainSpace.threeColumns .songLyrics {
		column-count: 1;
		column-rule: none;
		min-width: 0;
	}
}

/* Responsive: hide song list off-canvas on small screens */
@media (max-width: 720px) {
	.songMenu {
		position: fixed;
		top: var(--topbar-h);
		left: 0;
		z-index: 15;
		transform: translateX(-100%);
		transition: transform 0.2s ease;
		width: 85vw;
		height: calc(100vh - var(--topbar-h));
		height: calc(100dvh - var(--topbar-h));
	}
	.songMenu.open { transform: translateX(0); box-shadow: 4px 0 12px rgba(0,0,0,0.25); }
	.layout { position: relative; }
}

/* ---------- Login page ---------- */

.loginBody {
	display: flex;
	align-items: center;
	justify-content: center;
	min-height: 100vh;
	min-height: 100dvh;
	background: var(--panel);
}
.loginForm {
	background: var(--bg);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	padding: 24px;
	width: min(360px, 92vw);
	display: flex;
	flex-direction: column;
	gap: 10px;
}
.loginTitle { text-align: center; margin: 0 0 8px; }
.loginForm input {
	padding: 10px 12px;
	border: 1px solid var(--border);
	border-radius: var(--radius);
	font-size: 16px;
}

/* ---------- Buttons & notices ---------- */

.btn {
	padding: 10px 16px;
	border-radius: var(--radius);
	border: 1px solid var(--border);
	background: var(--bg);
	color: var(--fg);
	cursor: pointer;
}
.btnPrimary { background: var(--accent); color: var(--accent-contrast); border-color: var(--accent); }
.btnDanger { background: var(--danger); color: #fff; border-color: var(--danger); }
.adminBlockForm { display: inline; }
.adminBlockBtn { padding: 4px 10px; font-size: 14px; border-radius: var(--radius); border: 1px solid transparent; cursor: pointer; white-space: nowrap; }
.adminActionsCell { display: flex; flex-wrap: wrap; gap: 6px; }
.adminActionsCell .adminBlockForm { display: inline-flex; }

.notice {
	padding: 10px 14px;
	border-radius: var(--radius);
	margin-bottom: 12px;
}
.notice-ok { background: #e4f3e6; color: #1f6b2b; }
.notice-error { background: #fbe6e6; color: var(--danger); }

/* ---------- Editor / Admin / Settings pages ---------- */

.editorContent, .settingsContent {
	padding: 16px 20px 60px;
	width: 80%;
	margin: 0 auto;
}

.editorWorkspace {
	flex: 1 1 auto;
	min-height: 0;
	display: flex;
	flex-direction: column;
}

.adminContent {
	padding: 16px 20px 60px;
	width: 90%;
	margin: 0 auto;
}

.editorForm { display: flex; flex: 1 1 auto; flex-direction: column; gap: 10px; min-height: 0; }
.editorSongBody {
	padding: 10px 12px;
	border: 1px solid var(--border);
	border-radius: var(--radius);
	font-size: 16px;
}
textarea.editorSongBody { font-family: "Courier New", Courier, monospace; resize: vertical; }
.editorWorkspace textarea.editorSongBody { flex: 1 1 0; min-height: 0; }
.editorFormButtons { display: flex; gap: 8px; flex-wrap: wrap; }

.editorSearchBar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.editorSearchBar input { flex: 1; min-width: 200px; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius); }
.editorTuneHint { color: var(--muted); font-size: 14px; }

.editorTable, .adminTable { width: 100%; border-collapse: collapse; }
.editorTable th, .editorTable td, .adminTable th, .adminTable td {
	border-bottom: 1px solid var(--border);
	padding: 8px 10px;
	text-align: left;
}
.editorTableStartingChord, .adminTableSmallColumn { color: var(--muted); white-space: nowrap; }
.needsFixRow { background: #fff3b0; }

.settingsInfo { color: var(--muted); }
.settingsLine { margin: 20px 0; }
.settingsLineHeader { margin: 0 0 10px; font-size: 17px; }
.settingsLineForm { display: flex; flex-direction: column; gap: 8px; }
.settingsLineForm input, .settingsLineForm textarea {
	padding: 10px 12px;
	border: 1px solid var(--border);
	border-radius: var(--radius);
	font: inherit;
}

/* Hover feedback (icon/menu buttons, list rows) only for pointers that can
   actually hover. On touchscreens ":hover" is triggered by tapping but never
   cleared until something else is tapped, leaving buttons stuck looking
   "pressed" - so these styles are opt-in for mouse-like pointers only. */
@media (hover: hover) and (pointer: fine) {
	a:hover { text-decoration: underline; }
	.iconBtn:hover { background: rgba(255,255,255,0.15); }
	.menuItem:hover { background: var(--panel); text-decoration: none; }
	.leftMenuSongButton:hover { background: #ece9e4; }
	.leftMenuSongButton.needsFixSong:hover { background: #fdf2a0; }
	html.darkTheme .leftMenuSongButton:hover { background: #333333; }
	html.darkTheme .leftMenuSongButton.needsFixSong:hover { background: #5c5527; }
	.btn:hover { background: var(--panel); }
	.loginForm .btnPrimary:hover { background: var(--accent); filter: brightness(1.12); }
	.needsFixRow:hover { background: #ffe98a; }
}
