:root {
  --bg: #000;
  --surface: #0f0f10;
  --surface-2: #18181b;
  --line: #26262a;
  --text: #f5f5f4;
  --muted: #8a8a90;
  /* Colours are overridden per tenant by an inline :root style (lib/views.js). */
  --accent: #d4d4d8;
  --accent-hover: #d4d4d8;
  --on-accent: #000;
  --live: #22c55e;
  --warn: #f59e0b;
  --radius: 14px;
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; line-height: 1.5; -webkit-font-smoothing: antialiased; }
a { color: var(--text); }
a:focus-visible, button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }

/* ---- top bar ---- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1.1rem clamp(1rem, 4vw, 2.5rem); border-bottom: 1px solid var(--line); }
.brand img { display: block; height: 30px; width: auto; }
.brand svg { display: block; height: 28px; width: auto; color: var(--text); }
.wordmark { display: block; font-weight: 700; font-size: 1.05rem; letter-spacing: .18em; text-transform: uppercase; text-decoration: none; }
.brand { text-decoration: none; }
.topnav form { margin: 0; }
.link { background: none; border: 0; color: var(--muted); font: inherit; font-size: .9rem; cursor: pointer; padding: .3rem 0; }
.link:hover { color: var(--text); }

.wrap { flex: 1; width: 100%; max-width: 1280px; margin: 0 auto; padding: clamp(1.5rem, 4vw, 3rem) clamp(1rem, 4vw, 2.5rem); }
body.center .wrap { display: grid; place-items: center; }

/* ---- home ---- */
.hero { margin-bottom: 2rem; }
.eyebrow { margin: 0 0 .4rem; color: var(--accent); font-weight: 700; font-size: .78rem; letter-spacing: .14em; text-transform: uppercase; }
h1 { margin: 0; font-size: clamp(1.6rem, 3.6vw, 2.4rem); letter-spacing: -.03em; line-height: 1.15; }
.grid { list-style: none; padding: 0; margin: 0; display: grid; gap: 1.25rem; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); }
.card { display: block; text-decoration: none; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; transition: transform .18s ease, border-color .18s ease; }
.card:hover { transform: translateY(-3px); border-color: #3a3a40; }
.card-media { position: relative; display: block; aspect-ratio: 16 / 9; background: #111 center / cover no-repeat; }
.card-media::after { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, transparent 40%, rgba(0,0,0,.65)); }
.card-badge { position: absolute; z-index: 1; right: 14px; bottom: 14px; width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; background: rgba(0,0,0,.55); backdrop-filter: blur(6px); border: 1px solid rgba(255,255,255,.18); transition: background .18s; }
.card-badge svg { width: 18px; height: 18px; }
.card:hover .card-badge, .card-badge.is-open { background: var(--accent); border-color: transparent; }
.card-body { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; padding: 1rem 1.1rem; }
.card-title { font-weight: 700; font-size: 1.05rem; }
.card-meta { color: var(--muted); font-size: .82rem; }

/* ---- password panel ---- */
.panel { width: min(100%, 420px); background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 2rem; text-align: center; }
.panel h1 { font-size: 1.6rem; margin-bottom: .4rem; }
.panel-icon { display: inline-grid; place-items: center; width: 52px; height: 52px; border-radius: 50%; background: var(--surface-2); color: var(--accent); margin-bottom: 1rem; }
.panel-icon svg { width: 22px; height: 22px; }
.stack { display: grid; gap: .75rem; margin-top: 1.4rem; }
input[type="password"] { width: 100%; font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: .8rem 1rem; }
input[type="password"]:focus { border-color: var(--accent); outline: none; }
.alert { background: rgba(217,48,93,.12); border: 1px solid rgba(217,48,93,.45); color: #ffb3c6; border-radius: 10px; padding: .6rem .8rem; margin: 1rem 0 0; font-size: .9rem; }
.back { display: inline-block; margin-top: 1.4rem; color: var(--muted); text-decoration: none; font-size: .9rem; }
.back:hover { color: var(--text); }

/* ---- buttons ---- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .5rem; font: inherit; font-weight: 650; font-size: .92rem; color: var(--on-accent); background: var(--accent); border: 1px solid transparent; border-radius: 10px; padding: .75rem 1.1rem; cursor: pointer; text-decoration: none; transition: background .15s; }
.btn:hover { background: var(--accent-hover); filter: brightness(1.08); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.ghost { background: var(--surface-2); border-color: var(--line); color: var(--text); font-weight: 550; padding: .55rem .9rem; font-size: .85rem; }
.btn.ghost:hover { background: #222226; }

/* ---- stream page ---- */
.stage-head { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: 1rem; margin-bottom: 1.1rem; }
.status { margin: .35rem 0 0; display: flex; align-items: center; gap: .5rem; color: var(--muted); font-size: .88rem; }
.sep { opacity: .5; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.dot.live { background: var(--live); box-shadow: 0 0 0 0 rgba(34,197,94,.6); animation: pulse 1.8s infinite; }
.dot.wait { background: var(--warn); }
.dot.err { background: var(--accent); }
@keyframes pulse { 70% { box-shadow: 0 0 0 8px rgba(34,197,94,0); } 100% { box-shadow: 0 0 0 0 rgba(34,197,94,0); } }
.chips { display: flex; flex-wrap: wrap; gap: .5rem; }
.chip { font-size: .85rem; text-decoration: none; padding: .4rem .8rem; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); }
.chip:hover { color: var(--text); border-color: #3a3a40; }
.chip.locked::before { content: "🔒 "; font-size: .75em; }

.player-frame { position: relative; width: 100%; aspect-ratio: 16 / 9; max-height: calc(100dvh - 240px); margin: 0 auto; background: #050505; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); }
#gradetonic_player_wrapper { position: absolute; inset: 0; }
#gradetonic_player_wrapper > div, #gradetonic_player_wrapper video { width: 100% !important; height: 100% !important; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; margin-top: 1rem; }
.toolbar .muted { margin-left: auto; }

/* SLDP control bar tweaks carried over from the old theme (colours: see playerStyle() in views.js) */
.sldp_cbar { display: block; padding: 15px !important; }
.sldp_btn { width: 25px !important; height: 25px !important; cursor: pointer; margin-right: 10px; font-size: 22px !important; }

/* ---- toast ---- */
.toast { position: fixed; left: 50%; bottom: 24px; translate: -50% 0; background: var(--surface-2); border: 1px solid var(--line); color: var(--text); padding: .7rem 1rem; border-radius: 10px; font-size: .9rem; box-shadow: 0 10px 30px rgba(0,0,0,.5); transition: opacity .4s, translate .4s; z-index: 50; }
.toast.error { border-color: rgba(217,48,93,.6); }
.toast.out { opacity: 0; translate: -50% 8px; }

/* ---- footer ---- */
.foot { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .5rem; padding: 1.2rem clamp(1rem, 4vw, 2.5rem); border-top: 1px solid var(--line); color: var(--muted); font-size: .8rem; }
.foot a { color: var(--muted); }

@media (max-width: 640px) {
  .toolbar .muted { margin-left: 0; width: 100%; }
  .player-frame { border-radius: 10px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* ---- admin ---- */
.colors { display: grid; gap: .9rem 1.2rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr)); }
.colors label { display: flex; align-items: center; gap: .7rem; font-size: .9rem; color: var(--text); font-weight: 500; }
.colors input[type="color"] { width: 46px; height: 34px; padding: 2px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); cursor: pointer; }
.colors small { display: block; color: var(--muted); font-weight: 400; font-size: .78rem; }
.admin-actions { display: flex; gap: .6rem; flex-wrap: wrap; }
.topnav { display: flex; align-items: center; gap: 1.2rem; }
.topnav a.link { text-decoration: none; }
.admin-list { display: grid; gap: 1rem; margin-bottom: 1rem; }
.admin-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem 1.4rem; scroll-margin-top: 1rem; }
.admin-card + .admin-card { margin-top: 0; }
.admin-card-head { display: flex; justify-content: space-between; align-items: start; gap: 1rem; margin-bottom: 1rem; }
.admin-card h2 { margin: 0; font-size: 1.15rem; letter-spacing: -.01em; }
.admin-card .muted a { color: var(--muted); }
.fields { display: grid; gap: .9rem 1.2rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr)); }
.fields label { display: grid; gap: .35rem; font-size: .82rem; color: var(--muted); font-weight: 600; }
.fields input { width: 100%; font: inherit; font-size: .95rem; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: .65rem .85rem; }
.fields input:focus { border-color: var(--accent); outline: none; }
.notice { background: rgba(34,197,94,.1); border: 1px solid rgba(34,197,94,.4); color: #b7f5cb; border-radius: 10px; padding: .6rem .9rem; margin: 0 0 1rem; }
.hero .muted { margin: .5rem 0 0; }
.code { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: .7rem 1rem; text-align: left; overflow-x: auto; }

/* ---- player notices (402/423/429/503, warn line) ---- */
.notice-overlay { position: absolute; inset: auto 0 0 0; margin: 0; padding: 1rem 1.2rem; background: rgba(0,0,0,.72); color: #f5f5f4; font-size: .95rem; text-align: center; z-index: 5; }
.warn-line { margin: .75rem 0 0; color: var(--warn); font-size: .88rem; }
.topnav button.link { padding: 0; }

/* ---- surround: colour around the picture (public/js/surround.js) ----
   Text tokens per surround meet WCAG AA 4.5:1 for small text (muted, warn), see docs/decisions.md P8. */
.gt-surround { display: inline-flex; align-items: center; gap: .4rem; margin: 0; }
.gt-surround-label { font-size: .8rem; color: var(--muted); margin-right: .15rem; }
.gt-swatch { width: 22px; height: 22px; padding: 0; border-radius: 50%; cursor: pointer; border: 1px solid rgba(128,128,128,.7); transition: transform .12s; }
.gt-swatch:hover { transform: scale(1.12); }
.gt-swatch[aria-pressed="true"] { outline: 2px solid var(--text); outline-offset: 2px; }
.gt-swatch:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
html[data-gt-surround] body { transition: background-color .2s, color .2s; }
html[data-gt-surround="psgrey"] { --bg: #282828; --surface: #303030; --surface-2: #3a3a3a; --line: #444; --muted: #a1a1a7; }
html[data-gt-surround="midgrey"] { --bg: #808080; --surface: #787878; --surface-2: #8c8c8c; --line: #939393; --muted: #141414; --text: #000; --warn: #000; color-scheme: light; }
html[data-gt-surround="white"] { --bg: #fff; --surface: #f3f3f3; --surface-2: #e8e8e8; --line: #d6d6d6; --muted: #555; --text: #111; --warn: #b45309; color-scheme: light; }
/* Keep the area around the picture pure: no dark frame on a grey or white surround. */
html[data-gt-surround]:not([data-gt-surround="black"]) .player-frame { background: transparent; border-color: transparent; }
@media (prefers-reduced-motion: reduce) { .gt-swatch, html[data-gt-surround] body { transition: none; } }

/* ---- forms and admin ---- */
.panel-wide { width: min(100%, 480px); text-align: left; }
.form .field { display: grid; gap: .35rem; font-size: .85rem; color: var(--muted); font-weight: 600; }
.form input[type="text"], .form input[type="email"], .form input[type="password"], .form input[type="number"], .form input[type="datetime-local"], .form select, .form textarea {
  width: 100%; font: inherit; font-size: .95rem; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: .65rem .85rem; }
.form input:focus, .form select:focus, .form textarea:focus { border-color: var(--accent); outline: none; }
.form .row { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; }
.adminnav { display: flex; flex-wrap: wrap; gap: 1rem; }
.adminnav a { color: var(--muted); text-decoration: none; font-size: .9rem; }
.adminnav a[aria-current="page"], .adminnav a:hover { color: var(--text); }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th, .table td { text-align: left; padding: .55rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { color: var(--muted); font-weight: 600; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: .4rem 1rem; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.badge { display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-size: .78rem; border: 1px solid var(--line); color: var(--muted); }
.badge.ok { color: var(--live); border-color: var(--live); }
.badge.warn { color: var(--warn); border-color: var(--warn); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85rem; }
.section { margin-top: 2rem; }
.section h2 { font-size: 1.15rem; margin: 0 0 .8rem; }
.colors { display: grid; gap: .9rem 1.2rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 140px), 1fr)); }
.form input[type="color"] { width: 56px; height: 36px; padding: 2px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.table-wrap { overflow-x: auto; }
