:root {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-glass: rgba(30, 41, 59, 0.75);
  --border-glass: rgba(255, 255, 255, 0.12);
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  
  /* Organ Theme Colors */
  --mouth-color: #f43f5e;
  --mouth-bg: rgba(244, 63, 94, 0.15);
  --esophagus-color: #fb7185;
  --stomach-color: #eab308;
  --stomach-bg: rgba(234, 179, 8, 0.15);
  --duodenum-color: #10b981;
  --small-int-color: #06b6d4;
  --small-int-bg: rgba(6, 182, 212, 0.12);
  --large-int-color: #8b5cf6;
  --large-int-bg: rgba(139, 92, 246, 0.12);

  /* Button Accent Colors */
  --saliva-color: #38bdf8;
  --gastric-color: #a3e635;
  --bile-color: #22c55e;
  --pancreatic-color: #f59e0b;
  --intestinal-color: #c084fc;

  /* Font */
  --font-family: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

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

body {
  font-family: var(--font-family);
  background: radial-gradient(circle at 50% 20%, #1e1b4b 0%, #0f172a 60%, #020617 100%);
  color: var(--text-main);
  height: 100vh;
  max-height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Header & HUD */
header {
  background: var(--bg-glass);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-glass);
  padding: 6px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 100;
  position: relative;
  flex-shrink: 0;
}

.title-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-icon {
  font-size: 1.5rem;
  filter: drop-shadow(0 0 10px rgba(56, 189, 248, 0.6));
}

h1 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  background: linear-gradient(135deg, #38bdf8, #818cf8, #c084fc);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.badge {
  font-size: 0.7rem;
  background: rgba(56, 189, 248, 0.15);
  color: #38bdf8;
  border: 1px solid rgba(56, 189, 248, 0.3);
  padding: 1px 6px;
  border-radius: 10px;
  font-weight: 600;
}

.hud-panel {
  display: flex;
  align-items: flex-end;
  gap: 16px;
}

.hud-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
}

.hud-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.6px;
  font-weight: 600;
  line-height: 1.2;
}

.hud-val {
  font-size: 1.1rem;
  font-weight: 700;
  font-feature-settings: "tnum";
}

.hp-container {
  display: flex;
  align-items: center;
  gap: 6px;
}

.hp-bar-outer {
  width: 100px;
  height: 10px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--border-glass);
  position: relative;
}

.hp-bar-inner {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #ef4444, #f59e0b, #10b981);
  background-size: 100px 100%;
  transition: width 0.3s ease;
  border-radius: 6px;
}

.btn-group {
  display: flex;
  gap: 6px;
}

.icon-btn, .pill-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-glass);
  color: var(--text-main);
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 600;
  height: 28px;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: all 0.2s;
}

.icon-btn:hover, .pill-btn:hover {
  background: rgba(255, 255, 255, 0.16);
  border-color: rgba(255, 255, 255, 0.3);
  transform: translateY(-1px);
}

.pill-btn.active {
  background: linear-gradient(135deg, #0284c7, #2563eb);
  border-color: #38bdf8;
  box-shadow: 0 0 12px rgba(56, 189, 248, 0.4);
}

/* Main Arena */
main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 6px 16px 8px;
  gap: 6px;
  max-width: 1440px;
  margin: 0 auto;
  width: 100%;
  overflow: hidden;
}

/* Digestive Canvas Area (Reduced height to raise bottom buttons) */
.canvas-wrapper {
  position: relative;
  width: 100%;
  height: clamp(230px, 36vh, 285px);
  flex: none;
  background: rgba(15, 23, 42, 0.6);
  border-radius: 14px;
  border: 1px solid var(--border-glass);
  overflow: hidden;
  box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.6), 0 8px 32px rgba(0, 0, 0, 0.4);
}

#gameCanvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* Organ Labels Overlay (7 Equal Columns - Pixel-Perfect Alignment) */
.organ-labels-bar {
  position: absolute;
  top: 8px;
  left: 0;
  width: 100%;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  pointer-events: none;
  padding: 0 10px;
  gap: 8px;
  z-index: 10;
  box-sizing: border-box;
}

.organ-tag {
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(6px);
  padding: 5px 3px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  margin: 0;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.35);
  min-width: 0;
}

.organ-tag-name {
  font-size: clamp(0.74rem, 1.2vw, 1rem);
  font-weight: 800;
  letter-spacing: 0.4px;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.85);
  white-space: nowrap;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Glands Control Console (Pixel-Perfect Alignment with Canvas & Labels) */
.control-console {
  background: var(--bg-glass);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-glass);
  border-radius: 14px;
  padding: 6px 10px 8px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  flex-shrink: 0;
  box-sizing: border-box;
}

.console-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 4px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.console-title {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.console-hint {
  font-size: 0.72rem;
  color: #38bdf8;
  background: rgba(56, 189, 248, 0.1);
  padding: 1px 8px;
  border-radius: 8px;
}

/* 7 Equal Columns Glands Grid (Uniform Button Widths) */
.glands-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
}

.gland-col {
  display: flex;
  flex-direction: column;
  justify-content: stretch;
  gap: 4px;
  height: 100%;
  min-width: 0;
}

.gland-btn {
  position: relative;
  width: 100%;
  padding: 9px 4px 8px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(30, 41, 59, 0.85);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.25);
  height: 100%;
}


