/*
  星球勇者 / Planet Quest: the cube planet fills the stage under the site bar. Old-school
  windows (deep blue, a white double frame, a pointing hand) carry the talk, the menus and the
  battle; the party's status sits top-left; a pad and A / B buttons appear on touch screens.
*/

html,
body {
  height: 100%;
}

body.q-body {
  margin: 0;
  overflow: hidden;
  color: #f4f1e8;
  background: #04050d;
  font-family: var(--gh-font-body);
  overscroll-behavior: none;
}

.q-stage {
  --win: rgba(10, 14, 52, 0.93);
  --win-line: #f6f2e6;
  --ink: #f6f2e6;
  --dim: #a8b0d8;
  --gold: #ffd75a;
  --hp: #6ef08a;
  --low: #ff6a5a;
  position: fixed;
  inset: 56px 0 0;
  color: var(--ink);
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  font-size: 16px;
}

#qCanvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  opacity: 0;
  transition: opacity 900ms ease;
  image-rendering: auto;
}

.q-stage.is-ready #qCanvas {
  opacity: 1;
}

/* ------------------------------------------------------------ windows */
.q-win {
  position: absolute;
  z-index: 20;
  border: 3px solid var(--win-line);
  border-radius: 8px;
  background: var(--win);
  box-shadow: 0 0 0 2px #05061a, inset 0 0 0 2px #05061a, 0 12px 30px -10px rgba(0, 0, 0, 0.8);
  color: var(--ink);
  font-weight: 700;
  letter-spacing: 0.02em;
}

