/* ================================================================
   ANIMAL FARM — style.css
   ================================================================ */

/* ---------- ZMIENNE ---------- */
:root {
  --bg: #0d1b2e;
  --surface: #132340;
  --card: #1a2f52;
  --card-hover: #243d66;
  --border: #2a4880;
  --text: #e0eeff;
  --text-muted: #7a9cc8;
  --accent: #f4c430;
  --accent2: #ff9800;
  --danger: #e53935;
  --success: #29b6f6;
  --blue: #1976d2;
  --radius: 12px;
  --shadow: 0 4px 20px rgba(0,0,0,.55);
  --transition: .22s ease;

  /* kolory graczy */
  --c0: #2196F3;
  --c1: #F44336;
  --c2: #4CAF50;
  --c3: #FFC107;
  --c4: #FF9800;
  --c5: #9C27B0;
}

/* ---------- RESET / BASE ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
}

a { color: var(--accent); }
h1 { font-size: 2.2rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.2rem; }
h4 { font-size: 1rem; font-weight: 600; }

.hidden { display: none !important; }
.mt-1 { margin-top: 1rem; }

/* ---------- EKRANY ---------- */
.screen {
  display: none;
  min-height: 100dvh;
  animation: fadeIn .2s ease;
}
.screen.active { display: flex; flex-direction: column; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.center-box {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
  text-align: center;
  gap: 1rem;
}
.center-box > * { width: 100%; max-width: 480px; text-align: left; }
.center-box > h1, .center-box > h2, .center-box > p, .center-box > .logo, .center-box > .screen-top { text-align: center; }

.screen-inner {
  flex: 1;
  max-width: 560px;
  width: 100%;
  margin: 0 auto;
  padding: 1.5rem 1rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.screen-top {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin-bottom: .5rem;
}
.screen-top h2 { flex: 1; }

/* ---------- LOGO ---------- */
.logo { font-size: 5rem; line-height: 1; }
.subtitle { color: var(--text-muted); font-size: 1.05rem; margin-top: -.5rem; }
.win-trophy { font-size: 5rem; }

.start-stats {
  max-width: 320px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .9rem 1rem;
  text-align: center !important;
}
.start-stats-label {
  font-size: .78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-muted);
}
.start-stats-value {
  font-size: 2rem;
  line-height: 1.1;
  font-weight: 700;
  color: var(--accent);
  margin-top: .2rem;
}
.start-stats-hint {
  margin-top: .35rem;
  font-size: .82rem;
  color: var(--text-muted);
}
.start-stats-hint:empty {
  display: none;
}
.start-stats.is-loading .start-stats-value,
.start-stats.is-unavailable .start-stats-value {
  color: var(--text);
  font-size: 1.3rem;
}

/* ---------- FORM ---------- */
.form-group { display: flex; flex-direction: column; gap: .35rem; }
.field-label { font-size: .9rem; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }

input[type=text], select {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: .55rem .8rem;
  font-size: 1rem;
  outline: none;
  transition: border-color var(--transition);
  width: 100%;
}
input[type=text]:focus, select:focus { border-color: var(--accent); }
select { appearance: auto; cursor: pointer; }

/* ---------- BUTTONS ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  padding: .55rem 1.2rem;
  border-radius: 8px;
  border: none;
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  transition: filter var(--transition), transform var(--transition), opacity var(--transition);
  text-align: center;
}
.btn:active { transform: scale(.96); }
.btn:disabled { opacity: .4; cursor: not-allowed; transform: none; }
.btn:not(:disabled):hover { filter: brightness(1.15); }

.btn-primary  { background: var(--accent); color: #1a1a00; }
.btn-secondary{ background: var(--blue);   color: #fff; }
.btn-outline  { background: transparent; border: 2px solid var(--border); color: var(--text); }
.btn-danger   { background: var(--danger); color: #fff; }
.btn-back     { background: transparent; color: var(--text-muted); padding: .4rem .7rem; font-size: .9rem; border: 1px solid var(--border); border-radius: 8px; }
.btn-close    { background: transparent; border: none; color: var(--text-muted); font-size: 1.3rem; cursor: pointer; line-height: 1; padding: .2rem .5rem; }
.btn-close:hover { color: var(--text); }
.btn-sm       { padding: .3rem .7rem; font-size: .82rem; }
.btn-lg       { padding: .75rem 2rem; font-size: 1.05rem; border-radius: 10px; }

.btn-stack { display: flex; flex-direction: column; gap: .75rem; width: 100%; max-width: 320px; }
.btn-trade { background: #3a7bd5; color: #fff; }
.btn-roll  { background: var(--accent2); color: #fff; font-size: 1.1rem; padding: .7rem 1.8rem; }

.hint { color: var(--text-muted); font-size: .88rem; }

/* ---------- PLAYER SETUP ---------- */
#player-setup-list { display: flex; flex-direction: column; gap: .6rem; }

.player-setup-row {
  display: flex;
  align-items: center;
  gap: .6rem;
  background: var(--card);
  border-radius: 10px;
  padding: .5rem .75rem;
}
.player-setup-row .color-dot {
  width: 20px; height: 20px;
  border-radius: 50%;
  flex-shrink: 0;
}
.player-setup-row input { flex: 1; min-width: 0; }
.type-toggle {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: .25rem .5rem;
  font-size: .8rem;
  cursor: pointer;
  color: var(--text-muted);
  transition: all var(--transition);
  white-space: nowrap;
}
.type-toggle.ai { background: #3a3060; border-color: #7b5ea7; color: #c4a0f0; }

/* ---------- LOBBY ---------- */
#lobby-panel {
  display: flex;
  flex-direction: column;
  gap: .75rem;
  margin-top: .25rem;
}
.lobby-code-box {
  display: flex;
  align-items: center;
  gap: .6rem;
  background: var(--card);
  padding: .75rem 1rem;
  border-radius: 10px;
}
.code-badge {
  font-size: 1.8rem;
  font-weight: 700;
  letter-spacing: 6px;
  color: var(--accent);
  font-family: monospace;
}
.label { color: var(--text-muted); font-size: .85rem; }
.lobby-qr-card {
  background: var(--card);
  border-radius: 10px;
  padding: .75rem 1rem;
}
#lobby-qr { display: flex; justify-content: center; }
.lobby-qr-row {
  display: flex;
  align-items: center;
  gap: .75rem;
  justify-content: center;
}
.lobby-link-row {
  display: flex;
  align-items: center;
  gap: .5rem;
  background: var(--card);
  border-radius: 8px;
  padding: .4rem .6rem;
  margin-bottom: .5rem;
  flex-wrap: wrap;
}
.lobby-link-text {
  font-size: .7rem;
  color: var(--text-muted);
  word-break: break-all;
  flex: 1;
}
#lobby-ul { list-style: none; padding: 0; display: flex; flex-direction: column; gap: .3rem; }
#lobby-ul li {
  display: flex; align-items: center; gap: .5rem;
  padding: .35rem .6rem;
  background: var(--surface);
  border-radius: 6px;
  font-size: .9rem;
}
#lobby-ul li .dot { width: 12px; height: 12px; border-radius: 50%; }
#join-waiting, #join-lobby-players { margin-top: .75rem; }

