/* ============================================================
   ImageMatch — clinical UI theme
   Image-first layout. Sidebars are collapsible. Submit form
   docked to the bottom. Top bar is slim.
   ============================================================ */

:root {
  --accent: #0d9488;            /* teal — matches the website */
  --accent-dark: #0f766e;
  --accent-soft: #d5f5f0;
  --accent-rgb: 13,148,136;
  --grad: linear-gradient(135deg, #0d9488, #0891b2);

  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e3e6ea;
  --border-strong: #cfd4dc;

  --text: #1d1d1f;
  --text-muted: #55606e;
  --text-faint: #8a929e;

  --success: #0d9488;
  --warning: #d97706;
  --danger: #dc2626;

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08);

  --radius: 10px;
  --radius-sm: 7px;

  --header-h: 48px;
  --footer-h: 72px;
  --sidebar-w: 280px;
  --sidebar-collapsed-w: 44px;

  --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text",
          "Segoe UI", "Inter", Roboto, Helvetica, Arial, sans-serif;
}

/* Dark mode — the 2D app defaults to light (a clinical light-table look); this
   is the opt-in dark variant. The image stage keeps its neutral checker. */
html[data-theme="dark"] {
  --bg: #0e141c;
  --surface: #161f2b;
  --surface-2: #1e2937;
  --border: #263241;
  --border-strong: #3a4759;
  --text: #e8edf2;
  --text-muted: #9aa7b5;
  --text-faint: #6b7888;
  --accent-soft: rgba(13,148,136,0.20);
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.4);
  --shadow-md: 0 4px 14px rgba(0,0,0,0.5);
}
/* In dark mode the image "light table" checker becomes a dark grey checker —
   still shows PNG transparency, but easy on the eyes and consistent with the
   dark viewer. */
html[data-theme="dark"] .image-wrapper {
  background:
    linear-gradient(45deg, #1b2431 25%, transparent 25%),
    linear-gradient(-45deg, #1b2431 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #1b2431 75%),
    linear-gradient(-45deg, transparent 75%, #1b2431 75%);
  background-size: 24px 24px;
  background-position: 0 0, 0 12px, 12px -12px, -12px 0px;
  background-color: #10151d;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
}

button {
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  transition: background 120ms ease, border-color 120ms ease, transform 60ms ease;
}
button:hover { background: var(--surface-2); border-color: var(--text-muted); }
button:active { transform: translateY(1px); }
button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
button.primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
button.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
  padding: 5px 8px;
}
button.ghost:hover { color: var(--text); background: var(--surface-2); }

input[type="text"], input[type="number"], input[type="date"], select {
  font-family: inherit;
  font-size: 13px;
  padding: 6px 9px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
input:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.12);
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
  margin: 6px 0;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px var(--border-strong);
}
input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px var(--border-strong);
}

/* ============================================================
   App shell — header + main + footer, sidebars inside main
   ============================================================ */

.main-container {
  display: grid;
  grid-template-rows: var(--header-h) 1fr auto;
  height: 100vh;
  width: 100vw;
  background: var(--bg);
  transition: width 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}
/* When the live game panel is open, shrink the workspace so the panel never
   covers the submit button or the right stereo controls. */
body.game-panel-open .main-container {
  width: calc(100vw - 340px);
}
@media (max-width: 600px) {
  body.game-panel-open .main-container { width: 100vw; }
}

/* ---- Top bar ---- */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  z-index: 30;
}
.topbar .brand {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.2px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}
.topbar .brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
}
.topbar .brand-rt {
  display: inline-block;
  margin-left: 4px;
  padding: 1px 6px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 1px;
  color: #fff;
  background: var(--grad);
  border-radius: 5px;
  vertical-align: middle;
}
.topbar .topbar-group { display: flex; align-items: center; gap: 8px; }
.topbar label { font-size: 12px; color: var(--text-muted); font-weight: 500; }
.topbar .spacer { flex: 1; }
.topbar a {
  font-size: 13px;
  color: var(--text-muted);
  text-decoration: none;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
}
.topbar a:hover { background: var(--surface-2); color: var(--text); }

