:root {
  color-scheme: dark;
  font-family:
    Georgia, "Times New Roman", ui-serif, serif;
  background: #050403;
  color: #fff8df;
  --ink: #080705;
  --lacquer: #15100b;
  --ivory: #fff8df;
  --champagne: #f4df9f;
  --gold: #d7aa43;
  --gold-bright: #fff0a8;
  --gold-deep: #7c4e1f;
  --emerald: #174d3d;
  --jade: #3aa979;
  --app-width: 100vw;
  --app-height: 100vh;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  margin: 0;
  background: #050403;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
}

.game-shell {
  position: relative;
  width: var(--app-width, 100vw);
  height: 100vh;
  height: 100dvh;
  height: var(--app-height, 100vh);
  min-height: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 44%, rgba(77, 52, 20, 0.34), transparent 54%),
    linear-gradient(180deg, #060504, #100b08 52%, #030302);
  touch-action: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
}

.game-shell::before {
  position: absolute;
  inset: -12%;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 76% 18%, rgba(255, 240, 168, 0.2) 0 54px, transparent 56px),
    radial-gradient(ellipse at 28% 34%, rgba(142, 214, 173, 0.18) 0 19%, transparent 42%),
    linear-gradient(180deg, rgba(13, 49, 54, 0.46) 0%, rgba(14, 30, 26, 0.2) 44%, rgba(6, 5, 4, 0.84) 100%);
  content: "";
  opacity: 0.82;
  transform: translate3d(0, 0, 0) scale(1.03);
  animation: fallback-drift 24s linear infinite;
  will-change: transform;
}

.game-shell.video-ready::before {
  opacity: 0.34;
  animation-play-state: paused;
}

.game-shell.mobile-optimized::before {
  opacity: 0.66;
  animation-duration: 36s;
}

.game-shell.mobile-generated-background::before {
  display: none;
}

.game-shell::after {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background:
    radial-gradient(circle at 50% 38%, transparent 0 44%, rgba(0, 0, 0, 0.34) 76%),
    linear-gradient(90deg, rgba(255, 240, 168, 0.05), transparent 20% 80%, rgba(255, 240, 168, 0.05));
  content: "";
  opacity: 0.82;
}

.game-shell.mobile-optimized::after {
  display: none;
}

.background-video {
  position: absolute;
  inset: 0;
  z-index: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  pointer-events: none;
  transform: translateZ(0);
  backface-visibility: hidden;
  will-change: transform;
  transition: opacity 320ms ease;
}

.game-shell.video-ready .background-video {
  opacity: 0.22;
}

.game-shell.mobile-optimized.video-ready .background-video {
  opacity: 0.16;
}

.game-shell.mobile-optimized.game-active.video-ready .background-video {
  opacity: 0.12;
}

.game-shell.performance-saver .background-video {
  opacity: 0;
}

.game-shell.mobile-generated-background .background-video {
  display: none;
}

.game-shell.performance-saver::before {
  animation: none;
  opacity: 0.82;
}

