:root {
  --bg: #17181c;
  --bg-elevated: #212329;
  --bg-card: #262932;
  --border: #383c46;
  --text: #e8e9ed;
  --text-dim: #9a9eac;
  --accent: #5b9c3d;
  --accent-bright: #7ec753;
  --accent-soft: rgba(91, 156, 61, 0.16);
  --danger: #c65b4e;
  --radius: 0px;
  --stone: #6b6f7a;
  --font-mono: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-mono);
  -webkit-font-smoothing: antialiased;
}

/* App shell: header/nav are normal flex children (not position: fixed) so
   they can't drift out of place — iOS WebKit has a long-standing standalone-
   PWA bug where fixed elements misplace themselves after the keyboard opens
   and closes. Only <main> scrolls. 100svh is the safe fallback for browsers
   without dvh; 100dvh (iOS 15.4+) tracks Safari's chrome height live. */
body {
  display: flex;
  flex-direction: column;
  height: 100svh;
  height: 100dvh;
}

.app-header {
  flex: 0 0 auto;
  padding: 16px;
  padding-top: calc(16px + env(safe-area-inset-top, 0px));
  text-align: center;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, var(--bg-elevated), var(--bg));
}

.app-header h1 {
  margin: 0;
  font-size: 1.4rem;
  letter-spacing: 0.3px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.header-icon {
  width: 28px;
  height: 28px;
  image-rendering: pixelated;
}

.splash-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 24px;
  background: var(--bg);
  text-align: center;
  opacity: 1;
  transition: opacity 0.35s ease;
}

.splash-screen.hidden {
  opacity: 0;
  pointer-events: none;
}

.splash-icon {
  width: 96px;
  height: 96px;
  image-rendering: pixelated;
  margin-bottom: 8px;
}

.splash-title {
  margin: 0;
  font-size: 1.6rem;
  letter-spacing: 0.3px;
}

.splash-subtitle {
  margin: 0;
  color: var(--text-dim);
  font-size: 0.9rem;
  max-width: 280px;
}

main {
  flex: 1 1 auto;
  overflow-y: auto;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 16px;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

.section-title {
  margin: 0 0 10px;
  font-size: 1rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

/* --- Tiers tab --- */

.tiers-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin-top: 6px;
}

.tier-card {
  all: unset;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 92px;
  padding: 12px 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  cursor: pointer;
  opacity: 0.5;
  filter: grayscale(0.9);
  -webkit-tap-highlight-color: transparent;
  transition: opacity 0.15s ease, filter 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.tier-card:active {
  background: var(--bg-card);
}

.tier-card.done {
  opacity: 1;
  filter: none;
  background: var(--accent-soft);
  border-color: var(--accent);
}

.tier-icon {
  width: 36px;
  height: 36px;
  image-rendering: pixelated;
}

.tier-icon-material {
  width: 24px;
  height: 24px;
}

.tier-label {
  font-size: 0.78rem;
  color: var(--text-dim);
  letter-spacing: 0.3px;
}

.tier-card.done .tier-label {
  color: var(--accent-bright);
}

.tiers-label {
  margin: 14px 0 0;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--text-dim);
  text-align: center;
}

/* --- Overall progress --- */

.overall-bar, .stage-bar {
  height: 10px;
  border-radius: 0;
  background: var(--bg-elevated);
  overflow: hidden;
  border: 1px solid var(--border);
}

.overall-bar-fill, .stage-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-bright));
  transition: width 0.25s ease;
}

.overall-label {
  margin: 8px 0 0;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--text-dim);
  text-align: center;
}

/* --- Up next --- */

.up-next-list { list-style: none; margin: 0; padding: 0; }
.up-next-item { padding: 6px 0; }
.up-next-empty { color: var(--text-dim); font-size: 0.9rem; }

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  font-size: 0.95rem;
  padding: 11px 6px;
  margin: 0 -6px;
  min-height: 44px;
  border-radius: 0;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.12s ease;
}

.checkbox-row:active {
  background: var(--bg-elevated);
}

.checkbox-row input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 26px;
  height: 26px;
  margin: 0;
  border-radius: 0;
  border: 2px solid var(--border);
  background: var(--bg-elevated);
  flex-shrink: 0;
  position: relative;
  transition: background 0.12s ease, border-color 0.12s ease;
}

