:root {
  --felt: #123528;
  --felt-dark: #0b2018;
  --felt-vignette: radial-gradient(120% 120% at 50% -10%, #1c4a37 0%, #123528 45%, #0b2018 100%);
  --cream: #F2EFE6;
  --cream-dim: #B9C4B7;
  --ink: #0D1B15;
  --gold: #E0B24A;
  --gold-dim: #a9843b;
  --panel: rgba(12, 34, 25, 0.72);
  --panel-border: rgba(242, 239, 230, 0.12);
  --danger: #C1493D;

  --card-neg: #3B5BA5;
  --card-zero: #2F8FA6;
  --card-low: #3E8E52;
  --card-mid: #C99433;
  --card-high: #B3392E;
  --card-back: #0F2921;

  --font-display: 'Fredoka', system-ui, sans-serif;
  --font-body: 'Inter', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--felt-vignette);
  background-color: var(--felt);
  color: var(--cream);
  font-family: var(--font-body);
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: radial-gradient(rgba(255,255,255,0.035) 1px, transparent 1px);
  background-size: 22px 22px;
  z-index: 0;
}

.app {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px 14px 40px;
}

h1, h2, h3 { font-family: var(--font-display); font-weight: 600; margin: 0; }

.logo {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(2.2rem, 6vw, 3.2rem);
  letter-spacing: 0.5px;
  color: var(--gold);
  text-shadow: 0 2px 0 rgba(0,0,0,0.35);
  margin-bottom: 4px;
}
.tagline { color: var(--cream-dim); margin-bottom: 28px; font-size: 0.95rem; text-align: center; }

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 18px;
  padding: 24px;
  width: 100%;
  max-width: 480px;
  backdrop-filter: blur(6px);
  box-shadow: 0 10px 30px rgba(0,0,0,0.25);
}

.field { margin: 16px 0; }
.field label { display: block; font-size: 0.85rem; color: var(--cream-dim); margin-bottom: 6px; }
input[type="text"], input[type="password"], input[type="number"] {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--panel-border);
  background: rgba(255,255,255,0.06);
  color: var(--cream);
  font-family: var(--font-body);
  font-size: 1rem;
}
input:focus { outline: 2px solid var(--gold); outline-offset: 1px; }

button {
  font-family: var(--font-body);
  font-weight: 600;
  border: none;
  border-radius: 10px;
  padding: 12px 18px;
  cursor: pointer;
  font-size: 0.95rem;
  transition: transform 0.08s ease, filter 0.15s ease;
}
button:active { transform: scale(0.97); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--gold); color: var(--ink); }
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn-secondary { background: rgba(255,255,255,0.1); color: var(--cream); }
.btn-secondary:hover:not(:disabled) { background: rgba(255,255,255,0.16); }
.btn-danger { background: var(--danger); color: var(--cream); }
.btn-block { width: 100%; }
.btn-row { display: flex; gap: 10px; margin-top: 8px; }

.lobby-list { list-style: none; padding: 0; margin: 16px 0; display: flex; flex-direction: column; gap: 8px; }
.lobby-list li {
  display: flex; align-items: center; justify-content: space-between;
  background: rgba(255,255,255,0.05); padding: 10px 14px; border-radius: 10px;
}
.pill { font-family: var(--font-mono); font-size: 0.75rem; color: var(--cream-dim); }
.host-badge { color: var(--gold); font-size: 0.75rem; font-family: var(--font-mono); }

.board {
  width: 100%;
  max-width: 980px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.board-top {
  display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px;
}
.turn-banner {
  font-family: var(--font-display);
  font-size: 1.1rem;
  padding: 8px 16px;
  border-radius: 999px;
  background: rgba(224,178,74,0.14);
  border: 1px solid rgba(224,178,74,0.4);
}
.turn-banner.you { background: var(--gold); color: var(--ink); }

.piles {
  display: flex; justify-content: center; align-items: center; gap: 28px;
  padding: 18px 0;
}
.pile-stack { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.pile-label { font-size: 0.75rem; color: var(--cream-dim); font-family: var(--font-mono); text-transform: uppercase; letter-spacing: 1px; }

.card {
  width: 58px; height: 82px;
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.5rem;
  color: var(--cream);
  box-shadow: 0 3px 0 rgba(0,0,0,0.25), 0 6px 12px rgba(0,0,0,0.25);
  border: 1px solid rgba(255,255,255,0.15);
  user-select: none;
  position: relative;
}
.card.clickable { cursor: pointer; transition: transform 0.12s ease; }
.card.clickable:hover { transform: translateY(-4px); }
.card.hidden { background: var(--card-back); background-image: repeating-linear-gradient(45deg, rgba(255,255,255,0.03) 0 8px, transparent 8px 16px); color: transparent; }
.card.cleared { opacity: 0.35; filter: grayscale(0.6); box-shadow: none; }
.card.empty { background: transparent; border: 2px dashed rgba(255,255,255,0.15); box-shadow: none; }
.card.mini { width: 42px; height: 60px; font-size: 1.05rem; border-radius: 7px; }

.v-neg { background: var(--card-neg); }
.v-zero { background: var(--card-zero); }
.v-low { background: var(--card-low); }
.v-mid { background: var(--card-mid); }
.v-high { background: var(--card-high); }

.drawn-card-zone {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.drawn-card-zone .card { box-shadow: 0 0 0 3px var(--gold), 0 6px 14px rgba(0,0,0,0.35); }

.players-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px;
}
.player-card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  padding: 14px;
}
.player-card.active { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold) inset; }
.player-card.you { background: rgba(224,178,74,0.08); }
.player-head {
  display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px;
}
.player-name { font-weight: 600; font-family: var(--font-display); }
.player-score { font-family: var(--font-mono); color: var(--gold); font-size: 0.9rem; }
.offline-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--danger); margin-left: 6px; }

.grid-4x3 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}
.grid-4x3 .card { width: 100%; height: 58px; font-size: 1.15rem; }

.actions-bar {
  display: flex; gap: 10px; justify-content: center; flex-wrap: wrap;
  padding: 10px 0 4px;
}
.hint { text-align: center; color: var(--cream-dim); font-size: 0.85rem; min-height: 1.2em; }

.scoreboard { width: 100%; max-width: 520px; }
.score-table { width: 100%; border-collapse: collapse; margin: 14px 0; font-family: var(--font-mono); }
.score-table th, .score-table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--panel-border); }
.score-table th { color: var(--cream-dim); font-weight: 500; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.5px; }
.winner-row { color: var(--gold); font-weight: 700; }

.log-box {
  width: 100%; max-width: 980px; margin-top: 6px;
  font-family: var(--font-mono); font-size: 0.78rem; color: var(--cream-dim);
  display: flex; flex-direction: column; gap: 3px;
}

.toast {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--danger); color: var(--cream);
  padding: 10px 18px; border-radius: 10px;
  font-size: 0.9rem; opacity: 0; pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 50; max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.footer-link { margin-top: 24px; font-size: 0.8rem; }
.footer-link a { color: var(--cream-dim); }

@media (max-width: 520px) {
  .card { width: 48px; height: 68px; font-size: 1.2rem; }
  .grid-4x3 .card { height: 50px; font-size: 1rem; }
}
