:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tabbar-h: 64px;
}

html,
body {
  min-height: 100dvh;
}

body {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.app {
  min-height: 100dvh;
  padding-top: var(--safe-top);
  padding-bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 12px);
}

.topbar {
  padding-top: 12px;
}

.chip-stack {
  color: inherit;
  font: inherit;
  cursor: pointer;
}

.screen[hidden] {
  display: none;
}

.game-menu {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.game-menu-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid rgba(243, 234, 215, 0.22);
  color: var(--cream);
  text-decoration: none;
  font-weight: 600;
  font-size: 13px;
  background: rgba(0, 0, 0, 0.18);
}

.game-menu-item span {
  color: var(--gold);
  font-size: 15px;
  line-height: 1;
}

.game-menu-item.is-active,
.game-menu-item[aria-current="page"] {
  background: rgba(224, 195, 106, 0.16);
  border-color: rgba(224, 195, 106, 0.45);
  color: var(--gold);
}

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 12;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  padding: 8px 12px calc(8px + var(--safe-bottom));
  background: rgba(7, 26, 20, 0.94);
  border-top: 1px solid rgba(224, 195, 106, 0.2);
  backdrop-filter: blur(10px);
}

.tabbar[hidden] {
  display: none;
}

.tabbar button,
.tabbar .tab-link {
  min-height: 44px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--cream);
  font: inherit;
  font-weight: 600;
  display: grid;
  place-items: center;
  text-decoration: none;
  cursor: pointer;
}

.tabbar button[aria-current="page"],
.tabbar .tab-link[aria-current="page"] {
  background: rgba(224, 195, 106, 0.16);
  color: var(--gold);
}

.auth-card,
.profile-wrap {
  max-width: 520px;
  margin: 20px auto;
  padding: 0 16px 24px;
}

.auth-card h2,
.profile-card h2 {
  font-size: 32px;
}

.auth-form {
  display: grid;
  gap: 10px;
  margin: 16px 0 24px;
}

.auth-form label,
.auth-form input {
  display: block;
  width: 100%;
}

.auth-form input {
  margin-top: 6px;
  min-height: 48px;
  border-radius: 12px;
  border: 1px solid rgba(224, 195, 106, 0.35);
  background: #0b1f19;
  color: var(--cream);
  padding: 10px 12px;
  font-size: 16px;
}

.muted {
  opacity: 0.72;
  line-height: 1.45;
}

.user-list {
  display: grid;
  gap: 8px;
}

.user-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  min-height: 56px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(0, 0, 0, 0.22);
  color: var(--cream);
  border-radius: 14px;
  padding: 10px 12px;
  cursor: pointer;
}

.user-row small {
  display: block;
  opacity: 0.7;
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #1f5c46;
  color: var(--gold);
  font-weight: 700;
}

.user-avatar.lg {
  width: 72px;
  height: 72px;
  font-size: 28px;
  margin: 0 auto 10px;
}

.profile-card {
  text-align: center;
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 18px;
  padding: 20px;
  margin-bottom: 16px;
}

.profile-chips {
  color: var(--gold);
  font-size: 22px;
  font-weight: 700;
}

.profile-actions {
  margin: 16px 0 24px;
}

.pay-fold summary {
  font-family: "EB Garamond", Georgia, serif;
  font-size: 26px;
  cursor: pointer;
  list-style: none;
}

.pay-fold summary::-webkit-details-marker {
  display: none;
}

.primary-btn,
.secondary-btn,
.gold-btn,
.ghost-btn,
.chip-btn,
.diff-card,
.tabbar button,
.tabbar .tab-link {
  min-height: 44px;
}

.help-panel,
.gamble-overlay {
  padding-top: calc(16px + var(--safe-top));
  padding-bottom: calc(16px + var(--safe-bottom));
  overflow: auto;
}

.help-card,
.gamble-shell {
  max-height: calc(100dvh - 40px);
  overflow: auto;
}

.result-banner {
  bottom: calc(18px + var(--tabbar-h) + var(--safe-bottom));
}

@media (max-width: 860px) {
  .topbar {
    padding: 10px 12px 0;
    gap: 8px;
    flex-wrap: wrap;
  }

  .brand-mark {
    width: 38px;
    height: 38px;
    font-size: 20px;
  }

  .brand h1 {
    font-size: 22px;
  }

  .brand p {
    display: none;
  }

  #help-btn {
    padding: 8px 10px;
    font-size: 13px;
  }

  .game-menu {
    order: 3;
    flex: 1 0 100%;
  }

  .game-menu-item {
    flex: 1;
    justify-content: center;
    min-height: 42px;
  }

  .table {
    margin: 8px 10px 28px;
    padding: 12px;
    border-width: 6px;
    border-radius: 18px;
    gap: 14px;
  }

  .board {
    gap: 6px;
    aspect-ratio: 5 / 5.15;
    max-width: 520px;
    margin: 0 auto;
    width: 100%;
  }

  .board-actions {
    display: grid;
    grid-template-columns: 1fr 1.2fr 1.2fr;
  }

  .board-actions button {
    width: 100%;
  }

  .hand-slots {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .hand-slot,
  .hand-slot .playing-card {
    min-height: 72px;
  }

  .diff-grid,
  .gamble-doors {
    grid-template-columns: 1fr;
  }

  .setup-head {
    flex-wrap: wrap;
  }

  .wheel-stage {
    width: 180px;
    height: 180px;
  }
}

@media (min-width: 861px) {
  .tabbar {
    max-width: 420px;
    left: 50%;
    transform: translateX(-50%);
    border-radius: 16px 16px 0 0;
  }

  .pay-fold {
    display: block;
  }
}
