:root {
  /* Colors from style guide */
  --color-grayish-blue: hsl(237, 18%, 59%);
  --color-soft-red: hsl(345, 95%, 68%);
  --color-white: hsl(0, 0%, 100%);
  --color-dark-desaturated-blue: hsl(236, 21%, 26%);
  --color-very-dark-blue: hsl(235, 16%, 14%);
  --color-very-dark-mostly-black-blue: hsl(234, 17%, 12%);

  --font-family: "Red Hat Text", sans-serif;
  --font-weight-bold: 700;

  /*
    Why clamp()?
    Creates fluid typography that scales between min and max values.
    Syntax: clamp(min, preferred, max)
    This means: "use preferred size, but never smaller than min or larger than max"
  */
  --font-size-number: clamp(2rem, 8vw, 5rem);
  --font-size-label: clamp(0.5rem, 1.5vw, 0.875rem);
  --font-size-title: clamp(1.125rem, 2.5vw, 1.5rem);

  /* Spacing scale - using consistent spacing improves visual rhythm */
  --spacing-xs: 0.5rem;
  --spacing-sm: 1rem;
  --spacing-md: 1.5rem;
  --spacing-lg: 2rem;
  --spacing-xl: 3rem;

  /* Animation timing - centralized for consistent feel */
  --transition-speed: 600ms;
  --transition-timing: cubic-bezier(0.4, 0, 0.2, 1);
}

/*
  ============================================
  MODERN CSS RESET
  ============================================
  Why reset styles?
  Browsers have different default styles. A reset creates consistency.
  This is a modern, minimal reset that keeps useful defaults.
*/

/*
  Box-sizing: border-box means padding and border are included in width/height
  This makes sizing much more intuitive!
  Default is content-box where padding/border add to the width.
*/
*,
*::before,
*::after {
  box-sizing: border-box;
}

/*
  Remove default margins - browsers add unexpected margins to many elements.
  We'll add them back intentionally where needed.
*/
* {
  margin: 0;
}

/*
  Why line-height: 1.5?
  Improves readability. Default (1.2) is too cramped for body text.

  Why -webkit-font-smoothing?
  Makes fonts look smoother/lighter on macOS/iOS.

  Why text-rendering?
  Tells browser to prioritize readability over speed.
*/
body {
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/*
  Images are inline by default, which can cause layout issues.
  display: block fixes this. max-width prevents overflow.
*/
img,
picture,
video,
canvas,
svg {
  display: block;
  max-width: 100%;
}

/*
  Prevent text overflow issues with long words.
  overflow-wrap allows breaking in the middle of words if needed.
*/
p,
h1,
h2,
h3,
h4,
h5,
h6 {
  overflow-wrap: break-word;
}

/*
  ============================================
  BASE STYLES
  ============================================
*/
body {
  font-family: var(--font-family);
  font-weight: var(--font-weight-bold);
  background-color: var(--color-very-dark-mostly-black-blue);
  color: var(--color-white);

  min-height: 100vh;

  /*
    Background layers explained:
    Multiple backgrounds stack from top to bottom (first = front layer)
    1. Stars pattern (top layer)
    2. Hills pattern (bottom layer, positioned at bottom)
    3. Gradient (behind both patterns)
  */
  background-image: url("./images/bg-stars.svg"),
    url("./images/pattern-hills.svg"),
    linear-gradient(
      to bottom,
      var(--color-very-dark-blue),
      var(--color-very-dark-mostly-black-blue)
    );

  /*
    Background positioning:
    - center top: stars fill the top
    - center bottom: hills sit at the bottom
  */
  background-position: center top, center bottom;

  /*
    background-size:
    - auto: stars keep original size
    - 100% auto: hills stretch full width, maintain aspect ratio
  */
  background-size: auto, 100% auto;

  background-repeat: no-repeat;
  overflow-x: hidden;
}

/*
  ============================================
  LAYOUT - CONTAINER
  ============================================
*/
.container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-xl);

  min-height: 100vh;
  padding: var(--spacing-md);
}

