/* C022: Digital Forest terminal app stylesheet for apps/digital-forest/index.html. */
:root {
  --df-bg: #000000;
  --df-red: #E1192D;
  --df-red-soft: rgba(225, 25, 45, .16);
  --df-red-faint: rgba(225, 25, 45, .08);
  --df-red-strong: #E1192D;
  --df-text-dim: rgba(225, 25, 45, .68);
  --df-border: rgba(225, 25, 45, .34);
  --df-font: ui-monospace, SFMono-Regular, "SF Mono", Consolas, "Liberation Mono", Menlo, monospace;
  --df-menu-height: 58px;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
  background: var(--df-bg);
  color: var(--df-red);
  font-family: var(--df-font);
}

::-moz-selection {
  background-color: #E1192D;
  color: #ffffff;
}

::selection {
  background-color: #E1192D;
  color: #ffffff;
}

/* C022: Fullscreen class is toggled by script.js after the browser fullscreen API changes. */
html.is-df-fullscreen,
html.is-df-fullscreen body {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

body {
  overflow-x: hidden;
}

body::before,
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 5;
  pointer-events: none;
}

body::before {
  background:
    repeating-linear-gradient(
      180deg,
      rgba(225, 25, 45, .035) 0,
      rgba(225, 25, 45, .035) 1px,
      transparent 1px,
      transparent 4px
    );
  opacity: 0;
  transition: opacity 2.6s ease;
}

body::after {
  background:
    radial-gradient(circle at 20% 10%, rgba(225, 25, 45, .06), transparent 18rem),
    radial-gradient(circle at 84% 78%, rgba(225, 25, 45, .05), transparent 22rem),
    linear-gradient(90deg, transparent, rgba(225, 25, 45, .025), transparent);
  mix-blend-mode: screen;
  opacity: 0;
  animation: df-noise-drift 9s steps(6) infinite;
  transition: opacity 3s ease;
}

body.is-awake::before {
  opacity: .66;
}

body.is-awake::after {
  opacity: .88;
}

a {
  color: inherit;
}

button,
input {
  font: inherit;
}

.df-skip-link {
  position: fixed;
  left: 1rem;
  top: 1rem;
  z-index: 30;
  transform: translateY(-150%);
  border: 1px solid var(--df-border);
  background: #050000;
  color: var(--df-red-strong);
  padding: .75rem 1rem;
  text-decoration: none;
}

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

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

/* C022: Header status, fullscreen button, shell, and terminal markup match index.html data hooks. */
.df-menu-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 1rem;
  height: var(--df-menu-height);
  border: 1px solid rgba(225, 25, 45, .24);
  background: rgba(0, 0, 0, .78);
  box-shadow:
    0 0 20px rgba(225, 25, 45, .08),
    inset 0 0 24px rgba(225, 25, 45, .045);
  opacity: 0;
  padding: .45rem;
  transition: opacity 2.6s ease;
}

body.is-awake .df-menu-bar {
  opacity: .76;
}

.df-menu-title {
  min-width: 0;
  color: var(--df-text-dim);
  font-size: .82rem;
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow: 0 0 10px var(--df-red-soft);
  white-space: nowrap;
}

.df-status {
  min-width: 0;
  display: grid;
  gap: .08rem;
  color: var(--df-text-dim);
  font-size: clamp(.62rem, 1.1vw, .76rem);
  line-height: 1.12;
  text-shadow: 0 0 10px var(--df-red-soft);
  text-transform: uppercase;
}

.df-status span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.df-menu-actions {
  display: flex;
  align-items: center;
  flex: 0 0 auto;
  gap: .35rem;
}

.df-exit,
.df-fullscreen {
  border: 1px solid rgba(225, 25, 45, .28);
  background: rgba(0, 0, 0, .72);
  color: rgba(225, 25, 45, .72);
  cursor: pointer;
  min-height: 28px;
  padding: .28rem .48rem;
  font-size: .72rem;
  text-decoration: none;
  text-transform: uppercase;
  letter-spacing: 0;
  line-height: 1;
  transition: border-color .2s ease, color .2s ease, background .2s ease;
}

.df-exit:hover,
.df-exit:focus-visible,
.df-fullscreen:hover,
.df-fullscreen:focus-visible {
  background: rgba(28, 0, 0, .82);
  border-color: var(--df-red);
  color: var(--df-red-strong);
  outline: none;
}

.df-shell {
  position: relative;
  z-index: 10;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding:
    calc(var(--df-menu-height) + clamp(1rem, 4vw, 3rem))
    clamp(1rem, 4vw, 3rem)
    clamp(1rem, 4vw, 3rem);
  opacity: 0;
  filter: blur(10px);
  transform: scale(.985);
  transition: opacity 4.2s ease, filter 4.2s ease, transform 4.2s ease;
}

