/* ============================================================
   PERIODIC MINER — Theme System (dark default, light mode via body.light-mode)
   ============================================================ */

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

/* Disable double-tap zoom on iPad/tablets */
body, button, select, input, a { touch-action: manipulation; }

:root {
  --font-mono: 'Courier New', 'Consolas', monospace;
}

/* ── Dark mode (default) ─────────────────────────────────── */
body {
  --bg-deep:    #0a0a0f;
  --bg-panel:   #12121a;
  --bg-card:    #1a1a2e;
  --accent:     #00d4ff;
  --accent-dim: #007a99;
  --gold:       #ffd700;
  --danger:     #ff4444;
  --success:    #44ff88;
  --text:       #c8d6e5;
  --muted:      #5a6a7a;
  --border:     #2a2a3e;
  --glow:       0 0 8px var(--accent);
  --cave-rock:  #060408;
  background:
    linear-gradient(180deg, #000005 0%, transparent 12%),
    linear-gradient(0deg,   #000005 0%, transparent 8%),
    radial-gradient(ellipse 200% 80% at 50% 110%, rgba(60,35,0,0.2) 0%, transparent 55%),
    #0a0a0f;
}

/* ── Torch mode (warm amber cave — replaces the old bright light mode) ── */
body.light-mode {
  --bg-deep:    #2c1a08;
  --bg-panel:   #3d2510;
  --bg-card:    #4a3018;
  --accent:     #e8901a;
  --accent-dim: #c07010;
  --gold:       #ffc020;
  --danger:     #ff5533;
  --success:    #60cc60;
  --text:       #f0dca0;
  --muted:      #9a7840;
  --border:     #6a4820;
  --glow:       0 0 8px rgba(232,144,26,0.6);
  --cave-rock:  #180e04;
  background:
    linear-gradient(180deg, #180e04 0%, transparent 12%),
    linear-gradient(0deg,   #180e04 0%, transparent 8%),
    radial-gradient(ellipse 200% 80% at 50% 110%, rgba(200,100,0,0.35) 0%, transparent 55%),
    #2c1a08;
}

/* ── Neon theme (electric purple-green lab) ── */
body.theme-neon {
  --bg-deep:    #0d0d1a;
  --bg-panel:   #151525;
  --bg-card:    #1a1a30;
  --accent:     #39ff14;
  --accent-dim: #1a8c0a;
  --gold:       #ffff00;
  --danger:     #ff4466;
  --success:    #00ffff;
  --text:       #e0e0ff;
  --muted:      #6a6a9a;
  --border:     #2a2a4a;
  --glow:       0 0 12px rgba(57,255,20,0.4);
  --cave-rock:  #080812;
  background:
    linear-gradient(180deg, #0a0a15 0%, transparent 12%),
    linear-gradient(0deg,   #0a0a15 0%, transparent 8%),
    radial-gradient(ellipse 200% 80% at 50% 110%, rgba(100,0,200,0.15) 0%, transparent 55%),
    #0d0d1a;
}

/* ── Ocean theme (deep ocean blue) ── */
body.theme-ocean {
  --bg-deep:    #020d1a;
  --bg-panel:   #0a1628;
  --bg-card:    #0f1f35;
  --accent:     #00ffcc;
  --accent-dim: #00a08a;
  --gold:       #60dfff;
  --danger:     #ff6b6b;
  --success:    #4ade80;
  --text:       #c8e6f5;
  --muted:      #6a8aa0;
  --border:     #1a3a52;
  --glow:       0 0 10px rgba(0,255,204,0.3);
  --cave-rock:  #010609;
  background:
    linear-gradient(180deg, #010609 0%, transparent 12%),
    linear-gradient(0deg,   #010609 0%, transparent 8%),
    radial-gradient(ellipse 200% 80% at 50% 110%, rgba(0,100,150,0.2) 0%, transparent 55%),
    #020d1a;
}

/* ── Forest theme (earthy green) ── */
body.theme-forest {
  --bg-deep:    #0a1205;
  --bg-panel:   #121a0e;
  --bg-card:    #1a2516;
  --accent:     #7fff00;
  --accent-dim: #558c00;
  --gold:       #d4af37;
  --danger:     #ff7f7f;
  --success:    #5fd35f;
  --text:       #d8e6c4;
  --muted:      #7a8a6a;
  --border:     #2a3a20;
  --glow:       0 0 10px rgba(127,255,0,0.3);
  --cave-rock:  #050802;
  background:
    linear-gradient(180deg, #050802 0%, transparent 12%),
    linear-gradient(0deg,   #050802 0%, transparent 8%),
    radial-gradient(ellipse 200% 80% at 50% 110%, rgba(50,100,30,0.2) 0%, transparent 55%),
    #0a1205;
}

/* ── Solar theme (bright warm yellow) ── */
body.theme-solar {
  --bg-deep:    #1a1200;
  --bg-panel:   #2a1f08;
  --bg-card:    #3a2a10;
  --accent:     #ffe44d;
  --accent-dim: #cc9900;
  --gold:       #ffc700;
  --danger:     #ff5555;
  --success:    #55dd55;
  --text:       #f5e6d3;
  --muted:      #a0905a;
  --border:     #5a4a30;
  --glow:       0 0 12px rgba(255,228,77,0.35);
  --cave-rock:  #0d0a00;
  background:
    linear-gradient(180deg, #0d0a00 0%, transparent 12%),
    linear-gradient(0deg,   #0d0a00 0%, transparent 8%),
    radial-gradient(ellipse 200% 80% at 50% 110%, rgba(200,150,0,0.25) 0%, transparent 55%),
    #1a1200;
}

/* ── High Contrast theme (pure accessibility) ── */
body.theme-contrast {
  --bg-deep:    #000000;
  --bg-panel:   #1a1a1a;
  --bg-card:    #333333;
  --accent:     #ffff00;
  --accent-dim: #cccc00;
  --gold:       #ffff66;
  --danger:     #ff0000;
  --success:    #00ff00;
  --text:       #ffffff;
  --muted:      #999999;
  --border:     #666666;
  --glow:       0 0 8px rgba(255,255,0,0.5);
  --cave-rock:  #000000;
  background:
    linear-gradient(180deg, #000000 0%, transparent 12%),
    linear-gradient(0deg,   #000000 0%, transparent 8%),
    none,
    #000000;
}

/* ── Light theme (bright and readable) ── */
body.theme-light {
  --bg-deep:    #ffffff;
  --bg-panel:   #f5f5f5;
  --bg-card:    #e8e8e8;
  --accent:     #0066cc;
  --accent-dim: #0052a3;
  --gold:       #ff9500;
  --danger:     #cc0000;
  --success:    #00aa00;
  --text:       #1a1a1a;
  --muted:      #666666;
  --border:     #cccccc;
  --glow:       0 0 8px rgba(0,102,204,0.3);
  --cave-rock:  #d0d0d0;
  background:
    linear-gradient(180deg, #ffffff 0%, transparent 12%),
    linear-gradient(0deg,   #ffffff 0%, transparent 8%),
    radial-gradient(ellipse 200% 80% at 50% 110%, rgba(200,220,255,0.2) 0%, transparent 55%),
    #ffffff;
}

/* Light theme element cell styling — minimal background, clean borders */
body.theme-light .element-cell.unlocked {
  background: transparent !important;
  border-color: rgba(0, 102, 204, 0.2) !important;
}

body.theme-light .element-cell.unlocked:hover {
  background: rgba(0, 102, 204, 0.05) !important;
  border-color: var(--accent) !important;
}

body.theme-light .element-cell .el-name {
  text-shadow: none !important;
}

body.theme-light .element-cell .symbol,
body.theme-light .element-cell .atomic-num {
  color: var(--text) !important;
}

/* ── Light Warm theme (light with warm tones) ── */
body.theme-light-warm {
  --bg-deep:    #fffbf5;
  --bg-panel:   #f7f3ed;
  --bg-card:    #ede7e0;
  --accent:     #cc6600;
  --accent-dim: #994400;
  --gold:       #ff9500;
  --danger:     #cc0000;
  --success:    #00aa00;
  --text:       #2a1a0a;
  --muted:      #7a6a5a;
  --border:     #d4c4b4;
  --glow:       0 0 8px rgba(204,102,0,0.3);
  --cave-rock:  #d9c9b9;
  background:
    linear-gradient(180deg, #fffbf5 0%, transparent 12%),
    linear-gradient(0deg,   #fffbf5 0%, transparent 8%),
    radial-gradient(ellipse 200% 80% at 50% 110%, rgba(255,220,180,0.2) 0%, transparent 55%),
    #fffbf5;
}

body.theme-light-warm .element-cell.unlocked {
  background: transparent !important;
  border-color: rgba(204, 102, 0, 0.2) !important;
}

body.theme-light-warm .element-cell.unlocked:hover {
  background: rgba(204, 102, 0, 0.05) !important;
  border-color: var(--accent) !important;
}

body.theme-light-warm .element-cell .el-name {
  text-shadow: none !important;
}

body.theme-light-warm .element-cell .symbol,
body.theme-light-warm .element-cell .atomic-num {
  color: var(--text) !important;
}

/* ── Light Cool theme (light with cool tones) ── */
body.theme-light-cool {
  --bg-deep:    #f5f9ff;
  --bg-panel:   #eef5ff;
  --bg-card:    #e5f0ff;
  --accent:     #0066cc;
  --accent-dim: #0052a3;
  --gold:       #0099ff;
  --danger:     #cc0000;
  --success:    #00aa00;
  --text:       #001a4d;
  --muted:      #4d6680;
  --border:     #b3ccff;
  --glow:       0 0 8px rgba(0,102,204,0.3);
  --cave-rock:  #c4d9ff;
  background:
    linear-gradient(180deg, #f5f9ff 0%, transparent 12%),
    linear-gradient(0deg,   #f5f9ff 0%, transparent 8%),
    radial-gradient(ellipse 200% 80% at 50% 110%, rgba(180,220,255,0.2) 0%, transparent 55%),
    #f5f9ff;
}

body.theme-light-cool .element-cell.unlocked {
  background: transparent !important;
  border-color: rgba(0, 102, 204, 0.2) !important;
}

body.theme-light-cool .element-cell.unlocked:hover {
  background: rgba(0, 102, 204, 0.05) !important;
  border-color: var(--accent) !important;
}

body.theme-light-cool .element-cell .el-name {
  text-shadow: none !important;
}

body.theme-light-cool .element-cell .symbol,
body.theme-light-cool .element-cell .atomic-num {
  color: var(--text) !important;
}

html, body {
  height: 100%;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 13px;
  overflow: hidden;
}

/* ── Support Link ────────────────────────────────────────── */
#support-link {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 0.4rem 0.6rem;
  text-decoration: none;
  transition: opacity 0.15s;
  opacity: 0.7;
}

#support-link:hover {
  opacity: 1;
}

/* ── Cave formations ─────────────────────────────────────── */
.cave-rock { fill: var(--cave-rock); }

#cave-ceiling {
  position: fixed;
  top: 48px;
  left: 0; right: 0;
  height: 50px;
  pointer-events: none;
  z-index: 5;
}

#cave-floor {
  position: fixed;
  bottom: 0;
  left: 0; right: 0;
  height: 50px;
  pointer-events: none;
  z-index: 5;
}

/* ── Header ─────────────────────────────────────────────── */
#game-header {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0.5rem 1rem;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  height: 48px;
}

#game-header h1 {
  font-size: 1.1rem;
  color: var(--accent);
  text-shadow: var(--glow);
  white-space: nowrap;
}

#header-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  flex: 1;
}

.stat-group {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.stat-label {
  color: var(--muted);
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.stat-value {
  color: var(--text);
  font-size: 0.85rem;
  font-weight: bold;
}

#stat-protons { color: var(--gold); }
#stat-multiplier { color: var(--accent); }

#header-actions { display: flex; gap: 0.5rem; }

/* ── Layout ─────────────────────────────────────────────── */
#game-layout {
  display: grid;
  grid-template-columns: 240px 1fr 240px;
  /* 48px header + 50px cave ceiling + layout + 50px cave floor = 100vh */
  height: calc(100vh - 148px);
  margin-top: 50px;
  gap: 0;
}

aside, section {
  overflow-y: auto;
  padding: 0.75rem;
  border-right: 1px solid var(--border);
}

#panel-upgrades { border-right: none; border-left: 1px solid var(--border); }

aside h2, section h2 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--accent);
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.4rem;
  margin-bottom: 0.75rem;
}

/* ── Center panel: flex column so table + info strip share the height ── */
#panel-table {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#panel-table > h2 { flex-shrink: 0; }

/* Table collapse state */
#panel-table.table-collapsed {
  flex: 0;
}

#panel-table.table-collapsed #periodic-table,
#panel-table.table-collapsed #element-info-strip {
  display: none;
}

#toggle-table {
  transition: transform 0.3s;
}

#panel-table.table-collapsed #toggle-table {
  transform: rotate(-90deg);
}

/* ── Periodic Table Grid ────────────────────────────────── */
#periodic-table {
  display: grid;
  grid-template-columns: repeat(18, 1fr);
  column-gap: 2px;
  row-gap: 1px;
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
}

/* ── Element info strip (bottom of center panel) ────────── */
#element-info-strip {
  flex-shrink: 0;
  height: 54px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 0.75rem;
  overflow: hidden;
  background: var(--bg-panel);
}

#element-info-strip.empty { opacity: 0; }

#info-symbol {
  font-size: 2rem;
  font-weight: bold;
  line-height: 1;
  flex-shrink: 0;
}

#info-body { min-width: 0; flex: 1; }

#info-name {
  font-size: 0.8rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#info-fact {
  font-size: 0.6rem;
  color: var(--muted);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ── Feature Panel (below info strip) ────────────────────── */
#panel-features {
  flex-shrink: 0;
  height: 200px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
  overflow: hidden;
  transition: height 0.3s;
}

#panel-features.features-hidden {
  height: 32px;
  border-top: 1px solid var(--border);
  overflow: visible;
}

#panel-features.features-hidden #feature-content {
  display: none;
}

#panel-features.features-hidden #feature-tabs {
  display: none;
}

#features-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

#toggle-features {
  display: block;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 0.3rem 0.5rem;
  font-size: 0.8rem;
  transition: color 0.2s;
}

