:root {
  --ink: #050505;
  --cream: #fff4d7;
  --panel: rgba(255, 244, 215, 0.96);
  --gold: #f5d642;
  --brown: #8b6443;
  --green: #486d3f;
  --dark: #243421;
  --shadow: rgba(0, 0, 0, 0.32);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--dark);
  color: var(--ink);
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
}

button {
  min-height: 42px;
  border: 3px solid var(--ink);
  border-radius: 0;
  background: var(--gold);
  color: var(--ink);
  box-shadow: 0 4px 0 var(--shadow);
  font: inherit;
  font-weight: 950;
  padding: 7px 12px;
}

button:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--shadow);
}

#appShell {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

#gameRoot {
  display: grid;
  place-items: center;
  position: absolute;
  inset: 0;
  z-index: 0;
}

#gameRoot canvas {
  display: block;
  width: min(100vw, calc(100vh * 16 / 9)) !important;
  height: min(100vh, calc(100vw * 9 / 16)) !important;
  image-rendering: auto;
  touch-action: none;
}

.panel {
  position: absolute;
  z-index: 5;
  border: 3px solid var(--ink);
  border-radius: 0;
  background: var(--panel);
  box-shadow: 0 5px 0 var(--shadow);
}

#topHud,
#messageHud {
  pointer-events: none;
}

#topHud {
  top: max(8px, env(safe-area-inset-top));
  left: max(8px, env(safe-area-inset-left));
  right: max(8px, env(safe-area-inset-right));
  height: 62px;
  display: grid;
  grid-template-columns:
    minmax(180px, 230px) minmax(62px, 0.75fr) minmax(40px, 0.4fr)
    minmax(56px, 0.6fr) minmax(62px, 0.65fr) minmax(84px, 1fr);
  gap: 6px;
  align-items: center;
  padding: 7px 10px;
}

.brand {
  display: flex;
  gap: 8px;
  align-items: center;
  min-width: 0;
}

.badge {
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  border: 3px solid var(--ink);
  border-radius: 0;
  background: var(--gold) url("./assets/icon.svg") center 48% / 142% auto
    no-repeat;
}

.brand strong,
.stat strong,
#questHud strong {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand strong {
  font-size: 17px;
  line-height: 1.05;
}

.brand span:not(.badge),
.stat span,
#questHud span {
  display: block;
  font-size: 10px;
  font-weight: 900;
  line-height: 1.05;
  opacity: 0.72;
  text-transform: uppercase;
}

.stat {
  min-width: 0;
  padding-left: 6px;
  border-left: 2px solid rgba(5, 5, 5, 0.2);
}

.stat strong {
  font-size: 18px;
}

#questHud {
  top: calc(max(8px, env(safe-area-inset-top)) + 74px);
  left: max(8px, env(safe-area-inset-left));
  width: min(460px, 48vw);
  padding: 8px 12px;
  cursor: pointer;
  pointer-events: auto;
  transition:
    width 140ms ease,
    padding 140ms ease;
}

#questHud.collapsed {
  width: auto;
  min-width: 64px;
  padding: 7px 10px;
}

#questHud.collapsed strong {
  display: none;
}

#questHud strong {
  font-size: 15px;
  line-height: 1.18;
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
}

#actionDock {
  right: max(10px, env(safe-area-inset-right));
  bottom: calc(max(10px, env(safe-area-inset-bottom)) + 74px);
  width: min(236px, 31vw);
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  padding: 6px;
  pointer-events: auto;
}

#actionDock:empty {
  display: none;
}

#actionDock button {
  min-height: 31px;
  flex: 1 1 96px;
  padding: 4px 7px;
  background: var(--cream);
  font-size: 12px;
  line-height: 1.08;
}

#actionDock button.image-action {
  min-width: 48px;
  flex: 1 1 48px;
  padding: 3px;
}

#actionDock button.image-action img {
  display: block;
  width: 100%;
  height: 42px;
  object-fit: contain;
  pointer-events: none;
}

#actionDock button.image-action.selected {
  border-color: #fff4d7;
  background: #486d3f;
  box-shadow:
    0 0 0 3px #050505,
    0 4px 0 var(--shadow);
}

#plannerCostHud {
  top: calc(max(8px, env(safe-area-inset-top)) + 74px);
  right: max(10px, env(safe-area-inset-right));
  display: flex;
  gap: 12px;
  padding: 7px 10px;
  pointer-events: none;
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

#plannerCostHud span,
#plannerCostHud strong {
  display: block;
}

#plannerCostHud span.hidden {
  display: none;
}

#plannerCostHud strong {
  margin-top: 2px;
  font-size: 15px;
}

#plannerCostHud strong.over-budget {
  color: #b52121;
}

#plannerCostHud.hidden {
  display: none;
}

#messageHud {
  left: max(10px, env(safe-area-inset-left));
  bottom: max(10px, env(safe-area-inset-bottom));
  width: min(480px, 50vw);
  min-height: 48px;
  display: flex;
  align-items: center;
  padding: 9px 12px;
  background: rgba(36, 52, 33, 0.92);
  color: var(--cream);
  font-weight: 850;
  line-height: 1.2;
}

#missingEngine {
  left: 50%;
  top: 50%;
  width: min(520px, 90vw);
  padding: 16px;
  transform: translate(-50%, -50%);
  font-weight: 900;
  text-align: center;
}

.hidden {
  display: none;
}

