:root {
  --ink-950: #0e1216;
  --ink-900: #161b21;
  --ink-800: #1f2630;
  --ink-700: #2c3640;
  --ink-600: #46535f;
  --ink-500: #5e6b77;
  --ink-300: #b6c0c9;
  --ink-200: #d7dde2;
  --ink-100: #e9edf0;
  --ink-50: #f4f6f7;
  --paper: #fafbfc;
  --white: #ffffff;
  --clay-800: #8f3914;
  --clay-700: #b4471a;
  --clay-600: #d2551f;
  --clay-50: #fdf2eb;
  --green-600: #1f8a5b;
  --green-50: #eef7f1;
  --blue-600: #2670c0;
  --blue-50: #eff5fc;
  --gold-600: #b07d0a;
  --gold-50: #fbf6e3;
  --red-600: #c23a2b;
  --red-50: #fceeeb;
  --surface-panel: var(--white);
  --surface-page: var(--paper);
  --border-default: var(--ink-200);
  --text-primary: var(--ink-900);
  --text-secondary: var(--ink-600);
  --text-tertiary: var(--ink-500);
  --shadow-sheet: 0 -18px 48px rgba(14, 18, 22, 0.2);
  --shadow-card: 0 8px 24px rgba(14, 18, 22, 0.1);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: "Hanken Grotesk", Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text-primary);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--ink-950);
  color: var(--text-primary);
}

button,
input,
select {
  font: inherit;
}

button,
a.button {
  min-height: 44px;
}

code {
  font-family: "IBM Plex Mono", ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.92em;
}

.auth-body {
  background:
    radial-gradient(circle at 70% 12%, rgba(210, 85, 31, 0.18), transparent 28rem),
    linear-gradient(135deg, var(--ink-950), var(--ink-800));
}

.auth-shell {
  display: grid;
  min-height: 100%;
  padding: 24px;
  place-items: center;
}

.auth-panel {
  background: var(--surface-panel);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 16px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.35);
  max-width: 460px;
  padding: 28px;
}

.brand-mark {
  height: 58px;
  width: 58px;
}

.eyebrow {
  color: var(--text-tertiary);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  margin: 0 0 8px;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  font-size: clamp(2rem, 9vw, 3.2rem);
  letter-spacing: -0.015em;
  line-height: 0.95;
  margin-bottom: 14px;
}

h2 {
  font-size: 1.15rem;
  line-height: 1.15;
  margin-bottom: 6px;
}

.lede,
.muted {
  color: var(--text-secondary);
  line-height: 1.5;
}

.fine-print {
  color: var(--text-tertiary);
  font-size: 0.82rem;
  margin: 14px 0 0;
}

.notice,
.banner {
  border: 1px solid var(--border-default);
  border-radius: 8px;
  line-height: 1.4;
  padding: 10px 12px;
}

.notice.warning,
.banner.warning {
  background: var(--gold-50);
  border-color: rgba(176, 125, 10, 0.24);
  color: #855d09;
}

.notice.danger,
.banner.danger {
  background: var(--red-50);
  border-color: rgba(194, 58, 43, 0.24);
  color: #862518;
}

.banner.success {
  background: var(--green-50);
  border-color: rgba(31, 138, 91, 0.24);
  color: #185c3a;
}

.banner.info {
  background: var(--blue-50);
  border-color: rgba(38, 112, 192, 0.24);
  color: #1a4e8a;
}

.button,
.control-button,
.icon-text {
  align-items: center;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  font-weight: 800;
  justify-content: center;
  text-decoration: none;
}

.button {
  border: 1px solid transparent;
  padding: 0 16px;
}

.button.primary {
  background: var(--clay-600);
  color: var(--white);
}

.button.primary:hover {
  background: var(--clay-700);
}

.button.secondary,
.control-button,
.icon-text {
  background: var(--white);
  border: 1px solid var(--border-default);
  color: var(--ink-900);
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.button.small {
  font-size: 0.84rem;
  min-height: 36px;
}

.button.full {
  width: 100%;
}

.app-shell {
  background: var(--surface-page);
  height: 100vh;
  height: 100svh;
  margin: 0 auto;
  max-width: 520px;
  overflow: hidden;
  position: relative;
}

#map {
  height: 100%;
  width: 100%;
  z-index: 1;
}

