/**
 * Solitaire for Mom - Main Stylesheet
 *
 * ARCHITECTURE:
 * 1. CSS Variables (Design Tokens)
 * 2. Reset & Base Elements
 * 3. Typography
 * 4. Utility Classes
 * 5. Generic Component Patterns
 * 6. Layout Primitives
 * 7. Page-Specific Styles
 *
 * PRINCIPLES:
 * - Mobile-first, Apple-quality UX
 * - Semantic HTML first
 * - Generic patterns, not page-specific classes
 * - Affordances and feedback everywhere
 *
 * NOTE: Game-specific styles (tableau, cards, animations) are in solitaire.css
 */

/* ============================================================================
   1. CSS VARIABLES - Design Tokens
   ============================================================================ */

:root {
  /* Colors - Primary (teal flowershop feel) */
  --color-gold: #d4af37;
  --color-gold-light: #e5c76b;
  --color-gold-dark: #b8962e;
  --color-teal-dark: #0d2528;
  --color-teal-felt: #1a5f5f;
  --color-teal-felt-light: #237a7a;
  --color-teal-border: #2d5a5a;

  /* Colors - Feedback */
  --color-success: #10b981;
  --color-success-glow: rgba(16, 185, 129, 0.4);
  --color-error: #ef4444;

  /* Colors - Neutrals */
  --color-bg-dark: #0a0e1a;
  --color-text-primary: #ffffff;
  --color-text-secondary: #cbd5e1;
  --color-text-muted: #94a3b8;
  --color-text-faint: #64748b;
  --color-text-dark: #0a0e1a;

  /* Colors - Cards */
  --color-card-red: #dc2626;
  --color-card-black: #1a1a2e;
  --color-card-back: #1a365d;
  --color-card-back-light: #2d4a6f;

  /* Spacing */
  --space-2xs: 4px;
  --space-xs: 8px;
  --space-sm: 12px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-2xl: 40px;

  /* Border Radius */
  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
  --shadow-gold: 0 4px 20px rgba(212, 175, 55, 0.4);
  --shadow-gold-sm: 0 2px 12px rgba(212, 175, 55, 0.3);
  --shadow-inset: inset 0 2px 4px rgba(0, 0, 0, 0.2);

  /* Transitions */
  --transition-fast: 0.1s ease-out;
  --transition-base: 0.2s ease-out;
  --transition-slow: 0.3s ease-out;

  /* Card dimensions - Solitaire specific */
  --card-width: clamp(38px, 11vw, 52px);
  --card-height: calc(var(--card-width) * 1.4);
  --card-radius: 4px;
  --card-gap: clamp(4px, 1.5vw, 8px);
  --card-overlap-facedown: clamp(6px, 2vw, 10px);
  --card-overlap-faceup: clamp(16px, 5vw, 24px);

  /* Layout */
  --header-height: 48px;
  --safe-area-top: env(safe-area-inset-top, 0px);
  --safe-area-bottom: env(safe-area-inset-bottom, 0px);
}

/* ============================================================================
   2. RESET & BASE ELEMENTS
   ============================================================================ */

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

html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Roboto, sans-serif;
  background: var(--color-bg-dark);
  color: var(--color-text-primary);
  line-height: 1.5;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

#app {
  width: 100%;
  max-width: 430px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  background: radial-gradient(ellipse at 50% 0%, var(--color-teal-felt) 0%, var(--color-teal-dark) 100%);
  position: relative;
  overflow: hidden;
}

a {
  color: var(--color-gold);
  text-decoration: none;
  transition: opacity var(--transition-base);
}

a:hover {
  opacity: 0.8;
}

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

/* ============================================================================
   3. TYPOGRAPHY SYSTEM
   ============================================================================ */

/* Titles - display/emphasis */
h1, .h1 { font-size: 52px; font-weight: 900; line-height: 1.2; }
h2, .h2 { font-size: 36px; font-weight: 800; line-height: 1.2; }
h3, .h3 { font-size: 28px; font-weight: 800; line-height: 1.2; }
h4, .h4 { font-size: 20px; font-weight: 700; line-height: 1.2; }
h5, .h5 { font-size: 16px; font-weight: 700; line-height: 1.2; }
h6, .h6 { font-size: 14px; font-weight: 600; line-height: 1.2; }

h1, h2, h3, h4, h5, h6 {
  color: var(--color-text-primary);
}

/* Text - body/copy */
.t1 { font-size: 15px; font-weight: 400; }
.t2 { font-size: 13px; font-weight: 400; }
.t3 { font-size: 11px; font-weight: 400; }

p {
  color: var(--color-text-secondary);
}

/* Text colors */
.c-primary   { color: var(--color-text-primary); }
.c-secondary { color: var(--color-text-secondary); }
.c-muted     { color: var(--color-text-muted); }
.c-faint     { color: var(--color-text-faint); }
.c-dark      { color: var(--color-text-dark); }
.c-gold      { color: var(--color-gold); }
.c-success   { color: var(--color-success); }
.c-error     { color: var(--color-error); }

