/* LOOPLY — website styles.
 *
 * The palette is not invented here. Every colour below is a copy of a token from
 * screenshots/design-tokens.json, which is generated from scripts/generate-assets.py — the same
 * source the iOS app and the screenshot renderer use. If a token changes there, change it here;
 * scripts/check-frontend.py fails when the two drift apart.
 */

/* --- Tokens --------------------------------------------------------------- */

:root {
  --brand-indigo: #4A44E8;
  --brand-violet: #8A3FE0;

  --background: #F4F5FA;
  --surface: #FFFFFF;
  --surface-raised: #ECEEF6;
  --separator: #E1E4EE;
  --text-primary: #10131A;
  --text-secondary: #69707F;
  --text-on-brand: #FFFFFF;

  --board-surface: #E7EAF3;
  --board-cell: #FDFDFF;
  --board-cell-valid: #DCE0FF;
  --board-grid: #D6DAE7;

  --positive: #12996E;
  --warning: #C97A12;
  --danger: #D4304A;

  --tile-aqua: #0A8FA0;
  --tile-coral: #D33449;
  --tile-violet: #6A3AE0;
  --tile-lime: #3E8B22;
  --tile-amber: #B96B10;

  --bonus-tile2: #3F7FA8;
  --bonus-tile3: #2F6488;
  --bonus-loop2: #A85F9E;
  --bonus-loop3: #8A3F84;

  /* Spacing is the app's 4-point scale, unchanged. */
  --s-xxs: 2px;  --s-xs: 4px;  --s-s: 8px;   --s-m: 12px;
  --s-l: 16px;   --s-xl: 24px; --s-xxl: 32px; --s-huge: 48px;

  --radius-tile: 22%;
  --radius-card: 20px;
  --radius-pill: 999px;

  --shadow-card: 0 1px 2px rgba(16, 19, 26, .04), 0 8px 24px rgba(16, 19, 26, .06);
  --shadow-lift: 0 2px 6px rgba(16, 19, 26, .06), 0 18px 48px rgba(16, 19, 26, .12);

  --measure: 68ch;
  --page: 1120px;

  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, system-ui, sans-serif;
  /* SF Pro Rounded on Apple platforms, a graceful fall back to the body face elsewhere. The
     rounded face is what makes the page read as a game rather than a utility. */
  --font-rounded: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, Inter,
                  system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --brand-indigo: #6E68FF;
    --brand-violet: #A97BFF;

    --background: #0C0F15;
    --surface: #161A22;
    --surface-raised: #1F242F;
    --separator: #2A303D;
    --text-primary: #F2F4F8;
    --text-secondary: #98A0B0;
    --text-on-brand: #FFFFFF;

    --board-surface: #111520;
    --board-cell: #1C212B;
    --board-cell-valid: #2B3252;
    --board-grid: #232936;

    --positive: #2ECC97;
    --warning: #EFA53C;
    --danger: #FF5F72;

    --tile-aqua: #0E9FB2;
    --tile-coral: #E9455B;
    --tile-violet: #7E52F0;
    --tile-lime: #4BA22C;
    --tile-amber: #D07C1B;

    --bonus-tile2: #5A9CC4;
    --bonus-tile3: #4B87AE;
    --bonus-loop2: #C57EBB;
    --bonus-loop3: #AE5FA6;

    --shadow-card: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
    --shadow-lift: 0 2px 6px rgba(0, 0, 0, .45), 0 18px 48px rgba(0, 0, 0, .5);
  }
}

/* --- Base ----------------------------------------------------------------- */

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

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

body {
  margin: 0;
  background: var(--background);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4, .rounded { font-family: var(--font-rounded); letter-spacing: -.01em; }
h1 { font-size: clamp(2.2rem, 6vw, 3.6rem); line-height: 1.08; font-weight: 800; margin: 0 0 var(--s-l); }
h2 { font-size: clamp(1.6rem, 3.4vw, 2.3rem); line-height: 1.15; font-weight: 800; margin: 0 0 var(--s-m); }
h3 { font-size: 1.2rem; font-weight: 700; margin: 0 0 var(--s-s); }
p  { margin: 0 0 var(--s-l); max-width: var(--measure); }
ul, ol { max-width: var(--measure); }
li { margin-bottom: var(--s-xs); }

a { color: var(--brand-indigo); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--brand-violet); }

strong { font-weight: 700; }
code, kbd {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .88em;
  background: var(--surface-raised);
  padding: .1em .38em;
  border-radius: 6px;
}

