/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f0e17;
  --surface: #1a1930;
  --surface2: #252440;
  --border: rgba(255,255,255,0.08);
  --text: #fffffe;
  --muted: #a7a9be;
  --accent: #f8c537;
  --blue: #3a7bd5;
  --blue-light: #5b9cf6;
  --red: #e05555;
  --red-light: #f07070;
  --green: #27ae60;
  --green-light: #44cc77;
  --valid: rgba(248,197,55,0.25);
  --valid-border: #f8c537;

  /* board cell suit colors */
  --spade-bg: #151f30;
  --heart-bg: #2a1010;
  --diamond-bg: #2a1a08;
  --club-bg: #0d2018;
  --wild-bg: #2a2400;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

/* ── Screens ── */
.screen { display: none; min-height: 100dvh; }
.screen.active { display: flex; align-items: center; justify-content: center; }

/* ── Welcome ── */
.welcome-card {
  width: 100%;
  max-width: 420px;
  padding: 2.5rem 2rem;
  margin: 1rem;
}

.logo {
  text-align: center;
  margin-bottom: 0.5rem;
  line-height: 1;
}
.logo-s {
  font-size: 4.5rem;
  font-weight: 900;
  color: var(--accent);
  text-shadow: 0 0 30px rgba(248,197,55,0.4);
  display: block;
  font-family: Georgia, serif;
}
.logo-eq {
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: 0.5em;
  color: var(--muted);
}

.tagline { text-align: center; color: var(--muted); font-size: 0.85rem; margin-bottom: 2rem; }

.field-label { display: block; font-size: 0.75rem; font-weight: 600; color: var(--muted); margin-bottom: 0.4rem; text-transform: uppercase; letter-spacing: 0.05em; }

.text-input {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 1rem;
  padding: 0.7rem 1rem;
  outline: none;
  transition: border-color 0.15s;
  margin-bottom: 1rem;
}
.text-input:focus { border-color: var(--accent); }
.text-input::placeholder { color: var(--muted); opacity: 0.6; }

.code-input { text-transform: uppercase; letter-spacing: 0.25em; font-weight: 700; font-size: 1.1rem; flex: 1; margin-bottom: 0; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 0.95rem; font-weight: 700; border: none; border-radius: 10px;
  padding: 0.75rem 1.5rem; cursor: pointer; transition: filter 0.15s, transform 0.1s;
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

.btn-primary { background: var(--accent); color: #0f0e17; width: 100%; }
.btn-primary:hover:not(:disabled) { filter: brightness(1.1); }

.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }

.btn-warn { background: var(--red); color: #fff; }
.btn-warn:hover:not(:disabled) { filter: brightness(1.1); }

.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); font-size: 0.85rem; padding: 0.5rem 1rem; }
.btn-ghost:hover { color: var(--text); border-color: rgba(255,255,255,0.3); }

.btn-icon { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 1rem; padding: 0.2rem 0.4rem; border-radius: 6px; }
.btn-icon:hover { color: var(--text); background: var(--surface2); }

/* ── Card (surface) ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}

/* ── Divider ── */
.divider {
  display: flex; align-items: center; gap: 0.75rem;
  margin: 1.25rem 0; color: var(--muted); font-size: 0.8rem;
}
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }

/* ── Join row ── */
.join-row { display: flex; gap: 0.5rem; align-items: center; }
.join-row .btn { flex-shrink: 0; }

/* ── Lobby ── */
.screen#screen-lobby { background: var(--bg); }
.lobby-card {
  width: 100%; max-width: 460px;
  padding: 2rem;
  margin: 1rem;
}
.lobby-card h2 { font-size: 1.4rem; margin-bottom: 1rem; }

.room-badge {
  display: flex; align-items: center; gap: 0.5rem;
  background: var(--surface2); border-radius: 10px;
  padding: 0.6rem 1rem; margin-bottom: 0.5rem;
  font-size: 0.9rem; color: var(--muted);
}
.room-badge strong { font-size: 1.2rem; letter-spacing: 0.2em; color: var(--accent); }

.lobby-hint { font-size: 0.8rem; color: var(--muted); margin-bottom: 1.25rem; }

