:root {
  --bg: #0f172a;
  --bg2: #1e293b;
  --bg3: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent-dark: #0284c7;
  --danger: #f87171;
  --success: #4ade80;
  --radius: 12px;
}

:root[data-theme="light"] {
  --bg: #e2e8f0;
  --bg2: #ffffff;
  --bg3: #cbd5e1;
  --text: #0f172a;
  --muted: #475569;
  --accent: #075985;
  --accent-dark: #0369a1;
  --danger: #b91c1c;
  --success: #15803d;
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: 84px;
  transition: background .2s, color .2s;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg2);
  padding: 10px 16px 12px;
  padding-top: calc(10px + env(safe-area-inset-top));
  box-shadow: 0 2px 8px rgba(0,0,0,.4);
}
.topbar-row { display: flex; align-items: center; justify-content: space-between; }
.topbar h1 { font-size: 1.15rem; font-weight: 600; }
.icon-btn {
  background: var(--bg3);
  border: none;
  color: var(--text);
  font-size: 1.1rem;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}
.top-links { display: flex; gap: 8px; margin-top: 8px; overflow-x: auto; }
.top-links a {
  background: var(--bg3);
  color: var(--accent);
  text-decoration: none;
  font-size: .85rem;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 999px;
  white-space: nowrap;
}

main { padding: 16px; max-width: 640px; margin: 0 auto; }

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

.section-label {
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  margin: 18px 0 8px;
}

.muted { color: var(--muted); font-size: .9rem; margin: 6px 0; }

/* Cards */
.card-list { display: flex; flex-direction: column; gap: 8px; }
.card {
  background: var(--bg2);
  border: 1px solid var(--bg3);
  border-radius: var(--radius);
  padding: 14px 16px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  transition: background .15s;
  -webkit-tap-highlight-color: transparent;
}
.card:active { background: var(--bg3); }
.card .card-title { font-weight: 600; font-size: .95rem; }
.card .card-sub { color: var(--muted); font-size: .8rem; margin-top: 2px; }
.card .chevron { color: var(--muted); flex-shrink: 0; }
.card > div:first-child { flex: 1; min-width: 0; }
.draft-flag { color: var(--accent) !important; font-weight: 600; }

/* Buttons */
.btn {
  border: none;
  border-radius: var(--radius);
  padding: 12px 18px;
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn-primary { background: var(--accent-dark); color: #fff; }
.btn-primary:active { background: var(--accent); }
.btn-secondary { background: var(--bg3); color: var(--text); }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn-ghost { background: transparent; color: var(--accent); padding: 12px 8px; }
.btn-row { display: flex; gap: 10px; margin: 16px 0; flex-wrap: wrap; }

/* Editor */
.editor-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}
.editor-title { font-weight: 700; font-size: 1rem; flex: 1; min-width: 0; }
.autosave-status { color: var(--success); font-size: .8rem; white-space: nowrap; }
.btn-clear {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
  padding: 8px 14px;
  font-size: .85rem;
}

.field-label {
  display: block;
  font-size: .85rem;
  color: var(--muted);
  margin: 12px 0 4px;
}

.extras-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 14px 0 4px;
  font-size: .85rem;
  color: var(--muted);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.fav-btn {
  background: none;
  border: none;
  color: var(--bg3);
  font-size: 1.25rem;
  line-height: 1;
  padding: 12px 10px;
  margin: -12px 0;
  cursor: pointer;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
  transition: color .15s;
}
.fav-btn:hover { color: var(--muted); }
.fav-btn.active, .fav-btn.active:hover { color: #facc15; }
.fav-divider {
  border-top: 1px solid var(--bg3);
  margin: 6px 2px;
}

.wiki-images {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 10px;
}
.wiki-thumb {
  position: relative;
}
.wiki-thumb img {
  width: 96px;
  height: 96px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--bg3);
  display: block;
}
.wiki-thumb-rm {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 24px;
  height: 24px;
  border: none;
  border-radius: 50%;
  background: var(--danger);
  color: #fff;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}

.extras-toggle input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent-dark);
}

