/* Worlds Beyond HUD and the expansion pages of the shared Field Journal. */
:root {
  color-scheme: dark;
  font: 15px/1.45 Arial, Helvetica, sans-serif;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: #14252f;
  color: var(--frontier-paper);
  overscroll-behavior: none;
}
#cosmosView {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  outline: none;
}
#cosmosView:focus-visible { outline: 2px solid var(--frontier-mint); outline-offset: -2px; }
button, select, input { font: inherit; color: inherit; }
button, a.button, select {
  cursor: pointer;
  padding: 7px 11px;
  color: var(--frontier-paper);
  background: #142a32ee;
  border: 1px solid #c8dbc268;
  border-radius: 2px;
}
button:hover, a.button:hover { background: #294747; border-color: var(--frontier-mint); }
button:focus-visible, select:focus-visible, input:focus-visible, a:focus-visible {
  outline: 2px solid var(--frontier-mint);
  outline-offset: 2px;
}
button.active { background: #efd199; color: #223130; border-color: #f7dbab; }
small, #coords, #vitals, #nearby {
  color: #e9d4a7;
  font: 700 10px/1.4 "Courier New", monospace;
  letter-spacing: .08em;
}
kbd {
  display: inline-block;
  padding: 1px 4px;
  border: 1px solid #dbe5d277;
  border-radius: 2px;
  color: #fff5d7;
  font: 10px/1.2 "Courier New", monospace;
}

#mast, #deck, #objective, #rideBar, #notice, #touchNav { position: fixed; }
#mast {
  top: max(12px, env(safe-area-inset-top));
  right: max(14px, env(safe-area-inset-right));
  left: max(14px, env(safe-area-inset-left));
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 6px;
  pointer-events: none;
}
#mast > * { pointer-events: auto; }
#mast nav { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 5px; }
#mast nav button, #deck button { font-size: 13px; }
#helpBtn { color: var(--frontier-amber); }
.headplate, #objective, #deck, #rideBar {
  border: 1px solid #b4d1c35c;
  border-left: 2px solid var(--frontier-amber);
  border-radius: 2px;
  background: linear-gradient(105deg, #132331f5, #192e37e8);
  box-shadow: 0 3px 18px #11242429;
}
.headplate { padding: 8px 13px; }
.headplate small { color: var(--frontier-amber); }
.headplate h1 {
  margin: 3px 0;
  color: var(--frontier-paper);
  font: normal clamp(20px, 3vw, 29px)/1.1 Georgia, serif;
}
.headplate #coords { color: #e2e8d9; }
#compass { display: block; margin-top: 4px; color: #b6e9dd; font: 11px monospace; }

#deck {
  right: max(14px, env(safe-area-inset-right));
  bottom: max(14px, env(safe-area-inset-bottom));
  display: flex;
  gap: 6px;
  align-items: center;
  padding: 8px 10px;
  border-left-color: var(--frontier-mint);
}
#deck div > * { display: block; }
#deck div { padding-right: 9px; }
#deck small { color: var(--frontier-mint); }
#deck b { font: 600 16px/1.1 Georgia, serif; }
#vitals { color: var(--frontier-muted); }
#objective {
  left: max(14px, env(safe-area-inset-left));
  bottom: max(156px, calc(env(safe-area-inset-bottom) + 148px));
  width: min(360px, 40vw);
  padding: 9px 13px;
  pointer-events: none;
}
#objective strong, #objective span { display: block; }
#objective strong { font: normal 15px/1.3 Georgia, serif; }
#nearby { color: #ffda9a; margin-top: 4px; }
#trialReadout { display: block; color: #ffd18b; font: 12px monospace; margin: 7px 0; }
#trialReadout[hidden], #hitReadout[hidden] { display: none; }
#notice {
  z-index: 1;
  top: 20%;
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: 80vw;
  background: #14252feb;
  border: 1px solid #b5cfb26b;
  border-radius: 2px;
  color: #fff2d4;
  padding: 8px 14px;
  text-align: center;
  pointer-events: none;
  opacity: 0;
}
#notice.show { opacity: 1; }
#aim {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: #fff9da;
  text-shadow: 0 0 4px #151b1a;
  font: 21px monospace;
  pointer-events: none;
}
#aim.hit { color: #ffce83; font-weight: bold; font-size: 26px; }
#hitReadout {
  position: fixed;
  left: 50%;
  top: calc(50% + 30px);
  transform: translateX(-50%);
  max-width: 70vw;
  padding: 6px 10px;
  background: #172c2de8;
  border: 1px solid #ffce83;
  border-radius: 2px;
  color: #fff1d3;
  font: 12px monospace;
  text-align: center;
  pointer-events: none;
}
#rideBar { right: max(14px, env(safe-area-inset-right)); bottom: 156px; padding: 7px; }
#rideBar[hidden], #touchNav { display: none; }
#stations { display: flex; gap: 4px; margin: 5px 0; }
#rideBar button, #touchNav button { font: 600 11px/1.2 Arial, sans-serif; padding: 5px 7px; }
#touchNav {
  bottom: 156px;
  left: max(12px, env(safe-area-inset-left));
  grid-template-columns: repeat(4, 36px);
  gap: 3px;
  touch-action: none;
}
#touchNav button { min-height: 34px; touch-action: none; }

