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

:root {
  --color-felt: #2d8a4e;
  --color-felt-dark: #267a42;
  --color-felt-light: #35a05a;
  --color-felt-darker: #1e6b38;
  --color-primary: #2d7a3a;
  --color-primary-hover: #246b30;
  --color-card-white: #ffffff;
  --color-card-border: #b8b8b8;
  --color-card-red: #cc0000;
  --color-card-black: #111111;
  --color-gold: #f59e0b;
  --color-gold-light: #fef3c7;
  --color-sidebar: #2c2c2c;
  --color-sidebar-light: #3a3a3a;
  --color-header: #1a5c30;
  --font-display: "Inter", system-ui, -apple-system, sans-serif;

  /* Card dimensions — set by JS */
  --card-width: 100px;
  --card-height: 145px;
  --card-gap: 8px;
  --card-radius: 6px;
  --stack-offset: 25px;
  --stack-offset-down: 28px;
}

html {
  height: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  height: 100%;
  font-family: var(--font-display);
  background: #1a5c30;
  color: #f0f0f0;
  line-height: 1.5;
  overflow-x: hidden;
}

a {
  color: inherit;
  text-decoration: none;
}

img {
  max-width: 100%;
  display: block;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

/* ===== HEADER ===== */
.site-header {
  background: var(--color-header);
  padding: 0 16px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  position: relative;
  z-index: 100;
  flex-shrink: 0;
}

.site-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  font-weight: 700;
  color: white;
}

.site-logo .logo-icon {
  font-size: 20px;
}

.site-nav {
  display: flex;
  align-items: center;
  gap: 20px;
}

.site-nav a {
  color: rgba(255,255,255,0.8);
  font-size: 14px;
  font-weight: 500;
  transition: color 0.2s;
}

.site-nav a:hover,
.site-nav a.active {
  color: white;
}

.lang-switcher {
  position: relative;
}

.lang-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: 6px;
  font-size: 13px;
  color: rgba(255,255,255,0.9);
  background: rgba(255,255,255,0.08);
  transition: all 0.2s;
}

.lang-btn:hover {
  background: rgba(255,255,255,0.15);
}

.lang-dropdown {
  display: none;
  position: absolute;
  right: 0;
  top: 100%;
  margin-top: 4px;
  background: #2c2c2c;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 8px;
  overflow: hidden;
  min-width: 140px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  z-index: 200;
}

.lang-dropdown.open {
  display: block;
}

.lang-dropdown a {
  display: block;
  padding: 8px 14px;
  font-size: 13px;
  color: rgba(255,255,255,0.8);
  transition: background 0.2s;
}

.lang-dropdown a:hover,
.lang-dropdown a.active {
  background: rgba(255,255,255,0.1);
  color: white;
}

/* ===== FOOTER ===== */
.site-footer {
  background: var(--color-header);
  padding: 16px;
  text-align: center;
  font-size: 12px;
  color: rgba(255,255,255,0.5);
  border-top: 1px solid rgba(255,255,255,0.1);
  flex-shrink: 0;
}

/* ===== FELT BACKGROUND ===== */
.felt-bg {
  background: linear-gradient(135deg, #2d8a4e 0%, #267a42 40%, #1e6b38 100%);
}

/* ===== HOME PAGE ===== */
.home-page {
  overflow-y: auto;
  height: calc(100vh - 48px);
}

.hero {
  text-align: center;
  padding: 60px 20px 40px;
  background: linear-gradient(180deg, rgba(0,0,0,0.15) 0%, transparent 100%);
}

.hero h1 {
  font-size: 2.5rem;
  font-weight: 800;
  margin-bottom: 12px;
  text-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.hero p {
  font-size: 1.1rem;
  color: rgba(255,255,255,0.8);
  max-width: 600px;
  margin: 0 auto 24px;
}

.hero-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 32px;
  background: white;
  color: #1a5c30;
  font-size: 16px;
  font-weight: 700;
  border-radius: 10px;
  transition: transform 0.2s, box-shadow 0.2s;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.hero-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0,0,0,0.3);
}

/* Game Grid */
.games-section {
  padding: 40px 20px;
  max-width: 1200px;
  margin: 0 auto;
}

.games-section h2 {
  font-size: 1.8rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 8px;
}

.games-section .subtitle {
  text-align: center;
  color: rgba(255,255,255,0.7);
  margin-bottom: 32px;
}

.game-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

