:root {
  color-scheme: light;
  --ink: #19323c;
  --muted: #5f7480;
  --panel: #fffaf0;
  --line: #c9e1d9;
  --accent: #ff6b35;
  --accent-dark: #b23a1f;
  --mint: #5fc8a6;
  --advanced-ui-scale: 1;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  overscroll-behavior: none;
}

body {
  font-family: Avenir, "Avenir Next", "Trebuchet MS", system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 18% 12%, rgba(255, 205, 114, 0.35), transparent 28rem),
    radial-gradient(circle at 88% 18%, rgba(95, 200, 166, 0.28), transparent 24rem),
    linear-gradient(135deg, #eef8f6 0%, #fff4dc 52%, #fbe5d5 100%);
  touch-action: manipulation;
}

.shell {
  width: min(1100px, calc(100vw - 24px));
  min-height: 100vh;
  margin: 0 auto;
  display: grid;
  place-items: center;
  padding: 22px 0;
}

.game-card {
  width: 100%;
  padding: clamp(14px, 2vw, 22px);
  border: 1px solid rgba(25, 50, 60, 0.12);
  border-radius: 8px;
  background: rgba(255, 250, 240, 0.82);
  box-shadow: 0 28px 70px rgba(75, 54, 32, 0.16);
  backdrop-filter: blur(14px);
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent-dark);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 5vw, 4.2rem);
  line-height: 0.95;
  letter-spacing: 0;
}

button {
  min-height: 40px;
  border: 0;
  border-radius: 8px;
  padding: 0 14px;
  color: #fffaf0;
  background: #19323c;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

button:hover {
  background: #254957;
}

.topbar button,
.restart-button,
.initials-panel,
.onboarding-card,
.lootbox-card,
.control-strip {
  transform: scale(var(--advanced-ui-scale));
}

.topbar button,
.restart-button {
  transform-origin: right center;
}

.initials-panel,
.onboarding-card,
.lootbox-card {
  transform-origin: center;
}

.control-strip {
  transform-origin: left top;
}

.canvas-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 8 / 3;
  border: 2px solid rgba(25, 50, 60, 0.16);
  border-radius: 8px;
  overflow: hidden;
  background: #c7f1ff;
  touch-action: none;
  user-select: none;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: auto;
  touch-action: none;
  cursor: default;
  user-select: none;
}

.onboarding-panel {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: none;
  place-items: center;
  padding: 18px;
  background:
    radial-gradient(circle at 28% 16%, rgba(255, 209, 102, 0.28), transparent 16rem),
    rgba(18, 32, 38, 0.68);
}

.onboarding-panel.is-visible {
  display: grid;
}

.onboarding-card {
  width: min(390px, 100%);
  padding: clamp(16px, 2.6vw, 22px);
  border: 1px solid rgba(255, 209, 102, 0.42);
  border-radius: 8px;
  color: #fffaf0;
  background: rgba(8, 14, 28, 0.92);
  box-shadow: 0 18px 52px rgba(0, 0, 0, 0.28);
}

.onboarding-kicker {
  margin: 0 0 6px;
  color: #ffd166;
  font-size: 0.74rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.onboarding-card h2 {
  margin: 0 0 12px;
  font-size: clamp(1.55rem, 4vw, 2.15rem);
  line-height: 1;
  letter-spacing: 0;
}

.onboarding-card ul {
  display: grid;
  gap: 8px;
  margin: 0 0 16px;
  padding: 0 0 0 18px;
  color: #d8ecf4;
  font-size: 0.95rem;
  line-height: 1.32;
}

.onboarding-card button {
  width: 100%;
  color: #2b170d;
  background: #ffd166;
}

.onboarding-card button:hover {
  background: #ffe08a;
}

.restart-button {
  position: absolute;
  right: 18px;
  bottom: 18px;
  display: none;
  background: var(--accent);
  color: #2b170d;
}

.restart-button.is-visible {
  display: block;
}

.initials-panel {
  position: absolute;
  left: 50%;
  bottom: 34px;
  z-index: 3;
  display: none;
  width: min(260px, calc(100% - 28px));
  transform: translateX(-50%);
  padding: 10px;
  border: 1px solid rgba(255, 209, 102, 0.52);
  border-radius: 8px;
  background: rgba(16, 28, 38, 0.92);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.24);
}

.initials-panel.is-visible {
  display: block;
}

