@import url("https://fonts.googleapis.com/css2?family=Geist:wght@400;500;600;700&family=Geist+Mono:wght@400;500;600;700&display=swap");

:root {
  color-scheme: light;
  --bg: #FAF8F4;
  --surface: #FFFFFF;
  --surface-alt: #F2EFE8;
  --surface-sunk: #F6F3EC;
  --text: #1A1816;
  --text-mute: #6E6864;
  --text-dim: #A19B95;
  --border: rgba(26,24,22,0.08);
  --border-strong: rgba(26,24,22,0.16);
  --success: #2F8A4F;
  --danger: #C25540;
  --accent: oklch(0.62 0.10 158);
  --accent-ink: #FFFFFF;
  --accent-soft: oklch(0.93 0.03 158);
  --outer-bg: #EFECE6;
  --shadow: 0 30px 80px rgba(40,30,20,0.10), 0 1px 0 rgba(0,0,0,0.04);
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #15130F;
  --surface: #1E1B17;
  --surface-alt: #272320;
  --surface-sunk: #0E0C0A;
  --text: #F5F1EA;
  --text-mute: #9B948C;
  --text-dim: #6A6560;
  --border: rgba(245,241,234,0.09);
  --border-strong: rgba(245,241,234,0.18);
  --success: #7FD391;
  --danger: #E26D5A;
  --accent-soft: oklch(0.28 0.05 158);
  --outer-bg: #0E0C0A;
  --shadow: 0 30px 80px rgba(0,0,0,0.4), 0 0 0 1px rgba(255,255,255,0.04);
}

* { box-sizing: border-box; }

html {
  min-height: 100%;
  background: var(--outer-bg);
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--outer-bg);
  color: var(--text);
  font-family: "Geist", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button, input {
  font: inherit;
}

[hidden] {
  display: none !important;
}

button {
  -webkit-tap-highlight-color: transparent;
}

a {
  color: inherit;
}

.app-shell {
  min-height: 100vh;
  display: flex;
  justify-content: center;
}

.app-column {
  position: relative;
  width: 100%;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
}

.page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 15px;
  padding: 14px 17px 20px;
}

.home-intro {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-top: 7px;
}

.wordmark {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  color: var(--text);
  font-family: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0;
  text-decoration: none;
}

.wordmark.subdued {
  color: var(--text-mute);
}

.wordmark .app-suffix,
.wordmark .route-label {
  color: var(--text-dim);
  font-weight: 400;
}

.tagline {
  color: var(--text-mute);
  font-size: 13px;
  line-height: 1.45;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 17px;
}

.card.flush {
  overflow: hidden;
  padding: 0;
}

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

.heading {
  margin: 0;
  color: var(--text);
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0;
  line-height: 1.25;
}

.body-copy {
  margin: 0;
  color: var(--text-mute);
  font-size: 13px;
  line-height: 1.5;
}

.label {
  color: var(--text-mute);
  font-size: 13px;
  font-weight: 500;
}

.helper {
  margin: 0;
  color: var(--text-dim);
  font-size: 11px;
  line-height: 1.45;
}

.footer-line {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding-top: 7px;
  color: var(--text-dim);
  font-size: 11px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 0;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0;
  line-height: 1;
  padding: 11px 16px;
  text-align: center;
  text-decoration: none;
  transition: opacity 0.15s ease, transform 0.08s ease, border-color 0.15s ease;
}

.btn:hover {
  border-color: color-mix(in oklab, var(--border-strong), var(--text) 18%);
}

.btn:active {
  transform: translateY(1px);
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.btn.lg {
  width: 100%;
  padding: 14px 16px;
  font-size: 15px;
}

.btn.sm {
  flex: 1;
  padding: 8px 12px;
  font-size: 13px;
}

.btn:disabled,
.btn.disabled {
  cursor: not-allowed;
  opacity: 0.5;
  transform: none;
}

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

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-top: 5px;
}

.back-btn {
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  padding: 0;
  border-radius: 4px;
}

.theme-toggle {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 10;
  display: flex;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
}

.theme-toggle button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text-mute);
  cursor: pointer;
}

.theme-toggle button[aria-checked="true"] {
  background: var(--surface-alt);
  color: var(--text);
}

.theme-toggle button:hover {
  color: var(--text);
}

.code-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.countdown {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text-mute);
  font-family: "Geist Mono", ui-monospace, monospace;
  font-size: 11px;
  white-space: nowrap;
}

.countdown svg {
  flex: 0 0 14px;
}

.countdown-progress {
  stroke-dasharray: var(--dash, 34.5) 100;
}

.code-display {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-sunk);
  color: var(--text);
  font-family: "Geist Mono", ui-monospace, monospace;
  font-size: 36px;
  font-weight: 500;
  letter-spacing: 8px;
  line-height: 1;
  overflow-wrap: anywhere;
  padding: 18px 8px 18px 16px;
  user-select: all;
}

.radar {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 140px;
}

.radar-ring {
  position: absolute;
  width: 80px;
  height: 80px;
  border: 1.5px solid var(--accent);
  border-radius: 50%;
  opacity: 0.5;
  animation: sl-pulse-ring 2.4s ease-out infinite;
}

.radar-ring:nth-child(2) { animation-delay: 0.6s; }
.radar-ring:nth-child(3) { animation-delay: 1.2s; }

.radar-dot {
  position: relative;
  z-index: 1;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent);
  animation: sl-pulse-dot 1.8s ease-in-out infinite;
}