:focus-visible { outline: 3px solid var(--brand-indigo); outline-offset: 3px; border-radius: 6px; }

.wrap { width: min(100% - 2 * var(--s-xl), var(--page)); margin-inline: auto; }
.lede { font-size: 1.15rem; color: var(--text-secondary); }
.muted { color: var(--text-secondary); }
.center { text-align: center; margin-inline: auto; }
.nowrap { white-space: nowrap; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px;
  clip-path: inset(50%); overflow: hidden; white-space: nowrap;
}

.skip-link {
  position: absolute; left: var(--s-l); top: -100px; z-index: 100;
  background: var(--surface); color: var(--text-primary);
  padding: var(--s-s) var(--s-l); border-radius: var(--radius-pill); box-shadow: var(--shadow-lift);
}
.skip-link:focus { top: var(--s-l); }

/* --- Header --------------------------------------------------------------- */

.site-header {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--background) 82%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--separator);
}
.site-header__inner {
  display: flex; align-items: center; gap: var(--s-l);
  min-height: 64px; padding-block: var(--s-s);
}
.wordmark {
  display: inline-flex; align-items: center; gap: var(--s-s);
  font-family: var(--font-rounded); font-weight: 900; font-size: 1.15rem;
  letter-spacing: .16em; text-transform: uppercase; text-decoration: none;
  color: var(--text-primary);
}
.wordmark img { width: 30px; height: 30px; border-radius: 8px; }
.wordmark span {
  background: linear-gradient(120deg, var(--brand-indigo), var(--brand-violet));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.site-nav { display: flex; gap: var(--s-l); margin-left: auto; align-items: center; }
.site-nav a { color: var(--text-secondary); text-decoration: none; font-weight: 600; font-size: .95rem; }
.site-nav a:hover, .site-nav a[aria-current="page"] { color: var(--text-primary); }
@media (max-width: 760px) { .site-nav .hide-narrow { display: none; } }

/* Language switch. Two buttons, not a dropdown: one tap, and the other language is visible. */
.lang-switch {
  display: inline-flex; padding: 3px; gap: 2px;
  background: var(--surface-raised); border-radius: var(--radius-pill);
}
.lang-switch button {
  font: inherit; font-size: .8rem; font-weight: 700; letter-spacing: .04em;
  padding: var(--s-xs) var(--s-m); border: 0; border-radius: var(--radius-pill);
  background: transparent; color: var(--text-secondary); cursor: pointer;
}
.lang-switch button[aria-pressed="true"] {
  background: var(--surface); color: var(--text-primary); box-shadow: var(--shadow-card);
}

/* --- Buttons -------------------------------------------------------------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-s);
  font-family: var(--font-rounded); font-weight: 700; font-size: 1rem;
  padding: var(--s-m) var(--s-xl); border-radius: var(--radius-pill);
  border: 1px solid transparent; text-decoration: none; cursor: pointer;
  transition: transform .15s ease, box-shadow .15s ease, background .15s ease;
}
.btn:active { transform: translateY(1px); }
.btn--primary {
  background: linear-gradient(120deg, var(--brand-indigo), var(--brand-violet));
  color: var(--text-on-brand); box-shadow: var(--shadow-card);
}
.btn--primary:hover { color: var(--text-on-brand); box-shadow: var(--shadow-lift); }
.btn--ghost { background: var(--surface); color: var(--text-primary); border-color: var(--separator); }
.btn--ghost:hover { color: var(--text-primary); border-color: var(--brand-indigo); }
.btn--small { padding: var(--s-s) var(--s-l); font-size: .9rem; }

/* --- Sections and cards --------------------------------------------------- */

section { padding-block: clamp(var(--s-huge), 9vw, 104px); }
/* The header is sticky, so an anchor would otherwise drop its own heading underneath it. */
section[id], h2[id], h3[id] { scroll-margin-top: 88px; }
section + section { padding-top: 0; }
.section-head { max-width: var(--measure); margin-bottom: var(--s-xxl); }
.eyebrow {
  display: inline-block; margin-bottom: var(--s-s);
  font-family: var(--font-rounded); font-weight: 800; font-size: .78rem;
  letter-spacing: .14em; text-transform: uppercase; color: var(--brand-indigo);
}

.card {
  background: var(--surface); border: 1px solid var(--separator);
  border-radius: var(--radius-card); padding: var(--s-xl); box-shadow: var(--shadow-card);
}
.grid { display: grid; gap: var(--s-l); }
.grid--3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid--2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.card p:last-child, .card ul:last-child { margin-bottom: 0; }


/* --- Hero ----------------------------------------------------------------- */

.hero { position: relative; overflow: hidden; padding-top: clamp(var(--s-xxl), 6vw, 72px); }
.hero::before {
  content: ""; position: absolute; inset: -30% 30% 40% -20%; z-index: -1;
  background: radial-gradient(closest-side, color-mix(in srgb, var(--brand-indigo) 22%, transparent), transparent);
  filter: blur(20px);
}
.hero__inner { display: grid; gap: var(--s-huge); grid-template-columns: 1.05fr .95fr; align-items: center; }
@media (max-width: 900px) { .hero__inner { grid-template-columns: 1fr; gap: var(--s-xxl); } }
.hero__pitch {
  font-family: var(--font-rounded); font-weight: 800;
  font-size: clamp(1.05rem, 2.3vw, 1.35rem); letter-spacing: .02em;
  background: linear-gradient(120deg, var(--brand-indigo), var(--brand-violet));
  -webkit-background-clip: text; background-clip: text; color: transparent;
  margin-bottom: var(--s-l);
}
.hero__actions { display: flex; flex-wrap: wrap; gap: var(--s-m); margin-bottom: var(--s-l); }
.hero__actions.center { justify-content: center; }
.hero__note { font-size: .9rem; color: var(--text-secondary); }

/* --- Board ---------------------------------------------------------------- */

.board {
  --cells: 5;
  display: grid; grid-template-columns: repeat(var(--cells), 1fr);
  gap: 2px; padding: var(--s-m);
  background: var(--board-surface); border-radius: var(--radius-card);
  box-shadow: var(--shadow-lift);
  width: 100%; max-width: 460px; aspect-ratio: 1; margin-inline: auto;
}
.board--flat { box-shadow: none; max-width: 340px; }
.cell {
  position: relative; background: var(--board-cell); border-radius: 10%;
  display: grid; place-items: center; padding: 0; border: 0;
  outline-offset: -2px;
}
.cell--playable { cursor: pointer; }
.cell--valid { background: var(--board-cell-valid); box-shadow: inset 0 0 0 2px var(--brand-indigo); }
.cell--gap { background: var(--board-cell); box-shadow: inset 0 0 0 2px var(--warning); }
.cell--placed { animation: pop .28s cubic-bezier(.2, 1.4, .5, 1); }
.cell--loop { animation: glow 1.1s ease-out; }
.cell svg { width: 100%; height: 100%; display: block; }

@keyframes pop { from { transform: scale(.7); opacity: .4; } to { transform: scale(1); opacity: 1; } }
@keyframes glow {
  0%   { box-shadow: 0 0 0 0 color-mix(in srgb, var(--brand-violet) 70%, transparent); }
  100% { box-shadow: 0 0 0 14px transparent; }
}

/* --- Rack ----------------------------------------------------------------- */

.rack { display: flex; flex-wrap: wrap; gap: var(--s-s); justify-content: center; margin-block: var(--s-l); }
.rack__tile {
  width: 56px; height: 56px; padding: 0; border: 0; border-radius: 12px;
  background: transparent; cursor: pointer;
  transition: transform .15s ease, filter .15s ease;
}
.rack__tile svg { width: 100%; height: 100%; display: block; }
.rack__tile[aria-pressed="true"] { transform: translateY(-6px); filter: drop-shadow(0 8px 14px rgba(0,0,0,.25)); }
.rack__tile[disabled] { opacity: .3; cursor: default; transform: none; }

/* One column, centred: the board is the invitation, and nothing should sit beside it
 * competing for attention. */
.playground { display: grid; justify-items: center; gap: var(--s-s); }
.playground .board { margin-block: 0; }
.hint { min-height: 3em; font-size: .95rem; color: var(--text-secondary); margin-bottom: var(--s-s); }

/* --- Diagrams ------------------------------------------------------------- */

.pair { display: flex; align-items: center; gap: var(--s-s); }
.pair__verdict { font-family: var(--font-rounded); font-weight: 800; font-size: 1.1rem; }
.pair__verdict--ok { color: var(--positive); }
.pair__verdict--no { color: var(--danger); }
.pair svg { width: 48px; height: 48px; }
.pair-list { display: grid; gap: var(--s-m); list-style: none; padding: 0; margin: 0 0 var(--s-l); }
.pair-list li { display: grid; grid-template-columns: auto 1fr; gap: var(--s-m); align-items: center; }

/* --- Steps ---------------------------------------------------------------- */

.steps { counter-reset: step; display: grid; gap: var(--s-xl); grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.step { position: relative; }
.step__num {
  counter-increment: step; display: grid; place-items: center;
  width: 34px; height: 34px; border-radius: 50%; margin-bottom: var(--s-m);
  background: linear-gradient(120deg, var(--brand-indigo), var(--brand-violet));
  color: var(--text-on-brand); font-family: var(--font-rounded); font-weight: 800;
}
.step__num::before { content: counter(step); }

/* --- Tables --------------------------------------------------------------- */

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; width: 100%; font-size: .95rem; }
th, td { text-align: left; padding: var(--s-s) var(--s-m); border-bottom: 1px solid var(--separator); }
th { font-family: var(--font-rounded); font-weight: 700; color: var(--text-secondary); font-size: .85rem; letter-spacing: .04em; text-transform: uppercase; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:last-child td { border-bottom: 0; }

/* --- Screenshots ---------------------------------------------------------- */

.shots { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: var(--s-l); }
.shot { margin: 0; }
.shot img {
  width: 100%; height: auto; display: block;
  border-radius: 18px; border: 1px solid var(--separator); box-shadow: var(--shadow-card);
  background: var(--surface);
}
.shot figcaption { margin-top: var(--s-s); font-size: .85rem; color: var(--text-secondary); text-align: center; }

/* --- FAQ ------------------------------------------------------------------ */

.faq { max-width: var(--measure); }
.faq details {
  border-bottom: 1px solid var(--separator); padding: var(--s-l) 0;
}
.faq summary {
  cursor: pointer; font-family: var(--font-rounded); font-weight: 700; font-size: 1.05rem;
  list-style: none; display: flex; justify-content: space-between; gap: var(--s-l);
}
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after { content: "+"; color: var(--brand-indigo); font-size: 1.4rem; line-height: 1; }
.faq details[open] summary::after { content: "−"; }
.faq details p { margin: var(--s-m) 0 0; }

/* --- Callout -------------------------------------------------------------- */

.callout {
  border-left: 3px solid var(--brand-indigo);
  background: var(--surface-raised);
  border-radius: 0 var(--radius-card) var(--radius-card) 0;
  padding: var(--s-l) var(--s-xl);
  margin-block: var(--s-xl);
}
.callout p:last-child { margin-bottom: 0; }

/* --- Footer --------------------------------------------------------------- */

.site-footer { border-top: 1px solid var(--separator); padding-block: var(--s-huge); margin-top: var(--s-huge); }
.site-footer__grid { display: grid; gap: var(--s-xl); grid-template-columns: 1.4fr repeat(auto-fit, minmax(150px, 1fr)); }
.site-footer h4 { font-size: .8rem; letter-spacing: .12em; text-transform: uppercase; color: var(--text-secondary); }
.site-footer ul { list-style: none; padding: 0; margin: 0; }
.site-footer a { color: var(--text-secondary); text-decoration: none; }
.site-footer a:hover { color: var(--text-primary); }
.site-footer__legal { margin-top: var(--s-xxl); font-size: .85rem; color: var(--text-secondary); }

/* --- Prose pages ---------------------------------------------------------- */

.prose { padding-top: var(--s-huge); }
.prose h2 { margin-top: var(--s-huge); }
.prose h3 { margin-top: var(--s-xl); }
.toc { position: sticky; top: 88px; align-self: start; font-size: .92rem; }
.toc ul { list-style: none; padding: 0; margin: 0; }
.toc a { color: var(--text-secondary); text-decoration: none; display: block; padding: var(--s-xs) 0; }
.toc a:hover { color: var(--text-primary); }
.prose__layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: var(--s-huge); }
@media (max-width: 900px) { .prose__layout { grid-template-columns: 1fr; } .toc { position: static; display: none; } }

/* --- Utilities ------------------------------------------------------------ */
/* Small and deliberately few. They exist so that the pages carry no inline `style`
 * attributes, which is what lets the Content-Security-Policy forbid inline styles outright
 * rather than allowing them everywhere. */

.mt-m { margin-top: var(--s-m); }
.mt-l { margin-top: var(--s-l); }
.mt-xl { margin-top: var(--s-xl); }
.mt-huge { margin-top: var(--s-huge); }
.cap { margin: var(--s-l) 0 0; }
.footnote { margin-top: var(--s-l); font-size: .88rem; }
.measure { max-width: var(--measure); }
.narrow { max-width: 520px; }
.board--small { max-width: 180px; }