/* ---- Main work area: sidebar | canvas | (optional) sidebar ---- */
.workspace {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 0;
  position: relative;
  background: var(--bg);
}
.workspace.stereo {
  grid-template-columns: var(--sidebar-w) 1fr var(--sidebar-w);
}
.workspace.sidebar-collapsed {
  grid-template-columns: var(--sidebar-collapsed-w) 1fr;
}
.workspace.stereo.sidebar-collapsed {
  grid-template-columns: var(--sidebar-collapsed-w) 1fr var(--sidebar-w);
}
.workspace.stereo.right-collapsed {
  grid-template-columns: var(--sidebar-w) 1fr var(--sidebar-collapsed-w);
}
.workspace.stereo.sidebar-collapsed.right-collapsed {
  grid-template-columns: var(--sidebar-collapsed-w) 1fr var(--sidebar-collapsed-w);
}

/* ---- Sidebars ---- */
.menu, .right-menu {
  background: var(--surface);
  border-right: 1px solid var(--border);
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
  transition: padding 180ms ease;
}
.right-menu { border-right: none; border-left: 1px solid var(--border); }

.menu-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  position: sticky;
  top: 0;
  z-index: 5;
}
.menu-header h3 {
  margin: 0;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--text-muted);
}
.collapse-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  line-height: 1;
}
.collapse-btn:hover { background: var(--surface); color: var(--text); }

.menu-body { padding: 12px; flex: 1; }

.control-group {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 10px;
}
.control-group h4 {
  margin: 0 0 8px 0;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
}
.control-group label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin: 8px 0 2px 0;
}
.control-group label:first-of-type { margin-top: 0; }

.control-group .stat {
  font-size: 12px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 8px;
  margin-top: 6px;
  font-variant-numeric: tabular-nums;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
}

.control-group .hint {
  font-size: 10px;
  color: var(--text-faint);
  margin-top: 6px;
  text-align: center;
  letter-spacing: 0.2px;
  line-height: 1.4;
}

/* Zoom controls — the upgraded interface */
.zoom-row {
  display: grid;
  grid-template-columns: 32px 1fr 32px;
  gap: 6px;
  align-items: center;
}
.zoom-row button {
  padding: 4px 0;
  font-weight: 700;
  font-size: 14px;
  line-height: 1;
}
.zoom-readout-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
  gap: 6px;
}
.zoom-readout {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px 8px;
  flex: 1;
  text-align: center;
}
.zoom-readout-row button { font-size: 11px; padding: 5px 8px; }

.button-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.button-row button { width: 100%; }

/* Collapsed sidebar — show only chevron rail */
.workspace.sidebar-collapsed .menu .menu-body,
.workspace.sidebar-collapsed .menu .menu-header h3 {
  display: none;
}
.workspace.right-collapsed .right-menu .menu-body,
.workspace.right-collapsed .right-menu .menu-header h3 {
  display: none;
}

