/* ==========================================================================
   GR9 Studio · App legal pages (repchamp/terms/, repchamp/privacy/)
   Loaded AFTER app-page.css: the page reuses the app page's background (soft light, grain, the live grid
   drawn by app-page.js), its top bar and its letter-by-letter title. This file only adds what a long,
   scrolling text page needs.
   ========================================================================== */

/* The app page is one fixed screen; these pages scroll */
html.legal-page,
html.legal-page body {
  height: auto;
  overflow: visible;
  overscroll-behavior: auto;
}

html.legal-page { scroll-behavior: smooth; scroll-padding-top: 2rem; }

html.legal-page body {
  display: block;
  min-height: 100%;
  /* transparent so the fixed background layers (z-index -1) show through; <html> is the black */
  background: transparent;
}

/* the hero background sits fixed behind the top of the page and fades out as you scroll (app-legal.js) */
.legal-page .hero-bg { will-change: opacity; }

/* melt the grid into black sooner than on the app page, so it stays behind the head and not the text */
.legal-page .hero-bg::after { height: 55%; }

/* fine grain that stays for the whole page */
.grain {
  transform: translateZ(0); /* its own layer: drawn once, never repainted while scrolling */
  position: fixed;
  inset: 0;
  z-index: -2;
  pointer-events: none;
  opacity: 0.04;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0.9 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* reading progress: a hairline along the very top */
.progress {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  height: 2px;
  background: rgb(var(--c));
  transform: scaleX(0);
  transform-origin: 0 50%;
  will-change: transform;
  pointer-events: none;
}

/* no entrance animations on a legal page: everything is simply there */
html.legal-page.js .top { opacity: 1; animation: none; transition: none; }

.top-home { gap: 0.6rem; }

.top-home svg {
  width: 0.95rem;
  height: 0.95rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 0.3s var(--out);
}

.top-home:hover svg { transform: translateX(-3px); }

/* --------------------------------------------------------------------------
   Head: the app's icon, its name, then the document title
   -------------------------------------------------------------------------- */

.legal-page main {
  display: block;
  width: 100%;
  max-width: 1160px;
  margin: 0 auto;
  padding: clamp(0.25rem, 1.5vh, 1rem) var(--pad) 0;
}

.legal-head {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.app-icon {
  display: block;
  position: relative;
  width: clamp(70px, 6.5vw, 96px);
  height: clamp(70px, 6.5vw, 96px);
  border-radius: 22.5%;
  overflow: hidden;
  box-shadow: 0 22px 44px -18px rgba(0, 0, 0, 0.95);
  transition: transform 0.5s var(--out);
}

.app-icon:hover { transform: translateY(-3px); }

.app-icon img { width: 100%; height: 100%; object-fit: cover; }

/* a fine rim of light, like the icon on the app page */
.app-icon::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.14),
    inset 0 1px 0 rgba(255, 255, 255, 0.4);
  pointer-events: none;
}

.app-name {
  margin-top: 0.8rem;
  font-family: var(--head);
  font-size: 1.45rem;
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: -0.035em;
}

.legal-head .hero-sub { margin-top: 0.25rem; font-size: 0.74rem; }

