:root {
  color-scheme: dark;
  --bg: #101318;
  --panel: rgba(16, 19, 24, 0.78);
  --line: rgba(255, 255, 255, 0.1);
  --coin-gold: #dfc675;
  --text: #f3f0e8;
  --muted: #aeb6c5;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 20% 20%, rgba(229, 190, 92, 0.12), transparent 30rem),
    linear-gradient(135deg, #101318 0%, #202631 100%);
}

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

button,
input,
select {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 20px;
  width: min(1320px, calc(100vw - 32px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 24px 0;
}

.board-panel,
.control-panel {
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: 0 20px 80px rgba(0, 0, 0, 0.35);
}

.board-panel {
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 22px;
}

.top-bar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(2rem, 4vw, 4.5rem);
  line-height: 0.95;
  letter-spacing: 0;
}

h2 {
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: #dfc675;
}

p {
  margin-top: 8px;
  color: var(--muted);
}

.stat-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(78px, 1fr));
  gap: 8px;
  min-width: 300px;
}

.stat-strip div {
  position: relative;
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 13px 10px 10px;
  background: rgba(255, 255, 255, 0.04);
}

.score-stat {
  position: relative;
  grid-column: 1 / -1;
}

.stat-label {
  display: block;
  position: absolute;
  top: -8px;
  left: 8px;
  margin-bottom: 0;
  padding: 0 5px;
  background: #171c24;
  color: #9da6b5;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.stat-strip strong {
  font-size: 1.35rem;
}

.score-stat strong {
  display: block;
  max-width: 100%;
  font-size: 1.1rem;
  line-height: 1.15;
}

.score-pop {
  position: absolute;
  right: 12px;
  bottom: 10px;
  font-weight: 900;
  opacity: 0;
  pointer-events: none;
}

.score-pop--normal {
  color: var(--coin-gold);
}

.score-pop--streak {
  right: 76px;
  color: #f29a38;
}

.score-pop.is-rising {
  animation: score-rise 900ms ease-out forwards;
}

@keyframes score-rise {
  0% {
    opacity: 0;
    transform: translateY(8px) scale(0.95);
  }

  18% {
    opacity: 1;
  }

  100% {
    opacity: 0;
    transform: translateY(-28px) scale(1.06);
  }
}

.slot-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(98px, 1fr));
  gap: 10px;
}

.slot-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
  min-height: 176px;
  padding: 10px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.025));
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.slot-card:hover,
.slot-card.is-selected {
  border-color: var(--coin-gold);
  background: linear-gradient(160deg, rgba(223, 198, 117, 0.2), rgba(255, 255, 255, 0.04));
}

.slot-card.is-full:not(.is-selected) {
  border-color: rgba(255, 255, 255, 0.18);
  background: linear-gradient(160deg, rgba(203, 87, 87, 0.14), rgba(255, 255, 255, 0.025));
}

.slot-card.is-locked,
.slot-card.is-locked:hover {
  border-color: rgba(255, 255, 255, 0.08);
  background: repeating-linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.045),
    rgba(255, 255, 255, 0.045) 8px,
    rgba(255, 255, 255, 0.02) 8px,
    rgba(255, 255, 255, 0.02) 16px
  );
  color: #7f8795;
  cursor: not-allowed;
}

.slot-card__top,
.rate-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.slot-card__top span {
  color: var(--coin-gold);
  font-weight: 800;
}

.slot-card__top strong {
  font-size: 0.88rem;
}

.coin-stack {
  position: relative;
  flex: 0 0 124px;
  min-height: 124px;
}

.coin {
  position: absolute;
  left: 50%;
  top: calc(var(--coin-index) * 8px);
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border: 2px solid rgba(255, 255, 255, 0.45);
  border-radius: 999px;
  background: var(--coin-gold);
  box-shadow:
    inset 0 -7px 0 rgba(0, 0, 0, 0.16),
    0 8px 16px rgba(0, 0, 0, 0.28);
  color: #16140d;
  font-size: 0.78rem;
  font-weight: 900;
  transform: translateX(-50%);
  transition:
    top 140ms ease,
    transform 140ms ease,
    box-shadow 140ms ease;
  z-index: var(--coin-index);
}

.coin--animation-hidden {
  opacity: 0;
}

.coin::after {
  position: absolute;
  right: 8px;
  bottom: -10px;
  left: 8px;
  height: 8px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.34);
  content: "";
  opacity: 0;
  transform: translateY(8px) scaleX(0.72);
  transition:
    opacity 140ms ease,
    transform 140ms ease;
  z-index: -1;
}

