/* ==========================================================================
   2D Manga Sketchbook Portfolio Under Construction
   Hand-Drawn Ink Aesthetic + Interactive Umaru-Style Chibi
   ========================================================================== */

:root {
  /* Manga Drawing Palette: Neutral Ink & Paper */
  --paper-bg: #faf8f5;
  --paper-cream: #f4efe6;
  --ink-primary: #141413;
  --ink-secondary: #3a3733;
  --ink-muted: #726e67;
  --tone-light: #e8e4dc;
  --tone-mid: #c7c2b8;
  --tone-dark: #6e6a63;
  --white: #ffffff;

  /* Typography */
  --font-manga: 'Patrick Hand', cursive, sans-serif;
  --font-display: 'Fredoka', cursive, sans-serif;
  --font-system: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;

  /* Elevation: Sumi Ink Drop Shadows with Natural Paper Feathering */
  --shadow-ink-sm: 2px 2px 1px rgba(20, 20, 19, 0.7);
  --shadow-ink-md: 4px 4px 2px rgba(20, 20, 19, 0.65);
  --shadow-ink-lg: 5px 5px 3px rgba(20, 20, 19, 0.6);
}

/* Reset */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--paper-bg);
  color: var(--ink-primary);
  font-family: var(--font-manga);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  user-select: none;
}

/* Manga Paper Texture: Subtle Organic Grain (No synthetic grid) */
.manga-paper-texture {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  background-image: radial-gradient(circle at 50% 50%, rgba(20, 20, 19, 0.04) 1px, transparent 1px);
  background-size: 20px 20px;
  opacity: 0.75;
}

/* Main 2D Manga Stage */
.manga-stage {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
}

/* Centered Manga Narration Title Card */
.manga-title-card {
  position: absolute;
  top: 14%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  width: min(92vw, 680px);
  padding: 24px 32px 20px;
  background: var(--paper-bg);
  border: 3.5px solid var(--ink-primary);
  border-radius: 12px;
  box-shadow: var(--shadow-ink-lg);
  text-align: center;
  transition: transform 0.18s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Corner Push Pins */
.title-pin {
  position: absolute;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--ink-primary);
  box-shadow: 1px 1px 1px rgba(20, 20, 19, 0.35);
}

.title-pin.top-left {
  top: 10px;
  left: 12px;
}

.title-pin.top-right {
  top: 10px;
  right: 12px;
}

.manga-headline {
  font-family: var(--font-manga);
  font-size: clamp(1.8rem, 4.4vw, 2.75rem);
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.01em;
  color: var(--ink-primary);
  display: inline-block;
}

.animated-dots {
  display: inline-block;
  letter-spacing: 0.08em;
  font-weight: 700;
}

.animated-dots .dot {
  display: inline-block;
  animation: dotWave 1.4s infinite ease-in-out;
}

.animated-dots .dot:nth-child(1) { animation-delay: 0.0s; }
.animated-dots .dot:nth-child(2) { animation-delay: 0.18s; }
.animated-dots .dot:nth-child(3) { animation-delay: 0.36s; }
.animated-dots .dot:nth-child(4) { animation-delay: 0.54s; }
.animated-dots .dot:nth-child(5) { animation-delay: 0.72s; }

@keyframes dotWave {
  0%, 100% {
    transform: translateY(0);
    opacity: 0.35;
  }
  35% {
    transform: translateY(-5px);
    opacity: 1;
  }
}

