:root {
  color-scheme: dark;
  --soil: #30160b;
  --soil-2: #5d2d13;
  --paper: #f6d996;
  --gold: #ffd25a;
  --red: #e4472f;
  --black: #15232a;
  --teal: #22c7bd;
  --cream: #fff4cb;
  --panel: rgba(42, 20, 10, 0.82);
  --line: rgba(255, 218, 128, 0.38);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 10%, rgba(255, 207, 91, 0.16), transparent 34%),
    linear-gradient(140deg, #140b08, #321408 54%, #0b1113);
  color: var(--cream);
  font-family: ui-rounded, system-ui, -apple-system, "Segoe UI", sans-serif;
}

button {
  font: inherit;
}

.phone-shell {
  width: 100vw;
  height: 100dvh;
  display: grid;
  place-items: center;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.game-stage {
  position: relative;
  width: min(100vw, calc(100dvh * 390 / 844));
  height: min(100dvh, calc(100vw * 844 / 390));
  max-width: 430px;
  max-height: 932px;
  min-width: 320px;
  min-height: 620px;
  overflow: hidden;
  isolation: isolate;
  background: #7a401e;
  box-shadow: 0 22px 80px rgba(0, 0, 0, 0.42);
}

@media (max-width: 520px) {
  .game-stage {
    max-width: none;
    max-height: none;
    min-width: 0;
    min-height: 0;
  }
}

#arenaCanvas {
  position: absolute;
  inset: 0;
  z-index: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: manipulation;
}

.top-hud {
  position: absolute;
  z-index: 6;
  top: 10px;
  left: 10px;
  right: 10px;
  display: grid;
  grid-template-columns: 44px minmax(126px, 168px) 1fr;
  gap: 8px;
  align-items: start;
  pointer-events: none;
}

.resource-pill,
.icon-button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(36, 17, 8, 0.74);
  box-shadow: 0 10px 22px rgba(27, 9, 3, 0.26);
  backdrop-filter: blur(9px);
}

.resource-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  color: #ffe8a3;
  font-weight: 1000;
  white-space: nowrap;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.coin-icon {
  width: 22px;
  height: 22px;
  flex: 0 0 22px;
  object-fit: contain;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.28));
}

.icon-button {
  pointer-events: auto;
  display: grid;
  place-items: center;
  padding: 0;
  color: #ffeab2;
  cursor: pointer;
  font-size: 28px;
  font-weight: 1000;
}

.back-button {
  width: 44px;
  line-height: 1;
  text-shadow: 0 2px 0 rgba(65, 24, 7, 0.7);
}

.callout {
  position: absolute;
  z-index: 5;
  top: 74px;
  left: 22px;
  right: 22px;
  min-height: 44px;
  display: grid;
  place-items: center;
  padding: 7px 14px;
  border-radius: 8px;
  color: #fff6d2;
  background: linear-gradient(90deg, transparent, rgba(45, 20, 9, 0.74), transparent);
  text-align: center;
  font-size: clamp(16px, 4.8vw, 22px);
  font-weight: 1000;
  text-shadow: 0 3px 0 rgba(62, 24, 7, 0.72), 0 8px 18px rgba(0, 0, 0, 0.38);
  transition: opacity 180ms ease, transform 180ms ease;
}

.game-stage[data-state="entering"] .callout,
.game-stage[data-state="fighting"] .callout {
  top: 92px;
}

.pick-panel {
  position: absolute;
  z-index: 7;
  left: 12px;
  right: 12px;
  bottom: max(12px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-rows: auto auto auto auto auto;
  gap: 10px;
  padding: 12px;
  border: 1px solid rgba(255, 219, 134, 0.28);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(64, 28, 11, 0.92), rgba(24, 11, 6, 0.95)),
    radial-gradient(circle at 18% 0%, rgba(255, 211, 98, 0.18), transparent 44%);
  box-shadow:
    inset 0 1px 0 rgba(255, 238, 169, 0.14),
    0 18px 44px rgba(18, 6, 2, 0.48);
  backdrop-filter: blur(8px);
  transition: opacity 220ms ease, transform 220ms ease, visibility 220ms ease;
}

