/* ==========================================================================
   Color tokens (light = default, dark via [data-theme="dark"])
   ========================================================================== */

:root {
  color-scheme: light;

  /* Background */
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-hover: #f1f5f9;
  --surface-active: #e2e8f0;

  /* Typography */
  --fg: #0f172a;
  --muted: #64748b;
  --subtle: #94a3b8;

  /* Accent */
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-foreground: #ffffff;

  /* Borders */
  --border: #e2e8f0;
  --border-strong: #cbd5e1;

  /* Status */
  --success: #15803d;
  --warning: #a16207;
  --danger: #dc2626;
  --info: #0284c7;

  /* Interaction */
  --focus-ring: #3b82f6;
  --selection: #bfdbfe;

  /* Layout (non-color) */
  --max-width: 820px;
  --canvas-width: 1180px;
  --cv-width: 320px;
  --gutter: 16px;
  --radius: 10px;
  --radius-sm: 6px;
  --header-height: 84px;
  --transition: 150ms ease;
}

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

  /* Background */
  --bg: #0f1117;
  --surface: #181c25;
  --surface-hover: #222938;
  --surface-active: #293244;

  /* Typography */
  --fg: #f1f5f9;
  --muted: #94a3b8;
  --subtle: #64748b;

  /* Accent */
  --accent: #60a5fa;
  --accent-hover: #93c5fd;
  --accent-foreground: #0f172a;

  /* Borders */
  --border: #293244;
  --border-strong: #475569;

  /* Status */
  --success: #4ade80;
  --warning: #facc15;
  --danger: #f87171;
  --info: #38bdf8;

  /* Interaction */
  --focus-ring: #60a5fa;
  --selection: #1e40af;
}

/* ==========================================================================
   Base
   ========================================================================== */

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

html {
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--header-height) + 16px);
}

body {
  margin: 0;
  background-color: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  transition: background-color var(--transition), color var(--transition);
}

::selection {
  background-color: var(--selection);
  color: var(--fg);
}

h1,
h2,
h3 {
  line-height: 1.2;
  margin: 0 0 12px;
  color: var(--fg);
}

p {
  margin: 0 0 12px;
}

a {
  color: var(--accent);
  text-decoration: none;
  transition: color var(--transition);
}

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

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

button {
  font: inherit;
  cursor: pointer;
}

/* ==========================================================================
   Header
   ========================================================================== */

.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  min-height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding: 10px max(var(--gutter), calc((100% - var(--canvas-width)) / 2 + var(--gutter)));
  background-color: var(--surface);
  border-bottom: 1px solid var(--border);
}

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

/* ASCII-art logo: monospace + preserved whitespace keeps the letters aligned */
.nav-logo {
  margin: 0 8px 0 0;
  font-family: "JetBrains Mono", ui-monospace, "Cascadia Code", "SFMono-Regular", Menlo, Consolas,
    "Liberation Mono", monospace;
  font-size: 9px;
  line-height: 1.15;
  font-variant-ligatures: none;
  white-space: pre;
  color: var(--fg);
  user-select: none;
}

.nav a {
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-weight: 600;
  transition: background-color var(--transition), color var(--transition);
}

.nav a:hover {
  background-color: var(--surface-hover);
  color: var(--fg);
}

.nav a:active {
  background-color: var(--surface-active);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Language switcher: segmented control */
.lang-switcher {
  display: flex;
  padding: 3px;
  gap: 2px;
  background-color: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.lang-switcher button {
  padding: 4px 10px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  background-color: transparent;
  border: 0;
  border-radius: 4px;
  transition: background-color var(--transition), color var(--transition);
}

.lang-switcher button:hover {
  color: var(--fg);
  background-color: var(--surface-hover);
}

.lang-switcher button[aria-pressed="true"] {
  color: var(--accent-foreground);
  background-color: var(--accent);
}

/* Theme toggle */
.theme-toggle {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  color: var(--fg);
  background-color: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  transition: background-color var(--transition), border-color var(--transition);
}

.theme-toggle:hover {
  background-color: var(--surface-hover);
  border-color: var(--accent);
}

.theme-toggle:active {
  background-color: var(--surface-active);
}

.theme-toggle .icon-sun {
  display: none;
}

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

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

/* ==========================================================================
   Main content
   ========================================================================== */

/* Two-column page: CV on the left, main content on the right */
.canvas {
  display: grid;
  grid-template-columns: var(--cv-width) minmax(0, 1fr);
  align-items: start;
  gap: 32px;
  max-width: var(--canvas-width);
  margin: 0 auto;
  padding: 32px var(--gutter) 48px;
}

main {
  min-width: 0;
  display: grid;
  gap: 20px;
}

/* ==========================================================================
   CV column
   ========================================================================== */

.cv {
  position: sticky;
  top: calc(var(--header-height) + 16px);
  max-height: calc(100vh - var(--header-height) - 32px);
  overflow-y: auto;
  scrollbar-width: thin;
  padding: 24px;
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.92rem;
}

.cv:empty {
  display: none;
}

.cv-profile {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding-bottom: 20px;
}

.cv-avatar {
  width: 100%;
  height: 100%;
  margin-bottom: 12px;
  border-radius: var(--radius);
  border: 1px solid var(--accent);
  object-fit: cover;
}

.cv-avatar--initials {
  display: grid;
  place-items: center;
  font-size: 2rem;
  font-weight: 700;
  color: var(--accent-foreground);
  background-color: var(--accent);
}

.cv-name {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--fg);
}

.cv-title {
  margin: 2px 0 0;
  color: var(--muted);
}

.cv-download {
  margin-top: 14px;
  font-size: 0.9rem;
  padding: 8px 14px;
}

.cv-section {
  padding: 16px 0;
  border-top: 1px solid var(--border);
}

.cv-section:last-child {
  padding-bottom: 0;
}

.cv-section-title {
  margin: 0 0 10px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}

.cv-summary {
  margin: 0;
  color: var(--muted);
}

/* Contact: label / value rows */
.cv-contact {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 6px 12px;
  margin: 0;
}

.cv-contact dt {
  color: var(--subtle);
}

.cv-contact dd {
  margin: 0;
  color: var(--fg);
  overflow-wrap: anywhere;
}

/* Entries (experience, education, …) */
.cv-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 14px;
}

