:root {
  color-scheme: dark;
  --bg: #000;
  --orange: #ff4d19;
  --head-color: #9447b0;
  --terminal-green: #009f23;
  --terminal-pink: #ff1493;
  --terminal-dim: rgb(0 159 35 / 0.58);
  --terminal-text: #009f23;
  --site-cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='33' height='33' viewBox='0 0 33 33'%3E%3Cg fill='none' stroke='%2300d63a' stroke-width='2.4' stroke-linecap='round'%3E%3Cpath d='M16.5 5.5v22'/%3E%3Cpath d='M5.5 16.5h22'/%3E%3C/g%3E%3C/svg%3E") 16 16, crosshair;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
}

body {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  cursor: var(--site-cursor);
}

button,
a,
input,
.tetris-game,
#portrait {
  cursor: var(--site-cursor);
}

.terminal-title,
.terminal-commands,
.terminal-shortcuts,
.terminal-chat__entry,
.terminal-chat__prompt,
.tetris-game,
#portrait,
#source-face,
#source-face-smile {
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.terminal-chat__input {
  user-select: text;
  -webkit-user-select: text;
}

.stage {
  position: relative;
  display: grid;
  width: 100vw;
  height: 100vh;
  min-height: 560px;
  place-items: center;
  background: #000;
}

.terminal-panel {
  position: fixed;
  z-index: 5;
  top: max(clamp(22px, 3.2vw, 42px), env(safe-area-inset-top));
  left: max(clamp(18px, 2.6vw, 34px), env(safe-area-inset-left));
  width: min(50vw, 720px);
  min-width: 520px;
  overflow: visible;
  border: 0;
  background: transparent;
  box-shadow: none;
  color: var(--terminal-text);
  font-family: "Courier New", Courier, "Nimbus Mono PS", "Liberation Mono", monospace;
  font-size: clamp(11px, 0.95vw, 15px);
  font-weight: 400;
  line-height: 1.18;
  letter-spacing: 0.02em;
  text-shadow:
    0 0 2px rgb(0 159 35 / 0.42),
    0 0 9px rgb(0 159 35 / 0.14);
}

.terminal-panel::before {
  position: absolute;
  inset: -16px -30px -24px -22px;
  z-index: -1;
  background: transparent;
  content: "";
  pointer-events: none;
}

.terminal-title {
  display: block;
  width: min(42vw, 540px);
  height: auto;
  margin: 0 0 clamp(36px, 5.8vh, 64px);
  overflow: visible;
}

.terminal-title__strokes {
  fill: none;
  stroke: var(--terminal-green);
  stroke-width: 1.45;
  stroke-linecap: square;
  stroke-linejoin: miter;
}

.terminal-title__smile {
  opacity: 0;
}

body.smile-mode .terminal-title__normal {
  opacity: 0;
}

body.smile-mode .terminal-title__smile {
  opacity: 1;
}

.terminal-title__cap {
  stroke-width: 1.45;
}

.terminal-title__symbol {
  dominant-baseline: alphabetic;
  fill: var(--terminal-green);
  font-family: "Courier New", Courier, "Nimbus Mono PS", "Liberation Mono", monospace;
  font-size: 54px;
  font-weight: 700;
  stroke: none;
  text-anchor: middle;
}

.terminal-shell {
  display: block;
  margin: 0;
  font-size: clamp(14px, 1.55vw, 24px);
  line-height: 1.2;
}

.terminal-commands h2 {
  margin: 0 0 0.32em;
  color: var(--terminal-green);
  font: inherit;
  text-transform: lowercase;
}

.terminal-commands__list {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.12em;
}

.terminal-commands button {
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--terminal-pink);
  font: inherit;
  line-height: inherit;
  letter-spacing: inherit;
  text-align: left;
  text-shadow:
    0 0 2px rgb(255 20 147 / 0.46),
    0 0 9px rgb(255 20 147 / 0.16);
}

.terminal-commands button::before {
  color: var(--terminal-green);
  content: "$ ";
}

.terminal-commands button:hover,
.terminal-commands button:focus-visible,
.terminal-commands button.is-active {
  color: var(--terminal-green);
  outline: 0;
  text-shadow:
    0 0 2px rgb(0 159 35 / 0.5),
    0 0 10px rgb(0 159 35 / 0.2);
}

