:root {
  color-scheme: dark;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  background: #18140f;
  color: #f3e1b5;
  --ink: #18140f;
  --panel: #2d251b;
  --panel-deep: #211b15;
  --forest: #244a32;
  --forest-light: #386b46;
  --gold: #efbd4b;
  --gold-deep: #9a6322;
  --parchment: #f3e1b5;
  --parchment-muted: #c9b687;
  --danger: #df7665;
  --border: rgba(226, 195, 126, 0.72);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-width: 320px;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--ink);
}

button,
input {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

[hidden] {
  display: none !important;
}

.boot-status {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  color: var(--parchment);
  background:
    radial-gradient(circle at 50% 40%, rgba(75, 112, 61, 0.26), transparent 35%),
    var(--ink);
  font-size: clamp(18px, 2.5vw, 28px);
  font-weight: 700;
  letter-spacing: 0.08em;
}

.lobby {
  position: fixed;
  inset: 0;
  z-index: 2;
  display: grid;
  place-items: center;
  overflow: auto;
  padding: clamp(18px, 3.2vw, 48px);
  background:
    linear-gradient(90deg, rgba(18, 20, 13, 0.56), rgba(36, 28, 15, 0.12) 45%, rgba(18, 20, 13, 0.54)),
    linear-gradient(180deg, rgba(18, 17, 12, 0.08), rgba(15, 13, 10, 0.58)),
    url("/assets/backgrounds/enchanted-forest-at-dusk.png") center / cover no-repeat;
  isolation: isolate;
}

.lobby::before,
.lobby::after {
  content: "";
  position: fixed;
  z-index: -1;
  pointer-events: none;
}

.lobby::before {
  inset: 0;
  background:
    radial-gradient(circle at center, transparent 25%, rgba(16, 14, 10, 0.2) 65%, rgba(10, 9, 7, 0.62) 100%),
    linear-gradient(180deg, rgba(12, 11, 8, 0.24), transparent 28%, rgba(12, 10, 8, 0.36));
}

.lobby::after {
  inset: auto 0 0;
  height: 28%;
  background: linear-gradient(transparent, rgba(9, 9, 7, 0.6));
}

.lobby__glow {
  position: fixed;
  z-index: -1;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ffe393;
  box-shadow:
    8vw 5vh 10px 1px rgba(255, 213, 104, 0.72),
    22vw 21vh 8px rgba(255, 221, 120, 0.6),
    45vw -3vh 12px 2px rgba(255, 219, 112, 0.56),
    67vw 14vh 9px rgba(255, 225, 133, 0.66),
    82vw 36vh 11px 1px rgba(255, 214, 97, 0.55);
  opacity: 0.62;
  animation: firefly-drift 6s ease-in-out infinite alternate;
}

.lobby__glow--one {
  top: 18%;
  left: 8%;
}

.lobby__glow--two {
  right: 13%;
  bottom: 20%;
  animation-delay: -3s;
  transform: scale(0.72);
}

.lobby-card {
  position: relative;
  display: grid;
  grid-template-columns: minmax(280px, 0.88fr) minmax(390px, 1.12fr);
  width: min(1040px, 96vw);
  min-height: 610px;
  overflow: hidden;
  border: 2px solid var(--border);
  border-radius: 30px;
  background: rgba(32, 27, 20, 0.91);
  box-shadow:
    0 32px 90px rgba(4, 4, 3, 0.62),
    0 0 0 7px rgba(36, 28, 18, 0.54),
    inset 0 1px rgba(255, 244, 201, 0.12);
  backdrop-filter: blur(14px);
}

.lobby-card::before {
  content: "";
  position: absolute;
  inset: 12px;
  pointer-events: none;
  border: 1px solid rgba(239, 189, 75, 0.16);
  border-radius: 22px;
}

.lobby-story,
.lobby-controls {
  position: relative;
  min-width: 0;
}

.lobby-story {
  display: flex;
  flex-direction: column;
  padding: 58px 46px 34px;
  overflow: hidden;
  background:
    linear-gradient(160deg, rgba(44, 91, 55, 0.88), rgba(27, 57, 39, 0.94)),
    url("/assets/backgrounds/forest-lanes-daylight.png") 18% center / auto 100% no-repeat;
  border-right: 1px solid rgba(231, 198, 126, 0.42);
}

.lobby-story::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(circle at 30% 7%, rgba(247, 205, 95, 0.24), transparent 33%),
    linear-gradient(180deg, rgba(16, 31, 21, 0.1), rgba(12, 25, 17, 0.72));
}

.lobby-kicker {
  margin: 0;
  color: var(--gold);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.24em;
}

