@font-face {
  font-family: "JetBrains Mono";
  src: url("./assets/fonts/jetbrains-mono-400.woff2") format("woff2");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

@font-face {
  font-family: "JetBrains Mono";
  src: url("./assets/fonts/jetbrains-mono-500.woff2") format("woff2");
  font-style: normal;
  font-weight: 500;
  font-display: swap;
}

@font-face {
  font-family: "Great Vibes";
  src: url("./assets/fonts/great-vibes-400.woff2") format("woff2");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

:root {
  color-scheme: dark;
  --ice: rgba(232, 244, 255, 0.9);
  --ice-soft: rgba(213, 232, 246, 0.78);
  --violet: rgba(205, 185, 255, 0.92);
  --blue: rgba(146, 218, 255, 0.94);
  --cyan: rgba(161, 241, 235, 0.9);
  --gold: rgba(255, 224, 160, 0.9);
  --comment: rgba(126, 153, 181, 0.62);
  --line-number: rgba(190, 208, 225, 0.36);
  --tree-x: 68%;
  --code-width: 35vw;
}

* {
  box-sizing: border-box;
}

html,
body,
#experience {
  width: 100%;
  height: 100%;
  height: 100dvh;
  margin: 0;
  overflow: hidden;
}

body {
  background: #020812;
  color: var(--ice);
  font-family: "JetBrains Mono", monospace;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

button,
input,
textarea {
  font: inherit;
}

[hidden] {
  display: none !important;
}

#experience {
  position: relative;
  isolation: isolate;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  outline: none;
}

.code-overlay {
  position: fixed;
  z-index: 4;
  top: clamp(3.8rem, 8.4vh, 6.6rem);
  left: clamp(1.1rem, 3.7vw, 4.2rem);
  width: var(--code-width);
  max-width: 650px;
  height: clamp(310px, 67vh, 690px);
  pointer-events: none;
  background: transparent;
  opacity: 1;
  transform: translate3d(0, 0, 0);
  transition:
    opacity 680ms cubic-bezier(0.22, 1, 0.36, 1),
    transform 760ms cubic-bezier(0.22, 1, 0.36, 1);
  will-change: opacity, transform;
}

.code-overlay.is-hidden {
  opacity: 0;
  transform: translate3d(-18px, 0, 0);
}

.code-tabs {
  display: flex;
  align-items: flex-end;
  gap: clamp(0.8rem, 1.8vw, 1.7rem);
  min-height: 2.1rem;
  margin: 0 0 0.72rem;
  padding: 0;
  overflow: hidden;
  background: transparent;
  white-space: nowrap;
}

.code-tab {
  position: relative;
  flex: 0 0 auto;
  margin: 0;
  padding: 0 0 0.42rem;
  border: 0;
  outline: 0;
  color: rgba(164, 196, 216, 0.45);
  background: transparent;
  font-size: clamp(0.56rem, 0.62vw, 0.69rem);
  font-weight: 500;
  letter-spacing: 0.035em;
  text-shadow: 0 1px 8px rgba(0, 8, 18, 0.5);
  transition: color 400ms ease;
}

.code-tab.is-active {
  color: rgba(224, 244, 255, 0.9);
}

.code-tab.is-active::after {
  content: "";
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  height: 1px;
  background: linear-gradient(90deg, rgba(151, 223, 255, 0.7), rgba(209, 184, 255, 0.06));
  box-shadow: 0 0 9px rgba(137, 219, 255, 0.32);
}

.code-viewport {
  position: relative;
  display: grid;
  grid-template-columns: clamp(1.9rem, 2.7vw, 2.8rem) minmax(0, 1fr);
  height: calc(100% - 2.9rem);
  overflow-x: hidden;
  overflow-y: auto;
  background: transparent;
  scrollbar-color: rgba(186, 220, 240, 0.2) transparent;
  scrollbar-width: thin;
  scroll-behavior: smooth;
}

.code-viewport::-webkit-scrollbar,
.code-content::-webkit-scrollbar,
.line-numbers::-webkit-scrollbar {
  width: 3px;
  height: 3px;
  background: transparent;
}

.code-viewport::-webkit-scrollbar-track,
.code-content::-webkit-scrollbar-track,
.line-numbers::-webkit-scrollbar-track {
  background: transparent;
}

.code-viewport::-webkit-scrollbar-thumb,
.code-content::-webkit-scrollbar-thumb,
.line-numbers::-webkit-scrollbar-thumb {
  background: rgba(183, 218, 237, 0.17);
}

.line-numbers,
.code-content {
  height: auto;
  min-height: 100%;
  margin: 0;
  padding: 0;
  overflow: visible;
  background: transparent;
  font-family: "JetBrains Mono", monospace;
  font-size: clamp(0.61rem, 0.76vw, 0.82rem);
  font-variant-ligatures: none;
  line-height: 1.68;
  text-align: left;
  white-space: pre;
  text-shadow:
    0 1px 2px rgba(0, 3, 9, 0.9),
    0 2px 9px rgba(0, 6, 14, 0.65);
}

.line-numbers {
  padding-right: clamp(0.45rem, 0.8vw, 0.8rem);
  color: var(--line-number);
  text-align: right;
  opacity: 0.94;
}

.code-content {
  position: relative;
  min-width: 0;
  color: var(--ice-soft);
}

.code-line,
.number-line {
  position: relative;
  min-height: 1.68em;
  background: transparent;
  transition: color 160ms ease, opacity 240ms ease;
}

.code-line {
  padding-right: 1.2rem;
  opacity: 0;
  color: rgba(220, 237, 248, 0.8);
}

.code-line.is-visible {
  opacity: 0.82;
}

.code-line.is-current {
  opacity: 1;
  color: rgba(244, 250, 255, 0.96);
}

.code-line.is-current::before {
  content: "";
  position: absolute;
  top: 0.31em;
  bottom: 0.31em;
  left: -0.46rem;
  width: 1px;
  background: linear-gradient(180deg, transparent, rgba(144, 222, 255, 0.86), transparent);
  box-shadow: 0 0 8px rgba(127, 217, 255, 0.55);
}

.code-line.is-current::after {
  content: "";
  display: inline-block;
  width: 1px;
  height: 1.08em;
  margin-left: 1px;
  vertical-align: -0.16em;
  background: rgba(218, 242, 255, 0.9);
  animation: caret-blink 1.05s step-end infinite;
}

.code-line.is-event-sync {
  animation: code-sync 1.9s ease-out;
}

@keyframes code-sync {
  0% {
    color: rgba(255, 247, 219, 1);
    text-shadow:
      0 0 8px rgba(160, 226, 255, 0.62),
      0 2px 10px rgba(0, 5, 13, 0.8);
  }

  100% {
    color: rgba(220, 237, 248, 0.8);
    text-shadow:
      0 1px 2px rgba(0, 3, 9, 0.9),
      0 2px 9px rgba(0, 6, 14, 0.65);
  }
}

.code-line.is-sensitive .tok-keyword {
  color: var(--violet);
}

.tok-keyword {
  color: var(--violet);
}

.tok-function {
  color: var(--blue);
}

.tok-string {
  color: var(--cyan);
}

.tok-number {
  color: var(--gold);
}

.tok-comment {
  color: var(--comment);
  font-style: normal;
}

.tok-type {
  color: rgba(174, 211, 255, 0.83);
}

@keyframes caret-blink {
  0%,
  46% {
    opacity: 0.94;
  }

  47%,
  100% {
    opacity: 0;
  }
}

.terminal {
  position: fixed;
  z-index: 5;
  bottom: clamp(1.2rem, 3.2vh, 2.7rem);
  left: clamp(1.1rem, 3.7vw, 4.2rem);
  width: min(var(--code-width), 610px);
  min-height: 9.2rem;
  pointer-events: none;
  overflow: hidden;
  background: transparent;
}

.terminal-title {
  display: flex;
  align-items: center;
  gap: 0.54rem;
  margin-bottom: 0.62rem;
  color: rgba(190, 221, 238, 0.52);
  font-size: clamp(0.5rem, 0.56vw, 0.61rem);
  font-weight: 500;
  letter-spacing: 0.12em;
  text-shadow: 0 1px 6px rgba(0, 3, 9, 0.8);
}

.terminal-pulse {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: rgba(143, 238, 201, 0.9);
  box-shadow: 0 0 8px rgba(111, 241, 188, 0.8);
}

.terminal-lines {
  display: flex;
  flex-direction: column;
  gap: 0.29rem;
  background: transparent;
}

.terminal-line {
  margin: 0;
  color: rgba(190, 219, 235, 0.7);
  font-size: clamp(0.51rem, 0.61vw, 0.66rem);
  line-height: 1.55;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
  text-shadow:
    0 1px 2px rgba(0, 2, 7, 0.94),
    0 2px 7px rgba(0, 4, 10, 0.78);
  animation: terminal-in 700ms ease both;
  transition: opacity 900ms ease;
}

.terminal-line.is-old {
  opacity: 0.25;
}

.terminal-line .log-time {
  margin-right: 0.62rem;
  color: rgba(142, 179, 203, 0.41);
}

.terminal-line.is-event {
  color: rgba(218, 245, 255, 0.82);
}

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

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.control-note {
  position: fixed;
  z-index: 5;
  right: clamp(1.1rem, 3vw, 3rem);
  bottom: clamp(1.2rem, 3.1vh, 2.6rem);
  display: flex;
  align-items: center;
  gap: 0.45rem;
  color: rgba(185, 216, 234, 0.42);
  font-size: clamp(0.49rem, 0.56vw, 0.61rem);
  letter-spacing: 0.1em;
  pointer-events: none;
  text-shadow: 0 1px 5px rgba(0, 2, 7, 0.86);
  transition: opacity 300ms ease;
}

.control-note span {
  color: rgba(222, 243, 255, 0.72);
}

.control-note i {
  width: 1px;
  height: 0.78em;
  background: rgba(174, 211, 231, 0.2);
}

.auto-badge {
  position: fixed;
  z-index: 6;
  top: max(1rem, env(safe-area-inset-top));
  right: max(1rem, env(safe-area-inset-right));
  color: rgba(182, 222, 232, 0.44);
  font-size: clamp(0.48rem, 0.54vw, 0.59rem);
  letter-spacing: 0.13em;
  pointer-events: none;
  text-shadow: 0 1px 6px rgba(0, 2, 7, 0.9);
}

.auto-badge strong {
  color: rgba(163, 242, 211, 0.78);
  font-weight: 500;
}

.interaction-hint {
  position: fixed;
  z-index: 6;
  right: max(1rem, env(safe-area-inset-right));
  bottom: calc(max(4.2rem, env(safe-area-inset-bottom)) + 1.9rem);
  margin: 0;
  color: rgba(185, 216, 234, 0.44);
  font-size: clamp(0.48rem, 0.54vw, 0.6rem);
  letter-spacing: 0.08em;
  pointer-events: none;
  text-align: right;
  text-shadow: 0 1px 6px rgba(0, 2, 7, 0.9);
}

.touch-controls {
  position: fixed;
  z-index: 10;
  right: max(1rem, env(safe-area-inset-right));
  bottom: max(1rem, env(safe-area-inset-bottom));
  display: flex;
  gap: 0.55rem;
}

.control-button {
  min-width: 5.8rem;
  min-height: 2.75rem;
  padding: 0.68rem 0.9rem;
  border: 1px solid rgba(173, 221, 242, 0.24);
  border-radius: 999px;
  color: rgba(222, 243, 255, 0.76);
  background: rgba(2, 10, 22, 0.42);
  box-shadow: inset 0 0 18px rgba(133, 214, 255, 0.025);
  font-size: 0.58rem;
  letter-spacing: 0.1em;
  touch-action: manipulation;
}

.control-button:active,
.control-button[aria-pressed="true"] {
  border-color: rgba(161, 241, 235, 0.62);
  color: rgba(236, 255, 250, 0.94);
  background: rgba(17, 55, 60, 0.42);
}

.control-button:focus-visible {
  outline: 2px solid rgba(161, 241, 235, 0.75);
  outline-offset: 3px;
}

.loading {
  position: fixed;
  z-index: 20;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 1.2rem;
  color: rgba(208, 235, 249, 0.64);
  background: #020812;
  transition: opacity 1.2s ease, visibility 1.2s;
}

.loading.is-complete {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loading p {
  margin: 0;
  font-size: 0.58rem;
  letter-spacing: 0.18em;
  text-align: center;
}

.loading-mark {
  position: relative;
  width: 46px;
  height: 46px;
  margin: 0 auto;
}

.loading-mark span {
  position: absolute;
  inset: 0;
  border: 1px solid rgba(146, 216, 255, 0.23);
  border-radius: 50%;
  animation: loading-orbit 2.2s linear infinite;
}

.loading-mark span:nth-child(2) {
  inset: 8px;
  animation-duration: 1.5s;
  animation-direction: reverse;
}

.loading-mark span:nth-child(3) {
  inset: 17px;
  border-color: rgba(255, 221, 160, 0.56);
  box-shadow: 0 0 18px rgba(255, 228, 168, 0.18);
}

@keyframes loading-orbit {
  to {
    transform: rotate(360deg);
  }
}

.fatal-error {
  position: fixed;
  z-index: 30;
  top: 50%;
  left: 50%;
  width: min(32rem, calc(100vw - 3rem));
  transform: translate(-50%, -50%);
  color: rgba(255, 224, 224, 0.92);
  font-size: 0.76rem;
  line-height: 1.7;
  text-align: center;
}

.fatal-title {
  margin: 0 0 0.8rem;
  font-size: 0.82rem;
  letter-spacing: 0.06em;
}

#camera-source {
  position: fixed;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

body.code-is-hidden .terminal {
  opacity: 0.58;
}

body.code-is-hidden .control-note span:first-child {
  color: rgba(255, 225, 164, 0.86);
}

@media (max-width: 1050px) {
  :root {
    --code-width: 38vw;
  }

  .code-overlay {
    left: 2.1rem;
  }

  .line-numbers,
  .code-content {
    font-size: clamp(0.57rem, 0.8vw, 0.72rem);
  }
}

@media (max-width: 760px), (orientation: portrait) {
  :root {
    --code-width: 43vw;
  }

  .code-overlay {
    top: 6.5vh;
    left: 1rem;
    height: 52vh;
  }

  .terminal {
    bottom: 2.4vh;
    left: 1rem;
    width: 43vw;
    min-height: 7rem;
  }

  .control-note {
    right: 1rem;
    bottom: 2.2vh;
  }

  .auto-badge {
    top: max(0.85rem, env(safe-area-inset-top));
  }

  .interaction-hint {
    right: 1rem;
    bottom: calc(max(4.15rem, env(safe-area-inset-bottom)) + 1.4rem);
  }

  .touch-controls {
    right: 50%;
    bottom: max(0.8rem, env(safe-area-inset-bottom));
    transform: translateX(50%);
  }

  .control-button {
    min-width: 6.4rem;
    font-size: 0.53rem;
  }

  .line-numbers,
  .code-content {
    font-size: clamp(0.48rem, 1.45vw, 0.62rem);
  }
}

@media (pointer: coarse) {
  .terminal {
    display: none;
  }

  .code-overlay {
    top: max(4.5rem, calc(env(safe-area-inset-top) + 3.5rem));
    left: max(0.8rem, env(safe-area-inset-left));
    width: min(82vw, 31rem);
    height: 48vh;
  }

  .interaction-hint {
    display: block;
  }
}

@media (max-width: 430px) {
  .interaction-hint {
    font-size: 0.45rem;
    letter-spacing: 0.04em;
  }
}

@media (prefers-reduced-motion: reduce) {
  .code-line.is-current::after {
    animation-duration: 2s;
  }
}