#toggle-features:hover {
  color: var(--accent);
}

#panel-features.features-hidden #toggle-features {
  transform: rotate(180deg);
}

/* On large screens (> 900px height), show panel by default */
@media (min-height: 901px) {
  #panel-features.features-hidden {
    height: 200px;
    border-top: 1px solid var(--border);
  }
}

/* On small screens, hide panel by default */
@media (max-height: 900px) {
  #panel-features {
    height: 0;
    border-top: none;
  }

  #panel-features.features-hidden {
    height: 0;
  }

  #panel-features:not(.features-hidden) {
    height: 250px;
  }

  #toggle-features {
    display: block;
  }
}

#feature-tabs {
  display: flex;
  gap: 2px;
  padding: 0.5rem;
  background: var(--bg-deep);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.feat-btn {
  flex: 1;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.65rem;
  padding: 0.4rem 0.5rem;
  border-radius: 3px;
  text-transform: uppercase;
  cursor: pointer;
  transition: all 0.2s;
}

.feat-btn:hover {
  border-color: var(--accent-dim);
  color: var(--accent);
}

.feat-btn.active {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(0,212,255,0.08);
}

#feature-content {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
  font-size: 0.7rem;
}

/* Quiz */
.quiz-container {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.quiz-question {
  text-align: center;
  padding: 0.5rem;
  background: var(--bg-card);
  border-radius: 4px;
  min-height: 65px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.quiz-symbol {
  font-size: 2rem;
  font-weight: bold;
  color: var(--accent);
}

.quiz-name {
  font-size: 1rem;
  color: var(--text);
}

.quiz-prompt {
  font-size: 0.6rem;
  color: var(--muted);
  margin-top: 0.3rem;
}

.quiz-streak {
  text-align: center;
  color: var(--gold);
  font-weight: bold;
}

.quiz-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.3rem;
}

.quiz-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.4rem;
  border-radius: 3px;
  cursor: pointer;
  font-size: 0.65rem;
  transition: all 0.15s;
}

