/* Root color variables */
:root {
  --accent: #0a84ff;
  --radius-xs: 8px;
  --radius-sm: 10px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-pill: 999px;
  --radius: var(--radius-md);
  --shadow-soft: 0 6px 18px rgba(0, 0, 0, 0.22);
  --shadow-card: 0 4px 12px rgba(0, 0, 0, 0.24);
  --color-bg: #0e0f12; /* neutral charcoal */
  --color-bg-light: #16171a; /* slightly lighter neutral */
  --color-border: #e8e8ea; /* off-white neutral */
  --color-muted: #9a9aa0; /* neutral grey for secondary text */
  --color-stack-border: #2a2d34; /* neutral dark border */
  --color-stack-bg: #16171a; /* neutral background for table area */
  --color-modal-bg: #1b1d22; /* neutral modal surface */
  --color-modal-text: #e8e8ea;
  --color-modal-shadow: rgba(0,0,0,0.45);
  --color-btn-bg: color-mix(in oklab, var(--accent) 85%, #1a1a1a);
  --color-btn-bg-hover: color-mix(in oklab, var(--accent) 70%, #1a1a1a);
  --color-btn-text: #fff;
  --color-card-border: #2a2d34;
  --color-card-shadow: rgba(0, 0, 0, 0.3);
  --color-debug-bg: rgba(18, 18, 18, 0.85);
  --color-debug-text: #e8e8ea;
  --color-stack-number: #e8e8ea;
  --color-stack-number-shadow: rgba(0, 0, 0, 0.6);
  --color-mini-card-border: #2a2d34;
  --color-mini-card-bg: #1b1d22;
  --color-mini-card-text: #e8e8ea;
}

/* General styles */
html, body {
  margin: 0;
  padding: 0;
  font-family: 'Verdana', sans-serif;
  background-color: var(--color-bg);
  color: var(--color-border);
  color-scheme: dark;
}

header {
  padding: 12px;
  text-align: center;
}

#userArea {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

#openSettings {
  background: transparent;
  border: 1px solid var(--color-stack-border);
  color: var(--color-border);
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
#openSettings:hover {
  border-color: var(--accent);
  color: var(--accent);
}

#userBadge {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  border: 1px solid var(--color-stack-border);
  background: var(--color-bg-light);
  border-radius: var(--radius-pill);
}
#userBadge #userName {
  font-weight: 700;
}
#userBadge #userStats {
  color: var(--color-muted);
  font-size: 0.9em;
}

.container {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
}

#lobby {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1em;
}

.pill-btn, #createBtn, #joinBtn, .modal-buttons button {
  padding: 0.5em 1.5em;
  font-size: 1em;
  border-radius: var(--radius-md);
  border: none;
  background: var(--color-btn-bg);
  color: var(--color-btn-text);
  cursor: pointer;
  transition: background 0.2s, transform 0.12s ease;
}

#createBtn:hover, #joinBtn:hover, .modal-buttons button:hover {
  background: var(--color-btn-bg-hover);
}

#joinCode {
  padding: 0.5em;
  font-size: 1em;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-stack-border);
  width: 200px;
  background-color: transparent;
  color: var(--color-border);
}

#joinCodeDigits {
  display: flex;
  gap: 8px;
}

.join-digit {
  width: 44px;
  height: 48px;
  text-align: center;
  font-size: 1.2em;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-stack-border);
  background: var(--color-bg-light);
  color: var(--color-border);
  outline: none;
}

.join-digit:focus {
  border-color: var(--accent);
  box-shadow: 0 2px 8px rgba(10,132,255,0.12);
}

#createContainer, #joinContainer {
  border: 1px solid var(--color-stack-border);
  border-radius: var(--radius-md);
  padding: 1em;
  background: var(--color-bg-light);
  width: 300px;
}

#joinContainer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5em;
}

#gameCodeBox {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

#gameCodeBox span {
  padding: 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-bg-light);
  font-size: 1.4em;
  letter-spacing: 5px;
}

.divider {
  display: flex;
  align-items: center;
  text-align: center;
  color: #aaa;
  margin: 1em 0;
}

.divider::before, .divider::after {
  content: '';
  flex: 1;
  border-bottom: 1px solid #444;
}

.divider:not(:empty)::before {
  margin-right: 0.75em;
}
.divider:not(:empty)::after {
  margin-left: 0.75em;
}

.card-container {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  padding: 1em;
}

.card {
  width: 80px;
  margin: 5px;
  cursor: grab;
  border: 1px solid var(--color-card-border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-card);
}