.slot-card.is-selected .coin--movable {
  transform: translate(-50%, -8px);
  box-shadow:
    inset 0 -7px 0 rgba(0, 0, 0, 0.16),
    0 14px 22px rgba(0, 0, 0, 0.38);
}

.slot-card.is-selected .coin--movable::after {
  opacity: 1;
  transform: translateY(8px) scaleX(1);
}

.coin-flight {
  position: absolute;
  pointer-events: none;
  transform: none;
  z-index: 1000;
}

.coin-drop-back {
  position: absolute;
  pointer-events: none;
  transform: none;
  z-index: 999;
}

.coin--tier-1 {
  background: #dfc675;
}

.coin--tier-2 {
  background: #d68c52;
}

.coin--tier-3 {
  background: #7fc5bd;
}

.coin--tier-4 {
  background: #8fb6df;
}

.coin--tier-5 {
  background: #bda1df;
}

.coin--tier-6 {
  background: #e6a1b6;
}

.coin--wild {
  background:
    radial-gradient(circle at 35% 30%, rgba(255, 255, 255, 0.95), transparent 18%),
    linear-gradient(145deg, #f4f0ff 0%, #9ad7ff 42%, #f5a8ff 100%);
  color: #181124;
}

.empty-stack {
  display: grid;
  min-height: 72px;
  place-items: center;
  color: #768294;
}

.control-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 18px;
}

.control-group {
  display: grid;
  gap: 10px;
}

label {
  color: #c9d0dc;
  font-size: 0.86rem;
}

select,
input,
button#deal-button,
.secondary-button,
.danger-button {
  width: 100%;
  min-height: 42px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: #171c24;
  color: #f3f0e8;
  padding: 0 12px;
}

button#deal-button {
  margin-top: 4px;
  background: var(--coin-gold);
  color: #16140d;
  font-weight: 800;
  cursor: pointer;
}

.mobile-deal-button {
  display: none;
}

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

.secondary-button {
  background: #202938;
  color: #f3f0e8;
  cursor: pointer;
}

.danger-button {
  background: #4b2028;
  color: #ffd9de;
  cursor: pointer;
}

.save-status {
  min-height: 18px;
  color: #9da6b5;
  font-size: 0.82rem;
}

.account-status a,
.login-prompt a {
  color: #7dd3fc;
  font-weight: 800;
}

.login-prompt {
  margin: 0;
  color: #9da6b5;
  font-size: 0.82rem;
  line-height: 1.4;
}

.rank-badge,
.leaderboard-rank {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 42px;
  padding: 2px 7px;
  border-radius: 999px;
  font-weight: 900;
  font-size: 0.76rem;
}

.rank-badge--score,
.leaderboard-rank--score,
#leaderboard-score.is-active {
  color: #06131b;
  background: #7dd3fc;
}

.rank-badge--tier,
.leaderboard-rank--tier,
#leaderboard-tier.is-active {
  color: #161006;
  background: #fbbf24;
}

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