.quiz-btn:hover {
  border-color: var(--accent);
  background: var(--bg-deep);
}

/* Shells */
.shells-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.shells-header {
  font-size: 0.75rem;
  font-weight: bold;
  color: var(--accent);
}

.shells-svg {
  width: 100px;
  height: 100px;
}

.shells-config {
  font-size: 0.65rem;
  color: var(--muted);
  font-family: var(--font-mono);
}

.shells-tip {
  font-size: 0.6rem;
  color: var(--muted);
  font-style: italic;
  margin-top: 0.5rem;
  text-align: center;
}

/* Timeline */
.timeline-container {
  overflow-y: auto;
  height: 100%;
}

.timeline-century {
  margin-bottom: 0.75rem;
}

.timeline-century h4 {
  margin: 0.3rem 0;
  color: var(--accent);
  font-size: 0.7rem;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.2rem;
}

.timeline-row {
  display: grid;
  grid-template-columns: 35px 25px 1fr auto;
  gap: 0.4rem;
  font-size: 0.6rem;
  padding: 0.2rem;
  align-items: center;
}

.tl-year {
  color: var(--muted);
  font-family: var(--font-mono);
  font-weight: bold;
}

.tl-symbol {
  color: var(--accent);
  font-weight: bold;
  text-align: center;
}

