:root {
  color-scheme: light;
  --bg-1: #0e2a22;
  --bg-2: #123729;
  --bg-3: #1a4732;
  --ink: #10211a;
  --ink-soft: #35574c;
  --surface: #f5f3ea;
  --surface-2: #ece5d3;
  --line: #c8b57a;
  --gold: #c9a24b;
  --gold-deep: #8b6a23;
  --accent: #1f7a55;
  --danger: #9f2a1f;
  --ok: #1d6f47;
  --radius-lg: 18px;
  --radius-md: 12px;
  --shadow-main: 0 12px 30px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  color: var(--ink);
  font-family: "Avenir Next", "Segoe UI", "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  background:
    radial-gradient(circle at 12% 10%, rgba(210, 176, 95, 0.15), transparent 34%),
    radial-gradient(circle at 85% 85%, rgba(201, 162, 75, 0.12), transparent 28%),
    linear-gradient(160deg, var(--bg-1) 0%, var(--bg-2) 50%, var(--bg-3) 100%);
}

body {
  padding:
    calc(10px + env(safe-area-inset-top))
    calc(10px + env(safe-area-inset-right))
    calc(10px + env(safe-area-inset-bottom))
    calc(10px + env(safe-area-inset-left));
}

body[data-scene="game"] .shop-page {
  display: none !important;
}

body[data-scene="shop"] .main-layout {
  display: none !important;
}

.app-shell {
  max-width: 1120px;
  margin: 0 auto;
  display: grid;
  gap: 12px;
}

.card {
  border-radius: var(--radius-lg);
  border: 1px solid rgba(201, 162, 75, 0.5);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.86) 0%, rgba(245, 241, 225, 0.93) 100%),
    var(--surface);
  box-shadow: var(--shadow-main);
  backdrop-filter: blur(2px);
  padding: 12px;
}

.top-bar {
  position: sticky;
  top: 0;
  z-index: 10;
}

.top-bar h1 {
  margin: 0;
  font-size: clamp(1.28rem, 5.8vw, 2.2rem);
  font-family: "Copperplate", "Times New Roman", serif;
  letter-spacing: 0.02em;
}

.meta-row {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  color: var(--ink-soft);
  font-weight: 700;
}

.player-name {
  display: inline-flex;
  min-height: 30px;
  align-items: center;
  border-radius: 999px;
  padding: 0 10px;
  border: 1px solid rgba(31, 122, 85, 0.36);
  background: rgba(31, 122, 85, 0.12);
  color: #1e5a41;
}

.nickname-edit-btn {
  min-width: 112px;
}

.badge {
  display: inline-flex;
  min-height: 30px;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  padding: 0 12px;
  font-size: 0.82rem;
  letter-spacing: 0.04em;
  color: #2f250c;
  border: 1px solid rgba(139, 106, 35, 0.5);
  background: linear-gradient(180deg, #efd596 0%, #d1ad58 100%);
}

.main-layout {
  display: grid;
  gap: 12px;
}

.main-layout[hidden] {
  display: none !important;
}

.play-panel {
  display: grid;
  gap: 10px;
}

.bet-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  align-items: center;
  border: 1px solid rgba(31, 122, 85, 0.24);
  background: linear-gradient(180deg, rgba(31, 122, 85, 0.08), rgba(31, 122, 85, 0.02));
  border-radius: var(--radius-md);
  padding: 8px;
}

.bet-row label {
  font-weight: 800;
  color: #1f513d;
}

.bet-row input {
  min-height: 44px;
  border: 1px solid #8fae9f;
  border-radius: 10px;
  padding: 8px;
  font-size: 1rem;
  background: #fff;
  color: var(--ink);
}

.bet-row > button {
  grid-column: 1 / -1;
}

.bet-controls {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(4, minmax(56px, 72px));
  gap: 6px;
  justify-content: start;
}

.bet-controls .btn {
  min-height: 44px;
  padding: 6px 4px;
  font-size: 0.86rem;
}

.bet-preview {
  grid-column: 1 / -1;
  border: 1px dashed rgba(139, 106, 35, 0.55);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.5);
  padding: 8px;
}

.bet-preview-text {
  margin: 0 0 8px;
  font-weight: 800;
  color: #315549;
}

.bet-coin-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 28px;
}

.bet-coin-chip {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1px solid #8f6b22;
  background: radial-gradient(circle at 30% 30%, #fff2bc 0%, #ddb45a 70%);
  box-shadow: inset 0 1px 2px rgba(255, 255, 255, 0.45);
}

.bet-coin-empty {
  margin: 0;
  font-size: 0.84rem;
  color: #60736c;
}

.lane {
  border-radius: var(--radius-md);
  border: 1px solid rgba(200, 181, 122, 0.5);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.6), rgba(244, 237, 216, 0.55));
  padding: 10px;
}

