:root {
  --gold: #d4af37;
  --gold-bright: #f2d675;
  --felt: #0e5132;
  --felt-deep: #041a10;
  --ink: #1c2a24;
  --text: #f7f4e9;
  --muted: rgba(247, 244, 233, 0.62);
  --danger: #f06a6a;
  --panel-top: rgba(15, 61, 40, 0.97);
  --panel-bottom: rgba(4, 22, 13, 0.98);
  --ui-font: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui,
    -apple-system, sans-serif;
  --title-font: Georgia, "Songti SC", "STSong", serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #03150c;
  color: var(--text);
  font-family: var(--ui-font);
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

body {
  background:
    radial-gradient(circle at 50% 45%, rgba(24, 92, 60, 0.55), transparent 62%),
    #03150c;
  overscroll-behavior: none;
}

button,
input {
  font-family: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

#app {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
}

#stage {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}

#game {
  display: block;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  border-radius: 2px;
  box-shadow:
    0 30px 80px rgba(0, 0, 0, 0.6),
    0 0 0 1px rgba(212, 175, 55, 0.16);
}

.hidden {
  display: none !important;
}

/* ---------- HUD ---------- */

.hud {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 10px);
  right: calc(env(safe-area-inset-right, 0px) + 10px);
  z-index: 12;
  display: flex;
  flex-direction: row;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}

