/**
 * KeyBlock help pages — midnight background, elevated dark surfaces.
 * Mobile-first: safe areas, comfortable tap targets, fluid type.
 */

:root {
  --page-bg: #000000;
  --surface: #1c1c1e;
  --text: #f5f5f7;
  --text-secondary: #a1a1a6;
  --text-tertiary: #8e8e93;
  --separator: rgba(255, 255, 255, 0.22);
  --separator-light: rgba(255, 255, 255, 0.12);
  --link: #0a84ff;
  --link-pressed: #409cff;
  --radius-lg: 12px;
  --radius-md: 10px;
  --shadow-card: 0 1px 0 rgba(255, 255, 255, 0.06) inset, 0 4px 24px rgba(0, 0, 0, 0.45);
  --font-stack:
    -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", system-ui,
    "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --pad-x: max(1rem, env(safe-area-inset-left, 0px));
  --pad-y: max(1rem, env(safe-area-inset-top, 0px));
  --pad-bottom: max(2rem, env(safe-area-inset-bottom, 0px));
}

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

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

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font-stack);
  font-size: clamp(0.9375rem, 0.9rem + 0.2vw, 1.0625rem);
  line-height: 1.47;
  letter-spacing: -0.01em;
  color: var(--text);
  background: var(--page-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a {
  color: var(--link);
  text-decoration: none;
  text-underline-offset: 0.12em;
}

a:hover {
  text-decoration: underline;
}

a:active {
  color: var(--link-pressed);
}

a:focus-visible {
  outline: 2px solid var(--link);
  outline-offset: 2px;
  border-radius: 2px;
}

details.faq-item > summary:focus-visible,
details.section-details > summary:focus-visible {
  outline: 2px solid var(--link);
  outline-offset: -2px;
  border-radius: var(--radius-md);
  z-index: 1;
}

.page-wrap {
  max-width: 38rem;
  margin: 0 auto;
  padding: var(--pad-y) var(--pad-x) var(--pad-bottom);
  padding-bottom: max(2.5rem, var(--pad-bottom));
}

/* ——— Header ——— */
.page-header {
  margin-bottom: 1.25rem;
}

.page-header h1 {
  font-size: clamp(1.5rem, 1.35rem + 1vw, 1.75rem);
  font-weight: 700;
  letter-spacing: -0.022em;
  line-height: 1.2;
  margin: 0 0 0.5rem;
  color: var(--text);
}

.page-intro {
  margin: 0;
  font-size: 1rem;
  line-height: 1.5;
  color: var(--text-secondary);
}

.page-intro a {
  font-weight: 500;
}

/* Breadcrumb (Settings-style back path) */
.crumb {
  font-size: 0.8125rem;
  font-weight: 500;
  margin: 0 0 0.625rem;
  color: var(--text-tertiary);
}

.crumb a {
  color: var(--link);
}

.crumb a:hover {
  text-decoration: underline;
}

/* ——— Grouped surfaces (cards) ——— */
.surface {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  border: 0.5px solid var(--separator-light);
  overflow: hidden;
}

.surface + .surface {
  margin-top: 0.75rem;
}

.section-heading {
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  margin: 1.5rem 0 0.5rem 0.25rem;
  padding: 0 0.125rem;
}

.section-heading:first-child {
  margin-top: 0;
}

/* ——— FAQ & collapsible sections (<details>) ——— */
.faq-list {
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
}

details.faq-item,
details.section-details {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  border: 0.5px solid var(--separator-light);
  overflow: hidden;
}

details.faq-item > summary,
details.section-details > summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  min-height: 2.75rem;
  padding: 0.875rem 2.75rem 0.875rem 1.125rem;
  font-weight: 600;
  font-size: 1rem;
  line-height: 1.35;
  color: var(--text);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  user-select: none;
}

details.faq-item > summary::-webkit-details-marker,
details.section-details > summary::-webkit-details-marker {
  display: none;
}

details.section-details > summary h2 {
  flex: 1;
  min-width: 0;
  text-align: left;
  font-size: 1.0625rem;
  font-weight: 600;
  margin: 0;
  line-height: 1.25;
  color: var(--text);
}