body.is-awake .df-shell {
  animation: df-view-flicker 1.05s steps(1, end) both;
  opacity: 1;
  filter: blur(0);
  transform: scale(1);
}

/* C022: Terminal transcript, choices, and command form are populated by DigitalForestTerminal. */
.df-terminal {
  position: relative;
  width: min(100%, 980px);
  height: min(82vh, 760px);
  min-height: min(82vh, 760px);
  display: grid;
  grid-template-rows: minmax(360px, 1fr) auto auto;
  gap: 1rem;
  border: 1px solid var(--df-border);
  background:
    linear-gradient(180deg, rgba(225, 25, 45, .04), transparent 16rem),
    rgba(0, 0, 0, .92);
  box-shadow:
    0 0 32px rgba(225, 25, 45, .11),
    inset 0 0 40px rgba(225, 25, 45, .08);
  clip-path: inset(0);
  overflow: hidden;
  padding: clamp(1rem, 3vw, 1.45rem);
  transform-origin: center;
}

.df-terminal::before {
  content: "";
  position: absolute;
  inset: -1px;
  border: 1px solid rgba(225, 25, 45, .14);
  pointer-events: none;
  transform: translate(3px, -3px);
}

.df-terminal > * {
  position: relative;
  z-index: 1;
}

body:not(.is-awake) .df-terminal > * {
  opacity: 0;
}

body.is-awake .df-terminal {
  animation: df-terminal-draw 1.25s steps(9, end) .08s both;
}

body.is-awake .df-terminal > * {
  animation: df-terminal-content 1.1s steps(5, end) .46s both;
}

html.is-df-fullscreen .df-shell {
  width: 100vw;
  height: 100vh;
  min-height: 100vh;
  margin-top: 0;
  place-items: stretch;
  padding: 0;
}

html.is-df-fullscreen .df-terminal {
  width: 100vw;
  height: 100vh;
  min-height: 100vh;
  border-color: rgba(225, 25, 45, .42);
  border-radius: 0;
  grid-template-rows: minmax(0, 1fr) auto auto;
  padding:
    calc(var(--df-menu-height) + clamp(.75rem, 2vw, 1.2rem))
    clamp(.85rem, 2vw, 1.35rem)
    clamp(.85rem, 2vw, 1.35rem);
}

html.is-df-fullscreen .df-menu-bar {
  top: 0;
  left: 0;
  right: 0;
  opacity: 1;
}

html.is-df-fullscreen .df-terminal::before {
  inset: 0;
  transform: none;
}

.df-transcript {
  min-height: 0;
  overflow: auto;
  padding-right: .35rem;
  scrollbar-color: rgba(225, 25, 45, .38) transparent;
}