/*
  ============================================
  TITLE STYLING
  ============================================
*/
.title {
  font-size: var(--font-size-title);
  letter-spacing: 0.3em;
  text-transform: uppercase;
  text-align: center;
  color: var(--color-white);
  margin-block-end: var(--spacing-md);
}

/*
  ============================================
  COUNTDOWN LAYOUT
  ============================================
*/
.countdown {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--spacing-md);
  width: 100%;
  max-width: 680px;
  margin-block-end: var(--spacing-xl);
}

/*
  ============================================
  RESPONSIVE BREAKPOINT - MOBILE
  ============================================
*/
@media (max-width: 768px) {
  .countdown {
    grid-template-columns: repeat(2, 1fr);
    gap: var(--spacing-sm);
    max-width: 400px;
  }

  .title {
    font-size: 1.125rem;
    margin-block-start: var(--spacing-md);
  }
}

/*
  ============================================
  TIME UNIT CONTAINER
  ============================================
*/
.time-unit {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--spacing-sm);
}

/*
  ============================================
  FLIP CARD STRUCTURE
  ============================================
*/

.flip-card {
  position: relative;
  width: clamp(70px, 15vw, 140px);
  height: clamp(60px, 13vw, 130px);

  /*
    perspective creates 3D space for transforms
    Higher values = less dramatic 3D effect
    This makes the flip look more realistic
  */
  perspective: 600px;

  font-size: var(--font-size-number);
  color: var(--color-soft-red);
  font-weight: var(--font-weight-bold);
}

/*
  ============================================
  FLIP CARD HALVES - TOP & BOTTOM
  ============================================
  Each card is split horizontally into two halves
  This creates the appearance of a flipping card
*/

.flip-card-top,
.flip-card-bottom {
  position: absolute;
  width: 100%;
  height: 50%;
  overflow: hidden;
  background: var(--color-dark-desaturated-blue);

  /*
    Backface-visibility: hidden
    Hides the back of elements during 3D transforms
    Prevents flickering during animation
  */
  backface-visibility: hidden;

  z-index: 1;
}