.lobby-story h1 {
  margin: 0 0 18px;
  color: var(--parchment);
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(52px, 5vw, 76px);
  font-weight: 700;
  line-height: 0.82;
  letter-spacing: -0.055em;
  text-shadow: 0 5px 18px rgba(8, 10, 7, 0.72);
}

.lobby-story h1 span {
  color: var(--gold);
}

.lobby-lead {
  max-width: 330px;
  margin: 0;
  color: rgba(243, 225, 181, 0.83);
  font-size: 18px;
  line-height: 1.5;
}

.lobby-creatures {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  min-height: 92px;
  margin: auto -24px -15px;
  filter: drop-shadow(0 10px 10px rgba(7, 8, 6, 0.48));
}

.lobby-creatures img {
  width: 94px;
  height: 76px;
  margin: 0 -13px;
  object-fit: contain;
  transform-origin: center bottom;
}

.lobby-creatures img:nth-child(1) {
  transform: rotate(-4deg) scale(1.08);
}

.lobby-creatures img:nth-child(2) {
  transform: translateY(-3px) scale(0.86);
}

.lobby-creatures img:nth-child(3) {
  transform: scale(0.92);
}

.lobby-creatures img:nth-child(4) {
  transform: rotate(3deg) scale(0.88);
}

.lobby-controls {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 50px 54px 42px;
  background:
    radial-gradient(circle at 100% 0, rgba(179, 117, 43, 0.1), transparent 36%),
    rgba(43, 35, 26, 0.92);
}

.lobby-controls__heading h2 {
  margin: 5px 0 28px;
  color: var(--parchment);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 42px;
  line-height: 1;
}

.field {
  display: grid;
  gap: 8px;
}

.field > span {
  color: var(--parchment);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.field input {
  width: 100%;
  height: 52px;
  border: 2px solid rgba(213, 184, 119, 0.56);
  border-radius: 12px;
  outline: none;
  color: #241d15;
  background: #f0deb1;
  box-shadow: inset 0 2px 5px rgba(81, 57, 26, 0.18);
  padding: 0 16px;
  font-size: 18px;
  font-weight: 700;
  transition: border-color 140ms ease, box-shadow 140ms ease, transform 140ms ease;
}

.field input::placeholder {
  color: rgba(66, 52, 34, 0.48);
}

.field input:focus {
  border-color: var(--gold);
  box-shadow:
    0 0 0 4px rgba(239, 189, 75, 0.16),
    inset 0 2px 5px rgba(81, 57, 26, 0.16);
}

.lobby-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 16px;
}

.forest-button,
.join-button {
  border: 2px solid rgba(213, 184, 119, 0.7);
  outline: none;
  color: var(--parchment);
  cursor: pointer;
  transition: transform 130ms ease, filter 130ms ease, box-shadow 130ms ease, opacity 130ms ease;
}