/* Title Card Bonk Wobble (When hit from below by thrown chibi) */
.manga-title-card.card-bonked {
  animation: cardImpulse 0.36s cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes cardImpulse {
  0% { transform: translate(-50%, 0); }
  25% { transform: translate(calc(-50% - 3px), -4px) rotate(-1deg); }
  50% { transform: translate(calc(-50% + 3px), -2px) rotate(1deg); }
  75% { transform: translate(calc(-50% - 1px), -1px) rotate(-0.5deg); }
  100% { transform: translate(-50%, 0); }
}

/* ==========================================================================
   Unfinished Fading Handle in Background (@ryanc / @ryancuizon)
   Positioned in background between title card and ground horizon line
   ========================================================================== */
.manga-draft-handle {
  position: absolute;
  top: 40%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(94vw, 920px);
  z-index: 2;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  user-select: none;
}

.draft-ruler {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  max-width: 680px;
  margin-bottom: 8px;
  font-family: 'Syne', sans-serif;
  font-size: clamp(0.68rem, 1.3vw, 0.82rem);
  font-weight: 700;
  letter-spacing: 0.22em;
  color: var(--ink-muted);
}

.draft-ruler .ruler-line {
  flex: 1;
  height: 0;
  border-bottom: 1.5px dashed var(--tone-dark);
  opacity: 0.55;
}

.draft-ruler .ruler-tick {
  color: var(--ink-secondary);
  font-weight: 800;
  font-size: 0.95rem;
}

.draft-watermark {
  font-family: 'Syne', sans-serif;
  font-size: clamp(2.8rem, 7.8vw, 6.2rem);
  font-weight: 800;
  line-height: 1.0;
  letter-spacing: -0.035em;
  white-space: nowrap;
  display: flex;
  align-items: baseline;
  justify-content: center;
  filter: drop-shadow(2px 2px 0 var(--tone-light));
}

.handle-solid {
  color: var(--ink-primary);
  font-weight: 800;
  letter-spacing: -0.03em;
  display: inline-block;
}

/* Blinking inking drafting cursor between solid and unfinished */
.draft-cursor {
  display: inline-block;
  width: 4px;
  height: clamp(2.6rem, 7.2vw, 5.6rem);
  background: var(--ink-primary);
  margin: 0 4px 0 2px;
  animation: draftCursorBlink 1.1s infinite steps(2, start);
  vertical-align: middle;
}

@keyframes draftCursorBlink {
  0%, 100% { opacity: 0.85; }
  50% { opacity: 0; }
}

.handle-unfinished {
  display: inline-flex;
  align-items: baseline;
  letter-spacing: -0.03em;
}

/* Fading letters u-i-z-o-n fading progressively */
.fading-char {
  display: inline-block;
  transition: opacity 0.3s ease;
}

.char-u {
  color: var(--ink-secondary);
  opacity: 0.52;
  border-bottom: 2.5px dashed var(--tone-dark);
}

.char-i {
  color: var(--ink-muted);
  opacity: 0.38;
  border-bottom: 2px dotted var(--tone-mid);
}

.char-z {
  color: transparent;
  -webkit-text-stroke: 2px var(--tone-dark);
  opacity: 0.26;
  border-bottom: 1.5px dashed var(--tone-mid);
}

.char-o {
  color: transparent;
  -webkit-text-stroke: 1.5px var(--tone-mid);
  opacity: 0.16;
}

.char-n {
  color: transparent;
  -webkit-text-stroke: 1.2px var(--tone-mid);
  opacity: 0.08;
}

.draft-blueprint-line {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  max-width: 680px;
  margin-top: 10px;
  font-family: 'Syne', sans-serif;
  font-size: clamp(0.68rem, 1.3vw, 0.82rem);
  font-weight: 700;
  letter-spacing: 0.22em;
  color: var(--ink-muted);
}

.draft-blueprint-line .draft-guide-line {
  flex: 1;
  height: 0;
  border-bottom: 1.5px dashed var(--tone-mid);
  opacity: 0.55;
}

.draft-blueprint-line .draft-tick {
  color: var(--ink-secondary);
  font-weight: 800;
  font-size: 0.95rem;
}

/* 60fps Manga Ink FX Canvas */
#fx-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 10;
}

/* Hand-Drawn Sketch Ground Horizon Line */
.manga-ground-line {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 18%;
  height: 3.5px;
  background: var(--ink-primary);
  z-index: 5;
}

.manga-ground-line::after {
  content: '';
  position: absolute;
  left: 4%;
  right: 4%;
  top: 7px;
  height: 2px;
  border-bottom: 2px dashed var(--tone-mid);
  opacity: 0.6;
}

/* ==========================================================================
   Hand-Drawn Construction & Snack Station on Horizon Line
   ========================================================================== */
.manga-workstation {
  position: absolute;
  left: 50%;
  bottom: 18%;
  transform: translateX(-50%);
  width: min(92vw, 520px);
  height: 120px;
  pointer-events: none;
  z-index: 15;
}

/* Blueprint / Work Mat */
.work-mat {
  position: absolute;
  bottom: -2px;
  left: 50%;
  transform: translateX(-50%);
  width: 290px;
  height: 26px;
  background: var(--paper-cream);
  border: 2px dashed var(--tone-dark);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 2px 2px 0 rgba(20, 20, 19, 0.15);
}

.mat-label {
  font-family: var(--font-manga);
  font-size: 0.8rem;
  letter-spacing: 0.14em;
  color: var(--ink-secondary);
  font-weight: 700;
}

/* Cornerstone Building Block (Under Umaru's Hammer) */
.site-block-prop {
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 76px;
  height: 56px;
  pointer-events: auto;
  z-index: 18;
}

/* Impact Spark on Cornerstone */
.impact-spark {
  animation: sparkFlicker 4.2s infinite ease-in-out;
  transform-origin: 38px 8px;
}