/* Text alignment */
.text-center { text-align: center; }

/* Text effects */
.shimmer-gold {
  background: linear-gradient(135deg, #d4af37 0%, #ffd700 50%, #d4af37 100%);
  background-size: 200% 200%;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: shimmer 3s ease-in-out infinite;
  letter-spacing: 4px;
  filter: drop-shadow(0 0 30px rgba(212, 175, 55, 0.6));
}

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

/* Monospace for numbers (timer, counters) */
.mono {
  font-family: 'SF Mono', 'Menlo', 'Monaco', 'Courier New', monospace;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.5px;
}

/* ============================================================================
   4. GENERIC COMPONENT PATTERNS
   ============================================================================ */

/* Buttons */
button {
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  background: transparent;
  color: inherit;
  padding: 0;
  transition: all var(--transition-base);
  -webkit-tap-highlight-color: transparent;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Icon Button (hamburger, help, etc.) */
.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--color-text-secondary);
  transition: all var(--transition-base);
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.2);
  color: var(--color-text-primary);
}

.icon-btn:active {
  transform: scale(0.95);
  background: rgba(255, 255, 255, 0.15);
}

/* Primary CTA Button */
.btn-primary {
  width: 100%;
  padding: 16px 24px;
  background: linear-gradient(135deg, var(--color-gold) 0%, var(--color-gold-dark) 100%);
  border: none;
  border-radius: var(--radius-md);
  color: var(--color-text-dark);
  font-size: 17px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  box-shadow: var(--shadow-gold);
  transition: all var(--transition-base);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 24px rgba(212, 175, 55, 0.5);
}

.btn-primary:active {
  transform: translateY(0);
  box-shadow: var(--shadow-gold-sm);
}

/* Secondary Button */
.btn-secondary {
  width: 100%;
  padding: 14px 24px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(212, 175, 55, 0.3);
  border-radius: var(--radius-md);
  color: var(--color-gold);
  font-size: 14px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  cursor: pointer;
  transition: all var(--transition-base);
}

.btn-secondary:hover {
  background: rgba(212, 175, 55, 0.1);
  border-color: var(--color-gold);
}

/* Link Button */
.btn-link {
  padding: 12px;
  color: var(--color-text-muted);
  font-size: 14px;
  background: transparent;
  border: none;
  cursor: pointer;
}

.btn-link:hover {
  color: var(--color-gold);
}

/* Danger Button */
.btn-danger {
  width: 100%;
  padding: 14px 24px;
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: var(--radius-md);
  color: var(--color-error);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-base);
}

.btn-danger:hover {
  background: rgba(239, 68, 68, 0.2);
  border-color: var(--color-error);
}

/* Card Pattern (glass morphism) */
.card {
  background: rgba(255, 255, 255, 0.03);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-lg);
  padding: var(--space-md);
}

/* Option Card Pattern (selectable toggle) */
.option-group {
  display: flex;
  gap: var(--space-sm);
}

.option-card {
  flex: 1;
  padding: var(--space-md);
  background: rgba(255, 255, 255, 0.03);
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-md);
  text-align: center;
  cursor: pointer;
  transition: all var(--transition-base);
}

.option-card:hover {
  border-color: rgba(212, 175, 55, 0.3);
}

.option-card.active {
  border-color: var(--color-gold);
  background: rgba(212, 175, 55, 0.1);
}

.option-card.active .h2 {
  color: var(--color-gold);
}

/* Overlay Pattern (modal backdrop) */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}

.overlay.hidden {
  display: none;
}

/* Panel Pattern (modal content) */
.panel {
  background: var(--color-teal-dark);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  width: 100%;
  max-width: 280px;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.panel-item {
  width: 100%;
  padding: 14px 16px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-md);
  color: var(--color-text-primary);
  font-size: 15px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  transition: all var(--transition-base);
}

.panel-item:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--color-gold);
  color: var(--color-gold);
}

/* ============================================================================
   5. LAYOUT PRIMITIVES
   ============================================================================ */

/* Flex utilities */
.flex-center {
  display: flex;
  align-items: center;
  justify-content: center;
}

.flex-col {
  display: flex;
  flex-direction: column;
}

.flex-row {
  display: flex;
  flex-direction: row;
  align-items: center;
}

.gap-sm { gap: var(--space-sm); }
.gap-md { gap: var(--space-md); }
.gap-lg { gap: var(--space-lg); }

/* Spacing utilities */
.mt-md { margin-top: var(--space-md); }
.mt-lg { margin-top: var(--space-lg); }
.mt-xl { margin-top: var(--space-xl); }
.mb-xs { margin-bottom: var(--space-xs); }
.mb-sm { margin-bottom: var(--space-sm); }
.mb-md { margin-bottom: var(--space-md); }
.mb-lg { margin-bottom: var(--space-lg); }
.mb-xl { margin-bottom: var(--space-xl); }
.p-sm { padding: var(--space-sm); }
.p-md { padding: var(--space-md); }
.p-lg { padding: var(--space-lg); }
.p-xl { padding: var(--space-xl); }

