:root {
  --bg: #0c0b10;
  --surface: #16151d;
  --surface-2: #211f2a;
  --line: rgba(255, 255, 255, 0.09);
  --text: #f5f2ea;
  --muted: #a3a0ad;
  --accent: #ffc84a;
  --accent-ink: #1d1604;
  --danger: #ff7b6e;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html {
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
  overscroll-behavior: none;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(ellipse 90% 50% at 15% -10%, rgba(126, 87, 214, 0.22), transparent 70%),
    radial-gradient(ellipse 70% 40% at 100% 0%, rgba(255, 200, 74, 0.07), transparent 70%),
    var(--bg);
  background-attachment: fixed;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

body.locked { overflow: hidden; }

img { -webkit-user-drag: none; }
input { -webkit-user-select: text; user-select: text; }
button { font-family: inherit; cursor: pointer; }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 22px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
  font: 600 17px/1 var(--font);
  transition: transform 0.12s ease, background 0.12s ease;
}
.btn:active { transform: scale(0.96); }
.btn:disabled { opacity: 0.45; }
.btn.primary { background: var(--accent); border-color: transparent; color: var(--accent-ink); }
.btn.danger { color: var(--danger); border-color: rgba(255, 123, 110, 0.45); background: transparent; }
.btn.small { min-height: 40px; padding: 0 16px; font-size: 15px; }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }

/* ---------- Home ---------- */

.home {
  max-width: 1600px;
  margin: 0 auto;
  padding:
    calc(env(safe-area-inset-top) + 44px)
    max(36px, env(safe-area-inset-right))
    calc(env(safe-area-inset-bottom) + 56px)
    max(36px, env(safe-area-inset-left));
}

.masthead { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; margin-bottom: 36px; }
.masthead-text { min-width: 0; }

/* Small and quiet, so visitors aren't drawn to it; opens the PIN pad */
.admin-btn {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  margin-top: 6px;
  padding: 0 18px 0 14px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.05);
  color: var(--muted);
  font: 600 15px/1 var(--font);
  opacity: 0.75;
  transition: transform 0.12s ease, opacity 0.12s ease;
}
.admin-btn:active { transform: scale(0.95); opacity: 1; }
.admin-btn svg { width: 18px; height: 18px; fill: currentColor; }

.heading {
  display: inline-block;
  margin: 0;
  font-size: clamp(36px, 5.2vw, 64px);
  font-weight: 800;
  line-height: 1.02;
  letter-spacing: -0.035em;
}

.subheading {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: clamp(18px, 2.1vw, 24px);
  font-weight: 500;
  letter-spacing: -0.01em;
}

.grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 32px 24px;
}

.card {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  text-align: left;
}

.thumb {
  position: relative;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: 16px;
  background: var(--surface-2);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45), 0 0 0 1px var(--line);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.card:active .thumb { transform: scale(0.965); box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45), 0 0 0 3px var(--accent); }

.thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
/* Portrait films: whole frame over a blurred fill */
.thumb.portrait .thumb-fill { filter: blur(18px) brightness(0.6); transform: scale(1.3); }
.thumb.portrait .thumb-img { object-fit: contain; }

.thumb-none {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 44px;
  font-weight: 800;
  color: rgba(255, 255, 255, 0.5);
  background: linear-gradient(135deg, #2e1c4e, #14131b);
}

.play-badge {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 58px;
  height: 58px;
  margin: -29px 0 0 -29px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(10, 10, 14, 0.45);
  border: 1.5px solid rgba(255, 255, 255, 0.55);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}
.play-badge svg { width: 26px; height: 26px; margin-left: 3px; fill: #fff; }

.dur {
  position: absolute;
  right: 10px;
  bottom: 10px;
  padding: 4px 9px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.68);
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.meta { padding: 14px 4px 0; }
.student { display: block; font-size: 19px; font-weight: 700; letter-spacing: -0.01em; }
.title {
  display: -webkit-box;
  margin-top: 3px;
  color: var(--muted);
  font-size: 17px;
  line-height: 1.3;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.title:first-child { color: var(--text); font-size: 19px; font-weight: 700; margin-top: 0; }

.empty {
  max-width: 460px;
  margin: 12vh auto 0;
  padding: 40px 32px;
  text-align: center;
  border-radius: 24px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 18px;
}
.empty-title { margin: 0; color: var(--text); font-size: 26px; font-weight: 800; }
.empty .btn { margin-top: 12px; }

/* ---------- Player ---------- */

.player {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: #000;
  overflow: hidden;
}

.player video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}

.player-top,
.player-bottom,
.pick-bar {
  position: absolute;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 20px;
  padding-left: max(24px, env(safe-area-inset-left));
  padding-right: max(24px, env(safe-area-inset-right));
}

.player-top {
  top: 0;
  padding-top: calc(env(safe-area-inset-top) + 20px);
  padding-bottom: 48px;
  background: linear-gradient(rgba(0, 0, 0, 0.65), transparent);
  pointer-events: none;
}
.player-top > * { pointer-events: auto; }

.home-btn {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  height: 64px;
  padding: 0 30px 0 22px;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.95);
  color: #111;
  font: 700 21px/1 var(--font);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
  transition: transform 0.12s ease, opacity 0.3s ease;
}
.home-btn:active { transform: scale(0.95); }
.home-btn svg { width: 28px; height: 28px; fill: currentColor; }

.now-playing { min-width: 0; display: flex; flex-direction: column; gap: 3px; transition: opacity 0.3s ease; }
.now-student { font-size: 20px; font-weight: 700; }
.now-title { font-size: 17px; color: rgba(255, 255, 255, 0.75); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.now-student:empty { display: none; }

.big-play {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 116px;
  height: 116px;
  margin: -58px 0 0 -58px;
  display: none;
  place-items: center;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.7);
  background: rgba(0, 0, 0, 0.45);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}
.big-play svg { width: 54px; height: 54px; margin-left: 6px; fill: #fff; }
.player.paused .big-play { display: grid; }

.player-bottom {
  bottom: 0;
  padding-top: 56px;
  padding-bottom: calc(env(safe-area-inset-bottom) + 24px);
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.7));
  transition: opacity 0.3s ease;
}