.terminal-commands button:focus-visible::before,
.terminal-commands button.is-active::before {
  color: var(--terminal-pink);
  content: "> ";
}

.terminal-shortcuts {
  display: grid;
  gap: 0.1em;
  margin-top: clamp(18px, 2.8vh, 34px);
  color: var(--terminal-green);
}

.terminal-shortcuts p {
  margin: 0;
}

.terminal-chat {
  position: fixed;
  top: env(safe-area-inset-top);
  left: calc(50vw + min(18vw, 240px));
  right: max(clamp(16px, 2.4vw, 34px), env(safe-area-inset-right));
  bottom: env(safe-area-inset-bottom);
  z-index: 6;
  display: flex;
  height: calc(100svh - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  align-items: flex-end;
  color: var(--terminal-green);
  font-size: clamp(11px, 1.05vw, 16px);
  line-height: 1.28;
  overflow: hidden;
  pointer-events: none;
}

.terminal-chat--tetris {
  left: max(66vw, calc(100vw - 440px));
}

.terminal-chat--tetris .terminal-chat__history {
  overflow: hidden;
}

.terminal-chat__history {
  position: relative;
  display: flex;
  flex-direction: column-reverse;
  width: 100%;
  height: 100%;
  max-height: 100%;
  padding: clamp(20px, 3vh, 38px) 0;
  gap: 0.9em;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: none;
  -ms-overflow-style: none;
  -webkit-mask-image: linear-gradient(
    to bottom,
    transparent 0,
    #000 clamp(16px, 3vh, 34px),
    #000 calc(100% - clamp(16px, 3vh, 34px)),
    transparent 100%
  );
  mask-image: linear-gradient(
    to bottom,
    transparent 0,
    #000 clamp(16px, 3vh, 34px),
    #000 calc(100% - clamp(16px, 3vh, 34px)),
    transparent 100%
  );
}

.terminal-chat__history::-webkit-scrollbar {
  width: 0;
  height: 0;
}

.terminal-chat__input-line {
  display: flex;
  width: 100%;
  min-width: 0;
  margin: 0;
  pointer-events: auto;
  white-space: nowrap;
}

.terminal-chat__entry {
  pointer-events: auto;
}

.terminal-chat__entry--tetris {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
  flex-direction: column;
}

.terminal-chat--tetris .terminal-chat__entry:not(.terminal-chat__entry--tetris) {
  display: none;
}

.terminal-chat--tetris .terminal-chat__entry--tetris {
  position: absolute;
  inset: 0 0 calc(clamp(20px, 3vh, 38px) + 2.2em);
  z-index: 1;
}

.terminal-chat__entry--tetris .terminal-chat__output {
  display: flex;
  flex: 1 1 auto;
  height: 100%;
  min-height: 0;
}

.terminal-chat__line {
  margin: 0 0 0.55em;
  white-space: nowrap;
}

.terminal-chat__prompt {
  flex: 0 0 auto;
  color: var(--terminal-green);
}

.terminal-chat__input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 0 0 0 0.65ch;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--terminal-pink);
  font: inherit;
  letter-spacing: inherit;
  line-height: inherit;
  outline: 0;
  caret-color: var(--terminal-pink);
  text-shadow:
    0 0 2px rgb(255 20 147 / 0.46),
    0 0 9px rgb(255 20 147 / 0.16);
}

.terminal-chat__input::placeholder {
  color: rgb(172 172 188);
  opacity: 1;
  text-shadow:
    0 0 2px rgb(172 172 188 / 0.38),
    0 0 9px rgb(172 172 188 / 0.12);
}

.terminal-chat__command {
  color: var(--terminal-pink);
  text-shadow:
    0 0 2px rgb(255 20 147 / 0.46),
    0 0 9px rgb(255 20 147 / 0.16);
}

.terminal-chat__keyword {
  color: rgb(255 65 172 / 0.88);
  text-shadow:
    0 0 1px rgb(255 20 147 / 0.42),
    0 0 6px rgb(255 20 147 / 0.14);
}

.terminal-chat__cursor {
  color: rgb(172 172 188);
}

.terminal-chat__cursor::after {
  display: inline-block;
  width: 0.62ch;
  height: 0.95em;
  margin-left: 0.14ch;
  background: var(--terminal-green);
  box-shadow: 0 0 8px rgb(0 159 35 / 0.42);
  content: "";
  transform: translateY(0.12em);
  animation: terminalBlink 1s steps(2, start) infinite;
}