.tl-name {
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}

.tl-by {
  color: var(--muted);
  font-size: 0.55rem;
  min-width: 60px;
  text-align: right;
}

.element-cell {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 2px;
  cursor: pointer;
  position: relative;
  transition: border-color 0.15s, box-shadow 0.15s;
  min-width: 0;
  user-select: none;
  -webkit-user-select: none;
}

/* Category colors (muted by default, brighter when unlocked) */
.element-cell[data-category="alkali-metal"]       { --cat-color: #ff6b6b; }
.element-cell[data-category="alkaline-earth"]     { --cat-color: #ffa07a; }
.element-cell[data-category="transition-metal"]   { --cat-color: #87ceeb; }
.element-cell[data-category="post-transition"]    { --cat-color: #98fb98; }
.element-cell[data-category="metalloid"]          { --cat-color: #dda0dd; }
.element-cell[data-category="nonmetal"]           { --cat-color: #7fffd4; }
.element-cell[data-category="halogen"]            { --cat-color: #ffd700; }
.element-cell[data-category="noble-gas"]          { --cat-color: #00d4ff; }
.element-cell[data-category="lanthanide"]         { --cat-color: #ff69b4; }
.element-cell[data-category="actinide"]           { --cat-color: #ff8c00; }

.element-cell.locked {
  background: rgba(13, 13, 21, 0.5) !important;
  cursor: not-allowed;
  border-color: rgba(128, 128, 128, 0.2) !important;
}

.element-cell.locked .symbol,
.element-cell.locked .atomic-num {
  opacity: 0.5 !important;
}

.element-cell.unlocked {
  background: color-mix(in srgb, var(--cat-color) 8%, var(--bg-card));
  border-color: color-mix(in srgb, var(--cat-color) 40%, transparent);
}

.element-cell.unlocked:hover {
  border-color: var(--cat-color);
  box-shadow: 0 0 6px color-mix(in srgb, var(--cat-color) 60%, transparent);
  z-index: 1;
}

.element-cell.producing {
  /* Subtle pulse animation when actively mining */
  animation: pulse-mine 2s ease-in-out infinite;
}

@keyframes pulse-mine {
  0%, 100% { box-shadow: 0 0 4px color-mix(in srgb, var(--cat-color) 40%, transparent); }
  50%       { box-shadow: 0 0 12px color-mix(in srgb, var(--cat-color) 80%, transparent); }
}

.element-cell .atomic-num {
  font-size: 0.55em;
  color: var(--muted);
  line-height: 1;
}

.element-cell .symbol {
  font-size: 0.9em;
  font-weight: bold;
  color: var(--cat-color, var(--text));
  line-height: 1.1;
}

.element-cell .el-name {
  font-size: 0.50em !important;
  color: #ffffff !important;
  font-weight: 800 !important;
  text-shadow:
    -1.5px -1.5px 0 #000000,
    1.5px -1.5px 0 #000000,
    -1.5px 1.5px 0 #000000,
    1.5px 1.5px 0 #000000,
    0 0 4px #000000 !important;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 95%;
}

/* Production rate overlay bar (bottom) */
.element-cell .prod-bar {
  position: absolute;
  bottom: 0; left: 0;
  height: 2px;
  background: var(--cat-color, var(--accent));
  width: 0%;
  transition: width 0.5s;
  border-radius: 0 0 2px 2px;
}

/* Spacer cells for lanthanides/actinides gap */
.element-cell.spacer {
  border: none;
  background: transparent;
  cursor: default;
  pointer-events: none;
}

/* ── Chain Panel (Left) ─────────────────────────────────── */
.chain-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.3rem;
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}

.chain-row:hover { background: var(--bg-card); }

.chain-row .chain-symbol {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 3px;
  font-weight: bold;
  font-size: 0.9rem;
  flex-shrink: 0;
}

.chain-row .chain-info {
  flex: 1;
  min-width: 0;
}

.chain-row .chain-name {
  font-size: 0.75rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chain-row .chain-rate {
  font-size: 0.65rem;
  color: var(--muted);
}

.chain-row .chain-count {
  font-size: 0.7rem;
  color: var(--gold);
  white-space: nowrap;
}

.btn-buy-drill {
  background: var(--bg-card);
  border: 1px solid var(--accent-dim);
  color: var(--accent);
  border-radius: 3px;
  padding: 2px 6px;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.1s, border-color 0.1s;
}

/* inner content passes clicks through to the button */
.btn-buy-drill > * { pointer-events: none; }

.btn-buy-drill:hover:not(:disabled) {
  background: var(--accent-dim);
  color: #fff;
}

.btn-buy-drill:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  border-color: var(--border);
  color: var(--muted);
}

/* ── Upgrades Panel (Right) ─────────────────────────────── */
#upgrade-tabs {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 0.5rem;
}

.tab-btn {
  flex: 1;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  padding: 3px 0;
  cursor: pointer;
  border-radius: 2px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.tab-btn.active {
  border-color: var(--accent-dim);
  color: var(--accent);
}

.upgrade-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.5rem;
  margin-bottom: 0.4rem;
  cursor: pointer;
  transition: border-color 0.15s;
}

.upgrade-card:hover:not(.purchased):not(.unaffordable) {
  border-color: var(--accent-dim);
}

.upgrade-card.purchased {
  opacity: 0.5;
  cursor: default;
  border-color: var(--success);
}

.upgrade-card.unaffordable {
  opacity: 0.4;
  cursor: not-allowed;
}

.upgrade-card .upg-title,
.upgrade-card .upg-desc,
.upgrade-card .upg-cost {
  pointer-events: none; /* clicks pass through to parent card listener */
}

.upgrade-card .upg-title {
  font-size: 0.75rem;
  color: var(--text);
  margin-bottom: 0.2rem;
}

.upgrade-card .upg-desc {
  font-size: 0.65rem;
  color: var(--muted);
  margin-bottom: 0.3rem;
}

.upgrade-card .upg-cost {
  font-size: 0.65rem;
  color: var(--gold);
}

.upg-element-cost {
  color: var(--accent-dim);
  font-size: 0.6rem;
  display: block;
  margin-top: 0.1rem;
}

/* ── Discovery Toast ────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  display: flex;
  flex-direction: column-reverse;
  gap: 0.5rem;
  z-index: 200;
  pointer-events: none;
}

.discovery-toast {
  background: var(--bg-panel);
  border: 1px solid var(--accent-dim);
  border-radius: 6px;
  padding: 0.75rem 1rem;
  max-width: 300px;
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  box-shadow: 0 0 20px rgba(0,212,255,0.15);
  animation: toast-in 0.3s ease forwards;
  pointer-events: auto;
}

.discovery-toast.toast-out {
  animation: toast-out 0.4s ease forwards;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateX(30px); }
  to   { opacity: 1; transform: translateX(0); }
}

@keyframes toast-out {
  from { opacity: 1; transform: translateX(0); }
  to   { opacity: 0; transform: translateX(30px); }
}

.toast-symbol {
  font-size: 2rem;
  font-weight: bold;
  line-height: 1;
  flex-shrink: 0;
}

.toast-body { min-width: 0; }

.toast-header {
  font-size: 0.75rem;
  color: var(--accent);
  margin-bottom: 0.25rem;
}

.toast-fact {
  font-size: 0.65rem;
  color: var(--text);
  line-height: 1.4;
}

/* ── Buttons ────────────────────────────────────────────── */
button { cursor: pointer; }

.btn-prestige {
  background: transparent;
  border: 1px solid var(--gold);
  color: var(--gold);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  padding: 4px 10px;
  border-radius: 3px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  transition: background 0.15s;
}

.btn-prestige:hover:not(:disabled) { background: rgba(255,215,0,0.15); }
.btn-prestige:disabled { opacity: 0.3; cursor: not-allowed; }

.btn-prestige-proton {
  background: transparent;
  border: 1px solid var(--success);
  color: var(--success);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  padding: 4px 10px;
  border-radius: 3px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  transition: background 0.15s;
  min-width: 140px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-prestige-proton:hover:not(:disabled) { background: rgba(68,255,136,0.15); }
.btn-prestige-proton:disabled { opacity: 0.3; cursor: not-allowed; }

#btn-save {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  padding: 4px 8px;
  border-radius: 3px;
}

#btn-save:hover { border-color: var(--accent-dim); color: var(--accent); }

/* ── Modal ──────────────────────────────────────────────── */
#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

#modal-overlay.hidden { display: none; }

#modal-element {
  background: var(--bg-panel);
  border: 1px solid var(--accent-dim);
  border-radius: 6px;
  padding: 1.5rem;
  min-width: 320px;
  max-width: 480px;
  position: relative;
  box-shadow: 0 0 30px rgba(0,212,255,0.2);
}

#modal-close {
  position: absolute;
  top: 0.5rem; right: 0.75rem;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1rem;
  cursor: pointer;
}

#modal-close:hover { color: var(--text); }

/* ── Theme selector ────────────────────────────────────── */
#btn-theme {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.75rem;
  padding: 4px 6px;
  border-radius: 3px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
  font-family: var(--font-mono);
}
#btn-theme:hover {
  border-color: var(--accent-dim);
  color: var(--accent);
}
#btn-theme:focus {
  outline: 1px solid var(--accent);
  outline-offset: 1px;
}

#btn-reset {
  background: transparent;
  border: 1px solid var(--danger);
  color: var(--danger);
  font-family: var(--font-mono);
  font-size: 0.65rem;
  padding: 3px 7px;
  border-radius: 3px;
  cursor: pointer;
  opacity: 0.5;
  transition: opacity 0.15s;
}
#btn-reset:hover { opacity: 1; }

/* ── Upgrade progress bars ──────────────────────────────── */
.upg-progress {
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  margin-top: 0.3rem;
  overflow: hidden;
}
.upg-progress-fill {
  height: 100%;
  background: var(--accent-dim);
  border-radius: 2px;
  transition: width 0.5s;
}
.upgrade-card:not(.unaffordable) .upg-progress-fill { background: var(--success); }

/* ── Centered discovery splash ──────────────────────────── */
#splash-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 400;
  cursor: pointer;
  animation: splash-bg-in 0.3s ease;
}

#splash-overlay.hidden { display: none; }

@keyframes splash-bg-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

#splash-card {
  background: var(--bg-panel);
  border: 2px solid var(--accent);
  border-radius: 14px;
  padding: 2.5rem 3rem;
  max-width: 520px;
  width: 90vw;
  text-align: center;
  box-shadow: 0 0 60px rgba(0,212,255,0.3);
  animation: splash-card-in 0.4s cubic-bezier(0.34,1.56,0.64,1);
  pointer-events: none;
}

