/* ============================================================
   SCREEN-TEXT BIOME: CONWAY'S GAME OF LIFE — Stylesheet
   Glassmorphism, High-contrast Glowing Grid, and Responsive Layout
   ============================================================ */

:root {
  --color-bg:              #FAF5EB; /* Warm Luxurious Cream */
  --color-bg-2:            #FFFFFF; /* Pure White background */
  --color-surface:         rgba(255, 255, 255, 0.85); /* Light glass card */
  --color-surface-2:       #F5EFEB; /* Soft Linen */
  --color-border:          rgba(12, 35, 64, 0.06); /* Transparent deep navy border */
  --color-border-hover:    rgba(13, 92, 58, 0.25);

  --color-primary:         #0C2340; /* Deep Navy Blue */
  --color-primary-glow:    rgba(12, 35, 64, 0.15);
  --color-primary-dim:     rgba(12, 35, 64, 0.05);
  --color-secondary:       #0D5C3A; /* Rich Emerald Green */
  --color-secondary-glow:  rgba(13, 92, 58, 0.12);
  --color-accent:          #B45309; /* Warm Corporate Gold/Amber */

  --color-text:            #0F172A; /* Deep slate-charcoal */
  --color-text-muted:      #475569; /* Slate gray */
  --color-text-subtle:     #94A3B8;

  --font-display: 'Outfit', sans-serif;
  --font-body:    'Inter', sans-serif;

  --radius-sm:   6px;
  --radius-md:   12px;
  --radius-lg:   20px;
  --radius-xl:   32px;
  --radius-full: 9999px;

  --transition-fast:   150ms ease;
  --transition-base:   250ms ease;
  --transition-slow:   450ms ease;
  --transition-spring: 400ms cubic-bezier(0.34, 1.56, 0.64, 1);

  --shadow-card:       0 10px 30px -10px rgba(12, 35, 64, 0.06), 0 1px 3px rgba(12, 35, 64, 0.02);
  --shadow-card-hover: 0 20px 40px -12px rgba(12, 35, 64, 0.12), 0 0 0 1px rgba(13, 92, 58, 0.18);
}

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

html {
  scroll-behavior: smooth;
  font-size: 16px;
}

body {
  font-family: var(--font-body);
  background: var(--color-bg);
  background-image: 
    radial-gradient(at 0% 0%, rgba(13, 92, 58, 0.04) 0px, transparent 50%),
    radial-gradient(at 100% 100%, rgba(12, 35, 64, 0.03) 0px, transparent 50%);
  color: var(--color-text);
  line-height: 1.6;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

button, select {
  font-family: inherit;
  outline: none;
}

.skip-link {
  position: absolute;
  top: -100%;
  left: 1rem;
  background: var(--color-primary);
  color: #fff;
  padding: .5rem 1.5rem;
  border-radius: var(--radius-md);
  font-weight: 700;
  font-size: .9rem;
  z-index: 9999;
  transition: top var(--transition-fast);
}
.skip-link:focus {
  top: 1rem;
}

/* Focused elements get a nice amber ring */
:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 3px;
  border-radius: var(--radius-sm);
}

/* ============================================================
   AMBIENT GLOWS
   ============================================================ */
.ambient-glow {
  position: absolute;
  border-radius: 50%;
  filter: blur(140px);
  pointer-events: none;
  z-index: 0;
  opacity: 0.3;
}
.bg-glow-1 {
  width: 600px;
  height: 600px;
  background: rgba(13, 92, 58, 0.03);
  top: -100px;
  left: -100px;
}
.bg-glow-2 {
  width: 500px;
  height: 500px;
  background: rgba(12, 35, 64, 0.02);
  bottom: 50px;
  right: -50px;
}

/* ============================================================
   APPLICATION LAYOUT
   ============================================================ */
