/* =====================================================================
   Go/No-Go Task — Academic styling
   Goal: clean, high-contrast, low-distraction. Desktop-first.
   ===================================================================== */

:root {
  --bg: #f7f8fa;
  --fg: #111827;
  --muted: #4b5563;
  --accent: #1f2937;
  --border: #d1d5db;
  --card: #ffffff;
  --error: #b91c1c;
  --success: #15803d;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 18px;
  line-height: 1.55;
  /* Disable text selection during the task to avoid distraction. */
  -webkit-user-select: none;
  user-select: none;
}

/* Persistent phase banner (instructions / practice / block 1, etc.) */
#phase-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  padding: 8px 16px;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  text-align: center;
  display: none;
}
#phase-banner.visible { display: block; }
body:has(#phase-banner.visible) { padding-top: 40px; }

/* jsPsych container: give it room and keep it centered */
.jspsych-display-element {
  font-family: inherit !important;
  font-size: 18px !important;
  color: var(--fg) !important;
}
.jspsych-content {
  max-width: 760px !important;
}

/* Headings inside instructions/screens */
.gonogo-screen {
  text-align: left;
  padding: 24px;
}
.gonogo-screen h1 {
  font-size: 28px;
  margin: 0 0 16px;
}
.gonogo-screen h2 {
  font-size: 22px;
  margin: 24px 0 8px;
}
.gonogo-screen p { margin: 12px 0; color: var(--fg); }
.gonogo-screen ul { margin: 8px 0 16px 24px; }
.gonogo-screen li { margin: 6px 0; }
.gonogo-screen .muted { color: var(--muted); font-size: 15px; }
.gonogo-screen kbd {
  display: inline-block;
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: #fff;
  font-family: 'Menlo', 'Consolas', monospace;
  font-size: 14px;
}

/* =====================================================================
   Short-video phone interface
   Constant decorative shell that wraps every trial. None of these
   elements affect task logic — they exist only to make the task feel
   like scrolling through a short-video app.
   ===================================================================== */
.phone-frame {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px 0;
}
.phone-screen {
  position: relative;
  width: 360px;
  height: 720px;
  max-height: 80vh;
  border-radius: 36px;
  background: #000;
  color: #fff;
  overflow: hidden;
  box-shadow: 0 12px 40px rgba(0,0,0,0.25), 0 0 0 8px #111 inset;
  display: flex;
  flex-direction: column;
  font-family: 'Inter', sans-serif;
}
.phone-statusbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 20px 4px;
  font-size: 12px;
  color: #fff;
  letter-spacing: 0.04em;
}
.phone-statusbar-icons { font-size: 10px; opacity: 0.8; }
.phone-tabs {
  display: flex;
  justify-content: center;
  gap: 24px;
  padding: 6px 0 8px;
  font-size: 14px;
  color: rgba(255,255,255,0.55);
}
.phone-tabs .active { color: #fff; font-weight: 600; }
.video-area {
  position: relative;
  flex: 1;
  background: #0a0a0a;
  overflow: hidden;
}
.video-content {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.video-meta {
  position: absolute;
  left: 16px;
  bottom: 16px;
  font-size: 13px;
  text-shadow: 0 1px 2px rgba(0,0,0,0.6);
}
.video-user { font-weight: 600; margin-bottom: 4px; }
.video-caption { color: rgba(255,255,255,0.85); }
.video-side {
  position: absolute;
  right: 12px;
  bottom: 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  align-items: center;
}
.side-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255,255,255,0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}
.phone-bottomnav {
  display: flex;
  justify-content: space-around;
  padding: 8px 0 14px;
  font-size: 11px;
  color: rgba(255,255,255,0.55);
  background: #050505;
}
.phone-bottomnav .active { color: #fff; font-weight: 600; }

/* Trial stimulus: large centered circle in the "video" area */
.gonogo-stim {
  width: 160px;
  height: 160px;
  border-radius: 50%;
  box-shadow: 0 0 30px rgba(0,0,0,0.4);
}

/* Fixation cross — sits inside the phone's video area */
.gonogo-fixation {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 56px;
  font-weight: 300;
  color: rgba(255,255,255,0.85);
}

/* Swipe-to-next-video transition: brief vertical slide. Triggered by
   adding .video-swipe-in to the .video-area; duration is set via the
   --swipe-ms CSS var written by the JS wrapInPhone() helper. */
.video-swipe-in {
  animation: video-swipe-in var(--swipe-ms, 200ms) ease-out 1;
}
@keyframes video-swipe-in {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

/* Trial-by-trial feedback (practice only) */
.gonogo-feedback {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 60vh;
  font-size: 28px;
  font-weight: 600;
}
.gonogo-feedback.correct { color: var(--success); }
.gonogo-feedback.incorrect { color: var(--error); }

/* Results / debrief table */
.gonogo-results {
  text-align: left;
  padding: 24px;
}
.gonogo-results table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
}
.gonogo-results th, .gonogo-results td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  font-variant-numeric: tabular-nums;
}
.gonogo-results th {
  background: #eef0f3;
  font-weight: 600;
}
/* Crash recovery banner + overlay */
#gng-recovery-banner {
  position: fixed; top: 0; left: 0; right: 0;
  background: #fef3c7; color: #78350f;
  padding: 10px 16px; font-size: 14px;
  display: flex; gap: 12px; align-items: center; justify-content: center;
  z-index: 9999; border-bottom: 1px solid #fcd34d;
}
#gng-recovery-banner button {
  background: #111827; color: #fff; border: none; padding: 6px 12px;
  border-radius: 6px; font-size: 13px; cursor: pointer;
}
#gng-recovery-banner button + button { background: transparent; color: #78350f; border: 1px solid #b45309; }
#gng-crash-overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,0.85);
  display: flex; align-items: center; justify-content: center; z-index: 10000;
}
#gng-crash-overlay .crash-card {
  background: #fff; padding: 24px 28px; border-radius: 12px;
  max-width: 560px; box-shadow: 0 12px 40px rgba(0,0,0,0.3);
}
#gng-crash-overlay h2 { margin: 0 0 8px; color: #b91c1c; }
#gng-crash-overlay pre {
  background: #f3f4f6; padding: 10px; border-radius: 6px;
  font-size: 12px; max-height: 160px; overflow: auto; white-space: pre-wrap;
}
#gng-crash-overlay button {
  background: #111827; color: #fff; border: none; padding: 10px 16px;
  border-radius: 8px; font-size: 14px; cursor: pointer; margin-top: 8px;
}

