/* Cobbe's Secret Mission — base layer.
 *
 * The stylesheet stack (Phase C, docs/2026-11-21-next-version.md §4.4):
 *
 *   fonts.css → tokens.css → base.css → components.css → one surface file:
 *   agent.css (child tablet), console.css (Spelledare), paper.css (notebook,
 *   board, print sheet, certificate)
 *
 * This file holds what every page needs whatever its surface: reset, body,
 * layout shell, top bar, language switch, timer bar, keyframes and motion
 * utilities, the touch layer and a small set of layout utilities (u-*).
 * Templates carry no <style> blocks and no static inline styles; a screen's
 * own rules live in its surface file, scoped under its body class (scr-*).
 */

/* The hidden attribute must win over inline display styles (forms toggle
   field groups with el.hidden while those groups use style="display:flex"). */
[hidden] { display: none !important; }

/* ═══ Reset & body ═══════════════════════════════════════════════ */
/* Reset & base */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: var(--font-size-base);
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: var(--font-ui, 'Segoe UI', system-ui, -apple-system, sans-serif);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.6;
}


/* The agent shell's ambience: two faint glows, fixed behind the content. */
/* Background effect — subtle data stream */
body.csm-agent::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background:
    radial-gradient(ellipse at 20% 50%, rgba(0, 212, 255, 0.03) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 50%, rgba(0, 255, 136, 0.03) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}


/* ═══ Layout shell ═══════════════════════════════════════════════ */
/* Layout */
.app-container {
  position: relative;
  z-index: 1;
  max-width: 1200px;
  margin: 0 auto;
  padding: var(--spacing);
}

/* Top bar */
.top-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  margin-bottom: var(--spacing);
  box-shadow: var(--shadow-glow);
}

.top-bar__agent-name {
  color: var(--neon-blue);
  font-weight: 700;
  font-size: var(--font-size-lg);
  text-transform: uppercase;
  letter-spacing: 2px;
}

.top-bar__status {
  color: var(--text-secondary);
  font-size: var(--font-size-sm);
}

/* Logo / title */
.cobbe-logo {
  text-align: center;
  padding: 40px 0 20px;
}

.cobbe-logo__title {
  font-size: var(--font-size-2xl);
  font-weight: 800;
  color: var(--neon-blue);
  text-transform: uppercase;
  letter-spacing: 4px;
  text-shadow: 0 0 20px rgba(0, 212, 255, 0.4);
}

.cobbe-logo__subtitle {
  color: var(--text-secondary);
  font-size: var(--font-size-base);
  margin-top: 8px;
  letter-spacing: 2px;
}


.top-bar__right {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

/* ═══ Language switch ════════════════════════════════════════════ */
/* Language switcher */
.lang-switch {
  display: flex;
  gap: 8px;
}

.lang-switch__btn {
  padding: 4px 10px;
  font-size: var(--font-size-sm);
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  cursor: pointer;
  transition: all var(--transition-fast);
  font-family: inherit;
}

.lang-switch__btn--active {
  color: var(--neon-blue);
  border-color: var(--neon-blue);
}


@media (max-width: 768px) {
  :root {
    --font-size-base: 16px;
    --font-size-lg: 20px;
    --font-size-xl: 24px;
    --font-size-2xl: 30px;
  }
}

/* ═══ Timer bar ══════════════════════════════════════════════════
 * A child-friendly countdown across the top of every agent page. The script
 * in base.html sets the fill width and data-state; the look is all here.
 */
.timer-bar {
  --timer-ink: var(--timer-cyan);
  --timer-fill: var(--timer-green);
  --timer-edge: rgba(100, 200, 255, .3);
  position: relative;
  width: 100%;
  height: 60px;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0 var(--space-4);
  overflow: hidden;
  background: rgba(20, 20, 40, .6);
  border-bottom: 2px solid var(--timer-edge);
}
.timer-bar__icon { flex-shrink: 0; font-size: 32px; animation: timer-sand 2s ease-in-out infinite; }
.timer-bar__time {
  flex-shrink: 0;
  font-size: 28px;
  font-weight: 900;
  line-height: 1;
  letter-spacing: 2px;
  color: var(--timer-ink);
  text-shadow: 0 0 10px var(--timer-ink);
}
.timer-bar__track {
  flex-grow: 1;
  height: 28px;
  overflow: hidden;
  border-radius: 14px;
  background: rgba(50, 50, 80, .8);
  border: 2px solid rgba(100, 150, 200, .3);
  box-shadow: inset 0 0 8px rgba(0, 0, 0, .6);
}
.timer-bar__fill {
  height: 100%;
  width: 100%;
  border-radius: 12px;
  background: var(--timer-fill);
  box-shadow: 0 0 15px var(--timer-fill);
  transition: width .3s ease, background .5s ease, box-shadow .3s ease;
}
.timer-bar[data-state="half"] { --timer-ink: var(--timer-yellow); --timer-fill: var(--timer-yellow); --timer-edge: rgba(255, 221, 0, .4); }
.timer-bar[data-state="half"] .timer-bar__icon { animation-duration: 1.8s; }
.timer-bar[data-state="low"] { --timer-ink: var(--timer-amber); --timer-fill: var(--timer-orange); --timer-edge: rgba(255, 170, 0, .6); }
.timer-bar[data-state="low"] .timer-bar__icon { animation-duration: 1.5s; }
.timer-bar[data-state="low"] .timer-bar__fill { animation: timer-glow 1s ease-in-out infinite; }
.timer-bar[data-state="urgent"] { --timer-ink: var(--timer-red); --timer-fill: var(--timer-red); --timer-edge: rgba(255, 51, 85, .8); }
.timer-bar[data-state="urgent"] .timer-bar__icon { animation: timer-shake .2s ease-in-out infinite; }
.timer-bar[data-state="urgent"] .timer-bar__fill { animation: timer-pulse .6s ease-in-out infinite; }

@keyframes timer-sand {
  0%, 100% { transform: translateY(0) scaleY(1); }
  50% { transform: translateY(3px) scaleY(.95); }
}
@keyframes timer-glow {
  0%, 100% { filter: drop-shadow(0 0 10px rgba(255, 51, 85, .8)); }
  50% { filter: drop-shadow(0 0 25px rgba(255, 51, 85, 1)); }
}
@keyframes timer-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}
@keyframes timer-pulse {
  0%, 100% { box-shadow: 0 0 15px rgba(255, 51, 85, .6), inset 0 0 10px rgba(255, 51, 85, .3); }
  50% { box-shadow: 0 0 25px rgba(255, 51, 85, 1), inset 0 0 15px rgba(255, 51, 85, .5); }
}
@media (prefers-reduced-motion: reduce) {
  .timer-bar__icon, .timer-bar__fill { animation: none !important; }
}