input[type="text"], input[type="search"], textarea {
  width: 100%;
  background: var(--bg2);
  border: 1px solid var(--bg3);
  border-radius: var(--radius);
  color: var(--text);
  padding: 12px 14px;
  font-size: 16px; /* prevents iOS zoom */
  font-family: inherit;
}
input:focus, textarea:focus { outline: 2px solid var(--accent-dark); border-color: transparent; }
textarea { resize: vertical; }

#wiki-search { margin-bottom: 4px; }

input.mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 1.1rem; letter-spacing: .05em; }
.wiki-link { text-decoration: none; }

/* Grouped job picker */
.sub-picker { display: flex; gap: 10px; padding: 4px 8px 4px 24px; }
.sub-picker .sub-option { flex: 1; }

/* Info button + modal */
.info-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  margin-left: 6px;
  border-radius: 50%;
  border: 1.5px solid var(--accent);
  background: transparent;
  color: var(--accent);
  font-size: .7rem;
  font-weight: 700;
  font-style: italic;
  font-family: Georgia, serif;
  cursor: pointer;
  vertical-align: middle;
}
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0,0,0,.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.modal-box {
  background: var(--bg2);
  border: 1px solid var(--bg3);
  border-radius: var(--radius);
  padding: 20px;
  max-width: 420px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}
.modal-box pre {
  background: none;
  border: none;
  padding: 0 4px 0 0;
  font-family: inherit;
  font-size: .95rem;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  min-height: 0;
}

/* Smart fields */
.combo { display: flex; gap: 6px; }
.combo input { flex: 1; min-width: 0; }
.combo select {
  width: 48px;
  background: var(--bg3);
  color: var(--text);
  border: 1px solid var(--bg3);
  border-radius: var(--radius);
  font-size: 16px;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  text-align: center;
  text-align-last: center;
  cursor: pointer;
}

/* Back button */
.btn-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--accent-dark);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 10px 16px;
  font-size: .9rem;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}
.btn-back:active { opacity: .85; }
.speed { display: flex; gap: 6px; }
.speed input { flex: 1; min-width: 0; padding: 12px 8px; }
.speed-out { color: var(--accent); font-size: .85rem; margin-top: 4px; min-height: 1em; }

/* Preview */
pre {
  background: var(--bg2);
  border: 1px solid var(--bg3);
  border-radius: var(--radius);
  padding: 14px;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: .85rem;
  line-height: 1.45;
}

/* Photo checklist */
.check-list { display: flex; flex-direction: column; gap: 6px; }
.check-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg2);
  border: 1px solid var(--bg3);
  border-radius: var(--radius);
  padding: 12px 14px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.check-item input[type="checkbox"] {
  width: 22px; height: 22px;
  accent-color: var(--accent-dark);
  flex-shrink: 0;
}
.check-item.done span { text-decoration: line-through; color: var(--muted); }
.check-progress {
  font-size: .85rem;
  color: var(--accent);
  margin-bottom: 10px;
  font-weight: 600;
}

/* Bottom nav */
.bottombar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--bg2);
  border-top: 1px solid var(--bg3);
  display: flex;
  z-index: 20;
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-btn {
  flex: 1;
  background: none;
  border: none;
  color: var(--muted);
  padding: 10px 0 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: .7rem;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.nav-btn .nav-icon { font-size: 1.25rem; }
.nav-btn.active { color: var(--accent); }

/* Contacts */
a.card { color: inherit; text-decoration: none; }
.contact {
  background: var(--bg2);
  border: 1px solid var(--bg3);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.contact .warn { color: var(--danger); font-weight: 700; font-size: .8rem; margin-top: 4px; }
.contact-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.contact-actions .btn { text-decoration: none; display: inline-block; }

/* Toast */
.toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg3);
  color: var(--text);
  padding: 10px 20px;
  border-radius: 999px;
  font-size: .9rem;
  box-shadow: 0 4px 16px rgba(0,0,0,.5);
  z-index: 30;
  white-space: nowrap;
}
