:root {
  color-scheme: light dark;
  --bg: #09090b;
  --surface: #131316;
  --surface-2: #1c1c21;
  --text: #f4f4f5;
  --muted: #a1a1aa;
  --faint: #82828b;
  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.16);
  --accent: #38bdf8;
  --primary-bg: #f4f4f5;
  --primary-text: #09090b;
  --ok: #34d399;
  --error: #f87171;
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.04) inset,
    0 12px 32px -12px rgba(0, 0, 0, 0.6);
  --radius: 1.25rem;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #fafafa;
    --surface: #ffffff;
    --surface-2: #f4f4f5;
    --text: #18181b;
    --muted: #52525b;
    --faint: #71717a;
    --border: rgba(9, 9, 11, 0.09);
    --border-strong: rgba(9, 9, 11, 0.18);
    --accent: #0284c7;
    --primary-bg: #18181b;
    --primary-text: #fafafa;
    --ok: #059669;
    --error: #dc2626;
    --shadow: 0 1px 2px rgba(9, 9, 11, 0.04),
      0 12px 32px -16px rgba(9, 9, 11, 0.18);
  }
}

* {
  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",
    system-ui,
    -apple-system,
    "Segoe UI",
    sans-serif;
  font-feature-settings: "cv11", "ss01";
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3rem;
  padding: clamp(1.5rem, 9vh, 6rem) max(1.25rem, env(safe-area-inset-right))
    max(1.5rem, env(safe-area-inset-bottom))
    max(1.25rem, env(safe-area-inset-left));
}

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

header {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  margin-bottom: 0.75rem;
}

.mark {
  width: 2.5rem;
  height: 2.5rem;
  margin-bottom: 1.25rem;
  border-radius: 0.6rem;
  box-shadow: 0 0 0 1px var(--border);
}

header h1 {
  font-size: clamp(2rem, 5.5vw, 2.9rem);
  font-weight: 650;
  letter-spacing: -0.035em;
  line-height: 1.05;
  margin: 0 0 0.6rem;
  text-wrap: balance;
}

header p {
  margin: 0;
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.5;
  text-wrap: pretty;
}

/* textarea and its share actions read as one input, like a chat composer */
.composer {
  display: flex;
  flex-direction: column;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  box-shadow: var(--shadow);
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease;
}

.composer:focus-within {
  border-color: color-mix(in srgb, var(--accent) 60%, transparent);
  box-shadow:
    0 0 0 4px color-mix(in srgb, var(--accent) 16%, transparent),
    var(--shadow);
}

#query {
  display: block;
  width: 100%;
  min-height: 6.5rem;
  max-height: 50vh;
  padding: 1.1rem 1.2rem 0.5rem;
  border: 0;
  border-radius: var(--radius) var(--radius) 0 0;
  background: transparent;
  color: inherit;
  font: inherit;
  /* 16px minimum keeps mobile Safari from zooming on focus */
  font-size: 1.0625rem;
  line-height: 1.55;
  /* logical alignment follows dir="auto", so Persian/Arabic aligns right */
  text-align: start;
  resize: none;
  outline: none;
  field-sizing: content;
}

@supports not (field-sizing: content) {
  #query {
    resize: vertical;
  }
}

#query::placeholder {
  color: var(--faint);
}

#query[readonly] {
  cursor: default;
}

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

.actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.6rem;
}

.share-btn,
.copy-btn {
  flex: 0 0 auto;
  min-height: 2.5rem;
  padding: 0.5rem 0.95rem;
  border-radius: 0.8rem;
  font-size: 0.9rem;
}

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

.share-url {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 2.5rem;
  padding: 0.5rem 0.85rem;
  border-radius: 0.8rem;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  font: inherit;
  font-size: 0.875rem;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  text-overflow: ellipsis;
  outline: none;
}

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

.share-preview {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 2.5rem;
  padding: 0.5rem 0.9rem;
  border-radius: 0.8rem;
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.875rem;
  font-weight: 550;
  text-decoration: none;
  white-space: nowrap;
  transition: border-color 140ms ease;
}

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

.handoff {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  padding: 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
}

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

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

.handoff-track {
  height: 3px;
  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.5rem;
}

.handoff-btn {
  flex: 1 1 8rem;
  min-height: 2.5rem;
  border-radius: 0.8rem;
  font-size: 0.9rem;
}

/* opening right away is the main way out of the countdown */
#handoff-now {
  background: var(--primary-bg);
  border-color: transparent;
  color: var(--primary-text);
}