#portal {
  width: min(880px, calc(100% - 28px));
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-color: #617e70 #182d34;
}
#portal[open]:has(> .portal-scroll) { display: flex; flex-direction: column; overflow: hidden; }
#portal::backdrop { background: #07191cb8; }
.portal-scroll {
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-color: #617e70 #182d34;
  margin: -3px;
  padding: 3px;
}
#portal p { margin: 6px 0 12px; color: var(--frontier-muted); }
#portal h3 { margin: 6px 0; }
#portal a { color: var(--frontier-amber); }
#portal input { padding: 5px; background: #11262b; border: 1px solid #769185; }
#panelBody ul { padding-left: 19px; }
#panelBody label { display: block; margin: 7px 0; }
#panelBody select { max-width: 100%; }
#panelButtons {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(155px, 1fr));
  gap: 7px;
  margin-top: 12px;
}
#panelButtons:empty { display: none; }
#panelButtons button { min-height: 40px; padding: 8px 10px; text-align: left; }
.atlasGrid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}
#panelBody .atlasGrid button {
  min-width: 0;
  min-height: 76px;
  padding: 7px 9px;
  border-left: 3px solid var(--tint);
  text-align: left;
}
.atlasScene {
  display: block;
  width: 100%;
  height: 74px;
  object-fit: cover;
  margin-bottom: 6px;
}
.atlasGrid b { display: block; margin: 2px 0; font: normal 17px/1.1 Georgia, serif; }
.atlasGrid span { display: block; color: var(--frontier-muted); font-size: 11px; }
.brushes, .camp-controls { display: flex; flex-wrap: wrap; gap: 7px; }
.brushes button { border-left: 3px solid var(--tint); }
.field-card {
  margin: 9px 0;
  padding: 10px 12px;
  border: 1px solid var(--frontier-rule);
  background: #152c2f;
}
.field-card.route-card {
  border-left: 3px solid var(--frontier-amber);
  background: linear-gradient(110deg, #58463188, #243a3c);
}
.field-card summary { cursor: pointer; }
#portal .field-card :last-child:is(p, ul) { margin-bottom: 0; }
.field-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
  margin: 0;
}
.field-stats div { padding: 8px 10px; border: 1px solid var(--frontier-rule); background: #152c2f; }
.field-stats dt { color: var(--frontier-muted); font-size: 12px; line-height: 1.2; }
.field-stats dd { margin: 3px 0 0; color: var(--frontier-amber); font: normal 24px/1.1 Georgia, serif; }
.field-controls {
  display: grid;
  grid-template-columns: minmax(0, max-content) minmax(0, 1fr);
  gap: 8px 14px;
  align-items: start;
}
.field-controls dd { margin: 0; }
.field-controls dt { text-align: right; }
.camp-controls button[aria-pressed="true"] { border-color: #95ecdcaa; }

#hotbar {
  position: fixed;
  z-index: 4;
  left: 50%;
  bottom: max(82px, calc(env(safe-area-inset-bottom) + 74px));
  transform: translateX(-50%);
  width: min(880px, calc(100vw - 24px));
  padding: 6px 8px;
  border: 1px solid #b4d1c35c;
  border-radius: 3px;
  background: linear-gradient(105deg, #132331f5, #192e37e8);
  box-shadow: 0 8px 20px #07131680;
  pointer-events: auto;
}
.hotbar-slots { display: grid; grid-template-columns: repeat(9, minmax(0, 1fr)); gap: 4px; }
.hotbar-slot { display: grid; grid-template-columns: 19px minmax(0, 1fr) auto; grid-template-rows: auto auto; align-items: center; column-gap: 5px; min-width: 0; min-height: 42px; padding: 4px 5px; text-align: left; border-color: #82998d; }
.hotbar-slot.empty { visibility: hidden; }
.hotbar-slot.selected { border-color: #ffe09a; box-shadow: inset 0 0 0 1px #ffe09a80; }
.hotbar-swatch { grid-column: 1; grid-row: 1 / 3; width: 19px; height: 19px; border: 1px solid #fff6; background: var(--tint); background-size: cover; image-rendering: pixelated; }
.hotbar-name { grid-column: 2; grid-row: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 10px/1.1 Arial, sans-serif; }
.hotbar-count { grid-column: 2; grid-row: 2; color: var(--frontier-muted); font: 9px/1 monospace; }
.hotbar-slot kbd { grid-column: 3; grid-row: 1 / 3; font-size: 9px; }
.hotbar-page { display: block; margin-top: 3px; color: var(--frontier-muted); text-align: right; font: 9px/1.1 monospace; }
@media (pointer: coarse) {
  #touchNav { display: grid; }
  #objective { bottom: 180px; max-width: 45vw; }
  #rideBar { bottom: 180px; }
  #portal :is(button:not(.portraitPick), select) { min-height: 44px; }
}
@media (max-width: 680px) {
  #mast {
    top: max(5px, env(safe-area-inset-top));
    left: max(5px, env(safe-area-inset-left));
    right: max(5px, env(safe-area-inset-right));
  }
  .headplate { max-width: 53vw; padding: 5px 7px; }
  #hotbar { bottom: max(5px, env(safe-area-inset-bottom)); width: calc(100vw - 10px); padding: 4px; }
  .hotbar-slots { gap: 2px; }
  .hotbar-slot { grid-template-columns: 12px minmax(0, 1fr); column-gap: 3px; min-height: 34px; padding: 3px 2px; }
  .hotbar-swatch { width: 12px; height: 12px; }
  .hotbar-name { font-size: 7px; }
  .hotbar-count { font-size: 8px; }
  .hotbar-slot kbd { display: none; }
  .hotbar-page { font-size: 8px; }
  .headplate h1 { font-size: 19px; }
  #mast nav { max-width: 47vw; gap: 3px; }
  #mast nav button, #deck button { padding: 5px 7px; font-size: 11px; }
  #mast kbd, #deck kbd { display: none; }
  #deck {
    bottom: max(78px, calc(env(safe-area-inset-bottom) + 70px));
    left: max(5px, env(safe-area-inset-left));
    right: max(5px, env(safe-area-inset-right));

    justify-content: space-between;
  }
  #deck div { min-width: 0; padding-right: 3px; }
  #deck b { font-size: 14px; }
  #rideBar { right: max(5px, env(safe-area-inset-right)); bottom: 180px; max-width: 52vw; }
  #stations { flex-wrap: wrap; }
  #objective { left: max(5px, env(safe-area-inset-left)); bottom: 180px; width: 44vw; }
  #objective strong, #trialReadout, #hitReadout { font-size: 11px; }
  #trialReadout { margin: 3px 0; }
  #notice { top: 27%; }
  #compass { font-size: 10px; }
  #hitReadout { max-width: 90vw; }
  #portal { width: calc(100% - 18px); }
  #panelButtons, .atlasGrid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .atlasScene { height: 54px; }
}
@media (pointer: coarse) and (max-width: 680px) {
  #objective { width: calc(100vw - 10px); max-width: none; padding: 6px 9px; }
  body:has(#rideBar:not([hidden])) #objective { max-width: 44vw; }
  #mast nav button, #deck button { min-height: 34px; }
}

/* Touch play: one thumb joystick, an independent action cluster, and a persistent clean-HUD state. */
#touchStick { display: none; }
#hudBtn[aria-pressed="true"] { border-color: #ffe09a; color: #ffe09a; }
body.hud-clean .headplate,
body.hud-clean #objective,
body.hud-clean #hotbar,
body.hud-clean #notice,
body.hud-clean #rideBar,
body.hud-clean #deck > div { display: none; }
body.hud-clean #aim { opacity: .55; }
@media (pointer: coarse) {
  #touchStick {
    display: block;
    position: fixed;
    z-index: 5;
    left: max(10px, env(safe-area-inset-left));
    bottom: max(150px, calc(env(safe-area-inset-bottom) + 142px));
    width: 112px;
    height: 112px;
    border: 1px solid #b4d1c366;
    border-radius: 50%;
    background: radial-gradient(circle at 50% 50%, #14252fe0, #0b171de0);
    box-shadow: inset 0 0 0 1px #ffffff0d, 0 6px 16px #0006;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
  }
  #touchStick span {
    position: absolute;
    top: -15px;
    left: 50%;
    transform: translateX(-50%);
    color: #b7d1b7;
    font: 700 8px/1 "Courier New", monospace;
    letter-spacing: 1px;
    opacity: .75;
  }
  #touchStickKnob {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 48px;
    height: 48px;
    margin: -24px 0 0 -24px;
    border: 1px solid #f3cb90aa;
    border-radius: 50%;
    background: radial-gradient(circle at 38% 32%, #3a5a60, #172c33);
    box-shadow: 0 3px 10px #0007;
    pointer-events: none;
  }
  #touchNav {
    top: auto;
    right: max(8px, env(safe-area-inset-right));
    bottom: max(150px, calc(env(safe-area-inset-bottom) + 142px));
    left: auto;
    display: grid;
    grid-template-columns: repeat(2, minmax(44px, 1fr));
    gap: 4px;
    width: min(104px, 27vw);
    padding: 5px;
    border: 1px solid #b4d1c344;
    border-radius: 6px;
    background: #0d1c22c4;
  }
  #touchNav button { min-height: 44px; padding: 2px; font-size: 10px; }
  #touchNav button[hidden] { display: none; }
  #rideBar {
    top: calc(max(5px, env(safe-area-inset-top)) + 56px);
    right: max(8px, env(safe-area-inset-right));
    bottom: auto;
    z-index: 6;
    max-width: 58vw;
  }
  #objective {
    top: calc(max(5px, env(safe-area-inset-top)) + 124px);
    bottom: auto;
    left: max(5px, env(safe-area-inset-left));
    width: min(56vw, 320px);
  }
  body:has(#rideBar:not([hidden])) #objective { display: none; }
}
@media (pointer: coarse) and (max-height: 480px) {
  #touchStick { width: 92px; height: 92px; bottom: max(132px, calc(env(safe-area-inset-bottom) + 124px)); }
  #touchStickKnob { width: 40px; height: 40px; margin: -20px 0 0 -20px; }
  #touchNav { width: 92px; bottom: max(132px, calc(env(safe-area-inset-bottom) + 124px)); }
  #touchNav button { min-height: 40px; }
  #rideBar { top: calc(max(5px, env(safe-area-inset-top)) + 48px); }
}
@media (max-width: 680px) {
  #mast { flex-wrap: wrap; row-gap: 3px; }
  .headplate { flex: 1 1 100%; max-width: none; }
  #mast nav {
    width: 100%;
    max-width: none;
    flex-wrap: nowrap;
    justify-content: flex-start;
    overflow-x: auto;
    scrollbar-width: none;
  }
  #mast nav::-webkit-scrollbar { display: none; }
  #mast nav button { flex: 0 0 auto; }
  .headplate #coords { display: none; }
  #hotbar .hotbar-name { display: none; }
  #hotbar .hotbar-count { grid-column: 2; grid-row: 1 / 3; font-size: 8px; text-align: center; }
  #hotbar .hotbar-slot { grid-template-columns: 12px minmax(0, 1fr); min-height: 26px; }
  #hotbar .hotbar-page { display: none; }
  #deck { bottom: max(60px, calc(env(safe-area-inset-bottom) + 54px)); }
}