.lane h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 800;
  color: #253f35;
}

.lane-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.inventory-toggle {
  min-height: 44px;
  min-width: 88px;
  padding: 6px 10px;
  font-size: 0.84rem;
}

.score {
  margin: 5px 0;
  font-family: "Georgia", "Times New Roman", serif;
  font-weight: 700;
  color: #184a36;
}

.cards {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 62px;
}

.card-chip {
  min-width: 46px;
  min-height: 64px;
  border-radius: 10px;
  border: 1px solid #c9b57c;
  background: linear-gradient(180deg, #fffdfa 0%, #f0e5cc 100%);
  box-shadow: 0 6px 12px rgba(56, 40, 16, 0.16);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  padding: 7px 6px;
  font-family: "Georgia", "Times New Roman", serif;
  font-weight: 700;
  font-size: 0.95rem;
  animation: cardDeal 0.22s ease-out;
}

.card-chip[data-suit="♥"],
.card-chip[data-suit="♦"] {
  color: #b42318;
}

.card-chip[data-suit="♠"],
.card-chip[data-suit="♣"] {
  color: #111727;
}

.card-chip.hidden {
  background:
    linear-gradient(120deg, rgba(17, 39, 31, 0.55), rgba(44, 88, 67, 0.8)),
    repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.22) 0, rgba(255, 255, 255, 0.22) 8px, transparent 8px, transparent 16px);
  border-color: rgba(20, 54, 40, 0.86);
  color: transparent;
}

.status {
  margin: 0;
  min-height: 24px;
  border-radius: 10px;
  padding: 8px 10px;
  border: 1px solid rgba(29, 111, 71, 0.28);
  background: rgba(29, 111, 71, 0.08);
  color: var(--ok);
  font-weight: 800;
}

