/*
 * Nilakan design system: components for static pages (the site and the docs).
 *
 * Each component reads tokens only. The playground's React components in src/components use the
 * same tokens through tailwind.css, so palette and typography changes reach every surface.
 */

/* Wordmark: the logo with the name in Latin and Malayalam, stacked like a two-script seal. */

.nlk-wordmark {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  color: inherit;
  text-decoration: none;
}

.nlk-wordmark img {
  inline-size: 2.25rem;
  block-size: 2.25rem;
  border-radius: 0.55rem;
}

.nlk-wordmark-names {
  display: grid;
  gap: 0.2em;
  line-height: 1;
}

.nlk-wordmark-latin {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: var(--display-weight);
  letter-spacing: var(--display-tracking);
}

.nlk-wordmark-script {
  font-family: var(--font-malayalam);
  font-size: var(--text-xs);
}

/* Brand surface: the logo's blue, with a light screen-print grain. */

.nlk-brand {
  position: relative;
  isolation: isolate;
  background: var(--brand);
  color: var(--brand-foreground);
  --ring: var(--brand-foreground);
}

.nlk-brand::before {
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: inherit;
  background-image: var(--grain);
  opacity: 0.16;
  pointer-events: none;
  content: "";
}

/* Buttons */

.nlk-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-block-size: 2.75rem;
  padding: 0 var(--space-6);
  border: 1.5px solid transparent;
  border-radius: var(--radius-pill);
  font: inherit;
  font-size: var(--text-base);
  font-weight: 650;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition:
    background-color var(--duration-fast) ease,
    border-color var(--duration-fast) ease,
    transform var(--duration-fast) var(--ease-out),
    box-shadow var(--duration-fast) ease;
}

.nlk-button:hover {
  transform: translateY(-1px);
}

.nlk-button:active {
  transform: translateY(0);
}

.nlk-button--primary {
  background: var(--primary);
  color: var(--primary-foreground);
}

.nlk-button--primary:hover {
  box-shadow: var(--shadow-md);
}

.nlk-button--secondary {
  border-color: var(--input);
  background: transparent;
  color: var(--foreground);
}

.nlk-button--secondary:hover {
  border-color: var(--primary);
}

.nlk-button--small {
  min-block-size: 2.25rem;
  padding: 0 var(--space-4);
  font-size: var(--text-sm);
}

.nlk-brand .nlk-button--primary {
  background: var(--brand-foreground);
  color: var(--brand);
}

.nlk-brand .nlk-button--secondary {
  border-color: var(--brand-border);
  color: var(--brand-foreground);
}

.nlk-brand .nlk-button--secondary:hover {
  border-color: var(--brand-foreground);
}

/* Links */

.nlk-link {
  color: var(--primary);
  font-weight: 600;
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, currentColor 35%, transparent);
  text-decoration-thickness: 1.5px;
  text-underline-offset: 0.25em;
}

.nlk-link:hover {
  text-decoration-color: currentColor;
}

.nlk-brand .nlk-link {
  color: var(--brand-foreground);
}

/* Next-state names print whole in brass, with a bold prime. */

.nlk-next {
  color: var(--prime);
}

.nlk-prime {
  color: var(--prime);
  font-weight: 700;
}

.nlk-brand :is(.nlk-next, .nlk-prime) {
  color: var(--brand-accent);
}

/* Wide code and tables scroll sideways. Phones may never draw a scrollbar, so a soft shadow marks
   each edge with more content past it. The two covers scroll with the content and hide a shadow
   once its edge is reached, so short content shows none, and no script has to measure anything.
   A panel on another surface says so with --scroll-surface. */