.app-wrapper {
  position: relative;
  z-index: 1;
  max-width: 1240px;
  margin: 0 auto;
  padding: 0 1.5rem;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.app-header {
  height: 90px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: 2rem;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.logo-icon {
  font-size: 2.2rem;
  animation: pulse-glow 3s ease-in-out infinite;
}
@keyframes pulse-glow {
  0%, 100% { transform: scale(1); filter: drop-shadow(0 0 2px var(--color-primary-glow)); }
  50% { transform: scale(1.08); filter: drop-shadow(0 0 10px rgba(13,92,58,0.3)); }
}

.logo-text-group h1 {
  font-family: var(--font-display);
  font-size: 1.6rem;
  font-weight: 900;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--color-primary), var(--color-secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1;
}

.logo-sub {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 700;
}

.nav-back-link {
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--color-text-muted);
  transition: color var(--transition-fast);
  text-decoration: none;
}
.nav-back-link:hover {
  color: var(--color-primary);
}

/* Main Grid Workspace */
.main-content {
  display: grid;
  grid-template-columns: 1.6fr 1fr;
  gap: 2.5rem;
  flex: 1;
  align-items: flex-start;
  margin-bottom: 3rem;
}

/* ============================================================
   GLASS CARD BASE
   ============================================================ */
.glass-card {
  background: var(--color-surface);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  box-shadow: var(--shadow-card);
  transition: border-color var(--transition-base), box-shadow var(--transition-base);
}
.glass-card:hover {
  border-color: rgba(12, 35, 64, 0.12);
  box-shadow: var(--shadow-card-hover);
}

/* ============================================================
   GRID BOARD (LEFT COLUMN)
   ============================================================ */
.grid-panel {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.grid-card {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.grid-board-container {
  background: #ffffff;
  border: 1px solid rgba(12, 35, 64, 0.06);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  overflow: auto;
  display: flex;
  justify-content: center;
  align-items: center;
  box-shadow: inset 0 2px 8px rgba(12, 35, 64, 0.02);
}

/* Conway's Board rendering */
#life-grid {
  display: grid;
  grid-template-columns: repeat(40, 15px);
  grid-template-rows: repeat(25, 15px);
  gap: 2px;
  background: rgba(12, 35, 64, 0.03);
  padding: 4px;
  border-radius: var(--radius-sm);
  user-select: none;
  cursor: crosshair;
}

#life-grid:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 6px;
}

/* Cells */
.cell {
  background: rgba(12, 35, 64, 0.06);
  border-radius: 3px;
  transition: background-color 80ms ease, box-shadow 80ms ease;
  position: relative;
  cursor: pointer;
}

.cell:hover {
  background: rgba(13, 92, 58, 0.15);
}

/* Active Cell Glow */
.cell.alive {
  background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-secondary) 100%);
  box-shadow: 0 0 6px rgba(13, 92, 58, 0.4), 0 0 15px rgba(12, 35, 64, 0.1);
  animation: cell-birth 220ms cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes cell-birth {
  0% { transform: scale(0.4); opacity: 0.5; }
  100% { transform: scale(1); opacity: 1; }
}

/* Grid Navigation Cursor */
.cell.focused {
  outline: 2px solid var(--color-accent);
  outline-offset: -1px;
  z-index: 10;
}

/* Instructions card text formatting */
.instructions-panel {
  border-top: 1px solid var(--color-border);
  padding-top: 1.25rem;
}

.instructions-panel h3 {
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--color-text);
  margin-bottom: 0.6rem;
}

.shortcuts-list {
  list-style: none;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem 1.5rem;
}

.shortcuts-list li {
  font-size: 0.82rem;
  color: var(--color-text-muted);
  line-height: 1.4;
}

.shortcuts-list strong {
  color: var(--color-text);
}

kbd {
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  box-shadow: 0 2px 0 rgba(12, 35, 64, 0.15);
  color: var(--color-accent);
  display: inline-block;
  font-family: monospace;
  font-size: 0.75rem;
  font-weight: bold;
  padding: 0.1rem 0.35rem;
  margin: 0 0.1rem;
}

/* ============================================================
   SIDEBAR CONTROLS (RIGHT COLUMN)
   ============================================================ */
.sidebar-panel {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.panel-card {
  box-shadow: var(--shadow-card);
}
.panel-card:hover {
  border-color: rgba(12, 35, 64, 0.1);
}

.card-header {
  margin-bottom: 1.25rem;
}

.card-badge {
  display: inline-block;
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--color-secondary);
  background: var(--color-secondary-glow);
  border: 1px solid rgba(13, 92, 58, 0.25);
  padding: 0.2rem 0.75rem;
  border-radius: var(--radius-full);
  margin-bottom: 0.4rem;
}