@keyframes sparkFlicker {
  0%, 10% { opacity: 0; transform: scale(0.4); }
  12%, 14% { opacity: 1; transform: scale(1.2); }
  16%, 26% { opacity: 0; transform: scale(0.4); }
  28%, 30% { opacity: 1; transform: scale(1.2); }
  32%, 42% { opacity: 0; transform: scale(0.4); }
  44%, 47% { opacity: 1; transform: scale(1.35); }
  49%, 100% { opacity: 0; transform: scale(0.4); }
}

/* Interactive Snack Props (Chips & Coke) */
.snack-prop {
  position: absolute;
  bottom: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  pointer-events: auto;
  transition: transform 0.18s cubic-bezier(0.16, 1, 0.3, 1);
  outline: none;
  z-index: 25;
}

.snack-chips {
  left: calc(50% - 195px);
  transform-origin: bottom center;
}

.snack-coke {
  left: calc(50% + 135px);
  transform-origin: bottom center;
}

.snack-prop:hover {
  transform: translateY(-4px) scale(1.05);
}

.snack-prop:active,
.snack-prop.pop {
  animation: snackPop 0.36s cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes snackPop {
  0% { transform: translateY(0) scale(1); }
  40% { transform: translateY(-10px) scale(1.08); }
  100% { transform: translateY(0) scale(1); }
}

.snack-label {
  margin-top: 3px;
  font-family: var(--font-manga);
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--ink-secondary);
  background: var(--paper-bg);
  border: 1.5px solid var(--ink-primary);
  border-radius: 9999px;
  padding: 1px 8px;
  box-shadow: 1px 1px 0 var(--ink-primary);
  transition: transform 0.15s ease, background 0.15s ease;
}

.snack-prop:hover .snack-label {
  transform: scale(1.06);
  background: var(--paper-cream);
}

/* ==========================================================================
   Interactive Chibi Actor Container
   ========================================================================== */
.chibi-actor {
  position: absolute;
  top: 0;
  left: 0;
  width: 220px;
  height: 220px;
  z-index: 30;
  cursor: grab;
  touch-action: none;
  will-change: transform;
  outline: none;
}

.chibi-actor.is-grabbed {
  cursor: grabbing;
}

.chibi-svg-root {
  width: 100%;
  height: 100%;
  overflow: visible;
}

/* Manga Speech Bubble */
.chibi-speech-bubble {
  position: absolute;
  bottom: 95%;
  left: 50%;
  transform: translateX(-50%) scale(0.9);
  background: var(--paper-bg);
  border: 2.5px solid var(--ink-primary);
  border-radius: 9999px;
  padding: 6px 14px;
  box-shadow: var(--shadow-ink-sm);
  white-space: nowrap;
  font-family: var(--font-manga);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--ink-primary);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.18s ease, transform 0.22s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 40;
}

.chibi-speech-bubble.active {
  opacity: 1;
  transform: translateX(-50%) scale(1);
}

.speech-tail {
  position: absolute;
  bottom: -9px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
  border-top: 9px solid var(--ink-primary);
}

.speech-tail::after {
  content: '';
  position: absolute;
  bottom: 2px;
  left: -5px;
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 7px solid var(--paper-bg);
}

/* ==========================================================================
   Chibi SVG Expressions & Dynamic Parts
   ========================================================================== */
.eye-state,
.mouth-state {
  display: none;
}

.eye-state.active,
.mouth-state.active {
  display: inline;
}

/* Hood Ears Twitch Animation */
.hood-ear {
  transition: transform 0.16s cubic-bezier(0.16, 1, 0.3, 1);
}

.chibi-actor:hover #hood-ear-left {
  transform: rotate(-10deg);
}

.chibi-actor:hover #hood-ear-right {
  transform: rotate(10deg);
}

/* ==========================================================================
   2D Chibi Pose Switching & Manga Turn-and-Build Loop
   ========================================================================== */

/* Base Pose Visibility: Front Pose is Default (Shown during hits, flails, throws) */
#chibi-front-pose {
  display: inline;
  opacity: 1;
}

#chibi-back-pose {
  display: none;
  opacity: 0;
}

/* Master Turn-and-Build Loop in Idle State */
.chibi-actor.state-idle #chibi-front-pose {
  animation: frontPoseLoop 8.4s infinite ease-in-out;
}

.chibi-actor.state-idle #chibi-back-pose {
  display: inline;
  animation: backPoseLoop 8.4s infinite ease-in-out;
}

/* Whole Body 3D/2D Turn Squash & Bounce */
.chibi-actor.state-idle #chibi-squash-root {
  animation: chibiTurnSquashBob 8.4s infinite ease-in-out;
}

/* Front Pose Visibility Cycle:
   0% to 19%: Visible
   20% to 75%: Hidden (facing back)
   76% to 100%: Visible (turned back around to front)
*/
@keyframes frontPoseLoop {
  0%, 19% {
    opacity: 1;
    visibility: visible;
  }
  20%, 75% {
    opacity: 0;
    visibility: hidden;
  }
  76%, 100% {
    opacity: 1;
    visibility: visible;
  }
}