.cv-entry {
  padding-left: 12px;
  border-left: 2px solid var(--border-strong);
}

.cv-entry-title {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
}

.cv-entry-subtitle {
  margin: 0;
  color: var(--muted);
}

.cv-entry-meta {
  margin: 0;
  font-size: 0.82rem;
  color: var(--subtle);
}

.cv-entry-note {
  margin: 4px 0 0;
  color: var(--muted);
}

.cv-bullets {
  margin: 6px 0 0;
  padding-left: 18px;
  color: var(--muted);
}

/* Skills & interests: solid tags */
.cv-skill-group {
  margin: 10px 0 6px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}

.cv-skill-group:first-child {
  margin-top: 0;
}

.cv-chips {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.cv-chip {
  padding: 2px 10px;
  font-size: 0.82rem;
  color: var(--fg);
  background-color: var(--surface-hover);
  border: 1px solid var(--border);
  border-radius: 999px;
}

.hero {
  padding: 16px 0 12px;
}

.hero h1 {
  font-size: clamp(2rem, 6vw, 3rem);
  letter-spacing: -0.02em;
}

.hero h1::after {
  /* solid accent bar under the name */
  content: "";
  display: block;
  width: 56px;
  height: 4px;
  margin-top: 16px;
  background-color: var(--accent);
  border-radius: 2px;
}

.hero p {
  max-width: 60ch;
  font-size: 1.1rem;
  color: var(--muted);
}

/* ==========================================================================
   Terminal windows (markup built by assets/js/terminal.js)
   Palette is mapped to the theme tokens, so it follows light / dark mode.
   ========================================================================== */

.terminal {
  --term-bg: var(--surface);
  --term-bar: var(--surface-hover);
  --term-border: var(--border-strong);
  --term-fg: var(--fg);
  --term-dim: var(--muted);
  --term-green: var(--success);
  --term-blue: var(--accent);
  --term-red: var(--danger);
  --term-cyan: var(--info);
  --term-selection: var(--selection);
  --term-font: "JetBrains Mono", ui-monospace, "Cascadia Code", "SFMono-Regular", Menlo, Consolas,
    "Liberation Mono", monospace;

  overflow: hidden;
  font-family: var(--term-font);
  font-size: 14px;
  line-height: 1.5;
  font-variant-ligatures: none;
  color: var(--term-fg);
  background-color: var(--term-bg);
  border: 1px solid var(--term-border);
  border-radius: var(--radius);
  transition: background-color var(--transition), border-color var(--transition);
}

.terminal ::selection {
  background-color: var(--term-selection);
  color: var(--term-fg);
}

/* Title bar */
.terminal-bar {
  position: relative;
  display: flex;
  align-items: center;
  height: 36px;
  padding: 0 14px;
  background-color: var(--term-bar);
  border-bottom: 1px solid var(--term-border);
  user-select: none;
}

.terminal-title {
  position: absolute;
  inset: 0 48px;
  display: grid;
  place-items: center;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 12.5px;
  color: var(--term-dim);
}

/* Screen */
.terminal-screen {
  padding: 12px 16px 16px;
  overflow-x: auto;
  scrollbar-width: thin;
}

.terminal-screen p {
  margin: 0;
}

.terminal-line {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  column-gap: 1ch;
}

.prompt {
  white-space: nowrap;
  font-weight: 700;
}

.prompt-user {
  color: var(--term-green);
}

.prompt-sep {
  color: var(--term-fg);
}

.prompt-path {
  color: var(--term-blue);
}

.prompt-sign {
  margin-left: 0.15ch;
  color: var(--term-fg);
}

/* The command (each section's <h2>): plain terminal text */
.terminal-line h2 {
  margin: 0;
  font: inherit;
  color: var(--term-fg);
}

/* Command output */
.terminal-output {
  margin-bottom: 0.75em;
  color: var(--term-fg);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.terminal a {
  color: var(--term-cyan);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.terminal a:hover {
  color: var(--term-blue);
}

/* `ls` output: zsh-style directory listing (bold blue + trailing "/"),
   fixed-width columns filled row by row, wrapping when the line is full */
.terminal .ls {
  display: grid;
  grid-template-columns: repeat(auto-fill, min(var(--ls-col, 20ch), 100%));
  margin: 0;
  padding: 0;
  list-style: none;
  white-space: normal;
}

.terminal .ls li {
  min-width: 0;
  white-space: nowrap;
}

.terminal .ls a {
  font-weight: 700;
  color: var(--term-blue);
  text-decoration: none;
}

.terminal .ls a::after {
  content: "/";
}

.terminal .ls a:hover {
  color: var(--term-bg);
  background-color: var(--term-blue);
}

.terminal .ls a:focus-visible {
  outline-offset: 0;
}

/* Regular files in `ls` output (e.g. README.md): plain text, clickable */
.terminal .ls-file {
  padding: 0;
  font: inherit;
  color: var(--term-fg);
  background: none;
  border: 0;
  border-radius: 0;
  cursor: pointer;
}

.terminal .ls-file:hover {
  color: var(--term-bg);
  background-color: var(--term-fg);
}

/* ==========================================================================
   Terminal popup (<dialog class="terminal terminal-dialog">)
   ========================================================================== */

.terminal-dialog {
  width: min(720px, calc(100% - 32px));
  max-height: calc(100dvh - 64px);
  margin: auto;
  padding: 0;
}

.terminal-dialog[open] {
  display: flex;
  flex-direction: column;
}

.terminal-dialog:focus {
  outline: none;
}

.terminal-dialog .terminal-screen {
  overflow-y: auto;
}

.terminal-dialog::backdrop {
  background-color: rgb(15 23 42 / 0.45);
}

:root[data-theme="dark"] .terminal-dialog::backdrop {
  background-color: rgb(0 0 0 / 0.6);
}

.terminal-close {
  position: relative;
  z-index: 1;
  margin-left: auto;
  width: 24px;
  height: 24px;
  padding: 0;
  display: grid;
  place-items: center;
  font: inherit;
  font-size: 16px;
  line-height: 1;
  color: var(--term-dim);
  background: none;
  border: 0;
  border-radius: 4px;
}

.terminal-close:hover {
  color: var(--term-bg);
  background-color: var(--term-red);
}

/* lock page scroll while a popup is open */
body:has(dialog[open]) {
  overflow: hidden;
}

/* `ss -tulnp` output: column-aligned like a real terminal.
   Wide output scrolls sideways inside the window instead of wrapping. */
.terminal .ss-wrap {
  overflow-x: auto;
  scrollbar-width: thin;
  white-space: normal;
  /* ignore the HTML indentation around the table */
}

.terminal .ss {
  border-collapse: collapse;
  font: inherit;
}

.terminal .ss th,
.terminal .ss td {
  padding: 0 2ch 0 0;
  text-align: left;
  font-weight: 400;
  vertical-align: baseline;
  white-space: pre;
}

.terminal .ss th {
  color: var(--term-dim);
}

.terminal .ss .ss-listen {
  color: var(--term-green);
}

/* The link column stays pinned to the right edge while the rest scrolls,
   so the links are always visible even when the table is wider than the window */
.terminal .ss .ss-link,
.terminal .ss th:last-child {
  position: sticky;
  right: 0;
  padding: 0 0 0 1ch;
  background-color: var(--term-bg);
}

.terminal .ss .ss-link::before {
  content: "-> ";
  color: var(--term-dim);
}

.terminal :focus-visible {
  outline: 1px dashed var(--term-blue);
  outline-offset: 2px;
  border-radius: 0;
}

/* Solid button */
.button {
  display: inline-block;
  margin-top: 4px;
  padding: 10px 18px;
  font-weight: 600;
  color: var(--accent-foreground);
  background-color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  transition: background-color var(--transition), border-color var(--transition);
}

.button:hover {
  color: var(--accent-foreground);
  background-color: var(--accent-hover);
  border-color: var(--accent-hover);
}

/* ==========================================================================
   Footer
   ========================================================================== */

.site-footer {
  padding: 24px var(--gutter);
  text-align: center;
  font-size: 0.9rem;
  color: var(--subtle);
  background-color: var(--surface);
  border-top: 1px solid var(--border);
}

.site-footer p {
  margin: 0;
}

/* ==========================================================================
   Small screens
   ========================================================================== */

@media (max-width: 900px) {
  .canvas {
    grid-template-columns: minmax(0, 1fr);
    max-width: var(--max-width);
  }

  .cv {
    position: static;
    max-height: none;
    overflow: visible;
  }
}

@media (max-width: 560px) {
  .site-header {
    justify-content: center;
  }

  .nav {
    justify-content: center;
  }

  .hero {
    padding-top: 24px;
  }

  .terminal {
    font-size: 12.5px;
  }

  .terminal-screen {
    padding: 10px 12px 14px;
  }
}

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

  * {
    transition: none !important;
  }
}