.top-bar {
  align-items: center;
  display: flex;
  justify-content: space-between;
  left: 0;
  padding: calc(12px + var(--safe-top)) 12px 10px;
  pointer-events: none;
  position: absolute;
  right: 0;
  top: 0;
  z-index: 500;
}

.top-bar form,
.top-bar button {
  pointer-events: auto;
}

.brand-lockup {
  align-items: center;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(215, 221, 226, 0.9);
  border-radius: 999px;
  box-shadow: var(--shadow-card);
  display: flex;
  gap: 10px;
  padding: 8px 12px 8px 8px;
}

.brand-lockup strong {
  display: block;
  line-height: 1;
}

.brand-lockup span {
  color: var(--text-tertiary);
  display: block;
  font-size: 0.74rem;
  line-height: 1.1;
}

.runtime-status {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  justify-content: center;
  max-width: 142px;
}

.auth-runtime {
  justify-content: flex-start;
  margin: 0 0 14px;
  max-width: none;
}

.sheet-runtime {
  justify-content: flex-start;
  margin: 0 0 10px;
  max-width: none;
}

.runtime-pill {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--border-default);
  border-radius: 999px;
  box-shadow: var(--shadow-card);
  color: var(--ink-700);
  display: inline-flex;
  font-size: 0.66rem;
  font-weight: 900;
  line-height: 1;
  padding: 6px 8px;
  text-transform: uppercase;
  white-space: nowrap;
}

.runtime-pill.ready {
  border-color: rgba(31, 138, 91, 0.28);
  color: var(--green-600);
}

.runtime-pill.warning {
  border-color: rgba(176, 125, 10, 0.28);
  color: var(--gold-600);
}

.top-mark {
  height: 34px;
  width: 34px;
}

.icon-text {
  font-size: 0.84rem;
  min-height: 38px;
  padding: 0 12px;
}

.map-controls {
  display: grid;
  gap: 8px;
  position: absolute;
  right: 12px;
  top: calc(86px + var(--safe-top));
  width: min(178px, calc(100% - 24px));
  z-index: 450;
}

.control-button,
.select-label,
.toggle-line {
  backdrop-filter: blur(10px);
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--border-default);
  border-radius: 8px;
  box-shadow: var(--shadow-card);
  color: var(--ink-900);
}

.control-button {
  padding: 0 12px;
}

.select-label {
  display: grid;
  gap: 4px;
  padding: 8px 10px;
}

.select-label span {
  color: var(--text-tertiary);
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.select-label select {
  background: transparent;
  border: 0;
  color: var(--ink-900);
  font-weight: 800;
  outline: 0;
}

.toggle-line {
  align-items: center;
  display: flex;
  gap: 8px;
  min-height: 44px;
  padding: 0 12px;
}

.bottom-sheet {
  background: var(--surface-panel);
  border: 1px solid var(--border-default);
  border-radius: 16px 16px 0 0;
  bottom: 0;
  box-shadow: var(--shadow-sheet);
  left: 0;
  max-height: 62vh;
  overflow: auto;
  padding: 8px 16px calc(18px + var(--safe-bottom));
  position: absolute;
  right: 0;
  z-index: 400;
}

.sheet-grip {
  background: var(--ink-200);
  border-radius: 999px;
  height: 4px;
  margin: 0 auto 14px;
  width: 42px;
}

.sheet-section {
  border-top: 1px solid var(--ink-100);
  padding: 16px 0;
}

.sheet-section:first-of-type {
  border-top: 0;
  padding-top: 0;
}

.section-head {
  align-items: start;
  display: flex;
  gap: 14px;
  justify-content: space-between;
}

.score-badge {
  align-items: center;
  background: var(--ink-900);
  border-radius: 10px;
  color: var(--white);
  display: inline-flex;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 1.25rem;
  font-weight: 900;
  justify-content: center;
  min-height: 48px;
  min-width: 56px;
}

.best-topic {
  background: linear-gradient(var(--white), var(--white)) padding-box,
    linear-gradient(135deg, var(--clay-600), var(--blue-600)) border-box;
  border: 2px solid transparent;
  border-radius: 10px;
  margin: 14px 0;
  padding: 14px;
}

.best-topic h3 {
  margin-bottom: 6px;
}

.candidate-list,
.plan-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.candidate {
  border: 1px solid var(--border-default);
  border-radius: 10px;
  display: grid;
  gap: 8px;
  margin-top: 8px;
  padding: 12px;
}

.candidate-head {
  align-items: center;
  display: flex;
  gap: 10px;
  justify-content: space-between;
}

.candidate-title {
  font-weight: 900;
}

.meta-row {
  color: var(--text-tertiary);
  display: flex;
  flex-wrap: wrap;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.76rem;
  gap: 7px;
}

.tag {
  background: var(--ink-50);
  border: 1px solid var(--ink-100);
  border-radius: 999px;
  color: var(--ink-700);
  font-size: 0.72rem;
  font-weight: 800;
  padding: 3px 7px;
  text-transform: uppercase;
}

.progress-track {
  background: var(--ink-100);
  border-radius: 999px;
  height: 10px;
  overflow: hidden;
}

.progress-track span {
  animation: progress 1.4s ease-in-out infinite;
  background: var(--clay-600);
  border-radius: inherit;
  display: block;
  height: 100%;
  width: 42%;
}

@keyframes progress {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(240%); }
}