/* Game Header */
.game-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  padding-top: var(--safe-area-top);
  background: linear-gradient(180deg, rgba(10, 14, 26, 0.95) 0%, rgba(10, 14, 26, 0) 100%);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-left: var(--space-sm);
  padding-right: var(--space-sm);
}

.game-header-content {
  width: 100%;
  max-width: 430px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
}

/* Stats display (moves, timer) */
.game-stats {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  flex: 1;
  justify-content: center;
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 60px;
}

/* Emoji meter stat item - compact inline display */
.stat-item.emoji-stat {
  min-width: 40px;
  width: 40px;
  height: 40px;
}

.stat-item.emoji-stat .emoji-meter {
  width: 40px;
  height: 40px;
}

.stat-item.emoji-stat .emoji-meter-emoji {
  font-size: 28px;
}

/* Game Container */
.game-container {
  padding-top: calc(var(--header-height) + var(--safe-area-top) + var(--space-xs));
  padding-bottom: calc(var(--safe-area-bottom) + var(--space-md));
  padding-left: var(--space-sm);
  padding-right: var(--space-sm);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

/* Hamburger Menu Icon */
.hamburger {
  width: 20px;
  height: 14px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.hamburger-line {
  width: 100%;
  height: 2px;
  background: currentColor;
  border-radius: 1px;
  transition: all var(--transition-base);
}

.icon-btn:hover .hamburger-line {
  background: var(--color-gold);
}

/* ============================================================================
   6. RESPONSIVE ADJUSTMENTS
   ============================================================================ */

/* Larger phones */
@media (min-width: 390px) {
  :root {
    --card-width: clamp(42px, 12vw, 54px);
  }
}

/* Desktop - cap card size to fit 430px container */
@media (min-width: 500px) {
  :root {
    --card-width: 52px;
    --card-gap: 6px;
  }
}

/* Small phones */
@media (max-width: 350px) {
  :root {
    --card-width: 36px;
    --card-gap: 3px;
    --card-overlap-facedown: 5px;
    --card-overlap-faceup: 14px;
  }
}

/* Landscape orientation */
@media (orientation: landscape) and (max-height: 500px) {
  :root {
    --header-height: 40px;
    --card-width: clamp(32px, 8vh, 44px);
  }

  .game-container {
    gap: var(--space-xs);
  }
}

/* ============================================================================
   7. PAGE-SPECIFIC STYLES
   ============================================================================ */

/* --- Splash Page --- */

.splash-page {
  position: relative;
  overflow: hidden;
}

.splash-page #starfield {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

.splash-overlay {
  position: relative;
  z-index: 10;
  min-height: 100vh;
  min-height: 100dvh;
  justify-content: space-between;
  padding: 60px 20px;
  padding-bottom: max(40px, var(--safe-area-bottom));
  pointer-events: none;
}

.splash-overlay > * {
  pointer-events: auto;
}

/* --- Post-Game Page --- */

.postgame-page {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-lg);
}

.postgame-content {
  width: 100%;
  max-width: 340px;
}

.result-stats {
  display: flex;
  justify-content: center;
  gap: var(--space-xl);
}

.result-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}


.postgame-actions {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

/* --- Generic Page Layout --- */

.page {
  min-height: 100vh;
  min-height: 100dvh;
}

.page-header {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  padding: var(--space-sm) var(--space-md);
  padding-top: max(var(--space-sm), var(--safe-area-top));
  background: linear-gradient(180deg, rgba(13, 37, 40, 0.98) 0%, rgba(13, 37, 40, 0.9) 100%);
  z-index: 50;
}

.page-header h1 {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  font-size: 18px;
  font-weight: 700;
}

.page-content {
  padding: var(--space-lg);
  padding-bottom: max(var(--space-xl), var(--safe-area-bottom));
  min-height: calc(100vh - 80px);
}

/* --- Stats Page --- */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-sm);
}

.stat-card {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  text-align: center;
}

.records-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.record-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-sm) var(--space-md);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-md);
}


/* --- Help Page --- */

.help-tips {
  list-style: none;
  padding: 0;
}

.help-tips li {
  padding: var(--space-xs) 0;
  padding-left: var(--space-md);
  position: relative;
}

.help-tips li::before {
  content: '•';
  position: absolute;
  left: 0;
  color: var(--color-gold);
}

.help-illustration {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: var(--space-sm) var(--space-md);
  background: rgba(0, 0, 0, 0.2);
  border-radius: var(--radius-md);
}

/* ============================================================================
   8. UTILITY CLASSES
   ============================================================================ */

.hidden {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