@media (min-width: 640px) {
  .game-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (min-width: 1024px) {
  .game-grid { grid-template-columns: repeat(5, 1fr); }
}

.game-card {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 12px;
  padding: 20px 16px;
  text-align: center;
  transition: transform 0.2s, background 0.2s;
}

.game-card:hover {
  transform: translateY(-4px);
  background: rgba(255,255,255,0.14);
}

.game-card .card-icon {
  font-size: 36px;
  margin-bottom: 10px;
}

.game-card h3 {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 6px;
}

.game-card p {
  font-size: 12px;
  color: rgba(255,255,255,0.65);
  margin-bottom: 14px;
  line-height: 1.4;
}

.play-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 20px;
  background: white;
  color: #1a5c30;
  font-size: 13px;
  font-weight: 700;
  border-radius: 8px;
  transition: all 0.2s;
}

.play-btn:hover {
  background: #f0fdf4;
  transform: scale(1.05);
}

/* Features */
.features-section {
  padding: 40px 20px 60px;
  max-width: 1000px;
  margin: 0 auto;
}

.features-section h2 {
  font-size: 1.5rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 24px;
}

.features-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

@media (min-width: 768px) {
  .features-grid { grid-template-columns: repeat(4, 1fr); }
}

.feature-card {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 10px;
  padding: 20px 14px;
  text-align: center;
}

.feature-card .feat-icon {
  font-size: 28px;
  margin-bottom: 8px;
}

.feature-card h3 {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 6px;
}

.feature-card p {
  font-size: 12px;
  color: rgba(255,255,255,0.6);
  line-height: 1.4;
}

/* ===== GAME PAGE LAYOUT ===== */
.game-page {
  display: flex;
  height: calc(100vh - 48px);
  overflow: hidden;
}

.game-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

/* Game Top Bar */
.game-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  background: rgba(0,0,0,0.15);
  flex-shrink: 0;
  gap: 8px;
  flex-wrap: wrap;
}

.game-topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.game-title {
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
}

.all-games-btn {
  padding: 3px 10px;
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: 6px;
  font-size: 12px;
  color: rgba(255,255,255,0.85);
  background: rgba(255,255,255,0.08);
  cursor: pointer;
  position: relative;
}

.all-games-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: 4px;
  background: #2c2c2c;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 8px;
  min-width: 200px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  z-index: 150;
  max-height: 400px;
  overflow-y: auto;
}

.all-games-dropdown.open {
  display: block;
}

.all-games-dropdown a {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  font-size: 13px;
  color: rgba(255,255,255,0.8);
  transition: background 0.2s;
}

.all-games-dropdown a:hover,
.all-games-dropdown a.active {
  background: rgba(255,255,255,0.1);
  color: white;
}

.game-topbar-center {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 13px;
  color: rgba(255,255,255,0.8);
}

.game-topbar-center .stat {
  display: flex;
  align-items: center;
  gap: 4px;
}

.game-topbar-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.topbar-btn {
  padding: 5px 14px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  transition: all 0.2s;
}

.topbar-btn.primary {
  background: #22c55e;
  color: white;
}

.topbar-btn.primary:hover {
  background: #16a34a;
}

.topbar-btn.secondary {
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.2);
  color: rgba(255,255,255,0.9);
}

.topbar-btn.secondary:hover {
  background: rgba(255,255,255,0.18);
}

/* Game Board Area */
.game-board-area {
  flex: 1;
  position: relative;
  overflow: hidden;
  touch-action: none;
  user-select: none;
}

.game-board-area.felt-bg {
  padding: 8px;
}

#game-board {
  width: 100%;
  height: 100%;
  position: relative;
}

/* ===== SIDEBAR ===== */
.game-sidebar {
  width: 280px;
  background: var(--color-sidebar);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
  border-left: 1px solid rgba(255,255,255,0.08);
}

.sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

.sidebar-scroll::-webkit-scrollbar {
  width: 4px;
}
.sidebar-scroll::-webkit-scrollbar-track {
  background: transparent;
}
.sidebar-scroll::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.15);
  border-radius: 2px;
}

/* Sidebar Sections */
.sidebar-section {
  margin-bottom: 16px;
}

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

.sidebar-section-header h3 {
  font-size: 14px;
  font-weight: 700;
}

.sidebar-toggle-btn {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 4px;
  background: #22c55e;
  color: white;
  font-weight: 600;
}

/* Leaderboard Tabs */
.lb-tabs {
  display: flex;
  gap: 2px;
  margin-bottom: 10px;
  background: rgba(255,255,255,0.06);
  border-radius: 6px;
  padding: 2px;
}

.lb-tab {
  flex: 1;
  padding: 5px;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  border-radius: 5px;
  color: rgba(255,255,255,0.6);
  transition: all 0.2s;
}

.lb-tab.active {
  background: #22c55e;
  color: white;
}

.lb-tab:hover:not(.active) {
  color: white;
}

/* Leaderboard Table */
.lb-table {
  width: 100%;
  font-size: 12px;
}

