/* Spider Solitaire Stylesheet - Twilight Spider Web & Lunar Silver Theme */

:root {
  --bg-primary: #181324;
  --bg-secondary: #231b34;
  --bg-surface: #2f2546;
  --bg-card: #fdfcf9;
  --card-back-grad: linear-gradient(135deg, #372f4e 0%, #201a30 100%);
  --silk-glow: rgba(164, 136, 245, 0.45);
  --accent-gold: #e6c875;
  --accent-moon: #d1d8ec;
  --text-primary: #f2f0f8;
  --text-secondary: #a9a1c2;
  --suit-red: #d9383a;
  --suit-black: #1d1b26;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow-card: 0 4px 10px rgba(0, 0, 0, 0.35);
  --shadow-button: 0 4px 12px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: radial-gradient(circle at 50% 20%, #2a203f 0%, #171224 85%);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  position: relative;
}

/* Spider web ambient background texture */
body::before {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  background-image: 
    radial-gradient(circle at 15% 15%, rgba(164, 136, 245, 0.08) 0%, transparent 40%),
    radial-gradient(circle at 85% 25%, rgba(230, 200, 117, 0.06) 0%, transparent 35%);
  z-index: 0;
}

/* Header & Machine Status Bar */
.game-header {
  position: relative;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  background: rgba(24, 19, 36, 0.85);
  border-bottom: 1px solid rgba(164, 136, 245, 0.15);
  backdrop-filter: blur(8px);
}

.header-left, .header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.nav-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 14px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.05);
  transition: all 0.2s ease;
}

.nav-link:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.1);
  transform: translateY(-1px);
}

.brand-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-icon {
  font-size: 20px;
}

.icon-btn {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.18s ease;
}

.icon-btn:hover {
  background: rgba(164, 136, 245, 0.18);
  border-color: rgba(164, 136, 245, 0.35);
  transform: translateY(-1px);
}

.icon-btn:active {
  transform: translateY(1px);
}

/* Main Container Layout */
.main-stage-container {
  position: relative;
  z-index: 1;
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 310px;
  gap: 20px;
  max-width: 1320px;
  width: 100%;
  margin: 0 auto;
  padding: 16px 20px 80px;
}

/* Left Board Stage */
.board-stage {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

/* Stage Top Bar: Stock and Foundations */
.stage-top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(35, 27, 52, 0.6);
  border: 1px solid rgba(164, 136, 245, 0.12);
  border-radius: var(--radius-md);
  padding: 12px 18px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
}

.stock-section {
  display: flex;
  align-items: center;
  gap: 12px;
}

.stock-cocoon {
  position: relative;
  width: 66px;
  height: 92px;
  border-radius: var(--radius-sm);
  background: var(--card-back-grad);
  border: 1px solid rgba(164, 136, 245, 0.3);
  cursor: pointer;
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: all 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.stock-cocoon:hover:not(.disabled) {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(164, 136, 245, 0.35);
  border-color: rgba(164, 136, 245, 0.55);
}

.stock-cocoon.disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.stock-icon {
  font-size: 24px;
}

.stock-badge {
  margin-top: 4px;
  font-size: 11px;
  font-weight: 700;
  color: var(--accent-gold);
  background: rgba(0, 0, 0, 0.45);
  padding: 2px 6px;
  border-radius: 8px;
}

.stock-label-group {
  display: flex;
  flex-direction: column;
}

.stock-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.stock-sub {
  font-size: 11px;
  color: var(--text-secondary);
}

/* Foundation 8 Egg Sockets */
.foundations-section {
  display: flex;
  align-items: center;
  gap: 8px;
}

.foundation-slot {
  width: 44px;
  height: 60px;
  border-radius: var(--radius-sm);
  background: rgba(24, 19, 36, 0.65);
  border: 1px dashed rgba(164, 136, 245, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: var(--text-secondary);
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  position: relative;
}

.foundation-slot.completed {
  border-style: solid;
  border-color: var(--accent-gold);
  background: linear-gradient(135deg, rgba(230, 200, 117, 0.25), rgba(164, 136, 245, 0.2));
  color: var(--accent-gold);
  box-shadow: 0 0 12px rgba(230, 200, 117, 0.35);
  transform: scale(1.04);
}

/* Tableau Grid */
.tableau-area {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 8px;
  flex: 1;
  min-height: 540px;
  background: rgba(24, 19, 36, 0.4);
  border: 1px solid rgba(164, 136, 245, 0.08);
  border-radius: var(--radius-md);
  padding: 12px 10px;
}

.tableau-column {
  position: relative;
  min-height: 480px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.04);
  transition: background-color 0.2s ease;
}

.tableau-column.drag-over {
  background: rgba(164, 136, 245, 0.12);
  border-color: rgba(164, 136, 245, 0.4);
}

.tableau-column.hint-target {
  background: radial-gradient(circle at 50% 30%, rgba(230, 200, 117, 0.2), transparent 75%);
  border-color: rgba(230, 200, 117, 0.4);
}

/* Individual Playing Card */
.card {
  position: absolute;
  left: 0;
  right: 0;
  width: 100%;
  aspect-ratio: 5 / 7.2;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-card);
  cursor: pointer;
  transition: transform 0.14s ease, box-shadow 0.14s ease;
  user-select: none;
  font-family: inherit;
}