.card-header h2 {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--color-text);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 0.9rem;
  border: none;
  cursor: pointer;
  border-radius: var(--radius-full);
  min-height: 48px;
  padding: 0 1.5rem;
  transition: all var(--transition-spring);
}

.btn-primary {
  background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-secondary) 100%);
  color: #ffffff;
  box-shadow: 0 4px 16px rgba(12, 35, 64, 0.12);
}
.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(12, 35, 64, 0.22);
}
.btn-primary:active {
  transform: translateY(0);
}

.btn-secondary {
  background: transparent;
  color: var(--color-text);
  border: 1px solid var(--color-border);
}
.btn-secondary:hover {
  border-color: var(--color-primary);
  background: var(--color-primary-dim);
  transform: translateY(-1px);
}
.btn-secondary:active {
  transform: translateY(0);
}

/* Select Form Style */
.preset-dropdown {
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  color: var(--color-text);
  font-family: var(--font-body);
  font-size: 0.95rem;
  padding: 0.85rem 1.1rem;
  width: 100%;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  background-image: url("data:image/svg+xml;utf8,<svg fill='white' height='24' viewBox='0 0 24 24' width='24' xmlns='http://www.w3.org/2000/svg'><path d='M7 10l5 5 5-5z'/><path d='M0 0h24v24H0z' fill='none'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
}
.preset-dropdown:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-glow);
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.form-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--color-text-muted);
}

/* Live Stats */
.stats-list {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.stat-row {
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 0.85rem 1.1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.stat-label-text {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--color-text-muted);
}

.settings-value {
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--color-primary);
  font-size: 0.95rem;
}

/* Settings, sliders, controls */
.flex-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.btn-mute {
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 0.9rem;
  transition: all var(--transition-fast);
}
.btn-mute:hover {
  background: var(--color-primary-dim);
  border-color: var(--color-primary);
  transform: scale(1.08);
}
.btn-mute.muted {
  background: rgba(239, 68, 68, 0.1);
  border-color: rgba(239, 68, 68, 0.4);
  color: #EF4444;
}

.settings-item {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.settings-label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--color-text-muted);
}

.custom-range {
  -webkit-appearance: none;
  width: 100%;
  height: 4px;
  background: var(--color-surface-2);
  border-radius: var(--radius-full);
  outline: none;
}
.custom-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--color-primary);
  box-shadow: 0 0 8px var(--color-primary-glow);
  cursor: pointer;
  transition: transform var(--transition-fast);
}
.custom-range::-webkit-slider-thumb:hover {
  transform: scale(1.25);
}

/* ============================================================
   FOOTER STYLING
   ============================================================ */
.app-footer {
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-top: 1px solid var(--color-border);
  margin-top: auto;
}

.app-footer p {
  font-size: 0.8rem;
  color: var(--color-text-subtle);
  font-weight: 500;
}

/* ============================================================
   RESPONSIVE DESIGN Breakpoints
   ============================================================ */
@media (max-width: 980px) {
  .main-content {
    grid-template-columns: 1fr;
    gap: 2rem;
  }
  .grid-board-container {
    padding: 0.75rem;
  }
}

@media (max-width: 680px) {
  .app-wrapper {
    padding: 0 1rem;
  }
  .app-header {
    height: 70px;
    margin-bottom: 1.5rem;
  }
  .logo-icon {
    font-size: 1.8rem;
  }
  .logo-text-group h1 {
    font-size: 1.3rem;
  }
  .main-content {
    margin-bottom: 2rem;
    gap: 1.5rem;
  }
  .grid-board-container {
    padding: 0.5rem;
  }
  #life-grid {
    grid-template-columns: repeat(40, 10px);
    grid-template-rows: repeat(25, 10px);
    gap: 1px;
    padding: 2px;
  }
  .shortcuts-list {
    grid-template-columns: 1fr;
    gap: 0.5rem;
  }
  .glass-card {
    padding: 1.25rem;
  }
}