.leaderboard-list {
  display: grid;
  gap: 7px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.leaderboard-list li {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  color: #9da6b5;
  font-size: 0.84rem;
}

.leaderboard-list strong {
  color: #f3f0e8;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaderboard-message {
  grid-template-columns: 1fr !important;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(4, 8, 14, 0.72);
}

.modal-backdrop[hidden] {
  display: none;
}

.app-modal {
  width: min(520px, 100%);
  max-height: min(720px, calc(100vh - 32px));
  overflow: auto;
  padding: 18px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background: #10141b;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.38);
}

#modal-close-button {
  width: 32px;
  height: 32px;
  min-height: 0;
  padding: 0;
  margin: 0;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.modal-header h2 {
  margin: 0;
  font-size: 1rem;
}

.modal-body {
  display: grid;
  gap: 12px;
}

.modal-body p {
  margin: 0;
  color: #b9c2cf;
  line-height: 1.45;
}

.modal-body ul {
  display: grid;
  gap: 10px;
  margin: 0;
  padding-left: 18px;
  color: #b9c2cf;
  line-height: 1.45;
}

.rate-list {
  display: grid;
  gap: 8px;
}

.rate-row {
  min-height: 34px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.event-log {
  display: grid;
  gap: 8px;
  max-height: 250px;
  margin: 0;
  padding-left: 18px;
  overflow: auto;
  color: #b9c2cf;
  font-size: 0.88rem;
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .top-bar {
    align-items: stretch;
    flex-direction: column;
  }

  .stat-strip {
    min-width: 0;
  }

  .slot-grid {
    grid-template-columns: repeat(3, minmax(92px, 124px));
    justify-content: center;
  }
}

@media (max-width: 640px) {
  body {
    min-height: 100svh;
    overflow-x: hidden;
    background:
      radial-gradient(circle at 50% -10%, rgba(223, 198, 117, 0.18), transparent 18rem),
      linear-gradient(180deg, #12161d 0%, #0f1217 100%);
  }

  .app-shell {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
    min-height: 100svh;
    padding: 8px;
  }

  .board-panel,
  .control-panel {
    border-radius: 0;
    box-shadow: none;
  }

  .board-panel {
    gap: 10px;
    padding: 10px;
    background: rgba(16, 19, 24, 0.86);
  }

  .top-bar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
  }

  .top-bar p {
    display: none;
  }

  h1 {
    font-size: 1.7rem;
    line-height: 1;
  }

  .mobile-deal-button {
    display: inline-grid;
    min-width: 104px;
    min-height: 42px;
    place-items: center;
    border: 1px solid rgba(255, 255, 255, 0.14);
    background: var(--coin-gold);
    color: #16140d;
    padding: 0 10px;
    font-weight: 800;
    cursor: pointer;
  }

  h2 {
    font-size: 0.72rem;
    letter-spacing: 0.08em;
  }

  .stat-strip {
    grid-column: 1 / -1;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }

  .stat-strip div {
    min-width: 0;
    padding: 11px 7px 7px;
  }

  .stat-label {
    top: -7px;
    left: 6px;
    padding: 0 4px;
    font-size: 0.62rem;
  }

  .stat-strip strong {
    display: block;
    overflow: hidden;
    font-size: 1rem;
    line-height: 1.1;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .score-stat {
    grid-column: 1 / -1;
  }

  .slot-grid {
    grid-template-columns: repeat(3, minmax(92px, 112px));
    justify-content: center;
    gap: 6px;
  }

  .slot-card {
    gap: 6px;
    min-height: 127px;
    padding: 6px;
    touch-action: manipulation;
  }

  .slot-card__top {
    min-width: 0;
    gap: 4px;
  }

  .slot-card__top strong,
  .slot-card__top span {
    min-width: 0;
    overflow: hidden;
    font-size: 0.62rem;
    line-height: 1;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .coin-stack {
    flex-basis: 84px;
    min-height: 84px;
  }

  .coin {
    top: calc(var(--coin-index) * 5px);
    box-shadow:
      inset 0 -5px 0 rgba(0, 0, 0, 0.14),
      0 5px 10px rgba(0, 0, 0, 0.24);
  }

  .empty-stack {
    min-height: 54px;
    font-size: 0.72rem;
  }

  .control-panel {
    display: grid;
    grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
    gap: 8px;
    padding: 10px;
    background: rgba(13, 16, 21, 0.94);
  }

  .control-group:first-child {
    display: none;
  }

  .control-group {
    gap: 7px;
    min-width: 0;
  }

  .control-group:nth-child(1),
  .control-group:nth-child(2) {
    align-content: start;
  }

  .control-group:nth-child(3),
  .control-group:nth-child(4) {
    grid-column: 1 / -1;
  }

  button#deal-button,
  .secondary-button,
  .danger-button {
    min-height: 44px;
    padding: 0 10px;
  }

  .button-row {
    gap: 6px;
  }

  .save-status {
    min-height: 15px;
    font-size: 0.72rem;
  }

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

  .rate-row {
    min-height: 27px;
    font-size: 0.76rem;
  }

  .event-log {
    max-height: 92px;
    gap: 5px;
    padding-left: 16px;
    font-size: 0.75rem;
    line-height: 1.25;
  }
}

@media (max-width: 480px) {
  .slot-grid {
    grid-template-columns: repeat(3, minmax(88px, 1fr));
    gap: 5px;
  }

  .slot-card {
    min-height: 121px;
    padding: 5px;
  }

  .coin-stack {
    flex-basis: 84px;
    min-height: 84px;
  }

  .control-panel {
    grid-template-columns: 1fr;
  }

  .control-group:nth-child(3),
  .control-group:nth-child(4) {
    grid-column: auto;
  }
}
