/* ═══════════════════════════════════════════
   Reset & Base
═══════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --sky:      #87CEEB;
  --sky-low:  #B8E0F7;
  --grass:    #4a9e3f;
  --grass-dk: #2d6e25;
  --tree1:    #228B22;
  --tree2:    #2E8B57;
  --wood:     #8B5E3C;
  --wood-dk:  #5C3A1E;
  --wood-lt:  #C8884B;
  --frame:    #D4A843;
  --cream:    #FFF8E7;
  --white:    #FFFFFF;
  --accent:   #E65C00;
  --text:     #2C1A0E;
  --muted:    #7a6052;
  --radius:   16px;
}

html, body {
  width: 100%; height: 100%; overflow: hidden;
  font-family: 'Segoe UI', 'PingFang TC', 'Microsoft JhengHei', sans-serif;
  background: var(--sky);
  color: var(--text);
  user-select: none;
}

/* ═══════════════════════════════════════════
   Screen management
═══════════════════════════════════════════ */
.screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none;
  transition: opacity 0.35s ease;
}
.screen.active {
  opacity: 1; pointer-events: all;
}

/* ═══════════════════════════════════════════
   Card (register / instructions / results)
═══════════════════════════════════════════ */
.card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 40px 44px;
  width: min(520px, 92vw);
  box-shadow: 0 8px 40px rgba(0,0,0,0.18);
  max-height: 92vh;
  overflow-y: auto;
}

.logo-area { text-align: center; margin-bottom: 28px; }
.logo-icon  { font-size: 56px; line-height: 1; margin-bottom: 8px; }
h1 { font-size: 1.5rem; color: var(--wood-dk); margin-bottom: 4px; }
h2 { font-size: 1.3rem; color: var(--wood-dk); margin-bottom: 18px; text-align: center; }
h3 { font-size: 1rem;   color: var(--wood-dk); margin-bottom: 10px; }
.subtitle { font-size: 0.82rem; color: var(--muted); }

/* Form */
.field { margin-bottom: 16px; }
.field label {
  display: block; font-size: 0.84rem; font-weight: 600;
  color: var(--muted); margin-bottom: 5px;
}
.field input, .field select {
  width: 100%; padding: 10px 14px;
  border: 1.5px solid #D8C9BB;
  border-radius: 8px; font-size: 0.97rem;
  outline: none; transition: border-color .2s;
}
.field input:focus, .field select:focus {
  border-color: var(--accent);
}

/* Buttons */
.btn-primary, .btn-secondary {
  display: inline-block; padding: 12px 28px;
  border: none; border-radius: 10px;
  font-size: 1rem; font-weight: 700;
  cursor: pointer; transition: transform .1s, box-shadow .1s;
}
.btn-primary {
  background: var(--accent); color: white;
  box-shadow: 0 4px 14px rgba(230,92,0,.35);
  width: 100%; margin-top: 8px;
}
.btn-primary:hover  { transform: translateY(-1px); box-shadow: 0 6px 18px rgba(230,92,0,.4); }
.btn-primary:active { transform: translateY(1px);  box-shadow: none; }
.btn-secondary {
  background: #EEE; color: var(--text);
  box-shadow: 0 2px 8px rgba(0,0,0,.1);
}
.btn-secondary:hover { background: #DDD; }

/* ═══════════════════════════════════════════
   Instructions
═══════════════════════════════════════════ */
#instructions-content { font-size: 0.95rem; line-height: 1.7; margin-bottom: 20px; }
#instructions-content p { margin-bottom: 8px; }
#instructions-content strong { color: var(--accent); }

.target-demo { text-align: center; margin: 20px 0; }
.demo-label  { font-size: 0.9rem; margin-bottom: 8px; }
.demo-animal {
  font-size: 80px; line-height: 1;
  background: var(--cream); border-radius: 50%;
  width: 110px; height: 110px;
  display: inline-flex; align-items: center; justify-content: center;
  margin: 0 auto 6px;
}
.demo-animal.non-target {
  border: 4px solid #E53935;
  background: #FFF3F3;
}
.demo-name { font-size: 0.85rem; color: var(--muted); margin-bottom: 16px; }
.demo-row  { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 8px; }
.demo-target-item {
  font-size: 40px; background: var(--cream);
  border-radius: 10px; padding: 6px 10px;
  border: 2px solid #43A047;
}

/* ═══════════════════════════════════════════
   Countdown
═══════════════════════════════════════════ */
#screen-countdown { background: rgba(0,0,0,0.55); }
.countdown-wrap { text-align: center; color: white; }
.countdown-wrap p { font-size: 1.3rem; margin-bottom: 10px; letter-spacing: 0.04em; }
#countdown-num {
  font-size: 10rem; font-weight: 900;
  text-shadow: 0 4px 20px rgba(0,0,0,.5);
  animation: pulse 1s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { transform: scale(1);   opacity: 1; }
  50%       { transform: scale(1.1); opacity: .85; }
}

/* ═══════════════════════════════════════════
   Task screen – Zoo background
═══════════════════════════════════════════ */
#screen-task { overflow: hidden; }

