/* ============================================================
   Handwriting Simulation Visualization — style.css
   Vidya v3 AI Video Engine — Headless Playwright Compatible
   Uses only CSS / SVG — no Canvas / no WebGL
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Caveat:wght@400;500;600;700&family=Patrick+Hand&family=Architects+Daughter&family=Kalam:wght@300;400;700&display=swap');

/* ── Reset & Base ─────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  /* Whiteboard palette */
  --wb-bg:             #f8f6f0;
  --wb-bg-grain:       url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='300' height='300' filter='url(%23n)' opacity='0.03'/%3E%3C/svg%3E");
  --wb-ink:            #1a1a2e;
  --wb-ink-alt:        #16213e;
  --wb-accent:         #e94560;
  --wb-accent2:        #0f3460;
  --wb-frame:          #d0ccc0;
  --wb-shadow:         rgba(0,0,0,0.15);
  --wb-cursor:         #2563eb;

  /* Blackboard palette */
  --bb-bg:             #1a2332;
  --bb-bg-deep:        #0f1923;
  --bb-chalk:          #f0ece0;
  --bb-chalk-dim:      rgba(240,236,224,0.82);
  --bb-chalk-faint:    rgba(240,236,224,0.55);
  --bb-chalk-accent:   #f4d03f;
  --bb-chalk-red:      #e74c3c;
  --bb-chalk-blue:     #5dade2;
  --bb-chalk-green:    #58d68d;
  --bb-frame:          #2c1810;
  --bb-shadow:         rgba(0,0,0,0.55);

  /* Typography */
  --font-handwritten:  'Caveat', 'Kalam', cursive;
  --font-architect:    'Architects Daughter', 'Patrick Hand', cursive;

  /* Animation timing tokens */
  --ease-natural:      cubic-bezier(0.23, 1, 0.32, 1);
  --ease-ink:          cubic-bezier(0.25, 0.46, 0.45, 0.94);
  --ease-bounce:       cubic-bezier(0.34, 1.56, 0.64, 1);
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #111;
  font-family: var(--font-handwritten);
}

/* ── Board Container ──────────────────────────────────────── */
#board-wrapper {
  width: 100vw;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0d0d0d;
}

#board {
  width: 1280px;
  height: 720px;
  position: relative;
  overflow: hidden;
  border-radius: 4px;
  transition: background 0.6s ease;
}

/* ── Whiteboard Surface ───────────────────────────────────── */
#board.whiteboard {
  background-color: var(--wb-bg);
  box-shadow:
    inset 0 0 60px rgba(0,0,0,0.04),
    0 20px 60px var(--wb-shadow),
    0 0 0 12px var(--wb-frame),
    0 0 0 14px rgba(0,0,0,0.1);
}

/* Subtle whiteboard paper texture */
#board.whiteboard::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 39px,
      rgba(0,100,200,0.04) 39px,
      rgba(0,100,200,0.04) 40px
    );
  pointer-events: none;
  z-index: 0;
}

/* Whiteboard sheen */
#board.whiteboard::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    135deg,
    rgba(255,255,255,0.35) 0%,
    transparent 40%,
    transparent 70%,
    rgba(255,255,255,0.08) 100%
  );
  pointer-events: none;
  z-index: 0;
}

/* ── Blackboard Surface ───────────────────────────────────── */
#board.blackboard {
  background-color: var(--bb-bg);
  box-shadow:
    inset 0 0 80px rgba(0,0,0,0.5),
    inset 0 0 20px rgba(0,0,0,0.3),
    0 20px 60px var(--bb-shadow),
    0 0 0 18px var(--bb-frame),
    0 0 0 22px #1a0a00,
    0 0 0 24px rgba(0,0,0,0.2);
}

/* Blackboard chalk dust & grain texture */
#board.blackboard::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='400' height='400'%3E%3Cfilter id='chalk'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix type='matrix' values='0 0 0 0 0.9 0 0 0 0 0.9 0 0 0 0 0.85 0 0 0 0.04 0'/%3E%3C/filter%3E%3Crect width='400' height='400' filter='url(%23chalk)'/%3E%3C/svg%3E");
  opacity: 0.6;
  pointer-events: none;
  z-index: 0;
}

/* Blackboard subtle vignette */
#board.blackboard::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(
    ellipse at center,
    transparent 55%,
    rgba(0,0,0,0.35) 100%
  );
  pointer-events: none;
  z-index: 0;
}

/* ── SVG Drawing Layer ────────────────────────────────────── */
#drawing-layer {
  position: absolute;
  inset: 0;
  z-index: 2;
  overflow: visible;
}

/* ── Text Content Layer ───────────────────────────────────── */
#content-layer {
  position: absolute;
  inset: 0;
  z-index: 3;
  padding: 48px 64px;
  display: flex;
  flex-direction: column;
  gap: 0;
}

/* ── UI Controls Overlay ──────────────────────────────────── */
#controls-bar {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 12px;
  z-index: 100;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(12px);
  padding: 10px 20px;
  border-radius: 50px;
  border: 1px solid rgba(255,255,255,0.1);
}