.suggestion {
  margin: 0.5rem 0 -0.25rem;
  color: var(--muted);
  font-size: 0.875rem;
  text-align: center;
}

.grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

/* main.js fills in the service buttons; reserve their two rows so the guide
   below does not jump when they appear */
.grid:empty {
  min-height: 96px;
}

/* shared button base: service pills, composer and handoff actions */
.service {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.6rem 1rem;
  min-height: 2.75rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: inherit;
  font: inherit;
  font-size: 0.95rem;
  font-weight: 550;
  text-align: center;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition:
    background-color 140ms ease,
    border-color 140ms ease,
    color 140ms ease,
    transform 140ms ease;
}

.grid > .service {
  padding-inline: 0.95rem 1.15rem;
}

/* brand-colored glyphs keep each service recognizable at a glance */
.grid .service-icon {
  color: var(--tint);
}

@media (hover: hover) {
  .service:hover {
    border-color: var(--border-strong);
    background: var(--surface-2);
  }

  .grid > .service:hover {
    border-color: color-mix(in srgb, var(--tint) 55%, transparent);
    background: color-mix(in srgb, var(--tint) 9%, var(--surface));
  }

  .share-btn:hover,
  #handoff-now:hover {
    background: color-mix(in srgb, var(--primary-bg) 86%, var(--bg));
    border-color: transparent;
  }
}

.service:focus-visible,
.share-preview:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

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

/* service glyphs and button icons inherit the label color, so they stay
   visible in both color schemes */
.service-icon,
.btn-icon {
  width: 1.1em;
  height: 1.1em;
  flex: 0 0 auto;
}

.service-icon {
  border-radius: 0.2em;
}

.service-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* marks the service that the Enter key opens */
.grid > .service.default {
  border-color: color-mix(in srgb, var(--tint) 70%, transparent);
  background: color-mix(in srgb, var(--tint) 13%, var(--surface));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--tint) 14%, transparent);
}

.copy-btn {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}

@media (hover: hover) {
  .copy-btn:hover {
    color: var(--text);
    background: var(--surface-2);
    border-color: transparent;
  }
}

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

.share-btn.is-ok,
.copy-btn.is-ok {
  background: color-mix(in srgb, var(--ok) 16%, transparent);
  border-color: transparent;
  color: var(--ok);
}

.share-btn.is-error,
.copy-btn.is-error {
  background: color-mix(in srgb, var(--error) 16%, transparent);
  border-color: transparent;
  color: var(--error);
}

.about {
  margin-top: 2.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.6;
}

.about h2 {
  margin: 0 0 0.75rem;
  color: var(--text);
  font-size: 1.3rem;
}

.about h3 {
  margin: 1.75rem 0 0.5rem;
  color: var(--text);
  font-size: 1.05rem;
}

.about h4 {
  margin: 1.25rem 0 0.25rem;
  color: var(--text);
  font-size: 0.95rem;
}

.about p,
.about ol {
  margin: 0 0 0.75rem;
  text-wrap: pretty;
}

.about ol {
  padding-inline-start: 1.25rem;
}

.about a {
  color: var(--text);
}

footer {
  width: min(680px, 100%);
  margin-top: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  text-align: center;
}

footer p {
  margin: 0;
  color: var(--faint);
  font-size: 0.85rem;
  line-height: 1.5;
  text-wrap: pretty;
}

footer .credit {
  font-size: 0.8rem;
}

footer a {
  color: var(--muted);
  text-decoration: underline;
  text-decoration-color: var(--border-strong);
  text-underline-offset: 3px;
}

footer a:hover {
  color: var(--text);
}

@media (max-width: 520px) {
  body {
    gap: 2.5rem;
    padding-top: max(2rem, env(safe-area-inset-top));
  }

  main {
    gap: 1rem;
  }

  .mark {
    width: 2.25rem;
    height: 2.25rem;
    margin-bottom: 1rem;
  }

  header p {
    font-size: 1rem;
  }

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

  /* four rows of two on small screens */
  .grid:empty {
    min-height: 200px;
  }

  .grid > .service {
    justify-content: flex-start;
    border-radius: 1rem;
    padding-inline: 0.9rem;
  }

  .actions .service {
    flex: 1 1 0;
  }

  /* three buttons will not fit one row, so open now takes its own */
  .handoff-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #handoff-now {
    grid-column: 1 / -1;
  }

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

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

@media (prefers-reduced-motion: reduce) {
  .service,
  .composer,
  .share-preview {
    transition: none;
  }

  .service:active {
    transform: none;
  }
}