.player-list { display: flex; flex-direction: column; gap: 0.5rem; margin-bottom: 1rem; }

.player-item {
  display: flex; align-items: center; gap: 0.75rem;
  background: var(--surface2); border-radius: 10px;
  padding: 0.6rem 1rem; font-size: 0.9rem;
}
.player-item .player-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.player-item .badge { margin-left: auto; font-size: 0.7rem; font-weight: 700; color: var(--accent); }

.team-preview { margin-bottom: 1rem; }
.team-row { display: flex; gap: 0.4rem; align-items: center; margin-bottom: 0.3rem; font-size: 0.8rem; color: var(--muted); }
.team-chip-mini { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }

.muted { color: var(--muted); font-size: 0.85rem; text-align: center; margin-top: 0.75rem; }

/* ── Game Layout ── */
#screen-game { display: none; flex-direction: column; align-items: stretch; padding: 0; }
#screen-game.active { display: flex; }

#game-layout {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

/* Top bar */
#top-bar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.4rem 0.75rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  gap: 0.5rem;
  min-height: 48px;
}

#players-strip {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  flex: 1;
}

.player-pill {
  display: flex; align-items: center; gap: 0.3rem;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  font-size: 0.72rem; font-weight: 600;
  border: 1.5px solid transparent;
  background: var(--surface2);
  transition: all 0.2s;
}
.player-pill.active-turn {
  border-color: var(--accent);
  background: rgba(248,197,55,0.1);
}
.player-pill .pp-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.player-pill .pp-seqs { font-size: 0.65rem; color: var(--muted); }

#game-meta {
  display: flex; flex-direction: column; align-items: flex-end;
  font-size: 0.7rem; color: var(--muted); gap: 0.1rem; flex-shrink: 0;
}

/* Board area */
#board-wrap {
  flex: 1;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem;
  -webkit-overflow-scrolling: touch;
}

#game-board {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 2px;
  width: min(calc(100vw - 1rem), calc(100dvh - 200px));
  aspect-ratio: 1;
  flex-shrink: 0;
}

/* Board cells */
.bc {
  aspect-ratio: 0.7;
  border-radius: 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.07);
  font-size: clamp(0.45rem, 1.5vw, 0.65rem);
  transition: filter 0.1s;
  user-select: none;
}
.bc:active { filter: brightness(1.3); }

.bc.cell-spade   { background: var(--spade-bg); }
.bc.cell-heart   { background: var(--heart-bg); }
.bc.cell-diamond { background: var(--diamond-bg); }
.bc.cell-club    { background: var(--club-bg); }
.bc.cell-wild    { background: var(--wild-bg); }

.bc .cr { font-weight: 800; line-height: 1; }
.bc .cs { line-height: 1; opacity: 0.9; }