.forest-button {
  display: flex;
  min-height: 74px;
  align-items: center;
  gap: 11px;
  border-radius: 14px;
  background: linear-gradient(180deg, #3a7048, #295338);
  box-shadow:
    inset 0 1px rgba(255, 255, 255, 0.1),
    0 6px 14px rgba(8, 10, 7, 0.2);
  padding: 11px 14px;
  text-align: left;
}

.forest-button--gold {
  background: linear-gradient(180deg, #9a6a2d, #6f481f);
}

.forest-button__icon {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  flex: 0 0 auto;
  border: 1px solid rgba(255, 230, 166, 0.46);
  border-radius: 50%;
  background: rgba(24, 20, 15, 0.28);
  color: var(--gold);
  font-size: 18px;
}

.forest-button strong,
.forest-button small {
  display: block;
}

.forest-button strong {
  font-size: 15px;
  line-height: 1.2;
}

.forest-button small {
  margin-top: 3px;
  color: rgba(243, 225, 181, 0.68);
  font-size: 11px;
  font-weight: 600;
}

.forest-button:hover:not(:disabled),
.join-button:hover:not(:disabled) {
  filter: brightness(1.1);
  transform: translateY(-2px);
  box-shadow:
    inset 0 1px rgba(255, 255, 255, 0.12),
    0 9px 18px rgba(8, 10, 7, 0.28);
}

.forest-button:active:not(:disabled),
.join-button:active:not(:disabled) {
  transform: translateY(0) scale(0.985);
}

.forest-button:focus-visible,
.join-button:focus-visible {
  box-shadow: 0 0 0 4px rgba(239, 189, 75, 0.24);
}

.forest-button:disabled,
.join-button:disabled {
  cursor: not-allowed;
  filter: saturate(0.42);
  opacity: 0.42;
}

.lobby-divider {
  display: flex;
  align-items: center;
  gap: 13px;
  margin: 22px 0 17px;
  color: rgba(201, 182, 135, 0.72);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.lobby-divider::before,
.lobby-divider::after {
  content: "";
  height: 1px;
  flex: 1;
  background: linear-gradient(90deg, transparent, rgba(213, 184, 119, 0.44));
}

.lobby-divider::after {
  background: linear-gradient(90deg, rgba(213, 184, 119, 0.44), transparent);
}

.join-fields {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) 132px;
  align-items: end;
  gap: 12px;
}

.field--code input {
  letter-spacing: 0.22em;
  text-transform: uppercase;
}

.join-button {
  display: flex;
  height: 52px;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border-radius: 12px;
  background: linear-gradient(180deg, #4a4032, #342c22);
  font-size: 15px;
  font-weight: 800;
}

.join-button span {
  color: var(--gold);
  font-size: 20px;
}

.lobby-status {
  display: flex;
  min-height: 42px;
  align-items: center;
  gap: 10px;
  margin-top: 24px;
  border: 1px solid rgba(213, 184, 119, 0.18);
  border-radius: 11px;
  color: var(--parchment-muted);
  background: rgba(19, 16, 12, 0.38);
  padding: 10px 13px;
  font-size: 13px;
  line-height: 1.35;
}

.lobby-status__dot {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 10px rgba(239, 189, 75, 0.72);
  animation: status-pulse 1.4s ease-in-out infinite;
}

.lobby-status[data-tone="ready"] .lobby-status__dot {
  background: #70bd72;
  box-shadow: 0 0 10px rgba(112, 189, 114, 0.7);
  animation: none;
}

.lobby-status[data-tone="error"] {
  color: #f3b4a9;
  border-color: rgba(223, 118, 101, 0.34);
}

.lobby-status[data-tone="error"] .lobby-status__dot {
  background: var(--danger);
  box-shadow: 0 0 10px rgba(223, 118, 101, 0.72);
  animation: none;
}

.game-shell {
  position: fixed;
  inset: 0;
  z-index: 1;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: var(--ink);
}

#game-canvas {
  position: fixed;
  inset: 0;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  user-select: none;
}

.game-loading {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--parchment);
  font-size: clamp(16px, 2vw, 22px);
  font-weight: 800;
  letter-spacing: 0.08em;
}

.game-loading__mark {
  color: var(--gold);
  font-size: 24px;
  animation: loading-turn 1.5s ease-in-out infinite;
}

noscript {
  position: fixed;
  z-index: 30;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--parchment);
  background: var(--ink);
}

@keyframes firefly-drift {
  from {
    translate: -4px -8px;
    opacity: 0.38;
  }

  to {
    translate: 9px 5px;
    opacity: 0.82;
  }
}

@keyframes status-pulse {
  50% {
    opacity: 0.4;
    transform: scale(0.72);
  }
}

@keyframes loading-turn {
  50% {
    transform: rotate(180deg) scale(1.16);
  }

  100% {
    transform: rotate(360deg);
  }
}

@media (max-width: 820px), (max-height: 700px) {
  html {
    height: auto;
    min-height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
  }

  body {
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .lobby {
    position: relative;
    min-height: 100vh;
    place-items: start center;
    padding: 20px;
  }

  .lobby-card {
    grid-template-columns: 1fr;
    width: min(620px, 100%);
    min-height: 0;
  }

  .lobby-story {
    min-height: 245px;
    padding: 34px 36px 26px;
    border-right: 0;
    border-bottom: 1px solid rgba(231, 198, 126, 0.42);
  }

  .lobby-story h1 {
    margin: 0 0 12px;
    font-size: 50px;
    line-height: 0.9;
  }

  .lobby-story h1 br {
    display: none;
  }

  .lobby-story h1 span {
    margin-left: 0.13em;
  }

  .lobby-lead {
    max-width: 480px;
    font-size: 15px;
  }

  .lobby-creatures {
    position: absolute;
    right: 20px;
    bottom: 5px;
    width: 200px;
    min-height: 70px;
    opacity: 0.42;
  }

  .lobby-creatures img {
    width: 64px;
    height: 58px;
  }

  .lobby-controls {
    padding: 32px 36px 34px;
  }

  .lobby-controls__heading h2 {
    margin-bottom: 20px;
    font-size: 34px;
  }
}

@media (max-width: 520px) {
  .lobby {
    padding: 10px;
  }

  .lobby-card {
    border-radius: 22px;
  }

  .lobby-story {
    min-height: 220px;
    padding: 28px 24px 22px;
  }

  .lobby-story h1 {
    font-size: 42px;
  }

  .lobby-creatures {
    display: none;
  }

  .lobby-controls {
    padding: 28px 22px 26px;
  }

  .lobby-actions {
    grid-template-columns: 1fr;
  }

  .forest-button {
    min-height: 64px;
  }

  .join-fields {
    grid-template-columns: 1fr 112px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
