/* =========================================================================
   Walking Dots - iPad-portrait-first playfield.

   The play surface matches the Joystick Pursuit trainer: a light #edf2f8
   canvas inside a bordered frame, sitting on the app's dark chrome. Dots and
   tracks are therefore drawn dark-on-light.
   ========================================================================= */

#walkingDotsTrainerView {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

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

.wd-home {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  padding: 1.1rem 1.2rem 1.3rem;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 0.75rem;
  box-shadow: var(--shadow-card);
}

.wd-home-head h2 {
  font-family: var(--font-hud);
  font-size: 1.05rem;
  letter-spacing: 0.04em;
  margin: 0 0 0.25rem;
  color: var(--text-primary);
}

.wd-home-head p {
  margin: 0;
  font-size: 0.78rem;
  line-height: 1.5;
  color: var(--text-secondary);
  max-width: 62ch;
}

.wd-instruction {
  display: flex;
  gap: 0.55rem;
  align-items: flex-start;
  padding: 0.65rem 0.8rem;
  border-radius: 0.55rem;
  background: rgba(56, 189, 248, 0.08);
  border: 1px solid rgba(56, 189, 248, 0.25);
  font-size: 0.75rem;
  line-height: 1.55;
  color: var(--text-secondary);
}

.wd-instruction strong { color: var(--text-primary); }

.wd-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.85rem 1.1rem;
  align-items: flex-end;
}

.wd-control {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 8.5rem;
}

.wd-control label {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  text-transform: uppercase;
}

.wd-hint {
  font-family: var(--font-mono);
  font-size: 0.58rem;
  letter-spacing: 0.02em;
  color: var(--text-muted);
  white-space: nowrap;
}

.wd-bpm-row {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-family: var(--font-mono);
  font-size: 0.66rem;
  color: var(--text-secondary);
}

.wd-bpm-row.hidden { display: none; }

.wd-bpm-row input {
  width: 3.6rem;
  padding: 0.28rem 0.4rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 0.4rem;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 0.74rem;
  text-align: center;
}

.wd-bpm-row input:focus {
  outline: none;
  border-color: var(--border-focus);
}

.wd-toggle {
  flex-direction: row;
  align-items: center;
  gap: 0.45rem;
  min-width: 0;
}

.wd-toggle input { width: 1rem; height: 1rem; accent-color: var(--sky-accent); }

.wd-start-btn {
  margin-left: auto;
  padding: 0.62rem 1.7rem;
  border: none;
  border-radius: 0.55rem;
  background: linear-gradient(180deg, var(--sky-accent), #0284c7);
  color: #04121f;
  font-family: var(--font-hud);
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: filter var(--transition-fast);
}

.wd-start-btn:hover { filter: brightness(1.12); }
.wd-start-btn:active { transform: translateY(1px); }

/* ---- Session overlay ---------------------------------------------------- */

.wd-session {
  position: fixed;
  inset: 0;
  z-index: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-main);

  /* The training surface must swallow every browser gesture. */
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  overscroll-behavior: none;
  -webkit-touch-callout: none;
  padding: calc(env(safe-area-inset-top) + 0.5rem) calc(env(safe-area-inset-right) + 0.5rem)
           calc(env(safe-area-inset-bottom) + 0.5rem) calc(env(safe-area-inset-left) + 0.5rem);
}

/* Hide the app shell while a session is live. */
body.wd-session-active .trainer-nav,
body.wd-session-active .app-header,
body.wd-session-active header {
  visibility: hidden;
}

body.wd-session-active {
  overflow: hidden;
  overscroll-behavior: none;
}

/* The bordered light play surface - same treatment as .pursuit-canvas-wrap. */
.wd-stage {
  position: relative;
  height: 100%;
  width: 100%;
  /* Portrait play area, letterboxed on wide screens. */
  max-width: min(100%, calc((100vh - 1rem) * 0.75));
  margin: 0 auto;
  background: #edf2f8;
  border: 1px solid rgba(148, 163, 184, 0.35);
  border-radius: 0.65rem;
  box-shadow: inset 0 0 20px rgba(15, 23, 42, 0.12);
  overflow: hidden;
}

#wdPlayfield {
  display: block;
  width: 100%;
  height: 100%;
  background: transparent;
  touch-action: none;
  user-select: none;
}

/* ---- Tracks (dark-on-light) --------------------------------------------- */