.terminal-chat__output {
  max-width: 54ch;
  margin: 0;
  color: rgb(0 178 50 / 0.82);
  overflow-wrap: anywhere;
  text-shadow:
    0 0 1px rgb(0 159 35 / 0.36),
    0 0 6px rgb(0 159 35 / 0.12);
}

.terminal-chat__output-line {
  margin: 0;
}

.terminal-chat__output-line p {
  margin: 0;
}

.terminal-chat__output-line p + p {
  margin-top: 0.95em;
}

.terminal-chat__project + .terminal-chat__project {
  margin-top: 1em;
}

.terminal-chat__project-title {
  color: var(--terminal-pink);
  text-shadow:
    0 0 2px rgb(255 20 147 / 0.46),
    0 0 9px rgb(255 20 147 / 0.16);
}

.terminal-chat__output-line + .terminal-chat__output-line {
  margin-top: 0;
}

.terminal-chat__reveal-line {
  opacity: 0;
  transform: translateY(0.28em);
  animation: terminalLineReveal 260ms steps(5, end) forwards;
  animation-delay: var(--terminal-reveal-delay, 0ms);
}

.terminal-chat__output a {
  color: var(--terminal-pink);
  text-decoration: none;
  text-shadow:
    0 0 2px rgb(255 20 147 / 0.46),
    0 0 9px rgb(255 20 147 / 0.16);
}

.terminal-chat__output a:hover,
.terminal-chat__output a:focus-visible {
  color: var(--terminal-green);
  outline: 0;
}

.tetris-game {
  display: grid;
  width: 100%;
  height: 100%;
  min-height: 0;
  grid-template-rows: auto minmax(0, 1fr) auto;
  align-items: center;
  color: var(--terminal-green);
  font-size: var(--tetris-font-size, clamp(14px, 1.8vw, 24px));
  outline: 0;
}

.tetris-game:focus-visible {
  color: var(--terminal-pink);
}

.tetris-game__bar {
  display: flex;
  justify-content: space-between;
  gap: 2ch;
  margin-bottom: 0.5em;
  color: rgb(172 172 188);
  font-size: 0.72em;
}

.tetris-game__board {
  justify-self: center;
  margin: 0;
  color: var(--terminal-green);
  font: inherit;
  line-height: 1;
  white-space: pre;
  text-shadow:
    0 0 2px rgb(0 159 35 / 0.5),
    0 0 10px rgb(0 159 35 / 0.2);
}

.tetris-game__wall {
  color: rgb(255 20 147 / 0.82);
  text-shadow:
    0 0 2px rgb(255 20 147 / 0.42),
    0 0 10px rgb(255 20 147 / 0.18);
}

.tetris-game__piece {
  color: #00d63a;
  text-shadow:
    0 0 2px rgb(0 214 58 / 0.75),
    0 0 8px rgb(0 214 58 / 0.34),
    0 0 16px rgb(0 214 58 / 0.16);
}

.tetris-game__piece--active {
  color: #ff47b0;
  text-shadow:
    0 0 2px rgb(255 71 176 / 0.86),
    0 0 9px rgb(255 71 176 / 0.46),
    0 0 18px rgb(255 71 176 / 0.22);
}

.tetris-game__keys {
  margin-top: 0.7em;
  color: rgb(172 172 188);
  font-size: clamp(12px, 0.48em, 16px);
  line-height: 1.25;
  text-align: center;
}

.tetris-game__touch {
  display: none;
}

.tetris-game__stop {
  display: none;
}

@keyframes terminalBlink {
  50% {
    opacity: 0;
  }
}

@keyframes terminalLineReveal {
  0% {
    opacity: 0;
    transform: translateY(0.28em);
    filter: blur(1px);
  }

  65% {
    opacity: 1;
    filter: blur(0);
  }

  100% {
    opacity: 1;
    transform: translateY(0);
    filter: blur(0);
  }
}

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

#portrait {
  display: block;
  width: 100vw;
  height: 100vh;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#source-face,
#source-face-smile {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

