* {
  box-sizing: border-box;
}

@keyframes gradientShift {
  0% {
    background-position: 0% 50%;
  }
  50% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0% 50%;
  }
}

body {
  font-family: Arial, sans-serif;
  padding: 12px;
  background: linear-gradient(-45deg, #ee7752, #e73c7e, #23a6d5, #23d5ab);
  background-size: 400% 400%;
  animation: gradientShift 15s ease infinite;
  font-size: 18px;
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
}

h1 {
  background: rgba(255, 255, 255, 0.95);
  padding: 12px 20px;
  border-radius: 12px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
  display: block;
  color: #2c3e50;
  font-size: 2em;
  min-height: 50px;
  text-align: center;
  margin: 0 auto 12px;
  width: max-content;
  min-width: fit-content;
  max-width: calc(100vw - 200px);
}

.gracz-selector,
#gracz-startowy {
  display: flex;
  gap: 10px;
  margin: 20px 0;
  flex-wrap: wrap;
}

#liczba-graczy-buttons {
  display: grid;
  grid-template-columns: repeat(5, 55px);
  gap: 10px;
  margin: 16px auto;
  justify-content: center;
}

.gracz-selector input,
.nazwa-input input {
  width: 60px;
  padding: 12px;
  font-size: 1em;
  border: 2px solid #2c3e50;
  border-radius: 4px;
}

.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 15px;
  margin: 20px 0;
}

.menu-btn {
  padding: 14px;
  font-size: 1.1em;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: bold;
  transition: all 0.3s ease;
}

.menu-btn.play {
  font-size: 1.25em;
  background: linear-gradient(135deg, #4caf50 0%, #388e3c 100%);
  color: white;
  box-shadow: 0 4px 12px rgba(76, 175, 80, 0.3);
}

.menu-btn.rules {
  background: linear-gradient(135deg, #ffb74d 0%, #ff9800 100%);
  color: #5d2b00;
  box-shadow: 0 4px 12px rgba(255, 152, 0, 0.25);
}

.menu-btn.stats {
  background: linear-gradient(135deg, #2196f3 0%, #1976d2 100%);
  color: white;
  box-shadow: 0 4px 12px rgba(33, 150, 243, 0.3);
}

.menu-btn:hover {
  transform: translateY(-2px);
}
.menu-btn.play:hover { box-shadow: 0 6px 16px rgba(76, 175, 80, 0.4); }
.menu-btn.rules:hover { box-shadow: 0 6px 16px rgba(255, 152, 0, 0.35); }
.menu-btn.stats:hover { box-shadow: 0 6px 16px rgba(33, 150, 243, 0.4); }

/* --- DRAG & DROP and ADDING/REMOVING PLAYERS --- */
#start {
  max-width: 660px; 
}

.nazwa-input {
  display: flex;
  gap: 10px;
  align-items: center;
  margin: 10px 0;
  font-size: 1rem; 
  background: white;
  padding: 8px 12px;
  border-radius: 8px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.05);
  border: 1px solid #e0e0e0;
  transition: box-shadow 0.2s, transform 0.2s;
  width: 100%;
  box-sizing: border-box;
  cursor: grab;
}

.nazwa-input:active {
  cursor: grabbing;
}

.nazwa-input label {
  font-weight: 600;
  min-width: 80px;
  color: #2c3e50;
  flex-shrink: 0;
  font-size: 1.1em;
  cursor: inherit;
  user-select: none;
}

.nazwa-input-container {
  position: relative; 
  flex-grow: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: text;
}

.nazwa-input-container input {
  width: 100%;
  height: 42px; 
  padding: 8px 12px;
  font-size: 1.05em; 
  border: 2px solid #e0e0e0;
  border-radius: 6px;
  transition: border-color 0.2s;
  box-sizing: border-box;
}

.nazwa-input-container input:focus {
  outline: none;
  border-color: #2196f3;
}

.nazwa-input.dragging {
  opacity: 0.9;
  box-shadow: 0 8px 20px rgba(0,0,0,0.15);
  transform: scale(1.02);
  z-index: 10;
  border-color: #2196f3;
}

.drag-handle {
  color: #bbb;
  font-size: 1.4em; 
  padding-right: 4px;
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: color 0.2s;
  cursor: inherit; /* Inherits the cursor from .input-name, so it becomes grab/grabbing */
}

.drag-handle:hover {
  color: #2196f3;
}

.drag-handle:active {
  cursor: grabbing;
}

/* RED MINUS */
.btn-remove-player {
  background: linear-gradient(135deg, #f44336 0%, #e53935 100%);
  color: #000000; 
  border: 1px solid #d32f2f;
  width: 32px;
  height: 32px;
  min-width: 32px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4em;
  font-weight: 900; 
  box-shadow: 0 2px 6px rgba(244, 67, 54, 0.3);
  transition: all 0.2s ease;
  margin-left: 4px;
  flex-shrink: 0;
}

.btn-remove-player:hover {
  transform: scale(1.1);
  box-shadow: 0 4px 10px rgba(244, 67, 54, 0.4);
}

/* CONTAINER FOR "NEXT" BUTTON AND GREEN/YELLOW PLUS */
.etap-actions-wrapper {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 25px;
  padding-top: 20px;
  border-top: 1px solid #e0e0e0;
  width: 100%;
}

/* YELLOW PLUS */
.btn-add-player {
  order: 1;
}

.btn-add-player:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(251, 192, 45, 0.4);
  background: linear-gradient(135deg, #fff176 0%, #fbc02d 100%);
}

.nazwa-input-dropdown-btn {
  width: 42px !important;
  height: 42px !important;
  min-width: 42px !important;
  padding: 0 !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  border-radius: 6px !important;
  font-size: 1.2em !important;
  box-sizing: border-box !important;
}

.nazwa-input-dropdown-btn:hover {
  background: linear-gradient(135deg, #1976d2 0%, #1565c0 100%);
  transform: translateY(-2px);
}

.nazwa-input-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  width: 100%;
  background: white;
  border: 2px solid #4caf50;
  border-radius: 6px;
  max-height: 250px;
  overflow-y: auto;
  z-index: 2000 !important; 
  box-shadow: 0 8px 24px rgba(0,0,0,0.15);
  display: none;
}

.nazwa-input-dropdown.aktywny {
  display: block;
}

.nazwa-input-dropdown-item {
  padding: 10px 12px;
  cursor: pointer;
  border-bottom: 1px solid #e0e0e0;
  transition: background 0.2s ease;
  color: #2c3e50;
  font-size: 0.95em;
}

.nazwa-input-dropdown-item:last-child {
  border-bottom: none;
}

.nazwa-input-dropdown-item:hover {
  background: #e3f2fd;
  color: #1565c0;
  font-weight: 500;
}

.gracz-selector button,
#etap-nazwy button,
#etap-start button,
#gracz-startowy button {
  padding: 12px 18px;
  font-size: 1.06em;
  background: linear-gradient(135deg, #4caf50 0%, #388e3c 100%);
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: bold;
  transition: all 0.3s ease;
  box-shadow: 0 4px 12px rgba(76, 175, 80, 0.3);
}

#liczba-graczy-buttons button {
  padding: 15px;
  font-size: 1.15em;
  background: linear-gradient(135deg, #2196f3 0%, #1976d2 100%);
  color: white;
  border: none;
  border-radius: 7px;
  cursor: pointer;
  font-weight: bold;
  transition: all 0.3s ease;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 55px;
  min-height: 55px;
  box-shadow: 0 4px 12px rgba(33, 150, 243, 0.3);
}

#liczba-graczy-buttons button:hover {
  background: linear-gradient(135deg, #1976d2 0%, #1565c0 100%);
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(33, 150, 243, 0.4);
}

.gracz-selector button:hover,
#etap-nazwy button:hover,
#etap-start button:hover,
#gracz-startowy button:hover {
  background: linear-gradient(135deg, #388e3c 0%, #2e7d32 100%);
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(76, 175, 80, 0.4);
}

#gracz-startowy button {
  padding: 12px 24px;
  font-size: 1.03em;
  background: linear-gradient(135deg, #2196f3 0%, #1976d2 100%);
  min-width: 160px;
  margin: 8px;
  box-shadow: 0 4px 12px rgba(33, 150, 243, 0.3);
}

#gracz-startowy button:hover {
  background: linear-gradient(135deg, #1976d2 0%, #1565c0 100%);
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(33, 150, 243, 0.4);
}

/* Controls (top-right) */
#games-counter-top {
  display: none;
}

/* --- FLOATING ACTION BUTTON (FAB) --- */
#controls {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 2200;
  display: none; /* Shows with class .active */
}