/* Top half positioning */
.flip-card-top {
  top: 0;
  border-radius: 0.5rem 0.5rem 0 0;
  border-bottom: 1px solid rgba(0, 0, 0, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
}

.flip-card-top span {
  position: absolute;
  left: 50%;
  bottom: 0;
  transform: translate(-50%, 50%);
  line-height: 1;
}

/* Bottom half positioning */
.flip-card-bottom {
  bottom: 0;
  border-radius: 0 0 0.5rem 0.5rem;
  background: var(--color-dark-desaturated-blue);
  filter: brightness(0.9);

  display: flex;
  align-items: center;
  justify-content: center;
}

/*
  Mirror of top half:
  - Position span so its center aligns with TOP of this container
  - The TOP of this container is the middle of the full card
*/
.flip-card-bottom span {
  position: absolute;
  left: 50%;
  top: 0;
  transform: translate(-50%, -50%);
  line-height: 1;
}

/*
  ============================================
  FLIP CARD - BACK (ANIMATED PART)
  ============================================
*/

.flip-card-back {
  /*
    position: absolute with inset: 0 is shorthand for:
    top: 0; right: 0; bottom: 0; left: 0;
    Makes element fill its container
  */
  position: absolute;
  inset: 0;

  /*
    transform-style: preserve-3d
    Required for child elements to exist in 3D space
    Without this, children would be flattened
  */
  transform-style: preserve-3d;

  opacity: 0;
  z-index: 10;
  pointer-events: none;
}

/* Back top half - this is what flips down */
.flip-card-back-top {
  position: absolute;
  top: 0;
  width: 100%;
  height: 50%;
  overflow: hidden;
  background: var(--color-dark-desaturated-blue);
  border-radius: 0.5rem 0.5rem 0 0;
  border-bottom: 1px solid rgba(0, 0, 0, 0.2);

  display: flex;
  align-items: center;
  justify-content: center;

  /*
    transform-origin sets the pivot point for rotation
    bottom center means it rotates from the bottom edge
    Like a hinge at the bottom of a door
  */
  transform-origin: bottom center;

  transform: rotateX(0deg);

  backface-visibility: hidden;
}

.flip-card-back-top span {
  position: absolute;
  left: 50%;
  bottom: 0;
  transform: translate(-50%, 50%);
  line-height: 1;
}

/* Back bottom half - revealed after top half flips */
.flip-card-back-bottom {
  position: absolute;
  bottom: 0;
  width: 100%;
  height: 50%;
  overflow: hidden;
  background: var(--color-dark-desaturated-blue);
  border-radius: 0 0 0.5rem 0.5rem;
  filter: brightness(0.9);

  display: flex;
  align-items: center;
  justify-content: center;

  /*
    Initially rotated 180deg (hidden, facing away)
    Will animate to 0deg (facing viewer)
  */
  transform: rotateX(180deg);
  transform-origin: top center;

  backface-visibility: hidden;
}

.flip-card-back-bottom span {
  position: absolute;
  left: 50%;
  top: 0;
  transform: translate(-50%, -50%);
  line-height: 1;
}

/*
  ============================================
  FLIP ANIMATION
  ============================================
  When JavaScript adds the 'flip' class, this animation runs
*/

/* Make animated cards immediately visible when flip starts (no fade-in animation) */
.flip-card.flip .flip-card-back {
  opacity: 1;
  z-index: 50;
}

/* Animate top half flipping down (rotation only) */
.flip-card.flip .flip-card-back-top {
  animation: flip-top var(--transition-speed) var(--transition-timing) forwards;
}

/* Animate bottom half flipping up (rotation only) */
.flip-card.flip .flip-card-back-bottom {
  animation: flip-bottom var(--transition-speed) var(--transition-timing)
    forwards;
}

/*
  ============================================
  KEYFRAME ANIMATIONS
  ============================================
  Define how properties change over time
  from = 0%, to = 100%
*/

/* Simple fade-in animation */
@keyframes show {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/*
  Top half flip animation
  Rotates from 0deg to -180deg around X axis
  Why negative? Rotates "forward" towards viewer then away
*/
@keyframes flip-top {
  0% {
    transform: rotateX(0deg);
  }
  100% {
    transform: rotateX(-180deg);
  }
}

/*
  Bottom half flip animation
  Rotates from 180deg (hidden) to 0deg (visible)
  Reveals the bottom half of new number
*/
@keyframes flip-bottom {
  0% {
    transform: rotateX(180deg);
  }
  100% {
    transform: rotateX(0deg);
  }
}

/*
  ============================================
  DECORATIVE ELEMENTS
  ============================================
  The small circles on the sides of each card
*/

/*
  ::before and ::after pseudo-elements
  Create elements with CSS without HTML markup
  Perfect for decorative elements!
*/
.flip-card::before,
.flip-card::after {
  content: "";
  position: absolute;
  /*
    Positioned vertically in the middle (where the split is)
    translateY(-50%) perfectly centers the circle
  */
  top: 50%;
  transform: translateY(-50%);
  width: clamp(8px, 1.5vw, 12px);
  height: clamp(8px, 1.5vw, 12px);
  background: var(--color-very-dark-mostly-black-blue);
  border-radius: 50%; /* Makes square into circle */
  z-index: 5;
}

/* Position left circle */
.flip-card::before {
  left: -6px;
}

/* Position right circle */
.flip-card::after {
  right: -6px;
}

/*
  ============================================
  TIME LABELS (Days, Hours, etc.)
  ============================================
*/
.time-label {
  font-size: var(--font-size-label);
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--color-grayish-blue);
  text-align: center;
  margin-block-start: var(--spacing-xs);
}

/*
  ============================================
  SOCIAL LINKS - FOOTER
  ============================================
*/
.social-links {
  margin-block-start: auto;
  padding-block: var(--spacing-lg);
}

/* Remove default list styling */
.social-list {
  list-style: none;
  padding: 0;

  display: flex;
  gap: var(--spacing-md);
  align-items: center;
  justify-content: center;
}

.social-list li {
  display: flex;
}

/* Link styling */
.social-list a {
  display: inline-flex;
  align-items: center;
  justify-content: center;

  color: var(--color-grayish-blue);

  /*
    transition creates smooth hover effect
    all = transition all properties (color in this case)
  */
  transition: color 200ms ease-in-out;

  /*
    Increase click area for better mobile UX
    padding makes the clickable area larger than the icon
  */
  padding: var(--spacing-xs);
}

/*
  Hover state - improves interactivity
  :hover = when mouse is over element
  :focus-visible = when keyboard-navigated (accessibility!)
*/
.social-list a:hover,
.social-list a:focus-visible {
  /*
    outline for keyboard navigation
  */
  outline: 2px solid var(--color-soft-red);
  outline-offset: 4px;
  border-radius: 4px;
}

/*
  Change icon color on hover by targeting the img inside hovered link
  We use a CSS filter to change the grayish-blue to soft red

  How these filter values work:
  - brightness(1.8): Makes it lighter (soft red is bright)
  - saturate(2): Increases color saturation
  - hue-rotate(): Shifts color hue to achieve pinkish-red

  This is an approximation since we can't directly set fill on <img> tags
*/
.social-list a:hover img,
.social-list a:focus-visible img {
  /*
    Filter to approximate soft red hsl(345, 95%, 68%)
    These values were chosen through experimentation
  */
  filter: brightness(1.3) saturate(1.5) hue-rotate(-15deg);
}

/*
  SVG Icon Styling
  Why filter instead of fill?
  - These SVGs are loaded as <img> tags, not inline SVG
  - Can't access internal fill property of <img>
  - CSS filters allow color manipulation of external images

  How filter works:
  - invert(1) turns black to white (flips all colors)
  - brightness adjusts lightness
  - We can approximate color changes with filters
*/
.social-list img {
  width: 24px;
  height: 24px;
  /*
    Smooth transitions for filter changes
    Makes hover effect smooth
  */
  transition: filter 200ms ease-in-out;
}

/*
  ============================================
  ATTRIBUTION FOOTER
  ============================================
*/
.attribution {
  font-size: 11px;
  text-align: center;
  color: var(--color-grayish-blue);
  padding: var(--spacing-md);

  position: fixed;
  bottom: 0;
  width: 100%;
  background: linear-gradient(
    to top,
    var(--color-very-dark-mostly-black-blue),
    transparent
  );
  padding-block: var(--spacing-md);
}

.attribution a {
  color: var(--color-soft-red);
  text-decoration: none;
  transition: opacity 200ms ease-in-out;
}

.attribution a:hover,
.attribution a:focus-visible {
  opacity: 0.8;
  text-decoration: underline;
}

/*
  ============================================
  ACCESSIBILITY IMPROVEMENTS
  ============================================
*/

/*
  Respect user's motion preferences
  prefers-reduced-motion = user has requested less animation
  Important for users with vestibular disorders!
*/
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    /*
      Disable animations for users who prefer reduced motion
      They still get the functionality, just without the flip
    */
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/*
  Focus-visible polyfill support
  Only show focus outline when keyboard navigating
*/
:focus:not(:focus-visible) {
  outline: none;
}

/*
  Skip link for keyboard navigation
  Allows screen reader users to jump to main content
  Hidden until focused
*/
.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--color-soft-red);
  color: var(--color-white);
  padding: 8px;
  text-decoration: none;
  z-index: 100;
}

.skip-link:focus {
  top: 0;
}
