:root {
  color-scheme: light;
  --money-dark: #07543f;
  --money: #0f9b63;
  --money-light: #24c879;
  --mint: #90f0cf;
  --sky: #54d9c6;
  --sky-deep: #28b8b7;
  --ink: #3c1b10;
  --cream: #fff5d2;
  --white: #fffdfa;
  --gold: #ffd234;
  --orange: #ff9b21;
  --red: #f33242;
  --red-dark: #ad2330;
  --green: #36c86c;
  --cyan: #1ab9f0;
  --shadow: rgba(77, 31, 21, 0.32);
}

* {
  box-sizing: border-box;
}

html {
  width: 100%;
  min-height: 100%;
  overflow: hidden;
  background: var(--money-dark);
}

body {
  width: 100%;
  min-height: 100dvh;
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  background:
    radial-gradient(circle at 18% 24%, rgba(255, 210, 52, 0.24) 0 18px, transparent 19px),
    radial-gradient(circle at 78% 16%, rgba(255, 210, 52, 0.2) 0 13px, transparent 14px),
    linear-gradient(135deg, rgba(255, 255, 255, 0.09) 0 8px, transparent 8px 36px),
    linear-gradient(90deg, transparent 0 38px, rgba(255, 255, 255, 0.08) 38px 42px, transparent 42px 90px),
    linear-gradient(180deg, #0f9b63 0%, #087052 52%, #04382d 100%);
  background-size: 180px 180px, 140px 140px, 72px 72px, 90px 90px, auto;
  font-family: "Arial Rounded MT Bold", "Trebuchet MS", Arial, sans-serif;
  letter-spacing: 0;
  touch-action: manipulation;
}

button,
input {
  font: inherit;
}

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

h1,
h2,
p {
  margin-top: 0;
}

.app-shell {
  width: min(100vw, calc(100dvh / 1.5));
  height: 100dvh;
  margin: 0 auto;
  position: relative;
  overflow: hidden;
}

.game-stage {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--sky);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.16), 0 22px 48px var(--shadow);
  isolation: isolate;
}

.arena-wrap,
#gameCanvas,
.shine-layer {
  position: absolute;
  inset: 0;
}

#gameCanvas {
  width: 100%;
  height: 100%;
  display: block;
  background: var(--sky);
  touch-action: none;
}

.shine-layer {
  pointer-events: none;
  background:
    radial-gradient(circle at 18% 10%, rgba(255, 242, 132, 0.32) 0 8%, transparent 18%),
    radial-gradient(circle at 82% 28%, rgba(255, 242, 132, 0.22) 0 7%, transparent 17%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.16), transparent 32%, rgba(33, 86, 50, 0.18));
  mix-blend-mode: soft-light;
}

.hud {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  left: 14px;
  right: 14px;
  z-index: 5;
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  opacity: 0;
  transform: translateY(-20px);
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}

.app-shell[data-state="playing"] .hud,
.app-shell[data-state="ended"] .hud {
  opacity: 1;
  transform: translateY(0);
}

.brand-bar {
  display: none;
}