#controls.aktywna {
  display: block; /* Container for the menu */
}

/* MAIN FAB BUTTON */
.fab-main {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: linear-gradient(135deg, #2196f3 0%, #1976d2 100%);
  color: white;
  border: none;
  font-size: 28px;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(33, 150, 243, 0.4);
  
  /* Flexbox center the content, and line-height: 1 prevents "bumping" of emoji during rotation */
  display: flex;
  justify-content: center;
  align-items: center;
  line-height: 1; 
  padding: 0;
  
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 2;
  position: relative;
}

/* CLOSED STATE + HOVER */
.fab-main:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 20px rgba(33, 150, 243, 0.5);
}

/* OPEN STATE */
.fab-container.open .fab-main {
  /* For rotation of 180 degrees, it looks the most natural */
  transform: rotate(180deg); 
  background: linear-gradient(135deg, #ff6b6b 0%, #ee5a52 100%);
  box-shadow: 0 4px 16px rgba(255, 107, 107, 0.4);
}

/* CLOSED STATE + HOVER */
.fab-container.open .fab-main:hover {
  /* Connect the rotation and scale, so the button retains its "hover" size after clicking */
  transform: rotate(180deg) scale(1.05); 
  box-shadow: 0 6px 20px rgba(255, 107, 107, 0.5);
}

/* HIDDEN OPTION MENU */
.fab-menu {
  position: absolute;
  bottom: 80px;
  right: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: flex-end;
  opacity: 0;
  visibility: hidden;
  transform: translateY(20px) scale(0.9);
  transform-origin: bottom right;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: none;
}

/* VISIBLE OPTION MENU */
.fab-container.open .fab-menu {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
  pointer-events: auto; /* Allow clicks only when menu is visible */
}

/* SINGLE BUTTON IN THE MENU */
.fab-action {
  padding: 12px 20px;
  border-radius: 30px;
  background: white;
  color: #2c3e50;
  border: 2px solid transparent;
  font-size: 1.05em;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.fab-action:hover {
  background: #f8f9fa;
  border-color: #2196f3;
  color: #1976d2;
  transform: translateX(-5px); 
  box-shadow: 0 6px 16px rgba(33, 150, 243, 0.2);
}

#start h2 {
  color: #2c3e50;
  margin: 0 0 16px 0;
  background: rgba(255, 255, 255, 0.95);
  padding: 14px;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  display: block;
  font-size: 1.5em;
}

#start {
  background: rgba(255, 255, 255, 0.92);
  padding: 24px;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  max-width: 500px;
  margin: 8px auto;
}

#tura {
  display: none;
  background: rgba(255, 255, 255, 0.95);
  padding: 12px 16px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  width: fit-content;
  font-size: 1.2em;
  font-weight: bold;
  margin: 8px auto;
}

#partia-nr {
  display: none;
  background: rgba(255, 255, 255, 0.95);
  padding: 8px 16px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  width: fit-content;
  font-size: 1.05em;
  font-weight: bold;
  margin: -10px auto 10px auto;
}

.layout {
  display: none;
}

#controls {
  display: none;
}

#games-counter-top {
  display: none;
}

/* Left floating area for top-left controls (tura, partia-nr)
   Reserve visual space so these controls never overlap the game table. */
#left-floating {
  position: fixed;
  left: 16px;
  top: 16px;
  z-index: 2250;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-start;
  pointer-events: auto;
}

/* Make vertical gaps between title, tura and partia match the small
   gap used by inline confirms/buttons (8px). Only affects spacing,
   not element sizes or borders. */
#left-floating > * {
  margin: 0 0 8px 0;
}

/* Remove extra negative/top margins that were set globally when elements
   are moved into the floating container so spacing is consistent. */
#left-floating #tura,
#left-floating #partia-nr {
  margin: 0 0 8px 0 !important;
}

/* When left-floating is active reserve space for the layout so table is not overlapped */
/* When left-floating is active, adjust the layout to account for left controls */
body.left-floating .layout.aktywna {
  min-width: calc(100vw - 300px);
  margin-left: 150px; /* offset to center relative to remaining viewport */
}

/* Ensure the main title also respects the reserved left area and stays
   visually centered with the table when left-floating is active. */
body.left-floating h1 {
  max-width: calc(100vw - 300px);
  margin-left: auto;
  margin-right: auto;
}

/* Floating title when left controls are present */
.floating-title {
  /* when present, make title flow inside the left-floating container
     (we avoid fixed positioning to prevent it from covering the table) */
  position: static;
  left: auto;
  transform: none;
  z-index: 2245;
  max-width: calc(100vw - 300px);
  width: auto;
  text-align: center;
  margin: 0;
}

/* Ensure moved elements align nicely inside the floating container */
#left-floating #tura, #left-floating #partia-nr {
  margin: 0;
}

