:root {
  --night: #040904;
  --forest: #063d0a;
  --forest-bright: #0b7217;
  --leaf: #49b83d;
  --parchment: #f2e5b8;
  --gold: #f6d64a;
  --rust: #a83b25;
  --sky: #b9eff0;
  --stone: #a9aaa3;
  --ink: #17150f;
  --line: rgba(246, 214, 74, 0.35);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--night);
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--parchment);
  font-family: ui-monospace, "SFMono-Regular", Menlo, Monaco, Consolas, monospace;
  background:
    radial-gradient(circle at 50% -10%, rgba(73, 184, 61, 0.18), transparent 42rem),
    repeating-linear-gradient(135deg, rgba(255,255,255,0.018) 0 1px, transparent 1px 8px),
    #040904;
}

button {
  color: inherit;
  font: inherit;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

button:focus-visible,
canvas:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 3px;
}

.app-shell {
  width: min(1180px, calc(100% - 24px));
  margin: 0 auto;
  padding: 18px 0 14px;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  padding: 0 4px 13px;
}

.brand span {
  display: block;
  color: var(--gold);
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.35rem, 3vw, 2.25rem);
  font-weight: 900;
  letter-spacing: 0.055em;
  line-height: 1;
  text-shadow: 2px 2px 0 #4d1e12;
}

.brand small {
  display: block;
  margin-top: 6px;
  color: #8fbd6b;
  font-size: 0.62rem;
  letter-spacing: 0.16em;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: end;
  gap: 7px;
}

