/* App shell — sidebar + main (grid) */

#app {
  display: grid;
  grid-template-columns: var(--sidebar-w-collapsed) 1fr;
  grid-template-rows: 1fr;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
}

@media (min-width: 768px) {
  #app {
    grid-template-columns: var(--sidebar-w) 1fr;
  }
}

/* —— Sidebar —— */
.sidebar {
  display: flex;
  flex-direction: column;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  z-index: 20;
  min-width: 0;
}

.sidebar__brand {
  flex-shrink: 0;
  padding: 1rem 0.875rem;
  border-bottom: 1px solid var(--border);
  min-height: 4.25rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.sidebar__title,
.sidebar__subtitle {
  display: none;
}

.sidebar__title--mobile {
  display: block;
}

@media (min-width: 768px) {
  .sidebar__title,
  .sidebar__subtitle {
    display: block;
  }
  .sidebar__title--mobile {
    display: none;
  }
  .sidebar__footer {
    display: block;
  }
}

.sidebar__footer {
  display: none;
}

.sidebar__title {
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--text-primary);
  text-decoration: none;
  letter-spacing: -0.02em;
}

.sidebar__title:hover { color: var(--accent); }

.sidebar__subtitle {
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--accent);
  margin-top: 0.125rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.sidebar__title--mobile {
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--accent);
  text-decoration: none;
}

.sidebar__nav {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar__footer {
  flex-shrink: 0;
  padding: 0.625rem 0.875rem;
  font-size: var(--text-xs);
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}

.nav-tab {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.6875rem 0.875rem;
  margin: 0 0.375rem;
  border-radius: var(--radius);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-secondary);
  text-decoration: none;
  transition: background var(--transition), color var(--transition);
  border-left: 3px solid transparent;
}

.nav-tab__icon {
  font-size: 1.125rem;
  width: 1.5rem;
  text-align: center;
  flex-shrink: 0;
}

.nav-tab__label {
  display: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (min-width: 768px) {
  .nav-tab__label { display: block; }
}

.nav-tab:hover {
  background: var(--bg-muted);
  color: var(--text-primary);
}

.nav-tab.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-left-color: var(--accent);
  font-weight: 600;
}

/* —— Main column —— */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--bg-base);
}

/* —— HUD (fixed height) —— */
.hud {
  flex-shrink: 0;
  height: var(--hud-h);
  min-height: var(--hud-h);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  padding: 0  var(--page-pad);
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  font-size: var(--text-sm);
  z-index: 10;
}

.hud__stat {
  display: inline-flex;
  align-items: baseline;
  gap: 0.35rem;
}

.hud__stat--bacteria {
  position: relative;
  display: inline-flex;
  align-items: stretch;
}

.hud__stat-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: none;
  border: none;
  padding: 0.2rem 0.35rem;
  margin: -0.2rem -0.35rem;
  cursor: pointer;
  font: inherit;
  color: inherit;
  border-radius: var(--radius);
  text-align: left;
}

.hud__stat-btn:hover,
.hud__stat-btn.is-open {
  color: var(--accent);
  background: rgba(255, 107, 0, 0.08);
}

.hud__stat-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.hud__caret {
  font-size: 0.6em;
  opacity: 0.65;
  line-height: 1;
}

.hud-strain-panel[hidden] {
  display: none !important;
}

.hud-strain-panel {
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: 0.35rem;
  display: flex;
  flex-direction: column;
  flex-wrap: nowrap;
  gap: 0.35rem;
  min-width: min(20rem, calc(100vw - 2 * var(--page-pad)));
  max-width: min(22rem, 95vw);
  max-height: min(42vh, 16rem);
  overflow-x: hidden;
  overflow-y: auto;
  padding: 0.45rem 0.5rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  z-index: 50;
}

.hud-strain-panel__empty {
  font-size: var(--text-xs);
  color: var(--text-muted);
  white-space: nowrap;
  padding: 0.25rem 0.15rem;
}

.hud-strain-chip {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.45rem;
  width: 100%;
  flex-shrink: 0;
  padding: 0.35rem 0.5rem;
  border-radius: var(--radius);
  background: var(--bg-muted);
  font-size: var(--text-xs);
}

.hud-strain-chip__lead {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-width: 0;
  flex: 1 1 auto;
}

.hud-strain-chip__nums {
  display: inline-flex;
  align-items: baseline;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.35rem 0.5rem;
  flex: 0 0 auto;
  font-family: var(--font-mono);
  text-align: right;
}

.hud-strain-chip__name {
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hud-strain-chip__val {
  font-weight: 600;
  color: var(--accent);
}

.hud-strain-chip__meta {
  color: var(--text-muted);
  font-size: 0.68rem;
  font-family: var(--font-sans);
}

.hud__label {
  color: var(--text-muted);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.hud__value {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: var(--text-sm);
}

.hud__value--accent { color: var(--accent); }
.hud__value--money { color: var(--success); }

.hud__divider {
  width: 1px;
  height: 1.25rem;
  background: var(--border);
  flex-shrink: 0;
}

.hud__level {
  display: none;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
  max-width: 10rem;
  min-width: 6rem;
}

@media (min-width: 640px) {
  .hud__level { display: flex; }
}

.hud__level-track {
  flex: 1;
  height: 6px;
  background: var(--bg-muted);
  border-radius: 999px;
  overflow: hidden;
}

.hud__level-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.3s ease;
  width: 0%;
}

.hud__clock {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-secondary);
  background: var(--bg-muted);
  padding: 0.35rem 0.65rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  white-space: nowrap;
}