/* Kiedy gra się zaczyna, pokaż elementy */
#tura.aktywna {
  display: block;
}

#partia-nr.aktywna {
  display: block;
}

.layout.aktywna {
  display: grid;
}

#controls.aktywna {
  display: flex;
}

#games-counter-top.aktywna {
  display: block;
}

.layout.aktywna {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-width: 100vw;
  gap: 16px;
  background: transparent;
  padding: 20px;
  border-radius: 0;
  box-shadow: none;
  margin: 0;
  width: auto;
  max-width: none;
  overflow: auto;
}

.table-wrapper {
  overflow-x: auto;
  overflow-y: visible;
  background: white;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  width: fit-content;
  max-width: 100%;
}

table {
  border-collapse: collapse;
  table-layout: fixed;
  width: max-content;
  border: 3px solid #f0f0f0;
  background: white;
  border-radius: 8px;
  overflow: hidden;
}

/* Round corners on header cells */
thead tr:first-child th:first-child {
  border-radius: 5px 0 0 0;
}

thead tr:first-child th:last-child {
  border-radius: 0 5px 0 0;
}

/* Round corners on last row cells */
tbody tr:last-child td:first-child {
  border-radius: 0 0 0 5px;
}

tbody tr:last-child td:last-child {
  border-radius: 0 0 5px 0;
}

th {
  border: none;
  padding: 0; 
  height: 48px; 
  width: 110px; 
  text-align: center;
  background: linear-gradient(135deg, #2c3e50 0%, #34495e 100%);
  color: white;
  font-weight: bold;
  font-size: 1.02em;
  text-shadow: 0 1px 2px rgba(0,0,0,0.2);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.1);
  box-sizing: border-box;
}

th:first-child {
  border-right: 2px solid #2c3e50;
  width: 140px; 
}

td {
  border: 1px solid #e0e0e0;
  padding: 0; 
  height: 45px; 
  width: 110px; 
  text-align: center;
  transition: background-color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease; 
  font-size: 1.05em;
  white-space: nowrap;
  font-weight: 500;
  color: #333;
  box-sizing: border-box;
  overflow: hidden;
  font-variant-numeric: tabular-nums; 
}

td.pole-gry {
  cursor: pointer;
}

td.pole-gry:not(.zablokowane):not(:first-child):hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15), inset 0 1px 0 rgba(255,255,255,0.5);
  background-color: rgba(255, 255, 255, 0.3) !important;
}

td:first-child {
  font-weight: 700;
  background: linear-gradient(135deg, #f8f9fa 0%, #f0f0f0 100%);
  border-right: 2px solid #2c3e50;
  font-size: 0.95em;
  color: #2c3e50;
  width: 160px;
  border-top: 1px solid #e0e0e0;
  border-bottom: 1px solid #e0e0e0;
}

/* Pola górne */
tr[data-pole="Jedynki"] td:not(:first-child),
tr[data-pole="Dwójki"] td:not(:first-child),
tr[data-pole="Trójki"] td:not(:first-child),
tr[data-pole="Czwórki"] td:not(:first-child),
tr[data-pole="Piątki"] td:not(:first-child),
tr[data-pole="Szóstki"] td:not(:first-child) {
  background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%);
  color: #1565c0;
  font-weight: 600;
}