.initials-panel label {
  display: block;
  margin: 0 0 6px;
  color: #fff4d8;
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.initials-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.initials-row input {
  min-width: 0;
  height: 40px;
  border: 1px solid rgba(255, 250, 240, 0.28);
  border-radius: 8px;
  padding: 0 12px;
  color: #19323c;
  background: #fffaf0;
  font: 900 1.2rem Avenir, "Avenir Next", system-ui, sans-serif;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.initials-row button {
  min-height: 40px;
  background: var(--accent);
  color: #2b170d;
}

.lootbox-panel {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: none;
  place-items: center;
  padding: 18px;
  background:
    radial-gradient(circle at 50% 12%, rgba(255, 209, 102, 0.3), transparent 18rem),
    rgba(8, 14, 28, 0.72);
}

.lootbox-panel.is-visible {
  display: grid;
}

.lootbox-card {
  width: min(720px, 100%);
  padding: clamp(16px, 2.6vw, 24px);
  border: 1px solid rgba(255, 209, 102, 0.48);
  border-radius: 8px;
  color: #fffaf0;
  background: rgba(8, 14, 28, 0.94);
  box-shadow: 0 24px 58px rgba(0, 0, 0, 0.34);
}

.lootbox-kicker {
  margin: 0 0 6px;
  color: #ffd166;
  font-size: 0.74rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.lootbox-card h2 {
  margin: 0 0 14px;
  font-size: clamp(1.5rem, 3.7vw, 2.2rem);
  line-height: 1;
  letter-spacing: 0;
}

.lootbox-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.lootbox-option {
  min-height: 128px;
  display: grid;
  align-content: start;
  justify-items: start;
  gap: 8px;
  padding: 14px;
  border: 1px solid rgba(255, 250, 240, 0.16);
  border-radius: 8px;
  color: #fffaf0;
  background:
    linear-gradient(145deg, rgba(255, 107, 53, 0.28), rgba(95, 200, 166, 0.18)),
    rgba(25, 50, 60, 0.82);
  text-align: left;
}

.lootbox-option:hover {
  background:
    linear-gradient(145deg, rgba(255, 209, 102, 0.32), rgba(95, 200, 166, 0.26)),
    rgba(37, 73, 87, 0.92);
}

.lootbox-option strong {
  font-size: 1rem;
  line-height: 1.08;
}

.lootbox-option span {
  color: #d8ecf4;
  font-size: 0.82rem;
  font-weight: 700;
  line-height: 1.25;
}

.lootbox-toast {
  position: absolute;
  left: 50%;
  top: 18px;
  z-index: 6;
  width: min(520px, calc(100% - 28px));
  padding: 12px 16px;
  border: 1px solid rgba(255, 209, 102, 0.54);
  border-radius: 8px;
  color: #fffaf0;
  background: rgba(8, 14, 28, 0.94);
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.34);
  font-size: clamp(0.88rem, 2.2vw, 1rem);
  font-weight: 800;
  line-height: 1.25;
  text-align: center;
  transform: translate(-50%, -12px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

.lootbox-toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.control-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.control-strip span {
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  border: 1px solid rgba(25, 50, 60, 0.11);
  border-radius: 999px;
  padding: 0 12px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.52);
  font-size: 0.88rem;
  font-weight: 700;
}

.beetle-hunt {
  position: fixed;
  inset: 0;
  z-index: 7;
  pointer-events: none;
}

.gold-meter {
  position: fixed;
  left: 18px;
  bottom: 18px;
  z-index: 8;
  min-width: 112px;
  display: grid;
  align-content: center;
  justify-items: start;
  gap: 2px;
  border: 1px solid rgba(25, 50, 60, 0.12);
  border-radius: 8px;
  padding: 10px 12px;
  background: rgba(255, 250, 240, 0.88);
  box-shadow: 0 12px 30px rgba(75, 54, 32, 0.14);
  pointer-events: auto;
}

.gold-meter span {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.gold-meter strong {
  color: #a05b14;
  font-size: 1.65rem;
  line-height: 1;
}

.gold-shop {
  position: fixed;
  left: 148px;
  bottom: 18px;
  z-index: 8;
  width: 190px;
  display: none;
  gap: 8px;
  border: 1px solid rgba(25, 50, 60, 0.14);
  border-radius: 8px;
  padding: 12px;
  color: var(--ink);
  background: rgba(255, 250, 240, 0.92);
  box-shadow: 0 14px 34px rgba(75, 54, 32, 0.18);
  pointer-events: auto;
}

.gold-shop.is-visible {
  display: grid;
}

.shop-kicker {
  margin: 0;
  color: var(--accent-dark);
  font-size: 0.68rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.gold-shop h2 {
  margin: 0 0 2px;
  font-size: 1.05rem;
  line-height: 1;
}

.gold-shop button {
  min-height: 32px;
  justify-self: stretch;
  padding: 0 10px;
  color: #2b170d;
  background: #ffd166;
  font-size: 0.78rem;
  text-align: left;
}

.gold-shop button:hover {
  background: #ffe08a;
}

.gold-shop button:disabled {
  color: rgba(43, 23, 13, 0.54);
  background: rgba(255, 209, 102, 0.44);
  cursor: not-allowed;
}

.gold-shop button.is-equipped {
  color: #ecfeff;
  background: #19323c;
}

.gold-shop button.is-equipped:hover {
  background: #24495a;
}

.beetle-field {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

.bonus-beetle {
  position: fixed;
  width: 38px;
  height: 30px;
  min-height: 0;
  display: grid;
  place-items: center;
  border: 1px solid rgba(25, 50, 60, 0.14);
  border-radius: 999px;
  padding: 2px;
  background: rgba(255, 250, 240, 0.82);
  box-shadow: 0 8px 18px rgba(75, 54, 32, 0.16);
  transform: translate(-50%, -50%) scale(0.92);
  opacity: 0;
  animation: beetle-pop 180ms ease forwards;
  pointer-events: auto;
}

.bonus-beetle:hover {
  background: #fff4d8;
  transform: translate(-50%, -50%) scale(1.05);
}

.bonus-beetle img {
  width: 30px;
  height: 22px;
  display: block;
  pointer-events: none;
}

@media (max-width: 900px) {
  .gold-meter {
    top: auto;
    bottom: calc(112px + env(safe-area-inset-bottom));
    left: max(10px, env(safe-area-inset-left));
    min-width: 82px;
    padding: 8px 10px;
  }

  .gold-meter strong {
    font-size: 1.35rem;
  }

  .gold-shop {
    top: auto;
    bottom: calc(112px + env(safe-area-inset-bottom));
    left: calc(max(10px, env(safe-area-inset-left)) + 94px);
    width: min(176px, calc(100vw - 116px));
  }
}

@keyframes beetle-pop {
  to {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
}

@media (max-width: 680px) {
  html,
  body {
    height: 100%;
    overflow: hidden;
  }

  body {
    min-height: 100svh;
    min-height: 100dvh;
  }

  .shell {
    width: 100vw;
    min-height: 100svh;
    min-height: 100dvh;
    padding: 0;
    place-items: stretch;
  }

  .game-card {
    min-height: 100svh;
    min-height: 100dvh;
    border: 0;
    border-radius: 0;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto auto;
    padding:
      max(10px, env(safe-area-inset-top))
      max(10px, env(safe-area-inset-right))
      max(10px, env(safe-area-inset-bottom))
      max(10px, env(safe-area-inset-left));
    box-shadow: none;
  }

  .topbar {
    align-items: center;
    margin-bottom: 8px;
  }

  .eyebrow {
    margin-bottom: 2px;
    font-size: 0.64rem;
  }

  h1 {
    font-size: clamp(1.9rem, 10vw, 2.9rem);
  }

  .canvas-wrap {
    width: 100%;
    max-height: 100%;
    align-self: start;
    aspect-ratio: 16 / 9;
  }

  button {
    min-height: 38px;
    padding: 0 10px;
  }

  .onboarding-panel {
    padding: 8px;
  }

  .onboarding-card {
    width: min(320px, 100%);
    max-height: calc(100% - 16px);
    overflow: auto;
    padding: 12px;
  }

  .onboarding-kicker {
    margin-bottom: 4px;
    font-size: 0.62rem;
  }

  .onboarding-card h2 {
    margin-bottom: 8px;
    font-size: 1.45rem;
    line-height: 1.02;
  }

  .onboarding-card ul {
    gap: 5px;
    margin-bottom: 10px;
    padding-left: 16px;
    font-size: 0.78rem;
    line-height: 1.18;
  }

  .onboarding-card button {
    min-height: 34px;
    font-size: 0.88rem;
  }

  .control-strip {
    justify-content: center;
    gap: 6px;
    margin-top: 8px;
  }

  .control-strip span {
    min-height: 26px;
    padding: 0 9px;
    font-size: 0.76rem;
  }

  .lootbox-panel {
    padding: 10px;
  }

  .lootbox-options {
    grid-template-columns: 1fr;
  }

  .lootbox-option {
    min-height: 74px;
    padding: 10px 12px;
  }

  .lootbox-toast {
    top: 10px;
    padding: 10px 12px;
  }
}

@media (max-width: 680px) and (max-height: 620px) {
  .eyebrow,
  .control-strip,
  .beetle-hunt {
    display: none;
  }

  .topbar {
    margin-bottom: 6px;
  }
}
