/**
 * The Monospace Web
 * By Oskar Wickström
 * Licensed under the MIT License (https://github.com/owickstrom/the-monospace-web/blob/main/LICENSE.md)
 *
 * Copyright 2024 Oskar Wickström
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 **/
@import url('https://fonts.cdnfonts.com/css/jetbrains-mono-2');

:root {
  --font-family: "JetBrains Mono", monospace;
  --line-height: 1.20rem;
  --border-thickness: 2px;
  --text-color: #f0f0e8;
  --text-color-alt: #aaa8aa;
  --background-color: #000;
  --background-color-alt: #111111;
  --glow-color: rgba(240, 240, 232, 0.6);
  --glow-color-soft: rgba(240, 240, 232, 0.3);
  --glow-color-very-soft: rgba(245, 245, 232, 0.15);

  --font-weight-normal: 500;
  --font-weight-medium: 600;
  --font-weight-bold: 800;

  font-family: var(--font-family);
  font-optical-sizing: auto;
  font-weight: var(--font-weight-normal);
  font-style: normal;
  font-variant-numeric: tabular-nums lining-nums;
  font-size: 16px;
}

/* Amber theme: classic amber phosphor terminal */
:root.theme-amber {
  --text-color: #ffb000;
  --text-color-alt: #cc8800;
  --background-color: #000;
  --background-color-alt: #1a1000;
  --glow-color: rgba(255, 176, 0, 0.6);
  --glow-color-soft: rgba(255, 176, 0, 0.3);
  --glow-color-very-soft: rgba(255, 176, 0, 0.15);
}

/* Green theme: Apple II style green phosphor */
:root.theme-green {
  --text-color: #33ff00;
  --text-color-alt: #22aa00;
  --background-color: #000;
  --background-color-alt: #001a00;
  --glow-color: rgba(51, 255, 0, 0.6);
  --glow-color-soft: rgba(51, 255, 0, 0.3);
  --glow-color-very-soft: rgba(51, 255, 0, 0.15);
}

/* White theme: P4 paper white phosphor */
:root.theme-white {
  --text-color: #f0f0e8;
  --text-color-alt: #aaa8aa;
  --background-color: #000;
  --background-color-alt: #111111;
  --glow-color: rgba(240, 240, 232, 0.6);
  --glow-color-soft: rgba(240, 240, 232, 0.3);
  --glow-color-very-soft: rgba(245, 245, 232, 0.15);
}

/* Phosphor glow effect for amber, green, and white themes */
:root.theme-amber body,
:root.theme-green body,
:root.theme-white body {
  text-shadow:
    0 0 1px var(--glow-color),
    0 0 4px var(--glow-color-soft),
    0 0 6px var(--glow-color-very-soft);
}

/* Subtle scanline effect for amber, green, and white themes */
:root.theme-amber body::after,
:root.theme-green body::after,
:root.theme-white body::after {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 1px,
    rgba(0, 0, 0, 0.1) 1px,
    rgba(0, 0, 0, 0.1) 2px
  );
  z-index: 9999;
}

/* Disable glow on hidden bracket elements (non-active nav items and theme buttons) */
:root.theme-amber .nav-item:not(.active):not(:hover) .bracket-open::before,
:root.theme-amber .nav-item:not(.active):not(:hover) .bracket-close::before,
:root.theme-amber .theme-btn:not(.active):not(:hover) .bracket-open::before,
:root.theme-amber .theme-btn:not(.active):not(:hover) .bracket-close::before,
:root.theme-green .nav-item:not(.active):not(:hover) .bracket-open::before,
:root.theme-green .nav-item:not(.active):not(:hover) .bracket-close::before,
:root.theme-green .theme-btn:not(.active):not(:hover) .bracket-open::before,
:root.theme-green .theme-btn:not(.active):not(:hover) .bracket-close::before,
:root.theme-white .nav-item:not(.active):not(:hover) .bracket-open::before,
:root.theme-white .nav-item:not(.active):not(:hover) .bracket-close::before,
:root.theme-white .theme-btn:not(.active):not(:hover) .bracket-open::before,
:root.theme-white .theme-btn:not(.active):not(:hover) .bracket-close::before {
  text-shadow: none;
}

* {
  box-sizing: border-box;
}


* + * {
  margin-top: var(--line-height);
}

html {
  display: flex;
  width: 100%;
  margin: 0;
  padding: 0;
  flex-direction: column;
  align-items: center;
  background: var(--background-color);
  color: var(--text-color);
}

body {
  position: relative;
  width: 100%;
  margin: 0;
  padding: var(--line-height) 2ch;
  max-width: calc(min(80ch, round(down, 100%, 1ch)));
  line-height: var(--line-height);
  overflow-x: hidden;
}