.action-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.btn {
  min-height: 44px;
  border-radius: 11px;
  border: 1px solid #9f8a52;
  background: linear-gradient(180deg, #fff9ed 0%, #e9dcc0 100%);
  color: #2a2211;
  font-weight: 800;
  font-size: 0.95rem;
  letter-spacing: 0.01em;
  padding: 8px 10px;
  touch-action: manipulation;
  transition:
    transform 120ms ease,
    box-shadow 120ms ease,
    filter 120ms ease;
}

.btn.primary {
  border-color: #145036;
  color: #f6fffb;
  background: linear-gradient(180deg, #2c9a6e 0%, #1f6f4f 100%);
}

.btn.primary.action-ready {
  border-color: #0f3b29;
  background: linear-gradient(180deg, #1a6848 0%, #0f3f2c 100%);
  box-shadow: 0 10px 18px rgba(14, 64, 44, 0.42);
}

.btn.danger {
  border-color: #5f1f17;
  color: #fff;
  background: linear-gradient(180deg, #bf4130 0%, #8f2a1f 100%);
}

.btn:active:not(:disabled) {
  transform: translateY(1px) scale(0.995);
}

.btn:hover:not(:disabled) {
  box-shadow: 0 8px 15px rgba(0, 0, 0, 0.18);
  filter: saturate(1.05);
}

.btn:disabled {
  opacity: 0.5;
}

.side-stack {
  display: grid;
  gap: 12px;
}

.logs {
  overflow: hidden;
}

.leaderboard h2,
.logs h2 {
  margin: 0 0 8px;
  font-size: 1rem;
  font-family: "Copperplate", "Times New Roman", serif;
  letter-spacing: 0.02em;
}

.inventory-drawer {
  position: fixed;
  top: calc(78px + env(safe-area-inset-top));
  right: calc(10px + env(safe-area-inset-right));
  z-index: 85;
  width: min(320px, calc(100vw - 20px - env(safe-area-inset-left) - env(safe-area-inset-right)));
  max-height: calc(100dvh - 100px - env(safe-area-inset-bottom));
  overflow: auto;
  border-radius: 16px;
  border: 1px solid rgba(201, 162, 75, 0.6);
  background: linear-gradient(180deg, #fffdf6 0%, #f7eed9 100%);
  box-shadow: 0 16px 28px rgba(0, 0, 0, 0.28);
  padding: 10px;
  transform: translateX(calc(100% + 16px));
  transition: transform 220ms ease;
  pointer-events: none;
}

.inventory-drawer.open {
  transform: translateX(0);
  pointer-events: auto;
}

.inventory-drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.inventory-drawer-head h2 {
  margin: 0;
  font-size: 1rem;
  font-family: "Copperplate", "Times New Roman", serif;
}

.drawer-close {
  min-height: 44px;
  min-width: 64px;
}

.shop-page {
  display: grid;
  gap: 10px;
  min-height: calc(100dvh - 112px);
  align-content: start;
}

.shop-page[hidden] {
  display: none !important;
}

.shop-page-head h2 {
  margin: 0 0 6px;
  font-size: 1.1rem;
  font-family: "Copperplate", "Times New Roman", serif;
}

.result-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(4, 18, 13, 0.54);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding:
    calc(16px + env(safe-area-inset-top))
    calc(16px + env(safe-area-inset-right))
    calc(16px + env(safe-area-inset-bottom))
    calc(16px + env(safe-area-inset-left));
}

.result-modal[hidden] {
  display: none !important;
}

.shuffle-toast {
  position: fixed;
  left: 50%;
  bottom: calc(22px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 120;
  border-radius: 999px;
  border: 1px solid rgba(201, 162, 75, 0.65);
  background: rgba(17, 39, 31, 0.94);
  color: #f8e8b6;
  font-family: "Copperplate", "Times New Roman", serif;
  letter-spacing: 0.06em;
  font-weight: 700;
  padding: 10px 16px;
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.34);
}

.shuffle-toast[hidden] {
  display: none !important;
}

.result-modal-card {
  width: min(440px, 100%);
  border-radius: 16px;
  border: 1px solid rgba(201, 162, 75, 0.5);
  background: linear-gradient(180deg, #fffdf6 0%, #f5ecd6 100%);
  box-shadow: 0 18px 34px rgba(0, 0, 0, 0.3);
  padding: 14px;
  display: grid;
  gap: 10px;
}

.result-modal-card h2 {
  margin: 0;
  font-size: 1.2rem;
  font-family: "Copperplate", "Times New Roman", serif;
}

.result-modal-card p {
  margin: 0;
  color: #2f473d;
  font-weight: 700;
}

.nickname-input {
  min-height: 44px;
  border: 1px solid #8fae9f;
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 1rem;
  background: #fff;
  color: var(--ink);
}

.list,
.log-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 8px;
}

.list-item {
  border: 1px solid rgba(162, 134, 68, 0.5);
  border-radius: 10px;
  padding: 8px;
  background: linear-gradient(180deg, #fffdfa 0%, #f6edd7 100%);
}

.shop-item {
  position: relative;
}

.shop-item-tooltip {
  position: absolute;
  right: 8px;
  top: calc(100% + 6px);
  z-index: 6;
  width: min(270px, calc(100vw - 56px));
  margin: 0;
  border: 1px solid rgba(31, 54, 44, 0.85);
  border-radius: 8px;
  background: rgba(11, 26, 21, 0.94);
  color: #e8f0ea;
  font-size: 0.8rem;
  line-height: 1.4;
  padding: 7px 9px;
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.28);
  opacity: 0;
  transform: translateY(-4px);
  pointer-events: none;
  transition:
    opacity 140ms ease,
    transform 140ms ease;
}

.shop-item:hover .shop-item-tooltip,
.shop-item:focus-within .shop-item-tooltip {
  opacity: 1;
  transform: translateY(0);
}

.item-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
}

.hint {
  margin: 0 0 8px;
  color: #5d6e66;
  font-size: 0.88rem;
}

.log-list li {
  border-left: 4px solid #7d6327;
  padding: 7px 9px;
  background: linear-gradient(180deg, #fffef9 0%, #f8f1df 100%);
  border-radius: 8px;
  font-size: 0.84rem;
  color: #2d2c25;
}

.log-list li:nth-child(1) {
  animation: pulseLog 0.42s ease;
}

@keyframes cardDeal {
  from {
    opacity: 0;
    transform: translateY(-6px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes pulseLog {
  from {
    background: #fae7b7;
  }
  to {
    background: linear-gradient(180deg, #fffef9 0%, #f8f1df 100%);
  }
}

@media (min-width: 760px) {
  .main-layout {
    grid-template-columns: 1.25fr 1fr;
    align-items: start;
  }

  .action-grid {
    grid-template-columns: repeat(3, minmax(140px, 1fr));
  }

  .bet-row {
    grid-template-columns: 1fr 1fr 1fr;
  }

  .bet-row > button {
    grid-column: auto;
  }

  .bet-controls {
    grid-template-columns: repeat(4, 64px);
    justify-content: start;
  }

  .bet-controls,
  .bet-preview,
  .bet-row #dealBtn {
    grid-column: 1 / -1;
  }

  .inventory-drawer {
    top: calc(90px + env(safe-area-inset-top));
    width: min(360px, 42vw);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
