/*
  Cairn — the reading surface.

  The brief a text game hands its client is unusual: the prose IS the art, so
  every pixel here exists to get out of its way. That rules out the reflexive
  choice — green-on-black, scanlines, hacker terminal — because that aesthetic
  says COMPUTER, and the whole game is trying to say PLACE. This is built as a
  page from a book that's been in a rucksack: wet slate, bone ink, lamplight.

  The server sends prose as long lines and this page breaks them — pre-wrap
  plus a max-width. The measure below is a reading measure, nothing more: wide
  screens get a comfortable 76ch column, and anything narrower (a phone, a
  split screen) wraps to its actual width instead of fighting breaks the
  server guessed at. Only telnet gets server-side wrapping.
*/

:root {
  --measure: 76ch;

  --bg: #0e1013;
  --bg-raised: #14171c;
  --ink: #cfc9bd;
  --ink-bright: #f0eade;
  --ink-dim: #6c737e;
  --rule: #21252c;

  /* ANSI, translated out of terminal-primary and into weather. */
  --c-cyan: #7fa5a8;
  --c-yellow: #cf9d5e;
  --c-red: #b0574c;
  --c-green: #7f9463;
  --c-blue: #6d84a8;
  --c-magenta: #9c7292;
  --c-gray: #6c737e;

  --sky: #101a2e;
  --sky-strength: 0.5;

  --ease: cubic-bezier(0.2, 0.6, 0.2, 1);
}

:root[data-theme='paper'] {
  --bg: #e7e2d6;
  --bg-raised: #f1ede3;
  --ink: #33302a;
  --ink-bright: #14120e;
  --ink-dim: #8a8375;
  --rule: #d2cbbc;

  --c-cyan: #3f6a70;
  --c-yellow: #94661f;
  --c-red: #97372c;
  --c-green: #4e6535;
  --c-blue: #3f5680;
  --c-magenta: #77456b;
  --c-gray: #8a8375;

  --sky: #c9c0aa;
  --sky-strength: 0.55;
}

/*
  The world's clock, on the page.

  The server pushes the hour; this shifts the light behind the text. The
  transition is a full minute on purpose — you are never supposed to catch it
  moving. You look up and it's evening, the same way it happens outdoors.
*/
:root[data-light='dawn'] { --sky: #263a52; --sky-strength: 0.55; }
:root[data-light='day'] { --sky: #1b2733; --sky-strength: 0.4; }
:root[data-light='dusk'] { --sky: #4a2f22; --sky-strength: 0.6; }
:root[data-light='night'] { --sky: #0b1020; --sky-strength: 0.75; }

:root[data-theme='paper'][data-light='dawn'] { --sky: #b9c3d0; }
:root[data-theme='paper'][data-light='day'] { --sky: #cdc6b2; }
:root[data-theme='paper'][data-light='dusk'] { --sky: #d8bb9a; }
:root[data-theme='paper'][data-light='night'] { --sky: #a8adba; }

* {
  box-sizing: border-box;
  margin: 0;
}

html,
body {
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: 'IBM Plex Mono', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  font-size: 15px;
  font-weight: 400;
  line-height: 1.68;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  transition: background-color 1.2s var(--ease), color 1.2s var(--ease);
}

/* Light, coming from up there somewhere. */
.sky {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background: radial-gradient(
    120% 70% at 50% -10%,
    color-mix(in oklab, var(--sky) calc(var(--sky-strength) * 100%), transparent),
    transparent 70%
  );
  transition: background 60s linear;
}

/* Stone has tooth. Paper has tooth. Screens don't, unless you give them some. */
.grain {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  opacity: 0.035;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)'/%3E%3C/svg%3E");
}

.page {
  position: relative;
  z-index: 2;
  height: 100%;
  display: grid;
  grid-template-rows: auto 1fr auto;
  max-width: calc(var(--measure) + 6rem);
  margin: 0 auto;
  padding: 0 3rem;
}

@media (max-width: 640px) {
  .page {
    padding: 0 1.1rem;
  }
  body {
    font-size: 14px;
  }
}

/* ---- chrome: as little as possible, as quiet as possible ---- */

.chrome {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.4rem 0 0.9rem;
  border-bottom: 1px solid var(--rule);
}

.brand {
  font-family: 'IBM Plex Serif', Georgia, serif;
  font-size: 0.95rem;
  font-weight: 300;
  font-style: italic;
  letter-spacing: 0.14em;
  color: var(--ink-dim);
}

.chrome-right {
  display: flex;
  align-items: baseline;
  gap: 1.2rem;
}

.theme,
.status {
  font-size: 0.7rem;
  letter-spacing: 0.16em;
  text-transform: lowercase;
  color: var(--ink-dim);
}

.theme {
  background: none;
  border: 0;
  padding: 0;
  font-family: inherit;
  cursor: pointer;
  border-bottom: 1px solid transparent;
  transition: color 0.25s var(--ease), border-color 0.25s var(--ease);
}

.theme:hover {
  color: var(--ink);
  border-bottom-color: var(--rule);
}

.status::before {
  content: '';
  display: inline-block;
  width: 5px;
  height: 5px;
  margin-right: 0.5rem;
  border-radius: 50%;
  background: currentColor;
  vertical-align: middle;
}

.status[data-state='connecting'] {
  animation: breathe 1.6s ease-in-out infinite;
}
.status[data-state='open'] {
  color: var(--c-green);
}
.status[data-state='closed'] {
  color: var(--c-red);
  cursor: pointer;
}

@keyframes breathe {
  50% {
    opacity: 0.35;
  }
}

/* ---- the log ---- */

.log {
  overflow-y: auto;
  padding: 1.6rem 0 1rem;
  white-space: pre-wrap;
  word-break: break-word;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--rule) transparent;
}

.log::-webkit-scrollbar {
  width: 10px;
}
.log::-webkit-scrollbar-thumb {
  background: var(--rule);
  border-radius: 10px;
}

/* Text surfaces rather than snaps. Short enough not to slow down reading. */
.chunk {
  animation: surface 0.34s var(--ease) both;
}

@keyframes surface {
  from {
    opacity: 0;
    transform: translateY(1px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .chunk {
    animation: none;
  }
  .sky {
    transition: none;
  }
}

.b {
  color: var(--ink-bright);
  font-weight: 500;
}
.d {
  color: var(--ink-dim);
}
.fg-red { color: var(--c-red); }
.fg-green { color: var(--c-green); }
.fg-yellow { color: var(--c-yellow); }
.fg-blue { color: var(--c-blue); }
.fg-magenta { color: var(--c-magenta); }
.fg-cyan { color: var(--c-cyan); }
.fg-white { color: var(--ink-bright); }
.fg-gray { color: var(--c-gray); }

/* Room titles carry the weight. They're the only thing here allowed to. */
.fg-cyan.b {
  font-weight: 500;
  letter-spacing: 0.03em;
}

/* ---- the prompt ---- */

.prompt {
  display: flex;
  align-items: baseline;
  gap: 0.7rem;
  padding: 0.9rem 0 1.5rem;
  border-top: 1px solid var(--rule);
}

.caret {
  color: var(--ink-dim);
  user-select: none;
  transition: color 0.25s var(--ease);
}

.prompt:focus-within .caret {
  color: var(--c-yellow);
}

.input {
  flex: 1;
  background: none;
  border: 0;
  padding: 0;
  color: var(--ink-bright);
  font: inherit;
  caret-color: var(--c-yellow);
}

.input:focus {
  outline: none;
}

.input::placeholder {
  color: var(--ink-dim);
}
