:root {
  --sky-top: #d6ebe5;
  --sky-bottom: #a8cdbf;
  --leaf: #4c8f58;
  --good: #2b7a3f;
  --bad: #9f3b3b;
  --text: #17231a;
  --ground-letter-size: 64px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Trebuchet MS", "Avenir Next", sans-serif;
  background: #c9e8e4;
  color: var(--text);
  overflow-x: hidden;
}

.scene {
  position: relative;
  overflow: hidden;
  min-height: 100vh;
  max-width: 1024px;
  margin: 0 auto;
  padding: 16px;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 10px;
  background: linear-gradient(var(--sky-top), var(--sky-bottom));
}

.start-overlay {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  gap: 12px;
  padding: 18px;
  background: #1f4a33;
}

.start-overlay.hidden {
  display: none;
}

.start-hero {
  position: relative;
  width: min(760px, 88vw);
  aspect-ratio: 16 / 10;
  border-radius: 14px;
  overflow: hidden;
  border: 3px solid rgba(255, 255, 255, 0.6);
  box-shadow: 0 16px 26px rgba(0, 0, 0, 0.3);
}

.start-hero-bg {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(to top, rgba(0, 0, 0, 0.2), rgba(0, 0, 0, 0)),
    url('/assets/intro.webp');
  background-size: cover;
  background-position: center left;
}

.start-title {
  padding: 10px 14px;
  border-radius: 10px;
  background: rgba(255, 253, 245, 0.96);
  border: 2px solid rgba(42, 79, 57, 0.7);
  color: var(--text);
  font-size: clamp(1rem, 1.6vw, 1.35rem);
  font-weight: 900;
  text-align: center;
}

.start-panel {
  position: absolute;
  right: 4%;
  left: auto;
  top: 10%;
  display: grid;
  gap: 8px;
  justify-items: stretch;
  align-content: start;
  width: min(420px, 48%);
}

.start-subtitle {
  margin: 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(255, 253, 245, 0.95);
  border: 2px solid rgba(42, 79, 57, 0.45);
  color: var(--text);
  font-size: clamp(0.82rem, 1.2vw, 0.97rem);
  line-height: 1.35;
}

.start-btn {
  min-width: 120px;
  min-height: 54px;
  font-size: 1.02rem;
}

.start-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: flex-start;
}

.bg-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-repeat: no-repeat;
}

.bg-layer.upper {
  z-index: 0;
  background-image: url('/assets/backgrounds/bg_far_forest.png');
  background-size: cover;
  background-position: center top;
  opacity: 0.9;
}

.bg-layer.lower {
  z-index: 1;
  background-image: url('/assets/backgrounds/bg_near_foliage.png');
  background-size: cover;
  background-position: center bottom;
  opacity: 0.95;
}

.top-bar,
.play-area {
  position: relative;
  z-index: 6;
}

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.session-info {
  font-size: 1.2rem;
  font-weight: 800;
}

.btn {
  min-height: 56px;
  border: 0;
  border-radius: 12px;
  padding: 0 20px;
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  background: #d9e7d7;
  color: #19321f;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}

.btn-primary {
  background: var(--leaf);
  color: #fff;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.play-area {
  display: grid;
  align-content: start;
}

.phase {
  display: none;
  gap: 8px;
}

.phase.active {
  display: grid;
}

.slots {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
  padding-top: 4px;
}

.slot {
  width: 58px;
  height: 58px;
  border: 3px dashed #5a4d39;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: rgba(248, 242, 231, 0.94);
  font-weight: 800;
  font-size: 1.65rem;
}

.slot.filled {
  border-style: solid;
  border-color: #2b7a3f;
  color: #1e5c31;
}

.slot.separator {
  width: 20px;
  border: 0;
  background: transparent;
}

.forest-arena {
  position: relative;
  min-height: clamp(320px, 46vh, 430px);
  border-radius: 14px;
  overflow: hidden;
  border: 2px solid rgba(25, 49, 31, 0.42);
  background: linear-gradient(to bottom, rgba(218, 238, 229, 0.1), rgba(90, 138, 98, 0.22));
}

.forest-arena::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0));
  z-index: 1;
}

.forest-arena::after {
  content: none;
}

.lane {
  position: absolute;
  left: 0;
  right: 0;
  z-index: 2;
}

.lane::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 24px;
  background:
    radial-gradient(circle at 22px 14px, rgba(140, 184, 95, 0.95) 0 14px, transparent 15px),
    radial-gradient(circle at 90px 12px, rgba(131, 178, 88, 0.9) 0 13px, transparent 14px),
    linear-gradient(180deg, #93c464 0%, #71a449 100%);
  border-bottom: 2px solid rgba(63, 92, 44, 0.8);
}

