*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --ink: rgba(42, 52, 64, 0.72);
  --ink-strong: rgba(42, 52, 64, 0.9);
  --ink-soft: rgba(42, 52, 64, 0.38);
  --font: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --key-font: -apple-system, BlinkMacSystemFont, "SF Pro Rounded", "Helvetica Neue", Arial, sans-serif;
  --orange: #e8955f;
  --orange-deep: #d47a43;
  --cap-edge: #cfcfca;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #e8eef4;
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  -webkit-tap-highlight-color: transparent;
}

#sky {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.grain {
  pointer-events: none;
  position: fixed;
  inset: 0;
  opacity: 0.035;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

.home {
  position: fixed;
  inset: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(1.2rem, 4.5vh, 2.6rem);
  padding: calc(env(safe-area-inset-top, 0px) + 1.5rem) 1.25rem calc(env(safe-area-inset-bottom, 0px) + 1.5rem);
  transition: opacity 0.55s ease, filter 0.55s ease;
  pointer-events: none;
}

.home__title,
.home__keys {
  pointer-events: auto;
}

.home.is-dimmed {
  opacity: 0.32;
  filter: blur(6px);
  pointer-events: none;
}

.home__title {
  position: relative;
  z-index: 1;
  display: block;
  margin: 0;
  padding: 0;
  color: var(--ink);
  line-height: 0;
  animation: wm-rise 1.1s cubic-bezier(0.22, 0.82, 0.28, 1) both;
}

.home__wordmark {
  display: block;
  width: min(22rem, 86vw);
  height: auto;
  max-height: clamp(2.6rem, 12vh, 4.1rem);
  overflow: visible;
  color: var(--ink);
}

.wm__layer {
  stroke-width: 1.85;
}

.wm__glyph {
  fill: currentColor;
  fill-opacity: 0;
  stroke: currentColor;
  stroke-opacity: 0.9;
  stroke-dasharray: 1.05;
  stroke-dashoffset: 1.05;
  animation:
    wm-draw 1.2s cubic-bezier(0.4, 0.05, 0.2, 1) calc(var(--i) * 0.06s) both,
    wm-fill 0.75s ease calc(0.78s + var(--i) * 0.05s) both;
}

.home__keys {
  position: relative;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.7rem;
  width: min(22rem, 100%);
  animation: rise 1.8s 0.28s ease both;
}

.entry {
  appearance: none;
  display: block;
  width: 100%;
  border: 0;
  padding: 0;
  background: linear-gradient(180deg, #f3f3f1 0%, #e6e6e2 100%);
  border-radius: 16px;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.9),
    0 5px 0 var(--cap-edge),
    0 8px 14px rgba(40, 44, 52, 0.2);
  color: #26282c;
  font-family: var(--key-font);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}

.entry--field {
  position: relative;
}

.entry__runner {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
  z-index: 2;
}

.entry__runner-path {
  stroke: var(--orange-deep);
  stroke-width: 1.35;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-opacity: 0.82;
  stroke-dasharray: 0.12 0.88;
  stroke-dashoffset: 0;
  animation: entry-runner 5s linear infinite;
}

@keyframes entry-runner {
  to {
    stroke-dashoffset: -1;
  }
}

.entry__face {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 58px;
  margin: 5px 9px 14px;
  padding: 10px 14px 8px;
  border-radius: 12px;
  background: linear-gradient(170deg, #ffffff 0%, #fbfbfa 60%, #f3f3f1 100%);
  box-shadow: inset 0 1px 0 #ffffff, 0 1px 2px rgba(0, 0, 0, 0.06);
  text-align: left;
}

.entry__text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.entry__text b {
  font-weight: 700;
  font-size: clamp(0.98rem, 3.8vw, 1.12rem);
  line-height: 1.15;
  color: #26282c;
}

.entry__text small {
  font-size: 0.78rem;
  line-height: 1.2;
  color: rgba(42, 52, 64, 0.45);
  font-weight: 500;
}

.entry__led {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #3c3f44;
  box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.35);
  flex-shrink: 0;
}

.entry:hover .entry__led,
.entry:focus-visible .entry__led {
  background: var(--orange);
  box-shadow: 0 0 7px rgba(232, 149, 95, 0.85);
}

.entry:active,
.entry.is-pressed {
  transform: translateY(4px);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.9),
    0 1px 0 var(--cap-edge),
    0 3px 6px rgba(40, 44, 52, 0.18);
}

.entry:focus {
  outline: none;
}

.entry:focus-visible .entry__face {
  box-shadow: inset 0 1px 0 #ffffff, 0 0 0 2px rgba(232, 149, 95, 0.7);
}

.entry__icon {
  position: relative;
  width: 30px;
  height: 30px;
  flex-shrink: 0;
}

