@import url('https://fonts.googleapis.com/css2?family=Instrument+Serif:ital@0;1&family=Outfit:wght@300;400;500;600;700&display=swap');

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

:root {
  --bg: #080808;
  --surface: #111110;
  --surface-raised: #1a1918;
  --surface-hover: #222120;
  --border: #2a2928;
  --border-light: #3a3938;
  --text: #e6e1d8;
  --text-dim: #8a8580;
  --text-faint: #5a5550;
  --accent: #d4a43a;
  --accent-dim: #b08a2e;
  --accent-glow: rgba(212, 164, 58, 0.12);
  --accent-glow-strong: rgba(212, 164, 58, 0.25);
  --google: #4285f4;
  --waze: #05c8f7;
  --apple: #ff453a;
  --error: #e5484d;
  --radius: 14px;
  --radius-sm: 10px;
  --radius-xs: 7px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font-display: 'Instrument Serif', Georgia, serif;
  --font-body: 'Outfit', -apple-system, sans-serif;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  overscroll-behavior: none;
}

/* ——— App Container ——— */
#app {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: calc(24px + var(--safe-top)) 20px calc(24px + var(--safe-bottom));
  opacity: 0;
  visibility: hidden;
  transform: translateY(12px);
  transition: opacity 0.35s ease, transform 0.35s ease, visibility 0s 0.35s;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.screen.active {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  transition: opacity 0.35s ease, transform 0.35s ease, visibility 0s 0s;
}

/* ——— Settings Button ——— */
.btn-settings {
  position: absolute;
  top: calc(16px + var(--safe-top));
  right: 16px;
  z-index: 10;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  cursor: pointer;
  transition: all 0.2s ease;
  -webkit-appearance: none;
}

.btn-settings:active {
  background: var(--surface);
  color: var(--text);
}

.btn-settings svg {
  width: 18px;
  height: 18px;
}

/* ——— Home Screen ——— */
.brand {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding-bottom: 20px;
}

.brand-icon {
  width: 72px;
  height: 72px;
  margin-bottom: 8px;
  animation: pin-float 3s ease-in-out infinite;
}

.brand-icon svg {
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 4px 20px var(--accent-glow-strong));
}

@keyframes pin-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

.brand h1 {
  font-family: var(--font-display);
  font-size: 52px;
  font-weight: 400;
  letter-spacing: -0.02em;
  color: var(--text);
  line-height: 1;
}

.brand p {
  font-size: 15px;
  font-weight: 300;
  color: var(--text-dim);
  letter-spacing: 0.01em;
}

.home-actions {
  display: flex;
  gap: 12px;
  padding-bottom: 12px;
}

.btn-action {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 22px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  -webkit-appearance: none;
}

.btn-action:active {
  background: var(--surface-hover);
  transform: scale(0.97);
}

.btn-action svg {
  width: 28px;
  height: 28px;
  color: var(--accent);
}

/* ——— Address Search ——— */
.address-search {
  position: relative;
  padding-bottom: 12px;
}

.search-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 14px;
  width: 16px;
  height: 16px;
  color: var(--text-faint);
  pointer-events: none;
}

.address-input {
  width: 100%;
  padding: 14px 40px 14px 40px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 400;
  outline: none;
  transition: border-color 0.2s ease;
  -webkit-appearance: none;
}

.address-input:focus {
  border-color: var(--accent-dim);
}

.address-input::placeholder {
  color: var(--text-faint);
}

.btn-clear-search {
  position: absolute;
  right: 8px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--text-faint);
  cursor: pointer;
  -webkit-appearance: none;
  border-radius: 50%;
}

.btn-clear-search:active {
  background: var(--surface-hover);
}

.btn-clear-search svg {
  width: 14px;
  height: 14px;
}

.suggestions {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 50;
  margin-top: -8px;
  padding: 4px 0;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  list-style: none;
  max-height: 240px;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}

.suggestions li {
  padding: 12px 14px;
  font-size: 13px;
  line-height: 1.4;
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s ease;
  border-bottom: 1px solid var(--border);
}

.suggestions li:last-child {
  border-bottom: none;
}

.suggestions li:active {
  background: var(--surface-hover);
}

.suggestions li .suggestion-main {
  font-weight: 500;
  color: var(--text);
}

.suggestions li .suggestion-detail {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 2px;
}

.suggestions .suggestion-loading {
  padding: 14px;
  text-align: center;
  font-size: 12px;
  color: var(--text-faint);
  cursor: default;
}

.drop-zone {
  position: relative;
  padding: 28px;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  text-align: center;
  transition: all 0.25s ease;
  cursor: pointer;
}

