/* 0.66 UI pass. Loaded last, so it wins over the older sheets it corrects.
   1. One stacking order for everything that floats over the game: earlier sheets each picked their own numbers, and
      dialogs could open underneath the device or the beast storage (the game paused behind a screen you could not
      see). From the bottom up: HUD < panels < map < discovery ribbons < dialogs < toasts < fades and films < loading
      < splash < rotate-the-phone. */
:root {
  --z-hud: 10;
  --z-panel: 30;
  --z-device: 32;
  --z-map: 34;
  --z-ribbon: 70;
  --z-modal: 80;
  --z-toast: 90;
  --z-fade: 110;
  --z-film: 120;
  --z-loading: 150;
  --z-splash: 200;
  --z-top: 300;
}
#drawer,
.landscape-play #drawer,
.focus-ui {
  z-index: var(--z-panel);
}
body #drawer.device {
  z-index: var(--z-device);
}
#bigmap,
.landscape-play #bigmap {
  z-index: var(--z-map);
}
#discovery,
#app #discovery {
  z-index: var(--z-ribbon);
}
#modal-shade,
.landscape-play #modal-shade,
body.talk-cam #modal-shade {
  z-index: var(--z-modal);
}
#toasts {
  z-index: var(--z-toast);
}
#achievement-pop {
  z-index: var(--z-toast);
  /* it sat exactly on the dock button (Q); now it rises from the right edge below the minimap */
  bottom: auto;
  top: 340px;
}
#focus-fade {
  z-index: var(--z-fade);
}
#sleep-overlay {
  z-index: calc(var(--z-fade) + 1);
}
#film-flash {
  z-index: calc(var(--z-film) - 2);
}
#film-fade {
  z-index: calc(var(--z-film) - 1);
}
#intro-overlay {
  z-index: var(--z-film);
}
#load-screen {
  z-index: var(--z-loading);
}
#splash {
  z-index: var(--z-splash);
}
#rotate-screen {
  z-index: var(--z-top);
}

/* 2. What to do next, always on screen: the current instruction sits under the quest list as a button (tap it to
      hear the full line again). It used to vanish 11 seconds after the inner voice spoke it. */
#hud .mission .next-step {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  width: 100%;
  margin-top: 8px;
  padding: 8px 10px;
  text-align: left;
  font: inherit;
  font-size: 13px;
  line-height: 1.5;
  color: #eef4ea;
  background: #0a2a33d9;
  border: 1px solid #9ce8d14d;
  border-left: 3px solid var(--mint, #9ce8d1);
  border-radius: 8px;
  cursor: pointer;
}
#hud .mission .next-step:hover {
  background: #123d48e6;
}
#hud .mission .next-step b {
  flex: none;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #062027;
  background: var(--mint, #9ce8d1);
}
#hud .mission .next-step span {
  font-style: normal;
}
#hud .mission .next-step:has(span:empty) {
  display: none;
}

/* 3. While the mouse turns the camera (pointer lock) no HUD button can be clicked: say how to get the cursor back */
#cursor-chip {
  display: none;
  position: absolute;
  left: 50%;
  bottom: 118px;
  translate: -50% 0;
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 12px;
  color: #dfeee6;
  background: #041a25b3;
  border: 1px solid #9ce8d133;
  pointer-events: none;
  white-space: nowrap;
}
#cursor-chip kbd {
  padding: 0 5px;
  border-radius: 4px;
  border: 1px solid #9ce8d166;
  font: 11px monospace;
}
.mouse-look #cursor-chip {
  display: block;
  animation: chip-fade 6s ease forwards;
}
@keyframes chip-fade {
  0%,
  70% {
    opacity: 1;
  }
  100% {
    opacity: 0.35;
  }
}

/* 4. The main screens each have a labelled button in the bottom bar again: bag, beasts, journal, voyage, map
      (beside build and the device). Narrower than the old two so the row still fits beside the hotbar. */
#hud .bottom-hud .action-bar {
  gap: 4px;
}
#hud .bottom-hud .action-bar button.quick {
  width: 58px;
}
#hud .action-bar button {
  position: relative;
}
#hud .action-bar button kbd {
  position: absolute;
  top: 3px;
  right: 4px;
  font-size: 9px;
  opacity: 0.7;
}
@media (max-width: 1180px) {
  #hud .bottom-hud .action-bar button.quick {
    width: 48px;
  }
  #hud .bottom-hud .action-bar button.quick span:not(.tool-icon) {
    font-size: 10px;
  }
}