/* Upper sum and bonus */
tr[data-sum="Suma górna"] td:not(:first-child),
tr[data-sum="Premia"] td:not(:first-child) {
  background: linear-gradient(135deg, #81d4fa 0%, #4fc3f7 100%);
  font-weight: bold;
  border: 1px solid #0277bd;
  color: #01579b;
  box-shadow: inset 0 1px 2px rgba(255,255,255,0.3);
}

/* Lower fields */
tr[data-pole="Trzy jednakowe"] td:not(:first-child),
tr[data-pole="Cztery jednakowe"] td:not(:first-child),
tr[data-pole="Full"] td:not(:first-child),
tr[data-pole="Mały strit"] td:not(:first-child),
tr[data-pole="Duży strit"] td:not(:first-child),
tr[data-pole="Szansa"] td:not(:first-child),
tr[data-pole="Generał"] td:not(:first-child) {
  background: linear-gradient(135deg, #f3e5f5 0%, #e1bee7 100%);
  color: #6a1b9a;
  font-weight: 600;
}

/* Lower sum */
tr[data-sum="Suma dolna"] td:not(:first-child) {
  background: linear-gradient(135deg, #ce93d8 0%, #ba68c8 100%);
  font-weight: bold;
  border: 1px solid #7b1fa2;
  color: black;
  box-shadow: inset 0 1px 2px rgba(255,255,255,0.2);
}

/* TOTAL */
tr[data-sum="RAZEM"] td:not(:first-child) {
  background: linear-gradient(135deg, #66bb6a 0%, #4caf50 100%);
  font-weight: bold;
  font-size: 1.15em;
  border: 2px solid #2e7d32;
  color: black;
  text-shadow: 0 1px 2px rgba(255,255,255,0.3);
  box-shadow: inset 0 1px 2px rgba(255,255,255,0.2), 0 2px 4px rgba(0,0,0,0.1);
}

/* Inline confirm styles */
.inline-confirm {
  margin-top: 12px;
  padding: 12px;
  border-radius: 6px;
  background: #fff7e6;
  border: 1px solid #ffd54f;
}
.inline-confirm-msg {
  color: #333;
  margin-bottom: 8px;
  font-weight: 600;
}
.inline-confirm-actions { display:flex; gap:8px; }
.inline-confirm-actions .inline-yes {
  background:linear-gradient(135deg, #4caf50 0%, #388e3c 100%);
  color:white;
  border:none;
  padding:9px 14px;
  border-radius:5px;
  cursor:pointer;
  font-weight:700;
  transition: all 0.2s ease;
  box-shadow: 0 2px 8px rgba(76, 175, 80, 0.3);
}
.inline-confirm-actions .inline-yes:hover {
  background:linear-gradient(135deg, #388e3c 0%, #2e7d32 100%);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(76, 175, 80, 0.4);
}
.inline-confirm-actions .inline-no {
  background:linear-gradient(135deg, #f44336 0%, #d32f2f 100%);
  color:white;
  border:none;
  padding:9px 14px;
  border-radius:5px;
  cursor:pointer;
  font-weight:700;
  transition: all 0.2s ease;
  box-shadow: 0 2px 8px rgba(244, 67, 54, 0.3);
}
.inline-confirm-actions .inline-no:hover {
  background:linear-gradient(135deg, #d32f2f 0%, #c62828 100%);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(244, 67, 54, 0.4);
}

/* Rematch button color (yellow-orange) used in the two-option confirm */
.rematch-btn {
  background: linear-gradient(135deg, #ffb74d 0%, #ff9800 100%);
  color: #5d2b00;
  border: none;
  box-shadow: 0 4px 12px rgba(255, 152, 0, 0.18);
  font-weight: 700;
  padding: 9px 14px;
  border-radius: 5px;
}
.rematch-btn:hover {
  background: linear-gradient(135deg, #ffa726 0%, #fb8c00 100%);
  box-shadow: 0 6px 16px rgba(255, 152, 0, 0.22);
  transform: translateY(-2px);
}

/* Ensure rematch button overrides the default red 'inline-no' styles when inside confirms */
.inline-confirm-actions .rematch-btn,
.inline-confirm .rematch-btn,
.inline-confirm.global-fixed .rematch-btn,
.inline-confirm.global .rematch-btn {
  background: linear-gradient(135deg, #ffb74d 0%, #ff9800 100%) !important;
  color: #5d2b00 !important;
  box-shadow: 0 4px 12px rgba(255, 152, 0, 0.18) !important;
  border-color: rgba(0,0,0,0.08) !important;
}
.inline-confirm-actions .rematch-btn:hover,
.inline-confirm .rematch-btn:hover,
.inline-confirm.global-fixed .rematch-btn:hover,
.inline-confirm.global .rematch-btn:hover {
  background: linear-gradient(135deg, #ffa726 0%, #fb8c00 100%) !important;
}

.inline-confirm.global {
    background: #ffffff !important;
    border: 2px solid #2c3e50 !important;
    border-radius: 12px !important;
    box-shadow: 0 8px 25px rgba(0,0,0,0.2) !important;
    padding: 18px !important;
}

.zablokowane {
  background-color: #d3d3d3 !important;
  color: #666;
  opacity: 0.7;
  cursor: not-allowed;
}

#panel {
  min-width: 450px;
  max-width: 100%;
  border: 2px solid #2c3e50;
  padding: 24px;
  border-radius: 8px;
  background-color: white;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  position: fixed;
  left: 0;
  top: 0;
  z-index: 2210;
  pointer-events: auto;
  overscroll-behavior: contain;
  text-align: center;
}

#panel h3 {
  margin-top: 0;
  color: #2c3e50;
  font-size: 1.5em;
  margin-bottom: 16px;
  font-weight: 700;
}

#opis {
  font-size: 1.3em;
  color: #555;
  margin-bottom: 18px;
  padding: 15px;
  background-color: #e8f4f8;
  border-radius: 4px;
  border-left: 4px solid #0277bd;
  line-height: 1.4;
}

#opcje {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.input-liczby {
  margin-bottom: 10px;
}

.input-liczby input {
  width: 100%;
  padding: 14px;
  font-size: 1.2em;
  border: 3px solid #4caf50;
  background: linear-gradient(135deg, #f0f9f0 0%, #e8f5e9 100%);
  border-radius: 6px;
  text-align: center;
  font-weight: bold;
  color: #2e7d32;
  box-shadow: 0 2px 8px rgba(76, 175, 80, 0.2);
}

.input-liczby input:focus {
  outline: none;
  border-color: #2e7d32;
  box-shadow: 0 0 0 3px rgba(76, 175, 80, 0.2), 0 2px 12px rgba(76, 175, 80, 0.3);
  background: linear-gradient(135deg, #ffffff 0%, #f0f9f0 100%);
}

.separator {
  text-align: center;
  color: #999;
  font-weight: bold;
  margin: 10px 0;
}

.options-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  max-height: 400px;
  overflow-y: auto;
  padding: 8px;
  border: 1px solid #ddd;
  border-radius: 4px;
  background-color: #f9f9f9;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain; 
}

/* FORCE SCROLL BAR VISIBILITY ON macOS/SAFARI */
.options-grid::-webkit-scrollbar,
.nazwa-input-dropdown::-webkit-scrollbar,
.history-list::-webkit-scrollbar,
.highscores-wrapper::-webkit-scrollbar,
.stats-body::-webkit-scrollbar {
  width: 10px;
}

.options-grid::-webkit-scrollbar-track,
.nazwa-input-dropdown::-webkit-scrollbar-track,
.history-list::-webkit-scrollbar-track,
.highscores-wrapper::-webkit-scrollbar-track,
.stats-body::-webkit-scrollbar-track {
  background: #f0f0f0;
  border-radius: 5px;
  border: 1px solid #e0e0e0;
}

.options-grid::-webkit-scrollbar-thumb,
.nazwa-input-dropdown::-webkit-scrollbar-thumb,
.history-list::-webkit-scrollbar-thumb,
.highscores-wrapper::-webkit-scrollbar-thumb,
.stats-body::-webkit-scrollbar-thumb {
  background: #b0b0b0;
  border-radius: 5px;
}

.options-grid::-webkit-scrollbar-thumb:hover,
.nazwa-input-dropdown::-webkit-scrollbar-thumb:hover,
.history-list::-webkit-scrollbar-thumb:hover,
.highscores-wrapper::-webkit-scrollbar-thumb:hover,
.stats-body::-webkit-scrollbar-thumb:hover {
  background: #909090;
}

/* Force scrollbar visibility on macOS/Safari */
.game-end-ranking::-webkit-scrollbar {
  width: 8px;
}
.game-end-ranking::-webkit-scrollbar-track {
  background: #e0e0e0;
  border-radius: 4px;
}
.game-end-ranking::-webkit-scrollbar-thumb {
  background: #b0b0b0;
  border-radius: 4px;
}
.game-end-ranking::-webkit-scrollbar-thumb:hover {
  background: #909090;
}

.option-btn {
  padding: 9px 7px;
  font-size: 0.98em;
  background: linear-gradient(135deg, #2196f3 0%, #1976d2 100%);
  color: white;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  font-weight: 700;
  transition: all 0.2s ease;
  box-shadow: 0 2px 6px rgba(33, 150, 243, 0.3);
}

.option-btn:hover {
  background: linear-gradient(135deg, #1976d2 0%, #1565c0 100%);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(33, 150, 243, 0.4);
}

.option-btn:active {
  transform: scale(0.98);
}

td.aktywny-gracz:not(:first-child) {
  background: linear-gradient(135deg, #ffeb3b 0%, #fdd835 100%) !important;
  box-shadow: 0 0 8px rgba(255, 193, 7, 0.6), inset 0 1px 0 rgba(255,255,255,0.4);
  font-weight: 700;
  color: #f57f17;
}

td.nieaktywny {
  background-color: #eee !important;
  cursor: not-allowed;
}

#panel {
  transition: opacity 0.2s, transform 0.2s, box-shadow 0.2s;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px);
}

#panel.aktywny {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  box-shadow: 0 8px 16px rgba(0,0,0,0.2);
}

/* Error Notification */
.error-notification {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 16px 24px;
  border-radius: 8px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
  z-index: 2350;
  cursor: pointer;
  animation: slideInUp 0.3s ease-out;
  max-width: 350px;
  word-wrap: break-word;
}

@keyframes slideInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.error-notification.fade-out {
  animation: slideOutDown 0.3s ease-out forwards;
}

@keyframes slideOutDown {
  from {
    opacity: 1;
    transform: translateY(0);
  }
  to {
    opacity: 0;
    transform: translateY(20px);
  }
}

.error-content {
  font-size: 1em;
  font-weight: 600;
  line-height: 1.4;
}

/* Game End Modal */
.game-end-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2400;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s, visibility 0.3s;
}

.game-end-modal.aktywny {
  opacity: 1;
  visibility: visible;
}

.game-end-content {
  background: white;
  padding: 32px;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  max-width: 550px;
  width: 90%;
  text-align: center;
  animation: slideIn 0.4s ease-out;
  display: flex;
  flex-direction: column;
  align-items: center;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.game-end-content h2 {
  font-size: 1.8em;
  color: #2c3e50;
  margin: 0 0 16px 0;
}

.game-end-result {
  font-size: 1.1em;
  color: #333;
  margin: 16px 0 24px 0;
  line-height: 1.6;
}

.game-end-ranking {
  background: #f5f5f5;
  border-radius: 8px;
  padding: 20px;
  margin: 20px 0;
  text-align: left;
  min-width: 100%;
}

/* Force scrollbar visibility on macOS/Safari */
.game-end-ranking::-webkit-scrollbar {
  width: 8px;
}
.game-end-ranking::-webkit-scrollbar-track {
  background: #e0e0e0;
  border-radius: 4px;
}
.game-end-ranking::-webkit-scrollbar-thumb {
  background: #b0b0b0;
  border-radius: 4px;
}
.game-end-ranking::-webkit-scrollbar-thumb:hover {
  background: #909090;
}

.ranking-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 12px;
  border-bottom: 1px solid #ddd;
  font-size: 1.2em;
}

.ranking-row:last-child {
  border-bottom: none;
}

.ranking-row .rank {
  font-weight: bold;
  color: #2196f3;
  min-width: 50px;
  font-size: 1.4em;
}

.ranking-row .name {
  flex: 1;
  margin: 0 15px;
  font-weight: 600;
  color: #2c3e50;
  min-width: 120px;
}

.ranking-row .score {
  font-weight: bold;
  color: #4caf50;
  font-size: 1.3em;
  min-width: 80px;
  text-align: right;
}

.game-end-buttons {
  margin-top: 30px;
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

.game-end-buttons button {
  padding: 13px 30px;
  font-size: 1.1em;
  background: linear-gradient(135deg, #4caf50 0%, #388e3c 100%);
  color: white;
  border: none;
  border-radius: 7px;
  cursor: pointer;
  font-weight: bold;
  transition: all 0.3s ease;
  box-shadow: 0 4px 12px rgba(76, 175, 80, 0.3);
}

.game-end-buttons button:hover {
  background: linear-gradient(135deg, #388e3c 0%, #2e7d32 100%);
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(76, 175, 80, 0.4);
}
 

/* =======================
   STATS AND HISTORY MODAL
======================= */
.stats-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2400;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s, visibility 0.3s;
  pointer-events: none;
}

.stats-modal.aktywny {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.stats-content {
  background: white;
  padding: 30px;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  max-width: 700px;
  width: 90%;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden; /* body will scroll, not the whole modal */
  animation: slideIn 0.4s ease-out;
}

/* Scrollable body inside modal to keep footer/buttons visible */
.stats-body {
  overflow-y: auto;
  flex: 1 1 auto;
  padding-right: 8px; /* avoid hiding content under scrollbar */
}

.stats-content h2 {
  font-size: 1.8em;
  color: #2c3e50;
  margin: 0 0 20px 0;
  text-align: center;
}

.stats-content h3 {
  font-size: 1.3em;
  color: #2196f3;
  margin: 20px 0 15px 0;
  border-bottom: 2px solid #2196f3;
  padding-bottom: 10px;
}

.stats-section {
  margin-bottom: 30px;
}

.stats-table {
  width: 100%;
  border-collapse: collapse;
  background: #f9f9f9;
  border-radius: 8px;
  overflow: hidden;
}

.stats-table th {
  background: #2196f3;
  color: white;
  padding: 12px;
  text-align: center;
  font-weight: 600;
}

.stats-table th:first-child,
.stats-table td:first-child {
  width: 50px;           
  min-width: 50px;
  max-width: 50px;
  padding: 12px 5px;     
  text-align: center;
  white-space: nowrap;   
}

.stats-table th:nth-child(2),
.stats-table td:nth-child(2) {
  width: 100%;
  text-align: left;
}

.stats-table td {
  padding: 12px;
  border-bottom: 1px solid #e0e0e0;
  font-size: 1em;
}

.stats-table tr:last-child td {
  border-bottom: none;
}

.stats-table tr:nth-child(even) {
  background: #f0f0f0;
}

.stats-table tbody tr:hover {
  background: #e3f2fd;
}

/* Highscores wrapper: show ~5 rows and allow scrolling */
.highscores-wrapper {
  max-height: calc(5 * 48px + 48px); /* approx 5 rows + header */
  overflow-y: auto;
  border-radius: 6px;
  padding-right: 8px; /* avoid clipping under scrollbar */
  margin-bottom: 8px;
}

/* Force scrollbar visibility on macOS/Safari */
.game-end-ranking::-webkit-scrollbar {
  width: 8px;
}
.game-end-ranking::-webkit-scrollbar-track {
  background: #e0e0e0;
  border-radius: 4px;
}
.game-end-ranking::-webkit-scrollbar-thumb {
  background: #b0b0b0;
  border-radius: 4px;
}
.game-end-ranking::-webkit-scrollbar-thumb:hover {
  background: #909090;
}

/* Keep header visible when scrolling highscores */
.highscores-wrapper .stats-table thead th {
  position: sticky;
  top: 0;
  background: #2196f3;
  color: white;
  z-index: 5;
}

.history-list {
  background: #f9f9f9;
  border-radius: 8px;
  padding: 10px;
  max-height: 400px;
  overflow-y: auto;
}

.history-item {
  background: white;
  border: 1px solid #ddd;
  border-radius: 6px;
  padding: 12px;
  margin-bottom: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-item:last-child {
  margin-bottom: 0;
}

.history-date {
  font-size: 0.9em;
  color: #888;
  font-weight: 600;
}

.history-results {
  font-size: 0.95em;
  color: #2c3e50;
  word-break: break-word;
}

.game-stats-summary {
  background: linear-gradient(135deg, #2196f3 0%, #1976d2 100%);
  border: none;
  padding: 20px;
  border-radius: 8px;
  margin: 20px 0 25px 0;
  color: white;
  box-shadow: 0 4px 12px rgba(33, 150, 243, 0.3);
}

.game-stats-summary p {
  margin: 0;
  color: white;
  font-weight: 600;
  font-size: 1.1em;
}

.stats-buttons {
  margin-top: 25px;
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

.stats-buttons button {
  padding: 12px 24px;
  font-size: 1em;
  background: linear-gradient(135deg, #4caf50 0%, #388e3c 100%);
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: bold;
  transition: all 0.3s ease;
  box-shadow: 0 4px 12px rgba(76, 175, 80, 0.3);
}

.stats-buttons button:hover {
  background: linear-gradient(135deg, #388e3c 0%, #2e7d32 100%);
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(76, 175, 80, 0.4);
}

.stats-buttons .btn-danger {
  background: linear-gradient(135deg, #f44336 0%, #d32f2f 100%);
  box-shadow: 0 4px 12px rgba(244, 67, 54, 0.3);
}

.stats-buttons .btn-danger:hover {
  background: linear-gradient(135deg, #d32f2f 0%, #c62828 100%);
  box-shadow: 0 6px 16px rgba(244, 67, 54, 0.4);
}

/* Delete spinner arrows from number input */
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

input[type="number"] {
  -moz-appearance: textfield;
  appearance: textfield;
}

/* Animation for inline messages */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(-5px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeOut {
  from {
    opacity: 1;
    transform: translateY(0);
  }
  to {
    opacity: 0;
    transform: translateY(-5px);
  }
}

.inline-message {
  animation: fadeIn 0.3s ease-out;
  padding: 10px 15px;
  margin: 8px 0;
  border-radius: 4px;
  font-size: 0.95em;
  font-weight: 500;
  display: inline-block;
}

.inline-message.error {
  background-color: #ffebee;
  color: #c62828;
  border-left: 4px solid #d32f2f;
}

.inline-message.success {
  background-color: #e8f5e9;
  color: #2e7d32;
  border-left: 4px solid #4caf50;
}

/* Tooltip for PIN messages */
.pin-tooltip {
  position: fixed;
  color: white;
  padding: 8px 12px;
  border-radius: 4px;
  font-size: 0.85em;
  font-weight: 500;
  white-space: nowrap;
  z-index: 3000;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  animation: fadeIn 0.2s ease-out;
  pointer-events: none;
}

.pin-tooltip-error {
  background: #d32f2f;
}

.pin-tooltip-success {
  background: #4caf50;
}

/* Tooltip on the center of the screen for global messages */
.center-tooltip {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  color: white;
  padding: 16px 24px;
  border-radius: 8px;
  font-size: 1em;
  font-weight: 500;
  text-align: center;
  width: max-content;
  max-width: calc(100vw - 24px);
  white-space: nowrap;
  z-index: 3500;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  pointer-events: none;
  transition: opacity 0.3s ease-out;
}

.center-tooltip-error {
  background: #d32f2f;
}

.center-tooltip-success {
  background: #4caf50;
}

/* FORCE BUTTON COLORS */

#etap-nazwy button.btn-remove-player {
  background: linear-gradient(135deg, #f44336 0%, #e53935 100%) !important;
  color: #ffffff !important; 
  border: 2px solid #ffffff !important; 
  width: 34px !important;
  height: 34px !important;
  min-width: 34px !important;
  padding: 0 !important;
  border-radius: 50% !important;
  box-shadow: 0 2px 6px rgba(244, 67, 54, 0.4) !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
}

#etap-nazwy button.btn-remove-player:hover {
  transform: scale(1.15) !important;
  background: linear-gradient(135deg, #e53935 0%, #c62828 100%) !important;
  box-shadow: 0 4px 10px rgba(244, 67, 54, 0.5) !important;
}

#etap-nazwy button.btn-add-player {
  background: linear-gradient(135deg, #ffb74d 0%, #ff9800 100%) !important;
  color: #5d2b00 !important;
  border: 1px solid rgba(0,0,0,0.08) !important;
  padding: 10px 20px !important;
  border-radius: 6px !important;
  font-size: 1.05em !important;
  font-weight: 900 !important;
  box-shadow: 0 4px 12px rgba(255, 152, 0, 0.25) !important;
  text-shadow: none !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 8px !important;
}

#etap-nazwy button.btn-add-player:hover {
  transform: translateY(-2px) !important;
  background: linear-gradient(135deg, #ffa726 0%, #fb8c00 100%) !important;
  box-shadow: 0 6px 16px rgba(255, 152, 0, 0.3) !important;
}

#etap-nazwy button[onclick="validateAndProceedToStart()"] {
  order: 2; 
  margin-left: auto !important; 
}

/* Style for the Smart Joker Modal */
.smart-joker-box {
    position: fixed;
    z-index: 3000;
    width: 390px; 
    max-width: 95vw;
    padding: 22px;
    background: #ffffff;
    border: 3px solid #2c3e50;
    border-radius: 18px; 
    box-shadow: 0 15px 50px rgba(0,0,0,0.5);
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    font-family: 'Segoe UI', Roboto, sans-serif;
}

.smart-joker-box h3 {
    font-size: 1.5em !important;
    margin: 0 0 5px 0 !important;
    color: #1a252f;
}

/* Joker buttons */
.smart-joker-box .btn-joker-yes, 
.smart-joker-box .btn-joker-no, 
.smart-joker-box .btn-joker-disabled,
.smart-joker-box .btn-joker-joker {
    border: none;
    border-radius: 10px !important;
    font-weight: bold;
    transition: transform 0.1s, background 0.2s;
}

.smart-joker-box .btn-joker-yes {
    background: linear-gradient(135deg, #4caf50 0%, #388e3c 100%) !important;
    color: white !important;
    box-shadow: 0 3px 10px rgba(76, 175, 80, 0.4) !important;
    cursor: pointer;
}

.smart-joker-box .btn-joker-no {
    background: linear-gradient(135deg, #f44336 0%, #d32f2f 100%) !important;
    color: white !important;
    box-shadow: 0 3px 10px rgba(244, 67, 54, 0.3) !important;
    cursor: pointer;
}

.smart-joker-box .btn-joker-joker {
    background: linear-gradient(135deg, #ffa726 0%, #fb8c00 100%) !important;
    color: white !important;
    box-shadow: 0 3px 10px rgba(76, 175, 80, 0.4) !important;
    cursor: pointer;
}

.smart-joker-box .btn-joker-disabled {
    background: #f8f9fa !important;
    color: #a0a0a0 !important;
    border: 1px solid #ddd !important;
    cursor: not-allowed;
    opacity: 0.7;
}

.smart-joker-box .btn-main-normal {
    width: 100%;
    margin-bottom: 15px;
    padding: 15px 10px;
    font-size: 1.1em !important; 
    letter-spacing: 0.2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.smart-joker-box .dice-number { font-size: 1.4em; display: block; line-height: 1; margin-top: 2px; }
.smart-joker-box .status-text { font-size: 0.7em; text-transform: uppercase; display: block; margin-bottom: 2px; font-weight: normal; }

/* =========================
   STYLES OF GAME RULES (MODAL)
======================= */
.rule-text-justify {
  line-height: 1.6;
  text-align: justify;
  text-justify: inter-word;
  hyphens: none;
  -webkit-hyphens: none;
  -moz-hyphens: none;
  word-break: normal;
}

.rule-section-title {
  color: #2c3e50;
  border-bottom: 2px solid #e2e8f0;
  padding-bottom: 8px;
  margin-bottom: 18px;
  font-size: 1.25em;
  margin-top: 0;
}

.rule-section-title.red {
  color: #c62828;
  border-bottom-color: #fed7d7;
}

.rule-card-container {
  background: #fff;
  border: 2px solid #2c3e50;
  padding: 18px;
  border-radius: 14px;
  box-shadow: 0 6px 12px rgba(44, 62, 80, 0.08);
  margin-bottom: 25px;
}

.rule-card-container.red {
  border-color: #fc8181;
  box-shadow: 0 6px 12px rgba(229, 62, 62, 0.08);
}

.rule-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
  border-bottom: 1px dashed #cbd5e0;
  padding-bottom: 12px;
}

.rule-card-header.red { border-bottom-color: #fed7d7; }

.rule-card-title {
  font-weight: 900;
  color: #2c3e50;
  font-size: 1.2em;
}

.rule-card-title.red { color: #c62828; }

.rule-badge {
  padding: 6px 12px;
  border-radius: 20px;
  font-weight: 900;
  font-size: 0.9em;
  white-space: nowrap;
  text-transform: uppercase;
  color: #fff;
}

.rule-badge.dark { background: #2c3e50; box-shadow: 0 2px 4px rgba(44, 62, 80, 0.3); }
.rule-badge.red { background: #e53e3e; box-shadow: 0 2px 4px rgba(229, 62, 62, 0.3); }
.rule-badge.green { background: #38a169; box-shadow: 0 2px 4px rgba(56, 161, 105, 0.3); }

.rule-step-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.rule-step-card {
  background: #f8f9fa;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 14px;
}

.rule-step-card.blue { border-left: 4px solid #3182ce; }
.rule-step-card.red { border-left: 4px solid #e53e3e; }
.rule-step-card.light-blue { background: #f0f7ff; border-color: #90cdf4; }
.rule-step-card.purple { background: #faf5ff; border-color: #d6bcfa; }
.rule-step-card.green { background: #f0fff4; border-color: #c6f6d5; border-left: 4px solid #38a169; margin-bottom: 15px; }
.rule-step-card.info { background: #ebf8ff; border-color: #bee3f8; border-left: 4px solid #3182ce; }

.rule-step-title {
  font-weight: 800;
  font-size: 1.05em;
  text-transform: uppercase;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.rule-step-title.blue { color: #2b6cb0; }
.rule-step-title.red { color: #c53030; }
.rule-step-title.purple { color: #6b46c1; }

.rule-step-text {
  color: #2d3748;
  font-size: 0.95em;
}

.rule-step-text.indented { margin-left: 32px; margin-bottom: 10px; }

.rule-section-label {
  background: #f1f3f5;
  padding: 12px 15px;
  border-radius: 10px;
  font-weight: bold;
  font-size: 0.9em;
  text-transform: uppercase;
  color: #495057;
  margin-bottom: 12px;
}

.rule-section-label.blue { border-left: 4px solid #0984e3; }
.rule-section-label.dark { border-left: 4px solid #2c3e50; }

.rule-category-card {
  background: #fff;
  border: 1px solid #e2e8f0;
  padding: 15px;
  border-radius: 12px;
  box-shadow: 0 4px 6px rgba(0,0,0,0.03);
  display: flex;
  flex-direction: column;
  margin-bottom: 25px;
}

.rule-category-card.grid-item { 
  margin-bottom: 0; 
  border-left-width: 5px; 
  border-left-style: solid; 
  border-left-color: var(--cat-color); 
}
.rule-category-card.blue { border-left: 5px solid #0984e3; }

.rule-cat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.rule-cat-title {
  font-weight: 900;
  color: #2d3748;
  font-size: 1.15em;
}

.rule-cat-badge {
  background: #f8f9fa;
  border: 1px solid #e2e8f0;
  padding: 4px 10px;
  border-radius: 20px;
  font-weight: 800;
  font-size: 0.85em;
  box-shadow: 0 2px 4px rgba(0,0,0,0.02);
  white-space: nowrap;
}

.rule-cat-badge.blue { color: #0984e3; }
.rule-cat-badge.dynamic { color: var(--cat-color); }

.rule-cat-desc {
  color: #4a5568;
  font-size: 0.95em;
  line-height: 1.5;
  margin-bottom: 14px;
}

.rule-example-row {
  display: flex;
  gap: 6px;
  border-top: 1px dashed #e2e8f0;
  padding-top: 12px;
  margin-bottom: 15px;
  align-items: center;
  flex-wrap: wrap;
}
.rule-example-row.no-margin { margin-bottom: 0; }

.rule-example-label {
  font-size: 0.75em;
  color: #a0aec0;
  text-transform: uppercase;
  font-weight: bold;
  margin-right: 4px;
  letter-spacing: 0.5px;
}
.rule-example-label.red { color: #c62828; }

.rule-dice-group {
  display: flex;
  gap: 6px;
}

.rule-dice {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  font-weight: 900;
  transition: all 0.2s;
}

.rule-dice.sm { width: 26px; height: 26px; font-size: 14px; }
.rule-dice.md { width: 30px; height: 30px; font-size: 16px; border-radius: 8px; }

.rule-dice.blue-active {
  background: #e3f2fd;
  border: 2px solid #0984e3;
  color: #0984e3;
  box-shadow: inset 0 -2px 0 rgba(9,132,227,0.2);
}

.rule-dice.inactive {
  background: #f8f9fa;
  border: 2px solid #e2e8f0;
  color: #cbd5e0;
  opacity: 0.6;
  box-shadow: inset 0 -2px 0 rgba(0,0,0,0.05);
}

.rule-dice.dynamic-active {
  background: #fff;
  border: 2px solid var(--cat-color);
  color: var(--cat-color);
  box-shadow: inset 0 -2px 0 var(--cat-color-alpha);
}

.rule-dice.red-active {
  background: #fff;
  border: 2px solid #e53e3e;
  color: #e53e3e;
  box-shadow: 0 2px 4px rgba(229,62,62,0.15);
}

.rule-score-total {
  font-weight: 900;
  color: #0984e3;
  font-size: 1.1em;
  margin-left: auto;
}

.rule-bonus-box {
  background: #fff8e1;
  border: 1px solid #ffecb3;
  border-radius: 8px;
  padding: 12px;
  display: flex;
  gap: 12px;
  align-items: center;
}

.rule-bonus-icon {
  font-size: 1.6em;
  line-height: 1;
  filter: drop-shadow(0 2px 2px rgba(0,0,0,0.1));
}

.rule-bonus-title {
  font-weight: 900;
  color: #f57f17;
  font-size: 0.95em;
  margin-bottom: 2px;
}

.rule-bonus-desc {
  color: #666;
  font-size: 0.85em;
  line-height: 1.4;
}

.rule-category-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.rule-joker-intro {
  color: #2d3748;
  font-size: 1em;
  line-height: 1.6;
  margin-bottom: 18px;
}

.rule-joker-example-box {
  background: #fff5f5;
  border: 1px solid #fed7d7;
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

.rule-step-circle {
  color: #fff;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 14px;
}
.rule-step-circle.blue { background: #3182ce; }
.rule-step-circle.purple { background: #805ad5; }

.rule-example-result {
  background: #fff;
  padding: 10px;
  border-radius: 6px;
  font-size: 0.9em;
  margin-left: 32px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.rule-example-result.blue { border-left: 4px solid #3182ce; color: #2b6cb0; }
.rule-example-result.purple { border-left: 4px solid #805ad5; color: #6b46c1; }
.rule-example-result-title { display: block; margin-bottom: 2px; font-weight: bold; }
.rule-example-result-score { font-size: 1.1em; font-weight: 900; color: #e53e3e; }

.rule-tip-box {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.rule-tip-icon { font-size: 1.5em; line-height: 1; }
.rule-tip-text { color: #2a4365; font-size: 0.9em; }
.rule-tip-title {
  display: block;
  margin-bottom: 4px;
  text-transform: uppercase;
  font-size: 0.85em;
  letter-spacing: 0.5px;
  font-weight: bold;
}

  /*MOBILE OPTIMIZATION */ 
@media (max-width: 768px) {
  /* ---1. GLOBAL & MOBILE RESET --- */
  html, body {
    margin: 0;
    padding: 5px;
  }

  #start {
    zoom: 0.9;
  }

  /* ---2. MAIN LAYOUTS AND HEADERS --- */
  body.left-floating .layout.aktywna, 
  .layout.aktywna {
    margin: 0 !important;
    padding: 1px !important;
    padding-top: 111px !important;
    width: 100vw !important; 
    min-width: 100% !important;
    box-sizing: border-box;
  }

  #left-floating {
    left: 50% !important;
    transform: translateX(-50%) !important;
    width: 100%;
    align-items: center;
    top: 0.5px;
    gap: 0.5px;
    zoom: 0.6;
  }

  h1, body.left-floating h1.floating-title {
    font-size: 1.0em;
    padding: 4px 8px;
    margin: 0;
    position: relative !important;
    top: 0 !important;
  }

  /* ---3. TABELE I WRAPPERY --- */
  .table-wrapper {
    width: 100%;
    max-width: 100%;
    margin: 10px auto;
    -webkit-overflow-scrolling: touch; 
    background: transparent;
    box-shadow: none;
    padding-bottom: 20px;
  }

  table {
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    margin: auto;
  }

  /* Main Table */
  #tabela th:first-child, 
  #tabela td:first-child { 
    width: 150px !important; 
    font-size: 0.9em; 
  }

  #tabela th, 
  #tabela td { 
    width: 100px !important; 
    height: 38px !important; 
    font-size: 0.95em; 
  }

  /* Statistics Table */
  .stats-table th:first-child,
  .stats-table td:first-child {
    width: 40px !important;  
    min-width: 40px !important;
    max-width: 40px !important;
    padding: 8px 4px !important;
  }

  .stats-table th,
  .stats-table td {
    padding: 8px !important; 
    font-size: 0.85em;       
  }

  /* ---4. MODAL PANEL I --- */
  #panel {
    min-width: 0 !important;
    width: 92%;
    padding: 16px;
    left: 50% !important;
    top: 59% !important;
    transform: translate(-50%, -50%) !important;
  }

  .stats-modal {
    zoom: 0.6;
    min-height: 160vh;
  }

  .stats-content {
    min-height: 130vh; 
  }

  /* Jokera Modal */
  .smart-joker-box {
    width: 95% !important;
    padding: 15px !important;
  } 

  .smart-joker-box .btn-main-normal {
    font-size: 1.05em !important;
  }

  /* ---5. CONFIRMATION WINDOWS (CONFIRMS) --- */
  .inline-confirm {
    scale: 96%;
    left: -0.5% !important;
    top: 40% !important;
    font-size: 130%;
  }

  .inline-confirm-msg {
    zoom: 0.7;
  }

  /* Centered windows (e.g. New Game) */
  .inline-confirm.global-fixed {
    width: 90% !important;
    max-width: 340px !important;
    left: 50% !important;
    top: 50% !important;
    transform: translate(-50%, -50%) !important;
    position: fixed !important;
  }

  /* "Undo" box in the lower left corner */
  .inline-confirm.global.confirm-undo-mobile {
    position: fixed !important;
    left: 10px !important;
    right: auto !important;
    bottom: 20px !important;
    top: auto !important;
    transform: none !important;
    width: 280px !important;
    max-width: 80vw !important;
    z-index: 9999 !important;
  }

  /* ---6. CONTROLS AND INPUTS --- */
  #controls {
    bottom: 20px !important;
    right: 20px !important;
    transform: scale(0.85);
    transform-origin: bottom right;
  }

  .fab-menu {
    bottom: 75px !important;
    right: 0 !important;
    align-items: flex-end !important;
  }

  .options-grid {
    max-height: 35vh;
    zoom: 90%;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch; 
    overscroll-behavior: contain;
  }

  .nazwa-input input {
    font-size: 0.8em;
    border: 2px solid #2c3e50;
    border-radius: 4px;
  }
}

/* ---GLOBAL RULES (Always applied) --- */
.rules-body div[style*="justify-content: space-between"] {
    gap: 15px; 
}

.rules-body strong {
    flex-shrink: 0; 
}

.rules-body span {
    text-align: right; 
    color: #666;
}

/* Modal Joker Width Protection (Default on PC) */
.smart-joker-box {
    width: 400px !important; 
    max-width: 95vw !important;
}