/* ═══════════════════════════════════════════════════
   TRUCIZNA – arkusz stylów
   Paleta: ciemny motyw, akcenty czerwień/niebieski/fiolet
   Stosy: RED · BLUE · VIOLET   |   Trucizna: GREEN (karta ☠)
   ═══════════════════════════════════════════════════ */

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

:root {
  --bg:          #0f172a;
  --surface:     #1e293b;
  --surface2:    #273448;
  --border:      #334155;
  --text:        #e2e8f0;
  --muted:       #94a3b8;
  --accent:      #e94560;
  --red:         #ef4444;
  --blue:        #3b82f6;
  --violet:      #7c3aed;
  --poison-green:#16a34a;
  --warning:     #f59e0b;
  --gold:        #fbbf24;
  --silver:      #94a3b8;
  --bronze:      #c2734a;
  --radius:      10px;
  --shadow:      0 4px 24px rgba(0,0,0,.45);
}

html { font-size: 16px; }
body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding: 16px;
}
#app { width: 100%; max-width: 960px; }

/* ── Login screen ─────────────────────────────────── */
#login-screen {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
}
.login-box {
  background: var(--surface);
  border-radius: 16px;
  padding: 48px 40px;
  text-align: center;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 320px;
  max-width: 400px;
  width: 100%;
}
.login-box h1 { font-size: 2.8rem; color: var(--accent); }
.subtitle { color: var(--muted); font-size: .85rem; }
.error-msg { color: var(--red); font-size: .85rem; min-height: 1.2em; }

/* ── Inputs & buttons ─────────────────────────────── */
input[type="text"] {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 12px 16px;
  font-size: 1rem;
  outline: none;
  transition: border-color .2s;
  width: 100%;
}
input[type="text"]:focus { border-color: var(--accent); }

button {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 12px 28px;
  font-size: 1rem;
  cursor: pointer;
  transition: background .2s, transform .1s;
  min-height: 46px;   /* touch-friendly */
  touch-action: manipulation;
}
button:hover  { background: #c73652; }
button:active { transform: scale(.97); }
button:disabled { background: var(--border); cursor: not-allowed; }

/* ── Game screen layout ───────────────────────────── */
#game-screen { display: flex; flex-direction: column; gap: 20px; padding-bottom: 48px; }

header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  background: var(--surface);
  border-radius: var(--radius);
  border-left: 4px solid var(--accent);
  flex-wrap: wrap;
}
#game-title { font-size: 1.4rem; font-weight: 700; color: var(--accent); }

.badge {
  padding: 3px 10px;
  border-radius: 20px;
  font-size: .75rem;
  font-weight: 600;
  background: var(--surface2);
}
#round-badge  { color: var(--warning); }
#phase-badge  { color: var(--muted); }

/* ── Status bar ───────────────────────────────────── */
#status-bar {
  padding: 12px 20px;
  background: var(--surface);
  border-radius: var(--radius);
  font-style: italic;
  color: var(--blue);
  text-align: center;
  border: 1px solid var(--border);
  transition: color .3s, border-color .3s;
}
#status-bar.my-turn      { color: var(--warning); border-color: var(--warning); font-style: normal; font-weight: 600; }
#status-bar.error        { color: var(--red); border-color: var(--red); }
#status-bar.round-summary{ color: var(--violet); border-color: var(--violet); font-style: normal; font-weight: 600; }
#status-bar.game-over    { color: var(--gold); border-color: var(--gold); font-style: normal; font-weight: 700; font-size: 1.05rem; }

/* ── Section headings ─────────────────────────────── */
section { background: var(--surface); border-radius: var(--radius); padding: 16px 20px; }
section h2 { font-size: .95rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: 14px; }
section h2 small { font-size: .75rem; text-transform: none; letter-spacing: 0; }
section h3 { font-size: .85rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 18px 0 10px; }

/* ── Players ──────────────────────────────────────── */
#players-area {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}
.player-card {
  background: var(--surface2);
  border-radius: var(--radius);
  padding: 12px 16px;
  min-width: 150px;
  border: 2px solid transparent;
  transition: border-color .25s, box-shadow .25s;
}
.player-card.current-player {
  border-color: var(--warning);
  box-shadow: 0 0 14px rgba(245,158,11,.35);
}
.player-card.me { border-color: var(--blue); }
.player-card.current-player.me {
  border-color: var(--poison-green);
  box-shadow: 0 0 14px rgba(22,163,74,.35);
}

