:root {
  --led: #ff2a22;
  --led-dim: rgba(90, 8, 8, 0.22);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #14110f;
  color: #ccc;
  font-family: system-ui, sans-serif;
  touch-action: manipulation;
  user-select: none;
}

body {
  position: relative;
}

#world {
  position: absolute;
  inset: 0;
  transform-origin: 50% 50%;
  animation: step-in 1.2s cubic-bezier(0.22, 0.8, 0.28, 1) both,
             sway 12s ease-in-out 1.2s infinite;
  will-change: transform;
}

@keyframes step-in {
  from { transform: scale(1.09) translate3d(0, 6px, 0); }
  to   { transform: scale(1) translate3d(0, 0, 0); }
}

@keyframes sway {
  0%, 100% { transform: translate3d(0, 0, 0) rotate(0deg); }
  35%      { transform: translate3d(0.7px, 1.1px, 0) rotate(0.07deg); }
  68%      { transform: translate3d(-0.6px, 0.5px, 0) rotate(-0.05deg); }
}

#bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 48%;
  pointer-events: none;
}

#intercom {
  position: absolute;
  left: 50%;
  top: 50%;
  height: min(72vh, 680px);
  aspect-ratio: 448 / 824;
  transform: translate(-50%, -50%);
  overflow: hidden;
  border-radius: 2.8% / 1.6%;
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.62),
    1px 2px 0 rgba(20, 10, 8, 0.45),
    4px 8px 16px rgba(0, 0, 0, 0.4);
  z-index: 3;
}

#intercom > img {
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
  filter: brightness(0.94) saturate(0.9) contrast(1.04);
}

#shade {
  position: absolute;
  inset: 0;
  pointer-events: none;
  mix-blend-mode: soft-light;
  z-index: 1;
}

#led {
  position: absolute;
  left: 13.6%;
  top: 37.55%;
  width: 41%;
  height: 6.55%;
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 3.2%;
  padding: 0 7% 0 8.5%;
  background: linear-gradient(
    180deg,
    rgba(10, 0, 0, 0.2) 0%,
    rgba(16, 0, 0, 0.12) 50%,
    rgba(8, 0, 0, 0.22) 100%
  );
  box-shadow:
    inset 0 2px 3px rgba(0, 0, 0, 0.55),
    inset 0 -1px 2px rgba(255, 80, 80, 0.06);
  overflow: hidden;
  pointer-events: none;
  z-index: 2;
}

#led.calling .digit svg {
  animation: led-pulse 1.05s ease-in-out infinite;
}

@keyframes led-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.62; }
}

.digit {
  height: 90%;
  width: auto;
  aspect-ratio: 10 / 18;
  flex: 0 0 auto;
}

.digit svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.digit .seg {
  fill: transparent;
}

.digit .seg.on {
  fill: var(--led);
  filter: drop-shadow(0 0 1.2px #ff3a30) drop-shadow(0 0 4px rgba(255, 40, 30, 0.85));
}

#keys {
  position: absolute;
  inset: 0;
  z-index: 3;
}

.key {
  position: absolute;
  width: 12.5%;
  height: 7%;
  left: var(--x);
  top: var(--y);
  transform: translate(-50%, -50%);
  transform-origin: center center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  padding: 0;
  appearance: none;
  -webkit-appearance: none;
}

.key::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 78%;
  height: 78%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(circle at 50% 50%, rgba(0, 0, 0, 0.5) 0%, rgba(0, 0, 0, 0.22) 55%, transparent 72%);
  opacity: 0;
  pointer-events: none;
}

.key:focus {
  outline: none;
}

.key:focus-visible {
  box-shadow: 0 0 0 2px rgba(255, 220, 180, 0.35);
}

.key.down::after,
.key:active::after {
  opacity: 1;
}

body.debug .key {
  outline: 1px solid rgba(0, 255, 90, 0.7);
  background: rgba(0, 255, 80, 0.12);
}

#grade,
#night,
#frost,
#vignette,
#wx {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

#grade { z-index: 4; }
#night { z-index: 5; }
#frost { z-index: 6; }
#wx { z-index: 7; width: 100%; height: 100%; }
#vignette { z-index: 8; }

html[data-season="winter"] #grade {
  background: rgba(150, 180, 220, 0.2);
  mix-blend-mode: multiply;
}
html[data-season="winter"] #intercom > img {
  filter: brightness(0.8) saturate(0.72) contrast(1.05);
}
html[data-season="winter"] #shade {
  background: rgba(150, 185, 220, 0.55);
}

html[data-season="spring"] #grade {
  background: rgba(186, 220, 170, 0.1);
  mix-blend-mode: soft-light;
}
html[data-season="spring"] #intercom > img {
  filter: brightness(0.97) saturate(0.92) contrast(1.03);
}

html[data-season="summer"] #grade {
  background: radial-gradient(ellipse at 78% 8%, rgba(255, 214, 120, 0.42), rgba(255, 160, 60, 0.08) 42%, transparent 70%);
  mix-blend-mode: soft-light;
}
html[data-season="summer"] #intercom > img {
  filter: brightness(1.02) saturate(0.92) contrast(1.04) sepia(0.1);
}
html[data-season="summer"] #shade {
  background: linear-gradient(90deg, transparent 30%, rgba(255, 176, 70, 0.28) 100%);
}

html[data-season="autumn"] #grade {
  background: rgba(160, 90, 40, 0.16);
  mix-blend-mode: multiply;
}
html[data-season="autumn"] #intercom > img {
  filter: brightness(0.9) saturate(0.95) sepia(0.12) contrast(1.04);
}

html[data-night="1"] #night {
  background:
    radial-gradient(ellipse at 68% 42%, rgba(255, 170, 80, 0.1), transparent 34%),
    linear-gradient(180deg, rgba(6, 10, 28, 0.42), rgba(4, 6, 16, 0.58));
}

html[data-night="0"] #night { background: transparent; }

html[data-season="winter"] #frost {
  box-shadow:
    inset 0 0 80px 18px rgba(210, 230, 255, 0.14),
    inset 0 0 140px 40px rgba(180, 210, 240, 0.08);
}

#vignette {
  background: radial-gradient(ellipse at 50% 50%, transparent 46%, rgba(0, 0, 0, 0.36) 100%);
}

@media (max-width: 720px) {
  #intercom {
    left: 50%;
    top: 50%;
    height: min(78vh, 86vw / 0.544);
    transform: translate(-50%, -50%);
  }
}

@media (min-width: 1400px) {
  #intercom {
    height: min(74vh, 720px);
    left: 50%;
  }
}

@media (prefers-reduced-motion: reduce) {
  #world {
    animation: none;
  }
  #led.calling .digit svg {
    animation: none;
  }
}