.game-stage[data-state="entering"] .pick-panel,
.game-stage[data-state="locking"] .pick-panel,
.game-stage[data-state="fighting"] .pick-panel,
.game-stage[data-state="result"] .pick-panel {
  display: none;
  opacity: 0;
  pointer-events: none;
  transform: translateY(18px);
  visibility: hidden;
}

.bet-panel-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
  color: #ffe7a0;
  line-height: 1;
}

.bet-panel-header span {
  font-size: 13px;
  font-weight: 1000;
}

.bet-panel-header strong {
  min-width: 0;
  color: rgba(255, 238, 189, 0.72);
  font-size: 11px;
  font-weight: 900;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.fighter-card {
  position: relative;
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto auto auto;
  gap: 6px;
  padding: 10px;
  min-height: 124px;
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid rgba(255, 229, 150, 0.2);
  border-radius: 8px;
  cursor: pointer;
  color: #fff1b8;
  text-align: left;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(43, 19, 8, 0.82), rgba(17, 8, 5, 0.88)),
    radial-gradient(circle at 78% 24%, rgba(255, 225, 126, 0.11), transparent 40%);
  box-shadow: inset 0 1px 0 rgba(255, 238, 181, 0.08);
}

.fighter-card::before {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.16;
  pointer-events: none;
}