@media screen and (max-width: 480px) {
  :root {
    font-size: 14px;
  }
  body {
    padding: var(--line-height) 1ch;
  }
}

h1, h2, h3, h4, h5, h6 {
  font-weight: var(--font-weight-bold);
  margin: calc(var(--line-height) * 2) 0 var(--line-height);
  line-height: var(--line-height);
}

h1 {
  font-size: 2rem;
  line-height: calc(2 * var(--line-height));
  margin-bottom: calc(var(--line-height) * 2);
  text-transform: uppercase;
}
h2 {
  font-size: 1rem;
  text-transform: uppercase;
}

hr {
  position: relative;
  display: block;
  height: var(--line-height);
  margin: calc(var(--line-height) * 1.5) 0;
  border: none;
  color: var(--text-color);
}
hr:after {
  display: block;
  content: "";
  position: absolute;
  top: calc(var(--line-height) / 2 - var(--border-thickness));
  left: 0;
  width: 100%;
  border-top: calc(var(--border-thickness) * 3) double var(--text-color);
  height: 0;
}

a {
  text-decoration-thickness: var(--border-thickness);
}

a:link, a:visited {
  color: var(--text-color);
}

p {
  margin-bottom: var(--line-height);
}

strong {
  font-weight: var(--font-weight-bold);
}
em {
  font-style: italic;
}

sub {
  position: relative;
  display: inline-block;
  margin: 0;
  vertical-align: sub;
  line-height: 0;
  width: calc(1ch / 0.75);
  font-size: .75rem;
}

table {
  position: relative;
  top: calc(var(--line-height) / 2);
  width: calc(round(down, 100%, 1ch));
  border-collapse: collapse;
  margin: 0 0 calc(var(--line-height) * 2);
}

th, td {
  border: var(--border-thickness) solid var(--text-color);
  padding:
    calc((var(--line-height) / 2))
    calc(1ch - var(--border-thickness) / 2)
    calc((var(--line-height) / 2) - (var(--border-thickness)))
  ;
  line-height: var(--line-height);
  vertical-align: top;
  text-align: left;
}
table tbody tr:first-child > * {
  padding-top: calc((var(--line-height) / 2) - var(--border-thickness));
}


th {
  font-weight: 700;
}
.width-min {
  width: 0%;
}
.width-auto {
  width: 100%;
}

/* Site header - flexbox-based layout */
.site-header {
  position: relative;
  top: calc(var(--line-height) / 2);
  border: var(--border-thickness) solid var(--text-color);
  margin-bottom: calc(var(--line-height) * 2);
  margin-top: 0;
}

.site-header * {
  margin-top: 0;
}

.header-top {
  display: flex;
  justify-content: space-between;
  align-items: stretch;
  border-bottom: var(--border-thickness) solid var(--text-color);
}

.header-title {
  font-size: 2rem;
  line-height: calc(2 * var(--line-height));
  margin: 0;
  padding: calc(var(--line-height) / 2) calc(1ch - var(--border-thickness) / 2);
  text-transform: uppercase;
}

.header-right {
  text-align: right;
  padding: calc(var(--line-height) / 2) calc(1ch - var(--border-thickness) / 2);
  white-space: nowrap;
}

.header-right br {
  margin: 0;
}

.header-nav {
  display: flex;
  margin: 0;
}

.header-nav .nav-item {
  display: block;
  text-decoration: none;
  text-transform: uppercase;
  font-weight: var(--font-weight-medium);
  line-height: var(--line-height);
  padding: calc(var(--line-height) / 2 - var(--border-thickness)) 0;
  padding-bottom: calc(var(--line-height) / 2 - var(--border-thickness));
  border-right: var(--border-thickness) solid var(--text-color);
  box-sizing: border-box;
  text-align: center;
}

.header-nav .nav-spacer {
  flex: 1 1 auto;
}

p {
  word-break: break-word;
  word-wrap: break-word;
  hyphens: auto;
}

img, video {
  display: block;
  width: 100%;
  object-fit: contain;
  overflow: hidden;
}
img {
  font-style: italic;
  color: var(--text-color-alt);
}

details {
  border: var(--border-thickness) solid var(--text-color);
  padding: calc(var(--line-height) - var(--border-thickness)) 1ch;
  margin-bottom: var(--line-height);
}

summary {
  font-weight: var(--font-weight-medium);
  cursor: pointer;
}
details[open] summary {
  margin-bottom: var(--line-height);
}

details ::marker {
  display: inline-block;
  content: '▶';
  margin: 0;
}
details[open] ::marker {
  content: '▼';
}

details :last-child {
  margin-bottom: 0;
}

pre {
  white-space: pre;
  overflow-x: auto;
  margin: var(--line-height) 0;
  overflow-y: hidden;
}
figure pre {
  margin: 0;
}

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

