:root {
  color-scheme: dark;

  --oak: #1b1410;
  --screen: #120f0c;
  --panel: var(--screen);
  --ink: #e9dcc0;
  --dim: #9c8c70;
  --amber: #f2b544;
  --moss: #8fc28a;
  --rust: #e07a5f;
  --edge: #3a2c20;
  --display: "IM Fell English SC", Georgia, "Times New Roman", serif;
  --mono: "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;
}

body {
  margin: 0;
  background: var(--oak);
  color: var(--ink);
  font-family: var(--mono);
  display: flex;
  flex-direction: column;
  touch-action: manipulation;
}

h1 {
  font-family: var(--display);
  font-weight: 400;
  color: var(--amber);
  margin: 0;
}

code {
  color: var(--amber);
  background: rgb(242 181 68 / 10%);
  padding: 0 4px;
  border-radius: 3px;
  font-family: var(--mono);
}

/* Quest board */
.quest-board,
.quest-board *,
.tower-adventure,
.tower-adventure * {
  box-sizing: border-box;
}

.quest-board {
  min-height: 100dvh;
  line-height: 1.6;
  padding: 24px max(20px, env(safe-area-inset-left)) 40px
    max(20px, env(safe-area-inset-right));
  align-items: center;
}

.quest-board header {
  text-align: center;
  max-width: 46rem;
  margin-bottom: 8px;
}

.quest-board h1 {
  font-size: clamp(2rem, 7vw, 3.2rem);
  margin-bottom: 4px;
  letter-spacing: 0.02em;
  text-wrap: balance;
}

.tagline {
  color: var(--dim);
  font-size: clamp(0.85rem, 2.6vw, 1rem);
  margin: 0 0 6px;
}

.tagline b {
  color: var(--ink);
}

.rule {
  width: min(420px, 80%);
  height: 1px;
  border: 0;
  margin: 18px auto;
  background: linear-gradient(90deg, transparent, var(--amber), transparent);
}

.quest-board main {
  width: 100%;
  max-width: 46rem;
}

.quest-board h2 {
  font-family: var(--display);
  font-weight: 400;
  color: var(--ink);
  font-size: clamp(1.2rem, 4vw, 1.6rem);
  margin: 0 0 14px;
  text-align: center;
}

.board {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.quest {
  display: block;
  text-decoration: none;
  color: inherit;
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: 8px;
  padding: 18px 20px;
  box-shadow: inset 0 0 30px rgb(0 0 0 / 50%);
  transition:
    border-color 0.15s ease,
    transform 0.15s ease;
}

a.quest:hover,
a.quest:focus-visible {
  border-color: var(--amber);
  transform: translateY(-2px);
}

.quest-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.quest h3 {
  font-family: var(--display);
  font-weight: 400;
  color: var(--amber);
  font-size: clamp(1.3rem, 5vw, 1.7rem);
  margin: 0;
}

.badge {
  font-size: 0.72rem;
  color: var(--amber);
  border: 1px solid var(--edge);
  border-radius: 4px;
  padding: 3px 9px;
  background: rgb(242 181 68 / 8%);
  white-space: nowrap;
}

.quest p {
  margin: 10px 0 0;
  font-size: clamp(0.85rem, 2.6vw, 0.95rem);
}

.quest .teaches {
  margin-top: 10px;
  font-size: 0.78rem;
  color: var(--dim);
}

.quest-board code {
  padding: 0 5px;
  font-size: 0.92em;
}

.play {
  display: inline-block;
  margin-top: 14px;
  font-weight: 600;
  color: var(--oak);
  background: var(--amber);
  border-radius: 5px;
  padding: 9px 18px;
  font-size: 0.9rem;
}

.quest.locked {
  opacity: 0.65;
}

.quest.locked h3 {
  color: var(--dim);
}

.soon {
  display: inline-block;
  margin-top: 14px;
  color: var(--dim);
  font-size: 0.85rem;
  border: 1px dashed var(--edge);
  border-radius: 5px;
  padding: 8px 16px;
}

.quest-board footer {
  margin-top: 28px;
  text-align: center;
  color: var(--dim);
  font-size: 0.75rem;
  max-width: 46rem;
}

.quest-board footer a {
  color: var(--dim);
}

/* Shared adventure terminal */
.adventure {
  box-sizing: border-box;
  width: 100%;
  margin-inline: auto;
  height: 100dvh;
  font-size: 14px;
  padding: 12px max(16px, env(safe-area-inset-right))
    max(12px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

.adventure header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding-bottom: 10px;
}

.adventure h1 {
  font-size: clamp(1.4rem, 4.5vw, 2rem);
}

.adventure a {
  color: var(--amber);
}

.frame {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--edge);
  border-radius: 6px;
  background: var(--screen);
}

#out {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 14px;
  font-size: clamp(0.82rem, 2.6vw, 0.95rem);
  line-height: 1.55;
  overflow-wrap: anywhere;
}

#out > div {
  white-space: pre-wrap;
  max-width: 72ch;
  margin-bottom: 10px;
}

.hint {
  color: var(--moss);
}

.err {
  color: var(--rust);
}

.dim {
  color: var(--dim);
}

.dir {
  color: #7fb2e8;
}