body.light-mode #splash-card {
  box-shadow: 0 0 60px rgba(192,96,16,0.3);
}

@keyframes splash-card-in {
  from { opacity: 0; transform: scale(0.7); }
  to   { opacity: 1; transform: scale(1); }
}

#splash-symbol {
  font-size: 6rem;
  font-weight: bold;
  line-height: 1;
  margin-bottom: 0.5rem;
}

#splash-title {
  font-size: 1.4rem;
  color: var(--accent);
  margin-bottom: 0.25rem;
  letter-spacing: 0.05em;
}

#splash-subtitle {
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 1.25rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

#splash-fact {
  font-size: 0.9rem;
  color: var(--text);
  line-height: 1.7;
  margin-bottom: 1.5rem;
  font-style: italic;
}

.splash-dismiss {
  font-size: 0.65rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

/* ── Reactions tab ──────────────────────────────────────── */
.reaction-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.6rem;
  margin-bottom: 0.4rem;
}

.reaction-card.rx-ready {
  border-color: var(--success);
  box-shadow: 0 0 6px rgba(68,255,136,0.2);
  animation: rx-pulse 1.5s ease-in-out infinite;
}

@keyframes rx-pulse {
  0%, 100% { box-shadow: 0 0 4px rgba(68,255,136,0.2); }
  50%       { box-shadow: 0 0 12px rgba(68,255,136,0.5); }
}

