:root {
  --ink: #10201d;
  --muted: #6a756d;
  --paper: #fbfbf6;
  --line: rgba(16, 32, 29, 0.16);
  --green: #1d7454;
  --green-dark: #11352f;
  --yellow: #f1be47;
  --coral: #cf614a;
  --blue: #3c78a8;
  --shadow: 0 16px 42px rgba(15, 34, 31, 0.2);
}

* {
  box-sizing: border-box;
}

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

body {
  min-height: 100svh;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #d9e7df;
  touch-action: none;
  user-select: none;
}

button {
  min-height: 46px;
  border: 1px solid #0c2c28;
  border-radius: 8px;
  padding: 0 22px;
  color: #ffffff;
  background: var(--green-dark);
  box-shadow: 0 8px 18px rgba(17, 53, 47, 0.2);
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--ink);
  background: #ffffff;
  font: inherit;
}

button:active {
  transform: translateY(1px);
}

button:focus-visible {
  outline: 3px solid rgba(241, 190, 71, 0.55);
  outline-offset: 3px;
}

.game-shell {
  width: min(100vw, 480px);
  min-height: 100svh;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 10px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.64), rgba(255, 255, 255, 0.12) 42%, rgba(13, 49, 43, 0.08)),
    #d9e7df;
}

.hud,
.bottom-panel {
  display: grid;
  gap: 8px;
}

.hud {
  grid-template-columns: minmax(0, 1.25fr) repeat(3, minmax(58px, 0.55fr));
}