.story {
  color: var(--ink);
}

.win {
  color: var(--amber);
  font-weight: bold;
}

.adventure code {
  cursor: pointer;
}

.keys {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 8px 14px;
  border-top: 1px dashed var(--edge);
}

.keys button,
.conversation-options button,
.enter-command {
  font: inherit;
  color: var(--amber);
  background: #f2b54414;
  border: 1px solid var(--edge);
  border-radius: 4px;
  padding: 6px 12px;
  min-height: 36px;
  cursor: pointer;
}

.enter-command {
  flex-shrink: 0;
  min-height: 44px;
}

.enter-command:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 3px;
}

.conversation-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.conversation-options button {
  max-width: 100%;
  text-align: left;
  overflow-wrap: anywhere;
}

.conversation-options button:disabled {
  opacity: 0.5;
  cursor: default;
}

.conversation-options button:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 3px;
}

.adventure form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 8px 14px 12px;
}

.command-entry {
  display: flex;
  flex: 1 1 24ch;
  min-width: 0;
  align-items: center;
  gap: 8px;
}

#prompt {
  color: var(--amber);
  overflow-wrap: anywhere;
}

#cmd {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: 0;
  color: var(--ink);
  font: 16px var(--mono);
}

.adventure form:focus-within {
  background: #f2b54408;
}

.adventure footer,
.foot {
  font-size: 0.72rem;
  color: var(--dim);
  padding-top: 8px;
}

/* Preserve the tower's existing typography and command-chip tint. */
.tower-adventure {
  --mono: "JetBrains Mono", ui-monospace, monospace;
}

.tower-adventure h1 {
  font-family: "IM Fell English SC", Georgia, serif;
}

.tower-adventure code {
  background: #f2b54418;
  font-family: inherit;
}

#status {
  color: var(--moss);
  font-size: 0.8rem;
}

/* The market uses a slightly tighter terminal with animated new lines. */
html:has(.market-adventure) {
  height: 100%;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0);
  padding-bottom: env(safe-area-inset-bottom, 0);
  scroll-padding-top: env(safe-area-inset-top, 0);
}

.market-adventure {
  --mono:
    "JetBrains Mono", ui-monospace, "DejaVu Sans Mono", Menlo, Consolas,
    monospace;

  box-sizing: border-box;
  padding-block: 12px;
}

.market-adventure header {
  gap: 6px 16px;
}

.market-adventure h1 {
  letter-spacing: 0.02em;
  text-wrap: balance;
}

.log {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 0.78rem;
  color: var(--dim);
}

.log b {
  color: var(--ink);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.pips {
  display: inline-flex;
  gap: 3px;
  vertical-align: middle;
  margin-left: 4px;
}

.pips i {
  width: 9px;
  height: 9px;
  border: 1px solid var(--amber);
  transform: rotate(45deg);
  display: inline-block;
}

.pips i.on {
  background: var(--amber);
}

.market-adventure .frame {
  box-shadow: inset 0 0 40px rgb(0 0 0 / 60%);
}

.market-adventure #out {
  padding: 14px 14px 4px;
}

.market-adventure #out > div {
  margin: 0 0 6px;
}

.market-adventure #out > div:first-child {
  margin-top: 0;
}

#out > div.story {
  margin-bottom: 1lh;
}

.cmd {
  color: var(--ink);
  margin-top: 16px;
}

.cmd .p {
  color: var(--amber);
}

.muted-command-echoes #out > :is(.echo, .cmd) {
  color: var(--dim);
  margin-top: 16px;
  margin-bottom: 10px;
}

.muted-command-echoes #out > .cmd .p {
  color: inherit;
}

.market-adventure .dir {
  font-weight: 600;
}

.title {
  font-family: var(--display);
  color: var(--amber);
  font-size: 1.3em;
}

.market-adventure .win {
  font-weight: 600;
}

.market-adventure .keys {
  padding: 8px 14px 0;
}

.market-adventure .keys button {
  font-family: var(--mono);
  font-size: 0.8rem;
  background: rgb(242 181 68 / 8%);
  min-height: 34px;
  -webkit-tap-highlight-color: transparent;
}

.market-adventure .keys button:active {
  background: rgb(242 181 68 / 25%);
}

.market-adventure #prompt {
  white-space: nowrap;
  overflow-wrap: normal;
  font-size: clamp(0.82rem, 2.6vw, 0.95rem);
}

.market-adventure #cmd {
  outline: none;
  caret-color: var(--amber);
}

.market-adventure form:focus-within {
  background: rgb(242 181 68 / 4%);
}

.file-list {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px 24px;
}

.file-list .file-link {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  text-align: left;
  overflow-wrap: anywhere;
  max-width: 100%;
  cursor: pointer;
}

.file-list .file-link:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 3px;
}

.file-list .dir {
  font-weight: 600;
}

@media (width >= 64rem) {
  .adventure {
    width: 76%;
    max-width: 90ch;
  }
}

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

@media (prefers-reduced-motion: no-preference) {
  .market-adventure #out > div.new {
    animation: in 0.25s ease-out;
  }

  @keyframes in {
    from {
      opacity: 0.3;
    }

    to {
      opacity: 1;
    }
  }
}