.toolbar button,
.utility-row button {
  min-height: 38px;
  border: 1px solid #806e35;
  border-radius: 5px;
  padding: 7px 11px;
  color: #f4e9bf;
  background: linear-gradient(#26341c, #10170c);
  box-shadow: inset 0 1px rgba(255,255,255,0.08), 0 3px 9px rgba(0,0,0,0.35);
  cursor: pointer;
}

.toolbar button:hover,
.utility-row button:hover:not(:disabled) {
  border-color: var(--gold);
  color: #fff9d8;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(250px, 310px);
  gap: 14px;
  align-items: start;
}

.cabinet,
.journey-panel {
  border: 1px solid #4f5c32;
  border-radius: 9px;
  background: linear-gradient(145deg, rgba(20, 43, 17, 0.96), rgba(6, 13, 5, 0.98));
  box-shadow: 0 18px 50px rgba(0,0,0,0.45), inset 0 1px rgba(255,255,255,0.05);
}

.cabinet {
  padding: 13px;
}

.screen-bezel {
  padding: clamp(8px, 1.7vw, 16px);
  border: 1px solid #7b6331;
  border-radius: 8px;
  background:
    repeating-linear-gradient(90deg, #3a2b18 0 3px, #261a0f 3px 6px),
    #2e2114;
  box-shadow: inset 0 0 0 3px #120f09, inset 0 0 22px #000;
}

.screen-wrap {
  position: relative;
  overflow: hidden;
  border: 3px solid #090b07;
  border-radius: 4px;
  background: #000;
  box-shadow: 0 0 0 1px #8b8d72, 0 0 0 3px #1b180e;
}

canvas {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 10;
  background: #000;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  cursor: default;
  touch-action: pan-y;
}

.screen-glass {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(105deg, rgba(255,255,255,0.055), transparent 18% 78%, rgba(255,255,255,0.025)),
    repeating-linear-gradient(0deg, rgba(0,0,0,0.07) 0 1px, transparent 1px 3px);
  mix-blend-mode: screen;
  opacity: 0.45;
}

.turn-console {
  display: grid;
  gap: 11px;
  margin-top: 12px;
  padding: 13px;
  border: 1px solid rgba(169, 170, 163, 0.25);
  border-radius: 6px;
  background: rgba(0,0,0,0.48);
}

.turn-heading p,
.turn-heading h1 {
  margin: 0;
}

.turn-heading p,
.eyebrow {
  color: #8fbd6b;
  font-size: 0.65rem;
  letter-spacing: 0.14em;
}

.turn-heading h1 {
  margin-top: 4px;
  color: #fff8d4;
  font-size: clamp(0.9rem, 2vw, 1.08rem);
  line-height: 1.35;
}

.action-buttons {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
}

.action-card {
  position: relative;
  min-height: 70px;
  overflow: hidden;
  border: 1px solid #63754a;
  border-radius: 6px;
  padding: 10px 12px 9px;
  text-align: left;
  color: var(--parchment);
  background:
    linear-gradient(115deg, rgba(73,184,61,0.13), transparent 65%),
    #111d0e;
  box-shadow: inset 0 1px rgba(255,255,255,0.05), 0 4px 12px rgba(0,0,0,0.28);
  cursor: pointer;
}

.action-card::after {
  position: absolute;
  inset: auto -18px -25px auto;
  width: 62px;
  height: 62px;
  border: 1px solid rgba(246,214,74,0.12);
  border-radius: 50%;
  content: "";
}

.action-card:hover:not(:disabled),
.action-card.primary {
  border-color: #c9aa3d;
  background:
    linear-gradient(115deg, rgba(246,214,74,0.13), transparent 65%),
    #18240f;
}

.action-card.danger {
  border-color: rgba(168,59,37,0.8);
}

.action-card.reward {
  border-color: rgba(246,214,74,0.72);
  background:
    linear-gradient(115deg, rgba(246,214,74,0.1), transparent 65%),
    #14200f;
}

.action-card.reward strong {
  color: #ffe777;
}

.action-card.challenge {
  border-color: rgba(216,129,35,0.72);
  background:
    linear-gradient(115deg, rgba(216,129,35,0.11), transparent 65%),
    #1d180e;
}

.action-card.challenge strong {
  color: #ffd29b;
}

.action-card:disabled {
  cursor: default;
  opacity: 0.46;
}

.action-card .hotkey {
  float: right;
  min-width: 21px;
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 3px;
  padding: 2px 4px;
  color: #b5bca4;
  font-size: 0.62rem;
  text-align: center;
}

.action-card strong,
.action-card small {
  display: block;
}

.action-card strong {
  padding-right: 24px;
  color: #fff7cd;
  font-size: 0.88rem;
}

.action-card small {
  margin-top: 6px;
  color: #aebe98;
  font-size: 0.68rem;
  line-height: 1.3;
}

.utility-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.utility-row button {
  flex: 1;
  min-width: 145px;
}

.utility-row button:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.utility-row button.active {
  border-color: var(--gold);
  color: var(--gold);
  background: linear-gradient(#425228, #17200e);
}

.journey-panel {
  position: sticky;
  top: 12px;
  padding: 15px;
}

.chapter {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 5px 10px;
  align-items: end;
}

.chapter span,
.stats-grid span,
.gear-list small {
  color: #8f9f80;
  font-size: 0.66rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.chapter strong {
  color: var(--gold);
  font-size: 1.12rem;
}

.chapter-track {
  grid-column: 1 / -1;
  height: 7px;
  overflow: hidden;
  border: 1px solid #4f5d3c;
  background: #050804;
}

.chapter-track i {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--rust), var(--gold));
  transition: width 420ms ease;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 7px;
  margin: 14px 0;
}

.stats-grid div {
  display: grid;
  gap: 4px;
  border: 1px solid rgba(143,189,107,0.22);
  border-radius: 4px;
  padding: 8px 9px;
  background: rgba(0,0,0,0.32);
}

.stats-grid strong {
  color: #fff4be;
  font-size: 1rem;
}

.stats-grid div:first-child strong {
  color: #70d763;
}

.gear-list {
  display: grid;
  gap: 6px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.gear-list > div {
  display: grid;
  grid-template-columns: 27px 1fr;
  gap: 8px;
  align-items: center;
}

.gear-list > div > span {
  color: var(--gold);
  font-size: 1.15rem;
  text-align: center;
}

.gear-list p,
.gear-list strong,
.gear-list small {
  display: block;
  margin: 0;
}

.gear-list strong {
  margin-top: 2px;
  color: #e6dfc5;
  font-size: 0.77rem;
}

.travel-log {
  margin-top: 13px;
}

.travel-log h2 {
  margin: 0 0 8px;
  color: #8fbd6b;
  font-size: 0.68rem;
  letter-spacing: 0.13em;
}

.travel-log ol {
  display: grid;
  gap: 7px;
  min-height: 94px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.travel-log li {
  color: #bfc5ac;
  font-size: 0.68rem;
  line-height: 1.35;
}

.travel-log li::before {
  margin-right: 7px;
  color: #6b8f50;
  content: "›";
}

.travel-log li:first-child {
  color: #fff2b0;
}

.keyboard-hint {
  margin: 13px 0 0;
  color: #68745e;
  font-size: 0.6rem;
  line-height: 1.45;
}

footer {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 5px 0;
  color: #63715a;
  font-size: 0.62rem;
}

dialog {
  width: min(590px, calc(100% - 28px));
  border: 1px solid #88713a;
  border-radius: 8px;
  padding: 0;
  color: var(--parchment);
  background: #0a1408;
  box-shadow: 0 24px 80px #000;
}

dialog::backdrop {
  background: rgba(0,0,0,0.78);
  backdrop-filter: blur(3px);
}

.dialog-card {
  position: relative;
  padding: 25px;
  background:
    linear-gradient(135deg, rgba(73,184,61,0.09), transparent 50%),
    repeating-linear-gradient(0deg, rgba(255,255,255,0.018) 0 1px, transparent 1px 6px);
}

.dialog-close {
  position: absolute;
  top: 9px;
  right: 10px;
  width: 34px;
  height: 34px;
  border: 1px solid #625934;
  border-radius: 4px;
  color: #eee4bd;
  background: #151b10;
  cursor: pointer;
}

.dialog-card h2 {
  margin: 5px 0 10px;
  color: var(--gold);
  font-family: Georgia, serif;
  font-size: 1.6rem;
}

.dialog-card > p:not(.eyebrow):not(.help-keys) {
  color: #c4cbb8;
  line-height: 1.55;
}

.help-grid {
  display: grid;
  grid-template-columns: 135px 1fr;
  gap: 11px 18px;
  margin-top: 19px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.help-grid strong {
  color: #f0d46b;
  font-size: 0.75rem;
}

.help-grid p {
  margin: 0;
  color: #b6bea9;
  font-size: 0.73rem;
  line-height: 1.45;
}

.help-keys {
  margin: 20px 0 0;
  color: #8b987e;
  font-size: 0.66rem;
  line-height: 1.8;
}

kbd {
  border: 1px solid #6f6b4b;
  border-radius: 3px;
  padding: 2px 5px;
  color: #fff0ab;
  background: #161c11;
  box-shadow: inset 0 -1px #000;
}

.toast {
  position: fixed;
  z-index: 20;
  left: 50%;
  bottom: 24px;
  max-width: calc(100% - 30px);
  transform: translate(-50%, 18px);
  border: 1px solid #8e793d;
  border-radius: 4px;
  padding: 9px 13px;
  color: #fff4bd;
  background: rgba(9,18,7,0.97);
  box-shadow: 0 10px 35px #000;
  font-size: 0.72rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.visible {
  transform: translate(-50%, 0);
  opacity: 1;
}

@media (max-width: 850px) {
  .game-layout {
    grid-template-columns: 1fr;
  }

  .journey-panel {
    position: static;
  }

  .travel-log ol {
    min-height: 0;
  }
}

@media (max-width: 560px) {
  .app-shell {
    width: min(100% - 12px, 1180px);
    padding-top: 9px;
  }

  .topbar {
    align-items: center;
  }

  .brand span {
    font-size: 1.08rem;
  }

  .brand small {
    font-size: 0.5rem;
  }

  .toolbar button {
    min-height: 34px;
    padding: 5px 8px;
    font-size: 0.67rem;
  }

  .cabinet {
    padding: 7px;
  }

  .screen-bezel {
    padding: 7px;
  }

  .turn-console,
  .journey-panel {
    padding: 11px;
  }

  .action-buttons {
    grid-template-columns: 1fr;
  }

  .action-card {
    min-height: 61px;
  }

  .help-grid {
    grid-template-columns: 1fr;
    gap: 5px;
  }

  footer {
    display: grid;
  }
}

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