@media (max-width: 820px) {
  html,
  body {
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
  }

  .stage {
    height: 100svh;
    min-height: 100svh;
  }

  .terminal-panel {
    top: max(14px, env(safe-area-inset-top));
    right: auto;
    bottom: auto;
    left: max(12px, env(safe-area-inset-left));
    width: calc(100vw - 24px);
    min-width: 0;
    overflow: visible;
    font-size: clamp(8px, 1.95vw, 13px);
  }

  .terminal-panel::before {
    inset: -14px -18px -16px -12px;
  }

  .terminal-title {
    position: relative;
    z-index: 9;
    width: min(100%, 560px);
    max-width: none;
    margin-bottom: 14px;
  }

  .terminal-shell {
    position: fixed;
    z-index: 7;
    top: calc(var(--portrait-bottom, 62svh) + clamp(10px, 2svh, 18px));
    right: max(12px, env(safe-area-inset-right));
    bottom: max(12px, env(safe-area-inset-bottom));
    left: max(12px, env(safe-area-inset-left));
    display: flex;
    height: auto;
    align-items: flex-end;
    font-size: clamp(12px, 3.35vw, 15px);
    margin-top: 0;
    pointer-events: none;
    -webkit-mask-image: none;
    mask-image: none;
  }

  .terminal-shell.is-mobile-expanded {
    top: clamp(142px, 24svh, 205px);
    height: calc(100svh - clamp(142px, 24svh, 205px) - max(12px, env(safe-area-inset-bottom)));
  }

  .terminal-shell:has(.terminal-chat--tetris) {
    top: clamp(150px, 24svh, 205px);
    right: max(12px, env(safe-area-inset-right));
    bottom: max(12px, env(safe-area-inset-bottom));
    left: max(12px, env(safe-area-inset-left));
    height: auto;
    align-items: stretch;
    -webkit-mask-image: none;
    mask-image: none;
  }

  .terminal-shell::before {
    display: none;
  }

  .terminal-shortcuts {
    display: none;
  }

  .terminal-commands__list {
    max-width: 38ch;
    flex-flow: row wrap;
    column-gap: 1.1ch;
    row-gap: 0.25em;
  }

  .terminal-commands.is-mobile-hidden {
    display: none;
  }

  .terminal-commands:not(.is-help-expanded) [data-mobile-secondary] {
    display: none;
  }

  .terminal-commands,
  .terminal-chat__entry,
  .terminal-chat__input-line {
    background: rgb(0 0 0 / 0.58);
    box-shadow:
      0 0 0 0.35em rgb(0 0 0 / 0.58),
      0 0 18px 8px rgb(0 0 0 / 0.36);
    pointer-events: auto;
  }

  .terminal-commands button {
    flex: 0 0 auto;
    min-height: 2em;
    padding: 0.18em 0;
    touch-action: manipulation;
  }

  .terminal-chat {
    position: relative;
    top: auto;
    right: auto;
    bottom: auto;
    left: auto;
    display: flex;
    width: 100%;
    height: 100%;
    min-height: 0;
    margin-top: 6px;
    padding-top: 0;
    padding-left: 0;
    border: 0;
    font-size: inherit;
    align-items: flex-end;
    pointer-events: auto;
  }

  .terminal-chat__history {
    width: 100%;
    height: 100%;
    max-height: 100%;
    padding: 0;
    overflow-y: auto;
    -webkit-mask-image: none;
    mask-image: none;
  }

  .terminal-chat__line,
  .terminal-chat__input-line {
    white-space: normal;
  }

  .terminal-chat__input {
    min-height: 2em;
  }

  .terminal-chat--tetris .terminal-commands {
    display: none;
  }

  .terminal-chat--tetris .terminal-chat__input-line {
    display: none;
  }

  .terminal-chat--tetris .terminal-chat__entry--tetris {
    inset: 0;
    width: 100%;
    height: 100%;
  }

  .terminal-chat--tetris .terminal-chat__line {
    display: none;
  }

  .terminal-chat--tetris .terminal-chat__output {
    width: 100%;
    height: 100%;
  }

  .terminal-chat--tetris .terminal-chat__output-line {
    display: flex;
    width: 100%;
    height: 100%;
  }

  .terminal-chat--tetris .tetris-game {
    width: 100%;
    height: 100%;
    padding: 0;
    touch-action: none;
  }

  .terminal-chat--tetris .tetris-game__bar {
    margin-bottom: 0.35em;
    padding: 0 0.1ch;
  }

  .terminal-chat--tetris .tetris-game__board {
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
  }

  .tetris-game__keys {
    display: none;
  }

  .tetris-game__stop {
    display: block;
    justify-self: start;
    min-height: 42px;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--terminal-green);
    font: inherit;
    font-size: clamp(16px, 4.6vw, 20px);
    line-height: 1;
    text-align: left;
    text-shadow:
      0 0 2px rgb(0 159 35 / 0.5),
      0 0 10px rgb(0 159 35 / 0.2);
    touch-action: manipulation;
  }

  .tetris-game__stop::before {
    color: var(--terminal-green);
    content: "$ ";
  }

  .tetris-game__stop:active,
  .tetris-game__stop:focus-visible {
    color: var(--terminal-pink);
    outline: 0;
  }

}