#controls-bar button {
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.2);
  color: #fff;
  padding: 8px 18px;
  border-radius: 30px;
  cursor: pointer;
  font-size: 13px;
  font-family: system-ui, sans-serif;
  font-weight: 500;
  letter-spacing: 0.3px;
  transition: all 0.2s ease;
  white-space: nowrap;
}

#controls-bar button:hover {
  background: rgba(255,255,255,0.2);
  border-color: rgba(255,255,255,0.4);
  transform: translateY(-1px);
}

#controls-bar button.active {
  background: rgba(255,255,255,0.25);
  border-color: rgba(255,255,255,0.5);
}

#theme-indicator,
#stroke-indicator,
#tts-indicator {
  color: rgba(255,255,255,0.5);
  font-size: 12px;
  font-family: system-ui, sans-serif;
  display: flex;
  align-items: center;
  padding: 0 6px;
  border-right: 1px solid rgba(255,255,255,0.15);
  margin-right: 4px;
}

/* ── Writing Element Base ─────────────────────────────────── */
.hw-line {
  position: relative;
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  line-height: 1.5;
  margin-bottom: 0;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.hw-line.visible {
  opacity: 1;
  transform: translateY(0);
}

/* ── Text Elements ────────────────────────────────────────── */
.hw-text {
  font-family: var(--font-handwritten);
  line-height: 1.4;
  letter-spacing: 0.5px;
  position: relative;
}

/* Title style */
.hw-title {
  font-size: 54px;
  font-weight: 700;
  letter-spacing: -0.5px;
  line-height: 1.2;
  margin-bottom: 8px;
}

/* Subtitle */
.hw-subtitle {
  font-size: 32px;
  font-weight: 600;
  margin-bottom: 4px;
}

/* Body text */
.hw-body {
  font-size: 26px;
  font-weight: 400;
}

/* Small text */
.hw-small {
  font-size: 20px;
  font-weight: 400;
  opacity: 0.85;
}

/* Formula text */
.hw-formula {
  font-size: 28px;
  font-weight: 500;
  font-style: italic;
  letter-spacing: 1px;
}

/* Bullet point */
.hw-bullet {
  font-size: 24px;
  font-weight: 400;
  padding-left: 32px;
  position: relative;
}

/* Emphasis text */
.hw-emphasis {
  font-weight: 700;
  font-style: italic;
}

/* ── Whiteboard text colors ───────────────────────────────── */
.whiteboard .hw-title    { color: var(--wb-ink); }
.whiteboard .hw-subtitle { color: var(--wb-ink-alt); }
.whiteboard .hw-body     { color: var(--wb-ink); }
.whiteboard .hw-formula  { color: var(--wb-accent2); }
.whiteboard .hw-bullet   { color: var(--wb-ink); }
.whiteboard .hw-small    { color: rgba(26,26,46,0.7); }

/* ── Blackboard text colors ───────────────────────────────── */
.blackboard .hw-title    { color: var(--bb-chalk); }
.blackboard .hw-subtitle { color: var(--bb-chalk); }
.blackboard .hw-body     { color: var(--bb-chalk-dim); }
.blackboard .hw-formula  { color: var(--bb-chalk-accent); }
.blackboard .hw-bullet   { color: var(--bb-chalk-dim); }
.blackboard .hw-small    { color: var(--bb-chalk-faint); }

/* ── Chalk Text Effect ────────────────────────────────────── */
.blackboard .hw-text {
  text-shadow:
    0 0 8px rgba(240,236,224,0.3),
    1px 1px 0 rgba(0,0,0,0.15);
}

.blackboard .hw-title {
  text-shadow:
    0 0 15px rgba(240,236,224,0.25),
    0 0 30px rgba(240,236,224,0.1),
    2px 2px 0 rgba(0,0,0,0.2);
}

/* ── Marker / Chalk Stroke Appearance ────────────────────── */
/* Applied to SVG paths */
.stroke-marker {
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

.whiteboard .stroke-marker {
  stroke: #1a1a2e;
  filter: url(#marker-filter);
}

.blackboard .stroke-marker {
  stroke: #f0ece0;
  filter: url(#chalk-stroke-filter);
}

/* Accent colored strokes */
.stroke-accent {
  stroke: var(--wb-accent) !important;
}
.blackboard .stroke-accent {
  stroke: var(--bb-chalk-accent) !important;
}

.stroke-blue {
  stroke: var(--wb-accent2) !important;
}
.blackboard .stroke-blue {
  stroke: var(--bb-chalk-blue) !important;
}

.stroke-green {
  stroke: #27ae60 !important;
}
.blackboard .stroke-green {
  stroke: var(--bb-chalk-green) !important;
}

/* ── SVG Animation: stroke-dashoffset ────────────────────── */
/* All animated paths use stroke-dasharray = path length     */
/* JS sets these dynamically after measuring getTotalLength() */
.hw-path {
  stroke-dasharray: var(--path-length, 1000);
  stroke-dashoffset: var(--path-length, 1000);
  animation: none;
}

.hw-path.drawing {
  animation: draw-stroke var(--draw-duration, 1s) var(--ease-ink) forwards;
  animation-delay: var(--draw-delay, 0s);
}

@keyframes draw-stroke {
  to { stroke-dashoffset: 0; }
}

/* ── Cursor / Pen Tip ─────────────────────────────────────── */
.pen-cursor {
  position: absolute;
  width: 18px;
  height: 18px;
  pointer-events: none;
  z-index: 10;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.pen-cursor.visible {
  opacity: 1;
}

.pen-cursor::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  background: var(--wb-ink);
  box-shadow: 0 0 0 2px rgba(26,26,46,0.3);
}

.blackboard .pen-cursor::before {
  background: var(--bb-chalk);
  box-shadow: 0 0 6px rgba(240,236,224,0.5);
}

/* ── Character-level clip-path reveal ────────────────────── */
/* Used for text characters that reveal left-to-right */
.hw-char {
  display: inline-block;
  white-space: pre-wrap;
  clip-path: inset(-1.2em 100% -1.2em -0.5em);
  animation: reveal-char var(--char-duration, 0.08s) var(--ease-natural) forwards;
  animation-delay: var(--char-delay, 0s);
  animation-play-state: paused;
}

.hw-char.animate {
  animation-play-state: running;
}

.hw-tegaki-svg-wrapper {
  display: inline-block;
  line-height: 0;
  transform: translateY(3px);
}
.hw-tegaki-svg-wrapper svg {
  display: block;
}

@keyframes reveal-char {
  0%   { clip-path: inset(-1.2em 100% -1.2em -0.5em); opacity: 0.6; }
  40%  { clip-path: inset(-1.2em 20% -1.2em -0.5em);  opacity: 0.85; }
  100% { clip-path: inset(-1.2em -0.5em -1.2em -0.5em);   opacity: 1; }
}

/* ── Underline SVG animation ──────────────────────────────── */
.hw-underline {
  position: absolute;
  bottom: -4px;
  left: 0;
  width: 100%;
  height: 12px;
  overflow: visible;
}

/* ── Bullet dot SVG ───────────────────────────────────────── */
.bullet-dot {
  display: inline-block;
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
}

/* ── Box / Rect highlight ─────────────────────────────────── */
.hw-box-svg {
  position: absolute;
  overflow: visible;
  pointer-events: none;
}

/* ── Progress / status bar ────────────────────────────────── */
#progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  background: linear-gradient(90deg, #667eea, #764ba2, #f64f59);
  width: 0%;
  transition: width 0.3s ease;
  z-index: 200;
}

/* ── Speed indicator ──────────────────────────────────────── */
#speed-badge {
  position: fixed;
  top: 16px;
  right: 20px;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(8px);
  color: rgba(255,255,255,0.7);
  font-family: system-ui, monospace;
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 20px;
  border: 1px solid rgba(255,255,255,0.1);
  z-index: 100;
  letter-spacing: 0.5px;
}

/* ── Eraser animation ─────────────────────────────────────── */
@keyframes erase-line {
  0%   { clip-path: inset(-1.2em -0.5em -1.2em -0.5em); opacity: 1; }
  100% { clip-path: inset(-1.2em -0.5em -1.2em 100%); opacity: 0; }
}

.hw-line.erasing {
  animation: erase-line 0.4s var(--ease-natural) forwards;
}

/* ── SVG Filter Definitions (embedded inline) ─────────────── */
/* Applied via filter: url(#...) on elements */

/* ── Chalk dust particles ─────────────────────────────────── */
.chalk-particle {
  position: absolute;
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: rgba(240,236,224,0.6);
  pointer-events: none;
  animation: float-particle 1.2s ease-out forwards;
}

@keyframes float-particle {
  0%   { transform: translate(0,0) scale(1); opacity: 0.8; }
  100% { transform: translate(var(--px, 8px), var(--py, -20px)) scale(0); opacity: 0; }
}

/* ── Pulse ring for emphasis ──────────────────────────────── */
@keyframes pulse-ring {
  0%   { transform: scale(0.8); opacity: 0.8; }
  70%  { transform: scale(1.4); opacity: 0; }
  100% { transform: scale(1.4); opacity: 0; }
}

.pulse-ring {
  animation: pulse-ring 1s ease-out infinite;
}

/* ── Writing jitter effect ────────────────────────────────── */
/* Subtle SVG filter for natural pen wobble */
@keyframes subtle-jitter {
  0%, 100% { filter: url(#marker-filter); }
  50%       { filter: url(#marker-filter-jitter); }
}

/* ── Diagram label ────────────────────────────────────────── */
.diagram-label {
  position: absolute;
  font-family: var(--font-handwritten);
  font-size: 18px;
  pointer-events: none;
  white-space: nowrap;
}

.whiteboard .diagram-label { color: var(--wb-ink); }
.blackboard .diagram-label { color: var(--bb-chalk); }


