:root {
  color-scheme: dark;
  --ink: #0d1720;
  --deep: #10243a;
  --midnight: #16364a;
  --leaf: #2f6f57;
  --moss: #60905c;
  --paper: #f0dca8;
  --gold: #d7a846;
  --berry: #9b3f58;
  --cream: #f6ecd5;
  --shadow: rgba(2, 9, 16, 0.42);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button {
  font: inherit;
}

.game {
  width: 100vw;
  height: 100dvh;
  background:
    linear-gradient(180deg, #07111d 0%, #12344a 48%, #1b4b47 100%);
}

.viewport {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 520px;
  overflow: hidden;
  outline: none;
  isolation: isolate;
  user-select: none;
}

.viewport::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  background:
    linear-gradient(180deg, rgba(6, 14, 24, 0) 45%, rgba(10, 33, 33, 0.52) 100%),
    radial-gradient(circle at 74% 14%, rgba(241, 217, 151, 0.36), transparent 6.5rem);
  pointer-events: none;
}

.viewport::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 118px;
  z-index: 2;
  background:
    linear-gradient(180deg, rgba(14, 45, 42, 0), rgba(7, 22, 24, 0.88)),
    repeating-linear-gradient(90deg, rgba(222, 190, 101, 0.08) 0 9px, transparent 9px 20px);
  pointer-events: none;
}

.parallax {
  position: absolute;
  inset: auto 0 0 0;
  height: 720px;
  transform: translate3d(0, 0, 0);
  transform-origin: left bottom;
  pointer-events: none;
}

.parallax-far {
  z-index: 0;
}

.parallax-mid {
  z-index: 1;
}

.star {
  position: absolute;
  width: 2px;
  height: 2px;
  border-radius: 50%;
  background: rgba(246, 236, 213, 0.82);
  box-shadow: 0 0 9px rgba(246, 236, 213, 0.55);
  animation: starPulse 2.8s ease-in-out infinite alternate;
}

@keyframes starPulse {
  from {
    opacity: 0.38;
  }
  to {
    opacity: 0.95;
  }
}

.distant-shelf,
.garden-hill,
.glasshouse,
.canal,
.library-tower,
.lamp {
  position: absolute;
  bottom: 0;
}

.distant-shelf {
  width: 420px;
  height: 218px;
  border: 1px solid rgba(240, 220, 168, 0.08);
  border-bottom: 0;
  background:
    linear-gradient(90deg, transparent 0 7%, rgba(248, 227, 173, 0.06) 7% 8%, transparent 8% 16%),
    repeating-linear-gradient(90deg, rgba(248, 227, 173, 0.08) 0 9px, transparent 9px 27px),
    linear-gradient(180deg, rgba(26, 65, 76, 0.66), rgba(11, 29, 38, 0.74));
  clip-path: polygon(0 16%, 18% 8%, 36% 19%, 55% 6%, 76% 16%, 100% 11%, 100% 100%, 0 100%);
  opacity: 0.68;
}

.garden-hill {
  width: 560px;
  height: 130px;
  border-radius: 50% 50% 0 0;
  background: linear-gradient(180deg, rgba(47, 111, 87, 0.56), rgba(19, 62, 56, 0.86));
  opacity: 0.82;
}

.glasshouse {
  width: 260px;
  height: 168px;
  border: 2px solid rgba(222, 168, 70, 0.44);
  border-bottom: 0;
  background:
    repeating-linear-gradient(90deg, transparent 0 34px, rgba(246, 236, 213, 0.2) 34px 36px),
    linear-gradient(150deg, rgba(106, 163, 139, 0.24), rgba(15, 54, 61, 0.64));
  clip-path: polygon(50% 0, 100% 34%, 100% 100%, 0 100%, 0 34%);
}

.canal {
  width: 520px;
  height: 82px;
  border-radius: 50% 50% 0 0;
  background:
    repeating-linear-gradient(100deg, rgba(246, 236, 213, 0.17) 0 18px, transparent 18px 48px),
    linear-gradient(180deg, rgba(49, 126, 134, 0.72), rgba(12, 41, 51, 0.72));
  opacity: 0.82;
}