.p-name        { font-weight: 700; font-size: 1rem; margin-bottom: 4px; }
.p-score       { color: var(--muted); font-size: .8rem; }
.p-hand        { color: var(--blue); font-size: .8rem; margin-top: 2px; }
.p-turn-arrow  { color: var(--warning); font-size: .8rem; margin-top: 4px; }
.p-immune      { font-size: .75rem; margin-top: 4px; font-weight: 600; }
.p-poison      { font-size: .75rem; margin-top: 2px; color: var(--poison-green); }
.p-immune-RED    { color: var(--red);    }
.p-immune-BLUE   { color: var(--blue);   }
.p-immune-VIOLET { color: var(--violet); }

/* ── Piles ────────────────────────────────────────── */
#piles-area { display: flex; gap: 16px; }

.pile {
  flex: 1;
  min-height: 120px;
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  background: var(--surface2);
  border: 2px solid var(--border);
  cursor: pointer;
  user-select: none;
  transition: transform .2s, box-shadow .2s, border-color .2s;
  position: relative;
  touch-action: manipulation;
}
.pile:hover            { transform: translateY(-4px); box-shadow: var(--shadow); }
.pile.pile-selected    { border-color: #facc15 !important; box-shadow: 0 0 18px rgba(250,204,21,.45); }

.pile-RED    { border-top: 4px solid var(--red);    }
.pile-BLUE   { border-top: 4px solid var(--blue);   }
.pile-VIOLET { border-top: 4px solid var(--violet); }

.pile-color-label { font-size: .7rem; font-weight: 700; letter-spacing: .1em; color: var(--muted); margin-bottom: 6px; }
.pile-RED    .pile-color-label { color: var(--red);    }
.pile-BLUE   .pile-color-label { color: var(--blue);   }
.pile-VIOLET .pile-color-label { color: var(--violet); }

.pile-sum   { font-size: 2rem; font-weight: 800; line-height: 1.1; }
.pile-limit { font-size: 1rem; color: var(--muted); font-weight: 400; }
.pile-count { font-size: .8rem; color: var(--muted); margin-top: 4px; }

/* Wskaźnik trucizn na stosie */
.pile-poison {
  font-size: .75rem;
  font-weight: 700;
  color: var(--poison-green);
  margin-top: 6px;
  background: rgba(22,163,74,.15);
  border-radius: 6px;
  padding: 2px 6px;
  display: inline-block;
}

/* Danger gdy suma ≥ 10 */
.pile.danger .pile-sum { color: var(--red); }
.pile.danger::after {
  content: '⚠';
  position: absolute;
  top: 8px; right: 8px;
  color: var(--red);
  font-size: .85rem;
}

/* ── Hand ─────────────────────────────────────────── */
#hand-hint { color: var(--muted); font-size: .75rem; font-weight: 400; }
#hand-cards {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  min-height: 110px;
  align-items: flex-end;
}

.card {
  width: 68px;
  height: 96px;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  font-weight: 800;
  font-size: 1.7rem;
  cursor: pointer;
  border: 3px solid transparent;
  user-select: none;
  transition: transform .2s, box-shadow .2s, border-color .2s;
  position: relative;
  touch-action: manipulation;
}
.card:hover   { transform: translateY(-10px); box-shadow: 0 10px 24px rgba(0,0,0,.5); }
.card.selected {
  border-color: #facc15;
  transform: translateY(-10px);
  box-shadow: 0 0 20px rgba(250,204,21,.5);
}

