:root {
	color-scheme: light dark;
	/* Aventurine takes its theme from the stone: --brand is the default colour and the shades derive from it. */
	--brand: #1e5b45;
	--accent: var(--brand);
	--brand-dark: #154432;
	--brand-tint: #eef4f1;
	--on-brand: #fff;
	--bg: #f2f5f8;
	--surface: #fff;
	--ink: #14213d;
	--muted: #5d6b7c;
	--line: #d5dde6;
	--control-line: #aaa;
	--present: #167a41;
	--late: #f2b01e;
	--absent: #c93c3c;
	--error-bg: #fbe4e4;
	--error-ink: #7a1c1c;
	--note-bg: #fdf0c8;
	--dot-ok: #7bd88f;
	--dot-syncing: #8ab4ff;
	--dot-error: #ff9b9b;
	--glass: rgba(255,255,255,.14);
	--glass-faint: rgba(255,255,255,.28);
	--glass-line: rgba(255,255,255,.55);
	--shadow: 0 4px 12px rgba(0,0,0,.13);
	--radius-s: 4px;
	--radius-m: 12px;
	--radius-pill: 999px;
	--tap: 44px;
	--tap-lg: 52px;
	--tap-row: 68px;
	--on-late: #14213d;
}

/* Follows the system setting; the brand header and status colours stay as they are. */
@media (prefers-color-scheme: dark) {
	:root {
		--accent: #5fbf94;
		--brand-tint: #1f2d27;
		--bg: #10151b;
		--surface: #1a2129;
		--ink: #e6ebf1;
		--muted: #9aa7b5;
		--line: #2f3944;
		--control-line: #55606c;
		--error-bg: #4a1f1f;
		--error-ink: #f5c2c2;
		--note-bg: #4a3d12;
	}
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { min-height: 100dvh; margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.4 "Avenir Next", system-ui, -apple-system, "Segoe UI", sans-serif; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
a { color: var(--accent); font-weight: 600; text-decoration: none; }
h1 { margin: 0; font-size: 28px; }
label { display: block; margin-top: 8px; font-size: 14px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* Form field */
input, select, textarea { width: 100%; min-height: var(--tap); padding: 10px 12px; border: 1px solid var(--control-line); border-radius: var(--radius-m); background: var(--surface); color: inherit; font: inherit; }
textarea { min-height: 8em; resize: vertical; }
form, fieldset { display: grid; gap: 8px; min-width: 0; margin: 0; padding: 0; border: 0; }

/* Button: variants set the --btn-* properties */
button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: var(--tap); padding: 0 16px; border: 1px solid var(--btn-border, var(--btn-bg, var(--brand))); border-radius: var(--radius-m); background: var(--btn-bg, var(--brand)); color: var(--btn-fg, var(--on-brand)); font: inherit; font-weight: 700; cursor: pointer; }
button:hover:not(:disabled) { background: var(--btn-hover, var(--brand-dark)); }
button:active:not(:disabled) { transform: scale(.98); }
button:disabled { opacity: .55; cursor: default; }
.outline, .managed-students button { --btn-bg: transparent; --btn-fg: var(--accent); --btn-border: var(--accent); --btn-hover: var(--brand-tint); }
.managed-students button { width: var(--tap); padding: 0; font-size: 22px; }

.error { margin: 0; padding: 8px 12px; border-radius: var(--radius-s); background: var(--error-bg); color: var(--error-ink); font-size: 14px; }

/* Header: brand bar on every page; the menu and sync pill appear on app pages */
.app-header { position: sticky; top: 0; z-index: 2; padding: calc(10px + env(safe-area-inset-top)) 12px 10px; background: var(--brand); color: var(--on-brand); }
.app-header :focus-visible { outline-color: var(--on-brand); }
.app-nav { display: flex; align-items: center; gap: 12px; max-width: 960px; margin: 0 auto; }
.app-nav > a { color: var(--on-brand); }

/* Pill: sync status; the dot shows the state */
.pill { --btn-bg: var(--glass); --btn-border: transparent; --btn-hover: var(--glass); margin-left: auto; border-radius: var(--radius-pill); font-size: 14px; font-weight: 400; white-space: nowrap; }
.pill::before { content: ""; width: 10px; height: 10px; flex: none; border-radius: 50%; background: var(--dot-ok); }
.pill[data-state="wait"]::before { background: var(--late); }
.pill[data-state="syncing"]::before { background: var(--dot-syncing); }
.pill[data-state="error"]::before { background: var(--dot-error); }

/* Menu */
.account-menu { position: relative; flex: none; }
.account-menu summary { display: grid; place-items: center; width: var(--tap); height: var(--tap); border: 1px solid var(--glass-line); border-radius: var(--radius-m); cursor: pointer; list-style: none; }
.account-menu summary::-webkit-details-marker { display: none; }
.account-menu summary:hover { background: var(--glass); }
/* An invisible full-screen layer inside the summary: tapping anywhere else closes the menu without JS. */
.account-menu[open] summary::before { content: ""; position: fixed; inset: 0; z-index: 1; }
.account-links { position: absolute; z-index: 2; right: 0; top: calc(var(--tap) + 4px); width: 180px; padding: 4px; border: 1px solid var(--line); border-radius: var(--radius-s); background: var(--surface); box-shadow: var(--shadow); }
.account-links :is(a, button) { display: flex; align-items: center; justify-content: flex-start; width: 100%; min-height: var(--tap); padding: 10px 12px; color: var(--ink); text-align: left; font-weight: 600; }
.account-links button { --btn-bg: transparent; --btn-fg: var(--ink); --btn-border: transparent; --btn-hover: var(--brand-tint); }
.account-links a:hover { background: var(--brand-tint); }

/* Tab */
.field-tabs { display: flex; gap: 6px; max-width: 960px; margin: 10px auto 0; overflow-x: auto; scrollbar-width: none; }
.field-tabs button { --btn-bg: transparent; --btn-border: var(--glass-faint); --btn-hover: var(--glass); flex: 1 0 auto; min-height: var(--tap-lg); white-space: nowrap; }
.field-tabs button[aria-selected="true"] { --btn-bg: var(--surface); --btn-fg: var(--ink); --btn-border: var(--surface); --btn-hover: var(--surface); }
.field-tabs small { margin-left: 6px; font-weight: 500; opacity: .8; }

/* Page layout and panel */
.field-main { display: grid; gap: 16px; width: min(100% - 24px, 960px); margin: 20px auto 0; }
.field-main > button { justify-self: start; }
.panel { border: 1px solid var(--line); border-radius: var(--radius-s); background: var(--surface); }
.card { display: grid; gap: 16px; width: min(100% - 24px, 360px); margin: 15vh auto 40px; padding: 24px; }
.field-status, .field-empty { margin: 0; padding: 28px 16px; color: var(--muted); text-align: center; }
.field-note { margin: 0; padding: 8px 12px; background: var(--note-bg); font-size: 14px; }
.field-error { padding: 24px 16px; text-align: center; }
.field-error p { margin: 0 0 12px; }
.field-error a { display: inline-block; padding: 12px 20px; }
.student-editor { border-bottom: 1px solid var(--line); }
.student-editor summary { display: flex; align-items: center; justify-content: space-between; min-height: var(--tap-lg); padding: 12px 16px; background: var(--brand-tint); color: var(--accent); font-weight: 700; cursor: pointer; list-style: none; }
.student-editor summary::-webkit-details-marker { display: none; }
.student-editor summary::after { content: "+"; font-size: 24px; line-height: 1; }
.student-editor[open] summary::after { content: "−"; }
.student-form { padding: 0 16px 16px; }
.field-footer { position: sticky; bottom: 0; display: flex; flex-direction: column; gap: 8px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--surface); }
.field-footer button { min-height: var(--tap-lg); }
.field-footer-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-weight: 600; }
.field-footer input { width: auto; }