.nlk-code,
.nlk-trace-scroll,
.nlk-diagnostic {
  --scroll-shadow: color-mix(in srgb, var(--foreground) 12%, transparent);
  /* Covers stop at the scrollbar and can round short of the top, so the shadow stops before both. */
  --scroll-shadow-height: calc(100% - 0.875rem);
  background:
    linear-gradient(to right, var(--scroll-surface, var(--card)) 40%, transparent) left / 2.5rem
      100% repeat-y local,
    linear-gradient(to left, var(--scroll-surface, var(--card)) 40%, transparent) right / 2.5rem
      100% repeat-y local,
    linear-gradient(to right, var(--scroll-shadow), transparent) left top 2px / 1rem
      var(--scroll-shadow-height) no-repeat,
    linear-gradient(to left, var(--scroll-shadow), transparent) right top 2px / 1rem
      var(--scroll-shadow-height) no-repeat,
    var(--scroll-surface, var(--card));
}

:root[data-theme="dark"] :is(.nlk-code, .nlk-trace-scroll, .nlk-diagnostic) {
  --scroll-shadow: color-mix(in srgb, black 35%, transparent);
}

/* Inline code, either marked up directly or inside running prose. */

.nlk-inline-code,
.nlk-prose :where(p, li, td, th, figcaption, dd) > code {
  padding: 0.1em 0.4em;
  border-radius: var(--radius-sm);
  background: var(--card);
  font-family: var(--font-mono);
  font-size: 0.88em;
}

.nlk-brand :is(.nlk-inline-code, p > code) {
  background: color-mix(in srgb, var(--brand-foreground) 14%, transparent);
}

/* Inline code highlighted by the site renderer takes the code panels' inks. On the brand blue
   it stays white, with primes in brass. */
.nlk-inline-code span {
  color: var(--shiki-light);
  font-style: var(--shiki-light-font-style);
}

:where(:root[data-theme="dark"]) .nlk-inline-code span {
  color: var(--shiki-dark);
  font-style: var(--shiki-dark-font-style);
}

.nlk-inline-code :is(.nlk-next, .nlk-prime) {
  color: var(--prime);
}

.nlk-brand .nlk-inline-code span {
  color: inherit;
}

.nlk-brand .nlk-inline-code :is(.nlk-next, .nlk-prime) {
  color: var(--brand-accent);
}

/* Code panels hold highlighted Nilakan from the site renderer or Expressive Code. */

.nlk-code {
  min-inline-size: 0;
  overflow-x: auto;
  padding: var(--space-5) var(--space-6);
  border-radius: var(--radius-lg);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  line-height: 1.75;
  tab-size: 4;
}

.nlk-code pre {
  margin: 0;
  background: none !important;
  font: inherit;
}

.nlk-code pre code {
  font: inherit;
}

/* :where keeps the light/dark switch below the prime rule, which must always win. */
.nlk-code :where(pre.shiki span) {
  color: var(--shiki-light);
  font-style: var(--shiki-light-font-style);
  font-weight: var(--shiki-light-font-weight);
}

:root[data-theme="dark"] .nlk-code :where(pre.shiki span) {
  color: var(--shiki-dark);
  font-style: var(--shiki-dark-font-style);
  font-weight: var(--shiki-dark-font-weight);
}

.nlk-code pre.shiki .nlk-next {
  color: var(--prime);
}

.nlk-code pre.shiki .nlk-prime {
  color: var(--prime);
  font-weight: 700;
}

/* Code in another language, set beside Nilakan for comparison: the same inks, on a ruled edge
   instead of a card, so the two read apart at a glance. */

.nlk-code--other {
  --scroll-surface: var(--background);
  border: 1.5px dashed var(--input);
}

/* A teacher's red-pen marks: a ring around a wrong value and a note in the margin. */

.nlk-circled {
  position: relative;
  display: inline-block;
  margin: 0 -0.45em;
  padding: 0 0.45em;
  color: var(--destructive);
}

.nlk-circled::after {
  position: absolute;
  inset: 0;
  background: currentColor;
  -webkit-mask: var(--art-ring) center / 100% 100% no-repeat;
  mask: var(--art-ring) center / 100% 100% no-repeat;
  pointer-events: none;
  content: "";
}

.nlk-margin-note {
  color: var(--destructive);
  font-family: var(--font-hand);
  font-size: var(--text-md);
  line-height: var(--leading-snug);
}

/* Trace tables: one row per round. */

.nlk-trace-scroll {
  --scroll-surface: var(--background);
  min-inline-size: 0;
  overflow-x: auto;
}