/* Back Pose Visibility Cycle:
   0% to 19%: Hidden
   20% to 75%: Visible (facing back & building)
   76% to 100%: Hidden
*/
@keyframes backPoseLoop {
  0%, 19% {
    opacity: 0;
    visibility: hidden;
  }
  20%, 75% {
    opacity: 1;
    visibility: visible;
  }
  76%, 100% {
    opacity: 0;
    visibility: hidden;
  }
}

/* Body Squash & Turn Compression */
@keyframes chibiTurnSquashBob {
  /* Front Pose: Gentle idle breathing */
  0% { transform: scale(1, 1); }
  8% { transform: scale(1.03, 0.96); } /* Front mallet strike */
  12% { transform: scale(0.98, 1.02); }
  18% { transform: scale(1, 1); }

  /* Turn to Back Transition (2D horizontal compression flip!) */
  19% { transform: scale(1, 1); }
  20% { transform: scale(0.28, 1.05) translateY(-3px); }
  21% { transform: scale(1.05, 0.94); }
  22% { transform: scale(1, 1); }

  /* Back Pose: Heavy Construction Strikes Squash */
  28.5% { transform: scale(1.08, 0.91); } /* STRIKE 1 */
  31% { transform: scale(0.97, 1.03); }

  39.5% { transform: scale(1.08, 0.91); } /* STRIKE 2 */
  42% { transform: scale(0.97, 1.03); }

  /* Peek Back (46% - 53%) */
  48% { transform: scale(1.02, 1) rotate(2deg); }
  53% { transform: scale(1, 1) rotate(0deg); }

  58% { transform: scale(1.12, 0.88); } /* BIG STRIKE 3! */
  61% { transform: scale(0.95, 1.05); }

  66% { transform: scale(1.06, 0.93); } /* Tap 4 */
  69% { transform: scale(1, 1); }

  /* Turn Back to Front Transition */
  73.5% { transform: scale(1, 1); }
  74.5% { transform: scale(0.28, 1.05) translateY(-3px); }
  75.5% { transform: scale(1.05, 0.94); }
  76.5% { transform: scale(1, 1); }

  /* Proud Front Breather & Brow Wipe */
  85% { transform: scale(1.02, 1.02) translateY(-2px); }
  92% { transform: scale(1, 1); }
  100% { transform: scale(1, 1); }
}

/* Front Pose Arm Animations (Tapping block, wiping brow) */
.chibi-actor.state-idle #chibi-arm-right {
  animation: frontArmMallet 8.4s infinite ease-in-out;
  transform-origin: 166px 148px;
}

@keyframes frontArmMallet {
  0% { transform: rotate(0deg); }
  5% { transform: rotate(-32deg); }
  8% { transform: rotate(16deg); } /* Initial tap */
  12% { transform: rotate(0deg); }
  18%, 78% { transform: rotate(0deg); }
  84% { transform: rotate(-10deg); }
  92% { transform: rotate(0deg); }
  100% { transform: rotate(0deg); }
}

.chibi-actor.state-idle #chibi-arm-left {
  animation: frontArmBrowWipe 8.4s infinite ease-in-out;
  transform-origin: 54px 148px;
}

@keyframes frontArmBrowWipe {
  0%, 78% { transform: rotate(0deg); }
  /* Brow wipe upon turning back to front */
  82% { transform: rotate(-44deg) translateY(-8px); }
  88% { transform: rotate(-40deg) translateY(-8px); }
  94% { transform: rotate(0deg); }
  100% { transform: rotate(0deg); }
}

/* ==========================================================================
   Back Pose Active Tools: Hammer Swung & Sawing
   ========================================================================== */

/* Carpenter Hammer Swing in Back Pose */
.chibi-actor.state-idle #back-arm-hammer {
  animation: backHammerSwing 8.4s infinite ease-in-out;
  transform-origin: 164px 136px;
}

@keyframes backHammerSwing {
  0%, 21% { transform: rotate(0deg); }

  /* STRIKE 1 (24% - 31%) */
  24% { transform: rotate(-55deg); } /* Windup */
  28.5% { transform: rotate(32deg); } /* IMPACT 1! */
  31% { transform: rotate(12deg); } /* Rebound */

  /* STRIKE 2 (35% - 42%) */
  35% { transform: rotate(-58deg); } /* Windup */
  39.5% { transform: rotate(34deg); } /* IMPACT 2! */
  42% { transform: rotate(14deg); }

  /* Ready Hold while Peeking Back (46% - 53%) */
  46% { transform: rotate(-40deg); }
  52% { transform: rotate(-45deg); }

  /* MEGA STRIKE 3 (54% - 61%) */
  55% { transform: rotate(-68deg); } /* High Power Windup */
  58% { transform: rotate(38deg); } /* MAXIMUM IMPACT 3! */
  61% { transform: rotate(15deg); }

  /* Polish Tap 4 (63% - 68%) */
  64% { transform: rotate(-38deg); }
  66% { transform: rotate(26deg); }
  68% { transform: rotate(0deg); }

  72%, 100% { transform: rotate(0deg); }
}

