:root {
  color-scheme: dark;
  --bg: #07100d;
  --surface: rgba(19, 34, 29, 0.9);
  --surface-strong: #14251f;
  --surface-soft: rgba(255, 255, 255, 0.055);
  --line: rgba(255, 255, 255, 0.11);
  --text: #f4f7f5;
  --muted: #a9b8b1;
  --accent: #d7b66b;
  --accent-strong: #f3d58c;
  --success: #7ddeac;
  --danger: #ff938e;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.38);
  --radius-xl: 28px;
  --radius-lg: 20px;
  --radius-md: 14px;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--text);
  background:
    radial-gradient(circle at 15% 0%, rgba(44, 105, 78, 0.34), transparent 38%),
    radial-gradient(circle at 90% 10%, rgba(164, 126, 51, 0.18), transparent 32%),
    linear-gradient(180deg, #0b1713 0%, var(--bg) 60%);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
button, input, select { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 3px solid rgba(215, 182, 107, 0.4);
  outline-offset: 2px;
}

#app { min-height: 100dvh; }
.app-shell {
  width: min(100%, 1100px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 16px max(20px, env(safe-area-inset-bottom));
}
.center-screen {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.loader {
  width: 34px;
  height: 34px;
  border: 3px solid rgba(255,255,255,.12);
  border-top-color: var(--accent);
  border-radius: 999px;
  animation: spin .75s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.brand-row, .topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  letter-spacing: -0.03em;
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 13px;
  color: #1b160b;
  background: linear-gradient(145deg, #f2d58e, #b89143);
  box-shadow: 0 12px 32px rgba(191, 146, 66, .25);
}
.version { color: var(--muted); font-size: .78rem; }

.hero {
  padding: 58px 0 28px;
  text-align: center;
}
.eyebrow {
  margin: 0 0 12px;
  color: var(--accent-strong);
  font-size: .76rem;
  font-weight: 800;
  letter-spacing: .14em;
  text-transform: uppercase;
}
h1, h2, h3, p { margin-top: 0; }
h1 {
  margin-bottom: 14px;
  font-size: clamp(2.5rem, 12vw, 5.7rem);
  line-height: .91;
  letter-spacing: -.07em;
}
h2 { font-size: clamp(1.45rem, 6vw, 2.3rem); letter-spacing: -.04em; }
.hero-copy {
  width: min(100%, 560px);
  margin: 0 auto;
  color: var(--muted);
  font-size: 1.02rem;
  line-height: 1.65;
}

.grid { display: grid; gap: 14px; }
.home-grid { grid-template-columns: 1fr; margin-top: 24px; }
.card-panel {
  position: relative;
  overflow: hidden;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  background: linear-gradient(155deg, rgba(24, 44, 36, .93), rgba(12, 24, 20, .91));
  box-shadow: var(--shadow);
  backdrop-filter: blur(22px);
}
.card-panel::before {
  content: "";
  position: absolute;
  inset: 0 auto auto 0;
  width: 100%;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.25), transparent);
}
.panel-icon {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  margin-bottom: 28px;
  border-radius: 15px;
  background: var(--surface-soft);
  color: var(--accent-strong);
  font-size: 1.25rem;
}
.panel-copy { color: var(--muted); line-height: 1.5; }
.form-stack { display: grid; gap: 12px; }
.label { display: grid; gap: 8px; color: var(--muted); font-size: .86rem; font-weight: 700; }
.input, .select {
  width: 100%;
  min-height: 50px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 0 15px;
  color: var(--text);
  background: rgba(3, 9, 7, .48);
}
.input::placeholder { color: #718078; }
.code-input {
  text-align: center;
  text-transform: uppercase;
  letter-spacing: .28em;
  font-weight: 900;
}
.actions { display: flex; flex-wrap: wrap; gap: 10px; }
.btn {
  min-height: 48px;
  border: 1px solid transparent;
  border-radius: 15px;
  padding: 0 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  font-weight: 800;
  transition: transform .16s ease, opacity .16s ease, border-color .16s ease, background .16s ease;
}
.btn:active { transform: scale(.98); }
.btn:disabled { cursor: not-allowed; opacity: .45; }
.btn-primary {
  color: #191407;
  background: linear-gradient(145deg, #f1d58e, #bd9345);
  box-shadow: 0 12px 34px rgba(198, 154, 72, .2);
}
.btn-secondary { color: var(--text); border-color: var(--line); background: var(--surface-soft); }
.btn-danger { color: #ffd6d2; border-color: rgba(255,147,142,.25); background: rgba(255,147,142,.08); }
.btn-block { width: 100%; }
.icon-btn {
  width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 0;
  border-radius: 14px;
}

.lobby-layout { display: grid; gap: 16px; margin-top: 22px; }
.room-code-card { text-align: center; padding: 28px 20px; }
.room-code-label { color: var(--muted); font-size: .8rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.room-code {
  display: block;
  margin: 10px 0 16px;
  color: var(--accent-strong);
  font-size: clamp(2.1rem, 13vw, 4rem);
  line-height: 1;
  letter-spacing: .16em;
  font-weight: 900;
}
.player-list { display: grid; gap: 9px; margin: 0; padding: 0; list-style: none; }
.player-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 56px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255,255,255,.035);
}
.player-main { display: flex; align-items: center; gap: 11px; min-width: 0; }
.avatar {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  color: var(--accent-strong);
  background: rgba(215,182,107,.1);
  font-weight: 900;
}
.player-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 800; }
.badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  color: var(--muted);
  background: var(--surface-soft);
  font-size: .72rem;
  font-weight: 800;
}
.badge-accent { color: #241a07; background: var(--accent); }
.helper { color: var(--muted); font-size: .86rem; line-height: 1.55; }

.game-shell {
  min-height: calc(100dvh - max(18px, env(safe-area-inset-top)) - max(20px, env(safe-area-inset-bottom)));
  display: grid;
  grid-template-rows: auto auto minmax(190px, 1fr) auto auto;
  gap: 10px;
}
.game-topbar {
  min-width: 0;
  padding: 2px 0 4px;
}
.game-room { color: var(--muted); font-size: .75rem; font-weight: 800; letter-spacing: .1em; }
.turn-banner {
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 9px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--muted);
  background: rgba(255,255,255,.035);
  font-weight: 800;
  text-align: center;
}
.turn-banner.my-turn { color: #1a160a; border-color: transparent; background: linear-gradient(145deg, #f0d58e, #b88f42); }
.opponents {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
.opponent {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255,255,255,.035);
}
.opponent.active { border-color: rgba(215,182,107,.52); box-shadow: inset 0 0 0 1px rgba(215,182,107,.14); }
.opponent.finished { opacity: .62; }
.opponent-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .82rem; font-weight: 850; }
.opponent-meta { margin-top: 5px; color: var(--muted); font-size: .72rem; }

.table-zone {
  display: grid;
  place-items: center;
  min-height: 190px;
  padding: 16px;
  border: 1px solid rgba(215,182,107,.13);
  border-radius: 50% / 24%;
  background:
    radial-gradient(circle, rgba(39, 91, 66, .66), rgba(12, 39, 29, .86) 58%, rgba(4, 18, 13, .93));
  box-shadow: inset 0 0 60px rgba(0,0,0,.26), var(--shadow);
}
.pile { min-height: 98px; display: flex; align-items: center; justify-content: center; }
.pile-empty { color: rgba(255,255,255,.38); font-size: .84rem; font-weight: 800; }
.pile-card { margin-left: -25px; transform: rotate(var(--rotation, 0deg)); }
.pile-card:first-child { margin-left: 0; }

.hand-wrap { min-width: 0; }
.hand-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.hand-title { margin: 0; font-size: .86rem; color: var(--muted); }
.hand {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  min-height: 106px;
  padding: 9px 4px 4px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
}
.hand::-webkit-scrollbar { display: none; }
.playing-card {
  position: relative;
  flex: 0 0 58px;
  width: 58px;
  height: 86px;
  border: 1px solid rgba(0,0,0,.16);
  border-radius: 10px;
  padding: 7px;
  color: #161a18;
  background: linear-gradient(145deg, #fff, #e9ede9);
  box-shadow: 0 7px 18px rgba(0,0,0,.3);
  scroll-snap-align: center;
  transition: transform .15s ease, box-shadow .15s ease;
  user-select: none;
}
.playing-card.red { color: #bc302d; }
.playing-card.selected { transform: translateY(-12px); box-shadow: 0 15px 28px rgba(0,0,0,.4), 0 0 0 3px var(--accent); }
.playing-card:disabled { opacity: .72; }
.card-corner { display: grid; justify-items: center; font-weight: 900; font-size: .92rem; line-height: .9; }
.card-suit-large { position: absolute; inset: 0; display: grid; place-items: center; font-size: 1.75rem; }
.game-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding-bottom: max(0px, env(safe-area-inset-bottom));
}

.results { text-align: center; padding-top: 20px; }
.crown { font-size: 3.8rem; filter: drop-shadow(0 12px 22px rgba(215,182,107,.22)); }
.result-list { display: grid; gap: 9px; margin: 22px 0; padding: 0; list-style: none; text-align: left; }
.place { width: 32px; color: var(--accent-strong); font-weight: 900; }

.setup-note {
  width: min(100%, 650px);
  margin: auto;
}
.code-block {
  overflow-x: auto;
  padding: 14px;
  border-radius: 13px;
  color: #dce8e1;
  background: #050a08;
  font: 13px/1.6 ui-monospace, SFMono-Regular, Consolas, monospace;
}

.toast-region {
  position: fixed;
  z-index: 100;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  width: min(calc(100% - 28px), 440px);
  transform: translateX(-50%);
  pointer-events: none;
}
.toast {
  margin-top: 8px;
  padding: 13px 15px;
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--text);
  background: rgba(10, 19, 16, .96);
  box-shadow: var(--shadow);
  animation: toast-in .2s ease both;
}
.toast.error { border-color: rgba(255,147,142,.34); color: #ffd6d2; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

@media (min-width: 700px) {
  .app-shell { padding-inline: 28px; }
  .home-grid { grid-template-columns: 1fr 1fr; }
  .lobby-layout { grid-template-columns: .9fr 1.1fr; align-items: start; }
  .opponents { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .playing-card { flex-basis: 70px; width: 70px; height: 102px; }
  .hand { justify-content: center; }
  .game-actions { width: 430px; margin: 0 auto; }
}

@media (max-height: 690px) and (max-width: 699px) {
  .app-shell { padding-top: max(9px, env(safe-area-inset-top)); }
  .game-shell { gap: 6px; }
  .turn-banner { min-height: 36px; padding-block: 6px; font-size: .8rem; }
  .table-zone { min-height: 150px; }
  .playing-card { flex-basis: 52px; width: 52px; height: 76px; }
  .hand { min-height: 93px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
