/* ==========================================================================
   Kristjan Kongas — personal site
   Design tokens, layout primitives and components. No build step: plain CSS.

   Restrained on purpose: one accent colour, reserved for things you can click.
   Structure comes from spacing and hairlines rather than shadows or gradients.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Tokens
   -------------------------------------------------------------------------- */

:root {
  color-scheme: light dark;

  /* Light palette (default) */
  --bg: #fdfdfc;
  --bg-soft: #f5f5f3;
  --surface: #ffffff;
  --surface-2: #f2f2f0;
  --border: #e2e2dd;
  --border-strong: #c6c6bf;
  --text: #1a1a18;
  --text-soft: #40403c;
  --muted: #6a6a63;
  --accent: #2f4fb5;
  --accent-soft: #eceffa;
  --shadow-sm: 0 1px 2px rgba(26, 26, 24, 0.05);
  --code-bg: #1a1c20;
  --code-text: #d8dbe0;

  /* Scale */
  --wrap: 1060px;
  --wrap-narrow: 720px;
  --radius-sm: 5px;
  --radius: 8px;
  --gutter: clamp(1.15rem, 4vw, 2.25rem);

  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
    "Liberation Mono", monospace;

  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
}

:root[data-theme="dark"] {
  color-scheme: dark;

  --bg: #14151a;
  --bg-soft: #191a20;
  --surface: #1d1f26;
  --surface-2: #23252d;
  --border: #2f323b;
  --border-strong: #454a57;
  --text: #e7e7e4;
  --text-soft: #c2c3c0;
  --muted: #8e908d;
  --accent: #93aaf0;
  --accent-soft: #22273a;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
  --code-bg: #101116;
  --code-text: #d8dbe0;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;

    --bg: #14151a;
    --bg-soft: #191a20;
    --surface: #1d1f26;
    --surface-2: #23252d;
    --border: #2f323b;
    --border-strong: #454a57;
    --text: #e7e7e4;
    --text-soft: #c2c3c0;
    --muted: #8e908d;
    --accent: #93aaf0;
    --accent-soft: #22273a;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
    --code-bg: #101116;
    --code-text: #d8dbe0;
  }
}

/* --------------------------------------------------------------------------
   2. Base
   -------------------------------------------------------------------------- */

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: 5rem;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 1.0625rem;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 {
  margin: 0 0 0.6em;
  line-height: 1.25;
  letter-spacing: -0.015em;
  font-weight: 600;
  text-wrap: balance;
}

h1 { font-size: clamp(1.8rem, 1.4rem + 1.6vw, 2.4rem); }
h2 { font-size: clamp(1.35rem, 1.2rem + 0.8vw, 1.7rem); }
h3 { font-size: clamp(1.1rem, 1.02rem + 0.4vw, 1.25rem); }

p { margin: 0 0 1.1em; }

a {
  color: var(--accent);
  text-decoration-color: color-mix(in srgb, var(--accent) 35%, transparent);
  text-underline-offset: 3px;
}

a:hover { text-decoration-color: currentColor; }

img, video, canvas { max-width: 100%; height: auto; display: block; }

code, pre, kbd { font-family: var(--font-mono); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 3px;
}

::selection {
  background: color-mix(in srgb, var(--accent) 22%, transparent);
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 100;
  padding: 0.7rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0 0 var(--radius-sm) 0;
}

.skip-link:focus { left: 0; }

/* --------------------------------------------------------------------------
   3. Layout primitives
   -------------------------------------------------------------------------- */

.wrap {
  width: 100%;
  max-width: var(--wrap);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

.wrap--narrow { max-width: var(--wrap-narrow); }

.section {
  padding-block: clamp(2.75rem, 5vw, 4.5rem);
  position: relative;
}

.section--soft {
  background: var(--bg-soft);
  border-block: 1px solid var(--border);
}

.section__head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.4rem 1.25rem;
  margin-bottom: clamp(1.75rem, 3vw, 2.5rem);
}