.hud-meters {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.meter {
  min-width: 0;
  min-height: 54px;
  padding: 7px 9px 8px;
  border: 3px solid rgba(255, 255, 255, 0.92);
  border-radius: 18px;
  color: var(--white);
  background: rgba(46, 85, 134, 0.58);
  box-shadow: 0 6px 0 rgba(45, 43, 78, 0.22), inset 0 -7px 0 rgba(0, 0, 0, 0.08);
  backdrop-filter: blur(8px);
}

.meter span {
  display: block;
  color: rgba(255, 255, 255, 0.8);
  font-size: clamp(0.58rem, 2.4vw, 0.72rem);
  font-weight: 900;
  text-transform: uppercase;
}

.meter strong {
  display: block;
  max-width: 100%;
  overflow: hidden;
  color: var(--gold);
  font-size: clamp(1rem, 4.8vw, 1.42rem);
  line-height: 1.05;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-shadow: 0 2px 0 #853517, 0 4px 0 rgba(0, 0, 0, 0.16);
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
}

.overlay[hidden] {
  display: none;
}

.overlay-start {
  display: grid;
  grid-template-rows: 1fr auto;
  padding: max(18px, env(safe-area-inset-top)) 18px max(176px, calc(env(safe-area-inset-bottom) + 176px));
  pointer-events: auto;
}

.landing-hero {
  align-self: start;
  padding-top: clamp(52px, 12dvh, 118px);
  position: relative;
  text-align: center;
}

.coin-burst {
  position: absolute;
  top: clamp(0px, 2dvh, 18px);
  left: 50%;
  width: min(300px, 82%);
  height: 132px;
  transform: translateX(-50%);
  pointer-events: none;
}

.coin-burst span {
  position: absolute;
  width: 34px;
  height: 34px;
  border: 4px solid #9d4c18;
  border-radius: 50%;
  background: radial-gradient(circle at 34% 28%, #fff58b 0 14%, var(--gold) 15% 63%, #e28a16 64% 100%);
  box-shadow: 0 5px 0 #8e351c, 0 10px 16px rgba(76, 44, 13, 0.2);
}

.coin-burst span::after {
  content: "";
  position: absolute;
  inset: 8px 13px;
  border-radius: 999px;
  background: rgba(255, 251, 176, 0.72);
}

.coin-burst span:nth-child(1) {
  left: 6%;
  top: 48px;
  transform: rotate(-18deg);
}

.coin-burst span:nth-child(2) {
  left: 21%;
  top: 0;
  transform: scale(0.75) rotate(14deg);
}

.coin-burst span:nth-child(3) {
  right: 20%;
  top: 8px;
  transform: scale(0.82) rotate(-20deg);
}

.coin-burst span:nth-child(4) {
  right: 2%;
  top: 56px;
  transform: rotate(20deg);
}

.coin-burst span:nth-child(5) {
  left: 47%;
  top: 16px;
  transform: scale(0.62) rotate(8deg);
}

.hero-coin {
  width: clamp(62px, 17vw, 100px);
  height: clamp(62px, 17vw, 100px);
  margin: 0 auto 8px;
  position: relative;
  z-index: 1;
  border: 6px solid #9c4a18;
  border-radius: 50%;
  background: radial-gradient(circle at 34% 26%, #fff58d 0 16%, #ffd234 17% 64%, #df8616 65% 100%);
  box-shadow: 0 8px 0 #7f341b, 0 14px 24px rgba(72, 42, 14, 0.28);
}

.hero-coin::before,
.hero-coin::after {
  content: "";
  position: absolute;
  top: 49%;
  width: 24%;
  height: 8px;
  border-radius: 999px;
  background: #7b341b;
}

.hero-coin::before {
  left: -22%;
  transform: rotate(24deg);
}

.hero-coin::after {
  right: -22%;
  transform: rotate(-24deg);
}

.hero-coin i {
  position: absolute;
  top: 34%;
  width: 11%;
  height: 14%;
  border-radius: 50%;
  background: #4d2616;
}

.hero-coin i:first-child {
  left: 33%;
}

.hero-coin i:nth-child(2) {
  right: 33%;
}

.hero-coin b {
  position: absolute;
  left: 33%;
  bottom: 28%;
  width: 34%;
  height: 20%;
  border-bottom: 5px solid #4d2616;
  border-radius: 0 0 999px 999px;
}

.landing-hero h1 {
  margin: 0 auto 8px;
  display: grid;
  color: #ffdf34;
  font-size: clamp(3.25rem, 15.5vw, 6.2rem);
  font-weight: 1000;
  line-height: 0.76;
  letter-spacing: 0;
  text-transform: uppercase;
  text-shadow:
    0 5px 0 #fff3a0,
    0 9px 0 #f08a14,
    4px 12px 0 #8e351c,
    -4px 12px 0 #8e351c,
    0 18px 18px rgba(36, 78, 27, 0.32);
  transform: rotate(-1.5deg);
}

.landing-hero p {
  width: min(300px, 88%);
  margin: 0 auto;
  color: #fff9d7;
  font-size: clamp(0.92rem, 3.4vw, 1.1rem);
  font-weight: 900;
  line-height: 1.25;
  text-shadow: 0 2px 0 rgba(96, 39, 18, 0.32);
}

.landing-controls {
  width: min(350px, 100%);
  margin: 0 auto;
  display: grid;
  gap: 10px;
  position: relative;
}

.name-label {
  margin: 0;
  color: #fff7cf;
  font-size: 0.78rem;
  font-weight: 1000;
  text-align: left;
  text-transform: uppercase;
  text-shadow: 0 2px 0 rgba(91, 42, 22, 0.3);
}

input {
  width: 100%;
  min-width: 0;
  height: 48px;
  padding: 0 16px;
  border: 3px solid rgba(255, 255, 255, 0.95);
  border-radius: 18px;
  color: #5b2a16;
  background: rgba(255, 250, 220, 0.94);
  outline: none;
  box-shadow: 0 6px 0 rgba(80, 51, 33, 0.18), inset 0 -5px 0 rgba(255, 180, 66, 0.22);
  font-weight: 900;
}

input:focus {
  border-color: #ffe65f;
  box-shadow: 0 6px 0 rgba(80, 51, 33, 0.18), 0 0 0 4px rgba(255, 230, 95, 0.34);
}

.big-start {
  width: 100%;
  min-width: 0;
  min-height: 72px;
  padding: 8px 24px 10px;
  border: 5px solid #fff4e4;
  border-radius: 22px;
  display: inline-grid;
  grid-template-columns: 58px 1fr;
  align-items: center;
  gap: 10px;
  color: var(--white);
  background: linear-gradient(180deg, #ffe778 0%, #ffd234 48%, #f0a71e 100%);
  box-shadow:
    0 8px 0 #9a5516,
    0 13px 0 rgba(255, 249, 226, 0.85),
    0 22px 18px rgba(34, 82, 36, 0.34),
    inset 0 5px 0 rgba(255, 255, 255, 0.28);
  font-size: clamp(2rem, 8vw, 3.1rem);
  font-weight: 1000;
  line-height: 1;
  text-transform: uppercase;
  text-shadow: 0 4px 0 #9a5516;
  transition: transform 120ms ease, box-shadow 120ms ease;
}

.big-start > span:last-child {
  min-width: 0;
  overflow: hidden;
  text-align: center;
  text-overflow: ellipsis;
}

.big-start:hover {
  transform: translateY(-2px);
}

.big-start:active {
  transform: translateY(5px);
  box-shadow:
    0 3px 0 #9a5516,
    0 8px 0 rgba(255, 249, 226, 0.85),
    0 14px 12px rgba(34, 82, 36, 0.26),
    inset 0 5px 0 rgba(255, 255, 255, 0.22);
}

.big-start:disabled {
  opacity: 0.7;
  transform: none;
}

.big-start.compact {
  width: 100%;
  min-height: 58px;
  grid-template-columns: 44px 1fr;
  font-size: clamp(1.4rem, 5.6vw, 2rem);
}

.play-arrow {
  width: 58px;
  height: 52px;
  border-radius: 18px;
  background: linear-gradient(135deg, #27e48f 0%, #08a866 100%);
  box-shadow: inset 0 4px 0 rgba(255, 255, 255, 0.35), 0 5px 0 #087046;
  position: relative;
}

.play-arrow::after {
  content: "";
  position: absolute;
  left: 21px;
  top: 12px;
  border-top: 14px solid transparent;
  border-bottom: 14px solid transparent;
  border-left: 20px solid #e8fbff;
  filter: drop-shadow(0 2px 0 rgba(37, 88, 96, 0.4));
}

.compact .play-arrow {
  width: 44px;
  height: 40px;
  border-radius: 14px;
}

.compact .play-arrow::after {
  left: 17px;
  top: 10px;
  border-top-width: 10px;
  border-bottom-width: 10px;
  border-left-width: 15px;
}

.modal-panel {
  width: min(352px, calc(100% - 34px));
  margin: max(110px, 16dvh) auto 0;
  padding: 18px;
  border: 5px solid #fff4e4;
  border-radius: 26px;
  color: #fff7cf;
  background: rgba(18, 129, 88, 0.86);
  box-shadow: 0 12px 0 rgba(33, 82, 44, 0.26), 0 24px 28px rgba(24, 59, 31, 0.32);
  text-align: center;
  backdrop-filter: blur(9px);
  pointer-events: auto;
}

.eyebrow {
  margin: 0 0 5px;
  color: #ffe86c;
  font-size: 0.74rem;
  font-weight: 1000;
  letter-spacing: 0;
  text-transform: uppercase;
}

.result-panel h2 {
  margin: 2px 0 8px;
  color: var(--gold);
  font-size: clamp(3rem, 15vw, 5.4rem);
  line-height: 0.9;
  text-shadow: 0 5px 0 #a4401b, 0 11px 16px rgba(0, 0, 0, 0.18);
}

.rank-line {
  min-height: 24px;
  margin: 0 0 14px;
  color: #fff9d7;
  font-size: 1rem;
  font-weight: 900;
}

.scoreboard {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: max(12px, env(safe-area-inset-bottom));
  z-index: 6;
  height: clamp(130px, 18dvh, 164px);
  padding: 12px;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 8px;
  overflow: hidden;
  border: 4px solid #fff4e4;
  border-radius: 24px;
  color: #60301a;
  background: rgba(255, 247, 215, 0.95);
  box-shadow: 0 8px 0 rgba(119, 60, 32, 0.24), 0 18px 28px rgba(68, 34, 20, 0.24);
  transition: opacity 180ms ease, transform 180ms ease;
}

.app-shell[data-state="playing"] .scoreboard,
.app-shell[data-state="loading"] .scoreboard {
  opacity: 0;
  transform: translateY(120%);
  pointer-events: none;
}

.scoreboard-head {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
}

.scoreboard h2 {
  margin: 0;
  color: #5a2815;
  font-size: clamp(1.08rem, 4.6vw, 1.35rem);
  line-height: 1;
  text-transform: uppercase;
}

.period-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(36px, 1fr));
  gap: 5px;
}

.period-tabs button {
  min-width: 0;
  height: 34px;
  padding: 0 8px;
  border: 0;
  border-radius: 999px;
  color: #72351d;
  background: #ffd98a;
  box-shadow: inset 0 -4px 0 rgba(160, 81, 27, 0.16);
  font-size: 0.78rem;
  font-weight: 1000;
  text-transform: uppercase;
}

.period-tabs button.is-active {
  color: #fff;
  background: var(--green);
  box-shadow: inset 0 -4px 0 rgba(0, 92, 44, 0.2);
}

.leaderboard {
  min-height: 0;
  margin: 0;
  padding: 0;
  display: grid;
  align-content: start;
  gap: 6px;
  list-style: none;
  overflow: hidden;
}

.leaderboard li {
  min-height: 34px;
  padding: 5px 9px;
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr) auto;
  gap: 7px;
  align-items: center;
  border-radius: 14px;
  background: rgba(255, 218, 138, 0.6);
  font-size: 0.9rem;
  font-weight: 900;
}

.leaderboard li:nth-child(n+3) {
  display: none;
}

.leaderboard li.is-loading,
.leaderboard li.is-empty {
  grid-template-columns: 1fr;
  color: #815133;
}

.rank {
  color: var(--red);
}

.player {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player small {
  display: none;
}

.points {
  color: #974119;
  white-space: nowrap;
}

.error-page {
  display: grid;
  place-items: center;
  background: var(--money-dark);
}

.error-box {
  width: min(390px, calc(100vw - 24px));
  padding: 18px;
  border: 5px solid #fff4e4;
  border-radius: 24px;
  color: #fff9d7;
  background: rgba(36, 75, 124, 0.84);
  box-shadow: 0 12px 0 rgba(53, 44, 65, 0.26), 0 22px 26px rgba(50, 26, 18, 0.26);
  text-align: center;
}

.error-box h1 {
  color: #ffe86c;
}

@media (max-height: 720px) {
  .overlay-start {
    padding-bottom: max(142px, calc(env(safe-area-inset-bottom) + 142px));
  }

  .landing-hero {
    padding-top: clamp(42px, 9dvh, 74px);
  }

  .landing-hero h1 {
    font-size: clamp(3rem, 15vw, 5.3rem);
  }

  .scoreboard {
    height: 124px;
    padding: 10px;
  }

  .leaderboard li {
    min-height: 30px;
  }
}

@media (max-width: 360px) {
  .hud {
    left: 10px;
    right: 10px;
  }

  .hud-meters {
    gap: 5px;
  }

  .meter {
    min-height: 48px;
    padding: 6px;
    border-radius: 15px;
  }

  .overlay-start {
    padding-left: 12px;
    padding-right: 12px;
  }

  .scoreboard {
    left: 10px;
    right: 10px;
  }
}

@media (max-width: 430px) {
  .landing-controls {
    width: min(330px, 100%);
  }

  .big-start {
    min-height: 68px;
    padding: 8px 16px 10px;
    grid-template-columns: 52px minmax(0, 1fr);
    font-size: clamp(1.7rem, 7.2vw, 2.15rem);
  }

  .play-arrow {
    width: 52px;
    height: 46px;
    border-radius: 16px;
  }

  .play-arrow::after {
    left: 19px;
    top: 11px;
    border-top-width: 12px;
    border-bottom-width: 12px;
    border-left-width: 18px;
  }

  .scoreboard-head {
    gap: 6px;
  }

  .period-tabs button {
    height: 28px;
    font-size: 0.7rem;
  }
}