canvas {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
  contain: strict;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

.hud {
  position: absolute;
  top: max(16px, env(safe-area-inset-top));
  left: 50%;
  display: grid;
  grid-template-columns: repeat(3, minmax(74px, 1fr));
  gap: 12px;
  width: min(472px, calc(100vw - 24px));
  transform: translateX(-50%);
  pointer-events: none;
  z-index: 2;
}

.hud > div {
  position: relative;
  overflow: hidden;
  min-height: 60px;
  padding: 10px 14px 10px 43px;
  border: 2px solid rgba(255, 240, 168, 0.88);
  border-radius: 8px;
  background:
    radial-gradient(circle at 90% 16%, rgba(255, 255, 255, 0.44) 0 8px, transparent 9px),
    linear-gradient(145deg, rgba(255, 248, 223, 0.96) 0%, rgba(244, 223, 159, 0.94) 50%, rgba(178, 127, 55, 0.94) 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.76),
    inset 0 -10px 18px rgba(124, 78, 31, 0.18),
    0 8px 18px rgba(0, 0, 0, 0.36),
    0 0 0 1px rgba(8, 7, 5, 0.72);
}

.hud > div::before {
  position: absolute;
  top: 13px;
  left: 13px;
  width: 18px;
  height: 29px;
  border: 2px solid var(--ink);
  border-radius: 60% 45% 60% 45%;
  background:
    linear-gradient(90deg, transparent 45%, rgba(124, 78, 31, 0.7) 46% 56%, transparent 57%),
    linear-gradient(145deg, var(--gold-bright) 0%, var(--gold) 52%, #a4672c 100%);
  box-shadow:
    inset 3px 3px 0 rgba(255, 255, 255, 0.48),
    0 3px 8px rgba(124, 78, 31, 0.32);
  content: "";
  transform: rotate(-24deg);
}

.hud > div::after {
  position: absolute;
  right: -18px;
  bottom: -21px;
  width: 64px;
  height: 42px;
  border: 2px solid rgba(8, 7, 5, 0.16);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.14);
  content: "";
}

.leaderboard-panel {
  position: absolute;
  top: max(92px, calc(env(safe-area-inset-top) + 84px));
  right: max(14px, env(safe-area-inset-right));
  z-index: 4;
  width: min(286px, calc(100vw - 28px));
  max-height: min(66vh, 560px);
  overflow: hidden;
  padding: 13px;
  border: 2px solid rgba(255, 240, 168, 0.92);
  border-radius: 8px;
  background:
    radial-gradient(circle at 92% 10%, rgba(255, 255, 255, 0.5) 0 10px, transparent 11px),
    linear-gradient(145deg, rgba(255, 248, 223, 0.97), rgba(244, 223, 159, 0.96) 52%, rgba(178, 127, 55, 0.96));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.78),
    inset 0 -14px 24px rgba(124, 78, 31, 0.18),
    0 14px 28px rgba(0, 0, 0, 0.42),
    0 0 0 1px rgba(8, 7, 5, 0.74);
  color: #281a10;
  pointer-events: auto;
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

.leaderboard-panel::before {
  position: absolute;
  top: 13px;
  left: 14px;
  width: 18px;
  height: 33px;
  border: 2px solid var(--ink);
  border-radius: 60% 45% 60% 45%;
  background:
    linear-gradient(90deg, transparent 45%, rgba(124, 78, 31, 0.72) 46% 56%, transparent 57%),
    linear-gradient(145deg, var(--gold-bright) 0%, var(--gold) 52%, #a4672c 100%);
  box-shadow:
    inset 3px 3px 0 rgba(255, 255, 255, 0.48),
    0 3px 8px rgba(124, 78, 31, 0.32);
  content: "";
  transform: rotate(-22deg);
}

.game-shell.game-active .leaderboard-panel {
  opacity: 0;
  pointer-events: none;
  transform: translateY(-8px);
}

.leaderboard-heading {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 38px;
  padding-left: 34px;
}

.leaderboard-heading h2 {
  margin: 0;
  color: #281a10;
  font-size: 1rem;
  line-height: 1;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.54);
}

.mini-button {
  min-width: 72px;
  min-height: 30px;
  padding: 0 10px;
  border-color: rgba(8, 7, 5, 0.74);
  border-radius: 7px;
  font-size: 0.72rem;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.76),
    0 4px 0 #6f471f,
    0 8px 14px rgba(0, 0, 0, 0.24);
}

.mini-button:active {
  transform: translateY(2px);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.76),
    0 2px 0 #6f471f,
    0 4px 8px rgba(0, 0, 0, 0.24);
}

.leaderboard-list {
  display: grid;
  gap: 5px;
  max-height: min(43vh, 340px);
  margin: 10px 0 8px;
  padding: 0;
  overflow: auto;
  scrollbar-width: thin;
  list-style: none;
}

.leaderboard-list li {
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  min-height: 28px;
  padding: 5px 8px;
  border: 1px solid rgba(124, 78, 31, 0.34);
  border-radius: 7px;
  background: rgba(255, 248, 223, 0.44);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  font-size: 0.78rem;
  font-weight: 800;
}

.leaderboard-list li:nth-child(1),
.leaderboard-list li:nth-child(2),
.leaderboard-list li:nth-child(3) {
  background:
    radial-gradient(circle at 92% 16%, rgba(255, 255, 255, 0.5) 0 5px, transparent 6px),
    rgba(255, 240, 168, 0.64);
}

.score-rank {
  color: #7c4e1f;
  font-variant-numeric: tabular-nums;
}