/* 5. Loading: a dark screen that is still working says so — a turning ring and what it is waiting for */
#focus-fade.busy::before,
#focus-fade.busy::after {
  position: absolute;
  left: 50%;
  translate: -50% 0;
}
#focus-fade.busy::before {
  content: '';
  top: calc(50% - 34px);
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid #9ce8d133;
  border-top-color: #9ce8d1;
  animation: ui-spin 0.9s linear infinite;
}
#focus-fade.busy::after {
  content: attr(data-label);
  top: calc(50% + 14px);
  font-size: 14px;
  letter-spacing: 0.08em;
  color: #cfe6e0;
  white-space: nowrap;
}
@keyframes ui-spin {
  to {
    rotate: 360deg;
  }
}
#load-screen .load-progress {
  width: min(320px, 70vw);
  height: 4px;
  border-radius: 2px;
  background: #264d54;
  overflow: hidden;
}
#load-screen .load-progress i {
  display: block;
  width: 3%;
  height: 100%;
  background: linear-gradient(90deg, #6fcfb6, #9ce8d1);
  box-shadow: 0 0 10px #9ce8d199;
  transition: width 0.35s ease;
}
#load-screen #load-step {
  margin-top: -14px;
  font-size: 12px;
  letter-spacing: 0.1em;
  color: #7fa9a4;
}
.ui-busy {
  display: grid;
  place-items: center;
  gap: 14px;
  min-height: 240px;
  color: #cfe6e0;
  font-size: 14px;
  letter-spacing: 0.06em;
}
.ui-busy i {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 3px solid #9ce8d133;
  border-top-color: #9ce8d1;
  animation: ui-spin 0.9s linear infinite;
}

/* 6. Dialogs: a close button where one makes sense; the settings as a tabbed sheet */
#modal {
  position: relative;
}
#modal .modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 36px;
  height: 36px;
  min-height: 36px;
  padding: 0;
  border-radius: 50%;
  font-size: 16px;
  line-height: 1;
  color: #cfe6e0;
  background: #ffffff0d;
  border: 1px solid #9ce8d133;
}
#modal .modal-close:hover {
  background: #9ce8d122;
}
#modal.settings-modal {
  width: 640px;
  padding: 28px 30px 24px;
}
#modal.settings-modal #modal-title {
  font-size: 24px;
  margin-bottom: 14px;
}
.settings.sheet .set-tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  margin-bottom: 16px;
  border-radius: 10px;
  background: #0000002e;
}
.settings.sheet .set-tabs button {
  flex: 1;
  min-height: 36px;
  padding: 6px 4px;
  border: 0;
  border-radius: 7px;
  background: none;
  color: #a9c9c2;
  font-size: 14px;
}
.settings.sheet .set-tabs button.active {
  color: #062027;
  background: var(--mint, #9ce8d1);
  font-weight: 700;
}
.settings.sheet .set-page {
  min-height: 260px;
}
.settings.sheet .set-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 2px;
  border-bottom: 1px solid #9ce8d114;
}
.settings.sheet .set-label {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.settings.sheet .set-label span {
  font-size: 15px;
  color: #eef4ea;
}
.settings.sheet .set-label small {
  font-size: 12px;
  color: #8fb3ad;
}
.settings.sheet .set-control {
  flex: none;
  display: flex;
  justify-content: flex-end;
  max-width: 62%;
}
.settings.sheet .seg {
  display: inline-flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 4px;
}
.settings.sheet .seg button {
  min-height: 32px;
  padding: 4px 12px;
  border-radius: 6px;
  font-size: 13px;
}
.settings.sheet .seg button.active {
  color: #062027;
  background: var(--mint, #9ce8d1);
  border-color: var(--mint, #9ce8d1);
}
/* sliders: a filled track and a round thumb */
.settings.sheet .range {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}
.settings.sheet .range output {
  width: 44px;
  text-align: right;
  font-size: 13px;
  color: #cfe6e0;
}
.settings.sheet input[type='range'] {
  -webkit-appearance: none;
  appearance: none;
  width: 200px;
  height: 6px;
  border-radius: 3px;
  background: #264d54;
  outline: none;
}
.settings.sheet input[type='range']::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--mint, #9ce8d1);
  box-shadow: 0 0 0 4px #9ce8d133;
  cursor: pointer;
}
.settings.sheet input[type='range']::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border: 0;
  border-radius: 50%;
  background: var(--mint, #9ce8d1);
  cursor: pointer;
}
/* on/off switches */
.settings.sheet .switch {
  position: relative;
  display: inline-block;
  width: 46px;
  height: 26px;
  cursor: pointer;
}
.settings.sheet .switch input {
  position: absolute;
  opacity: 0;
  inset: 0;
  margin: 0;
  cursor: pointer;
}
.settings.sheet .switch i {
  position: absolute;
  inset: 0;
  border-radius: 13px;
  background: #264d54;
  transition: background 0.2s;
  pointer-events: none;
}
.settings.sheet .switch i::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #cfe6e0;
  transition: translate 0.2s;
}
.settings.sheet .switch input:checked + i {
  background: var(--mint, #9ce8d1);
}
.settings.sheet .switch input:checked + i::after {
  translate: 20px 0;
  background: #062027;
}
.settings.sheet .switch input:focus-visible + i {
  outline: 2px solid #f5efd4;
  outline-offset: 2px;
}
/* the key list */
.settings.sheet h3 {
  margin: 14px 0 6px;
  font-size: 12px;
  letter-spacing: 0.12em;
  color: var(--mint, #9ce8d1);
}
.settings.sheet dl.keys {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 6px 14px;
  margin: 0;
}
.settings.sheet dl.keys dt {
  text-align: right;
}
.settings.sheet dl.keys kbd {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 5px;
  border: 1px solid #9ce8d14d;
  background: #00000033;
  font: 12px monospace;
  color: #eef4ea;
}
.settings.sheet dl.keys dd {
  margin: 0;
  font-size: 13px;
  color: #cfe6e0;
}
.settings.sheet .about-row {
  margin-bottom: 8px;
}
@media (max-width: 640px), (max-height: 520px) {
  #modal.settings-modal {
    padding: 18px 16px 14px;
  }
  .settings.sheet .set-page {
    min-height: 0;
  }
  .settings.sheet .set-row {
    padding: 8px 2px;
  }
  .settings.sheet input[type='range'] {
    width: 130px;
  }
}

/* the ☰ menu: an even grid of equal buttons instead of a ragged wrapped row; 繼續 spans the top */
#modal.menu-modal #modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
#modal.menu-modal #modal-actions button {
  width: 100%;
  min-height: 44px;
  white-space: normal;
  flex: none;
}
#modal.menu-modal #modal-actions button.primary {
  grid-column: 1 / -1;
}
#modal.menu-modal #modal-actions button:last-child {
  grid-column: 1 / -1;
  color: #f0b8a8;
}