.lane::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 22px;
  bottom: 0;
  background:
    radial-gradient(circle at 18px 16px, rgba(94, 71, 45, 0.9) 0 4px, transparent 5px),
    radial-gradient(circle at 56px 28px, rgba(111, 82, 51, 0.9) 0 3px, transparent 4px),
    radial-gradient(circle at 102px 20px, rgba(85, 64, 40, 0.85) 0 4px, transparent 5px),
    linear-gradient(180deg, #8a653d 0%, #6d4d2f 100%);
  opacity: 0.94;
}

.lane-upper {
  top: 33%;
  height: 28%;
}

.lane-lower {
  bottom: 0;
  height: 34%;
}

.speech-wrap {
  position: absolute;
  left: 28px;
  top: 10px;
  display: flex;
  align-items: flex-start;
  gap: 4px;
  z-index: 9;
  transform: translateX(0);
}

.speech-wrap.enter {
  animation: ursanox-enter 680ms ease-out;
}

@keyframes ursanox-enter {
  0% { transform: translateX(-280px); }
  100% { transform: translateX(0); }
}

#ursanoxAssemblySprite {
  height: clamp(176px, 24vh, 236px);
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  filter: drop-shadow(0 3px 0 rgba(0, 0, 0, 0.35));
  position: relative;
  z-index: 2;
}

.speech-bubble {
  min-width: 160px;
  min-height: 62px;
  border-radius: 14px;
  padding: 10px 18px;
  background: #fffdf5;
  border: 3px solid #2f4f39;
  font-size: 1.7rem;
  font-weight: 800;
  text-transform: lowercase;
  display: grid;
  place-items: center;
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
  position: relative;
  margin-left: -8px;
}

.speech-bubble::before {
  content: "";
  position: absolute;
  left: -14px;
  top: 28px;
  width: 16px;
  height: 16px;
  background: #fffdf5;
  border-left: 3px solid #2f4f39;
  border-bottom: 3px solid #2f4f39;
  transform: rotate(45deg);
}

.ground-letters {
  position: absolute;
  inset: 0;
  z-index: 6;
}

.ground-letter {
  position: absolute;
  width: var(--ground-letter-size);
  height: var(--ground-letter-size);
  border-radius: 14px;
  border: 3px solid #203429;
  background-color: #f2e5c8;
  background-image: linear-gradient(145deg, #f4e7cc, #e5d2af);
  box-shadow: 0 8px 14px rgba(17, 31, 22, 0.14), inset 0 1px 0 rgba(255, 255, 255, 0.45);
  display: grid;
  place-items: center;
  font-size: 1.95rem;
  font-weight: 800;
  color: #17231a;
  text-transform: lowercase;
  user-select: none;
  transition: transform 240ms ease, opacity 240ms ease;
}

.ground-letter.bad {
  transform: scale(1.12);
  border-color: var(--bad);
}

.ground-letter.thrown {
  opacity: 0;
}

.benjax-actor {
  position: absolute;
  bottom: 10px;
  left: 24px;
  width: 124px;
  height: 156px;
  z-index: 7;
  transform: translateX(0);
}

.benjax-actor img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  filter: drop-shadow(0 3px 0 rgba(0, 0, 0, 0.35));
}

.controls {
  display: flex;
  justify-content: center;
  gap: 10px;
}

.common-controls {
  position: relative;
  width: min(310px, 94vw);
  height: 184px;
  margin: 0 auto;
}

.control-node {
  position: absolute;
  width: 60px;
  height: 60px;
  border-radius: 999px;
  border: 3px solid #244633;
  background: #e5efe2;
  color: #17361f;
  font-size: 1.8rem;
  font-weight: 800;
  display: grid;
  place-items: center;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.control-node.left { left: 2%; top: 50%; transform: translateY(-50%); }
.control-node.right { right: 2%; top: 50%; transform: translateY(-50%); }
.control-node.jump { left: 50%; top: 0; transform: translateX(-50%); }
.control-node.action {
  left: 50%;
  top: 50%;
  width: 72px;
  height: 72px;
  transform: translate(-50%, -50%);
  background: var(--leaf);
  color: #fff;
}
.control-node.swap { left: 50%; bottom: 0; transform: translateX(-50%); }

.control-node.is-pressed {
  transform: translateY(-50%) scale(0.95);
}

.control-node.jump.is-pressed,
.control-node.swap.is-pressed {
  transform: translateX(-50%) scale(0.95);
}

.control-node.action.is-pressed {
  transform: translate(-50%, -50%) scale(0.95);
}

.control-node.is-disabled {
  background: #b8c0ba;
  border-color: #6f7a72;
  color: #e9ece8;
  cursor: not-allowed;
  opacity: 0.85;
}

.next-overlay {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  z-index: 9;
}

.control-btn {
  min-width: 120px;
  -webkit-tap-highlight-color: transparent;
}

.hint {
  min-height: 1.25em;
  margin: 0;
  font-weight: 700;
  font-size: 1.02rem;
}

#assemblyHint {
  color: #d4ffd3;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
}