/* Hammer Motion Arcs Flash */
.chibi-actor.state-idle .hammer-motion-arcs {
  animation: hammerArcsFlash 8.4s infinite ease-out;
}

@keyframes hammerArcsFlash {
  0%, 27% { opacity: 0; }
  28%, 29.5% { opacity: 1; }
  30%, 38% { opacity: 0; }
  39%, 40.5% { opacity: 1; }
  41%, 56.5% { opacity: 0; }
  57.5%, 59% { opacity: 1; }
  60%, 65% { opacity: 0; }
  65.5%, 66.5% { opacity: 0.8; }
  67%, 100% { opacity: 0; }
}

/* Hammer Impact Starburst Spark */
.chibi-actor.state-idle .hammer-impact-spark {
  animation: hammerSparkFlash 8.4s infinite ease-out;
}

@keyframes hammerSparkFlash {
  0%, 28% { opacity: 0; transform: translate(158px, 120px) scale(0.2); }
  28.5%, 29.5% { opacity: 1; transform: translate(158px, 120px) scale(1.25); }
  30.5%, 39% { opacity: 0; transform: translate(158px, 120px) scale(0.2); }
  39.5%, 40.5% { opacity: 1; transform: translate(158px, 120px) scale(1.3); }
  41.5%, 57.5% { opacity: 0; transform: translate(158px, 120px) scale(0.2); }
  58%, 59% { opacity: 1; transform: translate(158px, 120px) scale(1.45); }
  60.5%, 65.5% { opacity: 0; transform: translate(158px, 120px) scale(0.2); }
  66%, 67% { opacity: 0.9; transform: translate(158px, 120px) scale(1.1); }
  68%, 100% { opacity: 0; transform: translate(158px, 120px) scale(0.2); }
}

/* Sawing Motion in Back Pose */
.chibi-actor.state-idle #back-arm-saw {
  animation: backSawRhythm 8.4s infinite ease-in-out;
  transform-origin: 56px 142px;
}

@keyframes backSawRhythm {
  0%, 22% { transform: translate(0, 0) rotate(0deg); }

  /* Continuous rapid sawing action throughout the back pose building phase */
  23% { transform: translate(-10px, 4px) rotate(4deg); }
  25% { transform: translate(14px, -6px) rotate(-6deg); }
  27% { transform: translate(-12px, 5px) rotate(5deg); }
  30% { transform: translate(14px, -6px) rotate(-6deg); }
  33% { transform: translate(-12px, 5px) rotate(5deg); }
  36% { transform: translate(14px, -6px) rotate(-6deg); }
  39% { transform: translate(-12px, 5px) rotate(5deg); }
  42% { transform: translate(14px, -6px) rotate(-6deg); }
  45% { transform: translate(-10px, 4px) rotate(4deg); }

  /* Steady stroke during peek */
  48% { transform: translate(12px, -5px) rotate(-5deg); }
  51% { transform: translate(-10px, 4px) rotate(4deg); }

  /* Rapid sawing burst */
  54% { transform: translate(14px, -6px) rotate(-6deg); }
  57% { transform: translate(-14px, 6px) rotate(6deg); }
  60% { transform: translate(14px, -6px) rotate(-6deg); }
  63% { transform: translate(-12px, 5px) rotate(5deg); }
  66% { transform: translate(12px, -5px) rotate(-5deg); }
  69% { transform: translate(-8px, 3px) rotate(3deg); }
  72% { transform: translate(0, 0) rotate(0deg); }

  73%, 100% { transform: translate(0, 0) rotate(0deg); }
}

/* Saw Speedlines Flash */
.chibi-actor.state-idle .saw-speedlines {
  animation: sawSpeedlinesVibe 8.4s infinite ease-in-out;
}

@keyframes sawSpeedlinesVibe {
  0%, 22% { opacity: 0; }
  23%, 45% { opacity: 0.85; }
  46%, 53% { opacity: 0.4; }
  54%, 70% { opacity: 0.9; }
  72%, 100% { opacity: 0; }
}

/* Cute Peek-Back Face Profile Animation */
.chibi-actor.state-idle #back-peek-face {
  animation: peekBackFaceCycle 8.4s infinite ease-in-out;
  transform-origin: 155px 95px;
}