/* ================================================================
   EKRAN GRY
================================================================ */
#screen-game {
  display: none;
  flex-direction: column;
  min-height: 100dvh;
}
#screen-game.active { display: flex; }

.game-layout {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: .6rem;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: .5rem;
}

/* ---- Nagłówek ---- */
.game-header {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .4rem .5rem;
  background: var(--surface);
  border-radius: var(--radius);
}
.turn-badge {
  background: var(--card);
  padding: .3rem .8rem;
  border-radius: 8px;
  font-weight: 700;
  font-size: .95rem;
  border-left: 4px solid var(--accent);
}
.phase-badge {
  font-size: .82rem;
  color: var(--text-muted);
  background: var(--card);
  border-radius: 6px;
  padding: .25rem .6rem;
}
.btn-quit {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.3rem;
  cursor: pointer;
  padding: .2rem .4rem;
  border-radius: 6px;
  line-height: 1;
  touch-action: manipulation;
  transition: color .15s, background .15s;
}
.btn-quit:hover { color: var(--danger); background: rgba(255,80,80,.1); }

/* ---- Główna ---- */
.game-main {
  flex: 1;
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: .6rem;
  min-height: 0;
}

/* ---- Panel akcji ---- */
.action-panel {
  display: flex;
  flex-direction: column;
  gap: .75rem;
}