/* Suit text colors */
.bc.cell-spade   .cs { color: #7ab0e8; }
.bc.cell-heart   .cs { color: #e87a7a; }
.bc.cell-diamond .cs { color: #e8a87a; }
.bc.cell-club    .cs { color: #7ae89a; }
.bc.cell-wild    .cs { color: var(--accent); font-size: 1.3em; }

.bc.cell-spade   .cr { color: #aaccee; }
.bc.cell-heart   .cr { color: #eeaaaa; }
.bc.cell-diamond .cr { color: #eeccaa; }
.bc.cell-club    .cr { color: #aaeebb; }

/* Chip on board */
.chip {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.chip::after {
  content: '';
  width: 70%;
  aspect-ratio: 1;
  border-radius: 50%;
  box-shadow: inset 0 2px 4px rgba(255,255,255,0.25), 0 1px 3px rgba(0,0,0,0.5);
}
.chip-blue::after   { background: radial-gradient(circle at 35% 30%, #7ab6ff, #1a55c0); }
.chip-red::after    { background: radial-gradient(circle at 35% 30%, #ff8080, #b01a1a); }
.chip-green::after  { background: radial-gradient(circle at 35% 30%, #80ff90, #1a8030); }
.chip-wild::after   { background: radial-gradient(circle at 35% 30%, #ffe788, #b08800); opacity: 0.6; }

/* In-sequence glow */
.bc.in-seq {
  box-shadow: inset 0 0 0 2px var(--accent);
  filter: brightness(1.1);
}

/* Valid move highlight */
.bc.valid-move {
  box-shadow: inset 0 0 0 2px var(--valid-border);
  background-color: var(--valid) !important;
  cursor: pointer;
}
.bc.valid-move:hover { filter: brightness(1.3); }

/* Last action highlight */
.bc.last-action {
  animation: pulse 0.8s ease-out;
}
@keyframes pulse {
  0%  { filter: brightness(2.5); }
  100%{ filter: brightness(1); }
}

/* ── Bottom bar ── */
#bottom-bar {
  flex-shrink: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 0.5rem 0.75rem;
}

#turn-banner {
  font-size: 0.8rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 0.4rem;
  min-height: 1.2em;
}

#player-hand {
  display: flex;
  gap: 0.35rem;
  justify-content: center;
  overflow-x: auto;
  padding: 0.25rem 0;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
#player-hand::-webkit-scrollbar { display: none; }

/* Hand cards */
.hcard {
  flex-shrink: 0;
  width: clamp(38px, 10vw, 52px);
  aspect-ratio: 0.68;
  background: #fff;
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border: 2px solid transparent;
  box-shadow: 0 2px 6px rgba(0,0,0,0.5);
  transition: transform 0.15s, border-color 0.15s;
  position: relative;
  overflow: hidden;
}
.hcard:hover { transform: translateY(-4px); }
.hcard.selected {
  transform: translateY(-10px);
  border-color: var(--accent);
  box-shadow: 0 4px 16px rgba(248,197,55,0.5);
}
.hcard.dead-card { opacity: 0.5; border-color: var(--red); }

.hcard .hr { font-size: clamp(0.7rem, 2.5vw, 0.9rem); font-weight: 900; line-height: 1; color: #111; }
.hcard .hs { font-size: clamp(0.8rem, 3vw, 1rem); line-height: 1; }
.hcard.hs-spade   .hs { color: #1a1a2a; }
.hcard.hs-heart   .hs { color: #cc1a1a; }
.hcard.hs-diamond .hs { color: #cc6600; }
.hcard.hs-club    .hs { color: #1a4a1a; }

/* Jack badges */
.jack-badge {
  position: absolute;
  top: 1px; right: 2px;
  font-size: 0.5rem;
  font-weight: 900;
  line-height: 1;
}
.jack-badge.one-eye { color: var(--red); }
.jack-badge.two-eye { color: var(--green); }

/* Dead indicator on card */
.hcard .dead-x {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(200,0,0,0.15);
  font-size: 1.5rem;
  color: var(--red);
  font-weight: 900;
}

#hand-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 0.4rem;
  min-height: 2rem;
}

#action-hint { font-size: 0.75rem; color: var(--muted); }

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #333;
  color: #fff;
  padding: 0.6rem 1.25rem;
  border-radius: 99px;
  font-size: 0.85rem;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 1000;
  white-space: nowrap;
  max-width: 90vw;
  text-align: center;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.error { background: #7a1a1a; }
.toast.success { background: #1a5a2a; }

/* ── Overlay / Modal ── */
.overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.75);
  display: flex; align-items: center; justify-content: center;
  z-index: 500;
  backdrop-filter: blur(4px);
}
.overlay.hidden { display: none; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 2.5rem 2rem;
  max-width: 400px;
  width: 90%;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}
.modal-icon { font-size: 3.5rem; margin-bottom: 0.75rem; }
.modal h2 { font-size: 1.6rem; margin-bottom: 0.5rem; }
.modal p { color: var(--muted); margin-bottom: 1.5rem; font-size: 0.9rem; }
.modal-actions { display: flex; gap: 0.75rem; justify-content: center; }

/* ── Team colors ── */
.team-blue   { color: var(--blue-light); }
.team-red    { color: var(--red-light); }
.team-green  { color: var(--green-light); }
.bg-blue     { background: var(--blue); }
.bg-red      { background: var(--red); }
.bg-green    { background: var(--green); }

/* ── Utility ── */
.hidden { display: none !important; }

/* ── Desktop tweaks ── */
@media (min-width: 768px) {
  #game-board {
    width: min(calc(100vh - 220px), 600px);
  }
}
