/* Myco — Earth-tone dark theme */

:root {
  --bg:           #1a1814;
  --bg-elevated:  #232017;
  --bg-card:      #2a2620;
  --border:       #3a342a;
  --text:         #e8e2d4;
  --text-dim:     #a39a85;
  --text-faint:   #6b6353;
  --accent:       #8aa468;       /* mossy green */
  --accent-dim:   #5e7548;
  --accent-bg:    #2d3a23;
  --warn:         #c98e4a;
  --danger:       #b6543c;
  --shadow:       0 2px 8px rgba(0,0,0,0.3);

  --tab-h: 64px;
  --header-h: 56px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

body {
  min-height: 100vh;
  padding-top: var(--safe-top);
  padding-bottom: calc(var(--tab-h) + var(--safe-bottom));
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

button {
  font: inherit;
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  cursor: pointer;
  min-height: 44px;
}
button:hover { background: var(--bg-card); }
button.primary {
  background: var(--accent);
  color: #1a1a14;
  border-color: var(--accent);
  font-weight: 600;
}
button.primary:hover { background: #9bb678; }
button.danger {
  background: transparent;
  color: var(--danger);
  border-color: var(--danger);
}

input, select, textarea {
  font: inherit;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  width: 100%;
  min-height: 44px;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
}

/* ---------------- Top header ---------------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: var(--header-h);
}
.app-header h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0.2px;
  flex: 1;
}
.app-header .back {
  background: transparent;
  border: none;
  color: var(--accent);
  padding: 0 4px;
  min-height: auto;
  font-size: 16px;
}

.search-bar {
  position: sticky;
  top: var(--header-h);
  z-index: 40;
  background: var(--bg);
  padding: 10px 16px 8px;
  border-bottom: 1px solid var(--border);
}
.search-bar input {
  background: var(--bg-elevated);
}

/* ---------------- Bottom tabs ---------------- */
.tab-bar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 100;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
  height: calc(var(--tab-h) + var(--safe-bottom));
}
.tab-bar a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  text-decoration: none;
  color: var(--text-dim);
  font-size: 12px;
  letter-spacing: 0.2px;
  padding: 8px 0;
  transition: color 0.15s;
}
.tab-bar a.active { color: var(--accent); }
.tab-bar a:hover { color: var(--text); }
.tab-bar a.active:hover { color: var(--accent); }
.tab-bar .tab-icon {
  font-size: 22px;
  line-height: 1;
}

/* ---------------- Content layout ---------------- */
.content {
  padding: 16px;
  max-width: 720px;
  margin: 0 auto;
}

.section-header {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 24px 0 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.section-header h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.section-header .count {
  color: var(--text-faint);
  font-size: 13px;
}
.section-header:first-child { margin-top: 4px; }

/* ---------------- Category chip strip ---------------- */
.category-chips {
  position: sticky;
  top: var(--header-h);
  z-index: 40;
  background: var(--bg);
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  scrollbar-width: none;
}
.category-chips::-webkit-scrollbar { display: none; }
.category-chips a {
  flex: 0 0 auto;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
}
.category-chips a:hover { color: var(--text); text-decoration: none; }

/* ---------------- Card list rows ---------------- */
.card-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.card-row {
  display: flex;
  gap: 12px;
  padding: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s, transform 0.05s;
}
.card-row:hover {
  border-color: var(--accent-dim);
  text-decoration: none;
}
.card-row:active { transform: scale(0.99); }
.card-row .thumb {
  flex: 0 0 64px;
  width: 64px;
  height: 64px;
  border-radius: 8px;
  background: var(--bg);
  background-size: cover;
  background-position: center;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-faint);
  font-size: 24px;
}
.card-row .body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  justify-content: center;
}
.card-row .title {
  font-weight: 600;
  font-size: 16px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}
.card-row .title .video-badge {
  font-size: 12px;
  color: var(--accent);
}
.card-row .preview {
  font-size: 14px;
  color: var(--text-dim);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ---------------- Card detail ---------------- */
.card-detail .meta {
  color: var(--text-faint);
  font-size: 13px;
  margin-bottom: 16px;
}
.card-detail .category-chip {
  display: inline-block;
  padding: 4px 10px;
  background: var(--accent-bg);
  color: var(--accent);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  margin-right: 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.video-frame {
  position: relative;
  width: 100%;
  padding-bottom: 56.25%;
  background: #000;
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 16px;
}
.video-frame iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

.video-dead {
  padding: 14px 16px;
  background: var(--bg-card);
  border: 1px solid var(--warn);
  border-radius: 10px;
  margin-bottom: 16px;
  color: var(--text-dim);
  font-size: 14px;
}
.video-dead strong { color: var(--warn); }

.desc {
  white-space: pre-wrap;
  font-size: 16px;
  line-height: 1.6;
  word-wrap: break-word;
}
.desc h1, .desc h2, .desc h3 {
  font-size: 17px;
  margin: 20px 0 8px;
  color: var(--accent);
}
.desc ol, .desc ul { padding-left: 24px; }
.desc li { margin-bottom: 4px; }

.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
  margin-top: 20px;
}
.image-grid a {
  display: block;
  aspect-ratio: 1;
  border-radius: 8px;
  background-size: cover;
  background-position: center;
  background-color: var(--bg-card);
  border: 1px solid var(--border);
}

.pdf-list {
  margin-top: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.pdf-list a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
}
.pdf-list .icon {
  font-size: 22px;
}

/* ---------------- Lightbox ---------------- */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.95);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  cursor: zoom-out;
}
.lightbox.open { display: flex; }
.lightbox img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

