:root {
  --wood: #4a3022;
  --wood-hi: #7a5338;
  --wood-lo: #2a1a12;
  --lcd: #cbb58a;
  --ink: #2a1b12;
  --mute: #6e5340;
  --hay: #d7b074;
  --hay-2: #c49655;
  --gold: #e6c36a;
  --hp: #b85a3c;
  --ok: #6a8a48;
  --pixel: 4px;
  --font: "Pixelify Sans", "Trebuchet MS", sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  min-height: 100%;
  background: #1c120c;
  color: var(--ink);
}

body {
  font-family: var(--font);
  image-rendering: pixelated;
  overflow-x: hidden;
}

img {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  background: none;
  border: 0;
}

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.room {
  min-height: 100svh;
  padding: 0.7rem;
  background:
    radial-gradient(ellipse at 50% 0%, #5a3d28 0%, #1c120c 62%),
    url("../assets/pixel-field.png") center / cover;
}

.bezel {
  max-width: 1080px;
  margin: 0 auto;
  padding: 10px;
  background: linear-gradient(180deg, #8a6244, #4a3022 40%, #2a1a12);
  box-shadow:
    0 0 0 4px #2a1a12,
    0 18px 0 #140c08,
    0 28px 40px rgba(0, 0, 0, 0.45);
}

.lcd {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: calc(100svh - 2.2rem);
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(44, 28, 18, 0.28), rgba(44, 28, 18, 0.45)),
    url("../assets/pixel-field.png") center / cover;
  box-shadow: inset 0 0 0 4px #d8c49a, inset 0 0 0 8px #2a1a12;
}

.hud {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.55rem 0.8rem;
  padding: 0.55rem 0.7rem;
  background: #ecd7b2;
  border-bottom: 4px solid #2a1a12;
  box-shadow: inset 0 -4px 0 #c4a06a;
}

.hud-face {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.hud-face img {
  width: 44px;
  height: 44px;
  background: #cbb58a;
  border: 4px solid #2a1a12;
}

.hud-face b,
.hud-odds strong,
.hud-item strong {
  display: block;
  line-height: 1;
}

.hud-face span,
.hud-stat span,
.hud-item span,
.hud-odds span {
  color: var(--mute);
  font-size: 0.7rem;
  letter-spacing: 0.08em;
}

.hud-stat {
  flex: 1;
  min-width: 8rem;
}

.bar {
  height: 14px;
  margin-top: 0.2rem;
  background: #2a1a12;
  box-shadow: inset 0 0 0 2px #2a1a12, 0 0 0 2px #c4a06a;
}

.bar i {
  display: block;
  width: 8%;
  height: 100%;
  background: repeating-linear-gradient(90deg, #e6c36a 0 8px, #b85a3c 8px 10px);
  transition: width 0.2s steps(8);
}

.pix,
.buy {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.1rem;
  padding: 0 0.75rem;
  color: #f3e6cc;
  background: #5a3d28;
  box-shadow:
    4px 0 0 #2a1a12,
    -4px 0 0 #2a1a12,
    0 4px 0 #2a1a12,
    0 -4px 0 #2a1a12,
    0 8px 0 #1a100c;
}

.buy {
  background: #b85a3c;
}

.buy:hover,
.pix:hover {
  filter: brightness(1.08);
}

.buy.lg {
  min-height: 2.7rem;
  padding: 0 1.1rem;
  font-size: 1.05rem;
}

.buy.wide {
  width: 100%;
}

.ghost-buy {
  background: transparent;
  color: #f3e6cc;
  box-shadow: 4px 0 0 #f3e6cc, -4px 0 0 #f3e6cc, 0 4px 0 #f3e6cc, 0 -4px 0 #f3e6cc;
}

.stage {
  position: relative;
  min-height: 0;
}

.title,
.got {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  text-align: center;
  background: linear-gradient(180deg, rgba(28, 18, 12, 0.35), rgba(28, 18, 12, 0.55));
}

.title[hidden],
.got[hidden],
.field[hidden] {
  display: none;
}

.quest {
  color: var(--gold);
  letter-spacing: 0.28em;
  text-shadow: 3px 3px 0 #2a1a12;
}

h1 {
  margin: 0.2rem 0;
  color: #f6ead0;
  font-size: clamp(3.4rem, 12vw, 6.4rem);
  line-height: 0.9;
  letter-spacing: 0.08em;
  text-shadow: 5px 5px 0 #2a1a12, -2px 0 0 #b85a3c;
}

.subtitle,
.blink,
.got-sub {
  color: #ecd7b2;
  text-shadow: 2px 2px 0 #2a1a12;
}

.title-hero {
  width: 132px;
  height: 132px;
  margin: 0.4rem 0 0.8rem;
  animation: idle 0.8s steps(2) infinite;
}

.start {
  min-height: 3rem;
  padding: 0 1.3rem;
  color: #2a1a12;
  font-size: 1.15rem;
  background: var(--gold);
  box-shadow:
    4px 0 0 #2a1a12,
    -4px 0 0 #2a1a12,
    0 4px 0 #2a1a12,
    0 -4px 0 #2a1a12,
    0 10px 0 #1a100c;
}

.blink {
  margin: 0.7rem 0 1rem;
  animation: blink 1.1s steps(2) infinite;
}

.field {
  position: absolute;
  inset: 0;
}

.grid {
  display: grid;
  width: 100%;
  height: 100%;
  padding: 0.28rem;
  gap: 2px;
}

.tile {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background:
    repeating-linear-gradient(115deg, #e2c38a 0 4px, #c49655 4px 5px),
    #c49655;
  box-shadow:
    inset 0 0 0 1px #8a6244,
    1px 1px 0 #2a1a12;
  cursor: pointer;
}

.tile::before {
  content: "";
  position: absolute;
  inset: 20% 26% auto;
  height: 52%;
  background: #d7b074;
  clip-path: polygon(50% 0, 100% 70%, 82% 100%, 18% 100%, 0 70%);
}

.tile.cursor {
  outline: 2px solid #f6ead0;
  outline-offset: -2px;
  z-index: 1;
}

.tile.raked {
  background: #8a6244;
}

.tile.raked::before {
  height: 22%;
  inset: 62% 18% auto;
  background: #c49655;
}

.tile.warm {
  box-shadow: inset 0 0 0 2px #e6c36a, 2px 2px 0 #2a1a12;
}

.tile.hot {
  box-shadow: inset 0 0 0 3px #b85a3c, 2px 2px 0 #2a1a12;
}

.tile.spark::after {
  content: "";
  position: absolute;
  inset: 8%;
  border: 3px dashed #f6ead0;
  animation: spark 0.6s steps(2) infinite;
}

.tile.needle {
  background: #2a1a12;
}

.tile.needle::before {
  display: none;
}

.tile.needle img {
  width: 72%;
  height: 72%;
  margin: 14% auto 0;
  object-fit: contain;
}

.walker {
  position: absolute;
  z-index: 2;
  width: 28px;
  height: 28px;
  margin-left: -14px;
  margin-top: -20px;
  pointer-events: none;
  filter: drop-shadow(1px 2px 0 #2a1a12);
  transition: left 0.12s steps(2), top 0.12s steps(2);
}

.got p:first-child {
  color: var(--gold);
  letter-spacing: 0.2em;
}

.got h2 {
  margin: 0.3rem 0 0.5rem;
  color: #f6ead0;
  font-size: clamp(2.2rem, 7vw, 3.4rem);
  text-shadow: 4px 4px 0 #2a1a12;
}

.got img {
  margin: 0.6rem 0;
  border: 4px solid #2a1a12;
  background: #ecd7b2;
}

.got .start {
  margin: 0.35rem 0 0.7rem;
}

.got .pix {
  margin-top: 0.7rem;
}

body.level-2 .grid,
body.level-3 .grid {
  gap: 1px;
  padding: 0.18rem;
}

body.level-3 .tile.raked {
  background:
    repeating-linear-gradient(115deg, #c9a06a 0 4px, #b08952 4px 5px),
    #b08952;
}

body.level-3 .hud-stat {
  opacity: 0.28;
}

.dialog {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.7rem;
  align-items: center;
  padding: 0.65rem 0.75rem;
  background: #ecd7b2;
  border-top: 4px solid #2a1a12;
}

.dialog-face img {
  width: 52px;
  height: 52px;
  background: #2a1a12;
  border: 4px solid #2a1a12;
}

#dialogText {
  font-size: 1.02rem;
  line-height: 1.35;
}

.dialog-btns {
  display: flex;
  gap: 0.45rem;
}

.below {
  padding: 1rem 0.9rem 1.4rem;
  background: #ecd7b2;
  border-top: 6px solid #2a1a12;
}

.below h2 {
  margin-bottom: 0.8rem;
  padding-bottom: 0.45rem;
  border-bottom: 4px solid #2a1a12;
  letter-spacing: 0.14em;
}

.codex-grid {
  display: grid;
  gap: 1.1rem;
}

.below h3 {
  margin-bottom: 0.5rem;
  color: var(--wood);
  letter-spacing: 0.12em;
}

.log {
  display: grid;
  gap: 0.55rem;
  list-style: none;
}

.log li {
  display: grid;
  grid-template-columns: 2.2rem 1fr;
  gap: 0.4rem;
  padding: 0.45rem;
  background: #dcc39a;
  box-shadow: inset 0 0 0 3px #2a1a12;
}

.log i {
  color: #b85a3c;
  font-style: normal;
}

.log p,
.help p,
.audit,
.out a,
.ca span,
.vitals span {
  color: var(--mute);
  font-size: 0.92rem;
  line-height: 1.4;
}

.almanac-head {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin-bottom: 0.6rem;
}

.almanac-head img {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border: 4px solid #2a1a12;
}

.ca {
  margin-bottom: 0.6rem;
  padding: 0.55rem;
  background: #dcc39a;
  box-shadow: inset 0 0 0 3px #2a1a12;
}

.ca div {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.2rem;
}

.ca button {
  color: #b85a3c;
  letter-spacing: 0.08em;
}

.ca p {
  overflow-wrap: anywhere;
}

.vitals {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0.4rem;
  margin-bottom: 0.5rem;
  list-style: none;
}

.vitals li {
  padding: 0.4rem;
  background: #dcc39a;
  box-shadow: inset 0 0 0 3px #2a1a12;
}

.vitals strong {
  display: block;
}

.vitals strong.flash {
  color: #b85a3c;
}

.out {
  display: flex;
  gap: 0.8rem;
  margin: 0.5rem 0 0.8rem;
}

.help details {
  margin-bottom: 0.35rem;
  padding: 0.35rem 0.5rem;
  background: #dcc39a;
  box-shadow: inset 0 0 0 3px #2a1a12;
}

.help summary {
  cursor: pointer;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.2rem;
  z-index: 30;
  padding: 0.55rem 0.9rem;
  color: #2a1a12;
  background: var(--gold);
  box-shadow:
    4px 0 0 #2a1a12,
    -4px 0 0 #2a1a12,
    0 4px 0 #2a1a12,
    0 -4px 0 #2a1a12;
  transform: translate(-50%, 140%);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.2s steps(4), opacity 0.2s steps(4);
}

.toast.on {
  transform: translate(-50%, 0);
  opacity: 1;
}

@keyframes idle {
  from { transform: translateY(0); }
  to { transform: translateY(6px); }
}

@keyframes blink {
  50% { opacity: 0; }
}

@keyframes spark {
  50% { opacity: 0.2; }
}

@media (min-width: 860px) {
  .codex-grid {
    grid-template-columns: 1fr 1.15fr;
  }

  .help {
    grid-column: 1 / -1;
  }
}

@media (max-width: 720px) {
  h1 {
    font-size: clamp(2.6rem, 16vw, 4rem);
  }

  .title-hero {
    width: 88px;
    height: 88px;
    margin: 0.15rem 0 0.5rem;
  }

  .room {
    padding: 0;
  }

  .bezel {
    padding: 6px;
    box-shadow: none;
  }

  .lcd {
    min-height: 100svh;
  }

  .hud-stat {
    display: none;
  }

  .dialog {
    grid-template-columns: 1fr auto;
  }

  .dialog-face {
    display: none;
  }

  .vitals {
    grid-template-columns: 1fr 1fr;
  }

  .grid {
    gap: 1px;
    padding: 0.18rem;
  }

  .walker {
    width: 22px;
    height: 22px;
    margin-left: -11px;
    margin-top: -16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .title-hero,
  .blink,
  .tile.spark::after,
  .walker {
    animation: none;
    transition: none;
  }
}