/* 7. Choosing 電腦 or 手把 in the settings really takes the touch pad away (the media queries showed it on any
      touch screen whatever the setting said) */
body:not(.touch-device) #touch-controls {
  display: none !important;
}
/* the discovery ribbon no longer lands on the header's resource bar */
#discovery,
#app #discovery {
  top: 66px;
}

/* 8. Phones held sideways: the screen buttons fold behind 功能 (a grid that opens above it), and the next step
      keeps to two lines */
.landscape-play #hud .mission .next-step {
  margin-top: 4px;
  padding: 4px 7px;
  font-size: 11px;
  line-height: 1.4;
}
.landscape-play #hud .mission .next-step span {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
/* the bottom row was capped to a width that cut the action buttons off the end */
.landscape-play #hud .bottom-hud {
  max-width: none;
  overflow: visible;
}
/* the settings on a short screen: a compact head, tabs and 完成 always in view, only the page scrolls */
@media (max-height: 520px) {
  #modal.settings-modal {
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 16px);
    overflow: hidden;
    padding: 10px 14px;
  }
  #modal.settings-modal #modal-eyebrow {
    display: none;
  }
  #modal.settings-modal #modal-title {
    font-size: 16px;
    margin: 0 0 6px;
  }
  #modal.settings-modal .modal-close {
    top: 6px;
    right: 8px;
    width: 30px;
    height: 30px;
    min-height: 30px;
  }
  #modal.settings-modal #modal-body {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
  }
  .settings.sheet {
    display: flex;
    flex-direction: column;
    min-height: 0;
    flex: 1;
  }
  .settings.sheet .set-tabs {
    margin-bottom: 4px;
  }
  .settings.sheet .set-tabs button {
    min-height: 28px;
    padding: 3px;
    font-size: 12px;
  }
  .settings.sheet .set-page {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
  }
  #modal.settings-modal #modal-actions {
    margin-top: 6px;
  }
  #modal.settings-modal #modal-actions button {
    min-height: 34px;
    padding: 4px;
  }
}