.drop-zone p {
  font-size: 13px;
  font-weight: 400;
  color: var(--text-faint);
}

.drop-zone.dragover {
  border-color: var(--accent);
  background: var(--accent-glow);
}

.drop-zone.dragover p {
  color: var(--accent);
}

.home-tip {
  padding: 16px 0 4px;
  text-align: center;
  font-size: 12px;
  color: var(--text-faint);
  letter-spacing: 0.02em;
}

.version-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 8px 0 0;
}

.version-tag {
  text-align: center;
  font-size: 10px;
  color: var(--text-faint);
  letter-spacing: 0.06em;
  opacity: 0.6;
}

.btn-update {
  padding: 4px 10px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  color: var(--text-faint);
  font-family: var(--font-body);
  font-size: 10px;
  font-weight: 500;
  cursor: pointer;
  -webkit-appearance: none;
  transition: all 0.2s ease;
}

.btn-update:active {
  background: var(--surface);
  color: var(--accent);
  border-color: var(--accent-dim);
}

/* ——— Processing Screen ——— */
.processing-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 32px;
  padding: 20px 0;
}

.preview-container {
  position: relative;
  width: 100%;
  max-width: 320px;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
}

.preview-container img {
  width: 100%;
  display: block;
  max-height: 280px;
  object-fit: contain;
  background: var(--surface);
}

.preview-overlay {
  position: absolute;
  inset: 0;
  background: rgba(8, 8, 8, 0.5);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
}

.scan-line {
  position: absolute;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  box-shadow: 0 0 16px var(--accent-glow-strong);
  animation: scan 2s ease-in-out infinite;
}

@keyframes scan {
  0% { top: 10%; opacity: 0; }
  10% { opacity: 1; }
  90% { opacity: 1; }
  100% { top: 90%; opacity: 0; }
}

.progress-section {
  width: 100%;
  max-width: 320px;
  text-align: center;
}

.progress-track {
  width: 100%;
  height: 4px;
  background: var(--surface);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 14px;
}

.progress-fill {
  width: 0%;
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.4s ease;
  box-shadow: 0 0 12px var(--accent-glow-strong);
}

.progress-fill.indeterminate {
  width: 30% !important;
  animation: indeterminate 1.4s ease-in-out infinite;
}

@keyframes indeterminate {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(430%); }
}

.progress-text {
  font-size: 13px;
  font-weight: 400;
  color: var(--text-dim);
  letter-spacing: 0.02em;
}

.btn-cancel {
  margin-top: 8px;
  padding: 10px 24px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-family: var(--font-body);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-cancel:active {
  background: var(--surface);
}

/* ——— Results Screen ——— */
.results-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding-bottom: 20px;
  flex-shrink: 0;
}

.btn-back {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  -webkit-appearance: none;
  flex-shrink: 0;
}

.btn-back:active {
  background: var(--surface-hover);
}

.btn-back svg {
  width: 14px;
  height: 14px;
}

.results-title {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 400;
  color: var(--text);
}

.results-scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 20px;
}

/* Address Card */
.address-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 12px;
  opacity: 0;
  transform: translateY(16px);
  animation: card-enter 0.4s ease forwards;
}

.address-card:nth-child(1) { animation-delay: 0.05s; }
.address-card:nth-child(2) { animation-delay: 0.12s; }
.address-card:nth-child(3) { animation-delay: 0.19s; }
.address-card:nth-child(4) { animation-delay: 0.26s; }
.address-card:nth-child(5) { animation-delay: 0.33s; }

@keyframes card-enter {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.address-top {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 6px;
}

.address-pin {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-glow);
  border-radius: var(--radius-xs);
  color: var(--accent);
}

.address-pin svg {
  width: 18px;
  height: 18px;
}

.address-text {
  flex: 1;
  font-size: 15px;
  font-weight: 400;
  line-height: 1.45;
  color: var(--text);
  word-break: break-word;
}

.address-coords {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 2px;
  font-family: 'SF Mono', 'Fira Code', monospace;
  letter-spacing: 0.02em;
}

.map-buttons {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 14px;
}

.map-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.2s ease;
  -webkit-appearance: none;
}

.map-btn:active {
  transform: scale(0.95);
}

.map-btn svg {
  width: 24px;
  height: 24px;
}

.map-btn--google { border-color: rgba(66, 133, 244, 0.3); }
.map-btn--google:active { background: rgba(66, 133, 244, 0.1); }
.map-btn--google svg { color: var(--google); }

.map-btn--waze { border-color: rgba(5, 200, 247, 0.3); }
.map-btn--waze:active { background: rgba(5, 200, 247, 0.1); }
.map-btn--waze svg { color: var(--waze); }

