/* =====================================================================
   Happy Clock Game Styles (Ages 5-7)
   Analog Dial, Rotating Hands, Cuckoo Attic & Daily Routine Cards
   ===================================================================== */

:root {
  --wood-dark: #78350f;
  --wood-warm: #92400e;
  --wood-light: #fef3c7;
  --clock-cream: #fffbeb;
  --hour-color: #2563eb;
  --hour-dark: #1d4ed8;
  --min-color: #e11d48;
  --min-dark: #be123c;
  --dial-size: 320px;
  --hour-deg: 0deg;
  --min-deg: 0deg;
}

body {
  background: radial-gradient(circle at 50% 15%, #fde68a 0%, #fed7aa 50%, #fbcfe8 100%);
  color: #1e293b;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  overflow: hidden;
}

.game-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  box-sizing: border-box;
}

/* ---------------------------------------------------------------------
   Workspace Layout
   --------------------------------------------------------------------- */

.clock-workspace {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  max-width: 520px;
  width: 100%;
  margin: 0 auto;
  padding: 4px 12px 10px;
  box-sizing: border-box;
  position: relative;
}

/* ---------------------------------------------------------------------
   Routine Story Card
   --------------------------------------------------------------------- */

.routine-card {
  width: 100%;
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 3px solid #f59e0b;
  border-radius: 20px;
  padding: 8px 16px;
  box-shadow: 0 6px 16px rgba(180, 83, 9, 0.15);
  box-sizing: border-box;
}

.routine-header {
  display: flex;
  align-items: center;
  gap: 14px;
}

.event-icon {
  font-size: 2.4rem;
  line-height: 1;
  filter: drop-shadow(0 3px 5px rgba(0, 0, 0, 0.12));
}

.routine-text-group {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.event-title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 800;
  color: #78350f;
  line-height: 1.25;
}

.target-time-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #fef3c7;
  border: 2px solid #f59e0b;
  border-radius: 14px;
  padding: 2px 10px;
  width: fit-content;
  box-shadow: 0 2px 5px rgba(245, 158, 11, 0.2);
}

.target-time-text {
  font-size: 1.15rem;
  font-weight: 900;
  color: #b45309;
  letter-spacing: 0.5px;
}

/* ---------------------------------------------------------------------
   Clock Tower & Dial Face
   --------------------------------------------------------------------- */

.clock-stage {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  margin: auto 0;
}

/* Cuckoo Attic */
.cuckoo-tower {
  position: relative;
  width: 80px;
  height: 48px;
  margin-bottom: -10px;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.cuckoo-roof {
  width: 0;
  height: 0;
  border-left: 45px solid transparent;
  border-right: 45px solid transparent;
  border-bottom: 24px solid var(--wood-dark);
  filter: drop-shadow(0 3px 3px rgba(0, 0, 0, 0.2));
}

.cuckoo-attic {
  position: relative;
  width: 54px;
  height: 32px;
  background: #451a03;
  border: 3px solid var(--wood-dark);
  border-top: none;
  border-radius: 0 0 10px 10px;
  overflow: hidden;
}

.cuckoo-doors {
  position: absolute;
  inset: 0;
  display: flex;
  z-index: 2;
  transition: opacity 0.2s ease;
}

.door {
  flex: 1;
  background: #78350f;
  border: 1px solid #92400e;
  transition: transform 0.35s ease;
  transform-origin: left center;
}

.door-right {
  transform-origin: right center;
}

.cuckoo-attic.open .door-left {
  transform: perspective(200px) rotateY(-110deg);
}

.cuckoo-attic.open .door-right {
  transform: perspective(200px) rotateY(110deg);
}

.cuckoo-bird {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0);
  font-size: 1.6rem;
  line-height: 1;
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  z-index: 1;
}

.cuckoo-attic.open .cuckoo-bird {
  transform: translate(-50%, -50%) scale(1.2);
  animation: birdBob 0.4s infinite alternate ease-in-out;
}

@keyframes birdBob {
  0% { transform: translate(-50%, -50%) scale(1.2) translateY(0); }
  100% { transform: translate(-50%, -50%) scale(1.2) translateY(-3px); }
}

/* Clock Dial */
.clock-dial {
  position: relative;
  width: var(--dial-size);
  height: var(--dial-size);
  background: radial-gradient(circle, #ffffff 60%, var(--clock-cream) 100%);
  border: 10px solid var(--wood-warm);
  border-radius: 50%;
  box-shadow: 0 10px 25px rgba(120, 53, 15, 0.25), inset 0 0 15px rgba(180, 83, 9, 0.15);
  cursor: pointer;
  touch-action: none;
  outline: none;
}

.clock-dial:focus-visible {
  box-shadow: 0 0 0 4px #fbbf24, 0 10px 25px rgba(120, 53, 15, 0.25);
}

.dial-marks {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.hour-number {
  position: absolute;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.28rem;
  font-weight: 900;
  color: var(--hour-dark);
  transform: translate(-50%, -50%);
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.1));
}