/* ---------------- Empty + loading states ---------------- */
.empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-faint);
}
.empty h3 { color: var(--text-dim); margin: 0 0 8px; }

.loading {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-faint);
}

/* ---------------- Install hint ---------------- */
.install-hint {
  position: fixed;
  bottom: calc(var(--tab-h) + var(--safe-bottom) + 12px);
  left: 16px;
  right: 16px;
  background: var(--accent-bg);
  color: var(--text);
  border: 1px solid var(--accent-dim);
  border-radius: 10px;
  padding: 12px 14px;
  display: none;
  z-index: 60;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.install-hint.hidden { display: none; }
.install-hint button {
  margin-left: auto;
  background: transparent;
  border: 1px solid var(--accent-dim);
  color: var(--accent);
}

/* ---------------- Spores ---------------- */
.spore-row .thumb { background-color: var(--accent-bg); }
.spore-detail .images { margin-top: 12px; }

.filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 16px 8px;
}
.filter-chips button {
  padding: 4px 10px;
  font-size: 13px;
  background: var(--bg-elevated);
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 999px;
  min-height: 0;
}
.filter-chips button.on {
  background: var(--accent-bg);
  color: var(--accent);
  border-color: var(--accent-dim);
}

/* ---------------- Batches ---------------- */
.stage-header {
  margin-top: 24px;
  margin-bottom: 8px;
  padding: 8px 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.stage-header h3 {
  margin: 0;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--accent);
}
.stage-header .count {
  color: var(--text-faint);
  font-size: 13px;
}

.batch-card {
  padding: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 8px;
}
.batch-card .row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 4px;
}
.batch-card .strain { font-weight: 600; }
.batch-card .date { color: var(--text-faint); font-size: 13px; }
.batch-card .qty { color: var(--text-dim); font-size: 13px; }
.batch-card .notes { color: var(--text-dim); font-size: 14px; margin-top: 6px; white-space: pre-wrap; }
.batch-card .actions {
  margin-top: 10px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.batch-card .actions button {
  padding: 6px 10px;
  font-size: 13px;
  min-height: 36px;
}

.fab {
  position: fixed;
  bottom: calc(var(--tab-h) + var(--safe-bottom) + 16px);
  right: 16px;
  z-index: 60;
  background: var(--accent);
  color: #1a1a14;
  border: none;
  border-radius: 50%;
  width: 56px;
  height: 56px;
  font-size: 28px;
  font-weight: 600;
  box-shadow: var(--shadow);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.fab:hover { background: #9bb678; }

/* ---------------- Modal ---------------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 150;
  display: none;
  align-items: flex-end;
  justify-content: center;
}
.modal-backdrop.open { display: flex; }
.modal {
  width: 100%;
  max-width: 560px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-bottom: 0;
  border-radius: 14px 14px 0 0;
  padding: 20px;
  padding-bottom: calc(20px + var(--safe-bottom));
  max-height: 90vh;
  overflow-y: auto;
}
.modal h2 { margin: 0 0 16px; font-size: 18px; }
.modal .form-row {
  margin-bottom: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.modal .form-row label {
  font-size: 13px;
  color: var(--text-dim);
  font-weight: 500;
}
.modal .actions {
  display: flex;
  gap: 8px;
  margin-top: 20px;
}
.modal .actions button { flex: 1; }

/* ---------------- Tools ---------------- */
.tool-anchors {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 24px;
}
.tool-anchors a {
  flex: 1 1 calc(50% - 4px);
  text-align: center;
  padding: 10px 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
}

.tool {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
}
.tool h2 {
  margin: 0 0 4px;
  font-size: 17px;
  color: var(--accent);
}
.tool p.desc-line {
  margin: 0 0 14px;
  color: var(--text-dim);
  font-size: 14px;
}
.tool .inputs {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.tool .field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.tool .field label {
  font-size: 13px;
  color: var(--text-dim);
}
.tool .results {
  margin-top: 16px;
  padding: 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
}
.tool .results .row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
}
.tool .results .row + .row {
  border-top: 1px dashed var(--border);
}
.tool .results .label { color: var(--text-dim); }
.tool .results .value { font-weight: 600; color: var(--accent); }