@keyframes peekBackFaceCycle {
  0%, 44% {
    opacity: 0;
    transform: translate(-12px, 4px) scale(0.85);
  }
  46%, 52% {
    opacity: 1;
    transform: translate(0, 0) scale(1);
  }
  54%, 100% {
    opacity: 0;
    transform: translate(-8px, 2px) scale(0.9);
  }
}

/* ==========================================================================
   Construction Effects: Smoke, Nails, Bricks, Wood Splinters
   ========================================================================== */

/* 1. Billowing Manga Smoke Clouds */
.chibi-actor.state-idle .smoke-puff.puff-1 {
  animation: smokePuffOne 8.4s infinite ease-out;
  transform-origin: 78px 135px;
}

@keyframes smokePuffOne {
  0%, 28% {
    opacity: 0;
    transform: scale(0.2) translate(0, 0);
  }
  29% {
    opacity: 0.95;
    transform: scale(1.0) translate(-8px, -12px);
  }
  33% {
    opacity: 0.8;
    transform: scale(1.5) translate(-22px, -32px);
  }
  36%, 100% {
    opacity: 0;
    transform: scale(1.8) translate(-32px, -45px);
  }
}

.chibi-actor.state-idle .smoke-puff.puff-2 {
  animation: smokePuffTwo 8.4s infinite ease-out;
  transform-origin: 135px 135px;
}

@keyframes smokePuffTwo {
  0%, 39% {
    opacity: 0;
    transform: scale(0.2) translate(0, 0);
  }
  40% {
    opacity: 0.95;
    transform: scale(1.1) translate(10px, -14px);
  }
  44% {
    opacity: 0.75;
    transform: scale(1.6) translate(24px, -35px);
  }
  47%, 100% {
    opacity: 0;
    transform: scale(1.9) translate(34px, -50px);
  }
}

.chibi-actor.state-idle .smoke-puff.puff-3 {
  animation: smokePuffThree 8.4s infinite ease-out;
  transform-origin: 110px 125px;
}

@keyframes smokePuffThree {
  0%, 57% {
    opacity: 0;
    transform: scale(0.25) translate(0, 0);
  }
  58% {
    opacity: 1;
    transform: scale(1.2) translate(0, -18px);
  }
  62% {
    opacity: 0.7;
    transform: scale(1.7) translate(-6px, -42px);
  }
  65%, 100% {
    opacity: 0;
    transform: scale(2.0) translate(-10px, -60px);
  }
}

.chibi-actor.state-idle .smoke-puff.puff-4 {
  animation: smokePuffFour 8.4s infinite ease-out;
  transform-origin: 60px 138px;
}

@keyframes smokePuffFour {
  0%, 24% {
    opacity: 0;
    transform: scale(0.3);
  }
  26%, 66% {
    opacity: 0.7;
    transform: scale(1.1) translate(-10px, -14px);
  }
  70%, 100% {
    opacity: 0;
    transform: scale(1.4) translate(-18px, -24px);
  }
}

/* 2. Flying Nails */
.chibi-actor.state-idle .flying-nail.nail-1 {
  animation: nailOneFly 8.4s infinite cubic-bezier(0.2, 0.8, 0.4, 1);
  transform-origin: 35px 110px;
}

@keyframes nailOneFly {
  0%, 28% {
    opacity: 0;
    transform: translate(35px, 110px) scale(0.3) rotate(0deg);
  }
  29% {
    opacity: 1;
    transform: translate(25px, 90px) scale(1) rotate(-90deg);
  }
  33% {
    opacity: 1;
    transform: translate(-10px, 75px) scale(1) rotate(-220deg);
  }
  36%, 100% {
    opacity: 0;
    transform: translate(-45px, 120px) scale(0.8) rotate(-380deg);
  }
}

.chibi-actor.state-idle .flying-nail.nail-2 {
  animation: nailTwoFly 8.4s infinite cubic-bezier(0.2, 0.8, 0.4, 1);
  transform-origin: 185px 95px;
}

@keyframes nailTwoFly {
  0%, 39% {
    opacity: 0;
    transform: translate(160px, 120px) scale(0.3) rotate(0deg);
  }
  40% {
    opacity: 1;
    transform: translate(185px, 95px) scale(1) rotate(90deg);
  }
  44% {
    opacity: 1;
    transform: translate(220px, 75px) scale(1) rotate(240deg);
  }
  47%, 100% {
    opacity: 0;
    transform: translate(250px, 120px) scale(0.8) rotate(390deg);
  }
}

.chibi-actor.state-idle .flying-nail.nail-3 {
  animation: nailThreeFly 8.4s infinite cubic-bezier(0.2, 0.8, 0.4, 1);
  transform-origin: 110px 60px;
}

