@font-face {
  font-family: 'Whyte Inktrap';
  src: url('../assets/fonts/ABCWhyteInktrapVariable-Trial.woff2') format('woff2');
  font-weight: 100 900;
  font-display: swap;
}
@font-face {
  font-family: 'Damoon';
  src: url('../assets/fonts/Damoon-FaNum-VF.woff2') format('woff2');
  font-weight: 100 900;
  font-display: swap;
}

:root {
  --bg: #030304;
  --fg: #f2f2ef;
  --mute: rgba(242, 242, 239, .55);
  --line: rgba(242, 242, 239, .14);
  --panel: rgba(10, 10, 12, .78);
  --ease: cubic-bezier(.16, 1, .3, 1);
  --g: clamp(14px, 2.4vw, 32px);
  color-scheme: dark; /* dark native scrollbars and form controls */
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; background: var(--bg); color: var(--fg); font-family: 'Whyte Inktrap', 'Helvetica Neue', Arial, sans-serif; font-weight: 350; -webkit-font-smoothing: antialiased; overflow: hidden; overscroll-behavior: none; }
button, select, input { font: inherit; color: inherit; }
button { background: none; border: 0; cursor: pointer; }
a { color: inherit; }
[hidden] { display: none !important; }

#gl { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; outline: none; touch-action: none; }

/* ---------- Entry ---------- */
.entry {
  position: fixed; inset: 0; z-index: 30; display: grid; place-content: center; justify-items: center; text-align: center; gap: 20px; padding: var(--g);
  background: radial-gradient(ellipse at 50% 60%, rgba(3, 3, 4, .2), rgba(3, 3, 4, .85) 70%);
  transition: opacity 1.4s var(--ease), visibility 1.4s;
}
body:not(.is-entry) .entry { opacity: 0; visibility: hidden; pointer-events: none; }
.entry__kicker { font-size: 12px; letter-spacing: .3em; text-transform: uppercase; color: var(--mute); }
.entry__title { font-size: clamp(44px, 9vw, 132px); font-weight: 200; letter-spacing: .12em; line-height: 1; margin-right: -.12em; }
.entry__sub { font-size: clamp(16px, 1.8vw, 22px); color: rgba(242, 242, 239, .8); font-weight: 300; }
.btn-primary {
  margin-top: 26px; padding: 18px 40px; border-radius: 999px; border: 1px solid rgba(242, 242, 239, .5);
  font-size: 13px; letter-spacing: .28em; text-transform: uppercase; transition: background .5s, color .5s, box-shadow .6s, opacity .4s;
}
.btn-primary:not(:disabled):hover { background: var(--fg); color: var(--bg); box-shadow: 0 0 80px rgba(255, 255, 255, .25); }
.btn-primary:disabled { opacity: .45; cursor: progress; }
.entry__opts { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px 22px; margin-top: 18px; font-size: 13px; color: var(--mute); }
.entry__opts select { margin-inline-start: 8px; background: transparent; border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px; }
.entry__opts select option { background: #111; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.check input { accent-color: #f2f2ef; }
.entry__hint { margin-top: 10px; font-size: 12px; color: rgba(242, 242, 239, .38); letter-spacing: .04em; }
.entry__back { position: fixed; inset-inline-start: var(--g); top: var(--g); font-size: 12px; letter-spacing: .14em; text-transform: uppercase; color: var(--mute); text-decoration: none; }

/* ---------- HUD ---------- */
.hud { position: fixed; inset: 0; z-index: 10; pointer-events: none; opacity: 1; transition: opacity .9s var(--ease); }
.hud > * { pointer-events: auto; }
body.is-entry .hud, body.hud-hidden .hud { opacity: 0; }
body.is-entry .hud > *, body.hud-hidden .hud > * { pointer-events: none; }
.hud__tl { position: absolute; inset-inline-start: var(--g); top: var(--g); }
.hud__brand { font-size: 13px; letter-spacing: .3em; text-transform: uppercase; text-decoration: none; }
.hud__brand span { color: var(--mute); }
.hud__place { margin-top: 10px; font-size: 13px; color: var(--mute); min-height: 1.2em; transition: opacity .8s; }
.hud__nav { position: absolute; inset-inline-end: var(--g); top: var(--g); display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px; padding: 6px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); max-width: calc(100vw - 2 * var(--g)); }
.hud__nav button { padding: 9px 14px; border-radius: 999px; font-size: 12px; letter-spacing: .08em; color: var(--mute); transition: color .3s, background .3s; }
.hud__nav button:hover, .hud__nav button.is-on { color: var(--fg); background: rgba(242, 242, 239, .08); }
.hud__bl { position: absolute; inset-inline-start: var(--g); bottom: var(--g); font-size: 12px; color: var(--mute); letter-spacing: .04em; }
.hud__keys { display: block; margin-top: 6px; color: rgba(242, 242, 239, .32); }
.hud__inspect { position: absolute; left: 50%; bottom: calc(var(--g) * 2.2); transform: translateX(-50%); padding: 10px 18px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel); font-size: 12px; letter-spacing: .08em; color: var(--mute); }
.hud__inspect b { color: var(--fg); font-weight: 400; margin-inline-start: 6px; }
.hud__leave { position: absolute; inset-inline-end: var(--g); bottom: var(--g); font-size: 12px; letter-spacing: .14em; text-transform: uppercase; color: var(--mute); text-decoration: none; }
.crosshair { position: fixed; left: 50%; top: 50%; width: 4px; height: 4px; margin: -2px; border-radius: 50%; background: rgba(242, 242, 239, .5); z-index: 9; pointer-events: none; transition: opacity .6s; }
body.is-entry .crosshair, body.mode-lab .crosshair, body.view-orbit .crosshair { opacity: 0; }
.skip-intro { position: fixed; z-index: 12; inset-inline-end: var(--g); bottom: var(--g); padding: 10px 18px; border-radius: 999px; border: 1px solid var(--line); font-size: 12px; letter-spacing: .14em; text-transform: uppercase; color: var(--mute); background: var(--panel); }