.zoo-sky {
  position: fixed; inset: 0;
  background: linear-gradient(180deg, #64B4E8 0%, #B8E0F7 100%);
  z-index: 0;
}

/* Decorative trees (CSS only) */
.zoo-trees {
  position: fixed; bottom: 28%; left: 0; right: 0;
  height: 160px; z-index: 1;
  display: flex; align-items: flex-end; justify-content: space-around;
}
.zoo-trees::before,
.zoo-trees::after {
  content: '🌳';
  font-size: clamp(70px, 10vw, 110px);
  line-height: 1;
}

.zoo-ground {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: 30%;
  background: linear-gradient(180deg, var(--grass) 0%, var(--grass-dk) 100%);
  z-index: 2;
}

/* Display stand */
.zoo-stage {
  position: relative; z-index: 10;
  display: flex; flex-direction: column; align-items: center;
}
.stage-top {
  display: flex; justify-content: center;
  margin-bottom: 0;
}
.stage-frame {
  background: var(--cream);
  border: 8px solid var(--frame);
  border-radius: 20px;
  box-shadow:
    0 0 0 3px var(--wood),
    0 12px 40px rgba(0,0,0,.35);
  width: 340px; height: 340px;
  display: flex; align-items: center; justify-content: center;
  position: relative;
  transition: box-shadow 0.15s;
}
.stage-frame.flash-green { box-shadow: 0 0 0 6px #43A047, 0 12px 40px rgba(0,0,0,.35); }
.stage-frame.flash-red   { box-shadow: 0 0 0 6px #E53935, 0 12px 40px rgba(0,0,0,.35); }

/* DOM-based stimulus display (replaces canvas) */
#stimulus-display {
  width: 100%; height: 100%;
  flex-direction: column;
  align-items: center; justify-content: center;
  border-radius: 12px;
  transition: background 0.05s;
}
.stim-emoji  { font-size: clamp(100px, 18vw, 180px); line-height: 1; }
.stim-label  { font-size: clamp(22px, 4vw, 36px); font-weight: 800;
               color: #333; margin-top: 8px; letter-spacing: .04em; }
.stim-cross  { font-size: clamp(48px, 8vw, 72px); color: #bbb;
               line-height: 1; font-weight: 300; }

.stage-leg {
  width: 28px; height: 80px;
  background: linear-gradient(90deg, var(--wood-lt), var(--wood), var(--wood-lt));
  border-radius: 4px;
}
.stage-base {
  width: 200px; height: 22px;
  background: linear-gradient(180deg, var(--wood-lt), var(--wood-dk));
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,.25);
}
.stage-label {
  margin-top: 10px;
  font-size: 0.85rem; font-weight: 600;
  color: white;
  text-shadow: 0 1px 4px rgba(0,0,0,.5);
  letter-spacing: 0.06em;
}

/* HUD */
.hud {
  position: fixed; top: 16px; left: 50%;
  transform: translateX(-50%);
  display: flex; gap: 24px; z-index: 20;
  background: rgba(0,0,0,.35);
  backdrop-filter: blur(6px);
  border-radius: 30px; padding: 8px 24px;
}
.hud-item { text-align: center; color: white; }
.hud-label { display: block; font-size: 0.68rem; opacity: .75; text-transform: uppercase; letter-spacing: .06em; }
.hud-val   { display: block; font-size: 1.1rem; font-weight: 700; }

/* Bottom hint */
.task-hint {
  position: fixed; bottom: 18px; left: 50%;
  transform: translateX(-50%);
  color: white; font-size: 0.88rem;
  text-shadow: 0 1px 4px rgba(0,0,0,.5);
  z-index: 20;
}
kbd {
  display: inline-block;
  background: rgba(255,255,255,.2);
  border: 1px solid rgba(255,255,255,.4);
  border-radius: 5px; padding: 1px 7px;
  font-family: inherit;
}

/* ═══════════════════════════════════════════
   Results
═══════════════════════════════════════════ */
#screen-results { background: #F5EEE6; align-items: flex-start; overflow-y: auto; }
.results-wrap {
  width: min(640px, 96vw); margin: 24px auto;
  background: white; border-radius: var(--radius);
  padding: 36px 40px;
  box-shadow: 0 4px 24px rgba(0,0,0,.1);
}
.results-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 14px; margin-bottom: 28px;
}
.result-card {
  background: var(--cream);
  border-radius: 10px; padding: 14px 12px;
  text-align: center;
}
.result-card .rc-val  { font-size: 1.8rem; font-weight: 800; color: var(--accent); }
.result-card .rc-label{ font-size: 0.73rem; color: var(--muted); margin-top: 2px; }

.results-blocks { margin-bottom: 24px; }
#results-blocks-table table {
  width: 100%; border-collapse: collapse; font-size: 0.85rem;
}
#results-blocks-table th, #results-blocks-table td {
  padding: 7px 10px; text-align: center;
  border-bottom: 1px solid #EEE;
}
#results-blocks-table th { background: #F8F2EA; font-weight: 700; color: var(--muted); }

.results-actions {
  display: flex; gap: 12px; margin-bottom: 16px;
}
.results-actions .btn-primary  { flex: 2; }
.results-actions .btn-secondary{ flex: 1; }

.timing-note {
  font-size: 0.72rem; color: var(--muted);
  border-top: 1px solid #EEE; padding-top: 12px;
  line-height: 1.6;
}

/* ═══════════════════════════════════════════
   Mobile / Touch
═══════════════════════════════════════════ */

/* Prevent text selection and callout on long-press */
#screen-task { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }

/* Make the entire task screen a tap target */
#screen-task { cursor: pointer; }

/* Prevent double-tap zoom on the task screen */
#screen-task { touch-action: manipulation; }

/* Larger stage on small phones */
@media (max-width: 500px) {
  .card { padding: 28px 20px; }
  .stage-frame { width: 82vw; height: 82vw; }
  #task-canvas { width: 100%; height: 100%; }
  .results-grid { grid-template-columns: 1fr 1fr; }
  .task-hint { font-size: 1rem; bottom: 24px; }
}

/* Tablet portrait */
@media (min-width: 501px) and (max-width: 820px) {
  .stage-frame { width: 60vw; height: 60vw; }
  #task-canvas { width: 100%; height: 100%; }
}