/* ---- Image wrapper / canvas ---- */
.image-wrapper {
  display: flex;
  position: relative;
  background:
    linear-gradient(45deg, #e9eef3 25%, transparent 25%),
    linear-gradient(-45deg, #e9eef3 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e9eef3 75%),
    linear-gradient(-45deg, transparent 75%, #e9eef3 75%);
  background-size: 24px 24px;
  background-position: 0 0, 0 12px, 12px -12px, -12px 0px;
  background-color: #dfe5eb;
  overflow: hidden;
}

.left-image-section, .right-image-section {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  min-width: 0;
}

.image-container {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

#baseImage, #overlayImage, #SSbaseImageR, #SSoverlayImageR {
  max-width: 100%;
  max-height: 100%;
  user-select: none;
  -webkit-user-drag: none;
}
#overlayImage, #SSoverlayImageR {
  position: absolute;
  top: 0;
  left: 0;
  cursor: move;
  opacity: 0.5;
}

/* Status pill in the bottom-left of each canvas */
.canvas-status {
  position: absolute;
  left: 12px;
  bottom: 12px;
  background: rgba(15, 23, 42, 0.78);
  color: #fff;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12px;
  pointer-events: none;
  backdrop-filter: blur(4px);
  z-index: 5;
}
.canvas-status .label {
  color: rgba(255, 255, 255, 0.65);
  margin-right: 6px;
  font-family: var(--font);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.cross-section-point {
  position: absolute;
  width: 12px;
  height: 12px;
  background: var(--accent);
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 1px var(--accent), 0 2px 6px rgba(0,0,0,0.3);
  cursor: move;
  z-index: 20;
  display: none;
  transform: translate(-50%, -50%);
}

.indicator {
  position: absolute;
  width: 8px;
  height: 8px;
  background: var(--accent);
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 1px var(--accent);
  bottom: -16px;
  left: 50%;
  transform: translateX(-50%);
  display: none;
}

.viewfinder-container {
  position: absolute;
  border: 2px solid var(--accent);
  background: transparent;
  z-index: 10;
  cursor: move;
  display: none;
  box-sizing: border-box;
}
.viewfinder-container::after {
  content: "";
  position: absolute;
  right: 0;
  bottom: 0;
  width: 10px;
  height: 10px;
  background: var(--accent);
  cursor: nwse-resize;
}
#viewfinderContainerR { border-color: var(--success); }
#viewfinderContainerR::after { background: var(--success); }

.middle-border {
  position: absolute;
  width: 1px;
  height: 100%;
  background: var(--border-strong);
  left: 50%;
  transform: translateX(-50%);
  display: none;
  z-index: 6;
}

/* ---- Bottom dock with submit form ---- */
.bottom-dock {
  background: var(--surface);
  border-top: 1px solid var(--border);
  box-shadow: 0 -1px 6px rgba(15, 23, 42, 0.04);
  padding: 12px 16px;
  z-index: 20;
}
#submitForm {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
#submitForm .field {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
#submitForm .field label {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
#submitForm .field input { width: 180px; }
#submitForm .checkbox-row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
#submitForm .checkbox-row label {
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
}
#submitForm .checkbox-row input[type="checkbox"] {
  width: 16px; height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}
#submitForm .spacer { flex: 1; }
#submitForm button[type="submit"] {
  background: var(--accent);
  color: #fff;
  border: 1px solid var(--accent);
  font-weight: 600;
  padding: 9px 18px;
}
#submitForm button[type="submit"]:hover {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
}
#leaderboardButton {
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
}

/* Toast notification */
.toast {
  position: fixed;
  top: 64px;
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  padding: 10px 16px;
  box-shadow: var(--shadow-md);
  font-size: 13px;
  color: var(--text);
  z-index: 100;
  max-width: 420px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease, transform 200ms ease;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }

/* Scrollbar polish */
.menu::-webkit-scrollbar, .right-menu::-webkit-scrollbar { width: 8px; }
.menu::-webkit-scrollbar-thumb, .right-menu::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 4px;
}
.menu::-webkit-scrollbar-track, .right-menu::-webkit-scrollbar-track { background: transparent; }

/* Responsive — collapse sidebars automatically on narrow screens */
@media (max-width: 900px) {
  :root { --sidebar-w: 240px; }
  #submitForm .field input { width: 140px; }
}

/* ============================================================
   Image-set dropdown — disabled options (unavailable image sets)
   ============================================================ */
#imageSet option:disabled {
  color: var(--text-faint);
  font-style: italic;
}
#imageSet optgroup {
  font-weight: 700;
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
#imageSet optgroup option {
  font-weight: 400;
  font-style: normal;
  font-size: 13px;
  color: var(--text);
  text-transform: none;
  letter-spacing: normal;
  padding-left: 8px;
}

/* ============================================================
   Previous Attempts panel
   ============================================================ */