.download-actions {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr 1fr;
  margin: 14px 0;
}

.bundle-meta {
  margin: 8px 0 12px;
}

.narrative-preview {
  background: var(--ink-50);
  border: 1px solid var(--ink-100);
  border-radius: 8px;
  color: var(--ink-800);
  font-size: 0.86rem;
  line-height: 1.45;
  margin: 12px 0;
  max-height: 180px;
  overflow: auto;
  padding: 12px;
  white-space: pre-wrap;
}

.reference-list {
  display: grid;
  gap: 8px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.reference-row {
  align-items: center;
  border: 1px solid var(--border-default);
  border-radius: 8px;
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr auto auto;
  padding: 10px;
}

.reference-row p {
  font-size: 0.78rem;
  margin: 2px 0 0;
  overflow-wrap: anywhere;
}

.reference-row.ready {
  border-color: rgba(31, 138, 91, 0.26);
}

.reference-row.failed {
  border-color: rgba(194, 58, 43, 0.26);
}

.handoff {
  background: var(--blue-50);
  border: 1px solid rgba(38, 112, 192, 0.2);
  border-radius: 10px;
  padding: 12px;
}

.handoff p {
  color: #1a4e8a;
  margin-bottom: 0;
}

.copy-row {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr auto;
  margin-top: 12px;
}

.copy-row input {
  background: var(--white);
  border: 1px solid rgba(38, 112, 192, 0.24);
  border-radius: 8px;
  color: var(--ink-900);
  font-family: "IBM Plex Mono", ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.78rem;
  min-width: 0;
  padding: 0 10px;
}

.copy-status {
  color: #1a4e8a;
  font-size: 0.82rem;
  margin-top: 8px;
}

.plan-list li {
  align-items: center;
  border: 1px solid var(--border-default);
  border-radius: 8px;
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  padding: 10px;
}

.plan-actions {
  display: grid;
  gap: 8px;
}

.bottom-sheet.pipeline-active .plan-panel {
  display: none;
}

.hidden {
  display: none !important;
}

.leaflet-control-attribution {
  font-size: 10px;
}

.leaflet-marker-icon.dp-marker {
  align-items: center;
  background: var(--ink-900);
  border: 2px solid var(--white);
  border-radius: 999px 999px 999px 4px;
  box-shadow: 0 4px 12px rgba(14, 18, 22, 0.25);
  color: var(--white);
  display: flex;
  font-size: 12px;
  font-weight: 900;
  justify-content: center;
  transform: rotate(-45deg);
}

.leaflet-marker-icon.dp-marker span {
  transform: rotate(45deg);
}

.leaflet-marker-icon.dp-marker.best {
  background: var(--clay-600);
}

@media (min-width: 720px) {
  .app-shell {
    border-left: 1px solid rgba(255, 255, 255, 0.08);
    border-right: 1px solid rgba(255, 255, 255, 0.08);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    scroll-behavior: auto !important;
    transition-duration: 0.001ms !important;
  }
}