@media (pointer: coarse) and (max-height: 480px) {
  #mast { flex-wrap: nowrap; gap: 4px; }
  .headplate { flex: 0 1 auto; max-width: 46vw; padding: 4px 8px; }
  .headplate small { display: none; }
  .headplate h1 { margin: 1px 0; font-size: 18px; }
  .headplate #coords { display: none; }
  #compass { margin-top: 1px; font-size: 9px; }
  #mast nav { width: auto; max-width: none; flex-wrap: nowrap; gap: 2px; justify-content: flex-end; overflow: visible; }
  #mast nav button { min-height: 30px; padding: 4px 6px; font-size: 10px; }
  #objective {
    top: calc(max(5px, env(safe-area-inset-top)) + 50px);
    max-height: 94px;
    overflow: hidden;
    width: min(46vw, 320px);
  }
  #hotbar { bottom: max(4px, env(safe-area-inset-bottom)); width: calc(100vw - 10px); padding: 4px; }
  .hotbar-slots { gap: 2px; }
  .hotbar-slot { grid-template-columns: 12px minmax(0, 1fr); column-gap: 3px; min-height: 26px; padding: 3px 2px; }
  .hotbar-swatch { width: 12px; height: 12px; }
  .hotbar-name { display: none; }
  .hotbar-count { grid-column: 2; grid-row: 1 / 3; font-size: 8px; text-align: center; }
  .hotbar-slot kbd { display: none; }
  .hotbar-page { display: none; }
  #deck {
    right: max(5px, env(safe-area-inset-right));
    bottom: max(58px, calc(env(safe-area-inset-bottom) + 52px));
    left: max(5px, env(safe-area-inset-left));
    gap: 4px;
    padding: 6px 8px;
    justify-content: space-between;
  }
  #deck button { min-height: 34px; padding: 4px 6px; font-size: 11px; }
  #mast kbd, #deck kbd { display: none; }
  #touchStick { bottom: max(144px, calc(env(safe-area-inset-bottom) + 136px)); }
  #touchNav { bottom: max(144px, calc(env(safe-area-inset-bottom) + 136px)); }
}