/* ---------- Panels ---------- */
.panel {
  position: fixed; z-index: 20; inset-inline-end: var(--g); top: calc(var(--g) + 64px); width: min(380px, calc(100vw - 2 * var(--g))); max-height: calc(100vh - var(--g) * 2 - 80px); overflow: auto;
  padding: 20px 22px 22px; border-radius: 18px; border: 1px solid var(--line); background: var(--panel); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  animation: panelIn .5s var(--ease);
}
@keyframes panelIn { from { opacity: 0; transform: translateY(12px); } }
.panel header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.panel h2 { font-size: 13px; letter-spacing: .24em; text-transform: uppercase; font-weight: 400; }
.panel p { font-size: 14px; line-height: 1.6; color: rgba(242, 242, 239, .82); margin-bottom: 12px; }
.panel .note { font-size: 12px; color: var(--mute); }
.close { font-size: 20px; color: var(--mute); width: 30px; height: 30px; border-radius: 50%; border: 1px solid var(--line); line-height: 1; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); font-size: 13px; }
.row select, .row input[type=range] { max-width: 55%; }
select { background: transparent; border: 1px solid var(--line); border-radius: 8px; padding: 5px 8px; }
select option { background: #111; }
input[type=range] { accent-color: #f2f2ef; }
.env-list { list-style: none; }
.env-list button { width: 100%; text-align: start; padding: 12px 0; border-top: 1px solid var(--line); display: grid; grid-template-columns: 34px 1fr; gap: 4px 10px; }
.env-list button:hover .env-name { color: var(--fg); }
.env-list .env-num { font-size: 11px; color: var(--mute); padding-top: 3px; letter-spacing: .1em; }
.env-list .env-name { font-size: 16px; color: rgba(242, 242, 239, .85); transition: color .3s; }
.env-list .env-desc { grid-column: 2; font-size: 12px; color: var(--mute); line-height: 1.5; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: 13px; margin: 6px 0 16px; }
.facts dt { color: var(--mute); }
.row-btns { display: flex; flex-wrap: wrap; gap: 8px; }
.btn { padding: 10px 16px; border-radius: 999px; background: var(--fg); color: var(--bg); font-size: 12px; letter-spacing: .08em; text-transform: uppercase; display: inline-flex; align-items: center; }
.btn.ghost { background: transparent; color: var(--fg); border: 1px solid var(--line); }
.btn.ghost:hover { border-color: rgba(242, 242, 239, .5); }
.show-item { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: center; padding: 12px 0; border-top: 1px solid var(--line); }
.show-item b { font-weight: 400; font-size: 14px; }
.show-item small { grid-column: 1; font-size: 11px; color: var(--mute); letter-spacing: .08em; text-transform: uppercase; }
.show-item .btn { grid-row: 1 / span 2; grid-column: 2; }

/* ---------- Pattern Lab ---------- */
.lab {
  position: fixed; z-index: 20; inset-inline-start: var(--g); top: calc(var(--g) + 54px); bottom: calc(var(--g) + 160px); width: min(340px, calc(100vw - 2 * var(--g))); overflow: auto;
  padding: 16px 18px; border-radius: 18px; border: 1px solid var(--line); background: var(--panel); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
}
.lab section { padding: 12px 0; border-top: 1px solid var(--line); }
.lab h4 { font-size: 11px; letter-spacing: .2em; text-transform: uppercase; font-weight: 400; color: var(--mute); margin-bottom: 10px; }
.lab h4 small { letter-spacing: .04em; text-transform: none; margin-inline-start: 6px; opacity: .7; }
.lab-name { width: 100%; background: transparent; border: 0; border-bottom: 1px solid var(--line); font-size: 18px; padding: 4px 0 8px; outline: none; }
.ctl { display: block; margin-bottom: 8px; font-size: 12px; color: rgba(242, 242, 239, .78); }
.ctl span { display: flex; justify-content: space-between; margin-bottom: 3px; }
.ctl b { font-weight: 400; color: var(--mute); font-variant-numeric: tabular-nums; }
.ctl input[type=range], .ctl select { width: 100%; }
.layer { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px 6px; margin-bottom: 10px; }
.layer legend { font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--mute); padding: 0 6px; }
.mini { font-size: 11px; color: var(--mute); border: 1px solid var(--line); border-radius: 999px; padding: 3px 9px; margin-inline-start: 6px; }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.swatches button { width: 24px; height: 24px; border-radius: 50%; background: var(--c); border: 2px solid transparent; box-shadow: 0 0 0 1px var(--line); }
.swatches button.is-on { border-color: var(--bg); box-shadow: 0 0 0 2px var(--fg); }
.hint { font-size: 11px; color: var(--mute); margin: 4px 0 6px; }
.lab-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.lab-actions .btn { font-size: 11px; padding: 9px 13px; cursor: pointer; }
.lab-msg { width: 100%; font-size: 12px; color: var(--fg); min-height: 1.4em; }
.saved { width: 100%; }
.saved-item { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; border-top: 1px solid var(--line); font-size: 13px; }
.link { text-decoration: underline; text-underline-offset: 3px; text-align: start; }
.timeline {
  position: fixed; z-index: 20; left: var(--g); right: var(--g); bottom: var(--g); height: 150px; padding: 10px 14px; border-radius: 16px; border: 1px solid var(--line);
  background: var(--panel); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
}
.tl-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; font-size: 12px; color: var(--mute); margin-bottom: 4px; }
.tl-bar input[type=number] { width: 54px; background: transparent; border: 1px solid var(--line); border-radius: 6px; padding: 2px 6px; margin: 0 4px; }
.tl-canvas { width: 100%; height: 120px; display: block; touch-action: none; }
body.mode-lab .hud__bl, body.mode-lab .hud__inspect, body.mode-lab .hud__place { display: none; }