.legal-title {
  margin-top: clamp(1.25rem, 3.5vh, 2rem);
  padding: 0 0.2em 0.12em;
  font-family: var(--head);
  font-size: clamp(2.4rem, 5vw, 4.25rem);
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: -0.055em;
  color: #fff;
  /* white at the top fading to soft grey, like the app name on the app page */
  -webkit-mask-image: linear-gradient(180deg, #000 40%, rgba(0, 0, 0, 0.62) 80%);
  mask-image: linear-gradient(180deg, #000 40%, rgba(0, 0, 0, 0.62) 80%);
}

.legal-meta {
  margin-top: 0.4rem;
  font-size: 0.85rem;
  color: var(--faint);
}

/* Terms | Privacy switch */
.legal-switch {
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  margin-top: 1.4rem;
  padding: 0.3rem;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  /* a flat tint, no backdrop blur: blurring the moving grid behind it every frame is what made scrolling hitch */
  background: rgba(16, 16, 16, 0.7);
}

.legal-switch a {
  padding: 0.62rem 1.45rem;
  border-radius: 999px;
  font-family: var(--head);
  font-size: 0.86rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--muted);
  text-align: center;
  white-space: nowrap;
  transition: color 0.25s ease, background-color 0.25s ease;
}

.legal-switch a:hover { color: #fff; }

.legal-switch a[aria-current="page"] {
  background: #fff;
  color: #000;
  box-shadow: 0 6px 18px -8px rgba(255, 255, 255, 0.35);
}

/* --------------------------------------------------------------------------
   Body: contents on the left (sticky), the text on the right
   -------------------------------------------------------------------------- */

.legal-body {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: clamp(2.5rem, 6vw, 6rem);
  margin-top: clamp(2.5rem, 7vh, 4rem);
}

/* contents: a plain list on a thin line, the section you're reading marked in white */
.legal-toc {
  position: sticky;
  top: 2rem;
  align-self: start;
  max-height: calc(100vh - 4rem);
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: none;
}

.legal-toc::-webkit-scrollbar { display: none; }

.toc-label {
  margin-bottom: 1rem;
  font-size: 0.64rem;
  font-weight: 500;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--faint);
}

.toc-list {
  list-style: none;
  border-left: 1px solid rgba(255, 255, 255, 0.08);
}

.toc-list a {
  position: relative;
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  padding: 0.34rem 0 0.34rem 1rem;
  font-size: 0.8rem;
  line-height: 1.45;
  color: var(--faint);
  transition: color 0.25s ease;
}

.toc-list a::before {
  content: "";
  position: absolute;
  left: -1px;
  top: 0.3rem;
  bottom: 0.3rem;
  width: 1px;
  background: #fff;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.toc-list a:hover { color: rgba(255, 255, 255, 0.8); }

.toc-list .n {
  flex: none;
  min-width: 1.05rem;
  font-size: 0.68rem;
  font-variant-numeric: tabular-nums;
  color: rgba(255, 255, 255, 0.24);
  transition: color 0.25s ease;
}

.toc-list a[aria-current="true"] { color: #fff; }
.toc-list a[aria-current="true"]::before { opacity: 1; }
.toc-list a[aria-current="true"] .n { color: rgba(255, 255, 255, 0.6); }

/* on phones the contents fold into a row above the text */
.toc-mobile { display: none; }

/* --------------------------------------------------------------------------
   The text
   -------------------------------------------------------------------------- */

.legal-text {
  max-width: 46rem;
  min-width: 0;
  /* Manrope would draw "(c)" as "©" (in "Art. 6(1)(c)"): keep the text exactly as written */
  font-variant-ligatures: none;
  font-feature-settings: "liga" 0;
}

.legal-text > p,
.legal-text li,
.legal-text td {
  font-size: 0.97rem;
  line-height: 1.78;
  color: var(--muted);
}

.legal-text > p + p { margin-top: 1rem; }

/* the opening paragraphs: a little larger and brighter */
.legal-intro p {
  font-size: 1.06rem;
  line-height: 1.8;
  color: rgba(255, 255, 255, 0.74);
}

.legal-intro p + p { margin-top: 1rem; }

.legal-text h2 {
  margin-top: 3.25rem;
  padding-top: 3.25rem;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
  font-family: var(--head);
  font-size: clamp(1.45rem, 2.4vw, 1.85rem);
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.03em;
  color: #fff;
}

.legal-text h3 {
  margin-top: 2rem;
  font-family: var(--head);
  font-size: 1.08rem;
  font-weight: 700;
  letter-spacing: -0.015em;
  color: rgba(255, 255, 255, 0.92);
}

.legal-text h2 + p,
.legal-text h2 + ul,
.legal-text h3 + p,
.legal-text h3 + ul,
.legal-text p + ul,
.legal-text ul + p,
.legal-text p + .table-wrap,
.legal-text .table-wrap + p { margin-top: 1rem; }

.legal-text ul {
  display: grid;
  gap: 0.6rem;
  list-style: none;
}

.legal-text li {
  position: relative;
  padding-left: 1.4rem;
}

/* a short hairline instead of a bullet */
.legal-text li::before {
  content: "";
  position: absolute;
  left: 0.1rem;
  top: 0.88em;
  width: 0.6rem;
  height: 1px;
  background: rgba(255, 255, 255, 0.45);
}

.legal-text strong { color: #fff; font-weight: 600; }

/* numbered steps (delete-account pages): a small numbered circle instead of the hairline */
.legal-text ol.steps {
  display: grid;
  gap: 0.75rem;
  list-style: none;
  counter-reset: step;
}

.legal-text ol.steps li {
  counter-increment: step;
  padding-left: 2.5rem;
}

.legal-text ol.steps li::before {
  content: counter(step);
  top: 0.1rem;
  left: 0;
  display: grid;
  place-items: center;
  width: 1.6rem;
  height: 1.6rem;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  font-family: var(--head);
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1;
  color: #fff;
}

.legal-text h2 + ol,
.legal-text p + ol,
.legal-text ol + p { margin-top: 1rem; }

.legal-text a:not(.next-card) {
  color: #fff;
  text-decoration: underline;
  text-decoration-color: rgba(255, 255, 255, 0.3);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  transition: text-decoration-color 0.2s ease;
  overflow-wrap: anywhere;
}

.legal-text a:not(.next-card):hover { text-decoration-color: #fff; }

/* address blocks (operator, controller, contact) */
.legal-text p.legal-card {
  padding: 1.15rem 1.35rem;
  border: 1px solid var(--line);
  border-radius: 1rem;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0.012));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
  color: rgba(255, 255, 255, 0.75);
}

/* ---- tables (purposes and providers) ---- */

.table-wrap {
  border: 1px solid var(--line);
  border-radius: 1.1rem;
  overflow: hidden;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.035), rgba(255, 255, 255, 0.008));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.legal-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

.legal-table th {
  padding: 0.85rem 1.1rem;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  font-size: 0.66rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--faint);
  white-space: nowrap;
}

.legal-text .legal-table td {
  padding: 0.95rem 1.1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  font-size: 0.88rem;
  line-height: 1.6;
  vertical-align: top;
}

.legal-table tr:last-child td { border-bottom: 0; }

.legal-text .legal-table td:first-child {
  color: rgba(255, 255, 255, 0.88);
  font-weight: 600;
}

/* ---- the other document + contact, at the end ---- */

.legal-next {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.9rem;
  margin-top: 4.5rem;
}

.next-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 1.4rem 1.5rem 1.5rem;
  border: 1px solid var(--line);
  border-radius: 1.25rem;
  background:
    radial-gradient(ellipse 80% 60% at 50% 0%, rgba(255, 255, 255, 0.05), transparent 70%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.035), rgba(255, 255, 255, 0.01) 60%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.07);
  transition: transform 0.45s var(--out), border-color 0.3s ease;
}