.fighter-card.is-red::before {
  background: linear-gradient(135deg, #f04b2f, transparent 55%);
}

.fighter-card.is-black::before {
  background: linear-gradient(135deg, #152c35, transparent 55%);
}

.fighter-card::after {
  content: "";
  position: absolute;
  right: 10px;
  top: 10px;
  width: 15px;
  height: 15px;
  border: 1px solid rgba(255, 231, 161, 0.36);
  border-radius: 50%;
  background: rgba(20, 8, 4, 0.44);
}

.fighter-card.is-selected {
  border-color: rgba(255, 214, 92, 0.86);
  box-shadow:
    0 0 0 2px rgba(255, 198, 61, 0.2),
    0 9px 22px rgba(0, 0, 0, 0.28);
}

.fighter-card.is-selected::after {
  border-color: #ffe37a;
  background:
    radial-gradient(circle at 50% 50%, #ffe37a 0 42%, transparent 45%),
    rgba(54, 20, 6, 0.82);
}

.side-label {
  position: relative;
  display: inline-flex;
  width: fit-content;
  padding: 4px 7px;
  border-radius: 999px;
  color: rgba(255, 225, 155, 0.9);
  background: rgba(12, 5, 3, 0.36);
  font-size: 10px;
  font-weight: 900;
  line-height: 1;
  z-index: 1;
}

.fighter-card strong {
  position: relative;
  display: block;
  color: rgba(255, 248, 226, 0.96);
  font-size: 21px;
  font-weight: 1000;
  line-height: 1;
  white-space: nowrap;
  z-index: 1;
  text-shadow:
    0 2px 0 rgba(45, 16, 7, 0.8),
    0 4px 8px rgba(0, 0, 0, 0.35);
}

.multiplier {
  position: relative;
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
  width: fit-content;
  color: #ffe39a;
  font-size: 15px;
  font-weight: 950;
  line-height: 1;
  z-index: 1;
  text-shadow: none;
}

.multiplier::before {
  content: "Phong cách";
  color: rgba(255, 236, 184, 0.68);
  font-size: 10px;
  font-weight: 900;
}

.cue-list {
  position: relative;
  display: grid;
  gap: 4px;
  color: rgba(255, 236, 205, 0.92);
  font-size: 9px;
  font-weight: 900;
  line-height: 1.1;
  z-index: 1;
  overflow: hidden;
  text-shadow: 0 1px 1px rgba(40, 14, 5, 0.9);
}

.cue-list span {
  display: block;
  min-width: 0;
  padding: 4px 6px;
  border-radius: 5px;
  color: inherit;
  background: rgba(16, 6, 3, 0.34);
  font: inherit;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cue-list span + span::before {
  content: none;
}

.stake-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  align-items: center;
}

.stake-chip {
  position: relative;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 8px;
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid rgba(255, 229, 150, 0.2);
  border-radius: 8px;
  cursor: pointer;
  color: #ffe9a8;
  background: rgba(22, 9, 5, 0.72);
  box-shadow: inset 0 1px 0 rgba(255, 236, 177, 0.08);
  font-size: 17px;
  font-weight: 1000;
}

.stake-chip .coin-icon {
  display: block;
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
}

.stake-chip span {
  display: block;
}

.stake-chip.is-selected {
  border-color: rgba(255, 214, 92, 0.84);
  color: #2b1307;
  background: linear-gradient(180deg, #ffe894, #e9992e);
  box-shadow:
    inset 0 1px 0 rgba(255, 250, 211, 0.42),
    0 6px 16px rgba(24, 8, 2, 0.32);
}

.stake-chip.is-selected::after {
  content: none;
}

.bet-lockup {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 0.9fr);
  align-items: center;
  gap: 8px;
  min-height: 62px;
  padding: 8px;
  border: 1px solid rgba(255, 218, 128, 0.58);
  border-radius: 6px;
  background:
    linear-gradient(180deg, rgba(86, 34, 10, 0.95), rgba(38, 14, 5, 0.96)),
    linear-gradient(90deg, rgba(255, 224, 129, 0.18), transparent 58%);
  box-shadow:
    inset 0 0 0 1px rgba(73, 25, 8, 0.72),
    inset 0 1px 0 rgba(255, 239, 166, 0.22),
    0 8px 18px rgba(20, 7, 3, 0.36);
  color: #ffeab2;
  pointer-events: none;
}

.lockup-main {
  min-width: 0;
  min-height: 40px;
  display: grid;
  grid-template-columns: auto minmax(38px, 1fr) auto minmax(52px, auto);
  align-items: center;
  gap: 5px;
  padding: 5px 7px;
  border-radius: 4px;
  background: rgba(28, 9, 4, 0.42);
  box-shadow: inset 0 0 0 1px rgba(255, 229, 142, 0.18);
}

.bet-lockup[data-pick="red"] .lockup-main {
  background: linear-gradient(90deg, rgba(140, 27, 13, 0.72), rgba(38, 12, 5, 0.42));
}

.bet-lockup[data-pick="black"] .lockup-main {
  background: linear-gradient(90deg, rgba(8, 24, 31, 0.8), rgba(35, 13, 6, 0.42));
}

.lockup-main span,
.lockup-main em,
.lockup-metrics span {
  color: rgba(255, 236, 184, 0.72);
  font-size: 9px;
  font-style: normal;
  font-weight: 900;
  line-height: 1;
  white-space: nowrap;
}

.lockup-main strong {
  min-width: 0;
  color: #fff5c4;
  font-size: 18px;
  font-weight: 1000;
  line-height: 1;
  white-space: nowrap;
  text-shadow: 0 2px 0 rgba(49, 18, 5, 0.62);
}

.lockup-main b {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 3px;
  color: #ffd864;
  font-size: 17px;
  font-weight: 1000;
  line-height: 1;
  white-space: nowrap;
}

.lockup-main .coin-icon {
  width: 14px;
  height: 14px;
  flex: 0 0 14px;
}

.lockup-metrics {
  display: grid;
  grid-template-columns: 1fr;
  gap: 4px;
  min-width: 0;
}

.lockup-metrics div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  min-width: 0;
  padding: 4px 6px;
  border-radius: 4px;
  background: rgba(21, 7, 3, 0.38);
}

.lockup-metrics strong {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  color: #fff3bc;
  font-size: 12px;
  font-weight: 1000;
  white-space: nowrap;
}

.lockup-metrics .coin-icon {
  width: 13px;
  height: 13px;
  flex: 0 0 13px;
}

.action-row {
  display: grid;
  grid-template-columns: 1fr;
  padding: 0;
}

.primary-action {
  min-height: 50px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 1000;
  letter-spacing: 0;
}

.primary-action {
  color: #8f281b;
  border: 0;
  background: transparent;
  box-shadow: none;
  font-size: 24px;
  font-family: "Songti SC", "STSong", "Noto Serif CJK SC", serif;
  text-shadow: 0 2px 2px rgba(76, 19, 7, 0.3);
}

.pick-panel .primary-action {
  border: 1px solid rgba(255, 236, 155, 0.62);
  border-radius: 7px;
  color: #331406;
  background: linear-gradient(180deg, #fff0ad 0%, #f0b94e 54%, #b95a18 100%);
  box-shadow:
    inset 0 0 0 2px rgba(116, 48, 16, 0.34),
    0 5px 0 rgba(78, 25, 8, 0.76),
    0 13px 22px rgba(23, 7, 2, 0.28);
  text-shadow: 0 1px 0 rgba(255, 238, 178, 0.78);
}

.primary-action:disabled {
  cursor: not-allowed;
  filter: saturate(0.45) brightness(0.74);
  box-shadow: 0 4px 0 #5d2814, 0 10px 20px rgba(27, 9, 3, 0.24);
}

@media (max-height: 720px) {
  .pick-panel {
    left: 10px;
    right: 10px;
    bottom: max(8px, env(safe-area-inset-bottom));
    gap: 8px;
    padding: 10px;
  }

  .fighter-card {
    padding: 9px;
    gap: 5px;
    min-height: 116px;
  }

  .side-label {
    font-size: 9px;
  }

  .fighter-card strong {
    font-size: 20px;
  }

  .stake-chip {
    padding: 8px 6px;
    font-size: 15px;
  }

  .bet-lockup {
    min-height: 54px;
    padding: 6px;
  }

  .primary-action {
    min-height: 44px;
  }

  .primary-action {
    font-size: 21px;
  }
}

.result-panel {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 24px 20px;
  background:
    radial-gradient(circle at 50% 38%, rgba(255, 211, 86, 0.23), transparent 38%),
    rgba(32, 12, 5, 0.72);
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
  transition: opacity 260ms ease, visibility 260ms ease;
}

.result-panel.is-visible {
  opacity: 1;
  pointer-events: auto;
  visibility: visible;
}

.settlement-card {
  width: min(100%, 350px);
  min-height: 520px;
  display: grid;
  align-content: center;
  gap: 18px;
  padding: 46px 30px 38px;
  border: 1px solid rgba(255, 230, 160, 0.32);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(48, 21, 9, 0.72), rgba(48, 21, 9, 0.9)),
    url("images/settlement-ticket.webp?v=20260627-cock-restart3-return85-v1") center / 100% 100% no-repeat;
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.54);
  text-align: center;
}

.result-kicker {
  color: #f4bf61;
  font-size: 13px;
  font-weight: 1000;
  text-transform: uppercase;
}

.settlement-card h1 {
  margin: 0;
  color: #fff0ad;
  font-size: clamp(30px, 8vw, 42px);
  line-height: 0.95;
  text-shadow: 0 4px 0 rgba(74, 27, 8, 0.8);
}

.settlement-card p {
  margin: 0;
  color: #fff7d4;
  font-size: 18px;
  font-weight: 1000;
}

.settlement-lines {
  display: grid;
  gap: 8px;
  text-align: left;
}

.settlement-lines div {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(19, 8, 4, 0.42);
  color: #ffeab2;
}

.settlement-lines span {
  color: rgba(255, 238, 188, 0.78);
  font-weight: 850;
}

.settlement-lines strong {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  font-weight: 1000;
}

.settlement-lines .coin-icon {
  width: 20px;
  height: 20px;
  flex-basis: 20px;
}

.settlement-card .primary-action {
  min-height: 52px;
  border: 0;
  border-radius: 8px;
  color: #2b1307;
  background: linear-gradient(180deg, #fff0a8, #ffbd43 56%, #e36b1d);
  box-shadow: 0 7px 0 #7e3314, 0 17px 32px rgba(27, 9, 3, 0.34);
  font-family: ui-rounded, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 18px;
  text-shadow: 0 1px 0 rgba(255, 244, 184, 0.7);
}

.loading-screen {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  color: #fff0b6;
  background:
    radial-gradient(circle at 50% 44%, rgba(255, 213, 94, 0.2), transparent 34%),
    rgba(35, 15, 7, 0.94);
}

.loading-screen[hidden] {
  display: none;
}

.loading-box {
  display: grid;
  justify-items: center;
  gap: 12px;
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(43, 19, 9, 0.86);
}

.loading-box p {
  margin: 0;
  font-weight: 1000;
}

.loading-spinner {
  width: 42px;
  height: 42px;
  border: 4px solid rgba(255, 238, 177, 0.22);
  border-top-color: #ffd25a;
  border-radius: 50%;
  animation: spin 900ms linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}