.prev-attempts .empty {
  font-size: 12px;
  color: var(--text-faint);
  font-style: italic;
  padding: 4px 0;
}
.prev-attempts .stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0;
  font-size: 12px;
}
.prev-attempts .stat-row span {
  color: var(--text-muted);
  text-transform: uppercase;
  font-size: 10px;
  letter-spacing: 0.6px;
  font-weight: 600;
}
.prev-attempts .stat-row strong {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 13px;
  color: var(--text);
}
.prev-attempts .stat-row strong.best {
  color: var(--accent);
}
.prev-attempts .divider {
  height: 1px;
  background: var(--border);
  margin: 8px 0;
}
.prev-attempts .attempt-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.prev-attempts .attempt {
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 8px;
  font-size: 11px;
}
.prev-attempts .attempt-line {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}
.prev-attempts .attempt .shifts {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  color: var(--text);
  font-weight: 600;
  font-size: 11px;
}
.prev-attempts .attempt .error {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  color: var(--text-muted);
  font-size: 10px;
}
.prev-attempts .attempt .date {
  color: var(--text-faint);
  font-size: 10px;
}
.prev-attempts .attempts-cap {
  font-size: 10px;
  color: var(--warning);
  text-align: center;
  margin-top: 6px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ============================================================
   Zoom-lock checkbox (visible only in stereo mode)
   ============================================================ */
.zoom-lock {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
}
.zoom-lock input[type="checkbox"] {
  width: 14px;
  height: 14px;
  accent-color: var(--accent);
  margin: 0;
  cursor: pointer;
}

/* ============================================================
   Toggle-button "active" state — used by the red-tint toggle
   ============================================================ */
button.active,
button.active:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* ============================================================
   Auth modal — login / register, shown until session confirmed
   ============================================================ */
.auth-modal {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(1200px 600px at 15% -10%, rgba(22,163,74,0.18), transparent 60%),
    radial-gradient(1000px 500px at 110% 110%, rgba(var(--accent-rgb),0.14), transparent 55%),
    linear-gradient(135deg, #1b2430 0%, #0f1620 100%);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 20px;
}

.auth-card {
  width: 100%;
  max-width: 440px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 24px 70px rgba(0,0,0,0.4);
  padding: 0 0 24px 0;
  overflow: hidden;
  animation: auth-card-in 0.4s cubic-bezier(0.18, 0.89, 0.32, 1.15);
}
@keyframes auth-card-in {
  from { opacity: 0; transform: translateY(16px) scale(0.97); }
  to   { opacity: 1; transform: none; }
}

.auth-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 22px;
  padding: 26px 26px 22px 26px;
  background: linear-gradient(135deg, #0d9488 0%, #0891b2 55%, #0e7490 100%);
  color: #fff;
}
.auth-brand { display: flex; align-items: center; gap: 14px; }
.auth-logo {
  font-size: 38px;
  line-height: 1;
  filter: drop-shadow(0 2px 6px rgba(0,0,0,0.25));
}
.auth-brand-text h2 {
  margin: 0;
  font-size: 24px;
  font-weight: 800;
  letter-spacing: 0.3px;
  color: #fff;
}
.auth-brand-text h2 .brand-rt {
  display: inline-block;
  margin-left: 5px;
  padding: 1px 7px;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 1px;
  vertical-align: middle;
  background: rgba(255,255,255,0.22);
  border-radius: 6px;
}
.auth-tagline {
  margin: 3px 0 0 0;
  font-size: 12px;
  color: rgba(255,255,255,0.85);
  font-weight: 500;
}
.auth-header h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.2px;
}

.auth-tabs {
  display: flex;
  gap: 0;
  margin: 0 26px 18px 26px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.auth-tab {
  flex: 1;
  padding: 10px 12px;
  background: var(--surface-2);
  border: none;
  border-right: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.auth-tab:last-child { border-right: none; }
.auth-tab:hover { color: var(--text); }
.auth-tab.active {
  background: #0d9488;
  color: #fff;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 0 26px;
}
.auth-form.hidden { display: none; }
.auth-form .field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.auth-form .field label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
  color: var(--text-muted);
}
.auth-form .field input,
.auth-form .field select {
  width: 100%;
  padding: 8px 10px;
  font-size: 13px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
}
.auth-form .field input:focus,
.auth-form .field select:focus {
  outline: none;
  border-color: #0d9488;
  box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.15);
}
.auth-form .field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.auth-form button.primary {
  margin-top: 8px;
  padding: 12px 14px;
  background: var(--grad);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.3px;
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s, filter 0.12s;
  box-shadow: 0 3px 10px rgba(22, 163, 74, 0.3);
}
.auth-form button.primary:hover { filter: brightness(1.06); transform: translateY(-1px); box-shadow: 0 5px 16px rgba(22, 163, 74, 0.4); }
.auth-form button.primary:active { transform: translateY(0); }

.auth-error {
  min-height: 16px;
  font-size: 12px;
  color: var(--danger, #b91c1c);
  margin-top: 2px;
}
.auth-error:empty { min-height: 0; margin: 0; }
.auth-success {
  font-size: 12px;
  color: var(--success, #065f46);
  background: #d1fae5;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid #a7f3d0;
}
.auth-note {
  font-size: 11px;
  color: var(--text-faint);
  text-align: center;
  margin-top: 4px;
}
.hidden { display: none !important; }

/* ============================================================
   Topbar — logged-in user info & logout
   ============================================================ */
.topbar-user {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-right: 4px;
}
.topbar-user #topbarUserName {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
}
.topbar-user #topbarUserOrg {
  font-size: 11px;
  color: var(--text-muted);
  max-width: 160px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-user #logoutBtn {
  padding: 4px 10px;
  font-size: 11px;
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.topbar-user #logoutBtn:hover {
  background: var(--surface-2);
  color: var(--text);
}

/* Bottom-dock "Submitting as" label that replaces the old name/student inputs */
.submitting-as {
  font-size: 13px;
  color: var(--text-muted);
  padding: 4px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.submitting-as strong {
  color: var(--text);
  font-weight: 600;
  margin-left: 4px;
}

/* ============================================================
   GAME MODE
   ============================================================ */

/* Topbar toggle button */
.game-mode-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  margin-right: 10px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.3px;
  color: #fff;
  background: var(--grad);
  border: none;
  border-radius: 20px;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(var(--accent-rgb), 0.3);
  transition: transform 0.12s, box-shadow 0.12s;
}
.game-mode-btn:hover { transform: translateY(-1px); box-shadow: 0 4px 14px rgba(var(--accent-rgb), 0.42); }
.game-mode-btn:active { transform: translateY(0); }

/* Sliding right-hand live leaderboard panel */
.game-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 340px;
  max-width: 88vw;
  height: 100vh;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: -8px 0 30px rgba(0, 0, 0, 0.12);
  transform: translateX(100%);
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 800;
  display: flex;
  flex-direction: column;
}
.game-panel.open { transform: translateX(0); }