#rotateNotice {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  place-items: center;
  padding: 24px;
  background: #172016;
  color: var(--cream);
  text-align: center;
}

#rotateNotice div {
  width: min(380px, 92vw);
  border: 4px solid var(--ink);
  border-radius: 0;
  background: var(--dark);
  padding: 20px;
  box-shadow: 0 8px 0 rgba(0, 0, 0, 0.35);
}

#rotateNotice strong {
  display: block;
  margin-bottom: 8px;
  font-size: 26px;
}

#rotateNotice span {
  font-weight: 750;
  line-height: 1.3;
}

@media (orientation: portrait) and (max-width: 900px) {
  #rotateNotice {
    display: grid;
  }
}

@media (max-height: 480px), (max-width: 760px) {
  #topHud {
    height: 54px;
    grid-template-columns:
      minmax(176px, 220px) minmax(60px, 0.75fr) minmax(38px, 0.4fr)
      minmax(52px, 0.6fr) minmax(58px, 0.65fr) minmax(76px, 1fr);
    gap: 4px;
    padding: 5px 7px;
  }

  .badge {
    width: 31px;
    height: 31px;
  }

  .brand strong {
    font-size: 14px;
  }

  .brand span:not(.badge),
  .stat span,
  #questHud span {
    font-size: 9px;
  }

  .stat strong {
    font-size: 14px;
  }

  #questHud {
    top: calc(max(8px, env(safe-area-inset-top)) + 62px);
    width: min(370px, 46vw);
  }

  #actionDock {
    width: min(220px, 31vw);
    gap: 4px;
    padding: 5px;
  }

  #actionDock button {
    min-height: 29px;
    flex-basis: 88px;
    padding: 3px 6px;
    font-size: 11px;
  }

  #actionDock button.image-action img {
    height: 34px;
  }

  #plannerCostHud {
    top: calc(max(8px, env(safe-area-inset-top)) + 62px);
    gap: 8px;
    padding: 5px 8px;
    font-size: 9px;
  }

  #plannerCostHud strong {
    font-size: 12px;
  }

  #questHud strong,
  #messageHud {
    font-size: 13px;
  }

  button {
    min-height: 36px;
    padding: 5px 9px;
    font-size: 13px;
  }
}

#journalButton {
  position: fixed;
  z-index: 7;
  right: max(12px, env(safe-area-inset-right));
  top: 82px;
  background: var(--cream);
  font-size: 12px;
}
#storyDialog {
  width: min(760px, 94vw);
  max-height: 90dvh;
  padding: 0;
  border: 3px solid var(--ink);
  background: var(--cream);
  color: var(--dark);
  box-shadow: 0 12px 50px #0008;
}
#storyDialog::backdrop {
  background: #122016b8;
}
#storyDialog header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 12px 18px;
  background: var(--dark);
  color: var(--cream);
}
#storyDialog h2 {
  font-size: 18px;
  margin: 0;
}
#storyDialog h3 {
  font-size: 16px;
  line-height: 1.3;
  margin: 16px 0 10px;
}
#storyBody {
  padding: 16px 22px 24px;
  overflow-y: auto;
  max-height: calc(90dvh - 78px);
  font:
    15px/1.6 ui-sans-serif,
    system-ui,
    sans-serif;
}
#storyBody button {
  font:
    600 13px/1.3 ui-sans-serif,
    system-ui,
    sans-serif;
  margin: 5px 7px 5px 0;
  background: #e9d8ae;
  min-height: 42px;
}
#storyBody p {
  margin: 10px 0;
}
#storyBody .hint {
  color: #526348;
  font-size: 13px;
}
#storyBody .portrait {
  float: right;
  width: 96px;
  height: 144px;
  image-rendering: auto;
  object-fit: contain;
  margin: 0 0 10px 16px;
}
.journal-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 16px;
}
#storyBody .journal-tabs button[aria-pressed="true"] {
  background: var(--dark);
  color: var(--cream);
}
.journal-row {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  padding: 4px 0;
  border-bottom: 1px solid #24342122;
}
.fulfilled {
  color: #35662c;
}
.journal-card {
  border-top: 2px solid #24342133;
  margin: 16px 0;
  padding-top: 4px;
  clear: both;
}
.result {
  border: 2px solid #8c533b;
  padding: 12px;
  background: #f4e1bd;
  clear: both;
}
.result.success {
  border-color: #486d3f;
}
#actionDock {
  max-height: 58vh;
  overflow-y: auto;
}
@media (max-height: 480px) {
  #journalButton {
    top: 72px;
  }
  #storyDialog {
    max-height: 96dvh;
  }
  #storyBody {
    max-height: calc(96dvh - 70px);
    padding: 8px 16px 18px;
  }
}

/* The village clock supports scheduled visits without obscuring the landscape. */
#topHud {
  grid-template-columns: minmax(170px, 220px) minmax(58px, 0.65fr) minmax(
      32px,
      0.4fr
    ) minmax(52px, 0.5fr) minmax(48px, 0.5fr) minmax(58px, 0.6fr) minmax(
      72px,
      0.8fr
    );
}
#plannedExtrasText {
  display: block;
  font-size: 10px;
  align-self: center;
  max-width: 160px;
}
@media (max-width: 900px) {
  #topHud {
    grid-template-columns: minmax(155px, 185px) 58px 34px 55px 48px 58px minmax(
        68px,
        1fr
      );
    gap: 3px;
  }
  .brand strong {
    font-size: 13px;
  }
}
