/* Tile Wrapper */
.tile {
  width: var(--tile-size);
  height: var(--tile-size);
  perspective: 4000px;
  perspective-origin: 50% 50%;
  
  /* Hardware Chassis Bezel */
  background: #020202;
  border-radius: 3px;
  border: 1px solid #000;
  border-bottom-color: #1a1a1a; /* Ambient reflection on bottom lip */
  border-right-color: #0c0c0c;
  
  /* Recessed look for the flaps inside the chassis */
  box-shadow: 
    inset 0 4px 6px rgba(0,0,0,1),
    0 2px 4px rgba(0,0,0,0.5);
  
  transition: transform 0.2s ease;
}

/* Inner Container */
.tile-inner {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  /* Add 2px chassis padding internally so flaps don't touch the very edge */
  padding: 2px;
  box-sizing: border-box;
}

/* Mechanical Halves (The distinct plates) */
.tile-half {
  position: absolute;
  left: 2px;
  right: 2px;
  /* height should be ~calc(50% - 2px) to account for chassis padding */
  height: calc(50% - 2px);
  background: #0c0c0e; /* Flat, matte dark charcoal */
  overflow: hidden;
  display: flex;
  justify-content: center;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.4);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.tile-half span {
  position: absolute;
  font-size: calc(var(--tile-size) * 0.55); /* slightly bigger font fill */
  font-weight: 700;
  color: #f7f7f7; /* Very crisp white */
  text-transform: uppercase;
  letter-spacing: 0.05em;
  line-height: 1;
  font-family: var(--font-flap);
  
  /* Very slight print blur, no deep 3d text shadow */
  text-shadow: 0 0 1px rgba(255, 255, 255, 0.4); 
  -webkit-font-smoothing: antialiased;
}

/* Top Halves */
.top-bg, .flap-top {
  top: 2px;
  transform-origin: bottom;
  border-radius: 2px 2px 0 0;
  align-items: flex-end;
}
.top-bg span, .flap-top span {
  transform: translateY(50%);
}

/* Bottom Halves */
.bottom-bg, .flap-bottom {
  bottom: 2px;
  transform-origin: top;
  border-radius: 0 0 2px 2px;
  align-items: flex-start;
}
.bottom-bg span, .flap-bottom span {
  transform: translateY(-50%);
}

/* Stacking Order */
.bottom-bg { z-index: 1; }
.top-bg { z-index: 2; }
.flap-bottom { z-index: 3; transform: rotateX(90deg); }
.flap-top { z-index: 4; }

/* The Hinge Seam (Deep shadow splitting the two cards) */
.tile-hinge {
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 2px;
  background: #000000;
  transform: translateY(-50%);
  z-index: 10;
  pointer-events: none;
  /* The upper flap edge sometimes catches light */
  border-top: 1px solid rgba(255, 255, 255, 0.04);
}

/* True Split Flap Animation */
.animate-top {
  animation: flapTopFall 120ms linear forwards;
}
.animate-bottom {
  animation: flapBottomReveal 120ms linear forwards;
  animation-delay: 120ms;
}

@keyframes flapTopFall {
  0% { transform: rotateX(0deg); }
  100% { transform: rotateX(-90deg); filter: brightness(0.7); }
}
@keyframes flapBottomReveal {
  0% { transform: rotateX(90deg); filter: brightness(0.7); }
  50% { filter: brightness(0.9); }
  100% { transform: rotateX(0deg); filter: brightness(1); }
}

/* GPU compositing hint during animation only */
.flipping .tile-half,
.scrambling .tile-half {
  will-change: transform, filter;
}