code {
  font-weight: var(--font-weight-medium);
}

:not(pre) > code::before {
  content: "`";
}

:not(pre) > code::after {
  content: "`";
}

figure {
  margin: calc(var(--line-height) * 2) 3ch;
  overflow-x: auto;
  overflow-y: hidden;
}

figcaption {
  display: block;
  font-style: italic;
  margin-top: var(--line-height);
}

ul, ol {
  padding: 0;
  margin: 0 0 var(--line-height);
}

ul {
  list-style-type: square;
  padding: 0 0 0 2ch;
}
ol {
  list-style-type: none;
  counter-reset: item;
  padding: 0;
}
ol ul,
ol ol,
ul ol,
ul ul {
  padding: 0 0 0 3ch;
  margin: 0;
}
ol li:before {
  content: counters(item, ".") ". ";
  counter-increment: item;
  font-weight: var(--font-weight-medium);
}

li {
  margin: 0;
  padding: 0;
}

li::marker {
  line-height: 0;
}

::-webkit-scrollbar {
    height: var(--line-height);
}

input, button, textarea {
  border: var(--border-thickness) solid var(--text-color);
  padding:
    calc(var(--line-height) / 2 - var(--border-thickness))
    calc(1ch - var(--border-thickness));
  margin: 0;
  font: inherit;
  font-weight: inherit;
  height: calc(var(--line-height) * 2);
  width: auto;
  overflow: visible;
  background: var(--background-color);
  color: var(--text-color);
  line-height: normal;
  -webkit-font-smoothing: inherit;
  -moz-osx-font-smoothing: inherit;
  -webkit-appearance: none;
}

input[type=checkbox],
input[type=radio] {
  display: inline-grid;
  place-content: center;
  vertical-align: top;
  width: 2ch;
  height: var(--line-height);
  cursor: pointer;
}
input[type=checkbox]:checked:before,
input[type=radio]:checked:before {
  content: "";
  width: 1ch;
  height: calc(var(--line-height) / 2);
  background: var(--text-color);
}
input[type=radio],
input[type=radio]:before {
  border-radius: 100%;
}

button:focus, input:focus {
  --border-thickness: 3px;
  outline: none;
}

input {
  width: calc(round(down, 100%, 1ch));
}
::placeholder {
  color: var(--text-color-alt);
  opacity: 1;
}
::-ms-input-placeholder {
  color: var(--text-color-alt);
}
button::-moz-focus-inner {
  padding: 0;
  border: 0
}

button {
  text-transform: uppercase;
  font-weight: var(--font-weight-medium);
  cursor: pointer;
}

button:hover {
  background: var(--background-color-alt);
}
button:active {
  transform: translate(2px, 2px);
}

label {
  display: block;
  width: calc(round(down, 100%, 1ch));
  height: auto;
  line-height: var(--line-height);
  font-weight: var(--font-weight-medium);
  margin: 0;
}

label input {
  width: 100%;
}

.tree, .tree ul {
  position: relative;
  padding-left: 0;
  list-style-type: none;
  line-height: var(--line-height);
}
.tree ul {
  margin: 0;
}
.tree ul li {
  position: relative;
  padding-left: 1.5ch;
  margin-left: 1.5ch;
  border-left: var(--border-thickness) solid var(--text-color);
}
.tree ul li:before {
  position: absolute;
  display: block;
  top: calc(var(--line-height) / 2);
  left: 0;
  content: "";
  width: 1ch;
  border-bottom: var(--border-thickness) solid var(--text-color);
}
.tree ul li:last-child {
  border-left: none;
}
.tree ul li:last-child:after {
  position: absolute;
  display: block;
  top: 0;
  left: 0;
  content: "";
  height: calc(var(--line-height) / 2);
  border-left: var(--border-thickness) solid var(--text-color);
}

.grid {
  --grid-cells: 0;
  display: flex;
  gap: 1ch;
  width: calc(round(down, 100%, (1ch * var(--grid-cells)) - (1ch * var(--grid-cells) - 1)));
  margin-bottom: var(--line-height);
}

.grid > *,
.grid > input {
  flex: 0 0 calc(round(down, (100% - (1ch * (var(--grid-cells) - 1))) / var(--grid-cells), 1ch));
}
.grid:has(> :last-child:nth-child(1)) { --grid-cells: 1; }
.grid:has(> :last-child:nth-child(2)) { --grid-cells: 2; }
.grid:has(> :last-child:nth-child(3)) { --grid-cells: 3; }
.grid:has(> :last-child:nth-child(4)) { --grid-cells: 4; }
.grid:has(> :last-child:nth-child(5)) { --grid-cells: 5; }
.grid:has(> :last-child:nth-child(6)) { --grid-cells: 6; }
.grid:has(> :last-child:nth-child(7)) { --grid-cells: 7; }
.grid:has(> :last-child:nth-child(8)) { --grid-cells: 8; }
.grid:has(> :last-child:nth-child(9)) { --grid-cells: 9; }

