:root {
  --bg: #12192b;
  --panel: #202b48;
  --panel-2: #2c3b61;
  --gold: #ffc83d;
  --gold-deep: #d88314;
  --green: #1fc676;
  --red: #e4483f;
  --white: #fff7df;
  --ink: #1b1520;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 18% 12%, rgba(255, 200, 61, 0.22), transparent 24rem),
    radial-gradient(circle at 82% 20%, rgba(228, 72, 63, 0.18), transparent 22rem),
    linear-gradient(145deg, #0c1324, #24182e 52%, #111827);
  color: var(--white);
  font-family: Arial, Helvetica, sans-serif;
}

button {
  font: inherit;
}

.app-shell {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 16px;
}

.phone-frame {
  position: relative;
  width: min(430px, 100%);
  min-height: 760px;
  padding: 16px;
  overflow: hidden;
  border: 5px solid #3c2a17;
  border-radius: 22px;
  background:
    linear-gradient(rgba(22, 22, 35, 0.32), rgba(22, 22, 35, 0.18)),
    radial-gradient(circle at top, #3b2b4d, #12192b 64%);
  box-shadow: var(--shadow);
}

.phone-frame::before {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(90deg, transparent 0 92%, rgba(255, 255, 255, 0.04) 92% 100%),
    linear-gradient(0deg, transparent 0 92%, rgba(255, 255, 255, 0.03) 92% 100%);
  background-size: 56px 56px;
  content: "";
}

.top-bar,
.matchup,
.status-row,
.boosters,
.message-panel,
.log-panel {
  position: relative;
  z-index: 1;
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--gold);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  font-weight: 900;
  letter-spacing: 0;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.28);
}

h1 {
  font-size: 30px;
}