.gland-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  border-color: rgba(255, 255, 255, 0.4);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4);
}

.gland-btn:active:not(:disabled) {
  transform: translateY(0);
}

.gland-btn:disabled {
  cursor: not-allowed;
  opacity: 0.85;
}

/* Specific button accent borders */
.btn-salivary { --accent: var(--saliva-color); }
.btn-gastric { --accent: var(--gastric-color); }
.btn-liver { --accent: var(--bile-color); }
.btn-pancreas { --accent: var(--pancreatic-color); }
.btn-intestinal { --accent: var(--intestinal-color); }

.gland-btn {
  border-bottom: 3px solid var(--accent);
}

.gland-btn.highlight {
  animation: pulse-glow 1s infinite alternate;
  border-color: var(--accent);
}

@keyframes pulse-glow {
  0% { box-shadow: 0 0 10px var(--accent); transform: scale(1); }
  100% { box-shadow: 0 0 25px var(--accent); transform: scale(1.03); }
}

.btn-icon {
  font-size: 1.3rem;
  line-height: 1;
}

.btn-name {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--text-main);
  line-height: 1.2;
  letter-spacing: 0.5px;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

/* Charge Bar at Bottom of Button */
.charge-container {
  width: 90%;
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 1px;
}

.charge-track {
  flex: 1;
  height: 5px;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 3px;
  overflow: hidden;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.4);
  position: relative;
}

.charge-fill {
  height: 100%;
  width: 100%;
  background: var(--accent);
  box-shadow: 0 0 6px var(--accent);
  border-radius: 3px;
  transition: width 0.15s ease-out, background 0.2s;
}

.charge-label {
  font-size: 0.62rem;
  font-weight: 800;
  color: #f8fafc;
  font-feature-settings: "tnum";
  min-width: 20px;
  text-align: right;
  line-height: 1;
}

.gland-btn.out-of-charges {
  opacity: 0.6;
  cursor: not-allowed;
  filter: grayscale(0.5);
}

.gland-col.gland-col-horizontal .charge-container {
  width: 96%;
  gap: 2px;
}

.gland-col.gland-col-horizontal .charge-label {
  font-size: 0.58rem;
  min-width: 18px;
}

.cd-text {
  font-size: 0.95rem;
  font-weight: 800;
  color: #f8fafc;
  font-feature-settings: "tnum";
}

/* Empty column placeholder for Esophagus and Large Intestine */
.no-gland-box {
  width: 100%;
  height: 100%;
  min-height: unset;
  border-radius: 10px;
  border: 1px dashed rgba(255, 255, 255, 0.08);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 6px 4px;
  text-align: center;
  gap: 2px;
  background: rgba(15, 23, 42, 0.3);
}

.no-gland-icon {
  font-size: 1.1rem;
  opacity: 0.5;
}

.no-gland-title {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
}

.no-gland-desc {
  font-size: 0.60rem;
  color: #64748b;
  line-height: 1.15;
}

/* Floating Status / Toast text in Canvas */
.floating-toast {
  position: absolute;
  transform: translate(-50%, -50%);
  pointer-events: none;
  font-weight: 800;
  font-size: 0.9rem;
  border-radius: 20px;
  padding: 4px 12px;
  white-space: nowrap;
  animation: float-up-fade 1.2s forwards ease-out;
  z-index: 50;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
}

@keyframes float-up-fade {
  0% { opacity: 0; transform: translate(-50%, 0) scale(0.8); }
  20% { opacity: 1; transform: translate(-50%, -15px) scale(1.05); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -40px) scale(0.95); }
}

/* Scientific Reference Guide / Modal */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(2, 6, 23, 0.85);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

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

.modal-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-glass);
  width: 90%;
  max-width: 820px;
  max-height: 85vh;
  border-radius: 20px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.7);
}

.modal-header {
  padding: 16px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-glass);
}

.modal-header h2 {
  font-size: 1.2rem;
  color: #38bdf8;
  display: flex;
  align-items: center;
  gap: 8px;
}

.close-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}

.close-btn:hover {
  color: var(--text-main);
}

.modal-body {
  padding: 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
  font-size: 0.88rem;
  line-height: 1.6;
}

.sci-callout {
  background: rgba(245, 158, 11, 0.1);
  border-left: 4px solid #f59e0b;
  padding: 12px 16px;
  border-radius: 0 10px 10px 0;
}

.sci-callout h4 {
  color: #fbbf24;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.table-wrapper {
  overflow-x: auto;
}

.sci-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.sci-table th, .sci-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sci-table th {
  background: rgba(255, 255, 255, 0.04);
  color: #38bdf8;
}

/* Game Over / Victory Modal */
.result-box {
  text-align: center;
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.result-icon {
  font-size: 3.5rem;
}

.result-title {
  font-size: 1.8rem;
  font-weight: 800;
}

.result-stats {
  display: flex;
  gap: 20px;
  background: rgba(255, 255, 255, 0.05);
  padding: 14px 28px;
  border-radius: 12px;
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.stat-val {
  font-size: 1.5rem;
  font-weight: 800;
  color: #38bdf8;
}

.stat-lbl {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Responsive */
@media (max-width: 900px) {
  .organ-labels-bar, .glands-grid {
    grid-template-columns: repeat(3, 1fr);
    row-gap: 10px;
  }
  .hud-panel {
    gap: 12px;
  }
  .hp-bar-outer {
    width: 90px;
  }
}