.score-name {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.score-value {
  color: #130d08;
  font-variant-numeric: tabular-nums;
}

.empty-score {
  grid-template-columns: 1fr !important;
  color: rgba(48, 32, 18, 0.72);
  text-align: center;
}

.leaderboard-status {
  min-height: 16px;
  margin: 0 0 8px;
  color: rgba(48, 32, 18, 0.72);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  font-size: 0.72rem;
  font-weight: 800;
  line-height: 1.25;
}

.score-submit {
  display: grid;
  gap: 7px;
  padding-top: 9px;
  border-top: 1px solid rgba(124, 78, 31, 0.32);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

.score-submit.hidden {
  display: none;
}

.score-submit label {
  color: rgba(48, 32, 18, 0.78);
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
}

.score-submit div {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 7px;
}

.score-submit input {
  width: 100%;
  min-height: 37px;
  padding: 0 10px;
  border: 2px solid rgba(8, 7, 5, 0.72);
  border-radius: 7px;
  background: rgba(255, 248, 223, 0.88);
  color: #281a10;
  font:
    800 0.84rem/1 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
  outline: none;
}

.score-submit input:focus {
  box-shadow: 0 0 0 3px rgba(255, 240, 168, 0.76);
}

.score-submit button {
  min-width: 78px;
  min-height: 37px;
  padding: 0 11px;
  border-color: rgba(8, 7, 5, 0.74);
  font-size: 0.78rem;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.76),
    0 4px 0 #6f471f,
    0 8px 14px rgba(0, 0, 0, 0.24);
}

.score-submit button:disabled {
  cursor: wait;
  filter: grayscale(0.25);
  opacity: 0.72;
}

.label {
  display: block;
  color: rgba(48, 32, 18, 0.72);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

strong {
  display: block;
  margin-top: 2px;
  color: #281a10;
  font-family:
    Georgia, "Times New Roman", ui-serif, serif;
  font-size: clamp(1.2rem, 4vw, 1.9rem);
  line-height: 1;
  text-shadow:
    0 1px 0 rgba(255, 255, 255, 0.56),
    0 5px 12px rgba(124, 78, 31, 0.22);
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 18px;
  padding: 24px;
  background:
    radial-gradient(circle at 50% 44%, rgba(255, 240, 168, 0.13), transparent 46%),
    linear-gradient(rgba(5, 4, 3, 0.1), rgba(5, 4, 3, 0.48));
  text-align: center;
  z-index: 3;
}

.overlay.hidden {
  display: none;
}

.overlay h1 {
  margin: 0;
  color: var(--ivory);
  font-size: clamp(2.8rem, 10vw, 6.2rem);
  font-weight: 700;
  line-height: 0.94;
  text-shadow:
    0 2px 0 #6f471f,
    0 9px 24px rgba(0, 0, 0, 0.52),
    0 0 34px rgba(255, 240, 168, 0.34);
}

.overlay p {
  width: min(560px, 86vw);
  margin: 0 auto;
  padding: 11px 15px;
  border: 2px solid rgba(255, 240, 168, 0.82);
  border-radius: 8px;
  background:
    linear-gradient(145deg, rgba(255, 248, 223, 0.94), rgba(244, 223, 159, 0.9));
  color: #281a10;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.72),
    0 14px 28px rgba(0, 0, 0, 0.4),
    0 0 0 1px rgba(8, 7, 5, 0.62);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  font-size: clamp(1rem, 3vw, 1.22rem);
  line-height: 1.5;
  text-shadow: none;
}

button {
  justify-self: center;
  min-width: 148px;
  min-height: 48px;
  padding: 0 22px;
  border: 2px solid rgba(255, 240, 168, 0.92);
  border-radius: 8px;
  background:
    radial-gradient(circle at 80% 18%, #fff7c5 0 8px, transparent 9px),
    linear-gradient(145deg, #fff0a8, var(--gold) 56%, #9a632c);
  color: #130d08;
  cursor: pointer;
  font:
    800 0.95rem/1 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.78),
    0 8px 0 #6f471f,
    0 14px 24px rgba(0, 0, 0, 0.42);
}

button:active {
  transform: translateY(4px);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.78),
    0 4px 0 #6f471f,
    0 8px 16px rgba(0, 0, 0, 0.42);
}

@keyframes fallback-drift {
  0% {
    transform: translate3d(0, 0, 0) scale(1.03);
  }

  100% {
    transform: translate3d(-52px, 0, 0) scale(1.03);
  }
}

@keyframes mobile-bg-drift {
  0% {
    transform: translate3d(0, 0, 0) scale(1.02);
  }

  100% {
    transform: translate3d(-8%, 0, 0) scale(1.02);
  }
}

@media (prefers-reduced-motion: reduce) {
  .game-shell::before {
    animation: none;
  }
}

@media (pointer: coarse) {
  body {
    position: fixed;
    inset: 0;
    touch-action: none;
  }
}

@media (max-width: 560px) {
  .game-shell {
    height: var(--app-height, 100svh);
  }

  .hud {
    top: max(10px, env(safe-area-inset-top));
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
  }

  .hud > div {
    min-height: 50px;
    padding: 7px 8px 7px 31px;
  }

  .hud > div::before {
    top: 13px;
    left: 8px;
    width: 15px;
    height: 22px;
  }

  .leaderboard-panel {
    top: auto;
    right: max(10px, env(safe-area-inset-right));
    bottom: max(10px, env(safe-area-inset-bottom));
    left: max(10px, env(safe-area-inset-left));
    width: auto;
    max-height: 37vh;
    padding: 10px;
  }

  .leaderboard-list {
    max-height: 17vh;
    margin-top: 7px;
  }

  .leaderboard-list li {
    min-height: 25px;
    padding: 4px 7px;
    font-size: 0.72rem;
  }

  .leaderboard-heading {
    min-height: 32px;
  }

  .leaderboard-heading h2 {
    font-size: 0.92rem;
  }

  .score-submit div {
    grid-template-columns: minmax(0, 1fr) auto;
  }
}
