/* =========================
   THEME & TOKENS
   ========================= */
:root {
  --maxw: 1500px;
  --gap: 14px;

  /* always-dark theme */
  --bg: #020617;      /* very dark backdrop */
  --panel: #0f172a;   /* dark panel */
  --panel-2: #020617; /* even darker surface */
  --border: #1e293b;

  --text: #e5e7eb;    /* light text */
  --muted: #94a3b8;   /* muted text */
  --accent: #2563eb;
  --accent-2: #1d4ed8;

  --radius: 14px;
  --shadow-1: 0 6px 20px rgba(0, 0, 0, 0.35);
  --shadow-2: 0 12px 40px rgba(0, 0, 0, 0.45);

  color-scheme: dark;
}

/* =========================
   BASE / VIEWPORT LAYOUT
   ========================= */
* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  color: var(--text);
  background:
    radial-gradient(
      1200px 600px at 50% -80px,
      rgba(37, 99, 235, 0.15),
      transparent 60%
    ),
    radial-gradient(
      900px 500px at -10% -10%,
      rgba(14, 165, 233, 0.12),
      transparent 60%
    ),
    var(--bg);
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Inter,
    Arial, sans-serif;
  line-height: 1.6;

  display: flex;
  justify-content: center;   /* center horizontally */
  align-items: flex-start;   /* stick to top */
  padding: 10px 0;
}

/* main viewport app “card” */
.app {
  width: min(var(--maxw), 100vw - 24px);
  min-height: calc(100vh - 24px);
  background: var(--panel-2);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-1);
  padding: 8px 18px;
  display: flex;
  flex-direction: column;
}

.hidden {
  display: none !important;
}

.center {
  text-align: center;
}

/* =========================
   TYPOGRAPHY
   ========================= */
h1 {
  font-size: clamp(24px, 3.4vw, 34px);
  line-height: 1.15;
  letter-spacing: -0.01em;
  margin: 0 0 4px;
}

p.lead {
  color: var(--muted);
  margin: 0 0 12px;
  font-size: clamp(14px, 1.9vw, 18px);
}

/* Ensure main interactive text uses the theme text color */
input,
textarea,
button,
label,
#counter,
h2,
ol,
ol li {
  color: var(--text);
}

/* Muted text where it should be muted */
.lead,
.help,
label.check span,
.pane figcaption {
  color: var(--muted);
}

/* Shared placeholder style */
input::placeholder,
textarea::placeholder {
  color: var(--muted);
  opacity: 0.9;
}

/* =========================
   APP LAYOUT: HEADER / MAIN
   ========================= */
.site-header {
  flex: 0 0 auto;
  margin-bottom: 10px;
}

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

.site-main > section {
  height: auto; /* let each screen be as tall as its content */
}

/* Card centering for non-trial screens */
.screen {
  display: flex;
  justify-content: center;
  align-items: center;
}

#welcome .card,
#instructions .card,
#done .card {
  width: 100%;
  max-width: 720px;
}

/* =========================
   HERO / HEADER
   ========================= */
.site-header.hero {
  text-align: left;
  padding: 8px 4px 18px;
  margin-bottom: 22px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.18);
}

.hero-title {
  font-size: clamp(26px, 3.6vw, 36px);
  line-height: 1.15;
  font-weight: 800;
  margin-bottom: 6px;
  letter-spacing: -0.02em;
}

.hero-subtitle {
  display: block;
  font-weight: 600;
  font-size: 0.88em;
  opacity: 0.85;
}

.hero-description {
  margin: 8px 0 14px;
  color: var(--muted);
  max-width: 760px;
  font-size: clamp(14px, 1.8vw, 17px);
  line-height: 1.55;
}

.hero-info {
  margin-top: 4px;
  font-size: 0.93rem;
  line-height: 1.45;
  color: var(--muted);
}

.hero-info strong {
  color: var(--text);
}

/* Hide header entirely during trials */
.app.in-trial .site-header {
  display: none;
}

/* =========================
   CARDS & PANELS
   ========================= */
.card {
  background: linear-gradient(180deg, var(--panel), var(--panel));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin: 0;
  box-shadow: var(--shadow-1);
  transition: box-shadow 0.25s ease;
}

.card:hover {
  box-shadow: var(--shadow-2);
}

.row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.row > label {
  flex: 1 1 260px;
}

/* =========================
   PROGRESS / COUNTER (trial)
   ========================= */
#counter {
  margin: 0 0 6px;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.progress {
  height: 8px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--border);
  overflow: hidden;
  margin: 0 0 6px;
}

.progress > i {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), #38bdf8);
  transition: width 0.35s ease;
}

/* =========================
   TRIAL LAYOUT
   ========================= */