.icon-btn {
  pointer-events: auto;
  min-height: 38px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid rgba(212, 175, 55, 0.45);
  background: rgba(4, 24, 14, 0.72);
  color: rgba(247, 244, 233, 0.9);
  font-size: 13px;
  letter-spacing: 0.04em;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

.icon-btn:hover {
  border-color: rgba(242, 214, 117, 0.8);
  background: rgba(10, 45, 29, 0.85);
}

.icon-btn:active {
  transform: scale(0.96);
}

.icon-btn.active {
  border-color: var(--gold-bright);
  color: var(--gold-bright);
  box-shadow: 0 0 16px rgba(242, 214, 117, 0.25);
}

/* ---------- Overlays & panels ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(env(safe-area-inset-top, 0px) + 18px)
    calc(env(safe-area-inset-right, 0px) + 18px)
    calc(env(safe-area-inset-bottom, 0px) + 18px)
    calc(env(safe-area-inset-left, 0px) + 18px);
  background: rgba(2, 12, 7, 0.62);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  animation: fade-in 0.2s ease;
}

.panel {
  width: min(92vw, 430px);
  max-height: min(88vh, 860px);
  overflow-y: auto;
  padding: 28px 26px;
  border-radius: 24px;
  border: 1px solid rgba(212, 175, 55, 0.52);
  background:
    linear-gradient(160deg, rgba(255, 255, 255, 0.045), transparent 38%),
    linear-gradient(165deg, var(--panel-top), var(--panel-bottom));
  box-shadow:
    0 28px 70px rgba(0, 0, 0, 0.55),
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    inset 0 0 60px rgba(212, 175, 55, 0.045);
  animation: panel-in 0.24s cubic-bezier(0.2, 0.9, 0.25, 1);
  scrollbar-width: thin;
}

.panel h1,
.panel h2 {
  margin: 0;
  font-family: var(--title-font);
  font-weight: 700;
  letter-spacing: 0.06em;
}

.panel h2 {
  font-size: clamp(26px, 6.2vw, 34px);
  color: var(--gold-bright);
}

.eyebrow {
  margin: 0 0 10px;
  font-size: 13px;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: rgba(242, 214, 117, 0.72);
}

.hint {
  margin: 14px 0 0;
  font-size: 13px;
  line-height: 1.7;
  color: var(--muted);
}

.hint code {
  padding: 2px 6px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--gold-bright);
  font-size: 12px;
}

.tiny {
  margin: 14px 0 0;
  font-size: 12px;
  color: rgba(247, 244, 233, 0.42);
  letter-spacing: 0.08em;
}

.error-text {
  margin: 14px 0 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(240, 106, 106, 0.12);
  border: 1px solid rgba(240, 106, 106, 0.35);
  color: #ffc0c0;
  font-size: 13px;
  line-height: 1.5;
}

.status-line {
  margin: 12px 0 0;
  font-size: 16px;
  color: rgba(247, 244, 233, 0.82);
  min-height: 24px;
}

/* ---------- Connecting ---------- */

.connecting-panel {
  text-align: center;
  padding: 40px 28px;
}

.connecting-panel h2 {
  margin-top: 18px;
  font-family: var(--ui-font);
  font-size: 20px;
  letter-spacing: 0.02em;
  color: var(--text);
}

.connecting-panel .hint {
  max-width: 330px;
  margin-left: auto;
  margin-right: auto;
}

.spinner {
  width: 44px;
  height: 44px;
  margin: 0 auto;
  border-radius: 50%;
  border: 3px solid rgba(212, 175, 55, 0.18);
  border-top-color: var(--gold-bright);
  animation: spin 0.9s linear infinite;
}

.spinner.small {
  width: 26px;
  height: 26px;
  border-width: 2px;
  margin-top: 20px;
}

/* ---------- Lobby ---------- */

.brand {
  text-align: center;
  margin-bottom: 26px;
}

.brand-suits {
  color: rgba(242, 214, 117, 0.5);
  letter-spacing: 0.7em;
  font-size: 15px;
  padding-left: 0.7em;
}

.brand h1 {
  margin-top: 8px;
  font-size: clamp(38px, 10vw, 50px);
  color: var(--gold-bright);
  text-shadow: 0 6px 30px rgba(242, 214, 117, 0.22);
}

.subtitle {
  margin: 8px 0 0;
  font-size: 13px;
  letter-spacing: 0.34em;
  color: rgba(247, 244, 233, 0.5);
}

.field {
  display: block;
  margin-bottom: 16px;
}

.field > span {
  display: block;
  margin-bottom: 7px;
  font-size: 12px;
  letter-spacing: 0.18em;
  color: rgba(242, 214, 117, 0.64);
}

input {
  width: 100%;
  min-height: 50px;
  padding: 0 15px;
  border-radius: 13px;
  border: 1px solid rgba(212, 175, 55, 0.28);
  background: rgba(2, 18, 10, 0.62);
  color: var(--text);
  font-size: 16px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input::placeholder {
  color: rgba(247, 244, 233, 0.3);
}

input:focus {
  border-color: rgba(242, 214, 117, 0.78);
  box-shadow: 0 0 0 3px rgba(242, 214, 117, 0.12);
}

#room-input {
  flex: 1;
  min-width: 0;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  font-weight: 600;
}

button.primary,
button.secondary,
button.ghost,
button.small-btn {
  border: 0;
  cursor: pointer;
  transition: transform 0.1s ease, filter 0.15s ease, opacity 0.15s ease;
}

button.primary {
  width: 100%;
  min-height: 52px;
  border-radius: 14px;
  background: linear-gradient(180deg, #f5dc8c, #c9a02d);
  color: #1c2a24;
  font-size: 17px;
  font-weight: 800;
  letter-spacing: 0.12em;
  box-shadow:
    0 10px 24px rgba(0, 0, 0, 0.32),
    inset 0 1px 0 rgba(255, 255, 255, 0.55);
}

button.secondary {
  min-height: 50px;
  padding: 0 20px;
  border-radius: 13px;
  border: 1px solid rgba(212, 175, 55, 0.55);
  background: rgba(9, 42, 26, 0.85);
  color: var(--gold-bright);
  font-size: 16px;
  font-weight: 700;
  white-space: nowrap;
}

button.ghost {
  width: 100%;
  min-height: 46px;
  margin-top: 14px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: transparent;
  color: rgba(247, 244, 233, 0.72);
  font-size: 14px;
}

button.primary:hover,
button.secondary:hover {
  filter: brightness(1.06);
}

button.primary:active,
button.secondary:active,
button.small-btn:active {
  transform: scale(0.98);
}

button:disabled {
  cursor: default;
  opacity: 0.45;
  filter: saturate(0.5);
  transform: none !important;
}

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 22px 0 16px;
  color: rgba(247, 244, 233, 0.34);
  font-size: 12px;
  letter-spacing: 0.08em;
}

.divider::before,
.divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(212, 175, 55, 0.26), transparent);
}

.join-row {
  display: flex;
  gap: 10px;
}