.next-card:hover {
  transform: translateY(-3px);
  border-color: rgba(255, 255, 255, 0.24);
}

.next-card small {
  font-size: 0.64rem;
  font-weight: 500;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--faint);
}

.next-card b {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  font-family: var(--head);
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.next-card svg {
  flex: none;
  width: 1.1rem;
  height: 1.1rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 0.35s var(--out);
}

.next-card:hover svg { transform: translateX(4px); }

.next-card span {
  font-size: 0.85rem;
  color: var(--muted);
  overflow-wrap: anywhere;
}

/* --------------------------------------------------------------------------
   Footer + back to top
   -------------------------------------------------------------------------- */

.foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem 2rem;
  max-width: 1160px;
  width: 100%;
  margin: clamp(4rem, 12vh, 7rem) auto 0;
  padding:
    1.75rem
    max(var(--pad), env(safe-area-inset-right))
    max(2rem, env(safe-area-inset-bottom))
    max(var(--pad), env(safe-area-inset-left));
  border-top: 1px solid var(--line);
  font-size: 0.8rem;
  color: var(--faint);
}

.foot nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.6rem;
}

.foot a { transition: color 0.2s ease; }
.foot a:hover { color: #fff; }

.to-top {
  position: fixed;
  right: max(1.25rem, env(safe-area-inset-right));
  bottom: max(1.25rem, env(safe-area-inset-bottom));
  z-index: 60;
  display: grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 50%;
  /* solid, no backdrop blur (a blurred fixed button has to be redrawn on every scroll frame) */
  background: rgba(14, 14, 14, 0.94);
  color: #fff;
  cursor: pointer;
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.4s var(--out), border-color 0.2s ease;
}

.to-top.is-on { opacity: 1; transform: none; pointer-events: auto; }
.to-top:hover { border-color: rgba(255, 255, 255, 0.5); }

.to-top svg {
  width: 1rem;
  height: 1rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* --------------------------------------------------------------------------
   Tablets and phones
   -------------------------------------------------------------------------- */

@media (max-width: 900px) {
  .legal-body { grid-template-columns: 1fr; margin-top: 2.5rem; }
  .legal-toc { display: none; }
  .legal-text { max-width: none; }

  .toc-mobile {
    display: block;
    margin-bottom: 2.5rem;
    border-block: 1px solid var(--line);
  }

  .toc-mobile summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 0.1rem;
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.75);
    cursor: pointer;
    list-style: none;
  }

  .toc-mobile summary::-webkit-details-marker { display: none; }

  .toc-mobile summary svg {
    width: 0.9rem;
    height: 0.9rem;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    transition: transform 0.3s var(--out);
  }

  .toc-mobile[open] summary svg { transform: rotate(180deg); }
  .toc-mobile .toc-list { margin: 0 0 1rem 0.1rem; }
  .toc-mobile .toc-list a { font-size: 0.88rem; color: var(--muted); }
}