.ctrl {
  flex: none;
  width: 56px;
  height: 56px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.16);
}
.ctrl svg { width: 28px; height: 28px; fill: #fff; }
.ctrl .i-play { display: none; margin-left: 3px; }
.player.paused .ctrl .i-play { display: block; }
.player.paused .ctrl .i-pause { display: none; }

.time { flex: none; min-width: 54px; font-size: 16px; font-weight: 600; font-variant-numeric: tabular-nums; text-align: center; }

.seek {
  --pct: 0%;
  flex: 1;
  min-width: 0;
  height: 44px;
  margin: 0;
  background: transparent;
  -webkit-appearance: none;
  appearance: none;
}
.seek::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(to right, var(--accent) var(--pct), rgba(255, 255, 255, 0.28) var(--pct));
}
.seek::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 26px;
  height: 26px;
  margin-top: -10px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}
.seek::-moz-range-track { height: 6px; border-radius: 3px; background: rgba(255, 255, 255, 0.28); }
.seek::-moz-range-progress { height: 6px; border-radius: 3px; background: var(--accent); }
.seek::-moz-range-thumb { width: 26px; height: 26px; border: 0; border-radius: 50%; background: #fff; }

/* Controls fade out while playing; the Home button never does */
.player.idle .player-bottom,
.player.idle .now-playing { opacity: 0; pointer-events: none; }
.player.idle .home-btn { opacity: 0.8; }

.ended {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 24px;
  text-align: center;
  background: rgba(8, 8, 12, 0.78);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}
.ended-title { margin: 0 0 18px; font-size: clamp(24px, 3.4vw, 36px); font-weight: 800; letter-spacing: -0.02em; }
.ended-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 14px; }
.ended .btn { min-height: 60px; padding: 0 30px; font-size: 20px; }
.countdown { margin: 18px 0 0; color: var(--muted); font-size: 16px; font-variant-numeric: tabular-nums; }

/* Choosing a thumbnail from the admin screen */
.player.picking .player-top,
.player.picking .big-play { display: none; }
.pick-bar {
  top: 0;
  justify-content: space-between;
  flex-wrap: wrap;
  padding-top: calc(env(safe-area-inset-top) + 18px);
  padding-bottom: 36px;
  background: linear-gradient(rgba(0, 0, 0, 0.75), transparent);
  font-size: 17px;
}
.pick-bar p { margin: 0; }
.pick-bar div { display: flex; gap: 12px; }

/* ---------- Admin ---------- */

.admin {
  position: fixed;
  inset: 0;
  z-index: 10;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  background: var(--bg);
}

.admin-bar {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding:
    calc(env(safe-area-inset-top) + 14px)
    max(24px, env(safe-area-inset-right))
    14px
    max(24px, env(safe-area-inset-left));
  background: rgba(12, 11, 16, 0.88);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.admin-bar h2 { margin: 0; font-size: 24px; letter-spacing: -0.02em; }

.admin-body {
  max-width: 920px;
  margin: 0 auto;
  padding: 24px max(20px, env(safe-area-inset-right)) calc(env(safe-area-inset-bottom) + 64px) max(20px, env(safe-area-inset-left));
}

.panel {
  margin-bottom: 18px;
  padding: 22px 24px;
  border-radius: 20px;
  background: var(--surface);
  border: 1px solid var(--line);
}
.panel h3 { margin: 0 0 14px; font-size: 20px; letter-spacing: -0.01em; }
.panel-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 4px; }
.panel-head h3 { margin: 0; }
.panel-actions { display: flex; gap: 10px; }
.count { color: var(--muted); font-weight: 600; }