/* ---------- Waiting ---------- */

.waiting-panel {
  text-align: center;
}

.room-code-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin: 6px 0 4px;
}

.room-code {
  font-family: "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: clamp(34px, 10vw, 46px);
  font-weight: 800;
  letter-spacing: 0.16em;
  padding-left: 0.16em;
  color: var(--gold-bright);
  text-shadow: 0 0 26px rgba(242, 214, 117, 0.25);
}

.small-btn {
  min-height: 34px;
  padding: 0 13px;
  border-radius: 999px;
  border: 1px solid rgba(212, 175, 55, 0.45);
  background: rgba(4, 24, 14, 0.55);
  color: var(--gold-bright);
  font-size: 12px;
  letter-spacing: 0.08em;
}

/* ---------- RPS ---------- */

.rps-panel {
  text-align: center;
}

.rps-choices {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 24px 0 4px;
}

.rps-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 118px;
  padding: 14px 6px;
  border-radius: 16px;
  border: 1px solid rgba(212, 175, 55, 0.32);
  background: rgba(3, 22, 12, 0.55);
  color: rgba(247, 244, 233, 0.88);
  font-size: 14px;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.15s ease, background 0.15s ease,
    box-shadow 0.15s ease;
}

.rps-btn:hover {
  border-color: rgba(242, 214, 117, 0.72);
  background: rgba(12, 52, 33, 0.7);
}

.rps-btn:active {
  transform: scale(0.97);
}

.rps-btn.selected {
  border-color: var(--gold-bright);
  background: rgba(64, 52, 18, 0.55);
  box-shadow:
    0 0 0 1px rgba(242, 214, 117, 0.28),
    0 0 24px rgba(242, 214, 117, 0.2);
}

.rps-btn:disabled {
  cursor: default;
  opacity: 0.48;
}

.rps-icon {
  font-size: 36px;
  line-height: 1;
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.4));
}

/* ---------- Game over ---------- */

.gameover-panel {
  text-align: center;
}

.gameover-panel h2 {
  font-size: clamp(36px, 9vw, 46px);
  margin: 8px 0 4px;
}

.gameover-panel h2.lose {
  color: #ffc6c6;
}

.gameover-panel .primary {
  margin-top: 26px;
}

/* ---------- Net overlay / banner / toasts ---------- */

.net-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(1, 9, 5, 0.55);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}

.net-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 26px 32px;
  border-radius: 18px;
  border: 1px solid rgba(212, 175, 55, 0.4);
  background: rgba(4, 24, 14, 0.94);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.net-card p {
  margin: 0;
  font-size: 15px;
  color: rgba(247, 244, 233, 0.86);
  letter-spacing: 0.04em;
}

.offline-banner {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 16px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  padding: 9px 18px;
  border-radius: 999px;
  border: 1px solid rgba(240, 106, 106, 0.5);
  background: rgba(52, 12, 12, 0.82);
  color: #ffd0d0;
  font-size: 13px;
  letter-spacing: 0.04em;
  pointer-events: none;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.toast-root {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 44px);
  transform: translateX(-50%);
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.dom-toast {
  padding: 10px 18px;
  border-radius: 999px;
  border: 1px solid rgba(212, 175, 55, 0.4);
  background: rgba(3, 20, 11, 0.9);
  color: var(--text);
  font-size: 13px;
  letter-spacing: 0.03em;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  animation: toast-in-out 1.9s ease forwards;
}

/* ---------- Animations ---------- */

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

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes panel-in {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes toast-in-out {
  0% {
    opacity: 0;
    transform: translateY(8px);
  }
  12% {
    opacity: 1;
    transform: translateY(0);
  }
  80% {
    opacity: 1;
    transform: translateY(0);
  }
  100% {
    opacity: 0;
    transform: translateY(-8px);
  }
}

@media (max-height: 620px) {
  .panel {
    padding: 20px 18px;
    border-radius: 18px;
  }

  .brand {
    margin-bottom: 16px;
  }

  .brand h1 {
    font-size: 36px;
  }

  .rps-btn {
    min-height: 92px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation-duration: 2.4s;
  }

  .panel,
  .overlay,
  .dom-toast {
    animation: none;
  }
}