.dice-area {
  display: flex;
  gap: .75rem;
  justify-content: center;
  padding: .5rem;
}
.die {
  width: 80px; height: 80px;
  background: var(--card);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.6rem;
  border: 2px solid var(--border);
  transition: box-shadow .1s;
  user-select: none;
}
.pink-die   { border-color: #e87aad; }
.yellow-die { border-color: #e8c32a; }

/* Animacja rzutu – szybki jitter, powtarzana w JS */
@keyframes dieShake {
  0%   { transform: translate(-3px, -2px) rotate(-8deg)  scale(1.08); }
  15%  { transform: translate( 3px,  2px) rotate( 9deg)  scale(.95); }
  30%  { transform: translate(-2px,  3px) rotate(-6deg)  scale(1.05); }
  45%  { transform: translate( 2px, -2px) rotate( 7deg)  scale(.97); }
  60%  { transform: translate(-3px,  1px) rotate(-5deg)  scale(1.04); }
  75%  { transform: translate( 2px,  2px) rotate( 4deg)  scale(.98); }
  100% { transform: translate( 0,    0)   rotate( 0deg)  scale(1); }
}

/* Animacja lądowania – bounce */
@keyframes dieLand {
  0%   { transform: scale(1.4) rotate(-5deg); filter: blur(1px); }
  40%  { transform: scale(.88) rotate(2deg);  filter: none; }
  65%  { transform: scale(1.10) rotate(-1deg); }
  82%  { transform: scale(.97); }
  100% { transform: scale(1); }
}

.die.rolling {
  animation: dieShake .12s linear infinite;
  box-shadow: 0 0 16px 4px rgba(255, 255, 255, .18), 0 0 32px 6px rgba(255, 200, 80, .12);
  filter: blur(.4px);
}
.pink-die.rolling   { box-shadow: 0 0 18px 5px rgba(232, 122, 173, .5); }
.yellow-die.rolling { box-shadow: 0 0 18px 5px rgba(232, 195,  42, .5); }

.die.landed {
  animation: dieLand .45s cubic-bezier(.22,.61,.36,1) forwards;
}
.pink-die.landed   { box-shadow: 0 0 22px 6px rgba(232, 122, 173, .7); }
.yellow-die.landed { box-shadow: 0 0 22px 6px rgba(232, 195,  42, .7); }

.dice-labels {
  display: flex;
  justify-content: center;
  gap: .75rem;
  font-size: .75rem;
  color: var(--text-muted);
  text-align: center;
  min-height: 1.1rem;        /* rezerwuje miejsce — bez skoku layoutu */
  visibility: hidden;
}
.dice-labels span { width: 72px; }

.action-btns {
  display: flex;
  flex-direction: column;
  gap: .5rem;
}

/* ---- Pool ---- */
.pool-box {
  background: var(--surface);
  border-radius: var(--radius);
  padding: .4rem .6rem;
  border: 1px solid var(--border);
}
.pool-box .section-title { margin-bottom: .3rem; }
.section-title {
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  margin-bottom: .5rem;
}
.pool-grid {
  display: flex;
  flex-wrap: wrap;
  gap: .2rem;
}
.pool-item {
  display: flex;
  align-items: center;
  gap: .2rem;
  font-size: .72rem;
  background: var(--card);
  border-radius: 5px;
  padding: .15rem .35rem;
  white-space: nowrap;
}
.pool-item .emoji { font-size: .95rem; }
.pool-item .count {
  font-weight: 700;
  color: var(--accent);
  margin-left: auto;
}
.pool-item.low .count { color: var(--danger); }

/* ---- Panel graczy ---- */
.players-panel {
  display: flex;
  flex-direction: column;
  gap: .5rem;
  overflow-y: auto;
  padding-right: .2rem;
}

.player-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: .6rem .75rem;
  border: 2px solid var(--border);
  transition: border-color var(--transition), opacity var(--transition), filter var(--transition);
  opacity: .45;
  filter: saturate(.3);
}
.player-card.active-player { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(244,196,48,.2); opacity: 1; filter: none; }
.player-card.winner-card   { border-color: var(--success); opacity: 1; filter: none; }

.player-header {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-bottom: .4rem;
}
.player-color-dot { width: 16px; height: 16px; border-radius: 50%; flex-shrink: 0; }
.player-name { font-weight: 700; font-size: .95rem; }
.player-tag  { font-size: .75rem; color: var(--text-muted); margin-left: auto; }
.ai-tag      { background: #3a3060; color: #c4a0f0; border-radius: 4px; padding: .1rem .35rem; font-size: .7rem; }
.dog-badge   { font-size: .85rem; line-height: 1; }
.dog-badge.has  { filter: none; }
.dog-badge.zero { opacity: .2; filter: grayscale(1); }

.inventory-grid {
  display: flex;
  flex-wrap: wrap;
  gap: .3rem;
}
.inv-item {
  display: flex;
  align-items: center;
  gap: .2rem;
  background: var(--card);
  border-radius: 6px;
  padding: .2rem .5rem;
  font-size: .82rem;
  min-width: 46px;
  justify-content: center;
}
.inv-item .inv-emoji { font-size: 1rem; }
.inv-item .inv-count { font-weight: 700; }
.inv-item.zero { opacity: .25; }
.inv-item.has  { background: #1a3060; }
.inv-item.inv-dog { min-width: unset; padding: .2rem .35rem; }
.inv-item.inv-dog.has  { background: #1a3060; box-shadow: 0 0 6px 1px rgba(100,181,246,.4); }
.inv-item.inv-dog.zero { background: var(--card); opacity: .25; }

.win-progress {
  display: flex;
  gap: .2rem;
  margin-top: .4rem;
  flex-wrap: wrap;
}
.win-check {
  font-size: .7rem;
  padding: .1rem .3rem;
  border-radius: 4px;
  background: var(--card);
  color: var(--text-muted);
}
.win-check.done { background: #1a3060; color: #64b5f6; }

/* ---- Log ---- */
.game-log {
  background: var(--surface);
  border-radius: var(--radius);
  padding: .6rem .75rem;
  border: 1px solid var(--border);
  max-height: 160px;
  overflow-y: auto;
  margin-top: .5rem;
}
.log-content { display: flex; flex-direction: column; gap: .1rem; }
.log-entry {
  font-size: .78rem;
  color: var(--text-muted);
  padding: .08rem 0;
  border-bottom: 1px solid rgba(255,255,255,.03);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  animation: fadeIn .2s ease;
}
.log-entry.highlight { color: var(--accent); }
.log-entry.event-bad  { color: #ef9a9a; }
.log-entry.event-good { color: #90caf9; }
.log-entry.event-turn { color: var(--text); font-weight: 600; margin-top: .2rem; }

/* ================================================================
   MODALS
================================================================ */
.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.7);
}
.modal-box {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 1.25rem;
  max-width: 680px;
  width: calc(100% - 1.5rem);
  max-height: 90vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: .75rem;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: .5rem;
  padding-top: .25rem;
  border-top: 1px solid var(--border);
}

/* ---- Trade modal ---- */
.trade-layout {
  display: flex;
  gap: .75rem;
  align-items: flex-start;
}
.trade-col { flex: 1; display: flex; flex-direction: column; gap: .5rem; }
.trade-col h4 { font-size: .9rem; font-weight: 700; color: var(--text-muted); }
.trade-arrow { font-size: 1.5rem; padding-top: 1.8rem; color: var(--text-muted); }
.trade-list { display: flex; flex-direction: column; gap: .3rem; min-height: 180px; }

.trade-item {
  display: flex;
  align-items: center;
  gap: .4rem;
  background: var(--card);
  border-radius: 8px;
  padding: .35rem .5rem;
  font-size: .88rem;
}
.trade-item .t-emoji { font-size: 1.2rem; }
.trade-item .t-name  { flex: 1; }
.trade-item .t-avail { color: var(--text-muted); font-size: .78rem; }
.trade-item .t-count { font-weight: 700; min-width: 24px; text-align: center; color: var(--accent); }
.trade-item .t-btns  { display: flex; gap: .2rem; }
.t-btn {
  width: 24px; height: 24px;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
}
.t-btn:hover:not(:disabled) { background: var(--card-hover); }
.t-btn:disabled { opacity: .3; cursor: not-allowed; }

.trade-val-row { font-size: .85rem; color: var(--text-muted); }
.trade-val { font-weight: 700; font-size: 1rem; color: var(--accent); }

.trade-msg {
  font-size: .9rem;
  font-weight: 600;
  text-align: center;
  padding: .4rem .8rem;
  border-radius: 8px;
  background: var(--card);
}
.trade-msg.ok  { color: var(--success); }
.trade-msg.err { color: var(--danger); }

/* Supabase schema */
.code-block {
  background: #111;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .75rem;
  font-size: .75rem;
  color: #90caf9;
  overflow-x: auto;
  white-space: pre;
  max-height: 180px;
  overflow-y: auto;
}

/* ================================================================
   RESPONSIVE — MOBILE
================================================================ */
@media (max-width: 700px) {
  .game-main {
    display: flex;
    flex-direction: column;
    flex: none;        /* nie rozpychaj — log musi być widoczny */
  }
  .game-log { flex: none; max-height: 130px; }
  .players-panel { order: 1; }
  .action-panel  { order: 2; flex-direction: row; flex-wrap: wrap; gap: .5rem; align-items: flex-start; }
  .dice-area { flex-shrink: 0; padding: .25rem; gap: .5rem; }
  .die { width: 60px; height: 60px; font-size: 1.9rem; border-radius: 12px; }
  .dice-labels { min-height: .9rem; gap: .5rem; }
  .dice-labels span { width: 54px; }
  .action-btns { flex-direction: row; flex-wrap: wrap; }
  .trade-layout { flex-direction: column; }
  .trade-arrow { padding-top: 0; align-self: center; transform: rotate(90deg); }
  .modal-box { padding: .85rem; }
}

/* Zapobiegaj double-tap zoom na przyciskach i elementach interaktywnych */
button, .t-btn, .inv-item, .pool-item {
  touch-action: manipulation;
}

/* ================================================================
   PLAYER COLORS (utility)
================================================================ */
.pc-0 { background-color: var(--c0); }
.pc-1 { background-color: var(--c1); }
.pc-2 { background-color: var(--c2); }
.pc-3 { background-color: var(--c3); }
.pc-4 { background-color: var(--c4); }
.pc-5 { background-color: var(--c5); }

.border-pc-0 { border-color: var(--c0) !important; }
.border-pc-1 { border-color: var(--c1) !important; }
.border-pc-2 { border-color: var(--c2) !important; }
.border-pc-3 { border-color: var(--c3) !important; }
.border-pc-4 { border-color: var(--c4) !important; }
.border-pc-5 { border-color: var(--c5) !important; }

/* ================================================================
   END SCREEN
================================================================ */
#winner-info {
  background: var(--card);
  border-radius: var(--radius);
  padding: 1.5rem 2rem;
  margin: 1rem 0;
  text-align: center;
}
#winner-info .w-name { font-size: 2rem; font-weight: 700; }
#winner-info .w-inv  { font-size: 1.5rem; margin-top: .5rem; }