.library-tower {
  width: 128px;
  height: 318px;
  border: 2px solid rgba(215, 168, 70, 0.3);
  border-bottom: 0;
  background:
    repeating-linear-gradient(0deg, transparent 0 42px, rgba(246, 236, 213, 0.11) 42px 45px),
    linear-gradient(180deg, rgba(34, 78, 85, 0.9), rgba(13, 38, 45, 0.96));
  clip-path: polygon(15% 10%, 50% 0, 85% 10%, 100% 100%, 0 100%);
  opacity: 0.78;
}

.lamp {
  width: 10px;
  height: 134px;
  background: linear-gradient(180deg, #b6843e, #5f3b2d);
}

.lamp::before {
  content: "";
  position: absolute;
  left: -23px;
  top: -28px;
  width: 56px;
  height: 46px;
  border: 2px solid rgba(246, 236, 213, 0.45);
  background: radial-gradient(circle, rgba(240, 220, 168, 0.92), rgba(215, 168, 70, 0.18) 62%, transparent 66%);
  clip-path: polygon(50% 0, 100% 28%, 82% 100%, 18% 100%, 0 28%);
}

.lamp::after {
  content: "";
  position: absolute;
  left: -82px;
  top: -86px;
  width: 172px;
  height: 172px;
  background: radial-gradient(circle, rgba(215, 168, 70, 0.22), transparent 66%);
}

.world {
  position: absolute;
  left: 0;
  bottom: 0;
  z-index: 3;
  width: 3720px;
  height: 720px;
  transform: translate3d(0, 0, 0);
  will-change: transform;
}

.platform {
  position: absolute;
  height: 42px;
  border: 1px solid rgba(246, 236, 213, 0.14);
  border-radius: 8px 8px 4px 4px;
  background:
    linear-gradient(180deg, rgba(246, 236, 213, 0.11) 0 3px, transparent 3px),
    repeating-linear-gradient(90deg, rgba(246, 236, 213, 0.08) 0 22px, transparent 22px 44px),
    linear-gradient(180deg, #366a55, #183f38);
  box-shadow:
    inset 0 1px rgba(255, 255, 255, 0.1),
    0 18px 32px rgba(2, 9, 16, 0.28);
}

.platform.stone {
  background:
    linear-gradient(180deg, rgba(246, 236, 213, 0.16) 0 3px, transparent 3px),
    repeating-linear-gradient(90deg, rgba(13, 23, 32, 0.18) 0 34px, transparent 34px 68px),
    linear-gradient(180deg, #65756f, #354945);
}

.platform.book {
  background:
    linear-gradient(180deg, rgba(246, 236, 213, 0.18) 0 4px, transparent 4px),
    repeating-linear-gradient(90deg, #7c3f48 0 44px, #bd8b47 44px 52px, #315b52 52px 92px),
    linear-gradient(180deg, #84495d, #39283c);
}

.platform.bridge {
  background:
    repeating-linear-gradient(90deg, #8b6741 0 46px, #6f4c34 46px 52px),
    linear-gradient(180deg, #9d7449, #553d31);
}

.pince {
  position: absolute;
  width: 96px;
  height: 104px;
  z-index: 8;
  background-image: url("./assets/pince-spritesheet.webp");
  background-repeat: no-repeat;
  background-size: 800% 900%;
  background-position: 0% 0%;
  filter: drop-shadow(0 16px 12px rgba(1, 8, 12, 0.38));
  transform-origin: 50% 100%;
  will-change: transform, left, top, background-position;
}

.item,
.stand,
.hazard {
  position: absolute;
  z-index: 5;
}

.item {
  width: 34px;
  height: 42px;
  transform: translate(-50%, -50%);
  transition:
    opacity 0.18s ease,
    transform 0.18s ease;
}

.item.page {
  border-radius: 4px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.45), transparent 34%),
    linear-gradient(180deg, #f6e8bd, #dcb970);
  box-shadow:
    0 0 18px rgba(240, 220, 168, 0.78),
    inset 0 0 0 1px rgba(71, 45, 30, 0.22);
  animation: floatPage 1.7s ease-in-out infinite alternate;
}

.item.page::before,
.item.page::after {
  content: "";
  position: absolute;
  left: 8px;
  right: 7px;
  height: 2px;
  background: rgba(87, 55, 36, 0.38);
}

.item.page::before {
  top: 13px;
}

.item.page::after {
  top: 22px;
  right: 12px;
}

.item.tea {
  width: 42px;
  height: 34px;
  border-radius: 0 0 13px 13px;
  background:
    radial-gradient(circle at 54% 12%, rgba(246, 236, 213, 0.72), transparent 28%),
    linear-gradient(180deg, #f4dfaa, #a95d54);
  box-shadow: 0 0 18px rgba(215, 168, 70, 0.55);
  animation: floatPage 1.9s ease-in-out infinite alternate;
}

.item.tea::after {
  content: "";
  position: absolute;
  right: -12px;
  top: 10px;
  width: 17px;
  height: 13px;
  border: 4px solid #d1a45f;
  border-left: 0;
  border-radius: 0 16px 16px 0;
}

.item.collected {
  opacity: 0;
  transform: translate(-50%, -58%) scale(1.45) rotate(8deg);
  pointer-events: none;
}

@keyframes floatPage {
  from {
    translate: 0 0;
  }
  to {
    translate: 0 -12px;
  }
}

.hazard {
  height: 18px;
  border-radius: 50%;
  background:
    radial-gradient(ellipse at 50% 30%, rgba(99, 55, 86, 0.86), rgba(23, 14, 25, 0.96) 62%, transparent 66%),
    linear-gradient(90deg, transparent, rgba(246, 236, 213, 0.18), transparent);
  box-shadow: 0 0 18px rgba(155, 63, 88, 0.48);
}

.stand {
  width: 58px;
  height: 84px;
  transform: translate(-50%, -100%);
}

.stand::before {
  content: "";
  position: absolute;
  left: 13px;
  bottom: 0;
  width: 32px;
  height: 58px;
  background: linear-gradient(180deg, #8a6742, #4c342b);
  clip-path: polygon(38% 0, 62% 0, 75% 100%, 25% 100%);
}

.stand::after {
  content: "";
  position: absolute;
  left: 2px;
  top: 0;
  width: 54px;
  height: 36px;
  border-radius: 5px 5px 8px 8px;
  background:
    linear-gradient(90deg, rgba(246, 236, 213, 0.28) 49%, rgba(75, 48, 40, 0.36) 50%),
    linear-gradient(180deg, #d9bd78, #8c5a40);
  box-shadow: 0 0 14px rgba(215, 168, 70, 0.28);
}

.stand.active::after {
  box-shadow:
    0 0 18px rgba(240, 220, 168, 0.72),
    0 0 30px rgba(47, 111, 87, 0.42);
}

.finish-gate {
  position: absolute;
  left: 3500px;
  top: 424px;
  z-index: 4;
  width: 128px;
  height: 172px;
  border: 4px solid rgba(215, 168, 70, 0.62);
  border-bottom: 0;
  border-radius: 64px 64px 0 0;
  background:
    radial-gradient(circle at 50% 66%, rgba(240, 220, 168, 0.24), transparent 42%),
    linear-gradient(180deg, rgba(40, 94, 83, 0.62), rgba(14, 44, 43, 0.2));
  box-shadow:
    inset 0 0 0 2px rgba(246, 236, 213, 0.14),
    0 0 30px rgba(215, 168, 70, 0.18);
}

.gate-roof {
  position: absolute;
  left: -22px;
  top: -30px;
  width: 164px;
  height: 48px;
  border-radius: 8px 8px 4px 4px;
  background: linear-gradient(180deg, #8d4e5a, #4a3041);
  clip-path: polygon(50% 0, 100% 74%, 88% 100%, 12% 100%, 0 74%);
}

.gate-light {
  position: absolute;
  left: 31px;
  bottom: 22px;
  width: 58px;
  height: 74px;
  border-radius: 50% 50% 42% 42%;
  background: radial-gradient(circle, rgba(240, 220, 168, 0.76), rgba(215, 168, 70, 0.22) 58%, transparent 68%);
  animation: gatePulse 1.8s ease-in-out infinite alternate;
}

@keyframes gatePulse {
  from {
    opacity: 0.5;
    scale: 0.96;
  }
  to {
    opacity: 1;
    scale: 1.03;
  }
}

.hud {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  left: max(14px, env(safe-area-inset-left));
  right: max(14px, env(safe-area-inset-right));
  z-index: 12;
  display: flex;
  align-items: center;
  gap: 10px;
  pointer-events: none;
}

.hud-title,
.hud-stat {
  min-height: 42px;
  border: 1px solid rgba(246, 236, 213, 0.18);
  border-radius: 8px;
  background: rgba(7, 17, 29, 0.68);
  color: var(--cream);
  box-shadow: 0 14px 34px var(--shadow);
  backdrop-filter: blur(16px);
}

.hud-title {
  display: flex;
  align-items: center;
  padding: 0 14px;
  font-weight: 800;
}

.hud-stat {
  display: grid;
  min-width: 92px;
  padding: 4px 10px 5px;
}

.hud-stat span {
  color: #ffe39a;
  font-size: 1.04rem;
  font-weight: 800;
  line-height: 1.15;
}

.hud-stat small {
  color: rgba(246, 236, 213, 0.72);
  font-size: 0.72rem;
  line-height: 1.1;
}

.toast {
  position: absolute;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  z-index: 12;
  width: min(620px, calc(100vw - 28px));
  min-height: 44px;
  padding: 11px 16px;
  border: 1px solid rgba(246, 236, 213, 0.2);
  border-radius: 8px;
  background: rgba(7, 17, 29, 0.72);
  color: var(--cream);
  box-shadow: 0 18px 40px var(--shadow);
  text-align: center;
  transform: translateX(-50%);
  transition:
    opacity 0.18s ease,
    translate 0.18s ease;
  backdrop-filter: blur(18px);
}

.toast.quiet {
  opacity: 0.1;
  translate: 0 14px;
}

.hint {
  position: absolute;
  z-index: 13;
  width: 30px;
  height: 30px;
  border: 1px solid rgba(246, 236, 213, 0.35);
  border-radius: 50%;
  background: rgba(215, 168, 70, 0.88);
  color: #1f1720;
  font-weight: 900;
  text-align: center;
  line-height: 29px;
  box-shadow: 0 0 20px rgba(215, 168, 70, 0.5);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.touch-pad {
  position: absolute;
  right: max(14px, env(safe-area-inset-right));
  bottom: max(14px, env(safe-area-inset-bottom));
  z-index: 14;
  display: none;
  grid-template-columns: repeat(4, 48px);
  gap: 8px;
}

.touch-button {
  width: 48px;
  height: 48px;
  border: 1px solid rgba(246, 236, 213, 0.24);
  border-radius: 8px;
  background: rgba(7, 17, 29, 0.68);
  color: var(--cream);
  font-size: 1.4rem;
  font-weight: 900;
  box-shadow: 0 14px 28px var(--shadow);
  backdrop-filter: blur(14px);
}

.touch-button:active,
.touch-button.active {
  background: rgba(215, 168, 70, 0.82);
  color: #1f1720;
}

.touch-button.inspect {
  color: #ffe39a;
}

.victory {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(6, 14, 24, 0.58);
  backdrop-filter: blur(10px);
}

.victory[hidden] {
  display: none;
}

.victory-panel {
  width: min(420px, 100%);
  border: 1px solid rgba(246, 236, 213, 0.24);
  border-radius: 8px;
  padding: 22px;
  background: rgba(12, 30, 39, 0.92);
  color: var(--cream);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.38);
  text-align: center;
}

.victory-panel h1 {
  margin: 0 0 10px;
  color: #ffe39a;
  font-size: clamp(2rem, 7vw, 3.2rem);
  line-height: 1.02;
}

.victory-panel p {
  margin: 0 0 18px;
  color: rgba(246, 236, 213, 0.8);
  line-height: 1.45;
}

.victory-panel button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  padding: 0 16px;
  background: linear-gradient(180deg, #f2d177, #bd7a48);
  color: #21141a;
  font-weight: 850;
  cursor: pointer;
}

@media (pointer: coarse), (max-width: 760px) {
  .hud {
    flex-wrap: wrap;
    gap: 8px;
  }

  .hud-title {
    width: 100%;
    min-height: 36px;
    font-size: 0.95rem;
  }

  .hud-stat {
    min-width: 76px;
    min-height: 38px;
  }

  .touch-pad {
    display: grid;
  }

  .toast {
    bottom: calc(76px + env(safe-area-inset-bottom));
    font-size: 0.92rem;
  }
}