/* ═══ Home screen (/) ════════════════════════════════════════════ */
.home__actions { justify-content: center; margin-top: var(--space-8); }
.home__more { justify-content: center; margin-top: var(--space-4); }
.home__logo { animation-delay: .2s; }
.home__training { border-color: var(--neon-green); color: var(--neon-green); }

/* ═══ Utilities ══════════════════════════════════════════════════
 * The whole vocabulary for layout tweaks that used to be inline styles.
 * Anything more specific than this belongs to the screen (scr-*) or to a
 * component modifier, not to a new utility.
 */
.u-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); }
.u-row--center { justify-content: center; }
.u-row--between { justify-content: space-between; }
.u-row--end { justify-content: flex-end; }
.u-row--top { align-items: flex-start; }
.u-row--nowrap { flex-wrap: nowrap; }
.u-stack { display: flex; flex-direction: column; gap: var(--space-3); }
.u-grow { flex: 1 1 auto; min-width: 0; }
.u-center { text-align: center; }
.u-right { text-align: right; }
.u-quiet { color: var(--text-secondary); }
.u-small { font-size: var(--font-size-sm); }
.u-mono { font-family: var(--font-mono); }
.u-nowrap { white-space: nowrap; }
.u-inline { display: inline; }
.u-block { display: block; width: 100%; }
.u-m0 { margin: 0; }
.u-mt-2 { margin-top: var(--space-2); }
.u-mt-4 { margin-top: var(--space-4); }
.u-mt-6 { margin-top: var(--space-6); }
.u-mt-8 { margin-top: var(--space-8); }
.u-mb-2 { margin-bottom: var(--space-2); }
.u-mb-4 { margin-bottom: var(--space-4); }
.u-mb-6 { margin-bottom: var(--space-6); }
.u-sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

/* ═══ Motion (was animations.css) ════════════════════════════════ */
/* Glitch effect (hacker terminal) */
.glitch {
  position: relative;
}

.glitch--active {
  animation: glitch-shake 0.3s linear infinite;
}

@keyframes glitch-shake {
  0% { transform: translate(0); }
  20% { transform: translate(-2px, 1px); }
  40% { transform: translate(2px, -1px); }
  60% { transform: translate(-1px, -2px); }
  80% { transform: translate(1px, 2px); }
  100% { transform: translate(0); }
}