/* —— Notifications —— */
#notifications {
  position: fixed;
  top: calc(var(--hud-h) + 0.75rem);
  right: max(0.75rem, env(safe-area-inset-right));
  left: auto;
  transform: none;
  z-index: 50;
  width: min(22rem, calc(100vw - var(--sidebar-w-collapsed) - 1.5rem));
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.5rem;
  pointer-events: none;
}

@media (min-width: 768px) {
  #notifications {
    width: min(22rem, calc(100vw - var(--sidebar-w) - 1.5rem));
  }
}

/* —— SPA page panels —— */
.page-panels {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
}

.page-panel {
  display: none;
  position: absolute;
  inset: 0;
  min-height: 0;
}

.page-panel.active {
  display: flex;
  flex-direction: column;
}

.page-panel--scroll {
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--page-pad);
  -webkit-overflow-scrolling: touch;
}

.page-panel--lab {
  overflow: hidden;
  padding: 0;
  background: var(--bg-lab-bench);
}

.lab-bench {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  min-height: 0;
}

.lab-bench__canvas-wrap {
  flex: 1;
  display: flex;
  align-items: stretch;
  justify-content: stretch;
  width: 100%;
  min-height: 0;
  padding: 0.5rem;
}

#lab-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.lab-toolbar {
  flex-shrink: 0;
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 0.75rem 1rem;
  padding: 0.625rem 1rem;
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
  box-shadow: 0 -2px 8px rgba(15, 23, 42, 0.04);
}

.lab-toolbar__main {
  display: flex;
  align-items: center;
  gap: 0.65rem 0.85rem;
  flex: 1 1 auto;
  min-width: 0;
}

.lab-toolbar__tools {
  display: grid;
  grid-template-columns: repeat(5, minmax(4.85rem, 1fr));
  flex-shrink: 0;
  gap: 0.35rem;
}

.lab-tool {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  padding: 0.4rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-muted);
  cursor: pointer;
  font-size: var(--text-xs);
  color: var(--text-secondary);
  transition: border-color var(--transition), background var(--transition);
  width: 100%;
  min-width: 0;
}

.lab-tool:hover { background: var(--bg-base); }

.lab-tool.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.lab-tool__icon { font-size: 1.125rem; }

.lab-toolbar__buy {
  flex-shrink: 0;
  margin-left: auto;
}

.lab-toolbar__dish-btn { white-space: nowrap; }

.lab-toolbar__price {
  font-family: var(--font-mono);
  font-weight: 500;
  margin-left: 0.25rem;
}

.lab-toolbar__hint {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  font-size: var(--text-xs);
  color: var(--text-muted);
  line-height: 1.35;
}

@media (max-width: 520px) {
  .lab-toolbar {
    flex-wrap: wrap;
  }

  .lab-toolbar__main {
    flex: 1 1 100%;
  }

  .lab-toolbar__buy {
    margin-left: 0;
    width: 100%;
  }

  .lab-toolbar__tools {
    width: 100%;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .lab-toolbar__dish-btn {
    width: 100%;
  }
}

.page-fill {
  width: 100%;
  max-width: 72rem;
  margin: 0 auto;
}

.landing-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.625rem;
  justify-content: center;
  margin-top: 1.25rem;
}

.landing-actions .btn-primary,
.landing-actions .landing-new-game {
  margin-top: 0;
}

.landing-new-game {
  padding: 0.75rem 1.25rem;
  font-size: var(--text-base);
}

/* —— Landing —— */
.landing {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.landing-card {
  width: 100%;
  max-width: 28rem;
  padding: 2rem 2rem 2.25rem;
  background: var(--bg-elevated);
  border-radius: var(--radius-lg);
  border: 1px solid var(--accent-border);
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.landing-card__title {
  font-size: var(--text-2xl);
  letter-spacing: -0.03em;
}

.landing-card__tagline {
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--accent);
  margin-top: 0.25rem;
}

.landing-card__desc {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  margin-top: 1rem;
  line-height: 1.6;
}

.landing-stats {
  margin-top: 1.5rem;
  text-align: left;
}

.landing-stats__grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.625rem;
  margin-top: 0.75rem;
}

.landing-stats__cell {
  background: var(--bg-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.625rem 0.75rem;
}

.landing-stats__cell span {
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.landing-stats__cell strong {
  display: block;
  margin-top: 0.2rem;
  font-family: var(--font-mono);
  font-size: var(--text-sm);
}

.landing-card__footer {
  margin-top: 1.5rem;
  font-size: var(--text-xs);
  color: var(--text-muted);
}
