:root {
  --bg: #050706;
  --panel: #090d0b;
  --panel-strong: #0d1511;
  --text: #e7f8ec;
  --muted: #8fa398;
  --green: #7cff9f;
  --green-soft: color-mix(in srgb, var(--green) 12%, transparent);
  --amber: #ffd166;
  --red: #ff5f57;
  --yellow: #febc2e;
  --cyan: #75d5ff;
  --line: color-mix(in srgb, var(--green) 20%, transparent);
  --line-strong: color-mix(in srgb, var(--green) 42%, transparent);
  --mono: "SFMono-Regular", "Cascadia Code", "Liberation Mono", Menlo, monospace;
  --sans: "Avenir Next", "Trebuchet MS", "Segoe UI", sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Georgia, serif;
}

* {
  box-sizing: border-box;
}

html {
  height: 100%;
  background: var(--bg);
  color-scheme: dark;
}

body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  color: var(--text);
  background: var(--bg);
  font-family: var(--sans);
}

body::before {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  content: "";
  opacity: 0.28;
  background:
    radial-gradient(circle at 50% 45%, color-mix(in srgb, var(--green) 8%, transparent), transparent 28rem),
    linear-gradient(transparent 0 95%, color-mix(in srgb, var(--green) 12%, transparent) 96% 100%);
  background-size: auto, 100% 6px;
}

a {
  color: inherit;
  text-decoration: none;
}

a:focus-visible,
button:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 4px;
}

p,
h1,
h2,
h3,
h4,
dl,
dd {
  margin-top: 0;
}

#main-content {
  height: 100%;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.skip-link {
  position: absolute;
  left: 1rem;
  top: 1rem;
  z-index: 20;
  padding: 0.7rem 1rem;
  color: #031006;
  background: var(--green);
  border-radius: 999px;
  font-family: var(--mono);
  font-weight: 800;
  transform: translateY(-150%);
}

.skip-link:focus {
  transform: translateY(0);
}

.terminal-only {
  display: grid;
  height: 100%;
  overflow: hidden;
  padding: clamp(1rem, 4vw, 3rem);
  place-items: center;
}

.terminal-window {
  width: min(920px, 100%);
  max-height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 18px;
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--green) 8%, transparent), transparent 34%),
    var(--panel);
  box-shadow:
    0 30px 120px rgba(0, 0, 0, 0.72),
    inset 0 0 0 1px rgba(255, 255, 255, 0.03);
}

