/* Interactive features: progress bar, motion, colophon, palette, inspect, toast. */

body { overflow-x: clip; }

/* ---------- Header additions ---------- */
.palette-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  height: 40px;
  padding-inline: 0.85rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
}
.palette-btn:hover { border-color: var(--accent); color: var(--text); }
.palette-btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }

kbd, .kbd-hint {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  direction: ltr;
}

.inspect-btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* Native CSS scroll-driven animation; hidden where unsupported. */
.scroll-progress {
  position: absolute;
  inset-inline: 0;
  bottom: -1px;
  height: 2px;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left;
  display: none;
}
[dir="rtl"] .scroll-progress { transform-origin: right; }
@supports (animation-timeline: scroll()) {
  .scroll-progress { display: block; animation: progress linear both; animation-timeline: scroll(root); }
}
@keyframes progress { to { transform: scaleX(1); } }

/* ---------- Hero motion ---------- */
.hero { position: relative; isolation: isolate; }
.hero::before {
  content: "";
  position: absolute;
  inset-block: 0;
  inset-inline: calc(50% - 50vw);
  z-index: -1;
  pointer-events: none;
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 56px 56px;
  mask-image: radial-gradient(ellipse 70% 60% at 50% 45%, #000 25%, transparent 75%);
}

.hero-name .word {
  display: inline-block;
  animation: word-in 1s var(--ease) both;
  animation-delay: calc(var(--i) * 110ms + 80ms);
}
@keyframes word-in {
  from { opacity: 0; transform: translateY(0.35em); filter: blur(10px); }
}

.hero-text > :not(.hero-name) { animation: fade-up 0.9s var(--ease) backwards; }
.hero-text > :nth-child(1) { animation-delay: 0ms; }
.hero-text > :nth-child(3) { animation-delay: 380ms; }
.hero-text > :nth-child(4) { animation-delay: 460ms; }
.hero-text > :nth-child(5) { animation-delay: 540ms; }
.hero-text > :nth-child(6) { animation-delay: 620ms; }
.portrait { animation: fade-up 1.1s var(--ease) 150ms backwards; }
@keyframes fade-up { from { opacity: 0; transform: translateY(16px); } }

.magnetic { transition: translate 0.35s var(--ease), transform 0.2s var(--ease), background-color 0.2s, border-color 0.2s; }
.tilt { transition: transform 0.5s var(--ease); will-change: transform; }

/* ---------- Cursor spotlight ---------- */
.spot { position: relative; overflow: hidden; isolation: isolate; }
.spot::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: inherit;
  pointer-events: none;
  background: radial-gradient(420px circle at var(--mx, 50%) var(--my, 50%),
    color-mix(in srgb, var(--accent) 14%, transparent), transparent 65%);
  opacity: 0;
  transition: opacity 0.35s;
}
.spot:hover::after { opacity: 1; }

/* ---------- Colophon ---------- */
.colophon-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--space-4); }

.panel {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-5);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.panel h3 { font-weight: 500; }

.code {
  margin: 0;
  padding: var(--space-4);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 0.95rem;
  line-height: 1.8;
  text-align: left;
  overflow-x: auto;
}
.tok-sel { color: var(--text); }
.tok-prop { color: var(--muted); }
.tok-val { color: var(--accent); border-radius: 4px; padding-inline: 2px; }
.tok-val.flash { animation: flash 0.8s var(--ease); }
@keyframes flash { from { background: color-mix(in srgb, var(--accent) 35%, transparent); } }

.swatches { display: flex; flex-wrap: wrap; gap: var(--space-3); }
.swatch {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 0;
  background: var(--swatch);
  cursor: pointer;
  transition: transform 0.25s var(--ease), box-shadow 0.25s;
}
.swatch:hover { transform: scale(1.12); }
.swatch[aria-checked="true"] { box-shadow: 0 0 0 3px var(--surface), 0 0 0 5px var(--swatch); }