.trial-layout {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto; /* fill remaining space but don’t force height */
  min-height: 0;
}

/* maps + answer + button all inside trial-layout */
.trial-layout .maps {
  flex: 1 1 auto; /* maps grow first */
  min-height: 0;
  margin-bottom: 8px;

  display: flex; /* panes side-by-side */
  gap: var(--gap);
  align-items: stretch;
}

.trial-layout .answer {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: auto;
  margin-bottom: 8px;
}

/* =========================
   MAPS
   ========================= */
.pane {
  flex: 1 1 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.pane figcaption {
  display: flex;
  justify-content: center;  /* center horizontally */
  align-items: center;
  gap: 8px;
  font-size: 0.92rem;
  margin: 0 0 4px;
  text-align: center;
  width: 100%;
}

.badge {
  display: inline-block;
  font-weight: 600;
  font-size: 0.78rem;
  padding: 4px 10px;
  border-radius: 999px;
  color: #e5e7eb;
  background: #0b2a40;
  border: 1px solid #10334b;
}

.maps img {
  flex: 1 1 0;
  width: 100%;
  height: 100%;
  max-height: 73vh; /* allow more vertical space */
  object-fit: contain;
  background: linear-gradient(180deg, var(--panel-2), var(--panel-2));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-1);
}

/* =========================
   FORMS (LABELS + INPUTS + TEXTAREA)
   ========================= */
label {
  display: block;
  font-weight: 600;
  margin: 6px 0 4px;
  color: var(--text);
}

label > input {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  font: inherit;
  background: var(--panel-2);
  color: var(--text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease,
    background 0.2s ease;
}

label > input:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.35);
  background: var(--panel);
  color: var(--text);
}

label.check {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 500;
  color: var(--muted);
}

label.check input {
  width: auto;
}

.help {
  color: var(--muted);
  font-size: 0.92rem;
  margin-top: 6px;
}

/* base textarea */
textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #1e293b;
  border-radius: 12px;
  font: inherit;
  line-height: 1.45;
  resize: none; /* avoid breaking the layout */
  background: #0f172a;
  color: #e5e7eb;
  transition: border-color 0.15s ease, box-shadow 0.15s ease,
    background 0.2s ease;
}

textarea:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.35);
  background: #0f172a;
  color: #e5e7eb;
}

/* textarea specifically in the answer row */
.answer textarea {
  flex: 1;
}

/* answer row (textarea + button) */
.answer-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 4px;
}

.answer-row textarea {
  flex: 1;
  height: 50px;
}

.answer-row button {
  height: 50px;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* =========================
   BUTTONS
   ========================= */
button {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--panel);
  padding: 10px 16px;
  border-radius: 12px;
  cursor: pointer;
  font: inherit;
  transition: transform 0.02s ease, box-shadow 0.2s ease,
    background 0.2s ease, border-color 0.2s ease;
}

button:hover {
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.3);
}

button:active {
  transform: translateY(1px);
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

button.primary {
  color: #fff;
  border-color: transparent;
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
  box-shadow: 0 8px 30px rgba(37, 99, 235, 0.32);
}

button.primary:hover {
  box-shadow: 0 10px 36px rgba(37, 99, 235, 0.5);
}

button.primary:focus-visible {
  outline: none;
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.25);
}

button.muted {
  background: var(--panel-2);
}

/* =========================
   SPINNER
   ========================= */
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.spinner {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 3px solid rgba(0, 0, 0, 0.15);
  border-top-color: rgba(0, 0, 0, 0.6);
  animation: spin 0.8s linear infinite;
  display: inline-block;
  margin-left: 8px;
  box-sizing: border-box;
}

/* ensure hidden wins */
.spinner.hidden {
  display: none;
}

#submitLabel,
#submitSpin {
  flex-shrink: 0;
}

/* ===== Block 1: Text1/Text2 on the left, counter+bar on the right ===== */
.trial-top {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 8px;
}

.trial-top-left {
  flex: 1 1 auto;
  min-width: 0;
}

.trial-title {
  margin: 0;
  font-size: 1.3rem;
  line-height: 1.2;
}

.trial-subtitle {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

/* right side: counter + skinny bar */
.trial-top-right {
  flex: 0 0 260px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}

.trial-top-right #counter {
  margin: 0;
  font-size: 0.95rem;
}

.trial-top-right .progress {
  width: 100%;
  height: 6px;
  margin: 0;
}

/* =========================
   DEVICE WARNING (Welcome Page)
   ========================= */
.device-warning {
  font-size: 0.95rem;
  color: var(--muted);
  margin-bottom: 18px;
  line-height: 1.45;
}

.device-warning strong {
  color: var(--text);
}
