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

:root {
  color-scheme: dark;
  --bg: #0d1117;
  --text: #c9d1d9;
  --muted: #8b949e;
  --accent: #58a6ff;
  --accent-hover: #79b8ff;
  --border: #30363d;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Monaco, Consolas, "Liberation Mono",
    monospace;
  /* Tuned to match <pre> content from ascii.txt (line count × line-height, max row width in chars) */
  --ascii-lines: 107;
  --ascii-line-height: 1.05;
  --ascii-cols: 200;
  /* Cap ASCII column so the links panel keeps ~half the viewport instead of ~75% */
  --ascii-panel-cap: 52vw;
  --layout-chrome-x: 21rem; /* aside + gap + page padding allowance */
}

html,
body {
  height: 100%;
  max-height: 100dvh;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: var(--font-mono);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}

.layout {
  display: flex;
  align-items: stretch;
  justify-content: center;
  gap: 2.5rem;
  max-width: 120rem;
  margin: 0 auto;
  padding: clamp(0.75rem, 2dvh, 1.5rem) clamp(1rem, 4vw, 3rem);
  height: 100%;
  max-height: 100dvh;
  min-height: 0;
}

.ascii-wrap {
  flex: 0 1 auto;
  width: max-content;
  max-width: min(100%, var(--ascii-panel-cap));
  min-width: 0;
  min-height: 0;
  max-height: 100%;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: clamp(0.5rem, 1.5dvh, 1rem) clamp(0.5rem, 1.5vw, 1.25rem);
  background: rgba(22, 27, 34, 0.6);
  display: flex;
  align-items: center;
}

.ascii {
  margin: 0;
  width: max-content;
  max-width: 100%;
  font-family: var(--font-mono);
  line-height: var(--ascii-line-height);
  white-space: pre;
  color: var(--text);
  /* Shorter of: viewport height, and width available inside capped panel (not full screen) */
  --ascii-inner-w: calc(
    max(0px, min(var(--ascii-panel-cap), 100vw - var(--layout-chrome-x)) - 2.5rem)
  );
  font-size: min(
    calc((100dvh - 8rem) / (var(--ascii-lines) * var(--ascii-line-height))),
    calc(var(--ascii-inner-w) / var(--ascii-cols))
  );
}

.links {
  display: flex;
  flex-direction: column;
  flex: 0 1 auto;
  min-width: min(20rem, 100%);
  max-width: min(26rem, 36vw);
  max-height: 100%;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: hidden;
  padding-left: 1.5rem;
  padding-bottom: 0.75rem;
  border-left: 1px solid var(--border);
  align-self: stretch;
}

.name {
  margin: 0 0 0.25rem;
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.tag {
  margin: 0 0 1.75rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.links nav {
  width: 100%;
  min-width: 0;
}

.links ul {
  list-style: none;
  margin: 0;
  padding: 0;
  width: 100%;
  min-width: 0;
}

.links li {
  margin-bottom: 1.25rem;
  min-width: 0;
}

.links li:last-child {
  margin-bottom: 0;
}

.links a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
}

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

.links a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.meta {
  display: block;
  margin-top: 0.2rem;
  font-size: 0.8rem;
  color: var(--muted);
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.fake-chatbot {
  flex-shrink: 0;
  margin-top: auto;
  align-self: flex-end;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 3rem;
  height: 3rem;
  margin-bottom: 0;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: rgba(22, 27, 34, 0.9);
  color: var(--text);
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.fake-chatbot:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: rgba(30, 58, 95, 0.35);
}

.fake-chatbot:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.fake-chatbot__icon {
  display: block;
}

.fake-chatbot-dialog {
  max-width: min(22rem, calc(100vw - 2rem));
  padding: 1.25rem 1.35rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.95rem;
  line-height: 1.45;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}

.fake-chatbot-dialog::backdrop {
  background: rgba(1, 4, 9, 0.55);
}

.fake-chatbot-dialog__msg {
  margin: 0 0 1.1rem;
}

.fake-chatbot-dialog__ok {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  padding: 0.45rem 1rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: rgba(22, 27, 34, 0.8);
  color: var(--accent);
  cursor: pointer;
}

.fake-chatbot-dialog__ok:hover {
  background: rgba(30, 58, 95, 0.35);
  border-color: var(--accent);
}

.fake-chatbot-dialog__ok:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (max-width: 768px) {
  .layout {
    flex-direction: column;
    gap: clamp(0.5rem, 1.5dvh, 1rem);
    padding-left: max(1rem, env(safe-area-inset-left, 0px));
    padding-right: max(1rem, env(safe-area-inset-right, 0px));
    padding-bottom: max(0.5rem, env(safe-area-inset-bottom, 0px));
  }

  /*
    Size glyphs from the real framed area (flex tile), not a guessed vh slice,
    so tall mobile chrome does not leave empty padding above/below the art.
  */
  .ascii-wrap {
    container-type: size;
    container-name: ascii-mobile;
    flex: 1 1 0%;
    width: 100%;
    max-width: 100%;
    min-height: 0;
    padding: 0.35rem 0.5rem;
    align-items: center;
    justify-content: center;
  }

  .ascii {
    /* Fallback when container query units unavailable */
    font-size: min(
      calc((100dvh - 13.5rem) / (var(--ascii-lines) * var(--ascii-line-height))),
      calc(max(0px, 100vw - 2.25rem) / var(--ascii-cols))
    );
  }

  @supports (font-size: 1cqh) {
    .ascii {
      --ascii-m-pad: 0.35rem;
      font-size: min(
        calc(
          (100cqh - var(--ascii-m-pad)) / (var(--ascii-lines) * var(--ascii-line-height))
        ),
        calc(max(0px, 100cqw - var(--ascii-m-pad)) / var(--ascii-cols))
      );
    }
  }

  .links {
    flex: 0 0 auto;
    align-self: stretch;
    width: 100%;
    max-width: none;
    min-width: 0;
    padding-left: 0;
    padding-right: 0;
    border-left: none;
    border-top: 1px solid var(--border);
    padding-top: 1rem;
    padding-bottom: max(0.85rem, calc(0.35rem + env(safe-area-inset-bottom, 0px)));
    overflow-x: visible;
    overflow-y: visible;
  }

  .fake-chatbot {
    margin-top: 1.25rem;
    align-self: flex-end;
  }
}