@keyframes nailThreeFly {
  0%, 57% {
    opacity: 0;
    transform: translate(110px, 130px) scale(0.3) rotate(0deg);
  }
  58% {
    opacity: 1;
    transform: translate(110px, 70px) scale(1) rotate(140deg);
  }
  61% {
    opacity: 1;
    transform: translate(115px, 25px) scale(1) rotate(290deg);
  }
  64%, 100% {
    opacity: 0;
    transform: translate(122px, 80px) scale(0.8) rotate(450deg);
  }
}

.chibi-actor.state-idle .flying-nail.nail-4 {
  animation: nailFourFly 8.4s infinite cubic-bezier(0.2, 0.8, 0.4, 1);
  transform-origin: 48px 80px;
}

@keyframes nailFourFly {
  0%, 65% {
    opacity: 0;
    transform: translate(65px, 125px) scale(0.3);
  }
  66% {
    opacity: 1;
    transform: translate(40px, 85px) scale(1) rotate(-110deg);
  }
  69%, 100% {
    opacity: 0;
    transform: translate(10px, 120px) scale(0.7) rotate(-280deg);
  }
}

/* 3. Flying Bricks */
.chibi-actor.state-idle .flying-brick.brick-1 {
  animation: brickOneTumble 8.4s infinite cubic-bezier(0.2, 0.8, 0.4, 1);
  transform-origin: 20px 70px;
}

@keyframes brickOneTumble {
  0%, 39% {
    opacity: 0;
    transform: translate(60px, 130px) scale(0.4) rotate(0deg);
  }
  40% {
    opacity: 1;
    transform: translate(25px, 80px) scale(1) rotate(-45deg);
  }
  43% {
    opacity: 1;
    transform: translate(-10px, 50px) scale(1.05) rotate(-110deg);
  }
  47%, 100% {
    opacity: 0;
    transform: translate(-45px, 130px) scale(0.85) rotate(-220deg);
  }
}

.chibi-actor.state-idle .flying-brick.brick-2 {
  animation: brickTwoTumble 8.4s infinite cubic-bezier(0.2, 0.8, 0.4, 1);
  transform-origin: 195px 75px;
}

@keyframes brickTwoTumble {
  0%, 57% {
    opacity: 0;
    transform: translate(145px, 135px) scale(0.4) rotate(0deg);
  }
  58% {
    opacity: 1;
    transform: translate(185px, 75px) scale(1.05) rotate(45deg);
  }
  61% {
    opacity: 1;
    transform: translate(220px, 45px) scale(1.1) rotate(130deg);
  }
  65%, 100% {
    opacity: 0;
    transform: translate(250px, 130px) scale(0.85) rotate(260deg);
  }
}

.chibi-actor.state-idle .flying-brick.brick-3 {
  animation: brickThreeTumble 8.4s infinite cubic-bezier(0.2, 0.8, 0.4, 1);
  transform-origin: 105px 45px;
}

@keyframes brickThreeTumble {
  0%, 57.5% {
    opacity: 0;
    transform: translate(110px, 125px) scale(0.3) rotate(0deg);
  }
  58.5% {
    opacity: 1;
    transform: translate(105px, 55px) scale(1) rotate(80deg);
  }
  62% {
    opacity: 0.8;
    transform: translate(100px, 15px) scale(1) rotate(190deg);
  }
  65%, 100% {
    opacity: 0;
    transform: translate(95px, 90px) scale(0.7) rotate(320deg);
  }
}

/* 4. Flying Wood Chips & Sawdust */
.chibi-actor.state-idle .anim-wood-group .flying-chip {
  animation: woodChipSpray 8.4s infinite ease-out;
}

.chibi-actor.state-idle .chip-1 { transform-origin: 48px 130px; animation-delay: 0.1s; }
.chibi-actor.state-idle .chip-2 { transform-origin: 73px 120px; animation-delay: 0.25s; }
.chibi-actor.state-idle .chip-3 { transform-origin: 145px 124px; animation-delay: 0.35s; }
.chibi-actor.state-idle .chip-4 { transform-origin: 74px 138px; animation-delay: 0.15s; }
.chibi-actor.state-idle .chip-5 { transform-origin: 82px 132px; animation-delay: 0.45s; }
.chibi-actor.state-idle .chip-6 { transform-origin: 62px 140px; animation-delay: 0.05s; }
.chibi-actor.state-idle .chip-7 { transform-origin: 136px 122px; animation-delay: 0.3s; }
.chibi-actor.state-idle .chip-8 { transform-origin: 52px 128px; animation-delay: 0.2s; }