/* Card Face Down */
.card.face-down {
  background: var(--card-back-grad);
  border: 1px solid rgba(164, 136, 245, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
}

.card.face-down::after {
  content: "";
  width: 70%;
  height: 70%;
  border-radius: 4px;
  border: 1px solid rgba(164, 136, 245, 0.15);
  background: repeating-linear-gradient(
    45deg,
    transparent,
    transparent 4px,
    rgba(164, 136, 245, 0.05) 4px,
    rgba(164, 136, 245, 0.05) 8px
  );
}

/* Card Face Up */
.card.face-up {
  background: var(--bg-card);
  border: 1px solid rgba(0, 0, 0, 0.15);
  padding: 4px 6px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.card.suit-spades, .card.suit-clubs {
  color: var(--suit-black);
}

.card.suit-hearts, .card.suit-diamonds {
  color: var(--suit-red);
}

.card-top, .card-bottom {
  display: flex;
  align-items: center;
  gap: 2px;
  font-weight: 700;
  font-size: 13px;
  line-height: 1;
}

.card-bottom {
  transform: rotate(180deg);
  align-self: flex-end;
}

.card-center {
  align-self: center;
  font-size: 20px;
  opacity: 0.85;
}

/* Radial Soft Glow Selection - Strictly NO border/stroke circle */
.card.selected {
  transform: translateY(-6px);
  box-shadow: 0 0 18px rgba(164, 136, 245, 0.8), 0 0 32px rgba(164, 136, 245, 0.4);
  z-index: 100 !important;
}

.card.hint-source {
  animation: pulseRadialGlow 1.4s infinite alternate;
}

@keyframes pulseRadialGlow {
  0% {
    box-shadow: 0 0 10px rgba(230, 200, 117, 0.4);
  }
  100% {
    box-shadow: 0 0 24px rgba(230, 200, 117, 0.9), 0 0 40px rgba(230, 200, 117, 0.4);
  }
}

/* Right Control HUD */
.control-dock {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card-plaque {
  background: linear-gradient(145deg, #2c2242, #1f1830);
  border: 1px solid rgba(164, 136, 245, 0.2);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
  position: relative;
  overflow: hidden;
}

.card-plaque::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent-gold), transparent);
}

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

.plaque-chapter {
  font-size: 14px;
  font-weight: 700;
  color: var(--accent-gold);
}

.plaque-subtitle {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 12px;
  line-height: 1.4;
}

.btn-select-level {
  width: 100%;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: rgba(164, 136, 245, 0.12);
  border: 1px solid rgba(164, 136, 245, 0.25);
  color: var(--text-primary);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-select-level:hover {
  background: rgba(164, 136, 245, 0.25);
  border-color: rgba(164, 136, 245, 0.45);
}

/* HUD Progress Stats */
.stats-panel {
  background: rgba(35, 27, 52, 0.6);
  border: 1px solid rgba(164, 136, 245, 0.12);
  border-radius: var(--radius-md);
  padding: 14px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.stat-box {
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: rgba(24, 19, 36, 0.45);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.04);
}

.stat-label {
  font-size: 11px;
  color: var(--text-secondary);
}

.stat-value {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.stat-value.gold {
  color: var(--accent-gold);
}

/* Mode Selection Tabs */
.mode-tabs {
  display: flex;
  gap: 6px;
  background: rgba(24, 19, 36, 0.5);
  padding: 4px;
  border-radius: var(--radius-sm);
}

.mode-tab {
  flex: 1;
  text-align: center;
  padding: 6px 8px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 4px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.18s ease;
}

.mode-tab.active {
  background: rgba(164, 136, 245, 0.25);
  color: var(--text-primary);
}

/* Action Dock Buttons */
.action-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(164, 136, 245, 0.25);
  background: linear-gradient(180deg, #3d3159 0%, #2b2241 100%);
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow-button);
  transition: all 0.18s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.action-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  border-color: rgba(164, 136, 245, 0.5);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35);
}

.action-btn:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}