/* ---------- Touch ---------- */
.touch { position: fixed; inset: auto 0 0 0; z-index: 15; height: 0; }
.joy { position: fixed; left: 28px; bottom: 34px; width: 120px; height: 120px; border-radius: 50%; border: 1px solid var(--line); background: rgba(10, 10, 12, .35); pointer-events: none; }
.joy i { position: absolute; left: 50%; top: 50%; width: 46px; height: 46px; margin: -23px; border-radius: 50%; background: rgba(242, 242, 239, .25); transition: transform .15s; }
.touch__btns { position: fixed; right: 18px; bottom: 34px; display: grid; gap: 10px; }
.touch__btns button { width: 64px; height: 64px; border-radius: 50%; border: 1px solid var(--line); background: var(--panel); font-size: 12px; letter-spacing: .08em; }

.fader { position: fixed; inset: 0; z-index: 25; background: #000; opacity: 0; pointer-events: none; transition: opacity .8s ease; }
.fader.is-on { opacity: 1; }
.toast { position: fixed; z-index: 26; left: 50%; top: 22%; transform: translateX(-50%); font-size: 13px; letter-spacing: .12em; text-transform: uppercase; color: var(--fg); opacity: 0; transition: opacity .8s; text-align: center; pointer-events: none; }
.toast.is-on { opacity: .9; }
body.mode-lab .toast { opacity: 0; } /* the lab reports in its own panel */
.nojs { position: fixed; inset: 0; display: grid; place-items: center; }

/* ---------- Language ---------- */
.lang-switch { font-family: 'Damoon', 'Whyte Inktrap', sans-serif; letter-spacing: 0 !important; text-transform: none !important; }
html[lang="fa"] .lang-switch { font-family: 'Whyte Inktrap', sans-serif; }
.entry__lang { position: fixed; inset-inline-end: var(--g); top: var(--g); padding: 7px 14px; border-radius: 999px; border: 1px solid var(--line); font-size: 14px; color: var(--mute); transition: color .3s, border-color .3s; }
.entry__lang:hover { color: var(--fg); border-color: rgba(242, 242, 239, .5); }

/* Persian: Damoon, and no letter-spacing or capitals (spacing breaks the joins between letters) */
html[lang="fa"] body { font-family: 'Damoon', 'Whyte Inktrap', Tahoma, sans-serif; font-weight: 400; }
html[lang="fa"] body *:not(canvas) { letter-spacing: 0 !important; text-transform: none !important; }
html[lang="fa"] .entry__title { font-weight: 300; margin-right: 0; font-size: clamp(40px, 8vw, 112px); }
html[lang="fa"] .entry__sub, html[lang="fa"] .panel p { line-height: 1.9; }
html[lang="fa"] .hud__nav button { font-size: 13px; }
html[lang="fa"] .hud__brand, html[lang="fa"] .panel h2, html[lang="fa"] .toast { font-size: 15px; }
html[lang="fa"] .btn, html[lang="fa"] .btn-primary, html[lang="fa"] .skip-intro, html[lang="fa"] .hud__leave, html[lang="fa"] .entry__back { font-size: 14px; }
html[lang="fa"] .lab h4, html[lang="fa"] .layer legend, html[lang="fa"] .entry__kicker { font-size: 13px; }
html[lang="fa"] .ctl, html[lang="fa"] .hud__bl, html[lang="fa"] .entry__hint, html[lang="fa"] .show-item small { font-size: 13px; }
html[lang="fa"] .hud__keys, html[lang="fa"] .tl-bar { direction: rtl; unicode-bidi: plaintext; }
html[dir="rtl"] .ctl input[type=range], html[dir="rtl"] .row input[type=range] { direction: ltr; }

@media (max-width: 760px) {
  /* one swipeable row: same height in every language, so nothing below can collide with it */
  .hud__nav {
    left: var(--g); right: var(--g); top: calc(var(--g) + 40px); flex-wrap: nowrap; justify-content: flex-start;
    overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: none;
    -webkit-mask-image: linear-gradient(90deg, transparent, #000 18px, #000 calc(100% - 18px), transparent);
    mask-image: linear-gradient(90deg, transparent, #000 18px, #000 calc(100% - 18px), transparent);
  }
  .hud__nav::-webkit-scrollbar { display: none; }
  .hud__nav button { flex: 0 0 auto; padding: 8px 11px; font-size: 11px; white-space: nowrap; }
  html[lang="fa"] .hud__nav button { font-size: 12.5px; }
  .hud__nav .lang-switch { order: -1; color: var(--fg); } /* always visible, not scrolled away */
  .hud__inspect { bottom: auto; top: calc(var(--g) + 100px); max-width: calc(100vw - 2 * var(--g)); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  /* below the nav and the inspect button */
  .toast { top: calc(var(--g) + 160px); width: min(86vw, 420px); line-height: 1.6; }
  .hud__place { display: none; }
  body.mode-lab .hud__nav { top: calc(var(--g) * .6); }
  .hud__bl, .hud__leave { display: none; }
  .panel { top: auto; bottom: calc(var(--g) + 60px); max-height: 60vh; }
  .lab { left: 10px; right: 10px; width: auto; top: auto; bottom: 170px; height: 42vh; }
  .timeline { left: 10px; right: 10px; bottom: 10px; }
  .tl-bar .hint { display: none; } /* double-click / right-click don't exist on touch */
}
@media (max-width: 760px) and (max-height: 760px) {
  .lab { height: 34vh; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