@keyframes woodChipSpray {
  0%, 22% {
    opacity: 0;
    transform: scale(0.3) translate(0, 0);
  }
  24%, 38% {
    opacity: 1;
    transform: scale(1.1) translate(-14px, -18px) rotate(-45deg);
  }
  39% {
    opacity: 0;
    transform: scale(0.6) translate(-26px, 10px) rotate(-90deg);
  }
  40%, 53% {
    opacity: 0.9;
    transform: scale(1.1) translate(16px, -20px) rotate(55deg);
  }
  54% {
    opacity: 0;
    transform: scale(0.6) translate(28px, 10px) rotate(110deg);
  }
  57%, 68% {
    opacity: 1;
    transform: scale(1.2) translate(-18px, -26px) rotate(-80deg);
  }
  70%, 100% {
    opacity: 0;
    transform: scale(0.5) translate(-32px, 12px) rotate(-160deg);
  }
}

/* Hardhat slight tilt on strikes */
.chibi-actor.state-idle #chibi-hardhat,
.chibi-actor.state-idle #back-chibi-hardhat {
  animation: hardhatTilt 8.4s infinite cubic-bezier(0.16, 1, 0.3, 1);
  transform-origin: 110px 24px;
}

@keyframes hardhatTilt {
  0%, 7% { transform: rotate(0deg); }
  8% { transform: rotate(2deg); }
  10% { transform: rotate(0deg); }
  28.5% { transform: rotate(-3deg); }
  31% { transform: rotate(0deg); }
  39.5% { transform: rotate(3deg); }
  42% { transform: rotate(0deg); }
  58% { transform: rotate(-4deg); }
  61% { transform: rotate(0deg); }
  100% { transform: rotate(0deg); }
}

/* Anger Vein Pulsing */
.anger-vein.active {
  opacity: 1;
  animation: veinPulse 0.55s infinite alternate ease-in-out;
}

@keyframes veinPulse {
  0% { transform: translate(150px, 48px) scale(0.85); }
  100% { transform: translate(150px, 48px) scale(1.15); }
}

/* Sweat Drop Tremble */
.sweat-drop.active {
  opacity: 1;
  animation: sweatSlide 1.2s infinite ease-in-out;
}

@keyframes sweatSlide {
  0% { transform: translate(162px, 92px); opacity: 0.8; }
  60% { transform: translate(162px, 104px); opacity: 1; }
  100% { transform: translate(162px, 114px); opacity: 0; }
}

/* Arm Flailing during tantrums / drops */
.chibi-actor.flailing #chibi-arm-left {
  animation: armFlailLeft 0.16s infinite alternate ease-in-out;
}

.chibi-actor.flailing #chibi-arm-right {
  animation: armFlailRight 0.16s infinite alternate ease-in-out;
}

@keyframes armFlailLeft {
  0% { transform: rotate(-25deg); }
  100% { transform: rotate(35deg); }
}

@keyframes armFlailRight {
  0% { transform: rotate(25deg); }
  100% { transform: rotate(-35deg); }
}

/* Tantrum Floor Roll (Umaru-Style rolling side to side) */
.chibi-actor.state-rolling #chibi-squash-root {
  animation: umaruRoll 0.6s infinite linear;
}

@keyframes umaruRoll {
  0% { transform: rotate(0deg) scale(1.05, 0.95); }
  50% { transform: rotate(180deg) scale(0.95, 1.05); }
  100% { transform: rotate(360deg) scale(1.05, 0.95); }
}

/* Keyboard Focus Outline */
.chibi-actor:focus-visible,
.snack-prop:focus-visible {
  outline: 3px dashed var(--ink-primary);
  outline-offset: 4px;
}

/* Accessibility: Reduced Motion */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Responsive Breakpoints */
@media (max-width: 768px) {
  .manga-title-card {
    top: 10%;
    padding: 18px 20px 16px;
  }

  .manga-draft-handle {
    top: 36%;
    width: 90vw;
  }

  .draft-watermark {
    font-size: clamp(1.15rem, 5.2vw, 2.2rem);
    letter-spacing: -0.04em;
  }

  .draft-cursor {
    height: clamp(1.1rem, 5vw, 2rem);
    width: 2px;
    margin: 0 2px;
  }

  .draft-ruler,
  .draft-blueprint-line {
    font-size: 0.62rem;
    letter-spacing: 0.12em;
    gap: 6px;
    max-width: 92vw;
  }

  .chibi-actor {
    width: 180px;
    height: 180px;
  }

  .manga-ground-line {
    bottom: 16%;
  }

  .manga-workstation {
    bottom: 16%;
    width: 96vw;
  }

  .snack-chips {
    left: calc(50% - 135px);
    transform: scale(0.85);
  }
  .snack-chips:hover {
    transform: scale(0.88) translateY(-3px);
  }

  .snack-coke {
    left: calc(50% + 85px);
    transform: scale(0.85);
  }
  .snack-coke:hover {
    transform: scale(0.88) translateY(-3px);
  }

  .work-mat {
    width: 230px;
  }
}