/* DEBUG UTILITIES */

.debug .debug-grid {
  --color: color-mix(in srgb, var(--text-color) 10%, var(--background-color) 90%);
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: -1;
  background-image:
    repeating-linear-gradient(var(--color) 0 1px, transparent 1px 100%),
    repeating-linear-gradient(90deg, var(--color) 0 1px, transparent 1px 100%);
  background-size: 1ch var(--line-height);
  margin: 0;
}

.debug .off-grid {
  background: rgba(255, 0, 0, 0.1);
}

/* Footer row - flexbox layout like header */
.footer-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-top: 0;
}

.footer-row * {
  margin-top: 0;
}

.footer-left {
  text-align: left;
}

.footer-right {
  text-align: right;
}

.debug-toggle-label {
  display: inline;
}

/* Header slogan */
.site-header .slogan {
  color: var(--text-color-alt);
  white-space: nowrap;
}

/* Theme switcher with three colored circles */
.site-header .theme-switcher {
  display: inline-block;
  user-select: none;
}

.site-header .theme-btn {
  cursor: pointer;
  display: inline;
}

/* Theme icon colors - always their respective colors */
.site-header .theme-icon.amber {
  color: #ffb000;
}

.site-header .theme-icon.green {
  color: #33ff00;
}

.site-header .theme-icon.white {
  color: #ffffff;
}


/* Bracket/angle bracket logic for nav items
   - Active items: show [TEXT]
   - Inactive items: show  TEXT  (space preserved)
   - Inactive hover: show <TEXT>
*/

/* Default: show brackets in background color (invisible but takes space) */
.site-header .nav-item .bracket-open::before {
  content: "[";
  color: var(--background-color);
}

.site-header .nav-item .bracket-close::before {
  content: "]";
  color: var(--background-color);
}

/* Active: show brackets */
.site-header .nav-item.active .bracket-open::before,
.site-header .nav-item.active .bracket-close::before {
  color: var(--text-color);
}

/* Hover on non-active: show <> */
.site-header .nav-item:not(.active):hover .bracket-open::before {
  content: "<";
  color: var(--text-color);
}

.site-header .nav-item:not(.active):hover .bracket-close::before {
  content: ">";
  color: var(--text-color);
}

/* Bracket logic for theme buttons */
.site-header .theme-btn .bracket-open::before {
  content: "[";
  color: var(--background-color);
}

.site-header .theme-btn .bracket-close::before {
  content: "]";
  color: var(--background-color);
}

/* Active theme: show brackets */
.site-header .theme-btn.active .bracket-open::before,
.site-header .theme-btn.active .bracket-close::before {
  color: var(--text-color);
}

/* Hover on non-active theme: show <> */
.site-header .theme-btn:not(.active):hover .bracket-open::before {
  content: "<";
  color: var(--text-color);
}

.site-header .theme-btn:not(.active):hover .bracket-close::before {
  content: ">";
  color: var(--text-color);
}

/* Navigation styles for Hugo theme (legacy, keeping for compatibility) */
nav.site-nav {
  margin-bottom: calc(var(--line-height) * 2);
}

nav.site-nav ul {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  gap: 2ch;
}

nav.site-nav li {
  margin: 0;
}

nav.site-nav li::before {
  content: none;
}

nav.site-nav a {
  text-transform: uppercase;
  font-weight: var(--font-weight-medium);
}

/* Blog post list styles */
.post-list {
  list-style: none;
  padding: 0;
}

.post-list li {
  margin-bottom: var(--line-height);
}

.post-list li::before {
  content: none;
}

.post-meta {
  color: var(--text-color-alt);
}

.post-meta a {
  color: var(--text-color-alt);
}

.post-meta:has(+ .post-tags) {
  margin-bottom: 0;
}

.post-meta + .post-tags {
  margin-top: 0;
}

.post-tags {
  color: var(--text-color-alt);
}

.post-tags a {
  color: var(--text-color-alt);
}

/* Reset global style overrides inside asciinema player */
.ap-wrapper * {
  margin-top: 0;
  box-sizing: content-box;
}

/* Align player to the left instead of centering */
.ap-wrapper {
  justify-content: flex-start;
}

/* Snap asciinema player spacing to the character grid */
.ap-player .ap-term {
  border-width: 0;
}


/* Page header styles */
.page-header {
  margin-bottom: calc(var(--line-height) * 2);
}

.page-header h1 {
  margin-bottom: var(--line-height);
}