.waiting-copy {
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-align: center;
}

.waiting-title {
  color: var(--text);
  font-size: 15px;
  font-weight: 500;
}

.waiting-hint {
  color: var(--text-dim);
  font-size: 12px;
}

.map-preview {
  position: relative;
  height: 140px;
  overflow: hidden;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(135deg, #f4ede0 0%, #eee5d3 100%);
}

html[data-theme="dark"] .map-preview {
  background: linear-gradient(135deg, #1c1a16 0%, #211e19 100%);
}

.map-preview svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.map-pin {
  position: absolute;
  top: 50%;
  left: 50%;
  pointer-events: none;
  transform: translate(-50%, -100%);
}

.map-pin::before {
  position: absolute;
  bottom: -8px;
  left: 50%;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--accent);
  content: "";
  opacity: 0.25;
  transform: translateX(-50%);
  animation: sl-pulse-ring 2s ease-out infinite;
}

.tile-map {
  position: relative;
  height: 156px;
  overflow: hidden;
  border-bottom: 1px solid var(--border);
  background: var(--surface-sunk);
  isolation: isolate;
}

.map-tile {
  position: absolute;
  width: 256px;
  height: 256px;
  user-select: none;
}

.accuracy-ring {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 1;
  border: 1.5px solid var(--accent);
  border-radius: 50%;
  background: color-mix(in oklab, var(--accent), transparent 82%);
  pointer-events: none;
  transform: translate(-50%, -50%);
}

.tile-map .map-pin {
  z-index: 2;
}

.map-attribution {
  position: absolute;
  right: 6px;
  bottom: 5px;
  z-index: 3;
  border-radius: 4px;
  background: rgba(255,255,255,0.86);
  color: #1A1816;
  font-size: 10px;
  line-height: 1;
  padding: 3px 5px;
  text-decoration: none;
}

.map-attribution:hover {
  text-decoration: underline;
}

.received-inner {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 17px;
}

.status-row {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-mute);
  font-size: 13px;
  font-weight: 500;
}

.dot-indicator {
  position: relative;
  display: inline-flex;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
}

.dot-indicator::before {
  position: absolute;
  inset: -2px;
  border-radius: 50%;
  background: var(--success);
  content: "";
  opacity: 0.25;
  animation: sl-pulse-ring 2s ease-out infinite;
}

.coords-grid {
  display: grid;
  grid-template-columns: 88px minmax(0, 1fr);
  column-gap: 12px;
  row-gap: 7px;
}

.coords-grid dt {
  color: var(--text-mute);
  font-size: 12px;
}

.coords-grid dd {
  min-width: 0;
  margin: 0;
  color: var(--text);
  font-family: "Geist Mono", ui-monospace, monospace;
  font-size: 13px;
  overflow-wrap: anywhere;
}

.fade-in {
  animation: sl-fade-in 0.25s ease;
}

.code-input-wrap {
  position: relative;
}

.code-input-wrap input {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: transparent;
  caret-color: transparent;
  font-size: 16px;
  opacity: 0;
}

.code-tiles {
  display: flex;
  justify-content: center;
  gap: 6px;
  pointer-events: none;
}

.code-tile {
  position: relative;
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: center;
  max-width: 44px;
  aspect-ratio: 0.85;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface-sunk);
  color: var(--text-dim);
  font-family: "Geist Mono", ui-monospace, monospace;
  font-size: 22px;
  font-weight: 500;
}

.code-tile.filled {
  border-color: var(--border-strong);
  color: var(--text);
}

.code-tile.active {
  border-color: var(--accent);
}

.cursor-bar {
  display: inline-block;
  width: 2px;
  height: 24px;
  border-radius: 1px;
  background: var(--accent);
  animation: sl-pulse-dot 1s ease-in-out infinite;
}

.banner {
  display: none;
  align-items: center;
  gap: 8px;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.35;
}

.banner.show {
  display: flex;
  animation: sl-fade-in 0.25s ease;
}

.banner.error {
  border: 1px solid color-mix(in oklab, var(--danger), transparent 74%);
  background: rgba(194,85,64,0.08);
  color: var(--danger);
}

html[data-theme="dark"] .banner.error {
  background: rgba(226,109,90,0.10);
}

.banner.success {
  border: 1px solid rgba(47,138,79,0.25);
  background: rgba(47,138,79,0.08);
  color: var(--success);
}

html[data-theme="dark"] .banner.success {
  border-color: rgba(127,211,145,0.30);
  background: rgba(127,211,145,0.12);
}

.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: var(--accent-ink);
  border-radius: 50%;
  animation: sl-spin 0.7s linear infinite;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@keyframes sl-pulse-ring {
  0% { transform: scale(0.6); opacity: 0.7; }
  80%, 100% { transform: scale(2); opacity: 0; }
}

@keyframes sl-pulse-dot {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.18); opacity: 0.7; }
}

@keyframes sl-spin {
  to { transform: rotate(360deg); }
}

@keyframes sl-fade-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

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

@media (min-width: 640px) {
  .app-shell {
    align-items: flex-start;
    padding: 32px 16px;
  }

  .app-column {
    max-width: 480px;
    min-height: min(760px, calc(100vh - 64px));
    border-radius: 18px;
    box-shadow: var(--shadow);
    overflow: hidden;
  }

  .page {
    min-height: min(760px, calc(100vh - 64px));
  }
}