.map-btn--apple { border-color: rgba(255, 69, 58, 0.3); }
.map-btn--apple:active { background: rgba(255, 69, 58, 0.1); }
.map-btn--apple svg { color: var(--apple); }

/* Copy button row */
.address-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.btn-copy {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  color: var(--text-dim);
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  -webkit-appearance: none;
}

.btn-copy:active {
  background: var(--surface-hover);
}

.btn-copy svg {
  width: 12px;
  height: 12px;
}

.btn-copy.copied {
  color: var(--accent);
  border-color: var(--accent-dim);
}

/* No Results */
.no-results {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  text-align: center;
  padding: 40px 0;
}

.no-results-icon {
  width: 56px;
  height: 56px;
  color: var(--text-faint);
  margin-bottom: 4px;
}

.no-results h3 {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 400;
  color: var(--text);
}

.no-results p {
  font-size: 14px;
  color: var(--text-dim);
  max-width: 260px;
}

.error-text {
  color: var(--error);
  font-size: 13px;
  max-width: 300px;
}

.manual-input-group {
  display: flex;
  gap: 8px;
  width: 100%;
  max-width: 360px;
  margin-top: 4px;
}

.manual-input {
  flex: 1;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s ease;
}

.manual-input:focus {
  border-color: var(--accent-dim);
}

.manual-input::placeholder {
  color: var(--text-faint);
}

.btn-manual {
  padding: 12px 20px;
  background: var(--accent);
  border: none;
  border-radius: var(--radius-sm);
  color: var(--bg);
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  -webkit-appearance: none;
  flex-shrink: 0;
}

.btn-manual:active {
  background: var(--accent-dim);
  transform: scale(0.97);
}

/* Raw text toggle */
.raw-text-section {
  margin-top: 20px;
  border-top: 1px solid var(--border);
  padding-top: 16px;
}

.btn-raw-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 10px 0;
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  -webkit-appearance: none;
}

.btn-raw-toggle svg {
  width: 12px;
  height: 12px;
  transition: transform 0.2s ease;
}

.btn-raw-toggle.open svg {
  transform: rotate(90deg);
}

.raw-text-content {
  display: none;
  padding: 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  font-family: var(--font-body);
  font-size: 12px;
  line-height: 1.7;
  color: var(--text-dim);
  word-break: break-word;
  max-height: 280px;
  overflow-y: auto;
  margin-top: 8px;
}

.raw-text-content .resp-label {
  color: var(--accent);
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.raw-text-content .resp-link {
  color: var(--google);
  text-decoration: none;
  word-break: break-all;
  font-size: 11px;
}

.raw-text-content .resp-link:active {
  opacity: 0.7;
}

.raw-text-content .resp-hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 8px 0;
}

.raw-text-content.open {
  display: block;
}

/* ——— Settings Modal ——— */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 1;
  transition: opacity 0.25s ease;
}

.modal-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.modal {
  width: 100%;
  max-width: 440px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 24px 20px calc(24px + var(--safe-bottom));
  transform: translateY(0);
  transition: transform 0.3s ease;
}

.modal-overlay.hidden .modal {
  transform: translateY(100%);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.modal-header h3 {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 400;
}

.btn-modal-close {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  color: var(--text-dim);
  cursor: pointer;
  -webkit-appearance: none;
}

.btn-modal-close svg {
  width: 16px;
  height: 16px;
}

.modal-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.input-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-dim);
  letter-spacing: 0.02em;
}

.key-input-row {
  display: flex;
  gap: 8px;
}

.key-input-row .manual-input {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 13px;
  letter-spacing: 0.02em;
}

.btn-toggle-key {
  width: 44px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  cursor: pointer;
  -webkit-appearance: none;
}

.btn-toggle-key svg {
  width: 18px;
  height: 18px;
}

.input-hint {
  font-size: 11px;
  color: var(--text-faint);
  line-height: 1.4;
}

.btn-save-key {
  width: 100%;
  margin-top: 4px;
  text-align: center;
}

/* Utility */
.hidden {
  display: none !important;
}

input[type="file"] {
  display: none;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 4px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

/* Desktop enhancements */
@media (min-width: 480px) {
  .screen {
    max-width: 440px;
    margin: 0 auto;
    padding-left: 24px;
    padding-right: 24px;
  }

  .brand h1 {
    font-size: 64px;
  }

  .map-buttons {
    gap: 10px;
  }

  .modal {
    border-radius: var(--radius);
    margin-bottom: 40px;
  }

  .modal-overlay {
    align-items: center;
  }
}

@media (min-width: 768px) {
  .screen {
    max-width: 520px;
  }
}