.terminal-titlebar {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 0.85rem;
  align-items: center;
  min-height: 44px;
  padding: 0 0.95rem;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  background: rgba(255, 255, 255, 0.035);
  font-family: var(--mono);
  font-size: 0.78rem;

  & p {
    margin-bottom: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

.terminal-dots {
  display: flex;
  gap: 0.45rem;

  & span {
    width: 0.72rem;
    height: 0.72rem;
    border-radius: 50%;
    background: var(--red);
  }

  & span:nth-child(2) { background: var(--yellow); }
  & span:nth-child(3) { background: var(--green); }
}

.terminal-screen {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: clamp(1rem, 3vw, 1.6rem);
  color: var(--text);
  font-family: var(--mono);
  font-size: clamp(0.92rem, 1.6vw, 1.04rem);
  line-height: 1.65;
  scrollbar-color: var(--line-strong) transparent;

  &::-webkit-scrollbar { width: 10px; }
  &::-webkit-scrollbar-track { background: transparent; }
  &::-webkit-scrollbar-thumb {
    border: 3px solid transparent;
    border-radius: 999px;
    background: var(--line-strong);
    background-clip: content-box;
  }
}

.terminal-line {
  display: flex;
  gap: 0.7rem;
  align-items: baseline;
  min-height: 1.65em;
}

.terminal-line[hidden],
.terminal-output[hidden],
.terminal-input-line[hidden] {
  display: none;
}

.terminal-prompt {
  color: var(--green);
  user-select: none;
}

.terminal-command {
  color: var(--text);
}

.terminal-cursor {
  display: none;
  width: 0.58em;
  height: 1.1em;
  translate: -0.35rem 0.16rem;
  background: var(--green);
  animation: cursor-blink 1s steps(1, end) infinite;
}

.terminal-line.is-active .terminal-cursor {
  display: inline-block;
}

.terminal-output {
  max-width: 72ch;
  margin: 0.85rem 0 0;
  color: var(--muted);
  transition: opacity 180ms ease-out, transform 180ms ease-out;

  &.is-visible {
    opacity: 1;
    transform: translateY(0);

    @starting-style {
      opacity: 0;
      transform: translateY(3px);
    }
  }
}

.identity-name {
  margin-bottom: 1rem;
  color: var(--amber);
  font-family: var(--serif);
  font-size: clamp(2.4rem, 8vw, 5.2rem);
  font-weight: 800;
  letter-spacing: -0.07em;
  line-height: 0.9;
}

.identity-grid {
  display: grid;
  gap: 0.65rem;
  margin-bottom: 1.1rem;

  & div {
    display: grid;
    grid-template-columns: 8.5rem minmax(0, 1fr);
    gap: 1rem;
  }

  & dt {
    color: var(--green);
    &::after { content: ":"; }
  }

  & dd {
    margin-left: 0;
    color: var(--text);
  }
}

.terminal-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  align-items: center;
  margin-top: 0.85rem;

  & a {
    display: inline-flex;
    padding: 0.28rem 0.5rem;
    border: 1px solid var(--line);
    border-radius: 7px;
    color: var(--cyan);
    background: color-mix(in srgb, var(--cyan) 5.5%, transparent);

    &:hover {
      border-color: var(--cyan);
      background: color-mix(in srgb, var(--cyan) 12%, transparent);
    }
  }
}

.terminal-label {
  width: 100%;
  margin-bottom: 0;
  color: var(--green);
  &::after { content: ":"; }
}

@media (pointer: fine) {
  [data-terminal-links] {
    visibility: hidden;
    height: 0;
    margin: 0;
    overflow: hidden;
  }

  [data-terminal-links].is-revealed {
    visibility: visible;
    height: auto;
    margin-top: 0.85rem;
    overflow: visible;
    animation: links-in 300ms ease-out;
  }
}

@keyframes links-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.terminal-history {
  display: grid;
  gap: 0.35rem;
  margin-top: 1rem;
}

.terminal-history-entry {
  display: grid;
  gap: 0.25rem;
}

.terminal-input-line,
.terminal-history-command {
  display: flex;
  gap: 0.7rem;
  align-items: baseline;
}

.terminal-response {
  margin-left: 1.45rem;
  color: var(--muted);

  & p { margin-bottom: 0.25rem; }

  & a {
    color: var(--cyan);
    text-decoration: underline;
    text-underline-offset: 0.2em;
  }

  & ul {
    padding-left: 1.2rem;
    margin: 0.2rem 0 0;
  }
}

.ls-dir { color: var(--green); }
.ls-link { color: var(--cyan); }
.ls-perms { color: var(--muted); }
.ls-long { white-space: pre; line-height: 1.8; }
.neofetch-art { color: var(--green); }
.neofetch-label { color: var(--green); font-weight: 700; }

.terminal-input-line {
  margin-top: 1rem;
}

.terminal-input-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
}

.terminal-input-line input {
  width: 100%;
  min-width: 0;
  padding: 0;
  border: 0;
  color: var(--text);
  background: transparent;
  caret-color: var(--green);
  caret-shape: block;
  font: inherit;
  outline: 0;

  &::selection {
    color: #031006;
    background: var(--green);
  }
}

.terminal-ghost {
  position: absolute;
  left: 0;
  top: 0;
  pointer-events: none;
  color: var(--muted);
  opacity: 0.4;
  font: inherit;
  white-space: pre;
}

@keyframes cursor-blink {
  50% { opacity: 0; }
}

/* Fallback styles for non-home pages. */
.site-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  max-width: 900px;
  margin: 2rem auto;
  padding: 0 1rem;
  font-family: var(--mono);
}

.nav-link {
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);

  &:hover {
    color: var(--text);
    border-color: var(--green);
  }
}

.section,
article,
.list-page,
.construction-container,
.project-title,
.bar,
.sem-title,
.text {
  max-width: 900px;
  margin-right: auto;
  margin-left: auto;
  padding-right: 1rem;
  padding-left: 1rem;
}

.project-title,
article h1,
.construction-title {
  color: var(--text);
  font-family: var(--serif);
  font-size: clamp(2.4rem, 8vw, 5rem);
  letter-spacing: -0.06em;
  line-height: 0.95;
}

.bar {
  border-bottom: 1px solid var(--line);
}

.sem-title {
  margin-top: 2rem;
  color: var(--green);
  font-family: var(--mono);
}

.text,
article p,
article li,
.list-page li,
.construction-message {
  color: var(--muted);
  line-height: 1.75;
}