.checkbox-row input[type="checkbox"]:checked {
  background: var(--accent);
  border-color: var(--accent);
}

.checkbox-row input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  left: 8px;
  top: 3px;
  width: 7px;
  height: 13px;
  border: solid white;
  border-width: 0 3px 3px 0;
  transform: rotate(45deg);
}

.up-next-icon {
  width: 20px;
  height: 20px;
  image-rendering: pixelated;
  flex-shrink: 0;
}

/* --- Stages --- */

.stages-section { margin-top: 4px; }

.stage-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 12px;
}

.stage-card.complete {
  border-color: var(--accent);
}

.stage-header {
  all: unset;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  cursor: pointer;
  font-weight: 600;
}

.stage-title { display: flex; align-items: center; gap: 8px; }
.stage-icon { width: 22px; height: 22px; image-rendering: pixelated; flex-shrink: 0; }

.stage-progress {
  font-family: var(--font-mono);
  color: var(--text-dim);
  font-size: 0.85rem;
  font-weight: 500;
}

.stage-bar { margin-top: 10px; }

.stage-blurb {
  margin: 8px 0 0;
  color: var(--text-dim);
  font-size: 0.85rem;
}

.stage-tasks {
  list-style: none;
  margin: 10px 0 0;
  padding: 10px 0 0;
  border-top: 1px solid var(--border);
}

.stage-link {
  all: unset;
  display: inline-block;
  margin-top: 10px;
  color: var(--accent-bright);
  font-size: 0.85rem;
  cursor: pointer;
}

.stage-link:hover { text-decoration: underline; }

.text-btn {
  all: unset;
  display: block;
  margin: 4px auto 24px;
  color: var(--danger);
  font-size: 0.85rem;
  cursor: pointer;
  text-align: center;
  width: fit-content;
}

.text-btn:hover { text-decoration: underline; }

/* --- Recipes --- */

.recipes-toolbar { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5; }

#search-input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 0;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 0.95rem;
  margin-bottom: 10px;
}

#search-input:focus {
  outline: none;
  border-color: var(--accent);
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  all: unset;
  padding: 5px 12px;
  border-radius: 0;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-dim);
  font-size: 0.8rem;
  cursor: pointer;
  white-space: nowrap;
}

.chip.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-bright);
}

.recipes-count {
  margin: 10px 0 0;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-dim);
}

.recipes-list {
  display: grid;
  gap: 10px;
}

.recipe-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}

.recipe-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.recipe-icon {
  width: 32px;
  height: 32px;
  image-rendering: pixelated;
  flex-shrink: 0;
  background: var(--bg-elevated);
  border-radius: 0;
  padding: 3px;
}

.recipe-name { font-weight: 600; font-size: 0.95rem; }

.recipe-station {
  font-size: 0.75rem;
  color: var(--text-dim);
}

.recipe-equation {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
}

.ingredient {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 3px 8px;
}

.ingredient .qty {
  font-family: var(--font-mono);
}

.ingredient.output {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.ing-icon {
  width: 18px;
  height: 18px;
  image-rendering: pixelated;
  flex-shrink: 0;
}

.plus, .arrow {
  color: var(--text-dim);
  font-size: 0.85rem;
}

.recipe-note {
  margin: 8px 0 0;
  font-size: 0.8rem;
  color: var(--text-dim);
  font-style: italic;
}

.empty-state {
  color: var(--text-dim);
  text-align: center;
  padding: 24px 0;
}

/* --- Bottom nav --- */

.bottom-nav {
  flex: 0 0 auto;
  display: flex;
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.nav-btn {
  all: unset;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 0 8px;
  color: var(--text-dim);
  cursor: pointer;
  text-align: center;
}

.nav-icon {
  width: 22px;
  height: 22px;
  image-rendering: pixelated;
}

.nav-btn span {
  font-size: 0.68rem;
  letter-spacing: 0.3px;
}

.nav-btn.active {
  color: var(--accent-bright);
}

@media (min-width: 720px) {
  .bottom-nav {
    position: fixed;
    left: 50%;
    bottom: 16px;
    z-index: 10;
    max-width: 320px;
    transform: translateX(-50%);
    border: 1px solid var(--border);
    border-radius: 0;
    overflow: hidden;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  }

  main { padding: 24px 16px 80px; }
}
