/* Theme tokens. The inline script in layout.html sets data-theme on <html> before first paint
   (saved choice, else the OS setting); the media query covers visitors without JavaScript. */
:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #eef0f6;
  --text: #15151c;
  --muted: #5d6174;
  --border: #e3e5ee;
  --accent: #fe2c55;
  --accent-2: #25f4ee;
  --accent-text: #ffffff;
  --error-bg: #fff0f2;
  --error-text: #c4162f;
  --topbar-bg: rgb(255 255 255 / 0.85);
  --hero-bg:
    radial-gradient(circle at 12% 18%, rgb(37 244 238 / 0.22), transparent 42%),
    radial-gradient(circle at 88% 8%, rgb(254 44 85 / 0.16), transparent 46%),
    linear-gradient(180deg, #ffffff, #f6f7fb);
  --hero-text: #15151c;
  --hero-muted: #5d6174;
  --input-bg: #ffffff;
  --input-border: #d9dce7;
  --radius: 14px;
  --shadow: 0 10px 30px rgb(20 20 40 / 0.08);
  --gutter: max(16px, env(safe-area-inset-left), env(safe-area-inset-right));
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0d0d12;
  --surface: #17171f;
  --surface-2: #22222d;
  --text: #f1f1f5;
  --muted: #a3a5b4;
  --border: #2a2a36;
  --error-bg: #3a1219;
  --error-text: #ff8597;
  --topbar-bg: rgb(13 13 18 / 0.85);
  --hero-bg:
    radial-gradient(circle at 12% 18%, rgb(37 244 238 / 0.14), transparent 42%),
    radial-gradient(circle at 88% 8%, rgb(254 44 85 / 0.22), transparent 46%),
    linear-gradient(160deg, #101018, #2a1030);
  --hero-text: #ffffff;
  --hero-muted: rgb(255 255 255 / 0.75);
  --input-bg: #1f1f29;
  --input-border: #34343f;
  --shadow: 0 10px 30px rgb(0 0 0 / 0.4);
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d0d12;
    --surface: #17171f;
    --surface-2: #22222d;
    --text: #f1f1f5;
    --muted: #a3a5b4;
    --border: #2a2a36;
    --error-bg: #3a1219;
    --error-text: #ff8597;
    --topbar-bg: rgb(13 13 18 / 0.85);
    --hero-bg:
      radial-gradient(circle at 12% 18%, rgb(37 244 238 / 0.14), transparent 42%),
      radial-gradient(circle at 88% 8%, rgb(254 44 85 / 0.22), transparent 46%),
      linear-gradient(160deg, #101018, #2a1030);
    --hero-text: #ffffff;
    --hero-muted: rgb(255 255 255 / 0.75);
    --input-bg: #1f1f29;
    --input-border: #34343f;
    --shadow: 0 10px 30px rgb(0 0 0 / 0.4);
    color-scheme: dark;
  }
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Thai", "Noto Sans Arabic", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  overflow-x: hidden;
}

a {
  color: inherit;
}

img {
  max-width: 100%;
}

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

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

.skip-link {
  position: absolute;
  inset-inline-start: 8px;
  top: -48px;
  z-index: 100;
  padding: 8px 14px;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
  text-decoration: none;
}

.skip-link:focus {
  top: 8px;
}

/* Top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--border);
  -webkit-backdrop-filter: saturate(1.6) blur(12px);
  backdrop-filter: saturate(1.6) blur(12px);
}

.topbar-inner {
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-template-areas: "logo nav actions";
  align-items: center;
  gap: 12px 24px;
  max-width: 1100px;
  margin: 0 auto;
  padding: 10px var(--gutter);
}

.logo {
  grid-area: logo;
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  font-size: 1.15rem;
  text-decoration: none;
}

.logo-mark {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  box-shadow: -3px -3px 0 var(--accent-2);
}

.main-nav {
  grid-area: nav;
  display: flex;
  gap: 4px;
}

.main-nav a {
  padding: 8px 12px;
  border-radius: 999px;
  color: var(--muted);
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}

.main-nav a:hover {
  color: var(--text);
  background: var(--surface-2);
}

.main-nav a[aria-current="page"] {
  color: var(--text);
  background: var(--surface-2);
  font-weight: 600;
}

.topbar-actions {
  grid-area: actions;
  display: flex;
  align-items: center;
  gap: 6px;
}

.icon-btn,
.lang-menu summary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 40px;
  min-width: 40px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.icon-btn:hover,
.lang-menu summary:hover {
  background: var(--surface-2);
}

.icon-btn svg,
.lang-menu svg {
  width: 18px;
  height: 18px;
}

/* Show the moon in light mode (switch to dark) and the sun in dark mode. */
.theme-toggle .icon-sun,
:root[data-theme="dark"] .theme-toggle .icon-moon {
  display: none;
}

:root[data-theme="dark"] .theme-toggle .icon-sun {
  display: contents;
}

.theme-toggle span {
  display: contents;
}

.lang-menu {
  position: relative;
}

.lang-menu summary {
  list-style: none;
}

.lang-menu summary::-webkit-details-marker {
  display: none;
}

.lang-menu ul {
  position: absolute;
  inset-inline-end: 0;
  top: calc(100% + 8px);
  z-index: 60;
  display: grid;
  grid-template-columns: repeat(2, minmax(130px, 1fr));
  gap: 2px;
  width: max-content;
  max-width: calc(100vw - 2 * var(--gutter));
  margin: 0;
  padding: 6px;
  list-style: none;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.lang-menu a {
  display: block;
  padding: 8px 12px;
  border-radius: 8px;
  text-decoration: none;
  white-space: nowrap;
}

.lang-menu a:hover {
  background: var(--surface-2);
}

.lang-menu a[aria-current="true"] {
  color: var(--accent);
  font-weight: 700;
}

/* Hero */
.hero {
  padding: 48px var(--gutter) 64px;
  text-align: center;
  color: var(--hero-text);
  background: var(--hero-bg);
}

.hero h1 {
  margin: 0 auto 10px;
  max-width: 800px;
  font-size: clamp(1.75rem, 5vw, 2.8rem);
  line-height: 1.15;
  letter-spacing: -0.01em;
}

.subtitle {
  margin: 0 auto 28px;
  max-width: 560px;
  color: var(--hero-muted);
}

.hero-small {
  padding: 80px var(--gutter);
}

.hero-small .primary-btn {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}

.search {
  display: flex;
  gap: 10px;
  max-width: 720px;
  margin: 0 auto;
}

.input-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
}

.search input {
  width: 100%;
  height: 56px;
  padding-block: 0;
  padding-inline: 18px 96px;
  border: 2px solid var(--input-border);
  border-radius: var(--radius);
  font-size: 1rem; /* 16px+ stops iOS Safari from zooming in on focus */
  background: var(--input-bg);
  color: var(--text);
  outline: none;
  box-shadow: var(--shadow);
}

.search input:focus {
  border-color: var(--accent-2);
}

.search input::placeholder {
  color: var(--muted);
}

.paste-btn {
  position: absolute;
  top: 8px;
  inset-inline-end: 8px;
  height: 40px;
  padding: 0 14px;
  border: 0;
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.primary-btn {
  position: relative;
  justify-content: center;
  height: 56px;
  min-width: 150px;
  padding: 0 24px;
  border: 0;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-text);
  font: inherit;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s, filter 0.15s;
}

.primary-btn:hover {
  filter: brightness(1.08);
}

.primary-btn:active {
  transform: scale(0.98);
}

.primary-btn:disabled {
  cursor: progress;
  filter: saturate(0.6);
}

.spinner {
  display: none;
  width: 22px;
  height: 22px;
  margin: 0 auto;
  border: 3px solid rgb(255 255 255 / 0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.primary-btn.loading .btn-label {
  display: none;
}

.primary-btn.loading .spinner {
  display: block;
}

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

.error {
  max-width: 720px;
  margin: 16px auto 0;
  padding: 12px 16px;
  border-radius: 10px;
  background: var(--error-bg);
  color: var(--error-text);
  font-weight: 500;
}

/* Result card */
.result {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  gap: 24px;
  max-width: 820px;
  margin: -32px auto 0;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  position: relative;
  scroll-margin-top: 80px;
}

.result[hidden] {
  display: none;
}

.result-media {
  position: relative;
  align-self: start;
}

.result-body {
  min-width: 0;
}

.result-media img {
  display: block;
  width: 100%;
  aspect-ratio: 9 / 16;
  object-fit: cover;
  border-radius: 10px;
  background: var(--border);
}

.badge {
  position: absolute;
  inset-inline-end: 8px;
  bottom: 8px;
  padding: 2px 8px;
  border-radius: 6px;
  background: rgb(0 0 0 / 0.7);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 600;
}

.badge:empty {
  display: none;
}

.author {
  display: flex;
  align-items: center;
  gap: 10px;
}

.author img {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--border);
}

.author img:not([src]),
.author img[src=""] {
  display: none;
}

.author div {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.author strong,
.author span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.author span {
  color: var(--muted);
  font-size: 0.9rem;
}

.caption {
  margin: 12px 0;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin: 0 0 18px;
  padding: 0;
  list-style: none;
  color: var(--muted);
  font-size: 0.9rem;
}

.download-buttons {
  display: grid;
  gap: 10px;
}

.dl-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 52px;
  padding: 12px 18px;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 700;
  text-decoration: none;
  transition: filter 0.15s;
}

.dl-btn:hover {
  filter: brightness(1.08);
}

.dl-btn.secondary {
  background: transparent;
  color: var(--text);
  border: 2px solid var(--border);
}

.dl-btn.secondary:hover {
  border-color: var(--accent);
}

.dl-btn small {
  flex-shrink: 0;
  font-weight: 500;
  opacity: 0.8;
}

.dl-btn.busy {
  pointer-events: none;
  opacity: 0.7;
}

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.gallery a {
  position: relative;
  display: block;
  border-radius: 10px;
  overflow: hidden;
  background: var(--border);
}

.gallery img {
  display: block;
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
}

.gallery span {
  position: absolute;
  inset-inline-end: 6px;
  bottom: 6px;
  padding: 2px 8px;
  border-radius: 6px;
  background: rgb(0 0 0 / 0.7);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 600;
}

.link-btn {
  margin-top: 16px;
  padding: 8px 0;
  border: 0;
  background: none;
  color: var(--muted);
  text-decoration: underline;
  cursor: pointer;
  font: inherit;
}

/* Info sections */
.info {
  max-width: 880px;
  margin: 56px auto;
  padding: 0 var(--gutter);
}

.info h2 {
  font-size: clamp(1.3rem, 3.5vw, 1.6rem);
  margin: 0 0 20px;
}

.features {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 16px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.features li {
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.feature-icon {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin-bottom: 12px;
  border-radius: 12px;
  background: rgb(254 44 85 / 0.12);
  color: var(--accent);
}

.features h3 {
  margin: 0 0 6px;
  font-size: 1.05rem;
}

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

.steps {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: step;
}

.steps li {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 20px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  counter-increment: step;
}

.steps li::before {
  content: counter(step);
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}

.steps span {
  color: var(--muted);
}

details:not(.lang-menu) {
  margin-bottom: 10px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
}

details:not(.lang-menu) summary {
  padding: 16px 20px;
  font-weight: 600;
  cursor: pointer;
}

details:not(.lang-menu) p {
  margin: 0;
  padding: 0 20px 16px;
  color: var(--muted);
}

.footer {
  padding: 32px var(--gutter) max(32px, env(safe-area-inset-bottom));
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  border-top: 1px solid var(--border);
}

.footer p {
  max-width: 720px;
  margin-inline: auto;
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px 20px;
  margin-bottom: 12px;
}

.footer-links a {
  padding: 6px 0;
  text-decoration: none;
}

.footer-links a:hover,
.footer-links a[aria-current="page"] {
  color: var(--text);
}

/* Ads: reserve space up front so the page doesn't jump when an ad loads (layout shift hurts SEO). */
.ad {
  max-width: 880px;
  min-height: 100px;
  margin: 24px auto;
  padding: 0 var(--gutter);
  text-align: center;
  overflow: hidden;
}

.ad-result {
  min-height: 250px;
  margin: 16px 0 0;
  padding: 0;
}

.ad-placeholder {
  display: grid;
  place-items: center;
  min-height: inherit;
  border: 2px dashed var(--border);
  border-radius: 12px;
  color: var(--muted);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* SEO text */
.intro p {
  color: var(--muted);
  font-size: 1.05rem;
}

.related {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
}

.related-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 18px 20px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  text-decoration: none;
  transition: border-color 0.15s;
}

.related-card:hover {
  border-color: var(--accent);
}

.related-card span {
  color: var(--muted);
  font-size: 0.9rem;
}

/* Legal pages */
.prose {
  max-width: 760px;
}

.prose h1 {
  margin: 0 0 4px;
  font-size: clamp(1.6rem, 5vw, 2rem);
}

.prose h2 {
  margin: 28px 0 8px;
  font-size: 1.2rem;
}

.prose p {
  color: var(--muted);
  overflow-wrap: anywhere;
}

.prose .updated {
  margin: 0 0 24px;
  font-size: 0.9rem;
}

/* Tablet */
@media (max-width: 860px) {
  .steps {
    grid-template-columns: 1fr;
  }

  .steps li {
    display: grid;
    grid-template-columns: 32px 1fr;
    column-gap: 14px;
    align-items: start;
  }

  .steps li::before {
    grid-row: span 2;
  }
}

/* Phone: nav moves to its own scrollable row under the logo. */
@media (max-width: 720px) {
  .topbar-inner {
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "logo actions"
      "nav nav";
    gap: 8px;
    padding-bottom: 6px;
  }

  .main-nav {
    margin-inline: calc(-1 * var(--gutter));
    padding-inline: var(--gutter);
    overflow-x: auto;
    scrollbar-width: none;
  }

  .main-nav::-webkit-scrollbar {
    display: none;
  }

  .hero {
    padding: 32px var(--gutter) 56px;
  }

  .subtitle {
    margin-bottom: 22px;
  }

  .search {
    flex-direction: column;
  }

  .primary-btn {
    width: 100%;
  }

  .result {
    grid-template-columns: minmax(0, 1fr);
    gap: 16px;
    margin: -32px var(--gutter) 0;
    padding: 16px;
  }

  .result-media {
    width: 100%;
    max-width: 180px;
    margin: 0 auto;
  }

  .info {
    margin: 40px auto;
  }

  .features {
    gap: 10px;
  }

  .features li {
    display: grid;
    grid-template-columns: 44px 1fr;
    column-gap: 14px;
    padding: 16px;
  }

  .feature-icon {
    grid-row: span 2;
    margin: 0;
  }

  .lang-menu ul {
    grid-template-columns: 1fr 1fr;
    position: fixed;
    top: 60px;
    inset-inline: var(--gutter);
    width: auto;
    max-width: none;
  }
}

@media (max-width: 360px) {
  .logo {
    font-size: 1rem;
  }

  .search input {
    padding-inline-end: 84px;
  }

  .paste-btn {
    padding: 0 10px;
  }
}

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