.bottom-panel {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.brand,
.stat,
.bottom-panel > div {
  min-height: 58px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  display: grid;
  align-content: center;
  gap: 2px;
  background: rgba(251, 251, 246, 0.76);
}

.brand span,
.stat span,
.bottom-panel span,
.result-grid span {
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 850;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.brand span {
  color: var(--green);
  text-transform: none;
}

.brand strong,
.stat strong,
.bottom-panel strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 1.05rem;
  line-height: 1.05;
}

.brand strong {
  color: var(--ink);
}

.stat.score-pulse {
  animation: scorePulse 320ms ease-out;
}

.stat.gain strong {
  color: var(--green);
}

.stat.loss strong {
  color: var(--coral);
}

@keyframes scorePulse {
  0% {
    transform: scale(1);
  }

  42% {
    transform: scale(1.05);
    border-color: rgba(241, 190, 71, 0.78);
    background: rgba(255, 255, 255, 0.94);
  }

  100% {
    transform: scale(1);
  }
}

.arena-wrap {
  position: relative;
  min-height: 0;
  overflow: hidden;
  border: 1px solid rgba(16, 32, 29, 0.2);
  border-radius: 8px;
  background:
    linear-gradient(180deg, #a6d7dc 0%, #e1eadf 54%, #c6d4bc 100%);
  box-shadow: var(--shadow);
  touch-action: none;
}

.game-bg-layer {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  pointer-events: none;
  z-index: 0;
  opacity: 0;
}

#gameCanvas {
  position: relative;
  z-index: 1;
  background: transparent;
  display: block;
  width: 100%;
  height: 100%;
  min-height: 420px;
  touch-action: none;
}

.overlay {
  position: absolute;
  inset: 0;
  padding: 18px;
  display: grid;
  place-items: center;
  background: rgba(13, 27, 24, 0.18);
  z-index: 10;
}

.overlay.hidden {
  display: none;
}

.dialog {
  width: min(100%, 320px);
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 8px;
  padding: 22px;
  display: grid;
  justify-items: center;
  gap: 15px;
  text-align: center;
  background: rgba(251, 251, 246, 0.94);
  box-shadow: 0 18px 38px rgba(18, 36, 32, 0.24);
}

.start-dialog {
  width: min(100%, 360px);
  gap: 14px;
  justify-items: stretch;
  text-align: left;
}

.kicker,
h1,
h2,
h3 {
  margin: 0;
}

.kicker {
  color: var(--green);
  font-size: 0.75rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2 {
  max-width: 100%;
  color: var(--green-dark);
  font-size: 2rem;
  line-height: 1;
  letter-spacing: 0;
}

.start-dialog h2 {
  color: var(--green);
  font-size: 1.25rem;
  text-align: center;
}

.how-to {
  width: 100%;
  display: grid;
  gap: 10px;
  justify-items: stretch;
  text-align: left;
}

.item-list {
  margin: 0;
  padding-left: 1.05rem;
}

.how-to ul {
  width: 100%;
  margin: 0;
  padding: 0;
  text-align: left;
  list-style: none;
}

.how-to li {
  width: 100%;
  margin: 0 0 7px;
  padding: 0;
  display: grid;
  grid-template-columns: 0.8rem minmax(0, 1fr);
  column-gap: 0.45rem;
  color: var(--ink);
  font-size: 0.74rem;
  line-height: 1.24;
  text-align: left;
}

.how-to li::before {
  content: "•";
  color: var(--ink);
  font-weight: 900;
  text-align: left;
}

.how-to li strong {
  font-weight: 900;
}

.how-to li span {
  min-width: 0;
  display: block;
  text-align: left;
}

.how-to p {
  margin: 0;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  line-height: 1.3;
  text-align: left;
}

.start-actions {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.secondary-button {
  color: var(--green-dark);
  background: #ffffff;
  border-color: var(--line);
  box-shadow: none;
}

.details-dialog {
  width: min(100%, 360px);
  max-height: min(92%, 620px);
  overflow: auto;
  align-content: start;
  text-align: left;
  touch-action: pan-y;
}

.details-dialog h2 {
  width: 100%;
  color: var(--green);
  font-size: 1.6rem;
  text-align: center;
}

.item-columns {
  width: 100%;
  display: grid;
  gap: 12px;
}

.item-columns h3 {
  margin-bottom: 6px;
  color: var(--green-dark);
  font-size: 0.84rem;
  font-weight: 900;
  text-transform: uppercase;
}

.item-list li {
  margin-bottom: 4px;
  font-size: 0.8rem;
  font-weight: 750;
  line-height: 1.25;
}

.leaderboard-title {
  width: 100%;
  color: var(--green-dark);
  font-size: 0.85rem;
  font-weight: 900;
  line-height: 1;
  letter-spacing: 0.02em;
  text-align: left;
  text-transform: uppercase;
}

.result-grid {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.result-grid > div {
  min-height: 70px;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  align-content: center;
  gap: 4px;
  background: #ffffff;
}

.result-grid strong {
  font-size: 1.65rem;
}

.leaderboard-form {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.leaderboard-form button {
  padding: 0 12px;
}

.leaderboard-list {
  width: 100%;
  max-height: 122px;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
  overflow: auto;
  list-style: none;
  text-align: left;
}

.leaderboard-list li {
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 9px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  background: #ffffff;
  font-size: 0.82rem;
  font-weight: 800;
}

.leaderboard-list span,
.leaderboard-list strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (min-width: 720px) {
  body {
    display: grid;
    place-items: center;
    background:
      linear-gradient(90deg, rgba(17, 53, 47, 0.18), rgba(60, 120, 168, 0.12)),
      #d9e7df;
  }

  .game-shell {
    min-height: min(900px, calc(100vh - 28px));
    border: 1px solid rgba(16, 32, 29, 0.18);
    border-radius: 8px;
    box-shadow: 0 22px 80px rgba(17, 53, 47, 0.22);
  }
}

@media (max-width: 360px) {
  .game-shell {
    padding-left: 8px;
    padding-right: 8px;
  }

  .brand,
  .stat,
  .bottom-panel > div {
    padding-left: 7px;
    padding-right: 7px;
  }

  .brand strong,
  .stat strong,
  .bottom-panel strong {
    font-size: 0.95rem;
  }
}