.game-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  background: linear-gradient(135deg, #1f2937, #374151);
  color: #fff;
}
.game-panel-title { display: flex; align-items: center; gap: 8px; font-size: 15px; font-weight: 700; }
.game-trophy { font-size: 18px; }
.game-panel-close {
  background: transparent; border: none; color: #fff; font-size: 24px;
  line-height: 1; cursor: pointer; opacity: 0.8; padding: 0 4px;
}
.game-panel-close:hover { opacity: 1; }

.game-status-bar {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  text-align: center;
  background: var(--surface-2);
}
.game-timer {
  font-size: 36px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  letter-spacing: 1px;
  line-height: 1;
}
.game-timer.urgent { color: var(--danger); animation: timer-pulse 1s infinite; }
@keyframes timer-pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.45; } }
.game-status-text { font-size: 11px; color: var(--text-muted); margin-top: 6px; }

.game-sets-row {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
}
.game-set-chip {
  min-width: 30px; padding: 5px 9px;
  font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums;
  background: var(--surface); color: var(--accent);
  border: 1.5px solid var(--accent); border-radius: 7px; cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
.game-set-chip:hover { background: var(--accent); color: #fff; }

.game-leaderboard { flex: 1; overflow-y: auto; padding: 10px 14px; }
.game-empty { color: var(--text-faint); font-size: 13px; text-align: center; padding: 28px 16px; line-height: 1.5; }

.game-lb-head, .game-lb-row {
  display: grid;
  grid-template-columns: 38px 1fr 56px 46px;
  align-items: center;
  gap: 4px;
  padding: 8px 8px;
}
.game-lb-head {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--text-muted); font-weight: 700; border-bottom: 1px solid var(--border);
}
.game-lb-head span:nth-child(3), .game-lb-head span:nth-child(4) { text-align: right; }
.game-lb-row {
  border-radius: 8px;
  font-size: 13px;
  transition: background 0.15s;
  animation: lb-in 0.3s ease;
}
@keyframes lb-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.game-lb-row:nth-child(even) { background: var(--surface-2); }
.game-lb-row.me { background: #fff4f1; box-shadow: inset 0 0 0 1.5px var(--accent); }
.game-lb-rank { font-size: 15px; font-weight: 800; text-align: center; }
.game-lb-name { font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.game-lb-perfects { color: var(--warning); font-size: 11px; font-weight: 700; }
.game-lb-score { text-align: right; font-weight: 800; color: var(--accent); font-variant-numeric: tabular-nums; }
.game-lb-sets { text-align: right; font-size: 11px; color: var(--text-muted); font-variant-numeric: tabular-nums; }

.game-host-controls {
  padding: 14px 18px; border-top: 1px solid var(--border);
  display: flex; gap: 8px; background: var(--surface-2);
}
.game-host-btn {
  flex: 1; padding: 10px; font-size: 13px; font-weight: 700;
  border-radius: 8px; cursor: pointer; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text);
}
.game-host-btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.game-host-btn.danger { background: var(--danger); color: #fff; border-color: var(--danger); }

/* Host setup modal */
.game-host-modal {
  position: fixed; inset: 0; z-index: 950;
  background: rgba(20, 22, 26, 0.55);
  backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px);
  display: none; align-items: center; justify-content: center; padding: 20px;
}
.game-host-modal.open { display: flex; }
.game-host-card {
  width: 100%; max-width: 480px; max-height: 86vh; overflow-y: auto;
  background: var(--surface); border-radius: var(--radius);
  border: 1px solid var(--border); box-shadow: 0 18px 50px rgba(0,0,0,0.2);
  padding: 24px;
}
.game-host-card h2 { margin: 0 0 6px; font-size: 19px; color: var(--text); }
.game-host-sub { margin: 0 0 18px; font-size: 12px; color: var(--text-muted); line-height: 1.5; }
.game-host-card .field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 16px; }
.game-host-card .field > label {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px;
  font-weight: 700; color: var(--text-muted);
}
.game-host-card .field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.game-host-card select {
  padding: 8px 10px; font-size: 13px; border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); background: var(--surface); color: var(--text);
}