.entry__icon--cards i {
  position: absolute;
  top: 3px;
  left: 8px;
  width: 15px;
  height: 22px;
  border-radius: 3px;
  background: linear-gradient(160deg, #f3a876, #d0753e);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transform-origin: 50% 100%;
}

.entry__icon--cards i:nth-child(1) {
  transform: rotate(-16deg);
  opacity: 0.55;
}

.entry__icon--cards i:nth-child(2) {
  transform: rotate(-4deg);
  opacity: 0.8;
}

.entry__icon--cards i:nth-child(3) {
  transform: rotate(10deg);
}

.entry__icon--case::before,
.entry__icon--case::after {
  content: "";
  position: absolute;
  border-radius: 4px;
  border: 1.5px solid var(--orange-deep);
  background: rgba(232, 149, 95, 0.18);
}

.entry__icon--case::before {
  inset: 4px 5px 6px 5px;
}

.entry__icon--case::after {
  top: 8px;
  left: 9px;
  right: 9px;
  height: 7px;
  border-radius: 2px;
  background: linear-gradient(160deg, #f3a876, #d0753e);
  border: 0;
}

.entry__icon--cloud::before {
  content: "";
  position: absolute;
  left: 3px;
  right: 3px;
  bottom: 7px;
  height: 12px;
  border-radius: 999px;
  background: linear-gradient(160deg, #f3a876, #d0753e);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18);
}

.entry__icon--cloud::after {
  content: "";
  position: absolute;
  left: 8px;
  top: 6px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: linear-gradient(160deg, #f3a876, #d0753e);
  box-shadow: 8px 3px 0 0 #d0753e;
}


.entry__icon--list i {
  position: absolute;
  left: 4px;
  right: 4px;
  height: 5px;
  border-radius: 999px;
  background: linear-gradient(160deg, #f3a876, #d0753e);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}

.entry__icon--list i:nth-child(1) {
  top: 6px;
}

.entry__icon--list i:nth-child(2) {
  top: 13px;
  right: 8px;
}

.entry__icon--list i:nth-child(3) {
  top: 20px;
  right: 12px;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-height: 560px) and (orientation: landscape) {
  .home {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    align-content: center;
    gap: clamp(1.5rem, 5vw, 3rem);
    padding-inline: 1.5rem;
  }

  .home__title {
    writing-mode: unset;
    transform: rotate(-90deg);
    animation: none;
    opacity: 1;
  }

  .home__wordmark {
    width: min(16rem, 52vh);
    max-height: none;
  }

  .wm__glyph {
    animation: none;
    fill-opacity: 1;
    stroke-opacity: 0;
    stroke-dashoffset: 0;
  }

  .home__keys {
    width: min(22rem, 70vw);
    animation: none;
    opacity: 1;
  }

  .entry__face {
    min-height: 52px;
  }
}

@keyframes wm-rise {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes wm-draw {
  from {
    stroke-dashoffset: 1.05;
    stroke-opacity: 0.9;
  }
  to {
    stroke-dashoffset: 0;
    stroke-opacity: 0.55;
  }
}

@keyframes wm-fill {
  from {
    fill-opacity: 0;
  }
  to {
    fill-opacity: 1;
    stroke-opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .home__title,
  .home__keys {
    animation: none;
  }

  .wm__glyph {
    animation: none !important;
    fill-opacity: 1;
    stroke-opacity: 0;
    stroke-dashoffset: 0;
  }

  .entry__runner-path {
    animation: none;
    stroke-dasharray: none;
    stroke-dashoffset: 0;
    stroke-opacity: 0.38;
  }

  .home-chaos.is-running .home-chaos__card {
    transition: none;
  }

  .fall-card {
    animation: none !important;
  }

  .fall-cards--off {
    display: none !important;
  }
}

/* Soft falling COPE cards — atmosphere only (pointer-events none) */
.fall-cards {
  pointer-events: none;
  position: fixed;
  inset: 0;
  overflow: hidden;
  z-index: 0;
  isolation: isolate;
}

.fall-cards--behind {
  z-index: 0;
}

.fall-cards--front {
  z-index: 2;
}

.fall-card {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1;
  width: var(--w, 4.6rem);
  aspect-ratio: 290 / 406;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 7%;
  overflow: hidden;
  background: rgba(255, 252, 246, 0.55);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.5),
    0 10px 22px -12px rgba(42, 52, 64, 0.32);
  opacity: 0;
  will-change: transform, opacity;
  transform: translate3d(var(--x, 0vw), -22vh, 0) rotate(var(--r0, -8deg));
  /* animation string set inline per spawn for reliable restart */
  animation-fill-mode: none;
  filter: none;
}

.fall-card--far {
  filter: saturate(0.92) brightness(1.03);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.35),
    0 6px 14px -10px rgba(42, 52, 64, 0.22);
}

.fall-card--near {
  filter: saturate(1.02) brightness(1);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.55),
    0 14px 28px -10px rgba(42, 52, 64, 0.42);
}

.fall-card img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

/* Even vertical progress (~const Y speed). Drift + tumble via X/rotate. */
@keyframes fall-leaf {
  0% {
    opacity: 0;
    transform: translate3d(var(--x, 0vw), -22vh, 0) rotate(var(--r0, -10deg));
  }
  5% {
    opacity: var(--op, 0.88);
  }
  25% {
    opacity: var(--op, 0.88);
    transform: translate3d(var(--xa, 2vw), 16vh, 0) rotate(var(--ra, -4deg));
  }
  50% {
    opacity: var(--op, 0.88);
    transform: translate3d(var(--xmid, 4vw), 48vh, 0) rotate(var(--rmid, 6deg));
  }
  75% {
    opacity: var(--op, 0.85);
    transform: translate3d(var(--xb, 6vw), 82vh, 0) rotate(var(--rb, 12deg));
  }
  92% {
    opacity: var(--op2, 0.75);
  }
  100% {
    opacity: 0;
    transform: translate3d(var(--x1, 8vw), 118vh, 0) rotate(var(--r1, 18deg));
  }
}

/* Marseille chaos under the keys (in-flow, zoom-stable) */
.home-chaos {
  position: relative;
  z-index: 0;
  width: min(34vw, 24dvh, 180px);
  height: min(34vw, 24dvh, 180px);
  flex-shrink: 0;
  margin-top: 0.15rem;
  margin-bottom: 1.6rem; /* room for caption under ring */
  pointer-events: none;
  touch-action: manipulation;
}
.home-chaos.is-running {
  pointer-events: auto;
}
.home-chaos.is-done {
  pointer-events: none;
}
.home-chaos__ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.55),
    inset 0 0 24px rgba(255, 255, 255, 0.12),
    0 0 0 1px rgba(70, 76, 86, 0.08);
  pointer-events: none;
}
.home-chaos__field {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 0;
  height: 0;
}
.home-chaos__card {
  position: absolute;
  left: 0;
  top: 0;
  width: clamp(20px, 3.4vw, 28px);
  height: auto;
  aspect-ratio: 0.62;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 4px;
  overflow: hidden;
  background: none;
  appearance: none;
  transform: translate(0, 0) translate(-50%, -50%) rotate(0deg);
  transform-origin: center center;
  will-change: transform;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.28),
    0 6px 12px -10px rgba(40, 48, 60, 0.4);
  pointer-events: none;
}
.home-chaos__card img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
  user-select: none;
}
.home-chaos__reveal {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  z-index: 2;
  pointer-events: none;
  animation: home-chaos-reveal 0.65s cubic-bezier(0.22, 0.82, 0.28, 1) both;
}
.home-chaos__reveal[hidden] {
  display: none !important;
}
.home-chaos__face {
  display: block;
  width: 72px;
  height: auto;
  border-radius: 6px;
  box-shadow:
    0 1px 0 rgba(228, 228, 224, 0.9),
    0 8px 16px -12px rgba(70, 76, 86, 0.4);
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}
.home-chaos__caption {
  position: absolute;
  left: 50%;
  top: calc(50% + var(--chaos-r, 90px) + 14px);
  transform: translateX(-50%);
  margin: 0;
  font-family: var(--font);
  font-size: clamp(0.86rem, 2.2vw, 1rem);
  font-style: italic;
  letter-spacing: 0.02em;
  color: var(--ink-soft);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.55);
  white-space: nowrap;
}
@keyframes home-chaos-reveal {
  from {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.94);
  }
  to {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
}
@media (max-width: 480px) {
  .home-chaos {
    width: min(42vw, 22dvh, 156px);
    height: min(42vw, 22dvh, 156px);
    margin-bottom: 1.75rem;
  }
  .home-chaos__card {
    width: clamp(16px, 4.2vw, 22px);
  }
  .home-chaos__caption {
    font-size: 0.9rem;
    top: calc(50% + var(--chaos-r, 78px) + 14px);
  }
}
@media (max-height: 560px) and (orientation: landscape) {
  .home-chaos {
    flex-basis: 100%;
    width: min(22vw, 34dvh, 150px);
    height: min(22vw, 34dvh, 150px);
    margin-top: 0.35rem;
    margin-bottom: 0.75rem;
  }
}

/* TODO(restore-poslaniya): delete this rule (and un-hide the button in index.html) to show «Послания» again */
.home__keys .entry--off,
.home__keys [data-entry="messages"][hidden] {
  display: none !important;
}

/* TODO(restore-home-chaos): delete this rule (and un-hide #home-chaos / SHOW_HOME_CHAOS) to restore card pick on home */
.home-chaos--off,
#home-chaos[hidden] {
  display: none !important;
}