.df-line {
  margin: 0 0 .62rem;
  color: var(--df-red);
  line-height: 1.55;
  text-shadow: 0 0 12px rgba(225, 25, 45, .32);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.df-block {
  max-width: 100%;
  margin: .35rem 0 1rem;
  color: var(--df-red-strong);
  font: inherit;
  line-height: 1.08;
  overflow-x: auto;
  white-space: pre;
  text-shadow:
    0 0 12px rgba(225, 25, 45, .46),
    2px 0 0 rgba(225, 25, 45, .12);
}

.df-block-title-art {
  font-size: clamp(.37rem, 1.05vw, .82rem);
  letter-spacing: 0;
}

.df-block-map {
  width: fit-content;
  border-left: 1px solid rgba(225, 25, 45, .36);
  color: color-mix(in srgb, var(--df-red), transparent 8%);
  font-size: clamp(.74rem, 2vw, .98rem);
  padding-left: .85rem;
}

.df-line-title {
  margin-top: .35rem;
  color: var(--df-red-strong);
  font-size: clamp(1.15rem, 4vw, 2.1rem);
  line-height: 1.05;
  text-transform: uppercase;
  text-shadow:
    0 0 12px rgba(225, 25, 45, .55),
    2px 0 0 rgba(225, 25, 45, .18);
}

.df-line-marker,
.df-line-system,
.df-line-checkpoint {
  color: var(--df-text-dim);
}

.df-line-marker {
  text-transform: uppercase;
}

.df-line-alert {
  color: #E1192D;
}

.df-line-input {
  color: #E1192D;
}

.df-choices {
  display: flex;
  flex-wrap: wrap;
  gap: .45rem;
}

/* C022: Choice buttons are generated from visible room choices in engine/state.js. */
.df-choice {
  min-height: 28px;
  border: 1px solid rgba(225, 25, 45, .3);
  background: rgba(225, 25, 45, .055);
  color: var(--df-red-strong);
  cursor: pointer;
  padding: .28rem .52rem;
  font-size: .84rem;
  line-height: 1.1;
  text-align: left;
  text-shadow: 0 0 10px var(--df-red-soft);
  transition: background .2s ease, border-color .2s ease, transform .2s ease;
}

.df-choice:hover,
.df-choice:focus-visible {
  border-color: rgba(225, 25, 45, .7);
  background: rgba(225, 25, 45, .11);
  outline: none;
  transform: translateY(-1px);
}

.df-choice:disabled {
  cursor: wait;
  opacity: .58;
}

.df-command {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: .55rem;
  border-top: 1px solid rgba(225, 25, 45, .22);
  padding-top: 1rem;
}

.df-prompt {
  color: #E1192D;
  text-shadow: 0 0 10px var(--df-red-soft);
}

.df-command input {
  width: 100%;
  min-height: 34px;
  border: 1px solid rgba(225, 25, 45, .24);
  background: rgba(0, 0, 0, .68);
  color: var(--df-red-strong);
  caret-color: #ffffff;
  padding: .42rem .6rem;
  outline: none;
  text-shadow: 0 0 10px var(--df-red-soft);
}

.df-command input:focus {
  border-color: rgba(225, 25, 45, .66);
  box-shadow: 0 0 20px rgba(225, 25, 45, .13);
}

.df-command button {
  min-height: 30px;
  border: 1px solid rgba(225, 25, 45, .34);
  background: rgba(225, 25, 45, .08);
  color: var(--df-red-strong);
  cursor: pointer;
  padding: .34rem .58rem;
  font-size: .78rem;
  line-height: 1;
  text-transform: uppercase;
  transition: background .2s ease, border-color .2s ease;
}

.df-command button:hover,
.df-command button:focus-visible {
  border-color: rgba(225, 25, 45, .76);
  background: rgba(225, 25, 45, .14);
  outline: none;
}

.df-command button:disabled,
.df-command input:disabled {
  cursor: wait;
  opacity: .62;
}

@keyframes df-noise-drift {
  0% {
    transform: translate3d(0, 0, 0);
  }

  30% {
    transform: translate3d(1.5%, -.75%, 0);
  }

  70% {
    transform: translate3d(-.8%, 1%, 0);
  }

  100% {
    transform: translate3d(0, 0, 0);
  }
}

@keyframes df-view-flicker {
  0%,
  7%,
  16%,
  28%,
  42% {
    opacity: 0;
    filter: blur(10px) brightness(.2);
    transform: scale(.985);
  }

  4%,
  12%,
  22%,
  34%,
  52% {
    opacity: 1;
    filter: blur(1px) brightness(1.35);
    transform: scale(1);
  }

  65% {
    opacity: .18;
    filter: blur(3px) brightness(.55);
  }

  72%,
  100% {
    opacity: 1;
    filter: blur(0) brightness(1);
    transform: scale(1);
  }
}

@keyframes df-terminal-draw {
  0% {
    border-color: rgba(225, 25, 45, 0);
    clip-path: inset(49% 50% 49% 50%);
    box-shadow: 0 0 0 rgba(225, 25, 45, 0), inset 0 0 0 rgba(225, 25, 45, 0);
    transform: translateY(8px) scale(.985);
  }

  18% {
    border-color: rgba(225, 25, 45, .72);
    clip-path: inset(49% 0 49% 0);
    transform: translateY(0) scale(1);
  }

  38% {
    clip-path: inset(0 0 0 0);
  }

  58% {
    border-color: rgba(225, 25, 45, .2);
    transform: translateX(-2px);
  }

  66% {
    transform: translateX(2px);
  }

  100% {
    border-color: var(--df-border);
    clip-path: inset(0);
    box-shadow:
      0 0 32px rgba(225, 25, 45, .11),
      inset 0 0 40px rgba(225, 25, 45, .08);
    transform: translateX(0) scale(1);
  }
}

@keyframes df-terminal-content {
  0%,
  35% {
    opacity: 0;
  }

  48% {
    opacity: .35;
  }

  56% {
    opacity: .12;
  }

  100% {
    opacity: 1;
  }
}

@media (max-width: 700px) {
  .df-shell {
    padding: calc(var(--df-menu-height) + 1.1rem) .7rem .7rem;
    place-items: stretch;
  }

  .df-terminal {
    height: calc(100vh - var(--df-menu-height) - 1.8rem);
    min-height: calc(100vh - var(--df-menu-height) - 1.8rem);
    grid-template-rows: minmax(280px, 1fr) auto auto;
  }

  .df-command {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .df-command button {
    grid-column: 2;
    justify-self: start;
  }

  .df-menu-bar {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: .4rem;
  }

  .df-menu-title {
    display: none;
  }

  .df-status {
    font-size: .58rem;
  }

  .df-exit,
  .df-fullscreen {
    min-height: 28px;
    padding: .28rem .42rem;
    font-size: .68rem;
  }
}

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

  .df-shell {
    filter: none;
    transform: none;
  }
}