details.faq-item > summary::after,
details.section-details > summary::after {
  content: "▼";
  position: absolute;
  right: 1rem;
  top: 50%;
  margin-top: -0.35rem;
  font-size: 0.5rem;
  line-height: 1;
  color: var(--text-tertiary);
  transform: rotate(-90deg);
  transition: transform 0.2s ease;
  flex-shrink: 0;
}

details.faq-item[open] > summary::after,
details.section-details[open] > summary::after {
  transform: rotate(0deg);
}

details.faq-item > summary:hover,
details.section-details > summary:hover {
  background: rgba(255, 255, 255, 0.06);
}

details.faq-item > summary:active,
details.section-details > summary:active {
  background: rgba(255, 255, 255, 0.1);
}

details.faq-item .faq-body,
details.section-details .section-body {
  padding: 1rem 1.125rem;
  color: var(--text-secondary);
  font-size: 0.9375rem;
  line-height: 1.5;
  border-top: 0.5px solid var(--separator-light);
}

details.faq-item .faq-body p {
  margin: 0 0 0.75rem;
}

details.faq-item .faq-body p:last-child {
  margin-bottom: 0;
}

details.faq-item .faq-body a {
  font-weight: 500;
}

/* ——— Lists inside answers ——— */
ol.steps,
ul.steps {
  margin: 0;
  padding-left: 1.25rem;
  color: var(--text-secondary);
}

ol.steps li,
ul.steps li {
  margin-bottom: 0.5rem;
  padding-left: 0.125rem;
}

ol.steps li:last-child,
ul.steps li:last-child {
  margin-bottom: 0;
}

ul.steps ul {
  margin: 0.35rem 0 0;
}

/* ——— iPhone setup: TOC ——— */
nav.toc.surface {
  margin: 1rem 0 1.25rem;
  padding: 0.875rem 0;
}

nav.toc strong {
  display: block;
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  padding: 0 1rem 0.5rem;
  margin: 0;
}

nav.toc ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

nav.toc li {
  margin: 0;
  border-top: 0.5px solid var(--separator-light);
}

nav.toc li:first-child {
  border-top: none;
}

nav.toc a {
  display: flex;
  align-items: center;
  min-height: 2.75rem;
  padding: 0.5rem 1rem;
  color: var(--link);
  font-size: 1rem;
  font-weight: 400;
  -webkit-tap-highlight-color: transparent;
}

nav.toc a:hover {
  background: rgba(255, 255, 255, 0.06);
  text-decoration: none;
}

nav.toc a:active {
  background: rgba(255, 255, 255, 0.1);
}

/* ——— Article sections (legacy .surface still used elsewhere) ——— */
details.section-details {
  margin-bottom: 0.75rem;
  scroll-margin-top: max(1rem, env(safe-area-inset-top));
}

/* Static legal pages (privacy, terms): flat document flow, no cards */
section.policy-section {
  margin: 0 0 1.75rem;
  scroll-margin-top: max(1rem, env(safe-area-inset-top));
}

section.policy-section > h2 {
  font-size: 1.0625rem;
  font-weight: 600;
  margin: 0 0 0.65rem;
  padding: 0;
  line-height: 1.3;
  color: var(--text);
}

section.policy-section .section-body {
  padding: 0;
  color: var(--text-secondary);
  font-size: 0.9375rem;
  line-height: 1.5;
}

.note-footer {
  color: var(--text-secondary);
  font-size: 0.9375rem;
  line-height: 1.5;
  margin-top: 1.25rem;
  padding: 1rem 1.125rem;
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 0.5px solid var(--separator-light);
  box-shadow: var(--shadow-card);
}

.note-footer strong {
  color: var(--text);
  font-weight: 600;
}

.note-footer a {
  font-weight: 500;
}

/* ——— Reduced motion ——— */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
  }
}

/* ——— Large screens: subtle max width breathing room ——— */
@media (min-width: 480px) {
  .page-wrap {
    padding-left: max(1.25rem, var(--pad-x));
    padding-right: max(1.25rem, var(--pad-x));
  }
}