.q-msg {
  left: 50%;
  bottom: 18px;
  width: min(760px, calc(100% - 24px));
  min-height: 112px;
  padding: 14px 22px 16px;
  transform: translate(-50%, 12px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms ease, transform 120ms ease;
  box-sizing: border-box;
}

.q-msg.is-open {
  transform: translate(-50%, 0);
  opacity: 1;
  pointer-events: auto;
}

.q-msg-name {
  display: block;
  margin-bottom: 4px;
  color: var(--gold);
  font-size: 0.92em;
}

.q-msg-text {
  margin: 0;
  font-size: 1.12em;
  line-height: 1.7;
  white-space: pre-wrap;
}

.q-msg-more {
  position: absolute;
  right: 18px;
  bottom: 8px;
  font-style: normal;
  font-size: 0.8em;
  animation: q-blink 0.9s steps(2, start) infinite;
}

@keyframes q-blink {
  to { visibility: hidden; }
}

.q-list {
  right: 18px;
  bottom: 146px;
  min-width: 200px;
  max-width: min(560px, calc(100% - 36px));
  max-height: min(56vh, 460px);
  padding: 10px 10px 10px 8px;
  overflow: auto;
  box-sizing: border-box;
}

.q-list-title {
  margin: 2px 8px 6px 30px;
  color: var(--gold);
  font-size: 0.95em;
  font-weight: 700;
}

.q-items {
  display: grid;
  grid-template-columns: 1fr;
  gap: 2px 12px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.q-items.cols-2 {
  grid-template-columns: 1fr 1fr;
}

.q-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px 5px 30px;
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
}

.q-item.is-cur::before {
  content: "▶";
  position: absolute;
  left: 8px;
  font-size: 0.8em;
  animation: q-nudge 0.7s ease-in-out infinite alternate;
}

@keyframes q-nudge {
  to { transform: translateX(3px); }
}

.q-item.is-cur {
  background: rgba(255, 255, 255, 0.08);
}

.q-item.is-off {
  color: #6a7098;
}

.q-label {
  flex: 1;
}

.q-sub {
  color: var(--dim);
  font-size: 0.86em;
  font-variant-numeric: tabular-nums;
}

.q-ico {
  width: 28px;
  height: 28px;
  margin: -4px 0;
  image-rendering: pixelated;
}

.q-list-note {
  min-height: 2.6em;
  margin: 8px 6px 0;
  padding-top: 8px;
  border-top: 2px solid rgba(246, 242, 230, 0.25);
  color: var(--dim);
  font-size: 0.86em;
  font-weight: 500;
  line-height: 1.5;
  white-space: normal;
}

/* The field menu and its friends stack from the left. */
.q-list.q-menu {
  left: 18px;
  right: auto;
  top: 110px;
  bottom: auto;
}

.q-list.q-members,
.q-list.q-equip,
.q-list.q-bag {
  left: 210px;
  right: auto;
  top: 110px;
  bottom: auto;
  min-width: 300px;
}

.q-list.q-bag {
  left: auto;
  right: 18px;
  width: min(420px, calc(100% - 36px));
}

.q-list.q-choice {
  right: max(18px, calc(50% - 380px));
  bottom: 140px;
  min-width: 140px;
}

.q-status {
  left: 50%;
  top: 92px;
  width: min(460px, calc(100% - 24px));
  padding: 14px 20px;
  transform: translateX(-50%);
  box-sizing: border-box;
}

.q-status h3 {
  margin: 0 0 8px;
  color: var(--gold);
}

.q-status dl {
  display: grid;
  grid-template-columns: auto 1fr auto 1fr;
  gap: 4px 12px;
  margin: 0;
}

.q-status dt {
  color: var(--dim);
}

.q-status dd {
  margin: 0;
  font-variant-numeric: tabular-nums;
}

.q-gear,
.q-sk {
  margin: 10px 0 0;
  color: #d8dcf0;
  font-size: 0.9em;
  line-height: 1.6;
}

/* ------------------------------------------------------------ HUD */
.q-hud {
  position: absolute;
  inset: 10px 10px auto;
  z-index: 10;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  pointer-events: none;
}

.q-hud > * {
  pointer-events: auto;
}

.q-party {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-width: min(640px, 60vw);
}

.q-chip {
  display: grid;
  grid-template-columns: auto auto;
  gap: 1px 8px;
  min-width: 112px;
  padding: 6px 10px 7px;
  border: 2px solid rgba(246, 242, 230, 0.85);
  border-radius: 6px;
  background: rgba(10, 14, 52, 0.82);
  font-size: 0.82em;
}

.q-chip b {
  overflow: hidden;
  max-width: 7em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.q-chip span:first-of-type {
  color: var(--dim);
  justify-self: end;
}

.q-chip small {
  grid-column: 1 / -1;
  color: #d8dcf0;
  font-variant-numeric: tabular-nums;
}

.q-chip.is-dead {
  border-color: #ff6a5a;
  color: #ff9a8a;
}

.q-chip.is-poison {
  border-color: #c070ff;
}

.q-bar {
  grid-column: 1 / -1;
  height: 5px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.14);
  overflow: hidden;
}

.q-bar i {
  display: block;
  height: 100%;
  background: var(--hp);
  transition: width 250ms ease;
}

.is-dead .q-bar i,
.is-low .q-bar i {
  background: var(--low);
}

.q-where {
  align-self: center;
  padding: 6px 14px;
  border: 2px solid rgba(246, 242, 230, 0.7);
  border-radius: 999px;
  background: rgba(10, 14, 52, 0.75);
  font-weight: 700;
  font-size: 0.9em;
  white-space: nowrap;
}

.q-tools {
  display: flex;
  align-items: center;
  gap: 6px;
}

.q-gold {
  margin-right: 4px;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(10, 14, 52, 0.75);
  color: var(--gold);
  font-weight: 700;
  font-size: 0.9em;
  font-variant-numeric: tabular-nums;
}

.q-tools button {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border: 2px solid rgba(246, 242, 230, 0.75);
  border-radius: 8px;
  background: rgba(10, 14, 52, 0.78);
  color: var(--ink);
  cursor: pointer;
}

.q-tools button:hover {
  background: rgba(40, 50, 120, 0.9);
}

.q-tools svg {
  width: 22px;
  height: 22px;
}

.q-mute-line {
  display: none;
}

.q-tools button[aria-pressed="false"] .q-mute-line {
  display: inline;
}

.q-tools button[aria-pressed="false"] {
  color: #8088b0;
}

.is-title .q-hud,
.is-battle .q-hud,
.is-title .q-pad {
  display: none;
}

.is-mapview .q-party,
.is-mapview .q-pad {
  opacity: 0.35;
}

/* ------------------------------------------------------------ world map */
.q-maplabels {
  position: absolute;
  inset: 0;
  z-index: 8;
  overflow: hidden;
  pointer-events: none;
}

.q-maplabel {
  position: absolute;
  left: 0;
  top: 0;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(10, 14, 52, 0.78);
  color: var(--ink);
  font-size: 0.82em;
  font-weight: 700;
  white-space: nowrap;
  will-change: transform;
}

.q-maplabel.is-kingdom {
  padding: 0;
  background: none;
  color: #fff;
  font-family: var(--gh-font-display);
  font-size: clamp(1.1rem, 2.6vw, 1.7rem);
  letter-spacing: 0.08em;
  text-shadow: 0 2px 0 #11185a, 0 0 12px rgba(0, 0, 0, 0.8);
}

.q-maplabel.is-dungeon {
  background: rgba(70, 18, 90, 0.82);
}

.q-mapui {
  position: absolute;
  right: 12px;
  bottom: 14px;
  z-index: 12;
  display: grid;
  gap: 10px;
  width: min(300px, calc(100% - 24px));
  padding: 12px 14px;
  border: 3px solid var(--win-line);
  border-radius: 8px;
  background: var(--win);
  box-sizing: border-box;
}

.q-mapui[hidden] {
  display: none;
}

.q-mapui h2 {
  margin: 0;
  color: var(--gold);
  font-size: 1.05em;
}

.q-map-legend {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 10px;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 0.85em;
  font-weight: 600;
}

.q-map-legend i {
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-right: 6px;
  border: 2px solid #fff;
  border-radius: 3px;
  vertical-align: -1px;
}

.q-map-legend .is-hero { border-radius: 50%; background: #ffd75a; }
.q-map-legend .is-town { background: #a8382a; }
.q-map-legend .is-dungeon { background: #5a1a6a; }
.q-map-legend .is-gate { background: #60e8ff; transform: rotate(45deg) scale(0.85); }

.q-map-btns {
  display: flex;
  gap: 8px;
}

.q-map-btns button {
  flex: 1;
  height: 40px;
  border: 2px solid var(--win-line);
  border-radius: 6px;
  background: #1a2470;
  color: var(--ink);
  font: inherit;
  font-size: 1.2em;
  font-weight: 700;
  cursor: pointer;
}

.q-map-btns button:hover {
  background: #26349a;
}

.q-map-btns svg {
  width: 22px;
  height: 22px;
  vertical-align: middle;
}

.q-map-hint {
  margin: 0;
  color: var(--dim);
  font-size: 0.8em;
  line-height: 1.5;
}

.is-mapview #qCanvas {
  cursor: grab;
}

.is-mapview #qCanvas:active {
  cursor: grabbing;
}

.is-mapview .q-where,
.is-mapview .q-tools > :not([data-act="map"]):not(.q-gold) {
  visibility: hidden;
}

/* ------------------------------------------------------------ battle */
.q-foes {
  position: absolute;
  left: 50%;
  top: 12px;
  z-index: 10;
  display: none;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 16px;
  max-width: calc(100% - 24px);
  padding: 8px 18px;
  border: 3px solid var(--win-line);
  border-radius: 8px;
  background: var(--win);
  font-weight: 700;
  transform: translateX(-50%);
}

.is-battle .q-foes {
  display: flex;
}

.q-bhud {
  position: absolute;
  left: 50%;
  bottom: 140px;
  z-index: 15;
  display: flex;
  gap: 8px;
  max-width: calc(100% - 24px);
  transform: translateX(-50%);
}

.q-bhud[hidden] {
  display: none;
}

.q-mem {
  position: relative;
  display: grid;
  grid-template-columns: auto auto;
  gap: 2px 10px;
  min-width: 128px;
  padding: 8px 12px;
  border: 3px solid var(--win-line);
  border-radius: 8px;
  background: var(--win);
  font-weight: 700;
  font-size: 0.9em;
  transition: transform 150ms ease;
}

.q-mem.is-active {
  border-color: var(--gold);
  transform: translateY(-8px);
}

.q-mem.is-dead {
  border-color: var(--low);
  color: #ff9a8a;
}

.q-mem.is-low:not(.is-dead) {
  color: #ffd27a;
}

.q-mem .q-lv {
  color: var(--dim);
  justify-self: end;
}

.q-mem .q-num {
  font-variant-numeric: tabular-nums;
}

.q-mem .q-num em {
  font-style: normal;
}

.q-mem .q-st {
  position: absolute;
  top: -12px;
  right: 8px;
  padding: 1px 6px;
  border-radius: 4px;
  background: #6a2a9a;
  font-size: 0.8em;
}

.q-bmsg {
  bottom: 14px;
  min-height: 108px;
}

.q-list.q-cmd {
  left: max(12px, calc(50% - 380px));
  right: auto;
  bottom: 232px;
  min-width: 150px;
}

.q-list.q-skills,
.q-list.q-targets {
  left: max(176px, calc(50% - 216px));
  right: auto;
  bottom: 232px;
}

.q-list.q-skills {
  width: min(520px, calc(100% - 190px));
}

/* ------------------------------------------------------------ cards, crawl, toasts */
.q-card {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: grid;
  place-content: center;
  gap: 12px;
  padding: 24px;
  background: radial-gradient(ellipse at 50% 50%, rgba(10, 14, 52, 0.92), rgba(2, 3, 10, 0.97));
  text-align: center;
  opacity: 0;
  transition: opacity 600ms ease;
}

.q-card.is-on {
  opacity: 1;
}

.q-card small {
  color: var(--gold);
  font-size: 1.05em;
  font-weight: 700;
  letter-spacing: 0.16em;
}

.q-card h2 {
  margin: 0;
  font-family: var(--gh-font-display);
  font-size: clamp(2.2rem, 7vw, 4.2rem);
  letter-spacing: 0.08em;
  text-shadow: 0 0 24px rgba(120, 160, 255, 0.55);
}

.q-card p {
  margin: 0;
  color: #c8d0f0;
  font-size: 1.05em;
}

.q-card.is-end h2 {
  color: var(--gold);
}

.q-card.is-credit {
  background: rgba(2, 3, 10, 0.55);
}

.q-crawl {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 18px;
  padding: 24px max(24px, calc(50% - 360px));
  background: #02030a;
  opacity: 0;
  transition: opacity 700ms ease;
}

.q-crawl.is-on {
  opacity: 1;
}

.q-crawl p {
  margin: 0;
  color: #e8ecff;
  font-size: 1.15em;
  font-weight: 600;
  line-height: 1.8;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 1.2s ease, transform 1.2s ease;
}

.q-crawl p.is-on {
  opacity: 1;
  transform: none;
}

.q-toast {
  position: absolute;
  left: 50%;
  top: 70px;
  z-index: 30;
  padding: 8px 18px;
  border: 2px solid var(--win-line);
  border-radius: 999px;
  background: var(--win);
  font-weight: 700;
  transform: translate(-50%, -10px);
  opacity: 0;
  transition: opacity 300ms ease, transform 300ms ease;
  pointer-events: none;
}

.q-toast.is-on {
  transform: translate(-50%, 0);
  opacity: 1;
}

.q-fader {
  position: absolute;
  inset: 0;
  z-index: 35;
  background: #000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 600ms ease;
}

.q-fader.is-on {
  opacity: 1;
}

.q-flash {
  position: absolute;
  inset: 0;
  z-index: 36;
  opacity: 1;
  pointer-events: none;
  transition: opacity 500ms ease;
  mix-blend-mode: screen;
}

.q-ask {
  left: 50%;
  top: 40%;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px 22px;
  transform: translate(-50%, -50%);
}

.q-ask label {
  display: grid;
  gap: 8px;
  color: var(--gold);
}

.q-ask input {
  padding: 8px 12px;
  border: 2px solid var(--win-line);
  border-radius: 6px;
  background: #050822;
  color: var(--ink);
  font: inherit;
  font-size: 1.2em;
  text-align: center;
}

.q-btn {
  padding: 9px 18px;
  border: 2px solid var(--win-line);
  border-radius: 6px;
  background: #1a2470;
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.q-btn:hover {
  background: #26349a;
}

/* ------------------------------------------------------------ title */
.q-title {
  position: absolute;
  inset: 0;
  z-index: 25;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 10px;
  padding: 24px;
  background: radial-gradient(ellipse 60% 70% at 50% 50%, transparent 30%, rgba(2, 3, 12, 0.55) 80%);
  text-align: center;
  pointer-events: none;
}

.q-title > * {
  pointer-events: auto;
}

.q-title[hidden] {
  display: none;
}

.q-title-kicker {
  margin: 0;
  color: var(--gold);
  font-weight: 700;
  letter-spacing: 0.2em;
  text-shadow: 0 2px 6px #000;
}

.q-title h1 {
  margin: 0;
  font-family: var(--gh-font-display);
  font-size: clamp(3rem, 11vw, 6.5rem);
  line-height: 1;
  letter-spacing: 0.06em;
  color: #fff;
  text-shadow: 0 4px 0 #2a3aa8, 0 8px 0 #11185a, 0 0 40px rgba(120, 170, 255, 0.7);
}

.q-title-sub {
  margin: 0 0 16px;
  color: #d8e0ff;
  font-weight: 700;
  text-shadow: 0 2px 6px #000;
}

.q-cleared {
  color: var(--gold);
  font-weight: 700;
}

.q-title-menu {
  display: grid;
  gap: 8px;
  min-width: 240px;
  padding: 12px;
  border: 3px solid var(--win-line);
  border-radius: 8px;
  background: var(--win);
}

.q-title-menu button {
  position: relative;
  padding: 8px 18px;
  border: 0;
  border-radius: 4px;
  background: none;
  color: var(--ink);
  font: inherit;
  font-size: 1.1em;
  font-weight: 700;
  cursor: pointer;
}

.q-title-menu button[hidden] {
  display: none;
}

.q-title-menu button.is-cur,
.q-title-menu button:hover {
  background: rgba(255, 255, 255, 0.1);
}

.q-title-menu button.is-cur::before {
  content: "▶";
  position: absolute;
  left: 8px;
  font-size: 0.8em;
}

.q-title-keys {
  margin: 6px 0 0;
  color: #b8c0e8;
  font-size: 0.85em;
  text-shadow: 0 2px 6px #000;
}

/* ------------------------------------------------------------ help */
.q-help {
  left: 50%;
  top: 50%;
  width: min(880px, calc(100% - 24px));
  max-height: calc(100% - 40px);
  padding: 18px 24px;
  overflow: auto;
  transform: translate(-50%, -50%);
  box-sizing: border-box;
  font-weight: 500;
}

.q-help h2 {
  margin: 0 0 8px;
  color: var(--gold);
}

.q-help h3 {
  margin: 12px 0 6px;
  color: var(--gold);
  font-size: 1em;
}

.q-help-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 28px;
}

.q-help ul {
  margin: 0;
  padding-left: 1.2em;
  line-height: 1.7;
}

.q-help p {
  margin: 0;
  line-height: 1.7;
}

.q-help .q-btn {
  margin-top: 14px;
}

/* ------------------------------------------------------------ touch pad */
.q-pad {
  display: none;
}

@media (pointer: coarse), (max-width: 760px) {
  .q-mapui {
    bottom: calc(176px + env(safe-area-inset-bottom));
  }

  .q-pad {
    position: absolute;
    inset: auto 0 calc(8px + env(safe-area-inset-bottom));
    z-index: 12;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    padding: 0 12px;
    pointer-events: none;
  }

  .q-pad button {
    pointer-events: auto;
    touch-action: none;
    border: 2px solid rgba(246, 242, 230, 0.75);
    background: rgba(10, 14, 52, 0.62);
    color: var(--ink);
    font-weight: 700;
  }

  .q-dpad {
    position: relative;
    width: 150px;
    height: 150px;
  }

  .q-dpad button {
    position: absolute;
    width: 52px;
    height: 52px;
    border-radius: 10px;
    font-size: 18px;
  }

  .q-dpad .up { left: 49px; top: 0; }
  .q-dpad .down { left: 49px; bottom: 0; }
  .q-dpad .left { left: 0; top: 49px; }
  .q-dpad .right { right: 0; top: 49px; }

  .q-ab {
    display: flex;
    gap: 14px;
    align-items: flex-end;
  }

  .q-ab button {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    font-size: 22px;
  }

  .q-ab .a {
    margin-bottom: 30px;
    background: rgba(40, 70, 190, 0.75);
  }

  .is-battle .q-pad,
  .is-menu .q-pad .q-dpad {
    opacity: 0.85;
  }

  .q-msg {
    bottom: 170px;
  }

  .q-list.q-choice {
    bottom: 290px;
  }

  .is-battle .q-pad {
    display: flex;
  }

  .is-battle .q-pad .q-dpad {
    display: block;
  }

  .is-battle .q-bmsg {
    bottom: 170px;
  }

  .is-battle .q-bhud {
    bottom: 290px;
  }

  .is-battle .q-list.q-cmd,
  .is-battle .q-list.q-skills,
  .is-battle .q-list.q-targets {
    bottom: 360px;
  }
}

@media (max-width: 760px) {
  .q-stage {
    font-size: 14px;
  }

  .q-hud {
    flex-wrap: wrap;
  }

  .q-where {
    order: 3;
  }

  .q-chip {
    min-width: 0;
    padding: 4px 7px;
  }

  .q-tools button {
    width: 34px;
    height: 34px;
  }

  .q-tools [data-act="turnL"],
  .q-tools [data-act="turnR"],
  .q-tools [data-act="help"] {
    display: none;
  }

  .q-list.q-menu,
  .q-list.q-members,
  .q-list.q-equip,
  .q-list.q-bag {
    left: 10px;
    right: 10px;
    top: 96px;
    max-width: none;
    min-width: 0;
  }

  .q-list.q-members,
  .q-list.q-equip,
  .q-list.q-bag {
    top: 140px;
  }

  .q-bhud {
    gap: 4px;
  }

  .q-mem {
    min-width: 0;
    padding: 5px 7px;
    font-size: 0.82em;
  }

  .q-list.q-cmd {
    left: 10px;
  }

  .q-list.q-skills,
  .q-list.q-targets {
    left: 10px;
    right: 10px;
    width: auto;
  }

  .q-help-cols {
    grid-template-columns: 1fr;
  }

  .q-status dl {
    grid-template-columns: auto 1fr;
  }
}

.q-fallback {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 10px;
  padding: 24px;
  text-align: center;
}

.q-fallback[hidden] {
  display: none;
}