.section__head h2 { margin: 0; }

.section__note {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.eyebrow {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin: 0 0 0.9rem;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.icon { width: 1.15em; height: 1.15em; flex: none; }
.icon--sm { width: 0.95em; height: 0.95em; }

/* --------------------------------------------------------------------------
   4. Header
   -------------------------------------------------------------------------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.site-header__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 3.75rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--text);
  font-weight: 600;
  letter-spacing: -0.01em;
  text-decoration: none;
}

.brand__mark {
  display: grid;
  place-items: center;
  width: 1.9rem;
  height: 1.9rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text-soft);
  font-size: 0.7rem;
  font-weight: 650;
  letter-spacing: 0.02em;
}

.nav {
  display: flex;
  align-items: center;
  gap: clamp(0.35rem, 1.6vw, 1.1rem);
}

.nav__link {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.35rem 0.5rem;
  border-radius: var(--radius-sm);
  color: var(--text-soft);
  font-size: 0.92rem;
  font-weight: 500;
  text-decoration: none;
  transition: color 0.15s var(--ease);
}

.nav__link:hover { color: var(--accent); }

.theme-toggle {
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  margin-left: 0.15rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  transition: color 0.15s var(--ease), border-color 0.15s var(--ease);
}

.theme-toggle:hover {
  color: var(--text);
  border-color: var(--border-strong);
}

.theme-toggle .icon { width: 1rem; height: 1rem; }
.theme-toggle .icon--moon { display: none; }

:root[data-theme="dark"] .theme-toggle .icon--sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon--moon { display: block; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .icon--sun { display: none; }
  :root:not([data-theme="light"]) .theme-toggle .icon--moon { display: block; }
}

@media (max-width: 34rem) {
  .brand__name { display: none; }
  .nav__link--external span { display: none; }
}

/* --------------------------------------------------------------------------
   5. Intro
   -------------------------------------------------------------------------- */

.hero {
  padding-block: clamp(2.75rem, 6vw, 4.5rem) clamp(2.25rem, 4vw, 3.25rem);
}

.hero__inner { max-width: 42rem; }

.hero__title {
  margin-bottom: 0.5em;
  font-size: clamp(1.9rem, 1.4rem + 2vw, 2.75rem);
  font-weight: 650;
  letter-spacing: -0.02em;
}

.hero__lede {
  margin-bottom: 0;
  max-width: 38rem;
  font-size: clamp(1rem, 0.97rem + 0.2vw, 1.12rem);
  color: var(--text-soft);
  line-height: 1.65;
}

.hero__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 1.75rem;
}

.hero__facts {
  max-width: 38rem;
  margin: 1.5rem 0 0;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.9rem;
}

/* --------------------------------------------------------------------------
   6. Buttons & links
   -------------------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 1rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 0.94rem;
  font-weight: 550;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s var(--ease), border-color 0.15s var(--ease);
}

.btn--primary {
  background: var(--accent);
  color: #fff;
}

.btn--primary:hover {
  background: color-mix(in srgb, var(--accent) 88%, #000);
}

:root[data-theme="dark"] .btn--primary { color: #14151a; }
:root[data-theme="dark"] .btn--primary:hover {
  background: color-mix(in srgb, var(--accent) 88%, #fff);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .btn--primary { color: #14151a; }
  :root:not([data-theme="light"]) .btn--primary:hover {
    background: color-mix(in srgb, var(--accent) 88%, #fff);
  }
}

.btn--ghost {
  background: var(--surface);
  border-color: var(--border-strong);
  color: var(--text);
}

.btn--ghost:hover { background: var(--surface-2); }

.link-arrow {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.92rem;
  font-weight: 540;
  text-decoration: none;
  color: var(--accent);
}

.link-arrow:hover { text-decoration: underline; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.1rem 0.45rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
  white-space: nowrap;
}

.chip--sm { font-size: 0.72rem; }

/* --------------------------------------------------------------------------
   7. Projects
   -------------------------------------------------------------------------- */

.projects {
  display: grid;
  gap: clamp(2.25rem, 4vw, 3.25rem);
}

/* Text left, demo right — the same way round every time. */
.project {
  display: grid;
  gap: clamp(1.25rem, 3vw, 2.5rem);
  align-items: start;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.project + .project {
  padding-top: clamp(2.25rem, 4vw, 3.25rem);
  border-top: 1px solid var(--border);
}

@media (max-width: 60rem) {
  .project { grid-template-columns: minmax(0, 1fr); }
}

.project__body { min-width: 0; }

.project__title {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin-bottom: 0.4em;
}

.project__title a {
  color: var(--text);
  text-decoration: none;
}

.project__title a:hover { color: var(--accent); }

.project__logo {
  width: 1.5rem;
  height: 1.5rem;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
}

.project__tagline {
  margin-bottom: 0.85em;
  color: var(--text-soft);
  font-size: 1rem;
}

.project__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 1rem;
}

.project__list {
  margin: 0 0 1.25rem;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 0.5rem;
  color: var(--text-soft);
  font-size: 0.96rem;
}

.project__list li {
  display: grid;
  grid-template-columns: 1.1rem 1fr;
  gap: 0.5rem;
  align-items: start;
}

.project__list .icon {
  margin-top: 0.45em;
  color: var(--muted);
}

.project__links {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1.25rem;
}

/* Media frame ------------------------------------------------------------- */

.media {
  position: relative;
  margin: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.media__frame {
  position: relative;
  display: block;
  aspect-ratio: 16 / 10;
  background: var(--code-bg);
}

.media__frame > img,
.media__frame > video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.media__caption {
  margin: 0;
  padding: 0.6rem 0.85rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.45;
}

.media__play {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border: 0;
  padding: 0;
  background: rgba(10, 12, 16, 0.3);
  color: #fff;
  cursor: pointer;
  transition: opacity 0.2s var(--ease), background 0.2s var(--ease);
}

.media__play:hover { background: rgba(10, 12, 16, 0.42); }

.media__play span {
  display: grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 50%;
  background: rgba(16, 18, 24, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.55);
}

.media__play svg { width: 1.15rem; height: 1.15rem; margin-left: 2px; }

.media.is-playing .media__play { opacity: 0; pointer-events: none; }

/* Terminal card ----------------------------------------------------------- */

.terminal {
  background: var(--code-bg);
  color: var(--code-text);
  font-size: clamp(0.72rem, 0.6rem + 0.4vw, 0.83rem);
  line-height: 1.65;
}

.terminal__bar {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.55rem 0.85rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.09);
}

.terminal__dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: #4a4f5c;
}