.wd-line {
  fill: none;
  stroke: #b0c0d6;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.wd-track.is-active .wd-line { stroke: #7f97bb; }

.wd-dot {
  fill: #8497b4;
  transition: fill 120ms ease, opacity 120ms ease;
  pointer-events: none;
}

.wd-track.is-active .wd-dot { fill: #2b4677; }

/* Spent dots go hollow. Solid = still live, outline = already walked, which
   reads faster at speed than a fill-brightness difference alone. */
.wd-dot.is-done {
  fill: none;
  stroke: #a9b8cd;
  stroke-width: 2.5;
  opacity: 0.95;
}

/* You are here - the strongest mark on the board. */
.wd-dot.is-current {
  fill: #0e1d3a;
  stroke: rgba(23, 59, 143, 0.30);
  stroke-width: 6;
}

/* Learn mode only - Professor never shows this. */
.wd-dot.is-next {
  fill: #20c56d;
  stroke: rgba(32, 197, 109, 0.30);
  stroke-width: 7;
}

/* The hitbox is always larger than the visible dot and never drawn. */
.wd-hit {
  fill: transparent;
  stroke: none;
  cursor: pointer;
  pointer-events: all;
}

.wd-track.is-correct .wd-line { stroke: #20c56d; }
.wd-track.is-wrong .wd-line { stroke: #f43f5e; }

/* Dashed ring marking exactly which dot a wrong tap hit. Sized to the touch
   target, so it also teaches how generous the hitbox really is.
   Learn/Train only - Professor shows no correctness feedback. */
.wd-error-ring {
  fill: none;
  stroke: #e11d48;
  stroke-width: 2.5;
  stroke-dasharray: 5 6;
  stroke-linecap: round;
  opacity: 0;
  pointer-events: none;
  transition: opacity 140ms ease;
}

.wd-error-ring.is-visible {
  opacity: 1;
  animation: wd-error-ring 620ms linear;
}

@keyframes wd-error-ring {
  from { stroke-dashoffset: 0; opacity: 1; }
  to { stroke-dashoffset: 44; opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .wd-error-ring.is-visible { animation: none; }
}

/* ---- Session chrome (on the light surface) ------------------------------ */

.wd-exit-btn {
  position: absolute;
  top: 0.5rem;
  left: 0.5rem;
  width: 2.1rem;
  height: 2.1rem;
  border-radius: 50%;
  border: 1px solid rgba(15, 23, 42, 0.18);
  background: rgba(255, 255, 255, 0.72);
  color: #475569;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  z-index: 2;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.wd-exit-btn:hover { color: #0e1d3a; background: #ffffff; }

.wd-hud {
  position: absolute;
  top: 0.55rem;
  right: 0.7rem;
  display: flex;
  gap: 0.9rem;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
  color: #64748b;
  z-index: 2;
  pointer-events: none;
}

.wd-countdown {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(237, 242, 248, 0.92);
  font-family: var(--font-hud);
  font-size: clamp(2.4rem, 12vw, 5rem);
  font-weight: 800;
  letter-spacing: 0.08em;
  color: #0e1d3a;
  z-index: 3;
  pointer-events: none;
}

.wd-question-text {
  position: absolute;
  left: 50%;
  bottom: 4%;
  transform: translateX(-50%);
  max-width: 88%;
  padding: 0.5rem 0.9rem;
  border-radius: 0.5rem;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid rgba(148, 163, 184, 0.45);
  color: #0e1d3a;
  font-size: 0.85rem;
  text-align: center;
  z-index: 2;
  pointer-events: none;
}

.wd-recovery {
  position: absolute;
  inset: auto 1rem 1rem;
  padding: 0.7rem 1rem;
  border-radius: 0.55rem;
  background: rgba(244, 63, 94, 0.12);
  border: 1px solid rgba(244, 63, 94, 0.45);
  color: #9f1239;
  font-size: 0.8rem;
  text-align: center;
  z-index: 4;
}

/* ---- Results ------------------------------------------------------------ */

.wd-results {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1.1rem 1.2rem 1.4rem;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 0.75rem;
  box-shadow: var(--shadow-card);
}

.wd-headline {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
  gap: 0.7rem;
}

.wd-headline-stat {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 0.85rem 1rem;
  border-radius: 0.6rem;
  background: rgba(30, 41, 59, 0.65);
  border: 1px solid var(--border-subtle);
}

.wd-headline-label {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
}

.wd-headline-value {
  font-family: var(--font-hud);
  font-size: 1.7rem;
  font-weight: 800;
  color: var(--text-primary);
}

.wd-result-table { display: flex; flex-direction: column; }

.wd-result-section {
  margin-top: 0.8rem;
  padding: 0.35rem 0;
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--sky-accent);
  border-bottom: 1px solid var(--border-subtle);
}

.wd-result-row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.32rem 0;
  font-size: 0.8rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.wd-result-label { color: var(--text-secondary); }
.wd-result-value {
  font-family: var(--font-mono);
  color: var(--text-primary);
}

.wd-review-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.wd-review-q {
  display: flex;
  gap: 0.6rem;
  align-items: baseline;
  flex: 1 1 22rem;
  min-width: 0;
}

.wd-review-index {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--text-secondary);
  min-width: 1.4rem;
}

.wd-review-text {
  flex: 1;
  font-size: 0.8rem;
  color: var(--text-primary);
}

.wd-review-answer {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--emerald-success);
  white-space: nowrap;
}

.wd-review-marks { display: flex; gap: 0.35rem; }

.wd-review-marks button {
  padding: 0.24rem 0.6rem;
  border-radius: 0.4rem;
  border: 1px solid var(--border-subtle);
  background: rgba(30, 41, 59, 0.65);
  color: var(--text-secondary);
  font-size: 0.68rem;
  cursor: pointer;
  transition: color var(--transition-fast), background var(--transition-fast);
}

.wd-review-marks button:hover { color: var(--text-primary); }
.wd-review-marks button.is-marked {
  background: rgba(56, 189, 248, 0.18);
  border-color: var(--border-focus);
  color: #cfe9ff;
}

.wd-result-actions { display: flex; gap: 0.6rem; }

.wd-result-actions button {
  padding: 0.5rem 1.2rem;
  border-radius: 0.5rem;
  border: 1px solid var(--border-subtle);
  background: rgba(30, 41, 59, 0.65);
  color: var(--text-primary);
  font-size: 0.8rem;
  cursor: pointer;
  transition: background var(--transition-fast);
}

.wd-result-actions button:hover { background: var(--bg-card-hover); }

.wd-result-note,
.wd-empty {
  font-family: var(--font-mono);
  font-size: 0.66rem;
  color: var(--text-muted);
}

.wd-section-title {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--sky-accent);
  margin: 0 0 0.3rem;
}

/* ---- Portrait request --------------------------------------------------- */

@media (orientation: landscape) and (max-height: 560px) {
  .wd-stage::after {
    content: 'Rotate to portrait for Walking Dots.';
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(237, 242, 248, 0.96);
    color: #0e1d3a;
    font-size: 0.95rem;
    z-index: 5;
  }
}