.nlk-trace {
  inline-size: 100%;
  border-collapse: collapse;
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.nlk-trace th,
.nlk-trace td {
  padding: var(--space-2) var(--space-3);
  text-align: end;
  vertical-align: middle;
}

.nlk-trace th:first-child {
  padding-inline-start: 0;
  text-align: start;
}

.nlk-trace thead th {
  color: var(--muted-foreground);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: 500;
  vertical-align: bottom;
}

.nlk-trace thead code {
  padding: 0;
  background: none;
  color: var(--foreground);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
}

.nlk-trace thead tr.group th:not(:empty) {
  border-block-end: 1.5px dotted var(--input);
}

.nlk-trace thead tr.group th {
  padding-block: var(--space-1);
  text-align: start;
  font-size: var(--text-xs);
}

.nlk-trace .center {
  text-align: center;
}

.nlk-trace tbody tr > * {
  border-block-start: 1px solid var(--border);
}

.nlk-trace tbody th {
  color: var(--muted-foreground);
  font-family: var(--font-sans);
  font-weight: 500;
}

.nlk-trace .cond {
  color: var(--success);
  font-weight: 700;
  text-align: center;
}

.nlk-trace tr.exit > * {
  border-block-start: 1.5px solid var(--foreground);
  font-weight: 700;
}

.nlk-trace tr.exit th {
  color: var(--foreground);
}

.nlk-trace tr.exit .cond {
  color: var(--destructive);
}

.nlk-trace .temp,
.nlk-trace thead .temp code {
  color: var(--info);
}

/* The rounds print in order, and each new row's values arrive in the prime ink. */
@media (prefers-reduced-motion: no-preference) {
  .nlk-trace[data-animate] tbody tr {
    animation: nlk-print-row 280ms ease-out both;
    animation-delay: calc(400ms + var(--row, 0) * 220ms);
  }

  .nlk-trace[data-animate] tbody td:not(.cond) {
    animation: nlk-settle-value 900ms ease-in both;
    animation-delay: calc(400ms + var(--row, 0) * 220ms);
  }
}

@keyframes nlk-print-row {
  from {
    opacity: 0;
  }
}

@keyframes nlk-settle-value {
  from {
    color: var(--prime);
  }
}

/* Diagnostics, as Nilakan prints them. */

.nlk-diagnostic {
  margin: 0;
  overflow-x: auto;
  padding: var(--space-5) var(--space-6);
  border-radius: var(--radius-lg);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  line-height: 1.7;
  white-space: pre-wrap;
}

.nlk-diagnostic .severity {
  color: var(--destructive);
  font-weight: 700;
}

.nlk-diagnostic .message {
  font-weight: 700;
}

.nlk-diagnostic .gutter,
.nlk-diagnostic .location {
  color: var(--muted-foreground);
}

.nlk-diagnostic .caret {
  color: var(--destructive);
  font-weight: 700;
}

.nlk-diagnostic .help {
  color: var(--success);
  font-weight: 700;
}

/* The planetary illustration generated by scripts/art.mjs. */

.nlk-art {
  aspect-ratio: 1;
  background: var(--art-hero) center / contain no-repeat;
}

.nlk-mark {
  display: inline-block;
  inline-size: 1.25em;
  block-size: 1.25em;
  background: currentColor;
  -webkit-mask: var(--art-mark) center / contain no-repeat;
  mask: var(--art-mark) center / contain no-repeat;
  vertical-align: -0.2em;
}

/* Section divider: a kolam line looping around dots. */

.nlk-divider {
  block-size: 1.5rem;
  background: color-mix(in srgb, var(--primary) 45%, var(--background));
  -webkit-mask: var(--art-divider) repeat-x center / auto 100%;
  mask: var(--art-divider) repeat-x center / auto 100%;
}

.nlk-brand .nlk-divider {
  background: color-mix(in srgb, var(--brand-foreground) 55%, var(--brand));
}

@media (prefers-reduced-motion: reduce) {
  .nlk-button {
    transition: none;
  }

  .nlk-button:hover {
    transform: none;
  }
}