.metrics { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--space-3) var(--space-4); margin: 0; }
.metric { border-block-start: 1px dashed var(--border); padding-block-start: var(--space-3); }
.metric dt { font-size: var(--step--1); }
.metric dd {
  margin: 0;
  font-family: var(--font-mono);
  font-size: var(--step-2);
  font-weight: 500;
  color: var(--text);
  text-align: start;
}
.metric-unit { font-size: var(--step--1); color: var(--accent); margin-inline-start: 0.3em; }
:lang(ar) .metric dd { text-align: right; }
.metrics-note { margin-block-start: auto; }

.tech-list li {
  position: relative;
  padding-block: 0.45rem;
  padding-inline-start: 1.2rem;
  border-block-end: 1px dashed var(--border);
}
.tech-list li:last-child { border-block-end: 0; }
.tech-list li::before {
  content: "";
  position: absolute;
  inset-inline-start: 0;
  top: 1.05em;
  width: 6px;
  height: 6px;
  background: var(--accent);
  rotate: 45deg;
}

.shortcut-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-3);
  padding-block: 0.6rem;
  border-block-end: 1px dashed var(--border);
}
.shortcut-list li:last-child { border-block-end: 0; }
.keys { display: inline-flex; gap: 4px; }
.keys kbd {
  min-width: 2em;
  padding: 0.15rem 0.5rem;
  text-align: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-block-end-width: 2px;
  border-radius: 6px;
}

/* ---------- Command palette ---------- */
.palette {
  width: min(560px, 100% - 2rem);
  max-height: 70vh;
  margin: 12vh auto auto;
  padding: 0;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 30px 80px -20px rgb(0 0 0 / 0.55);
}
.palette[open] { animation: palette-in 0.25s var(--ease); }
.palette::backdrop { background: rgb(0 0 0 / 0.45); backdrop-filter: blur(4px); }
@keyframes palette-in { from { opacity: 0; transform: translateY(-8px) scale(0.98); } }

.palette-box { display: flex; flex-direction: column; max-height: 70vh; }
.palette-search {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-block-end: 1px solid var(--border);
}
.palette-search svg { width: 18px; height: 18px; flex: none; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; }
.palette-search input {
  flex: 1;
  min-width: 0;
  padding-block: 0.5rem;
  font: inherit;
  font-size: var(--step-1);
  color: var(--text);
  background: transparent;
  border: 0;
  outline: none;
}
.palette-list {
  overflow-y: auto;
  padding: var(--space-2);
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.palette-group { padding: 0.6rem 0.8rem 0.3rem; color: var(--muted); }
.palette-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0.6rem 0.8rem;
  border-radius: 10px;
  cursor: pointer;
  border-inline-start: 2px solid transparent;
}
.palette-item[aria-selected="true"] { background: var(--surface-2); border-inline-start-color: var(--accent); }
.palette-swatch { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.palette-empty { padding: var(--space-4); text-align: center; }
.palette-foot { padding: var(--space-2) var(--space-4); color: var(--muted); border-block-start: 1px solid var(--border); }

/* ---------- Inspect overlay ---------- */
.is-inspecting, .is-inspecting * { cursor: crosshair !important; }
.inspect-box {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 90;
  pointer-events: none;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  outline: 1px solid var(--accent);
  transition: transform 0.08s linear, width 0.08s linear, height 0.08s linear;
}
.inspect-pad {
  position: absolute;
  inset: 0;
  border-style: solid;
  border-color: rgb(147 196 125 / 0.35);
}
.inspect-label {
  position: absolute;
  bottom: calc(100% + 4px);
  left: 0;
  direction: ltr;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  white-space: nowrap;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 0.75rem;
}
.inspect-box.label-below .inspect-label { bottom: auto; top: calc(100% + 4px); }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  z-index: 95;
  max-width: calc(100% - 2rem);
  padding: 0.6rem 1.1rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: 0 12px 30px -10px rgb(0 0 0 / 0.4);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition: opacity 0.3s var(--ease), transform 0.3s var(--ease);
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Responsive / input type ---------- */
@media (hover: none) {
  .inspect-btn, .kbd-hint { display: none; }
  .palette-btn { width: 40px; justify-content: center; padding: 0; }
}

@media (max-width: 860px) {
  .colophon-grid { grid-template-columns: 1fr; }
}