.input-panel {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  background: rgba(240, 228, 204, 0.96);
  border: 4px solid rgba(111, 80, 48, 0.9);
  border-radius: 12px;
  padding: 12px;
}

#recallInput {
  flex: 1;
  min-width: 180px;
  min-height: 60px;
  font-size: 1.7rem;
  border: 2px solid #44614a;
  border-radius: 10px;
  padding: 0 12px;
}

#recallInput.shake {
  animation: shake 220ms linear;
  border-color: var(--bad);
}

@keyframes shake {
  0% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  50% { transform: translateX(5px); }
  75% { transform: translateX(-3px); }
  100% { transform: translateX(0); }
}

.summary {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 20;
}

.summary > * {
  width: min(460px, 100%);
  background: #eef5e9;
  border: 4px solid #304d38;
  border-radius: 14px;
  padding: 8px 14px;
  margin: 0;
}

.summary .btn {
  width: min(460px, 100%);
}

.hidden {
  display: none;
}

@media (max-width: 768px) {
  .forest-arena {
    min-height: 420px;
  }

  #ursanoxAssemblySprite {
    height: 202px;
  }

  .lane-upper {
    top: 142px;
    height: 108px;
  }

  .speech-bubble {
    font-size: 1.4rem;
  }

  .benjax-actor {
    width: 120px;
    height: 150px;
    bottom: 16px;
  }

  .ground-letter {
    --ground-letter-size: 58px;
  }

  .control-btn {
    min-width: 96px;
  }
}

@media (orientation: portrait) and (max-width: 900px) {
  .scene {
    max-width: 100vw;
    padding: 6px;
    gap: 6px;
    min-height: 100dvh;
    height: auto;
    padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px));
  }

  .play-area {
    min-height: 0;
    display: block;
  }

  #assemblyPhase.phase.active {
    min-height: 0;
    height: auto;
    grid-template-rows: none;
    align-content: start;
  }

  .top-bar {
    gap: 6px;
  }

  .session-info {
    font-size: 0.95rem;
  }

  .btn {
    min-height: 42px;
    font-size: 0.9rem;
    padding: 0 10px;
  }

  .slot {
    width: 44px;
    height: 44px;
    font-size: 1.2rem;
  }

  .forest-arena {
    min-height: 280px;
    height: 48vh;
    max-height: 420px;
  }

  .lane-upper {
    top: 30%;
    height: 20%;
  }

  .lane-lower {
    height: 30%;
  }

  #ursanoxAssemblySprite {
    height: 148px;
  }

  .speech-bubble {
    min-width: 122px;
    min-height: 50px;
    font-size: 0.96rem;
    padding: 6px 10px;
  }

  .ground-letter {
    --ground-letter-size: 44px;
    font-size: 1.45rem;
  }

  .benjax-actor {
    width: 94px;
    height: 122px;
    bottom: 8px;
  }

  .controls {
    gap: 6px;
  }

  .common-controls {
    width: min(230px, 92vw);
    height: 126px;
    margin-bottom: env(safe-area-inset-bottom, 0);
  }

  .control-node {
    width: 42px;
    height: 42px;
    font-size: 1.15rem;
  }

  .control-node.action {
    width: 50px;
    height: 50px;
  }

  .control-btn {
    min-width: 76px;
  }

  .hint {
    display: none;
  }

  .start-hero {
    width: min(94vw, 560px);
    aspect-ratio: auto;
    overflow: visible;
    border: 0;
    box-shadow: none;
    background: transparent;
    display: grid;
    gap: 10px;
  }

  .start-hero-bg {
    position: relative;
    border-radius: 14px;
    border: 3px solid rgba(255, 255, 255, 0.6);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.25);
    min-height: 0;
    aspect-ratio: 16 / 9;
    background-position: center;
  }

  .start-panel {
    position: relative;
    left: 0;
    right: auto;
    top: 0;
    width: 100%;
    gap: 8px;
    padding: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .start-title {
    font-size: 0.98rem;
  }

  .start-subtitle {
    font-size: 0.9rem;
    line-height: 1.3;
    background: rgba(255, 253, 245, 0.95);
    color: var(--text);
    border-color: rgba(42, 79, 57, 0.45);
    backdrop-filter: blur(2px);
  }

  .start-actions {
    justify-content: stretch;
    gap: 8px;
  }

  .start-btn {
    min-width: 0;
    flex: 1 1 0;
    min-height: 46px;
    font-size: 0.95rem;
  }
}