.reaction-card.rx-done {
  opacity: 0.5;
  border-color: var(--success);
}

.rx-header {
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
  margin-bottom: 0.2rem;
}

.rx-formula {
  font-size: 1rem;
  font-weight: bold;
  color: var(--accent);
}

.rx-name {
  font-size: 0.7rem;
  color: var(--text);
  flex: 1;
}

.rx-reward {
  font-size: 0.65rem;
  color: var(--gold);
}

.rx-flavour {
  font-size: 0.6rem;
  color: var(--muted);
  font-style: italic;
  margin-bottom: 0.4rem;
  line-height: 1.4;
}

.rx-reagent-row {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  margin-bottom: 0.2rem;
}

.rx-reagent-symbol {
  width: 22px;
  font-size: 0.65rem;
  font-weight: bold;
  color: var(--muted);
  flex-shrink: 0;
}

.rx-reagent-symbol.met { color: var(--success); }

.rx-reagent-bar {
  flex: 1;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}

.rx-reagent-fill {
  height: 100%;
  background: var(--accent-dim);
  border-radius: 2px;
  transition: width 0.5s;
}

.rx-reagent-count {
  font-size: 0.55rem;
  color: var(--muted);
  white-space: nowrap;
  min-width: 60px;
  text-align: right;
}

.rx-reagent-count.met { color: var(--success); }

.rx-status {
  font-size: 0.65rem;
  color: var(--success);
  margin-top: 0.3rem;
  text-align: center;
}

/* ── Scrollbars ─────────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: var(--bg-deep); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* ── Prestige-ready notification ────────────────────────── */
@keyframes prestige-pop {
  from { opacity: 0; transform: translateX(-50%) scale(0.8); }
  to   { opacity: 1; transform: translateX(-50%) scale(1); }
}

/* ── Utility ────────────────────────────────────────────── */
.hidden { display: none !important; }
.text-accent { color: var(--accent); }
.text-gold   { color: var(--gold); }
.text-muted  { color: var(--muted); }