.glitch--active::before,
.glitch--active::after {
  content: attr(data-text);
  padding: inherit;   /* the ghost text must sit exactly on the word */
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

.glitch--active::before {
  color: var(--neon-blue);
  animation: glitch-clip-1 2s infinite linear;
  clip-path: inset(0 0 70% 0);
  transform: translate(-2px);
}

.glitch--active::after {
  color: var(--neon-red);
  animation: glitch-clip-2 2s infinite linear;
  clip-path: inset(70% 0 0 0);
  transform: translate(2px);
}

@keyframes glitch-clip-1 {
  0%, 100% { clip-path: inset(0 0 70% 0); }
  25% { clip-path: inset(20% 0 50% 0); }
  50% { clip-path: inset(50% 0 20% 0); }
  75% { clip-path: inset(10% 0 60% 0); }
}

@keyframes glitch-clip-2 {
  0%, 100% { clip-path: inset(70% 0 0 0); }
  25% { clip-path: inset(50% 0 20% 0); }
  50% { clip-path: inset(20% 0 50% 0); }
  75% { clip-path: inset(60% 0 10% 0); }
}

/* Fade in */
.fade-in {
  opacity: 0;
  transform: translateY(10px);
  animation: fade-in-up 0.5s ease forwards;
}

.fade-in--delay-1 { animation-delay: 0.2s; }
.fade-in--delay-2 { animation-delay: 0.4s; }
.fade-in--delay-3 { animation-delay: 0.6s; }
.fade-in--delay-4 { animation-delay: 0.8s; }

@keyframes fade-in-up {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Pulse glow (active elements) */
.pulse-glow {
  animation: pulse-glow 2s ease-in-out infinite;
}

@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 0 5px rgba(0, 212, 255, 0.2); }
  50% { box-shadow: 0 0 20px rgba(0, 212, 255, 0.4); }
}

/* Stamp slam (keyframes only; the reveal and briefing use it) */
@keyframes stamp-slam {
  to {
    opacity: 0.85;
    transform: rotate(-5deg) scale(1);
  }
}

/* Blinking cursor (hacker terminal) */
.terminal-cursor {
  display: inline-block;
  width: 10px;
  height: 1.2em;
  background: var(--neon-green);
  animation: cursor-blink 1s step-end infinite;
  vertical-align: text-bottom;
}

@keyframes cursor-blink {
  50% { opacity: 0; }
}

/* Screen flicker (intro) */
.screen-flicker {
  animation: flicker 0.15s linear 3;
}

@keyframes flicker {
  0% { opacity: 1; }
  50% { opacity: 0.3; }
  100% { opacity: 1; }
}

/* ── Page transition ── */
.page-enter {
  animation: pageSlideIn 0.35s ease-out forwards;
}

@keyframes pageSlideIn {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Scale pop (for results, achievements) */
.scale-pop {
  opacity: 0;
  transform: scale(0.85);
  animation: scalePop 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes scalePop {
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* Staggered children — auto-stagger child elements */
.stagger-children > * {
  opacity: 0;
  transform: translateY(10px);
  animation: fade-in-up 0.4s ease forwards;
}
.stagger-children > *:nth-child(1) { animation-delay: 0.05s; }
.stagger-children > *:nth-child(2) { animation-delay: 0.10s; }
.stagger-children > *:nth-child(3) { animation-delay: 0.15s; }
.stagger-children > *:nth-child(4) { animation-delay: 0.20s; }
.stagger-children > *:nth-child(5) { animation-delay: 0.25s; }
.stagger-children > *:nth-child(6) { animation-delay: 0.30s; }
.stagger-children > *:nth-child(7) { animation-delay: 0.35s; }
.stagger-children > *:nth-child(8) { animation-delay: 0.40s; }
.stagger-children > *:nth-child(9) { animation-delay: 0.45s; }
.stagger-children > *:nth-child(10) { animation-delay: 0.50s; }

/* Reduce motion for accessibility */
@media (prefers-reduced-motion: reduce) {
  .fade-in, .scale-pop,
  .page-enter, .stagger-children > * {
    animation: none !important;
    opacity: 1 !important;
    transform: none !important;
  }
}

/* ═══ Touch layer (was tablet.css) ═══════════════════════════════ */
/* --- No horizontal overflow anywhere --- */
html, body { max-width: 100%; overflow-x: hidden; }
img, svg, video, canvas { max-width: 100%; height: auto; }

/* --- Form fields: >=16px font stops iOS/Safari auto-zoom; comfy height --- */
input, textarea, select, button { font-size: max(16px, 1rem); }
input[type="text"], input[type="password"], textarea, select {
  min-height: 48px;
}

/* --- Minimum tap targets (WCAG ~44-48px); the ds-* components carry their own --- */
.lang-switch__btn { min-height: 48px; }

/* Radio/checkbox option labels (settings, guest, solve) get a big hit area */
label:not(.ds-choice):has(> input[type="radio"]),
label:not(.ds-choice):has(> input[type="checkbox"]) {
  min-height: 48px;
  display: inline-flex;
  align-items: center;
}
input[type="radio"], input[type="checkbox"] { min-width: 22px; min-height: 22px; }

/* Language switch: bigger, finger-friendly */
.lang-switch__btn { padding: 10px 14px; min-width: 44px; text-align: center; }

/* --- Tablet portrait & up: roomier, two-column option grids --- */
@media (min-width: 600px) {
  #g-options {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }
}