.lb-table th {
  text-align: left;
  padding: 4px 6px;
  color: rgba(255,255,255,0.5);
  font-weight: 600;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.lb-table td {
  padding: 5px 6px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}

.lb-table .rank-1 { color: #f59e0b; }
.lb-table .rank-2 { color: #94a3b8; }
.lb-table .rank-3 { color: #cd7f32; }

.lb-table .score { color: #22c55e; font-weight: 700; }

.lb-no-scores {
  text-align: center;
  color: rgba(255,255,255,0.4);
  padding: 16px;
  font-size: 13px;
}

.lb-refresh {
  display: block;
  margin: 8px auto 0;
  font-size: 11px;
  color: rgba(255,255,255,0.4);
  cursor: pointer;
}
.lb-refresh:hover { color: rgba(255,255,255,0.7); }

/* Instructions */
.instructions-content {
  font-size: 12px;
  line-height: 1.6;
  color: rgba(255,255,255,0.75);
}

.instructions-content h4 {
  color: white;
  font-weight: 700;
  font-size: 13px;
  margin: 10px 0 4px;
}

.instructions-content h4:first-child {
  margin-top: 0;
}

.instructions-content p {
  margin-bottom: 8px;
}

/* Achievements Summary */
.achievements-grid-mini {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.achievement-mini {
  text-align: center;
  padding: 8px 4px;
  background: rgba(255,255,255,0.05);
  border-radius: 6px;
  font-size: 11px;
}

.achievement-mini .val {
  font-weight: 700;
  font-size: 13px;
  display: block;
  margin-bottom: 2px;
}

.achievement-mini .label {
  color: rgba(255,255,255,0.5);
}

/* ===== CARD STYLES ===== */
.playing-card {
  width: var(--card-width);
  height: var(--card-height);
  border-radius: var(--card-radius);
  overflow: hidden;
  position: relative;
  flex-shrink: 0;
  cursor: pointer;
  transition: box-shadow 0.15s;
}

.playing-card img {
  width: 100%;
  height: 100%;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

.playing-card.face-up {
  background: white;
  border: 1px solid var(--color-card-border);
}

.playing-card.face-down {
  border: 1px solid rgba(255,255,255,0.15);
}

.playing-card.highlighted {
  box-shadow: 0 0 0 3px rgba(255, 215, 0, 0.8), 2px 4px 12px rgba(0, 0, 0, 0.4);
}

.playing-card.dragging {
  opacity: 0.4;
}

.card-shadow {
  box-shadow: 1px 2px 4px rgba(0, 0, 0, 0.35);
}

/* Card Slot (empty) */
.card-slot {
  width: var(--card-width);
  height: var(--card-height);
  border-radius: var(--card-radius);
  border: 2px dashed rgba(255,255,255,0.2);
  background: rgba(255,255,255,0.04);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.card-slot .slot-label {
  font-size: calc(var(--card-width) * 0.2);
  color: rgba(255,255,255,0.25);
}

.card-slot.drop-target {
  border-color: rgba(255, 215, 0, 0.6);
  background: rgba(255, 215, 0, 0.08);
}

/* Card Stack */
.card-stack {
  position: relative;
  width: var(--card-width);
}

.card-stack .stack-card {
  position: absolute;
  left: 0;
}

/* Drag overlay */
.drag-overlay {
  position: fixed;
  pointer-events: none;
  z-index: 1000;
  opacity: 0.9;
}

.drag-overlay .playing-card {
  cursor: grabbing;
}

/* ===== GAME LAYOUTS ===== */
/* Common layout */
.card-row {
  display: flex;
  gap: var(--card-gap);
  justify-content: center;
  margin-bottom: var(--card-gap);
}

.card-col {
  width: var(--card-width);
  min-width: 0;
  flex-shrink: 1;
}

.card-row-tableau {
  flex: 1;
  align-items: flex-start;
}

.card-col-tableau {
  min-height: var(--card-height);
}

/* Klondike / standard layout */
.klondike-layout,
.freecell-layout,
.yukon-layout,
.golf-layout,
.scorpion-layout,
.canfield-layout {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: var(--card-gap);
}

/* Spider layout — 10 columns */
.spider-layout {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: var(--card-gap);
}

/* Pyramid layout */
.pyramid-layout {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--card-gap);
}

/* TriPeaks layout */
.tripeaks-layout {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--card-gap);
}

/* Clock layout */
.clock-layout {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--card-gap);
}

.clock-circle {
  position: relative;
  width: min(90vw, 600px);
  height: min(90vw, 600px);
  max-height: calc(100vh - 140px);
  max-width: calc(100vh - 140px);
}

.clock-pile {
  position: absolute;
  transform: translate(-50%, -50%);
}

/* ===== WIN MODAL ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
}

.modal-content {
  background: #2c2c2c;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 16px;
  padding: 32px;
  max-width: 400px;
  width: 90%;
  text-align: center;
}

.modal-content h2 {
  font-size: 24px;
  font-weight: 800;
  margin-bottom: 8px;
}

.modal-content .modal-emoji {
  font-size: 48px;
  margin-bottom: 12px;
}

.modal-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin: 16px 0;
}

.modal-stat {
  text-align: center;
}

.modal-stat .val {
  font-size: 20px;
  font-weight: 700;
  color: #22c55e;
}

.modal-stat .label {
  font-size: 11px;
  color: rgba(255,255,255,0.5);
}

.modal-input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 8px;
  background: rgba(255,255,255,0.06);
  color: white;
  font-size: 14px;
  margin: 12px 0;
  text-align: center;
}

.modal-input::placeholder {
  color: rgba(255,255,255,0.3);
}

.modal-input:focus {
  outline: none;
  border-color: #22c55e;
}

.modal-btn-primary {
  width: 100%;
  padding: 12px;
  background: #22c55e;
  color: white;
  font-size: 15px;
  font-weight: 700;
  border-radius: 8px;
  margin-top: 8px;
  transition: background 0.2s;
}

.modal-btn-primary:hover {
  background: #16a34a;
}

.modal-btn-secondary {
  width: 100%;
  padding: 10px;
  background: transparent;
  border: 1px solid rgba(255,255,255,0.2);
  color: rgba(255,255,255,0.7);
  font-size: 13px;
  font-weight: 600;
  border-radius: 8px;
  margin-top: 8px;
  transition: all 0.2s;
}

.modal-btn-secondary:hover {
  background: rgba(255,255,255,0.06);
  color: white;
}

/* ===== SETTINGS MODAL ===== */
.settings-group {
  text-align: left;
  margin: 16px 0;
}

.settings-group label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  font-size: 13px;
  color: rgba(255,255,255,0.8);
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

/* ===== LEADERBOARD PAGE ===== */
.page-container {
  overflow-y: auto;
  height: calc(100vh - 48px);
  padding: 32px 20px;
}

.page-content {
  max-width: 800px;
  margin: 0 auto;
}

.page-content h1 {
  font-size: 1.8rem;
  font-weight: 800;
  margin-bottom: 24px;
  text-align: center;
}

.filter-bar {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
  justify-content: center;
}

.filter-bar select {
  padding: 6px 12px;
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 6px;
  background: rgba(255,255,255,0.08);
  color: white;
  font-size: 13px;
}

.filter-bar select option {
  background: #2c2c2c;
}

.lb-page-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.lb-page-table th {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 2px solid rgba(255,255,255,0.15);
  color: rgba(255,255,255,0.6);
  font-weight: 600;
}

.lb-page-table td {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.lb-page-table tr:hover {
  background: rgba(255,255,255,0.04);
}

/* ===== ACHIEVEMENTS PAGE ===== */
.achievements-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

@media (min-width: 640px) {
  .achievements-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (min-width: 1024px) {
  .achievements-grid { grid-template-columns: repeat(4, 1fr); }
}

.achievement-card {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 10px;
  padding: 16px;
  text-align: center;
  transition: transform 0.2s;
}

.achievement-card.unlocked {
  border-color: rgba(245, 158, 11, 0.4);
  background: rgba(245, 158, 11, 0.08);
}

.achievement-card.locked {
  opacity: 0.5;
}

.achievement-card .ach-icon {
  font-size: 28px;
  margin-bottom: 8px;
}

.achievement-card h3 {
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 4px;
}

.achievement-card p {
  font-size: 11px;
  color: rgba(255,255,255,0.5);
  line-height: 1.3;
}

/* ===== 404 PAGE ===== */
.error-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: calc(100vh - 48px);
  text-align: center;
}

.error-page h1 {
  font-size: 72px;
  font-weight: 800;
  opacity: 0.3;
}

.error-page p {
  font-size: 18px;
  margin: 12px 0 24px;
  color: rgba(255,255,255,0.6);
}

/* ===== MOBILE RESPONSIVE ===== */
@media (max-width: 900px) {
  .game-page {
    flex-direction: column;
  }

  .game-sidebar {
    width: 100%;
    height: auto;
    max-height: 300px;
    border-left: none;
    border-top: 1px solid rgba(255,255,255,0.08);
  }

  .game-topbar {
    flex-wrap: wrap;
    padding: 4px 8px;
  }

  .game-topbar-center {
    order: 3;
    width: 100%;
    justify-content: center;
    font-size: 12px;
  }

  .hero h1 { font-size: 1.8rem; }
  .hero p { font-size: 0.95rem; }
}

@media (max-width: 480px) {
  .site-nav a:not(:first-child) {
    display: none;
  }

  .game-topbar-right .topbar-btn span {
    display: none;
  }

  .hero h1 { font-size: 1.5rem; }
}