.game-set-picker {
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 12px; max-height: 220px; overflow-y: auto; background: var(--surface-2);
}
.picker-group-label {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.6px;
  font-weight: 700; color: var(--text-muted); margin: 4px 0 8px;
}
.picker-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.picker-chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 8px; font-size: 12px; font-variant-numeric: tabular-nums;
  border: 1px solid var(--border-strong); border-radius: 6px;
  background: var(--surface); cursor: pointer; user-select: none;
}
.picker-chip input { margin: 0; }
.game-set-picker-actions { display: flex; gap: 14px; margin-top: 8px; }
.link-btn {
  background: none; border: none; color: var(--accent); cursor: pointer;
  font-size: 12px; font-weight: 600; padding: 0; text-decoration: underline;
}
.game-host-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; }
.game-host-actions .ghost {
  padding: 9px 16px; border: 1px solid var(--border-strong); background: var(--surface);
  color: var(--text); border-radius: var(--radius-sm); cursor: pointer; font-size: 13px; font-weight: 600;
}
.game-host-actions .primary {
  padding: 9px 18px; border: 1px solid var(--accent); background: var(--accent);
  color: #fff; border-radius: var(--radius-sm); cursor: pointer; font-size: 13px; font-weight: 700;
}

/* ============================================================
   SPLASH FEEDBACK
   ============================================================ */
.splash-overlay {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none; opacity: 0;
}
.splash-overlay.show { animation: splash-fade 0.3s ease forwards; }
@keyframes splash-fade { from { opacity: 0; } to { opacity: 1; } }
.splash-content { text-align: center; transform: scale(0.5); }
.splash-overlay.show .splash-content { animation: splash-pop 0.5s cubic-bezier(0.18, 0.89, 0.32, 1.28) forwards; }
@keyframes splash-pop { 0% { transform: scale(0.4); opacity: 0; } 60% { transform: scale(1.15); opacity: 1; } 100% { transform: scale(1); opacity: 1; } }