.terminal__name {
  margin-left: 0.4rem;
  color: #8b8f9a;
  font-family: var(--font-mono);
  font-size: 0.78em;
}

.terminal pre {
  margin: 0;
  padding: 1rem 1.1rem;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: inherit;
  line-height: inherit;
  tab-size: 4;
}

.terminal pre + pre {
  border-top: 1px solid rgba(255, 255, 255, 0.09);
}

.tok-key { color: #c9a0e6; }
.tok-type { color: #8fc4e8; }
.tok-fn { color: #e8c88a; }
.tok-str { color: #a8cf95; }
.tok-num { color: #e0a284; }
.tok-com { color: #7a8090; }
.tok-pre { color: #8fcdbb; }
.tok-out { color: #a9adb8; }
.tok-prompt { color: #7fb3c8; }

/* --------------------------------------------------------------------------
   8. Writing
   -------------------------------------------------------------------------- */

.post-list {
  display: grid;
  gap: 0;
  margin: 0;
  padding: 0;
  list-style: none;
  border-top: 1px solid var(--border);
}

.post-card {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.25rem 1.25rem;
  padding: 1.1rem 0.25rem;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
  color: inherit;
}

.post-card:hover .post-card__title { color: var(--accent); }

.post-card__date {
  color: var(--muted);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
  min-width: 7rem;
}

.post-card__title {
  margin: 0;
  font-size: 1.08rem;
  font-weight: 600;
}

.post-card__desc {
  flex-basis: 100%;
  margin: 0.2rem 0 0;
  padding-left: 8.25rem;
  color: var(--muted);
  font-size: 0.92rem;
}

@media (max-width: 34rem) {
  .post-card__desc { padding-left: 0; }
}

.post-card__go {
  margin-left: auto;
  color: var(--muted);
}

.post-card:hover .post-card__go { color: var(--accent); }

/* --------------------------------------------------------------------------
   9. Post / prose
   -------------------------------------------------------------------------- */

.page--post main,
.page-body { padding-block: clamp(2.25rem, 4vw, 3.25rem) clamp(2.75rem, 5vw, 4rem); }

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin-bottom: 1.5rem;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 500;
  text-decoration: none;
}

.back-link:hover { color: var(--accent); }

.post__header { margin-bottom: 2.25rem; }

.post__title { margin-bottom: 0.4em; }

.post__lede {
  margin: 0;
  color: var(--text-soft);
  font-size: 1.1rem;
}

.prose { font-size: 1.0625rem; }

.prose > * + * { margin-top: 1.15em; }

.prose h2 { margin-top: 2em; }
.prose h3 { margin-top: 1.6em; }

.prose ul, .prose ol { padding-left: 1.3em; }
.prose li + li { margin-top: 0.35em; }

.prose blockquote {
  margin-inline: 0;
  padding: 0.4rem 0 0.4rem 1.15rem;
  border-left: 3px solid var(--border-strong);
  color: var(--text-soft);
}

.prose code {
  padding: 0.15em 0.4em;
  border-radius: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 0.9em;
}

.prose pre {
  padding: 1rem 1.1rem;
  overflow-x: auto;
  border-radius: var(--radius);
  background: var(--code-bg);
  color: var(--code-text);
  font-size: 0.9rem;
  line-height: 1.6;
}

.prose pre code {
  padding: 0;
  border: 0;
  background: none;
  font-size: inherit;
  color: inherit;
}

.prose hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin-block: 2.5em;
}

.prose img { border-radius: var(--radius); }

/* Interactive demo canvas (Phase Transition) */
.demo {
  margin-block: 1.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--code-bg);
}

.demo canvas {
  display: block;
  width: 100%;
  height: auto;
  background: #000;
  touch-action: none;
}

.demo__hint {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1.25rem;
  margin: 0;
  padding: 0.65rem 0.85rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-size: 0.82rem;
}

kbd {
  display: inline-block;
  min-width: 1.5em;
  padding: 0.05em 0.4em;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.85em;
  text-align: center;
}

/* --------------------------------------------------------------------------
   10. Footer
   -------------------------------------------------------------------------- */

.site-footer {
  margin-top: clamp(2.5rem, 5vw, 4rem);
  padding-top: clamp(2rem, 4vw, 2.75rem);
  border-top: 1px solid var(--border);
  background: var(--bg-soft);
  font-size: 0.9rem;
}

.site-footer__inner {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 1.25rem 2.5rem;
  padding-bottom: 1.75rem;
}

.site-footer__name { margin: 0; font-weight: 600; }

.site-footer__tagline { margin: 0.15rem 0 0; color: var(--muted); }

.site-footer__links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.25rem;
}

.site-footer__links a {
  color: var(--text-soft);
  text-decoration: none;
}

.site-footer__links a:hover { color: var(--accent); }

.site-footer__meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.35rem 2rem;
  padding-block: 1rem;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.84rem;
}

.site-footer__meta p { margin: 0; }

/* --------------------------------------------------------------------------
   11. Motion
   -------------------------------------------------------------------------- */

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

  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