.action-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.action-btn.btn-deal {
  background: linear-gradient(180deg, #5b448a 0%, #3e2d63 100%);
  border-color: rgba(164, 136, 245, 0.45);
}

.action-btn.btn-deal:hover:not(:disabled) {
  background: linear-gradient(180deg, #6b51a1 0%, #4a3775 100%);
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 12, 23, 0.75);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  padding: 20px;
}

.modal-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.modal-content {
  background: linear-gradient(145deg, #2b2142, #1d162f);
  border: 1px solid rgba(164, 136, 245, 0.25);
  border-radius: var(--radius-lg);
  max-width: 520px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  padding: 24px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.55);
  transform: translateY(12px) scale(0.97);
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-backdrop.open .modal-content {
  transform: translateY(0) scale(1);
}

.modal-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--accent-gold);
  margin-bottom: 14px;
}

.rules-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 20px;
}

.rule-item {
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-primary);
  background: rgba(24, 19, 36, 0.45);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--accent-gold);
}

/* Level Grid in Modal */
.level-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}

.level-card-btn {
  aspect-ratio: 1;
  background: rgba(24, 19, 36, 0.55);
  border: 1px solid rgba(164, 136, 245, 0.2);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-weight: 700;
  transition: all 0.2s ease;
  font-size: 14px;
}

.level-card-btn:hover {
  background: rgba(164, 136, 245, 0.25);
  border-color: rgba(164, 136, 245, 0.45);
  transform: scale(1.05);
}

.level-card-btn.active {
  border-color: var(--accent-gold);
  background: rgba(230, 200, 117, 0.2);
}

.level-stars-mini {
  font-size: 10px;
  color: var(--accent-gold);
  margin-top: 2px;
}

/* Victory Modal Specifics */
.victory-celebration {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.victory-icon {
  font-size: 52px;
  animation: bounceCelebration 1.2s infinite alternate ease-in-out;
}

@keyframes bounceCelebration {
  0% { transform: translateY(0) scale(1); }
  100% { transform: translateY(-8px) scale(1.08); }
}

.victory-stars {
  font-size: 28px;
  color: var(--accent-gold);
  letter-spacing: 4px;
}

.victory-stats-row {
  display: flex;
  justify-content: space-around;
  width: 100%;
  background: rgba(24, 19, 36, 0.5);
  padding: 12px;
  border-radius: var(--radius-md);
}

.victory-stat-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  width: 100%;
}

.btn-primary {
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  background: var(--accent-gold);
  color: #171224;
  border: none;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.18s ease;
}

.btn-primary:hover {
  background: #f0d588;
  transform: translateY(-1px);
}

/* Mobile Responsive */
@media (max-width: 900px) {
  .main-stage-container {
    grid-template-columns: 1fr;
    padding-bottom: max(68px, calc(16px + env(safe-area-inset-bottom)));
  }

  .stage-top-bar {
    padding: 8px 12px;
  }

  .foundation-slot {
    width: 32px;
    height: 46px;
    font-size: 14px;
  }

  .stock-cocoon {
    width: 50px;
    height: 70px;
  }

  .card-top, .card-bottom {
    font-size: 10px;
  }

  .card-center {
    font-size: 14px;
  }

  .tableau-area {
    gap: 4px;
    padding: 8px 4px;
  }
}

/* Accessibility & Reduced Motion */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