/* List row: register and students share it; data-mark colours the left edge */
.student-list { margin: 0; padding: 0; list-style: none; }
.student-list li { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: var(--tap-row); padding: 8px 12px 8px 10px; border-bottom: 1px solid var(--line); border-left: 6px solid transparent; background: var(--surface); font-size: 18px; font-weight: 600; }
.student-list li span { min-width: 0; overflow-wrap: anywhere; }
.note-list li span { font-weight: 400; white-space: pre-wrap; }
.student-list li[data-mark="present"] { border-left-color: var(--present); }
.student-list li[data-mark="late"] { border-left-color: var(--late); }
.student-list li[data-mark="absent"] { border-left-color: var(--absent); }
.student-details { min-width: 0; overflow-wrap: anywhere; }
.student-details small { display: block; margin-top: 4px; color: var(--muted); font-size: 14px; font-weight: 400; }
.student-actions, .status-options { display: flex; flex: none; gap: 8px; }
.student-actions .percentage { font-weight: 400; }
.student-actions .tally { font-size: 14px; font-weight: 400; color: var(--muted); white-space: nowrap; }

/* Status buttons: the pressed one takes its status colour */
.status-options button { --btn-bg: var(--surface); --btn-fg: var(--muted); --btn-border: var(--line); --btn-hover: var(--brand-tint); width: 56px; min-height: var(--tap-lg); padding: 0; border-width: 2px; font-size: 18px; }
.status-options button[data-status="present"] { --on: var(--present); }
.status-options button[data-status="late"] { --on: var(--late); --on-fg: var(--on-late); }
.status-options button[data-status="absent"] { --on: var(--absent); }
.status-options button[aria-pressed="true"] { --btn-bg: var(--on); --btn-fg: var(--on-fg, var(--on-brand)); --btn-border: var(--on); --btn-hover: var(--on); }

@media (min-width: 720px) {
	.student-list { display: grid; grid-template-columns: 1fr 1fr; column-gap: 1px; background: var(--line); }
}