/* 9. (0.67) The 選單 hub: one sheet for everything that used to be split between the device's app grid, the 功能
      buttons and the ☰ menu. A clean panel instead of the cracked phone frame. */
body #drawer.device {
  width: 440px;
  border-radius: 20px;
  border: 1px solid #9ce8d140;
  outline: none;
  background: radial-gradient(130% 70% at 20% 0%, #12343bf2 0%, #0a2229f5 55%, #071a20f8 100%), #071a20;
  box-shadow:
    0 24px 60px #000b,
    inset 0 1px 0 #ffffff12;
}
body #drawer.device::after,
body #drawer.device #drawer-body::after {
  display: none;
}
body #drawer.device .eyebrow {
  color: #7fa9a4;
  font-size: 11px;
}
body #drawer.device h2 {
  font-size: 22px;
  letter-spacing: 0.04em;
}
.hub-head {
  display: grid;
  gap: 8px;
  padding: 14px 16px;
  margin-bottom: 6px;
  border-radius: 14px;
  background: linear-gradient(135deg, #1b4a52cc, #0e2f37cc);
  border: 1px solid #9ce8d126;
}
.hub-head > div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}
.hub-head strong {
  font:
    600 30px/1 ui-monospace,
    Menlo,
    monospace;
  color: #eaf6f1;
}
.hub-head span {
  font-size: 13px;
  color: #a9c9c2;
}
.hub-head p {
  display: flex;
  gap: 8px;
  margin: 0;
  font-size: 13px;
  line-height: 1.5;
  color: #dceee8;
}
.hub-head p b {
  flex: none;
  height: fit-content;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 11px;
  color: #062027;
  background: var(--mint, #9ce8d1);
}
.hub-group {
  margin: 14px 2px 8px;
  font-size: 12px;
  letter-spacing: 0.14em;
  color: var(--mint, #9ce8d1);
}
.hub-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.hub-card {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 62px;
  padding: 10px 12px;
  text-align: left;
  border-radius: 12px;
  border: 1px solid #9ce8d124;
  background: #ffffff08;
  color: #eaf6f1;
  transition:
    background 0.15s,
    border-color 0.15s;
}
.hub-card:hover:not(:disabled) {
  background: #9ce8d114;
  border-color: #9ce8d166;
}
.hub-icon {
  flex: none;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  font-size: 20px;
  color: var(--gold, #e9c46a);
  background: #00000033;
  border: 1px solid #e9c46a33;
}
.hub-text {
  display: grid;
  gap: 2px;
  min-width: 0;
}
.hub-text b {
  font-size: 15px;
  font-weight: 600;
}
.hub-text small {
  font-size: 11.5px;
  line-height: 1.35;
  color: #9dbdb6;
}
.hub-card.locked {
  opacity: 0.55;
}
.hub-card.locked .hub-icon {
  filter: grayscale(1);
}
.hub-card[data-app='cross'] {
  grid-column: 1 / -1;
  border-color: #e9c46a66;
  background: linear-gradient(90deg, #e9c46a1f, #ffffff05);
}
@media (max-height: 560px) {
  body #drawer.device {
    width: min(760px, calc(100vw - 24px));
    border-radius: 16px;
    border-width: 1px;
  }
  .hub-head {
    padding: 8px 12px;
  }
  .hub-head strong {
    font-size: 20px;
  }
  .hub-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
  }
  .hub-card {
    min-height: 50px;
    padding: 6px 8px;
    gap: 7px;
  }
  .hub-icon {
    width: 30px;
    height: 30px;
    font-size: 16px;
  }
  .hub-text b {
    font-size: 13px;
  }
  .hub-text small {
    display: none;
  }
  .hub-group {
    margin: 8px 2px 5px;
  }
}

/* the bottom bar now carries only what you can use here: build (at home) and the hub */
#hud .bottom-hud .action-bar button.hub-button {
  border-color: #9ce8d166;
}
.hot-slot[hidden] {
  display: none !important;
}
/* the ☰ menu on a short screen: three columns of compact buttons, so it fits without scrolling */
@media (max-height: 560px) {
  #modal.menu-modal {
    padding: 14px 16px;
  }
  #modal.menu-modal #modal-eyebrow,
  #modal.menu-modal #modal-body {
    display: none;
  }
  #modal.menu-modal #modal-title {
    font-size: 16px;
    margin: 0 0 8px;
  }
  #modal.menu-modal #modal-actions {
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
  }
  #modal.menu-modal #modal-actions button {
    min-height: 38px;
    padding: 4px 6px;
    font-size: 13px;
  }
  #modal.menu-modal #modal-actions button.primary,
  #modal.menu-modal #modal-actions button:last-child {
    grid-column: auto;
  }
}
/* the hub on a short screen: no status line or clock card (the HUD has both), a small title, more room for cards */
@media (max-height: 560px) {
  body #drawer.device > header {
    padding: 6px 14px;
  }
  body #drawer.device .eyebrow {
    display: none;
  }
  body #drawer.device h2 {
    font-size: 15px;
  }
  body #drawer.device #close-drawer {
    top: 6px;
    right: 8px;
    width: 30px;
    height: 30px;
  }
  body #drawer.device #drawer-body {
    padding: 4px 12px 12px;
    overflow-y: auto;
  }
  #drawer.device .hub-head {
    display: none;
  }
}
/* phones held sideways: the vitals sit above the joystick, so the bottom row (hotbar + build + 選單) stays clear of
   the round action button on the right; the dock card shrinks to its title */