.help { margin: 8px 0 14px; color: var(--muted); font-size: 15px; line-height: 1.5; }
.help:empty { display: none; }

.notice {
  margin: 0 0 18px;
  padding: 16px 18px;
  border-radius: 16px;
  background: rgba(255, 200, 74, 0.1);
  border: 1px solid rgba(255, 200, 74, 0.45);
  font-size: 16px;
  line-height: 1.5;
}

.field { display: block; margin-bottom: 14px; color: var(--muted); font-size: 14px; font-weight: 600; }
.field:last-child { margin-bottom: 0; }

input[type="text"],
input[type="password"] {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  font: 400 17px/1.3 var(--font); /* 16px+ stops iOS zooming on focus */
}
input[type="text"]:focus,
input[type="password"]:focus { outline: none; border-color: var(--accent); }

.row-inline { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.row-inline input { flex: 1 1 160px; width: auto; margin: 0; }

.import-log { list-style: none; margin: 0 0 8px; padding: 0; font-size: 15px; }
.import-log li { padding: 8px 12px; margin-bottom: 6px; border-radius: 10px; background: var(--surface-2); }
.import-log li.ok { color: #9be3a8; }
.import-log li.err { color: var(--danger); }

.admin-list { list-style: none; margin: 0; padding: 0; }
.admin-item {
  display: grid;
  grid-template-columns: 160px 1fr auto;
  gap: 18px;
  align-items: center;
  padding: 16px 0;
  border-top: 1px solid var(--line);
}
.admin-item .thumb { border-radius: 12px; box-shadow: none; }
.admin-item .fields input { margin: 0 0 8px; padding: 10px 12px; }
.admin-item .info { color: var(--muted); font-size: 14px; }
.admin-item .info.warn { margin-top: 4px; color: var(--accent); }
.admin-item .actions { display: grid; grid-template-columns: 48px 48px; gap: 8px; }
.admin-item .actions .btn { min-height: 44px; padding: 0 12px; font-size: 15px; }
.admin-item .actions .wide { grid-column: span 2; }
.icon-btn { padding: 0 !important; font-size: 20px !important; }

@media (max-width: 720px) {
  .admin-item { grid-template-columns: 120px 1fr; }
  .admin-item .actions { grid-column: 1 / -1; display: flex; flex-wrap: wrap; }
  .admin-item .actions .btn { flex: 1 1 auto; }
}

.steps { margin: 0; padding-left: 22px; font-size: 16px; line-height: 1.55; }
.steps li { margin-bottom: 8px; }

/* PIN pad: big keys, no on-screen keyboard */
.pin-dialog {
  width: min(380px, calc(100vw - 32px));
  padding: 28px 28px 22px;
  border-radius: 26px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  text-align: center;
}
.pin-dialog::backdrop { background: rgba(0, 0, 0, 0.7); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); }
.pin-dialog.shake { animation: shake 0.4s ease; }
@keyframes shake {
  20%, 60% { transform: translateX(-10px); }
  40%, 80% { transform: translateX(10px); }
}
.pin-prompt { margin: 0; font-size: 21px; font-weight: 700; letter-spacing: -0.01em; }
.pin-prompt:focus { outline: none; }
.pin-dots { display: flex; justify-content: center; gap: 14px; height: 16px; margin: 20px 0 10px; }
.pin-dots span { width: 16px; height: 16px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.45); }
.pin-dots span.on { background: var(--text); border-color: var(--text); }
.pin-msg { min-height: 42px; margin: 0 0 8px; color: var(--muted); font-size: 15px; line-height: 1.4; }
.pin-msg.bad { color: var(--danger); }
.pin-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.pin-pad button {
  height: 68px;
  border: 0;
  border-radius: 18px;
  background: var(--surface-2);
  color: var(--text);
  font: 600 28px/1 var(--font);
  font-variant-numeric: tabular-nums;
  transition: transform 0.08s ease, background 0.08s ease;
}
.pin-pad button:active { transform: scale(0.94); background: rgba(255, 255, 255, 0.16); }
.pin-pad button:disabled { opacity: 0.35; }
.pin-pad .pin-fn { background: transparent; font-size: 19px; }
.pin-pad .pin-fn svg { width: 30px; height: 30px; fill: currentColor; vertical-align: middle; }
.pin-pad .pin-ok { background: var(--accent); color: var(--accent-ink); }
.pin-pad .pin-ok:disabled { background: var(--surface-2); color: var(--muted); }
.pin-pad .gone { visibility: hidden; }
.pin-cancel { width: 100%; margin-top: 16px; }

/* Off-screen video used to read duration and grab thumbnails while importing */
.probe { position: fixed; left: 0; top: 0; width: 160px; height: 90px; opacity: 0.01; pointer-events: none; z-index: -1; }