.min-dot {
  position: absolute;
  width: 5px;
  height: 5px;
  background: #f43f5e;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  opacity: 0.65;
}

.min-dot.major {
  width: 8px;
  height: 8px;
  background: #be123c;
  opacity: 0.95;
}

/* Clock Hands */
.clock-hand {
  position: absolute;
  top: 50%;
  left: 50%;
  transform-origin: 50% 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: none;
  z-index: 5;
  transition: transform 0.28s cubic-bezier(0.34, 1.3, 0.64, 1);
}

.clock-dial.dragging .clock-hand {
  transition: none !important;
}

.clock-dial.dragging {
  cursor: grabbing;
}

.hour-hand {
  width: 10px;
  height: 72px;
  margin-left: -5px;
  margin-top: -72px;
  transform: rotate(var(--hour-deg));
}

.hour-hand .hand-arrow {
  width: 0;
  height: 0;
  border-left: 9px solid transparent;
  border-right: 9px solid transparent;
  border-bottom: 14px solid var(--hour-dark);
}

.hour-hand .hand-line {
  width: 10px;
  height: 59px;
  margin-top: -1px;
  background: linear-gradient(to right, #3b82f6, var(--hour-color));
  border-radius: 0 0 5px 5px;
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.25);
}

.min-hand {
  width: 6px;
  height: 115px;
  margin-left: -3px;
  margin-top: -115px;
  transform: rotate(var(--min-deg));
  z-index: 6;
}

.min-hand .hand-arrow {
  width: 0;
  height: 0;
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
  border-bottom: 18px solid var(--min-dark);
}