.icon-button {
  width: 52px;
  height: 52px;
  border: 0;
  border-radius: 8px;
  background: linear-gradient(#ffe26a, #f4a51e);
  color: #442300;
  cursor: pointer;
  font-size: 28px;
  font-weight: 900;
  box-shadow: 0 5px 0 #a85b0e;
}

.matchup {
  display: grid;
  align-items: center;
  grid-template-columns: 1fr 54px 1fr;
  gap: 8px;
  margin-bottom: 10px;
}

.player-card {
  display: flex;
  align-items: center;
  min-width: 0;
  min-height: 78px;
  gap: 8px;
  padding: 8px;
  border: 3px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: linear-gradient(180deg, #344778, #233153);
}

.player-card.rival {
  background: linear-gradient(180deg, #6a3028, #3b2638);
}

.avatar {
  width: 52px;
  height: 52px;
  flex: 0 0 52px;
  border: 3px solid var(--gold);
  border-radius: 8px;
  object-fit: cover;
  background: #14223e;
}

.avatar-player {
  display: grid;
  place-items: center;
  color: #442300;
  background: linear-gradient(#fff4a3, #ffc83d);
  font-size: 13px;
  font-weight: 900;
}

.card-label {
  display: block;
  max-width: 100%;
  overflow: hidden;
  color: rgba(255, 247, 223, 0.8);
  font-size: 12px;
  font-weight: 900;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player-card strong {
  display: block;
  margin-top: 2px;
  color: #fff;
  font-size: 22px;
  font-weight: 900;
}

.versus {
  display: grid;
  width: 54px;
  height: 54px;
  place-items: center;
  border: 4px solid #fff2a1;
  border-radius: 50%;
  background: linear-gradient(#ff4f3f, #a61419);
  color: #fff;
  font-size: 20px;
  font-weight: 900;
  text-shadow: 0 2px 0 #6b0000;
}

.status-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.status-pill {
  min-height: 64px;
  padding: 8px;
  border: 3px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: linear-gradient(#30436f, #1d2948);
  text-align: center;
}

.status-pill span {
  display: block;
  color: rgba(255, 247, 223, 0.78);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.status-pill strong {
  display: block;
  margin-top: 2px;
  color: var(--gold);
  font-size: 28px;
  font-weight: 900;
}

.status-pill.goal strong {
  color: #6cf3a9;
}

.board-wrap {
  position: relative;
  z-index: 1;
  padding: 10px;
  border: 5px solid #6e421d;
  border-radius: 10px;
  background: linear-gradient(180deg, #8e5a24, #3e2a1e);
  box-shadow: inset 0 0 0 4px rgba(255, 226, 106, 0.28), 0 12px 24px rgba(0, 0, 0, 0.25);
}

.board {
  display: grid;
  width: 100%;
  aspect-ratio: 1;
  grid-template-columns: repeat(7, 1fr);
  gap: 5px;
}

.gem {
  position: relative;
  display: grid;
  min-width: 0;
  min-height: 0;
  place-items: center;
  border: 0;
  border-radius: 9px;
  background: rgba(0, 0, 0, 0.28);
  cursor: pointer;
  transition: transform 110ms ease, filter 110ms ease;
}

.gem::before {
  display: block;
  width: 76%;
  height: 76%;
  border: 4px solid rgba(255, 255, 255, 0.7);
  box-shadow: inset -7px -9px 0 rgba(0, 0, 0, 0.16), 0 5px 0 rgba(0, 0, 0, 0.25);
  content: "";
}

.gem.ruby::before {
  border-radius: 48% 52% 42% 58%;
  background: linear-gradient(135deg, #ff6b62, #d71931);
}

.gem.sapphire::before {
  border-radius: 48% 48% 58% 58%;
  background: linear-gradient(135deg, #5ad1ff, #1267e8);
}

.gem.emerald::before {
  clip-path: polygon(50% 0, 94% 27%, 94% 73%, 50% 100%, 6% 73%, 6% 27%);
  background: linear-gradient(135deg, #59f59a, #0c9f52);
}

.gem.amber::before {
  border-radius: 8px;
  background: linear-gradient(135deg, #ffe66b, #f7941e);
}

.gem.diamond::before {
  clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
  background: linear-gradient(135deg, #fff, #b54bff 65%, #6d1fbf);
}

.gem.selected {
  transform: scale(1.08);
  filter: brightness(1.35);
}

.gem.selected::after,
.gem.hint::after {
  position: absolute;
  inset: -4px;
  border: 4px solid var(--gold);
  border-radius: 12px;
  content: "";
  animation: pulse 650ms infinite alternate;
}

.gem.removing {
  animation: popOut 260ms ease forwards;
}

.hint-bubble {
  position: absolute;
  top: 16px;
  left: 50%;
  z-index: 4;
  padding: 8px 14px;
  border: 3px solid #fff4a3;
  border-radius: 8px;
  background: #1fc676;
  color: #082217;
  font-weight: 900;
  pointer-events: none;
  transform: translateX(-50%);
  box-shadow: 0 5px 0 #0a7440;
}

.combo-banner {
  position: absolute;
  top: 44%;
  left: 50%;
  z-index: 5;
  width: max-content;
  max-width: 90%;
  padding: 14px 20px;
  border: 5px solid #fff4a3;
  border-radius: 10px;
  background: linear-gradient(#ffef66, #ff6b35);
  color: #491e00;
  font-size: 34px;
  font-weight: 900;
  transform: translate(-50%, -50%) rotate(-3deg);
  text-shadow: 0 2px 0 #fff;
  box-shadow: 0 8px 0 #9b3515;
  animation: bannerPop 700ms ease both;
}

.boosters {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.booster {
  min-height: 70px;
  padding: 6px;
  border: 3px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: linear-gradient(#334a7c, #1f2d4f);
  color: var(--white);
  cursor: pointer;
  font-size: 12px;
  font-weight: 900;
}

.booster:disabled {
  cursor: not-allowed;
  filter: grayscale(1) brightness(0.62);
}

.booster-icon,
.booster strong {
  display: block;
  font-size: 22px;
}

.booster strong {
  margin-top: 2px;
  color: var(--gold);
}

.message-panel {
  min-height: 58px;
  margin-top: 12px;
  padding: 10px 12px;
  border: 3px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.28);
}

.message-panel strong,
.message-panel span {
  display: block;
}

.message-panel strong {
  color: var(--gold);
  font-size: 18px;
  font-weight: 900;
}

.message-panel span {
  margin-top: 2px;
  color: rgba(255, 247, 223, 0.82);
  font-size: 14px;
  font-weight: 700;
}

.log-panel {
  margin-top: 10px;
}

.log-panel button {
  width: 100%;
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  background: #111827;
  color: #cbd5e1;
  cursor: pointer;
  font-size: 13px;
  font-weight: 900;
}

.log-body {
  max-height: 140px;
  margin-top: 8px;
  overflow: auto;
  padding: 8px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.5);
  color: #d6e3ff;
  font-family: Consolas, monospace;
  font-size: 11px;
}

.start-overlay {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 50% 26%, rgba(255, 232, 94, 0.28), transparent 14rem),
    rgba(9, 12, 25, 0.86);
}

.start-card {
  width: 100%;
  padding: 24px;
  border: 5px solid #fff0a5;
  border-radius: 12px;
  background: linear-gradient(160deg, #26385f, #3e2349);
  text-align: center;
  box-shadow: var(--shadow);
}

.start-card h2 {
  color: var(--gold);
  font-size: 42px;
}

.start-card p:not(.eyebrow) {
  min-height: 44px;
  margin: 12px 0 18px;
  color: rgba(255, 247, 223, 0.88);
  font-size: 16px;
  font-weight: 800;
}

.start-card p.error {
  color: #ffb5ad;
}

.play-button {
  width: 100%;
  min-height: 66px;
  border: 0;
  border-radius: 8px;
  background: linear-gradient(#ffe26a, #f4a51e);
  color: #442300;
  cursor: pointer;
  font-size: 28px;
  font-weight: 900;
  box-shadow: 0 6px 0 #a85b0e;
  text-transform: uppercase;
}

.play-button:disabled {
  cursor: not-allowed;
  filter: grayscale(1) brightness(0.7);
}

.hidden {
  display: none !important;
}

.coin-layer {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
}

.flying-coin,
.score-pop,
.spark {
  position: fixed;
  z-index: 10;
  pointer-events: none;
}

.flying-coin {
  width: 22px;
  height: 22px;
  border: 3px solid #b46b10;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 28%, #fff5a8, #ffc83d 50%, #d88314);
  animation: coinFly 900ms ease-out forwards;
}

.score-pop {
  color: #fff7df;
  font-size: 24px;
  font-weight: 900;
  text-shadow: 0 3px 0 #7b320f;
  animation: scoreFloat 800ms ease-out forwards;
}

.spark {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 18px var(--gold);
  animation: sparkBurst 580ms ease-out forwards;
}

.result-dialog {
  width: min(390px, calc(100% - 32px));
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--white);
}

.result-dialog::backdrop {
  background: rgba(0, 0, 0, 0.72);
}

.dialog-card {
  padding: 22px;
  border: 5px solid #fff0a5;
  border-radius: 12px;
  background: linear-gradient(160deg, #26385f, #3e2349);
  text-align: center;
  box-shadow: var(--shadow);
}

.dialog-card h2 {
  margin-bottom: 8px;
  color: var(--gold);
  font-size: 42px;
}

.dialog-card p {
  color: rgba(255, 247, 223, 0.86);
  font-weight: 800;
}

.reward-box {
  margin: 18px 0;
  padding: 14px;
  border: 4px solid var(--gold);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.28);
}

.reward-box span,
.reward-box strong {
  display: block;
}

.reward-box strong {
  color: #6cf3a9;
  font-size: 28px;
  font-weight: 900;
}

.dialog-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.dialog-actions button {
  min-height: 58px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 900;
}

.primary {
  background: linear-gradient(#ffe26a, #f4a51e);
  color: #442300;
  box-shadow: 0 5px 0 #a85b0e;
}

.secondary {
  background: linear-gradient(#70d8ff, #2079e8);
  color: #fff;
  box-shadow: 0 5px 0 #13529c;
}

.shake {
  animation: shake 260ms ease;
}

@keyframes pulse {
  from { opacity: 0.45; transform: scale(0.98); }
  to { opacity: 1; transform: scale(1.04); }
}

@keyframes popOut {
  to { opacity: 0; transform: scale(1.7) rotate(18deg); }
}

@keyframes bannerPop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.4) rotate(-8deg); }
  35% { opacity: 1; transform: translate(-50%, -50%) scale(1.18) rotate(-3deg); }
  100% { opacity: 0; transform: translate(-50%, -80%) scale(1) rotate(2deg); }
}

@keyframes coinFly {
  to {
    opacity: 0;
    transform: translate(var(--dx), var(--dy)) scale(0.55) rotate(540deg);
  }
}

@keyframes scoreFloat {
  to { opacity: 0; transform: translateY(-52px) scale(1.25); }
}

@keyframes sparkBurst {
  to {
    opacity: 0;
    transform: translate(var(--dx), var(--dy)) scale(0.2);
  }
}

@keyframes shake {
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

@media (max-width: 420px) {
  .app-shell {
    padding: 0;
  }

  .phone-frame {
    width: 100%;
    min-height: 100vh;
    border-width: 0;
    border-radius: 0;
  }

  h1 {
    font-size: 26px;
  }

  .player-card strong {
    font-size: 19px;
  }

  .status-pill strong {
    font-size: 23px;
  }

  .board {
    gap: 4px;
  }
}