.splash-tier {
  font-size: clamp(40px, 9vw, 96px);
  font-weight: 900;
  letter-spacing: 2px;
  text-transform: uppercase;
  line-height: 1;
  text-shadow: 0 4px 24px rgba(0,0,0,0.25);
}
.splash-tier.tier-perfect {
  background: linear-gradient(135deg, #5eead4, #0891b2, #0d9488);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 4px 18px rgba(255, 90, 54, 0.5));
}
.splash-tier.tier-excellent { color: #06d6a0; }
.splash-tier.tier-great { color: #118ab2; }
.splash-tier.tier-good { color: #5b6573; }
.splash-tier.tier-ok { color: #94a3b8; font-size: clamp(30px, 6vw, 60px); }

.splash-combo {
  margin-top: 10px;
  font-size: clamp(20px, 4vw, 38px);
  font-weight: 800;
  letter-spacing: 3px;
  color: #ffd166;
  text-shadow: 0 2px 14px rgba(255, 209, 102, 0.6);
  animation: combo-shake 0.4s ease;
}
@keyframes combo-shake { 0%,100% { transform: rotate(0); } 25% { transform: rotate(-3deg); } 75% { transform: rotate(3deg); } }

.splash-stats {
  margin-top: 16px;
  display: flex; gap: 18px; justify-content: center; align-items: baseline;
}
.splash-score {
  font-size: clamp(22px, 4vw, 34px); font-weight: 800; color: var(--text);
  background: rgba(255,255,255,0.85); padding: 4px 16px; border-radius: 20px;
  font-variant-numeric: tabular-nums;
}
.splash-err {
  font-size: clamp(13px, 2vw, 17px); color: var(--text-muted); font-weight: 600;
  background: rgba(255,255,255,0.7); padding: 3px 12px; border-radius: 14px;
  font-variant-numeric: tabular-nums;
}

/* Confetti */
.confetti-piece {
  position: fixed; top: -20px; z-index: 1001; pointer-events: none;
  border-radius: 1px;
  animation-name: confetti-fall; animation-timing-function: linear; animation-fill-mode: forwards;
}
@keyframes confetti-fall {
  0% { transform: translateY(0) rotate(0deg); opacity: 1; }
  100% { transform: translateY(105vh) rotate(720deg); opacity: 0.9; }
}

@media (max-width: 600px) {
  .game-panel { width: 100vw; max-width: 100vw; }
}

/* ============================================================
   HELP BUTTON + MODAL
   ============================================================ */
.help-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  margin-right: 8px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 20px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
.help-btn:hover { background: var(--surface-2); border-color: #0d9488; color: #0891b2; }

.help-modal {
  position: fixed;
  inset: 0;
  z-index: 960;
  background: rgba(15, 22, 32, 0.6);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.help-modal.open { display: flex; }

.help-card {
  width: 100%;
  max-width: 620px;
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-radius: 14px;
  box-shadow: 0 24px 70px rgba(0,0,0,0.35);
  overflow: hidden;
  animation: auth-card-in 0.35s cubic-bezier(0.18, 0.89, 0.32, 1.12);
}

.help-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  background: linear-gradient(135deg, #0d9488 0%, #0891b2 55%, #0e7490 100%);
  color: #fff;
  flex-shrink: 0;
}
.help-header h2 { margin: 0; font-size: 19px; font-weight: 800; letter-spacing: 0.2px; color: #fff; }
.help-header h2 .brand-rt {
  display: inline-block; margin-left: 5px; padding: 1px 6px; font-size: 12px;
  font-weight: 800; letter-spacing: 1px; vertical-align: middle;
  background: rgba(255,255,255,0.22); border-radius: 5px;
}
.help-close {
  background: transparent; border: none; color: #fff; font-size: 26px;
  line-height: 1; cursor: pointer; opacity: 0.85; padding: 0 4px;
}
.help-close:hover { opacity: 1; }

.help-body {
  padding: 22px 24px 24px;
  overflow-y: auto;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
}
.help-intro { margin: 0 0 18px; color: var(--text-muted); }
.help-body h3 {
  margin: 20px 0 8px;
  font-size: 14px;
  font-weight: 700;
  color: #0891b2;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.help-body ol, .help-body ul { margin: 0 0 4px; padding-left: 22px; }
.help-body li { margin-bottom: 7px; }
.help-body strong { color: var(--text); font-weight: 700; }

.help-contact {
  margin-top: 24px;
  padding: 18px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-align: center;
}
.help-contact p { margin: 0 0 12px; font-size: 14px; color: var(--text-muted); }
.help-contact-btn {
  padding: 11px 22px;
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  background: var(--grad);
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  box-shadow: 0 3px 10px rgba(22, 163, 74, 0.3);
  transition: transform 0.12s, box-shadow 0.12s, filter 0.12s;
}
.help-contact-btn:hover { filter: brightness(1.06); transform: translateY(-1px); box-shadow: 0 5px 16px rgba(22, 163, 74, 0.4); }
.help-contact-btn:active { transform: translateY(0); }

@media (max-width: 600px) {
  .help-btn { padding: 6px 9px; }
  .help-card { max-height: 90vh; }
}

/* ============================================================
   Responsive layout — tablet & phone (mobile-friendly build)
   Stacks the control sidebars beneath the image, lets the page
   scroll, and enlarges touch targets. Overlay drag works by touch
   (see script.js); the fine nudge controls stay the precise input.
   ============================================================ */
@media (max-width: 820px) {
  html, body { height: auto; overflow-y: auto; overflow-x: hidden; }
  .main-container { height: auto; min-height: 100vh; grid-template-rows: auto 1fr auto; }
  body.game-panel-open .main-container { width: 100vw; }

  /* Top bar wraps so every control stays reachable */
  .topbar { flex-wrap: wrap; height: auto; padding: 8px 12px; gap: 8px 10px; }
  .topbar .spacer { display: none; }
  .topbar .topbar-group { flex-wrap: wrap; }

  /* Single column: image on top, control menu(s) beneath, full width */
  .workspace,
  .workspace.stereo,
  .workspace.sidebar-collapsed,
  .workspace.stereo.sidebar-collapsed,
  .workspace.stereo.right-collapsed,
  .workspace.stereo.sidebar-collapsed.right-collapsed {
    grid-template-columns: 1fr;
  }
  .image-wrapper { order: -1; min-height: 52vh; }
  .menu, .right-menu {
    border-left: none; border-right: none; border-top: 1px solid var(--border);
    max-height: none;
  }
  /* When stacked, always show the menu contents (no hover-to-expand) and drop
     the collapse chevrons that only make sense in a side-by-side layout. */
  .workspace.sidebar-collapsed .menu .menu-body,
  .workspace.sidebar-collapsed .menu .menu-header h3,
  .workspace.right-collapsed .right-menu .menu-body,
  .workspace.right-collapsed .right-menu .menu-header h3 { display: block; }
  .collapse-btn { display: none; }

  /* Stereoscopic: stack the two panes vertically so each stays usable */
  .workspace.stereo .image-wrapper { flex-direction: column; }

  /* Larger touch targets in the control menus */
  .menu button, .right-menu button { min-height: 40px; }
}

@media (max-width: 560px) {
  .image-wrapper { min-height: 46vh; }
  .topbar .brand { font-size: 14px; }
  #threeDLink { padding: 6px 10px !important; }
}

/* ===== Game Mode: lobby / roster / join, and the flashing notify button ===== */
.game-lobby { border-top: 1px solid var(--border); }
.game-lobby-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px 8px; }
.game-lobby-head span { flex: 1; font-weight: 600; font-size: 13px; color: var(--text); }
.game-roster { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 14px 12px; }
.game-roster .chip {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 100px; padding: 4px 11px; font-size: 12px; color: var(--text);
}
.game-roster .empty { color: var(--text-muted); font-size: 12px; }
.game-lobby #gameLobbyHostControls { padding: 0 14px 12px; display: flex; gap: 8px; }

/* Pulse the Game Mode button when a lobby/active game is available to join. */
@keyframes gm-flash {
  0%, 100% { box-shadow: 0 0 0 0 rgba(45,212,191,.55); }
  50%      { box-shadow: 0 0 0 5px rgba(45,212,191,0); }
}
.game-mode-btn.flash {
  background: #0d9488; color: #fff; border-color: #0d9488;
  animation: gm-flash 1.1s ease-in-out infinite;
}