.min-hand .hand-line {
  width: 6px;
  height: 98px;
  margin-top: -1px;
  background: linear-gradient(to right, #fb7185, var(--min-color));
  border-radius: 0 0 3px 3px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

/* Center Pin */
.clock-center-pin {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 32px;
  height: 32px;
  background: radial-gradient(circle at 35% 35%, #fbbf24, #d97706);
  border: 3px solid #78350f;
  border-radius: 50%;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  pointer-events: none;
}

.pin-face {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.pin-eye {
  width: 4px;
  height: 4px;
  background: #451a03;
  border-radius: 50%;
  display: inline-block;
}

.pin-smile {
  width: 8px;
  height: 4px;
  border-bottom: 2px solid #451a03;
  border-radius: 0 0 6px 6px;
}

/* Digital Readout Under Clock */
.current-time-container {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  background: #ffffff;
  border: 3px solid var(--wood-warm);
  border-radius: 20px;
  padding: 4px 16px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
}

.current-time-icon {
  font-size: 1.25rem;
}

.current-digital-text {
  font-size: 1.35rem;
  font-weight: 900;
  color: #1e293b;
  font-family: monospace, monospace;
  letter-spacing: 1px;
}

/* ---------------------------------------------------------------------
   Controls Section
   --------------------------------------------------------------------- */

.controls-section {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.step-buttons-tray {
  display: flex;
  gap: 8px;
  width: 100%;
}

.step-btn {
  flex: 1;
  font-family: inherit;
  font-size: 0.96rem;
  font-weight: 800;
  padding: 10px 4px;
  border-radius: 16px;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
  transition: transform 0.1s ease, filter 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
}

.step-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  filter: brightness(1.1);
}

.step-btn:active:not(:disabled) {
  transform: scale(0.96);
}

.step-btn:disabled,
.action-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
  filter: grayscale(0.2);
}

.hour-step-btn {
  background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
  border-bottom: 3px solid #1e40af;
}

.half-step-btn {
  background: linear-gradient(135deg, #f43f5e 0%, #e11d48 100%);
  border-bottom: 3px solid #be123c;
}

.quarter-step-btn {
  background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
  border-bottom: 3px solid #b45309;
}

.action-buttons-tray {
  display: flex;
  gap: 8px;
  width: 100%;
}

.action-btn {
  font-family: inherit;
  font-size: 1.12rem;
  font-weight: 800;
  padding: 12px 16px;
  border-radius: 20px;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  transition: transform 0.1s ease, filter 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
}

.action-btn:active {
  transform: scale(0.96);
}

.check-btn {
  flex: 1;
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  border-bottom: 4px solid #047857;
}

.check-btn.ready {
  animation: checkPulse 0.9s infinite alternate ease-in-out;
}

@keyframes checkPulse {
  0% { transform: scale(1); box-shadow: 0 4px 12px rgba(16, 185, 129, 0.35); }
  100% { transform: scale(1.03); box-shadow: 0 6px 20px rgba(16, 185, 129, 0.7); }
}

.next-btn {
  flex: 1;
  background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
  border-bottom: 4px solid #b45309;
}

.play-again-btn {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  border-bottom: 4px solid #047857;
  padding: 12px 30px;
}

.hidden {
  display: none !important;
}

/* ---------------------------------------------------------------------
   Sparks & Celebration Modal
   --------------------------------------------------------------------- */

.sparks-container {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 40;
}

.sparkle {
  position: absolute;
  font-size: 1.5rem;
  animation: sparkBurst 0.8s ease-out forwards;
}

@keyframes sparkBurst {
  0% { transform: translate(0, 0) scale(0.5); opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) scale(1.3); opacity: 0; }
}

.celebration-overlay {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.75);
  backdrop-filter: blur(6px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
  padding: 16px;
}

.celebration-card {
  background: #ffffff;
  border: 4px solid #f59e0b;
  padding: 24px 28px;
  border-radius: 28px;
  text-align: center;
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.35);
  max-width: 420px;
  width: 100%;
  animation: cardBounce 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.celebration-icon {
  font-size: 3.2rem;
  margin-bottom: 8px;
}

.celebration-text {
  font-size: 1.25rem;
  font-weight: 800;
  color: #78350f;
  margin-bottom: 20px;
  line-height: 1.4;
}

@keyframes cardBounce {
  0% { transform: scale(0.6); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

/* ---------------------------------------------------------------------
   Mobile & Responsive Layout
   --------------------------------------------------------------------- */

@media (max-width: 480px), (max-height: 700px) {
  :root {
    --dial-size: 260px;
  }
  .hour-hand {
    height: 58px;
    margin-top: -58px;
  }
  .hour-hand .hand-arrow {
    border-left-width: 8px;
    border-right-width: 8px;
    border-bottom-width: 12px;
  }
  .hour-hand .hand-line {
    height: 47px;
  }
  .min-hand {
    height: 94px;
    margin-top: -94px;
  }
  .min-hand .hand-arrow {
    border-left-width: 6px;
    border-right-width: 6px;
    border-bottom-width: 15px;
  }
  .min-hand .hand-line {
    height: 80px;
  }
  .hour-number {
    font-size: 1.15rem;
  }
  .routine-card {
    padding: 6px 12px;
  }
  .event-icon {
    font-size: 2rem;
  }
  .event-title {
    font-size: 1.05rem;
  }
  .step-btn {
    font-size: 0.85rem;
    padding: 8px 2px;
  }
  .action-btn {
    font-size: 1rem;
    padding: 10px 12px;
  }
}

@media (max-height: 580px) {
  :root {
    --dial-size: 205px;
  }
  .cuckoo-tower {
    height: 38px;
    margin-bottom: -6px;
  }
  .cuckoo-roof {
    border-left-width: 36px;
    border-right-width: 36px;
    border-bottom-width: 18px;
  }
  .cuckoo-attic {
    width: 44px;
    height: 24px;
  }
  .cuckoo-bird {
    font-size: 1.2rem;
  }
  .hour-hand {
    height: 48px;
    margin-top: -48px;
  }
  .hour-hand .hand-arrow {
    border-left-width: 7px;
    border-right-width: 7px;
    border-bottom-width: 10px;
  }
  .hour-hand .hand-line {
    height: 39px;
  }
  .min-hand {
    height: 74px;
    margin-top: -74px;
  }
  .min-hand .hand-arrow {
    border-left-width: 5px;
    border-right-width: 5px;
    border-bottom-width: 13px;
  }
  .min-hand .hand-line {
    height: 62px;
  }
  .hour-number {
    font-size: 0.92rem;
  }
  .clock-workspace {
    padding: 2px 8px 6px;
    overflow-y: auto;
  }
  .current-time-container {
    margin-top: 4px;
    padding: 2px 10px;
  }
}

@media (orientation: landscape) and (max-height: 580px) {
  .clock-workspace {
    display: grid;
    grid-template-columns: auto 1fr;
    grid-template-rows: auto auto;
    max-width: 720px;
    gap: 6px 18px;
    align-items: center;
    padding: 2px 14px 6px;
    overflow-y: auto;
  }
  .clock-stage {
    grid-column: 1;
    grid-row: 1 / span 2;
    margin: 0;
  }
  .routine-card {
    grid-column: 2;
    grid-row: 1;
    margin: 0;
  }
  .controls-section {
    grid-column: 2;
    grid-row: 2;
    margin: 0;
  }
}

/* ---------------------------------------------------------------------
   Reduced Motion
   --------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .clock-hand,
  .door,
  .cuckoo-bird,
  .celebration-card,
  .check-btn.ready,
  .sparkle {
    transition: none !important;
    animation: none !important;
  }
}