.underline {
  color: var(--cyan);
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

.construction-container {
  display: grid;
  min-height: 70vh;
  place-items: center;
  text-align: center;
}

.construction-icon {
  font-size: 4rem;
}

@media (max-width: 640px) {
  .terminal-only {
    align-items: start;
    padding: 0.75rem;
  }

  .terminal-window { border-radius: 14px; }
  .terminal-titlebar { grid-template-columns: auto minmax(0, 1fr); }
  .terminal-screen { font-size: 0.86rem; }
  .identity-grid div { grid-template-columns: 1fr; gap: 0.1rem; }
}

/* ── Theme: Bare TTY ── */

[data-theme="tty"] {
  & .terminal-window {
    border: none;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    width: 100%;
    max-width: none;
  }

  & .terminal-titlebar { display: none; }

  &.terminal-only {
    padding: 2rem clamp(1.5rem, 5vw, 4rem);
    align-items: start;
  }

  & .terminal-screen {
    height: calc(100vh - 4rem);
    padding: 0;
  }

  & .identity-name {
    font-size: clamp(2rem, 6vw, 3.6rem);
  }
}

/* ── Theme: Retro CRT ── */

[data-theme="crt"] {
  --text: #ffb000;
  --muted: #996e00;
  --green: #ffc633;
  --green-soft: color-mix(in srgb, #ffb000 8%, transparent);
  --amber: #ffb000;
  --cyan: #ffd866;
  --line: color-mix(in srgb, #ffb000 15%, transparent);
  --line-strong: color-mix(in srgb, #ffb000 30%, transparent);

  & .terminal-window {
    border: 6px solid #2a2a20;
    border-radius: 24px;
    background: #0a0800;
    box-shadow:
      0 0 80px color-mix(in srgb, #ffb000 6%, transparent),
      inset 0 0 80px rgba(0, 0, 0, 0.5);
  }

  & .terminal-titlebar {
    background: color-mix(in srgb, #ffb000 3%, transparent);
  }

  & .terminal-dots span { background: #554400; }
  & .terminal-dots span:nth-child(2) { background: #776600; }
  & .terminal-dots span:nth-child(3) { background: #998800; }

  & .terminal-screen {
    text-shadow: 0 0 4px color-mix(in srgb, #ffb000 50%, transparent);
    background-image: repeating-linear-gradient(
      transparent 0 2px,
      rgba(0, 0, 0, 0.1) 2px 4px
    );
  }

  & .terminal-cursor { background: #ffb000; }
  & .identity-name { color: #ffb000; }

  & .terminal-input-line input::selection {
    color: #0a0800;
    background: #ffb000;
  }
}

/* ── Theme: Brutalist ── */

[data-theme="brutalist"] {
  & .terminal-window {
    border: 3px solid var(--text);
    border-radius: 0;
    background: var(--bg);
    box-shadow: 8px 8px 0 var(--text);
  }

  & .terminal-titlebar {
    border-bottom: 3px solid var(--text);
    background: var(--text);
    color: var(--bg);

    & p {
      color: var(--bg);
      text-transform: uppercase;
      letter-spacing: 0.1em;
      font-weight: 700;
    }
  }

  & .terminal-dots { display: none; }

  & .identity-name {
    font-family: var(--mono);
    text-transform: uppercase;
    letter-spacing: -0.02em;
  }

  & .terminal-group a {
    border: 2px solid var(--text);
    border-radius: 0;

    &:hover {
      color: var(--bg);
      background: var(--text);
      border-color: var(--text);
    }
  }
}

/* ── Theme: Floating prompt ── */

[data-theme="float"] {
  & .terminal-window {
    border: none;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    max-width: 720px;
  }

  & .terminal-titlebar { display: none; }

  & .terminal-screen {
    height: auto;
    max-height: calc(100vh - 6rem);
    padding: 0;
  }

  & .terminal-output {
    border-bottom: 1px solid var(--line);
    padding-bottom: 1.2rem;
    margin-bottom: 1rem;
  }

  & .terminal-group a {
    border: none;
    border-radius: 0;
    padding: 0;
    background: none;
    color: var(--cyan);
    text-decoration: underline;
    text-underline-offset: 0.2em;

    &:hover {
      border: none;
      background: none;
      color: var(--text);
    }
  }

  & .identity-name {
    font-size: clamp(3rem, 10vw, 6rem);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 1ms !important;
  }
}