/* Kolory zwykłych kart */
.card-RED    { background: linear-gradient(145deg, #991b1b, #ef4444); color: #fff; }
.card-BLUE   { background: linear-gradient(145deg, #1d4ed8, #3b82f6); color: #fff; }
.card-VIOLET { background: linear-gradient(145deg, #4c1d95, #7c3aed); color: #fff; }

/* Trucizna (GREEN) */
.card-GREEN  { background: linear-gradient(145deg, #14532d, #16a34a); color: #fff; }
.card.poison { background: linear-gradient(145deg, #14532d, #16a34a) !important; }

.card-label { font-size: .6rem; font-weight: 600; letter-spacing: .05em; margin-top: 2px; opacity: .85; }
.card-sub   { font-size: .7rem; color: rgba(255,255,255,.7); margin-top: 1px; }
.card-value { line-height: 1; }

.card.not-my-turn { opacity: .5; cursor: not-allowed; }
.card.not-my-turn:hover { transform: none; box-shadow: none; }

/* ── Action area ──────────────────────────────────── */
#action-area { text-align: center; display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
#start-btn     { font-size: 1.1rem; padding: 14px 40px; }
#next-round-btn {
  font-size: 1.1rem;
  padding: 14px 40px;
  background: var(--violet);
}
#next-round-btn:hover { background: #5b21b6; }

/* ── Summary & Results tables ─────────────────────── */
.summary-table,
.results-table,
.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .85rem;
  margin-top: 4px;
  overflow-x: auto;
}

.summary-table th,
.results-table th,
.history-table th {
  padding: 8px 10px;
  text-align: left;
  color: var(--muted);
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  border-bottom: 1px solid var(--border);
}

.summary-table td,
.results-table td,
.history-table td {
  padding: 9px 10px;
  border-bottom: 1px solid rgba(255,255,255,.05);
}

.summary-table tr:last-child td,
.results-table tr:last-child td,
.history-table tr:last-child td { border-bottom: none; }

.summary-table tr:hover td,
.results-table  tr:hover td     { background: rgba(255,255,255,.04); }

/* Kolorowe wiersze wyników */
.row-gold   td { background: rgba(251,191,36,.10); }
.row-silver td { background: rgba(148,163,184,.10); }
.row-bronze td { background: rgba(194,115,74,.10); }
.row-me     td { outline: 1px solid var(--blue); }
.row-totals td { font-weight: 700; border-top: 2px solid var(--border); }

.td-center   { text-align: center; }
.td-name     { font-weight: 600; }
.td-medal    { font-size: 1.1rem; }
.td-score    { color: var(--warning); font-weight: 600; }
.td-total    { color: var(--text); font-weight: 700; }
.td-poison   { color: var(--poison-green); }
.td-score-sm { color: var(--muted); font-size: .8rem; }
.td-round    { color: var(--muted); font-size: .8rem; font-weight: 600; }

/* Odznaki immunizacji w tabeli */
.immune-badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: .72rem;
  font-weight: 600;
}
.immune-RED    { background: rgba(239,68,68,.2);  color: var(--red);    }
.immune-BLUE   { background: rgba(59,130,246,.2); color: var(--blue);   }
.immune-VIOLET { background: rgba(124,58,237,.2); color: var(--violet); }

.immune-dot { font-size: .8rem; }

.history-title {
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--muted);
  margin: 20px 0 8px;
  border-top: 1px solid var(--border);
  padding-top: 16px;
}

/* ── Log ──────────────────────────────────────────── */
#log-entries {
  background: var(--surface2);
  border-radius: 8px;
  padding: 12px;
  max-height: 200px;
  overflow-y: auto;
  font-size: .82rem;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.log-entry {
  padding: 3px 0;
  border-bottom: 1px solid rgba(255,255,255,.05);
  color: var(--muted);
  white-space: pre-wrap;
}
.log-entry.log-bust  { color: var(--red); }
.log-entry.log-round { color: var(--warning); font-weight: 600; }

/* ── Footer ───────────────────────────────────────── */
.site-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  text-align: center;
  padding: 6px 0;
  font-size: .72rem;
  color: #334155;
  letter-spacing: .04em;
  pointer-events: none;   /* nie blokuje kliknięć na grę */
}
.site-footer a {
  color: #475569;
  text-decoration: none;
  transition: color .2s;
  pointer-events: auto;   /* ale sam link klikalny */
}
.site-footer a:hover { color: var(--accent); }

/* ── Ghost button (secondary) ─────────────────────── */
.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover {
  background: var(--surface2);
  color: var(--text);
}

/* ── Reconnect overlay ────────────────────────────── */
#reconnect-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .85);
  backdrop-filter: blur(4px);
  z-index: 9999;
  display: flex;
  justify-content: center;
  align-items: center;
}
.reconnect-box {
  background: var(--surface);
  border-radius: 16px;
  padding: 40px 36px;
  text-align: center;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  min-width: 260px;
  max-width: 360px;
  border: 1px solid var(--border);
}
.reconnect-spinner {
  font-size: 2.4rem;
  color: var(--blue);
  animation: spin 1.2s linear infinite;
  display: inline-block;
}
@keyframes spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}
.reconnect-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
}
.reconnect-sub {
  font-size: .85rem;
  color: var(--muted);
}

/* ── Room selection screen ────────────────────────── */
#room-screen {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding-top: 60px;
  min-height: 100vh;
}
.room-box {
  background: var(--surface);
  border-radius: 16px;
  padding: 36px 32px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 20px;
  width: 100%;
  max-width: 600px;
}
.room-header {
  text-align: center;
}
.room-header h1 { font-size: 2.4rem; color: var(--accent); }
.room-header .subtitle { color: var(--muted); font-size: .85rem; margin-top: 4px; }

/* Wiersz tworzenia nowego stołu */
.create-room-row {
  display: flex;
  gap: 10px;
}
.create-room-row input { flex: 1; }
#create-room-btn {
  white-space: nowrap;
  padding: 12px 20px;
  font-size: .95rem;
}