.card.dragging {
  filter: grayscale(70%) brightness(0.9);
  opacity: 0.7;
  transform: scale(0.98);
}

/* opponent ghost styling */
#opponentDrag {
  transition: transform 0.06s linear, left 0.06s linear, top 0.06s linear;
  filter: grayscale(70%) brightness(0.9);
  opacity: 0.9;
}

#opponentCards {
  display: none;
  height: 125px;
}

#tableCards {
  background-color: var(--color-stack-bg);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 40px 40px 20px 40px;
  min-width: 400px;
  min-height: 160px;
  box-shadow: var(--shadow-soft);
}

.stack {
  position: relative;
  display: inline-block;
  width: 100px;
  height: 150px;
  margin: 6px;
}

.stack .card {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translate(-50%, calc(5px * var(--stack-index))) rotate(calc(15deg * var(--stack-index)));
  z-index: calc(var(--stack-index));
  box-shadow: var(--shadow-card);
  border: 1px solid var(--color-card-border);
  border-radius: var(--radius-sm);
  transition: transform 0.2s, box-shadow 0.2s;
}

.stack-number {
  transform: translateY(-30px);
  position: absolute;
  color: var(--color-stack-number);
  font-size: 1.2em;
  font-weight: bold;
  width: 100%;
  text-shadow: 1px 1px 1px var(--color-stack-number-shadow);
}

.hidden { display: none !important; }

/* Toasts */
#toasts {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 3000;
}
.toast {
  background: var(--color-bg-light);
  color: var(--color-modal-text);
  border: 1px solid var(--color-stack-border);
  padding: 10px 12px;
  border-radius: var(--radius-md);
  box-shadow: 0 4px 16px var(--color-modal-shadow);
}
.toast.success { border-color: #28a745; }
.toast.error { border-color: #e55353; }

/* Loader */
#globalLoader {
  position: fixed;
  top: 12px;
  right: 12px;
  background: var(--color-bg-light);
  color: var(--color-modal-text);
  border: 1px solid var(--color-stack-border);
  padding: 8px 12px;
  border-radius: var(--radius-md);
  box-shadow: 0 4px 16px var(--color-modal-shadow);
  z-index: 3000;
}

/* Modal styles */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal {
  background: var(--color-modal-bg);
  color: var(--color-modal-text);
  border-radius: var(--radius-lg);
  padding: 1em 1.2em;
  box-shadow: 0 8px 32px var(--color-modal-shadow);
  min-width: 260px;
  max-width: 90vw;
  max-height: 80vh;
  text-align: center;
  overflow-y: auto;
  font-size: 1em;
}

.modal-entry {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.modal-signin {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.modal-welcome {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.welcome-row {
  width: 40%;
}

.modal-welcome h2 {
  margin: 0.2em 0 0.1em 0;
}
.modal-welcome .sub {
  margin: 0 0 1em 0;
  color: var(--color-muted);
}
.welcome-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  margin: 10px 0;
  text-align: left;
}
.welcome-row input[type="text"] {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-stack-border);
  background: var(--color-bg-light);
  color: var(--color-border);
}

/* Make card summaries wrap nicely */
.modal p {
  margin: 0.5em 0 0.2em 0;
}

.modal-buttons {
  margin-top: 1.5em;
}
.modal-buttons { display: flex; justify-content: center; gap: 12px; }

.debug-info {
  position: fixed;
  bottom: 0;
  left: 0;
  background: var(--color-debug-bg);
  color: var(--color-debug-text);
  font-size: 0.95em;
  padding: 10px 16px;
  border-top-right-radius: var(--radius-lg);
  z-index: 9999;
  min-width: 220px;
  max-width: 350px;
  pointer-events: none;
  opacity: 0.92;
}

.mini-card {
  border: 2px solid var(--color-mini-card-border);
  background: var(--color-mini-card-bg);
  color: var(--color-mini-card-text);
  padding: 3px;
  border-radius: 10px;
  margin: 2px 0px;
}

#opponentLastAction {
  color: var(--color-bg);
}

#bugReport {
  position: absolute;
  bottom: 10px;
  right: 10px;
  color: var(--color-btn-text);
  padding: 5px 10px;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  text-decoration: none;
  background-color: var(--color-btn-bg);
}

/* Opponent back card accent tint */
.card.opponent-back {
  filter: drop-shadow(0 6px 10px rgba(0,0,0,0.25));
  position: relative;
}
.card.opponent-back::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: radial-gradient(120% 120% at 10% 10%, color-mix(in oklab, var(--accent) 45%, transparent), transparent 60%);
  mix-blend-mode: color;
  pointer-events: none;
}