.landscape-play #hud .bottom-hud .vitals {
  /* the bottom row starts 158px in from the left edge: step back out to sit over the joystick */
  position: absolute;
  left: -150px;
  bottom: 118px;
  width: 128px;
  padding: 4px 8px;
  border-radius: 8px;
  background: #06222dcc;
}
.landscape-play #hud .bottom-hud .vitals #save-status {
  display: none;
}
.landscape-play #hud #dock-btn {
  min-width: 0;
  max-width: 150px;
  padding: 6px 10px;
}
.landscape-play #hud #dock-btn small,
.landscape-play #hud #dock-btn span:not(:first-child) {
  display: none;
}
body.landscape-play:has(#dock-btn:not([hidden])) #home-btn {
  display: none;
}

/* 10. (0.67 playtest) Phones with a beast out: the partner bar used to hide the whole quest block, next step
       included. Now only the title and list step aside; the next step stays, and the bar sits below the supplies. */
body.landscape-play.beast-on .mission {
  display: block;
}
body.landscape-play.beast-on .mission > .eyebrow,
body.landscape-play.beast-on #quest-title,
body.landscape-play.beast-on #quest-list {
  display: none;
}
body.landscape-play.beast-on .supply-row {
  margin-top: 4px;
}
body.landscape-play.beast-on #beast-bar {
  top: 116px;
}

/* 11. (0.67 playtest) things that sat on top of each other */
/* the tutorial card and the build banner (its 旋轉 / 結束建造 buttons were under the card) */
body:has(#tutorial:not([hidden])) #build-banner {
  top: 210px;
}
/* a facility close-up: its 管理 / 離開 bar is at the bottom, so the bottom HUD steps aside */
body.focus-on #hud .bottom-hud {
  display: none;
}
/* a discovery ribbon and the inner voice no longer print over each other */
body:has(#discovery:not([hidden])) #monologue {
  top: 150px;
}
/* world labels (island names, buildings) stay under the HUD's panels and buttons */
#world-labels {
  z-index: 1;
}
#hud .hud-header,
#hud .left-hud,
#hud .right-hud,
#hud .bottom-hud,
#tutorial,
#monologue,
#beast-bar,
#context-action {
  z-index: 3;
}
/* the fixed corner key hint said 駕艇 on foot and in town, and covered the action bar: the keys tab in 設定 lists
   every key instead */
#hud .control-hint {
  display: none;
}
/* the salvage line's bar only shows while a line is out */
#salvage-progress[hidden],
.salvage-progress[hidden] {
  display: none !important;
}
/* phones: the tutorial card sits to the right of the quest column instead of over it */
.landscape-play #tutorial {
  left: calc(var(--edge-left, 16px) + 236px);
  right: calc(var(--edge-right, 16px) + 110px);
  width: auto;
  max-width: none;
  translate: none;
  transform: none;
}
/* locked hub cards keep their unlock hint on a phone too (the others drop the subtitle for room) */
@media (max-height: 560px) {
  .hub-card.locked .hub-text small {
    display: block;
    font-size: 10px;
  }
}