/* ── Room list ────────────────────────────────────── */
#room-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.room-loading {
  text-align: center;
  color: var(--muted);
  font-style: italic;
  padding: 24px 0;
  font-size: .9rem;
}
.room-empty {
  text-align: center;
  color: var(--muted);
  padding: 24px 0;
  font-size: .9rem;
}

/* ── Room card ────────────────────────────────────── */
.room-card {
  background: var(--surface2);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  transition: border-color .2s, box-shadow .2s;
}
.room-card.room-joinable {
  border-color: var(--poison-green);
  cursor: pointer;
}
.room-card.room-joinable:hover {
  box-shadow: 0 0 14px rgba(22,163,74,.25);
}

.room-card-left { flex: 1; min-width: 0; }
.room-card-right { flex-shrink: 0; }

.room-card-name {
  font-weight: 700;
  font-size: 1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 5px;
}
.room-card-meta {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.rc-players {
  font-size: .78rem;
  color: var(--muted);
}
.rc-phase {
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .06em;
  padding: 2px 8px;
  border-radius: 20px;
  background: var(--surface);
}
.rc-phase-LOBBY        { color: var(--blue);         background: rgba(59,130,246,.15);  }
.rc-phase-PLAYING      { color: var(--poison-green); background: rgba(22,163,74,.15);   }
.rc-phase-ROUND_SUMMARY{ color: var(--warning);      background: rgba(245,158,11,.15);  }
.rc-phase-GAME_OVER    { color: var(--muted);        background: rgba(148,163,184,.10); }

.join-btn {
  background: var(--poison-green);
  padding: 10px 20px;
  font-size: .9rem;
  min-height: 40px;
}
.join-btn:hover { background: #15803d; }

.room-in-progress {
  font-size: .8rem;
  color: var(--muted);
  font-style: italic;
}

/* ── Room name badge in header ────────────────────── */
.badge-room {
  color: var(--poison-green);
  background: rgba(22,163,74,.15);
  border: 1px solid rgba(22,163,74,.3);
  max-width: 220px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Leave room button ────────────────────────────── */
#leave-room-btn {
  padding: 10px 20px;
  font-size: .9rem;
}

/* ── Offline player ───────────────────────────────── */
.player-card.offline {
  opacity: .5;
  filter: grayscale(.4);
}
.p-offline {
  font-size: .72rem;
  color: var(--muted);
  margin-top: 4px;
  font-style: italic;
}

/* ── Responsive / Mobile ──────────────────────────── */
@media (max-width: 640px) {
  body { padding: 10px; }

  #piles-area {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 8px;
  }
  .pile { min-height: 90px; padding: 10px 6px; }
  .pile-sum { font-size: 1.5rem; }

  #players-area .player-card { min-width: 130px; flex: 1; }

  #hand-cards { gap: 6px; }
  .card {
    width: 60px;
    height: 84px;
    font-size: 1.4rem;
  }

  .summary-table,
  .results-table,
  .history-table {
    font-size: .78rem;
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .summary-table th,
  .results-table th,
  .history-table th,
  .summary-table td,
  .results-table td,
  .history-table td { padding: 6px 7px; }

  #next-round-btn,
  #start-btn { width: 100%; }

  /* Room screen mobile */
  #room-screen { padding-top: 20px; align-items: flex-start; }
  .room-box { padding: 24px 16px; border-radius: 12px; }
  .create-room-row { flex-direction: column; }
  #create-room-btn { width: 100%; }
  .room-card { flex-direction: column; align-items: flex-start; gap: 10px; }
  .room-card-right { width: 100%; }
  .join-btn { width: 100%; }

  /* Reconnect overlay mobile */
  .reconnect-box { padding: 30px 20px; min-width: 0; margin: 16px; }
}

@media (max-width: 400px) {
  .card { width: 52px; height: 76px; font-size: 1.2rem; }
  .card-label { font-size: .55rem; }
}