.final-score-card {
  margin: 24px 0 32px;
  padding: 24px 28px;
  border-radius: 14px;
  background: linear-gradient(135deg, #1f2937 0%, #111827 100%);
  color: #fff;
  box-shadow: 0 6px 18px rgba(0,0,0,0.18);
}
.final-score-card.invalid {
  background: linear-gradient(135deg, #7f1d1d 0%, #450a0a 100%);
}
.final-score-label {
  font-size: 14px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.7);
}
.final-score-value {
  font-size: 56px;
  font-weight: 700;
  line-height: 1.1;
  margin: 4px 0 8px;
}
.final-score-help {
  font-size: 14px;
  color: rgba(255,255,255,0.75);
  margin-bottom: 18px;
}
.final-score-breakdown {
  width: 100%;
  margin: 8px 0 12px;
  background: rgba(255,255,255,0.06);
  border-radius: 8px;
  overflow: hidden;
}
.final-score-breakdown th, .final-score-breakdown td {
  padding: 8px 12px;
  font-size: 14px;
  color: #fff;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.final-score-breakdown th { text-align: left; font-weight: 500; color: rgba(255,255,255,0.85); }
.final-score-breakdown td { text-align: right; font-variant-numeric: tabular-nums; }
.final-score-breakdown tr:last-child th,
.final-score-breakdown tr:last-child td { border-bottom: none; font-weight: 600; }
.final-score-norms {
  font-size: 12px;
  color: rgba(255,255,255,0.6);
  margin-top: 8px;
}

.gonogo-results .tiktok-return-row {
  margin-top: 24px;
}
.gonogo-btn.tiktok-btn {
  display: inline-flex !important;
  align-items: center;
  gap: 8px;
  font-size: 16px !important;
  padding: 12px 28px !important;
  background: #010101 !important;
  border-color: #010101 !important;
  border-radius: 8px !important;
  text-decoration: none;
  letter-spacing: 0.01em;
}
.gonogo-btn.tiktok-btn::before {
  content: "";
  display: inline-block;
  width: 18px;
  height: 18px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'%3E%3Cpath d='M19.59 6.69a4.83 4.83 0 0 1-3.77-4.25V2h-3.45v13.67a2.89 2.89 0 0 1-2.88 2.5 2.89 2.89 0 0 1-2.89-2.89 2.89 2.89 0 0 1 2.89-2.89c.28 0 .54.04.79.1V9.01a6.33 6.33 0 0 0-.79-.05 6.34 6.34 0 0 0-6.34 6.34 6.34 6.34 0 0 0 6.34 6.34 6.34 6.34 0 0 0 6.33-6.34V9.15a8.16 8.16 0 0 0 4.77 1.52V7.22a4.85 4.85 0 0 1-1-.53z'/%3E%3C/svg%3E") no-repeat center/contain;
}
.gonogo-btn.tiktok-btn:hover { opacity: 0.85; }

.upload-status {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 18px;
  padding: 10px 14px;
  border-radius: 6px;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  font-size: 14px;
  color: #334155;
}
.upload-status .us-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #94a3b8;
  flex-shrink: 0;
}
.upload-status .us-dot.pending { background: #f59e0b; animation: pulse 1.2s ease-in-out infinite; }
.upload-status .us-dot.ok      { background: #10b981; }
.upload-status .us-dot.err     { background: #ef4444; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.35; } }

/* Buttons (jsPsych default plus our custom ones) */
.jspsych-btn,
.gonogo-btn {
  font-family: inherit !important;
  font-size: 16px !important;
  padding: 10px 18px !important;
  border: 1px solid var(--accent) !important;
  background: var(--accent) !important;
  color: #fff !important;
  border-radius: 6px !important;
  cursor: pointer;
}
.gonogo-btn.secondary {
  background: #fff !important;
  color: var(--accent) !important;
}
.jspsych-btn:hover, .gonogo-btn:hover { opacity: 0.9; }

/* Warning toast for fullscreen exit / tab switch */
#gonogo-warning {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--error);
  color: #fff;
  padding: 10px 16px;
  border-radius: 6px;
  z-index: 200;
  display: none;
  font-size: 14px;
}
#gonogo-warning.visible { display: block; }

/* -----------------------------------------------------------------------
 * Participant login overlay
 * --------------------------------------------------------------------- */
#participant-login {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  /* Allow text selection in the login form */
  -webkit-user-select: text;
  user-select: text;
}
#participant-login.hidden { display: none; }
.pl-card-hidden { display: none !important; }

.pl-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 44px 40px 36px;
  width: 360px;
  max-width: calc(100vw - 32px);
  box-shadow: 0 4px 24px rgba(0,0,0,0.07);
}
.pl-logo {
  font-size: 22px;
  font-weight: 700;
  color: var(--fg);
  margin-bottom: 6px;
  letter-spacing: -0.01em;
}
.pl-subtitle {
  font-size: 15px;
  color: var(--muted);
  margin: 0 0 28px;
}
.pl-card label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  color: var(--fg);
  margin-bottom: 6px;
}
.pl-card input[type="text"] {
  width: 100%;
  padding: 10px 12px;
  font-size: 16px;
  font-family: inherit;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--fg);
  outline: none;
  transition: border-color 0.15s;
}
.pl-card input[type="text"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(31,41,55,0.10);
}
.pl-error {
  font-size: 13px;
  color: var(--error);
  min-height: 18px;
  margin-top: 6px;
}
.pl-card button[type="submit"] {
  margin-top: 18px;
  width: 100%;
  padding: 11px;
  font-size: 16px;
  font-weight: 600;
  font-family: inherit;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: opacity 0.15s;
}
.pl-card button[type="submit"]:hover { opacity: 0.88; }
.pl-card button[type="submit"]:disabled { opacity: 0.5; cursor: not-allowed; }

/* Return-user card */
.pl-return-username {
  font-size: 20px;
  font-weight: 700;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 20px;
  word-break: break-all;
}
#pl-continue-btn {
  width: 100%;
  padding: 11px;
  font-size: 16px;
  font-weight: 600;
  font-family: inherit;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: opacity 0.15s;
}
#pl-continue-btn:hover { opacity: 0.88; }
#pl-notme-btn {
  display: block;
  width: 100%;
  margin-top: 12px;
  padding: 6px;
  font-size: 13px;
  font-family: inherit;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}
#pl-notme-btn:hover { color: var(--fg); }
#pl-restart-btn {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 6px;
  font-size: 13px;
  font-family: inherit;
  background: none;
  border: none;
  color: #b45309;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}
#pl-restart-btn:hover { color: #92400e; }

/* Responsive: optimized for desktop, but readable on smaller screens */
@media (max-width: 600px) {
  body { font-size: 16px; }
  .gonogo-stim { width: 130px; height: 130px; }
  .pl-card { padding: 32px 20px 28px; }
}
