:root {
  --green-900: #315f11;
  --green-700: #4d8018;
  --green-500: #7eaa2e;
  --lime: #b7d955;
  --cream: #fff9ed;
  --ink: #17210e;
  --orange: #ef7d22;
  --shadow: 0 22px 80px rgba(21, 38, 6, 0.3);
}

* {
  box-sizing: border-box;
}

html {
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  width: 100vw;
  height: 100%;
  min-height: 100dvh;
  overflow: hidden;
  color: var(--cream);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    linear-gradient(90deg, rgba(49, 95, 17, 0.84), rgba(126, 170, 46, 0.78)),
    url("./assets/bg.png") center / cover no-repeat fixed;
  display: grid;
  place-items: center;
}

button {
  font: inherit;
}

.game-shell {
  width: min(100vw, 430px);
  height: 100dvh;
  max-height: 932px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top, 0px) + 8px) 10px calc(env(safe-area-inset-bottom, 0px) + 10px);
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 8px;
  overflow: hidden;
}

.topbar {
  display: grid;
  gap: 8px;
  margin-bottom: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 2px solid rgba(255, 255, 255, 0.44);
  border-radius: 50%;
  color: #f9ffd7;
  font-weight: 900;
  letter-spacing: 0;
  background: rgba(255, 255, 255, 0.16);
  box-shadow: inset 0 0 24px rgba(255, 255, 255, 0.16);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 25px;
  line-height: 0.98;
}

.brand p {
  max-width: 430px;
  margin-top: 2px;
  color: rgba(255, 255, 255, 0.82);
  font-size: 12px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(92px, 1fr));
  gap: 6px;
}

.stat {
  min-width: 0;
  padding: 8px 9px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  background: rgba(24, 54, 8, 0.5);
  backdrop-filter: blur(10px);
}

.stat span {
  display: block;
  color: rgba(255, 255, 255, 0.72);
  font-size: 12px;
}

.stat strong {
  display: block;
  margin-top: 2px;
  color: #fff;
  font-size: 22px;
}

.play-area {
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  align-items: end;
  gap: 8px;
  overflow: hidden;
}

.board-wrap {
  width: min(100%, calc(100dvh - 354px));
  max-width: 410px;
  min-width: 0;
  aspect-ratio: 1;
  padding: 6px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.22), rgba(31, 67, 8, 0.48)),
    rgba(245, 255, 219, 0.12);
  box-shadow: var(--shadow);
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 6px;
  cursor: pointer;
  touch-action: none;
  background: rgba(247, 255, 229, 0.76);
}

.panel {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  min-height: 0;
}

.panel-block {
  padding: 9px 10px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  background: rgba(25, 48, 10, 0.62);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.panel h2 {
  margin-bottom: 5px;
  font-size: 14px;
}

.panel p,
.panel li {
  color: rgba(255, 255, 255, 0.82);
  line-height: 1.25;
  font-size: 11px;
}

.panel ul {
  margin: 0;
  padding-left: 18px;
}

.status-block {
  border-color: rgba(255, 211, 109, 0.42);
}

.combo-panel {
  display: none;
}

.coupon-panel,
.panel > .primary-button {
  grid-column: 1 / -1;
}

.coupon-panel {
  min-height: 122px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px 8px;
}

.coupon-panel h2,
.coupon-panel p {
  grid-column: 1 / -1;
}

.meter {
  height: 10px;
  margin-bottom: 6px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.22);
}

.meter span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #ffd36d, #ef7d22);
  transition: width 220ms ease;
}

.primary-button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  color: var(--ink);
  font-weight: 800;
  background: linear-gradient(180deg, #fff2a1, #ffc655 58%, #ef7d22);
  box-shadow: 0 12px 28px rgba(34, 28, 4, 0.22);
  cursor: pointer;
}

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

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(13, 28, 4, 0.72);
}

.modal[hidden] {
  display: none;
}

.modal-card {
  width: min(420px, 100%);
  padding: 24px;
  border-radius: 8px;
  color: var(--ink);
  background: var(--cream);
  box-shadow: var(--shadow);
}

.modal-card h2 {
  margin-bottom: 8px;
  color: var(--green-900);
  font-size: 28px;
}

.modal-card p {
  line-height: 1.45;
}

.eyebrow {
  margin-bottom: 6px;
  color: var(--orange);
  font-weight: 800;
  text-transform: uppercase;
  font-size: 12px;
}

.coupon {
  min-height: 42px;
  margin: 10px 0;
  padding: 9px 10px;
  border: 2px dashed var(--orange);
  border-radius: 8px;
  color: var(--green-900);
  font-weight: 900;
  text-align: center;
  background: #fff6d4;
}

.coupon-panel .coupon {
  grid-column: 1;
  margin: 0;
  display: grid;
  place-items: center;
  min-width: 0;
  font-size: clamp(14px, 4vw, 20px);
  overflow-wrap: anywhere;
}

.code-coupon {
  user-select: all;
  opacity: 0.48;
}

.code-coupon.is-ready {
  opacity: 1;
}

.secondary-button:disabled {
  cursor: not-allowed;
  filter: grayscale(0.85);
  opacity: 0.55;
}

.coupon-panel .secondary-button {
  grid-column: 2;
  min-width: 112px;
  min-height: 42px;
  padding: 0 12px;
  font-size: 13px;
}

@media (max-width: 880px) {
  /* Mobile-first layout is already the default for Telegram Mini App. */
}

@media (min-width: 900px) {
  body {
    background:
      radial-gradient(circle at 50% 20%, rgba(255, 255, 255, 0.16), transparent 34%),
      linear-gradient(90deg, rgba(49, 95, 17, 0.9), rgba(126, 170, 46, 0.84)),
      url("./assets/bg.png") center / cover no-repeat fixed;
  }

  .game-shell {
    border-left: 1px solid rgba(255, 255, 255, 0.18);
    border-right: 1px solid rgba(255, 255, 255, 0.18);
    background: rgba(31, 67, 8, 0.18);
    box-shadow: 0 26px 80px rgba(0, 0, 0, 0.28);
  }
}

@media (max-height: 760px) {
  h1 {
    font-size: 21px;
  }

  .brand-mark {
    width: 36px;
    height: 36px;
  }

  .brand p,
  .panel p,
  .panel li,
  .stat span {
    font-size: 10px;
  }

  .stat strong {
    font-size: 19px;
  }
}