@media (max-width: 820px) and (orientation: landscape) {
  .terminal-panel {
    top: max(10px, env(safe-area-inset-top));
    left: max(10px, env(safe-area-inset-left));
    width: calc(100vw - 20px);
    font-size: clamp(8px, 1.55vw, 10px);
  }

  .terminal-title {
    width: min(58vw, 380px);
    margin-bottom: 8px;
  }

  .terminal-shell {
    right: max(10px, env(safe-area-inset-right));
    bottom: max(8px, env(safe-area-inset-bottom));
    left: max(10px, env(safe-area-inset-left));
    top: max(8px, env(safe-area-inset-top));
    height: calc(100svh - max(10px, env(safe-area-inset-top)) - max(8px, env(safe-area-inset-bottom)));
    font-size: clamp(11px, 1.95vw, 13px);
    -webkit-mask-image: linear-gradient(
      to bottom,
      transparent 0,
      transparent clamp(78px, 30svh, 112px),
      #000 clamp(118px, 44svh, 160px),
      #000 100%
    );
    mask-image: linear-gradient(
      to bottom,
      transparent 0,
      transparent clamp(78px, 30svh, 112px),
      #000 clamp(118px, 44svh, 160px),
      #000 100%
    );
  }

  .terminal-chat__history {
    padding-top: clamp(118px, 40svh, 160px);
  }

  .terminal-commands__list {
    max-width: 50ch;
    row-gap: 0.1em;
  }

  .terminal-commands button {
    min-height: 1.8em;
  }

  .terminal-shell:has(.terminal-chat--tetris) {
    top: max(8px, env(safe-area-inset-top));
  }

  .terminal-panel:has(.terminal-chat--tetris) .terminal-title {
    display: none;
  }

  .terminal-chat--tetris .tetris-game__stop {
    min-height: 34px;
    font-size: clamp(14px, 2.2vw, 16px);
  }
}

@media (max-width: 340px) and (orientation: portrait) {
  .terminal-shell {
    top: calc(var(--portrait-bottom, 62svh) + 3px);
    right: max(8px, env(safe-area-inset-right));
    bottom: max(8px, env(safe-area-inset-bottom));
    left: max(8px, env(safe-area-inset-left));
    font-size: 10px;
    line-height: 1.12;
  }

  .terminal-shell.is-mobile-expanded {
    top: clamp(148px, 30svh, 190px);
    height: calc(100svh - clamp(148px, 30svh, 190px) - max(8px, env(safe-area-inset-bottom)));
  }

  .terminal-commands h2 {
    display: none;
  }

  .terminal-commands__list {
    column-gap: 0.8ch;
    row-gap: 0;
  }

  .terminal-commands button {
    min-height: 1.28em;
    padding: 0;
  }

  .terminal-chat {
    margin-top: 1px;
  }

  .terminal-chat__input {
    min-height: 1.3em;
  }
}

@media (min-width: 701px) and (max-width: 820px) and (orientation: portrait) {
  .terminal-title {
    width: min(62vw, 480px);
  }

  .terminal-shell {
    font-size: clamp(13px, 1.8vw, 15px);
  }
}

@media (hover: none) and (pointer: coarse) {
  html,
  body,
  .stage,
  .terminal-panel,
  .terminal-shell {
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
  }

  button,
  a,
  .terminal-title,
  .terminal-commands,
  .terminal-chat,
  .terminal-chat__history,
  .terminal-chat__entry,
  .terminal-chat__output,
  .tetris-game {
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
  }

  .terminal-chat__input {
    user-select: text;
    -webkit-user-select: text;
    -webkit-touch-callout: default;
  }

  #portrait {
    touch-action: none;
  }
}