@media (max-width: 768px) {
  /* the tables turn into one small card per row, each cell with its column name */
  .table-wrap { border: 0; background: none; box-shadow: none; overflow: visible; }
  .legal-table, .legal-table tbody, .legal-table tr, .legal-table td { display: block; width: 100%; }
  .legal-table thead { display: none; }
  .legal-table tbody { display: grid; gap: 0.7rem; }

  .legal-table tr {
    padding: 0.4rem 0;
    border: 1px solid var(--line);
    border-radius: 1rem;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0.01));
  }

  .legal-text .legal-table td { padding: 0.5rem 1.1rem; border-bottom: 0; }

  .legal-table td[data-label]::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 0.15rem;
    font-size: 0.6rem;
    font-weight: 600;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--faint);
  }

  .legal-text .legal-table td:first-child { font-size: 0.95rem; }
}

@media (max-width: 560px) {
  .legal-title { font-size: clamp(2.1rem, 10vw, 3rem); }
  .legal-body { margin-top: 2.25rem; }
  .legal-switch { width: 100%; max-width: 21rem; }
  .legal-switch a { padding-inline: 0.8rem; }
  .legal-intro p { font-size: 1rem; }
  .legal-text h2 { margin-top: 2.5rem; padding-top: 2.5rem; }
  .legal-next { grid-template-columns: 1fr; }
  .foot { flex-direction: column; align-items: flex-start; }
}

@media (prefers-reduced-motion: reduce) {
  html.legal-page { scroll-behavior: auto; }
}
