:root {
  color-scheme: light dark;
  --bg: #0f172a;
  --text: #e2e8f0;
  --muted: rgba(148, 163, 184, 0.85);
  --card: rgba(255, 255, 255, 0.06);
  --border: rgba(148, 163, 184, 0.18);
  --accent: #38bdf8;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f1f5f9;
    --text: #0f172a;
    --muted: rgba(15, 23, 42, 0.65);
    --card: rgba(255, 255, 255, 0.75);
    --border: rgba(15, 23, 42, 0.08);
  }
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

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

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

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family:
    "Inter",
    "Segoe UI",
    system-ui,
    -apple-system,
    sans-serif;
  background:
    radial-gradient(circle at top, rgba(56, 189, 248, 0.12), transparent 55%),
    var(--bg);
  color: var(--text);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: clamp(1.25rem, 5vmin, 3rem) max(4vmin, env(safe-area-inset-right))
    max(2rem, env(safe-area-inset-bottom)) max(4vmin, env(safe-area-inset-left));
}

main {
  width: min(720px, 100%);
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

header h1 {
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0 0 0.4rem;
}

header p,
footer p {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.5;
}

#query {
  width: 100%;
  resize: vertical;
  min-height: 3.2rem;
  padding: 0.9rem 1rem;
  border-radius: 0.9rem;
  border: 1px solid var(--border);
  background: var(--card);
  color: inherit;
  font: inherit;
  /* 16px minimum keeps mobile Safari from zooming on focus */
  font-size: max(1rem, 1.05rem);
  outline: none;
}

#query:focus {
  border-color: rgba(56, 189, 248, 0.7);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.2);
}

#query[readonly] {
  cursor: default;
}

body.handoff-active .actions {
  display: none;
}

.actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-top: 0.75rem;
}

.share-btn,
.copy-btn {
  flex: 0 0 auto;
  padding: 0.6rem 1.1rem;
  font-size: 0.92rem;
  min-height: 2.75rem;
}

.copy-btn {
  background: var(--card);
  border: 1px solid var(--border);
  color: inherit;
}

.share-result {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.share-url {
  flex: 1 1 auto;
  min-width: 0;
  padding: 0.6rem 0.75rem;
  border-radius: 0.7rem;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--muted);
  font: inherit;
  font-size: 0.85rem;
  text-overflow: ellipsis;
  outline: none;
}

.share-url:focus {
  border-color: var(--accent);
  color: var(--text);
}

.share-preview {
  flex: 0 0 auto;
  padding: 0.6rem 0.9rem;
  border-radius: 0.7rem;
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}

.share-preview:hover {
  border-color: var(--accent);
}

.handoff {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  padding: 0.95rem 1rem;
  border-radius: 0.9rem;
  border: 1px solid var(--border);
  background: var(--card);
}

.handoff-status {
  margin: 0;
  font-size: 0.95rem;
  color: var(--muted);
}

.handoff-count {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.handoff-track {
  height: 4px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}

.handoff-fill {
  height: 100%;
  width: 100%;
  border-radius: 999px;
  background: var(--accent);
}

.handoff-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.handoff-btn {
  flex: 1 1 8rem;
}

.suggestion {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.grid {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: repeat(auto-fit, minmax(8.5rem, 1fr));
}

.service {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.8rem 0.75rem;
  min-height: 2.9rem;
  border-radius: 0.9rem;
  border: 1px solid var(--border);
  background: var(--card);
  color: inherit;
  font: inherit;
  font-size: 0.98rem;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition:
    transform 140ms ease,
    border-color 140ms ease,
    box-shadow 140ms ease;
}

@media (hover: hover) {
  .service:hover,
  .service:focus-visible {
    transform: translateY(-3px);
    border-color: var(--tint, var(--accent));
    box-shadow: 0 10px 30px
      color-mix(in srgb, var(--tint, var(--accent)) 25%, transparent);
    outline: none;
  }
}

.service:active {
  transform: scale(0.98);
}

/* marks the service that the Enter key opens */
.service.default {
  border-color: var(--tint, var(--accent));
}

/* the share button is the page's primary action */
.share-btn {
  background: var(--accent);
  border-color: transparent;
  color: #062130;
}

.share-btn.is-ok,
.copy-btn.is-ok {
  background: #34d399;
  border-color: transparent;
  color: #05271a;
}

.share-btn.is-error,
.copy-btn.is-error {
  background: #f87171;
  border-color: transparent;
  color: #380b0b;
}

footer {
  border-top: 1px solid var(--border);
  padding-top: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

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

footer a:hover {
  text-decoration: underline;
}

@media (max-width: 520px) {
  main {
    gap: 1.15rem;
  }

  header h1 {
    font-size: 1.7rem;
  }

  .grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.6rem;
  }

  .service {
    padding: 0.75rem 0.5rem;
    font-size: 0.94rem;
  }

  .actions {
    justify-content: stretch;
    flex-direction: column;
  }

  .share-btn,
  .copy-btn {
    width: 100%;
  }

  .share-result {
    flex-wrap: wrap;
  }

  .share-url {
    flex: 1 1 100%;
  }
}
