:root {
  --ivory: #F2E3C2;
  --gold: #E8A24B;
  --green: #7FA24B;
  --teal: #2E6E6B;
  --night: #12303A;
  --terra: #C4553B;
  --brown: #3B2A20;
  --deep: #07151b;
  --flag-blue: #0038A8;
  --flag-red: #CE1126;
  --flag-yellow: #FCD116;
  --pixel-shadow: 3px 3px 0 rgba(0, 0, 0, 0.42);
  --font-display: "Pixelify Sans", system-ui, sans-serif;
  --font-body: "IBM Plex Mono", ui-monospace, monospace;
  --font-num: "Silkscreen", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--deep);
  color: var(--ivory);
  font-family: var(--font-body);
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  -webkit-tap-highlight-color: transparent;
}

#app { position: fixed; inset: 0; }
.scene { position: absolute; inset: 0; }
[hidden] { display: none !important; }

img { image-rendering: pixelated; }
button { font: inherit; }

.key {
  display: inline-block;
  font-family: var(--font-num);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--ivory);
  background: var(--night);
  border: 1px solid #6f8f8e;
  padding: 2px 5px;
  line-height: 1.4;
  box-shadow: 1px 1px 0 #041014;
}

/* ------------------------------------------------------------------ */
/* Title screen                                                       */
/* ------------------------------------------------------------------ */

#title {
  background: #07151b;
  overflow-y: auto;
  overflow-x: hidden;
}

.title-bg {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 42%;
  animation: sea-breathe 34s ease-in-out infinite alternate;
}

@keyframes sea-breathe {
  from { transform: scale(1.01); }
  to { transform: scale(1.045); }
}

.title-shade {
  position: fixed;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(4, 13, 18, 0.55) 0%, rgba(4, 13, 18, 0) 24%, rgba(4, 13, 18, 0) 54%, rgba(4, 13, 18, 0.79) 88%, rgba(4, 13, 18, 0.94) 100%),
    radial-gradient(ellipse at 50% 42%, rgba(4, 13, 18, 0) 35%, rgba(4, 13, 18, 0.5) 100%);
  pointer-events: none;
}

.title-content {
  position: relative;
  z-index: 2;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: max(3.5vh, 18px) 16px 74px;
  text-align: center;
}

.title-art-wrap {
  width: min(900px, 94vw);
  animation: title-drift 17s ease-in-out infinite;
  filter: drop-shadow(0 3px 0 rgba(0, 0, 0, 0.38));
}

@keyframes title-drift {
  0%, 100% { transform: translate3d(0, 0, 0); }
  50% { transform: translate3d(2px, -5px, 0); }
}

.title-art {
  display: block;
  width: 100%;
  height: auto;
}

.flag-line {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-top: 2px;
  padding: 5px 10px;
  background: rgba(6, 18, 24, 0.55);
  border: 1px solid rgba(242, 227, 194, 0.38);
  box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.35);
}

.flag {
  width: 32px;
  height: 21px;
  display: block;
  box-shadow: 0 0 0 1px #06151c;
}

.flag-line span {
  font-family: var(--font-num);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--ivory);
}

.title-gloss {
  margin: 12px 0 0;
  max-width: 620px;
  font-size: clamp(10px, 1.15vw, 12px);
  letter-spacing: 0.02em;
  color: #cbbda5;
}

.title-tag {
  margin: 9px 0 0;
  font-family: var(--font-display);
  font-size: clamp(18px, 2.5vw, 27px);
  font-weight: 700;
  color: var(--ivory);
  text-shadow: 2px 2px 0 #07151b;
}

.title-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-top: clamp(16px, 3vh, 28px);
  width: 100%;
}

.pixel-button {
  position: relative;
  width: min(310px, 82vw);
  aspect-ratio: 280 / 108;
  border: 0;
  padding: 0;
  background: transparent;
  color: #3b2a20;
  font-family: var(--font-display);
  font-size: clamp(18px, 2.4vw, 25px);
  font-weight: 700;
  letter-spacing: 0.02em;
  cursor: pointer;
  text-shadow: 0 1px 0 rgba(255, 246, 218, 0.4);
  transition: transform 80ms steps(1);
}

.pixel-button:hover { filter: brightness(1.04); }
.pixel-button:active,
.pixel-button.pressed {
  background-image: none;
  transform: translateY(2px);
}
.pixel-button:focus-visible { outline: 2px solid var(--ivory); outline-offset: 3px; }
.pixel-button:disabled { opacity: 0.6; cursor: wait; }

.text-button {
  background: none;
  border: 0;
  color: #e5d6ba;
  font-size: 11px;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
  padding: 4px;
}
.text-button:hover { color: #fff5df; }

.title-save-note {
  min-height: 16px;
  margin: 6px 0 0;
  font-size: 10px;
  color: #a9b3a4;
}

.title-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 16px;
  margin-top: clamp(14px, 2.6vh, 26px);
  font-size: 10px;
  color: #d7c9ae;
}

.title-controls > span { white-space: nowrap; }

.title-small {
  max-width: 540px;
  margin: 12px 0 0;
  font-size: 9.5px;
  line-height: 1.6;
  color: #9cae9f;
}

.title-foot {
  position: fixed;
  z-index: 3;
  bottom: max(8px, env(safe-area-inset-bottom));
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  gap: 7px;
  font-family: var(--font-num);
  font-size: 8px;
  letter-spacing: 0.1em;
  color: #8f9f98;
  pointer-events: none;
}
.title-foot .dot { color: var(--gold); }

.sound-toggle {
  position: fixed;
  z-index: 5;
  top: max(10px, env(safe-area-inset-top));
  right: 12px;
  background: rgba(6, 18, 24, 0.7);
  border: 1px solid #5f7f7e;
  color: var(--ivory);
  font-family: var(--font-num);
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 7px 9px;
  cursor: pointer;
  text-transform: uppercase;
}
.sound-toggle:hover { border-color: var(--gold); }
.fs-toggle { left: 12px; right: auto; }

/* ------------------------------------------------------------------ */
/* Game shell                                                         */
/* ------------------------------------------------------------------ */

#game { background: #0a202a; }
#phaser { position: absolute; inset: 0; }
#phaser canvas { display: block; touch-action: none; }

.hud {
  position: absolute;
  z-index: 20;
  top: 0;
  left: 0;
  right: 0;
  padding: max(7px, env(safe-area-inset-top)) 10px 0;
  pointer-events: none;
}

.hud-strip {
  pointer-events: auto;
  position: relative;
  display: flex;
  align-items: center;
  gap: clamp(6px, 1vw, 13px);
  width: 100%;
  max-width: 1010px;
  min-height: 70px;
  margin: 0 auto;
  padding: 7px clamp(8px, 1.4vw, 15px);
  background: transparent;
  filter: drop-shadow(2px 2px 0 rgba(0, 0, 0, 0.32));
}

.portrait-wrap {
  flex: 0 0 auto;
  width: clamp(42px, 5vw, 58px);
  height: clamp(44px, 5.2vw, 60px);
  overflow: hidden;
}
.portrait { width: 100%; height: 100%; object-fit: contain; display: block; }

.who { display: flex; flex-direction: column; min-width: 0; padding-top: 2px; }
.who-top { display: flex; align-items: baseline; gap: 7px; }
.hero-name {
  font-family: var(--font-display);
  font-size: clamp(13px, 1.4vw, 17px);
  font-weight: 700;
  color: #f8ecd2;
  line-height: 1.1;
  white-space: nowrap;
}
.level {
  font-family: var(--font-num);
  font-size: clamp(8px, 0.8vw, 10px);
  font-weight: 700;
  color: var(--gold);
  letter-spacing: 0.06em;
  white-space: nowrap;
}
.hero-class {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 2px;
  font-family: var(--font-num);
  font-size: clamp(7px, 0.75vw, 9px);
  letter-spacing: 0.06em;
  color: #e7d9bd;
  white-space: nowrap;
}
.hero-class em { font-family: var(--font-body); font-style: normal; font-size: 8px; color: #b9c3b3; }
.level-inline { display: none; margin-left: 4px; color: var(--gold); }
.badge-mini img { width: 13px; height: 14px; display: block; }
.exp-line { display: flex; align-items: center; gap: 4px; margin-top: 2px; }
.exp-bar {
  width: clamp(34px, 5vw, 60px);
  height: 4px;
  background: #0b1c21;
  border: 1px solid #061014;
  box-shadow: inset 0 0 0 1px rgba(242, 227, 194, 0.12);
  overflow: hidden;
}
.exp-bar span { display: block; width: 0%; height: 100%; background: var(--gold); transition: width 140ms linear; }
.exp-label { font-family: var(--font-num); font-size: 7px; color: #91b2ab; }
.exp-num { font-family: var(--font-num); font-size: 7px; color: #cbbda4; white-space: nowrap; }

.vitals {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1 1 90px;
  max-width: 150px;
  min-width: 64px;
}
.vital { display: flex; align-items: center; gap: 4px; }
.vital-icon { width: clamp(12px, 1.4vw, 16px); height: auto; flex: 0 0 auto; }
.bar {
  position: relative;
  flex: 1 1 auto;
  height: 7px;
  background: #0b1c21;
  border: 1px solid #061014;
  box-shadow: inset 0 0 0 1px rgba(242, 227, 194, 0.13);
  overflow: hidden;
}
.bar > span { display: block; height: 100%; width: 100%; }
.bar.hp > span { background: var(--terra); }
.bar.sp > span { background: var(--teal); }
.vital-num {
  font-family: var(--font-num);
  font-size: 7px;
  color: #f0e2c8;
  min-width: 20px;
  text-align: right;
}

.area-tag {
  display: flex;
  align-items: center;
  gap: 6px;
  padding-left: 10px;
  border-left: 1px solid rgba(242, 227, 194, 0.16);
  flex: 0 0 auto;
}
.area-tag img { width: 24px; height: 24px; }
.area-tag b {
  display: block;
  font-family: var(--font-display);
  font-size: 12px;
  line-height: 1.1;
  color: #f4e6c8;
}
.area-tag span {
  display: block;
  font-family: var(--font-num);
  font-size: 7px;
  color: #a9c1b8;
  letter-spacing: 0.08em;
}

.rank {
  display: flex;
  align-items: center;
  gap: 5px;
  padding-left: 10px;
  border-left: 1px solid rgba(242, 227, 194, 0.16);
  flex: 0 0 auto;
}
.rank img { width: 27px; height: 30px; }
.rank span {
  font-family: var(--font-num);
  font-size: 7px;
  font-weight: 700;
  letter-spacing: 0.13em;
  color: var(--gold);
}

.hud-buttons { display: flex; align-items: center; gap: 4px; margin-left: auto; flex: 0 0 auto; }
.hud-icon-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 31px;
  padding: 3px 6px;
  background: rgba(7, 21, 27, 0.58);
  border: 1px solid #5d7b7a;
  color: var(--ivory);
  font-family: var(--font-num);
  font-size: 7px;
  font-weight: 700;
  letter-spacing: 0.07em;
  cursor: pointer;
}
.hud-icon-btn img { width: 19px; height: 19px; }
.hud-icon-btn.square { width: 31px; justify-content: center; padding: 0; font-size: 12px; }
.hud-icon-btn.auto-btn {
  width: 40px;
  justify-content: center;
  padding: 0;
  font-size: 6px;
  letter-spacing: 0.04em;
  color: #a9c1b8;
}
.hud-icon-btn.auto-btn.auto-on {
  background: var(--gold);
  border-color: #fff0c9;
  color: #2a1d10;
}
.hud-icon-btn:hover { border-color: var(--gold); }
.hud-icon-btn:active { transform: translateY(1px); }
.hud-icon-btn:focus-visible { outline: 1px solid var(--ivory); outline-offset: 2px; }

.hud-bars {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: 6px;
  flex-wrap: wrap;
  max-width: min(96vw, 980px);
  margin: 4px auto 0;
}
.hud-bars .quest-strip,
.hud-bars .event-bar { margin: 0; }

@media (min-width: 700px) {
  .hud-bars {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    width: min(96vw, 940px);
  }
  .hud-bars .quest-strip,
  .hud-bars .event-bar { max-width: none; width: auto; justify-self: center; }
}

.quest-strip {
  pointer-events: none;
  display: flex;
  align-items: center;
  gap: 8px;
  width: fit-content;
  max-width: min(92vw, 640px);
  margin: 4px auto 0;
  padding: 4px 10px 4px 8px;
  background: rgba(7, 21, 27, 0.74);
  border-left: 2px solid var(--gold);
  border-right: 1px solid rgba(242, 227, 194, 0.18);
  font-size: clamp(8.5px, 0.9vw, 10px);
  line-height: 1.35;
  color: #eadfc6;
  box-shadow: 1px 1px 0 rgba(0, 0, 0, 0.35);
}
.quest-kicker {
  flex: 0 0 auto;
  font-family: var(--font-num);
  font-size: 7px;
  letter-spacing: 0.1em;
  color: var(--gold);
}
#quest-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ------------------------------------------------------------------ */
/* Toast / interaction prompt                                         */
/* ------------------------------------------------------------------ */

.toast {
  position: absolute;
  z-index: 26;
  top: calc(max(7px, env(safe-area-inset-top)) + 106px);
  left: 50%;
  transform: translate(-50%, -7px);
  width: min(430px, 88vw);
  min-height: 52px;
  padding: 12px 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  background: transparent;
  color: var(--brown);
  font-size: clamp(10px, 1vw, 12px);
  line-height: 1.35;
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.interact-prompt {
  position: absolute;
  z-index: 24;
  left: 50%;
  bottom: calc(74px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 11px;
  background: rgba(9, 27, 34, 0.88);
  border: 2px solid var(--ivory);
  box-shadow: var(--pixel-shadow);
  font-size: 11px;
  color: var(--ivory);
  white-space: nowrap;
  pointer-events: none;
}
.prompt-dot { width: 8px; height: 8px; background: var(--gold); display: block; }
.prompt-key { margin-left: 2px; }

/* ------------------------------------------------------------------ */
/* Dialogue                                                           */
/* ------------------------------------------------------------------ */

.dialog {
  position: absolute;
  z-index: 30;
  left: 50%;
  bottom: calc(14px + env(safe-area-inset-bottom));
  width: min(780px, 94vw);
  height: clamp(170px, 23vh, 202px);
  padding: 40px 32px 20px 24%;
  background: transparent;
  color: var(--brown);
  transform: translate(-50%, 130%);
  transition: transform 155ms cubic-bezier(0.2, 0.85, 0.3, 1);
  filter: drop-shadow(3px 3px 0 rgba(0, 0, 0, 0.36));
}
.dialog.open { transform: translate(-50%, 0); }

.speaker-icon {
  position: absolute;
  left: 11%;
  top: 23%;
  width: 13%;
  height: 38%;
  background: #12303a;
  border: 2px solid #3b2a20;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.speaker-icon img { width: 100%; height: 100%; object-fit: contain; }
.speaker-icon.creature { background: #d8c7a6; }

.dialog-copy { height: 100%; display: flex; flex-direction: column; min-width: 0; }
.speaker-name {
  font-family: var(--font-display);
  font-size: clamp(14px, 1.5vw, 18px);
  font-weight: 700;
  line-height: 1.1;
  color: #9b5d12;
}
.speaker-name span {
  display: inline;
  font-family: var(--font-body);
  font-size: 9px;
  font-weight: 400;
  color: #725c45;
}
.dialog-text {
  margin: 6px 0 0;
  font-size: clamp(11px, 1.1vw, 13.5px);
  line-height: 1.5;
  color: #3b2a20;
  max-height: 92px;
  overflow: hidden;
}
.dialog-cursor {
  display: inline-block;
  width: 7px;
  height: 10px;
  margin-left: 2px;
  background: var(--teal);
  vertical-align: -1px;
  animation: cursor-blink 900ms steps(1) infinite;
}
@keyframes cursor-blink { 0%, 55% { opacity: 1; } 56%, 100% { opacity: 0; } }

.dialog-next {
  position: absolute;
  right: 18px;
  bottom: 16px;
  border: 0;
  background: none;
  color: #2e6e6b;
  font-family: var(--font-num);
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.08em;
  cursor: pointer;
  padding: 4px;
}
.dialog-next:hover { color: #9b5d12; }

/* ------------------------------------------------------------------ */
/* Touch controls                                                     */
/* ------------------------------------------------------------------ */

.touch-controls { display: none; }

body.touch .touch-controls {
  position: absolute;
  z-index: 23;
  left: 10px;
  right: 10px;
  bottom: calc(10px + env(safe-area-inset-bottom));
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  pointer-events: none;
}

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 42px);
  grid-template-rows: repeat(3, 42px);
  gap: 3px;
  width: 132px;
  height: 132px;
  pointer-events: auto;
  touch-action: none;
}
.dpad-btn {
  background: rgba(7, 21, 27, 0.56);
  border: 2px solid #648583;
  color: var(--ivory);
  font-size: 13px;
  line-height: 1;
  padding: 0;
  cursor: pointer;
  touch-action: none;
  user-select: none;
}
.dpad-btn.up { grid-area: 1 / 2; }
.dpad-btn.left { grid-area: 2 / 1; }
.dpad-btn.right { grid-area: 2 / 3; }
.dpad-btn.down { grid-area: 3 / 2; }
.dpad-btn:active, .dpad-btn.on { background: var(--teal); border-color: var(--ivory); }

.touch-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  pointer-events: auto;
}
.run-btn {
  width: 62px;
  height: 38px;
  background: rgba(7, 21, 27, 0.56);
  border: 2px solid var(--gold);
  color: var(--gold);
  font-family: var(--font-num);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.08em;
  cursor: pointer;
  touch-action: none;
}
.run-btn[aria-pressed="true"] { background: var(--gold); color: #23180f; }
.action-btn {
  width: 78px;
  height: 78px;
  background: rgba(18, 48, 58, 0.82);
  border: 3px solid #7b9b95;
  color: var(--ivory);
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.02em;
  box-shadow: var(--pixel-shadow);
  cursor: pointer;
  touch-action: none;
}
.action-btn.ready { border-color: var(--gold); color: #ffe9b8; }
.action-btn:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 rgba(0, 0, 0, 0.42); }

body.dialog-open .touch-controls,
body.dialog-open .interact-prompt { display: none; }

/* ------------------------------------------------------------------ */
/* Loading                                                            */
/* ------------------------------------------------------------------ */

.loading {
  position: absolute;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  background: rgba(4, 14, 19, 0.88);
  padding: 20px;
}
.loading-box {
  width: min(330px, 88vw);
  padding: 20px 22px 18px;
  text-align: center;
  background: var(--ivory);
  color: var(--brown);
  border: 3px solid var(--night);
  box-shadow: 4px 4px 0 #041014;
}
.loading-glyph { width: 46px; margin: 0 auto 8px; }
.loading-glyph img { width: 100%; height: auto; }
.loading-box p {
  margin: 0 0 12px;
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 700;
}
.loading-bar {
  height: 10px;
  background: var(--night);
  border: 1px solid #06151c;
  padding: 1px;
}
.loading-bar span { display: block; height: 100%; width: 0%; background: var(--gold); transition: width 160ms ease; }

/* ------------------------------------------------------------------ */
/* Codex                                                              */
/* ------------------------------------------------------------------ */

.codex-overlay {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 2vh max(3vw, 12px);
  background: rgba(4, 14, 19, 0.68);
}

.codex-page {
  position: relative;
  width: min(470px, 43vw, calc(90vh * 0.587));
  aspect-ratio: 601 / 1024;
  filter: drop-shadow(4px 4px 0 rgba(0, 0, 0, 0.42));
}

.codex-parchment { width: 100%; height: 100%; display: block; }

.codex-banner {
  position: absolute;
  top: 6.4%;
  left: 10.2%;
  width: 85.5%;
  height: 12.4%;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 6px;
  background: #10100d;
  color: var(--ivory);
}
.codex-title { flex: 1 1 auto; text-align: center; line-height: 1; min-width: 0; }
.codex-title span {
  display: block;
  font-family: var(--font-display);
  font-size: clamp(13px, 1.5vw, 18px);
  font-weight: 700;
  letter-spacing: 0.1em;
}
.codex-title em {
  display: block;
  margin-top: 3px;
  font-family: var(--font-body);
  font-style: normal;
  font-size: clamp(6px, 0.6vw, 8px);
  letter-spacing: 0.1em;
  color: #b9c7b1;
}
.codex-arrow {
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  background: transparent;
  border: 1px solid #6b7f72;
  color: var(--ivory);
  font-family: var(--font-num);
  font-size: 11px;
  cursor: pointer;
  padding: 0;
}
.codex-arrow:hover { border-color: var(--gold); color: var(--gold); }

.codex-close {
  position: absolute;
  top: -34px;
  right: 0;
  width: 30px;
  height: 30px;
  background: #10100d;
  border: 1px solid #8a9a88;
  color: var(--ivory);
  font-family: var(--font-num);
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  z-index: 2;
}
.codex-close:hover { border-color: var(--gold); color: var(--gold); }

.codex-body {
  position: absolute;
  top: 20.2%;
  left: 9.6%;
  right: 9.8%;
  bottom: 17%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.codex-index { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 7px; flex: 0 0 auto; }
.codex-index button {
  width: 9px;
  height: 9px;
  padding: 0;
  border: 1px solid #a59172;
  background: transparent;
  cursor: pointer;
}
.codex-index button.unlocked { background: #2e6e6b; border-color: #2e6e6b; }
.codex-index button.current { background: var(--gold); border-color: #8a5a1a; }
.codex-index button.locked { background: transparent; opacity: 0.55; }

.codex-entry { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; }
.codex-word {
  font-family: var(--font-display);
  font-size: clamp(25px, 3.2vw, 38px);
  font-weight: 700;
  line-height: 0.98;
  color: #2e6e6b;
  letter-spacing: -0.01em;
}
.codex-gloss {
  margin-top: 4px;
  font-family: var(--font-num);
  font-size: clamp(7px, 0.7vw, 9px);
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: #81684d;
}
.codex-rule { height: 2px; background: #2e6e6b; opacity: 0.55; margin: 9px 0 9px; flex: 0 0 auto; }
.codex-note {
  margin: 0;
  padding-right: 4px;
  font-size: clamp(10.5px, 1.05vw, 13px);
  line-height: 1.62;
  color: #3b2a20;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #a59172 transparent;
}
.codex-note::-webkit-scrollbar { width: 4px; }
.codex-note::-webkit-scrollbar-thumb { background: #a59172; }
.codex-locked { flex: 1 1 auto; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; color: #74604a; }
.codex-locked .lock-mark { font-family: var(--font-display); font-size: 40px; color: #b7a184; line-height: 1; }
.codex-locked p { max-width: 240px; margin: 6px 0 0; font-size: 10.5px; line-height: 1.5; }

.codex-seal-row {
  position: absolute;
  left: 6%;
  right: 6%;
  bottom: 13%;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 26px;
  pointer-events: none;
}
.codex-seal { text-align: center; }
.codex-seal img { width: clamp(20px, 2.4vw, 28px); height: auto; display: block; margin: 0 auto; }
.codex-seal span {
  display: block;
  margin-top: 2px;
  font-family: var(--font-num);
  font-size: clamp(6px, 0.6vw, 7.5px);
  font-weight: 700;
  letter-spacing: 0.03em;
  line-height: 1.2;
  color: #3b2a20;
  max-width: 112px;
}
.codex-seal.mixed span { color: #7a3a26; }

.codex-legend {
  position: absolute;
  left: 8%;
  right: 8%;
  bottom: 18.4%;
  text-align: center;
  font-size: clamp(6px, 0.58vw, 7.5px);
  line-height: 1.3;
  color: #6b5741;
}

/* ------------------------------------------------------------------ */
/* Help                                                               */
/* ------------------------------------------------------------------ */

.help-overlay {
  position: absolute;
  inset: 0;
  z-index: 55;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(4, 14, 19, 0.68);
}
.help-panel {
  position: relative;
  width: min(360px, 90vw);
  padding: 50px 26px 22px;
  background: transparent;
  color: var(--brown);
  filter: drop-shadow(4px 4px 0 rgba(0, 0, 0, 0.4));
}
.help-head {
  position: absolute;
  top: 14px;
  left: 10px;
  right: 10px;
  text-align: center;
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--ivory);
}
.help-body p { margin: 0 0 7px; font-size: 10.5px; line-height: 1.5; }
.help-body b { color: #2e6e6b; }
.help-note { margin-top: 10px !important; padding-top: 8px; border-top: 1px solid rgba(59, 42, 32, 0.25); font-size: 9px !important; color: #6d5842; }
.help-close {
  display: block;
  margin: 12px auto 0;
  padding: 6px 16px;
  background: var(--night);
  border: 1px solid #06151c;
  color: var(--ivory);
  font-family: var(--font-num);
  font-size: 9px;
  letter-spacing: 0.08em;
  cursor: pointer;
}
.help-close:hover { background: var(--teal); }

/* ------------------------------------------------------------------ */
/* Movement and skill controls                                        */
/* ------------------------------------------------------------------ */

.touch-controls { display: none; }

.skill-dock {
  position: absolute;
  left: 50%;
  bottom: calc(10px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 24;
  display: flex;
  align-items: center;
  gap: 6px;
  pointer-events: auto;
}
.skill-edit {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 2px solid #8fa39a;
  background: rgba(7,21,27,0.78);
  color: #d8e8d2;
  font-family: var(--font-num);
  font-size: 6px;
  font-weight: 700;
  letter-spacing: 0.03em;
  cursor: pointer;
}
.skill-bar { display: flex; gap: 6px; }
.skill-slot {
  position: relative;
  width: 47px;
  height: 47px;
  border-radius: 50%;
  border: 3px solid #8fa39a;
  background: rgba(7,21,27,0.82);
  color: var(--ivory);
  cursor: pointer;
  padding: 0;
  overflow: hidden;
  touch-action: none;
}
.skill-slot .skill-glyph {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-num);
  font-size: 6.5px;
  font-weight: 700;
  letter-spacing: 0.01em;
}
.skill-slot .skill-cost {
  position: absolute;
  right: 4px;
  bottom: 3px;
  font-family: var(--font-num);
  font-size: 6px;
  color: var(--gold);
}
.skill-slot .skill-cd {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(4,14,19,0.72);
  color: #fff5df;
  font-family: var(--font-num);
  font-size: 10px;
  font-weight: 700;
}
.skill-slot.cooling .skill-cd { display: flex; }
.skill-slot.cooling { border-color: #5e6e64; filter: saturate(0.5); }
.skill-slot.no-sp { opacity: 0.55; }
.skill-slot:active { transform: scale(0.94); }
.skill-slot:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

.touch-actions {
  position: absolute;
  right: 12px;
  bottom: calc(10px + env(safe-area-inset-bottom));
  z-index: 25;
  display: none;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  pointer-events: auto;
}
.run-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2px solid #7FA24B;
  background: rgba(7,21,27,0.78);
  color: #d8e8b8;
  font-family: var(--font-num);
  font-size: 7px;
  font-weight: 700;
  letter-spacing: 0.04em;
  cursor: pointer;
}
.run-btn[aria-pressed="true"] { background: #7FA24B; color: #18200d; }
.action-btn {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 3px solid var(--gold);
  background: rgba(7,21,27,0.82);
  color: var(--ivory);
  font-family: var(--font-num);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow: 2px 2px 0 rgba(0,0,0,0.4);
}
.action-btn.ready { border-color: var(--gold); color: #fff0c9; }
.action-btn.is-on { background: var(--gold); color: #2a1d10; }
.action-btn:active { transform: scale(0.95); }
body.touch .touch-actions { display: flex; }
body.dialog-open .skill-dock,
body.dialog-open .touch-actions,
body.codex-open .skill-dock,
body.codex-open .touch-actions,
body.help-open .skill-dock,
body.help-open .touch-actions,
body.event-open .skill-dock,
body.event-open .touch-actions,
body.tithe-open .skill-dock,
body.tithe-open .touch-actions,
body.reward-open .skill-dock,
body.reward-open .touch-actions { display: none !important; }

.skill-book {
  position: absolute;
  inset: 0;
  z-index: 57;
  display: grid;
  place-items: center;
  padding: 14px;
  background: rgba(4,14,19,0.72);
}
.skill-book-card {
  width: min(430px, 94vw);
  max-height: 92vh;
  overflow-y: auto;
  padding: 0 18px 16px;
  background: #f3e6c9;
  color: var(--brown);
  border: 3px solid #7a4a10;
  box-shadow: 5px 5px 0 rgba(0,0,0,0.45);
  clip-path: polygon(10px 0, 100% 0, 100% calc(100% - 10px), calc(100% - 10px) 100%, 0 100%, 0 10px);
}
.skill-book-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 -18px 10px;
  padding: 8px 12px;
  background: #12303a;
  color: var(--ivory);
  font-family: var(--font-num);
  font-size: 8px;
  letter-spacing: 0.1em;
}
.skill-book-note { margin: 0 0 10px; font-size: 10px; line-height: 1.4; color: #6d5842; }
.skill-edit-slots { display: flex; gap: 8px; justify-content: center; margin-bottom: 12px; }
.skill-edit-slot {
  width: 46px; height: 46px; border-radius: 50%;
  border: 3px solid #a58a63; background: #efe0c0;
  font-family: var(--font-num); font-size: 6px; font-weight: 700;
  color: #3b2a20; cursor: pointer; padding: 0;
}
.skill-edit-slot.sel { border-color: #2e6e6b; background: #d8e8c8; }
.skill-book-list { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 12px; }
.skill-choice {
  text-align: left; padding: 7px 8px; background: #efe0c0;
  border: 2px solid #a58a63; color: #3b2a20; cursor: pointer;
}
.skill-choice:hover { border-color: #2e6e6b; }
.skill-choice b { display: block; font-family: var(--font-display); font-size: 14px; color: #2e6e6b; }
.skill-choice span { display: block; font-size: 8px; line-height: 1.35; color: #6d5842; }
body.skill-open .skill-dock, body.skill-open .touch-actions { display: none !important; }

/* ------------------------------------------------------------------ */
/* World event                                                        */
/* ------------------------------------------------------------------ */

.event-bar {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 7px;
  width: fit-content;
  max-width: min(94vw, 720px);
  margin: 4px auto 0;
  padding: 4px 9px 4px 7px;
  background: rgba(7, 21, 27, 0.82);
  border-left: 2px solid var(--flag-yellow);
  border-top: 1px solid rgba(242, 227, 194, 0.18);
  border-right: 1px solid rgba(242, 227, 194, 0.18);
  border-bottom: 1px solid rgba(242, 227, 194, 0.18);
  color: var(--ivory);
  font-family: var(--font-num);
  font-size: 7px;
  letter-spacing: 0.04em;
  cursor: pointer;
  box-shadow: 1px 1px 0 rgba(0, 0, 0, 0.35);
}
.event-bar:hover { border-left-color: var(--ivory); }
.event-kicker { color: var(--flag-yellow); font-weight: 700; letter-spacing: 0.1em; }
.event-name { font-family: var(--font-display); font-size: clamp(10px, 1vw, 12px); color: #f4e6c8; }
.event-clock-label { color: #8fb3ad; font-size: 6px; letter-spacing: 0.08em; }
.event-clock { color: var(--gold); font-weight: 700; }
.event-small { color: #b9cbbf; }
.event-bar .event-small::before { content: "·"; margin-right: 5px; color: #6f8f88; }

.event-overlay {
  position: absolute;
  inset: 0;
  z-index: 52;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(4, 14, 19, 0.7);
}
.event-card {
  position: relative;
  width: min(470px, 92vw);
  max-height: 90vh;
  overflow-y: auto;
  padding: 0 24px 20px;
  background: #f3e6c9;
  color: var(--brown);
  border: 3px solid #7a4a10;
  box-shadow: 5px 5px 0 rgba(0, 0, 0, 0.48);
  clip-path: polygon(10px 0, 100% 0, 100% calc(100% - 10px), calc(100% - 10px) 100%, 0 100%, 0 10px);
}
.event-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 -24px 12px;
  padding: 8px 14px;
  background: #12303a;
  color: var(--ivory);
  font-family: var(--font-num);
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.12em;
}
.event-close {
  width: 26px;
  height: 24px;
  background: transparent;
  border: 1px solid #8fa39a;
  color: var(--ivory);
  font-family: var(--font-num);
  font-size: 10px;
  cursor: pointer;
}
.event-close:hover { border-color: var(--flag-yellow); color: var(--flag-yellow); }
.event-card h2 {
  margin: 2px 0 2px;
  font-family: var(--font-display);
  font-size: clamp(24px, 4vw, 33px);
  line-height: 1;
  color: #2e6e6b;
}
.event-time-line {
  margin: 4px 0 10px;
  font-family: var(--font-num);
  font-size: 9px;
  color: #a86515;
}
.event-story {
  margin: 0 0 14px;
  font-size: 12px;
  line-height: 1.55;
  color: #463420;
}
.event-goal { margin: 0 0 10px; }
.event-goal-label { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.event-goal-label span { font-family: var(--font-num); font-size: 7px; letter-spacing: 0.1em; color: #7a6248; }
.event-goal-label b { font-family: var(--font-num); font-size: 9px; color: #2e6e6b; }
.event-meter {
  height: 8px;
  margin-top: 3px;
  padding: 1px;
  background: #d7c39f;
  border: 1px solid #7f6a4d;
}
.event-meter span { display: block; width: 0%; height: 100%; background: #a86515; transition: width 180ms ease; }
.event-meter.world span { background: var(--flag-blue); }
.event-reward {
  margin: 14px 0 4px;
  padding-top: 10px;
  border-top: 1px solid rgba(59, 42, 32, 0.24);
  font-size: 11px;
  line-height: 1.45;
  color: #2e6e6b;
}
.event-wallet {
  margin: 0 0 4px;
  font-family: var(--font-num);
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #a86515;
}
.event-pack {
  margin: 0 0 8px;
  font-size: 8px;
  line-height: 1.35;
  color: #7a6248;
}
.event-source { margin: 0 0 12px; font-size: 9px; line-height: 1.4; color: #7c654c; }
.event-go {
  display: block;
  width: 100%;
  padding: 8px 12px;
  background: #12303a;
  border: 2px solid #07151b;
  color: var(--ivory);
  font-family: var(--font-num);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.08em;
  cursor: pointer;
}
.event-go:hover { background: #2e6e6b; }
body.event-open .touch-controls,
body.event-open .interact-prompt { display: none !important; }

.hud-icon-btn.wide {
  width: 39px;
  font-size: 6px;
  letter-spacing: 0.04em;
}

.piloncito {
  display: flex;
  align-items: center;
  gap: 3px;
  padding-left: 7px;
  border-left: 1px solid rgba(242, 227, 194, 0.16);
  flex: 0 0 auto;
}
.piloncito img { width: 20px; height: 20px; display: block; }
.piloncito span {
  font-family: var(--font-num);
  font-size: 8px;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: 0.04em;
  white-space: nowrap;
}
.piloncito b { color: #f7e8c8; }

.reward-p {
  margin: 6px 0 0;
  font-family: var(--font-num);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: #b07a1e;
}

.tithe-card { width: min(430px, 94vw); }
.tithe-balance {
  margin: 0 0 10px;
  font-family: var(--font-num);
  font-size: 9px;
  letter-spacing: 0.04em;
  color: #5e4a2f;
}
.tithe-balance b { color: #a86515; }
.tithe-options { display: flex; flex-direction: column; gap: 7px; margin-bottom: 10px; }
.tithe-option {
  display: grid;
  grid-template-columns: 64px 1fr;
  grid-template-rows: auto auto;
  column-gap: 8px;
  text-align: left;
  padding: 8px 10px;
  background: #efe0c0;
  border: 2px solid #a58a63;
  color: #3b2a20;
  cursor: pointer;
}
.tithe-option:hover { border-color: #2e6e6b; background: #f7ecd6; }
.tithe-option:disabled { opacity: 0.4; cursor: not-allowed; }
.tithe-amount {
  grid-row: 1 / 3;
  align-self: center;
  font-family: var(--font-num);
  font-size: 13px;
  font-weight: 700;
  color: #a86515;
}
.tithe-name { font-family: var(--font-display); font-size: 15px; font-weight: 700; color: #2e6e6b; }
.tithe-hint { font-size: 9px; line-height: 1.35; color: #6d5842; }
body.tithe-open .touch-controls,
body.tithe-open .interact-prompt { display: none !important; }

.event-note {
  margin: -8px 0 12px;
  font-size: 9px;
  line-height: 1.45;
  color: #7a6248;
  font-style: italic;
}

.reward-overlay {
  position: absolute;
  inset: 0;
  z-index: 58;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(4, 14, 19, 0.82);
}
.reward-card {
  width: min(360px, 88vw);
  padding: 18px 22px 20px;
  text-align: center;
  background: #f3e6c9;
  border: 3px solid #7a4a10;
  box-shadow: 6px 6px 0 rgba(0, 0, 0, 0.5);
  clip-path: polygon(12px 0, 100% 0, 100% calc(100% - 12px), calc(100% - 12px) 100%, 0 100%, 0 12px);
}
.reward-kicker {
  font-family: var(--font-num);
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.18em;
  color: #a86515;
}
.reward-chest {
  display: block;
  width: clamp(110px, 32vw, 150px);
  height: auto;
  margin: 10px auto 4px;
  image-rendering: pixelated;
}
.reward-card h2 {
  margin: 4px 0 2px;
  font-family: var(--font-display);
  font-size: clamp(22px, 3.3vw, 29px);
  line-height: 1.1;
  color: #2e6e6b;
}
.reward-rarity {
  font-family: var(--font-num);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: #8a8577;
  text-transform: uppercase;
}
.reward-type {
  margin: 10px 0 6px;
  font-size: 10px;
  color: #5e4a2f;
}
.reward-note {
  margin: 0 0 14px;
  font-size: 9.5px;
  line-height: 1.5;
  color: #7a6248;
}
.reward-close {
  width: 100%;
  padding: 9px 12px;
  background: #12303a;
  border: 2px solid #07151b;
  color: var(--ivory);
  font-family: var(--font-num);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.1em;
  cursor: pointer;
}
.reward-close:hover { background: #2e6e6b; }
body.reward-open .touch-controls,
body.reward-open .interact-prompt { display: none !important; }

/* ------------------------------------------------------------------ */
/* Responsive                                                         */
/* ------------------------------------------------------------------ */

@media (max-width: 860px) {
  .area-tag { display: none; }
  .rank { display: none; }
  .hud-strip { min-height: 78px; padding: 16px 8px 10px; gap: 7px; }
  .vitals { max-width: 120px; }
  .vital-num { min-width: 17px; }
  .hud-icon-btn span { display: none; }
  .hud-icon-btn { min-height: 30px; padding: 3px 5px; }
  .codex-page { width: min(470px, calc(88vh * 0.587)); }
}

@media (max-width: 560px) {
  .title-content { padding: max(3vh, 12px) 12px 66px; }
  .title-art-wrap { width: 100vw; margin-left: -12px; margin-right: -12px; }
  .title-gloss { font-size: 9.5px; max-width: 92vw; }
  .title-tag { font-size: 17px; max-width: 88vw; }
  .flag-line { padding: 4px 8px; }
  .flag-line span { font-size: 7.5px; }
  .title-controls { flex-direction: column; gap: 4px; font-size: 9.5px; }
  .title-small { font-size: 8.5px; max-width: 88vw; }
  .title-foot { font-size: 7px; }
  .hud { padding-left: 5px; padding-right: 5px; }
  .hud-strip { min-height: 74px; padding: 14px 6px 10px; gap: 5px; }
  .skill-dock { bottom: calc(8px + env(safe-area-inset-bottom)); gap: 4px; }
  .skill-slot { width: 40px; height: 40px; border-width: 2px; }
  .skill-slot .skill-glyph { font-size: 5.5px; }
  .skill-edit { width: 32px; height: 32px; font-size: 5px; }
  .touch-actions { right: 8px; bottom: calc(8px + env(safe-area-inset-bottom)); }
  .action-btn { width: 58px; height: 58px; font-size: 8px; }
  .run-btn { width: 40px; height: 40px; }
  .skill-bar { gap: 4px; }
  .portrait-wrap { width: 38px; height: 40px; }
  .hero-name { font-size: 11.5px; }
  .who-top { gap: 4px; }
  .who-top .level { display: none; }
  .level-inline { display: inline; }
  .hero-class { font-size: 6.5px; }
  .hero-class em { display: none; }
  .badge-mini img { width: 11px; height: 12px; }
  .vitals { min-width: 54px; max-width: 88px; gap: 3px; }
  .vital-icon { width: 11px; }
  .vital-num { display: none; }
  .bar { height: 6px; }
  .exp-num { font-size: 6px; }
  .hud-icon-btn { min-height: 27px; padding: 2px 4px; }
  .hud-icon-btn img { width: 16px; height: 16px; }
  .hud-icon-btn.square { width: 27px; font-size: 10px; }
  .hud-icon-btn.auto-btn { width: 31px; font-size: 5.5px; }
  .exp-bar { width: 30px; height: 3px; }
  .quest-strip { margin-top: 3px; padding: 3px 7px; font-size: 8px; max-width: calc(100vw - 10px); }
  .quest-kicker { font-size: 6px; }
  .event-bar { margin-top: 3px; padding: 3px 7px; font-size: 6px; max-width: calc(100vw - 10px); gap: 5px; }
  .event-name { font-size: 9px; }
  .event-bar .event-small::before { margin-right: 3px; }
  .hud-icon-btn.wide { width: 34px; font-size: 5.5px; }
  .piloncito { padding-left: 4px; gap: 2px; }
  .piloncito img { width: 15px; height: 15px; }
  .piloncito span { font-size: 7px; }
  .toast { top: calc(max(7px, env(safe-area-inset-top)) + 92px); min-height: 46px; padding: 9px 16px; }
  .dialog {
    width: 96vw;
    height: clamp(158px, 25vh, 196px);
    padding: 38px 18px 16px 24%;
    bottom: calc(8px + env(safe-area-inset-bottom));
  }
  .speaker-icon { left: 10.5%; top: 22%; width: 13%; height: 40%; }
  .speaker-name { font-size: 13px; }
  .speaker-name span { font-size: 8px; }
  .dialog-text { font-size: 11px; line-height: 1.45; max-height: 88px; }
  .dialog-next { right: 10px; bottom: 12px; font-size: 7px; }
  .codex-overlay { justify-content: center; padding: 14px 8px; }
  .codex-page { width: min(94vw, calc(86vh * 0.587)); }
  .codex-close { top: -32px; }
  .codex-word { font-size: clamp(23px, 6.4vw, 31px); }
  .codex-note { font-size: 10.5px; line-height: 1.55; }
  .codex-gloss { font-size: 7px; }
  .codex-legend { font-size: 5.5px; }
  .hud-icon-btn:not(.square) span { display: none; }
}

@media (max-height: 820px) and (min-width: 600px) and (orientation: landscape) {
  .title-content { padding-top: 8px; padding-bottom: 14px; }
  .title-art-wrap { width: min(800px, 82vw); }
  .title-actions { margin-top: 10px; }
  .title-controls { margin-top: 7px; }
  .title-small { display: none; }
  .title-foot { position: static; margin-top: 8px; }
}

@media (max-height: 540px) and (orientation: landscape) {
  .title-content { padding-top: 2px; padding-bottom: 6px; }
  .title-art-wrap { width: min(470px, 52vw); }
  .title-gloss { display: none; }
  .title-tag { font-size: 13px; margin-top: 2px; }
  .title-actions { margin-top: 5px; }
  .pixel-button { width: min(210px, 48vw); }
  .title-controls { display: none; }
  .title-small { display: none; }
  .title-foot { display: none; }
  .flag-line { margin-top: 0; padding: 2px 6px; }
  .flag { width: 24px; height: 16px; }
  .flag-line span { font-size: 6px; }
  .sound-toggle { padding: 5px 7px; font-size: 7px; }
  .dialog { height: clamp(144px, 34vh, 184px); }
  .codex-page { width: min(400px, calc(92vh * 0.587)); }
  .event-card { padding-left: 16px; padding-right: 16px; padding-bottom: 10px; max-height: calc(100vh - 18px); }
  .event-panel-head { margin-left: -16px; margin-right: -16px; } 
  .event-card h2 { font-size: 22px; }
  .event-story { font-size: 10px; line-height: 1.4; margin-bottom: 7px; }
  .event-note { display: none; }
  .event-goal { margin-bottom: 5px; }
  .event-reward { margin-top: 6px; padding-top: 6px; font-size: 9.5px; }
  .event-source { display: none; }
  .event-wallet { margin-bottom: 4px; }
  .event-pack { display: none; }
  .event-go { padding: 6px 10px; }
}

@media (pointer: coarse) {
  body:not(.no-touch-extra) .touch-controls { /* enabled by JS class too */ }
}

.touch-only { display: none; }
body.touch .touch-only { display: flex; }
body.touch .desktop-only { display: none !important; }


.touch-only { display: none; }
body.touch .touch-only { display: flex; }
body.touch .desktop-only { display: none !important; }
body.touch .interact-prompt { display: none !important; }
body.codex-open .touch-controls,
body.help-open .touch-controls,
body.codex-open .interact-prompt,
body.help-open .interact-prompt { display: none !important; }
.action-btn:disabled { opacity: 0.48; cursor: default; }
.action-btn:disabled.ready { opacity: 0.48; }

@media (prefers-reduced-motion: reduce) {
  .title-art-wrap, .title-bg { animation: none; }
  .dialog { transition: none; }
  .dialog-cursor { animation: none; }
}

/* ------------------------------------------------------------------ */
/* The rest of the design: jobs, travel, pack, quests, boss          */
/* ------------------------------------------------------------------ */

.boss-bar {
  position: absolute;
  top: max(112px, 15vh);
  left: 50%;
  transform: translateX(-50%);
  z-index: 32;
  width: min(520px, 82vw);
  padding: 5px 10px 7px;
  background: rgba(7, 21, 27, 0.9);
  border: 2px solid #C4553B;
  box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.45);
  pointer-events: none;
}
.boss-bar > span {
  display: block;
  margin-bottom: 4px;
  color: #F2E3C2;
  font-family: var(--font-num);
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-align: center;
  text-shadow: 1px 1px 0 #07151b;
}
.boss-meter {
  height: 10px;
  padding: 1px;
  background: #1a0c06;
  border: 1px solid #7a4a10;
}
.boss-meter span {
  display: block;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, #C4553B, #FCD116);
  transition: width 160ms ease;
}

.adventure-card { width: min(560px, 94vw); }
.sheet-tabs {
  display: flex;
  gap: 4px;
  margin: 0 0 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid rgba(59, 42, 32, 0.24);
}
.sheet-tab {
  flex: 1;
  padding: 6px 4px;
  background: #e4d3b2;
  border: 2px solid #a58a63;
  color: #6b4a2a;
  font-family: var(--font-num);
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.08em;
  cursor: pointer;
}
.sheet-tab.on { background: #12303a; border-color: #07151b; color: #F2E3C2; }
.sheet-tab:hover { border-color: #2e6e6b; }

.job-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.job-name { margin: 0; font-family: var(--font-display); font-size: clamp(24px, 4vw, 32px); line-height: 1; color: #2e6e6b; }
.job-gloss { margin: 2px 0 0; font-family: var(--font-num); font-size: 9px; color: #a86515; }
.job-role { margin: 8px 0 0; font-family: var(--font-num); font-size: 8px; letter-spacing: 0.06em; color: #6d5842; text-transform: uppercase; }
.job-passive { margin: 10px 0 0; padding: 8px 10px; background: #efe0c0; border-left: 3px solid #2e6e6b; font-size: 11px; line-height: 1.5; color: #463420; }
.job-progress { margin: 10px 0 0; font-family: var(--font-num); font-size: 8px; color: #7a6248; }
.job-bar { height: 8px; margin: 4px 0 10px; padding: 1px; background: #d7c39f; border: 1px solid #7f6a4d; }
.job-bar span { display: block; width: 0%; height: 100%; background: #2e6e6b; transition: width 180ms ease; }
.job-section-title { margin: 12px 0 5px; font-family: var(--font-num); font-size: 8px; font-weight: 700; letter-spacing: 0.1em; color: #12303a; }
.job-skill-list { display: flex; flex-wrap: wrap; gap: 4px; margin: 0 0 8px; }
.job-pill { padding: 3px 6px; background: #efe0c0; border: 1px solid #a58a63; font-family: var(--font-num); font-size: 7px; color: #5a422c; }
.job-choices { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 6px 0 10px; }
.job-choice {
  text-align: left;
  padding: 7px 8px;
  background: #efe0c0;
  border: 2px solid #a58a63;
  color: #3b2a20;
  cursor: pointer;
}
.job-choice:hover { border-color: #2e6e6b; }
.job-choice b { display: block; font-family: var(--font-display); font-size: 15px; color: #2e6e6b; }
.job-choice span { display: block; margin-top: 2px; font-size: 8px; line-height: 1.35; color: #6d5842; }
.job-choice .job-accent { color: #a86515; font-family: var(--font-num); font-size: 7px; }
.job-note { margin: 6px 0 0; font-size: 9px; line-height: 1.4; color: #7a6248; }
.job-advanced { border-color: #B07A1E; background: #f6e7c4; }

.pack-list, .market-list { display: grid; gap: 6px; margin: 6px 0 10px; }
.pack-item, .market-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  background: #efe0c0;
  border: 2px solid #a58a63;
}
.pack-item.equipped { border-color: #2e6e6b; background: #dfead0; }
.pack-copy { flex: 1; min-width: 0; }
.pack-copy b { display: block; font-family: var(--font-display); font-size: 14px; color: #3b2a20; line-height: 1.1; }
.pack-copy span { display: block; font-size: 8px; line-height: 1.3; color: #6d5842; }
.pack-actions { display: flex; gap: 4px; flex-shrink: 0; }
.pack-actions button, .market-item button {
  padding: 4px 7px;
  background: #12303a;
  border: 1px solid #07151b;
  color: #F2E3C2;
  font-family: var(--font-num);
  font-size: 7px;
  font-weight: 700;
  cursor: pointer;
}
.pack-actions button:hover, .market-item button:hover { background: #2e6e6b; }
.pack-actions button:disabled { opacity: 0.45; cursor: default; }
.pack-empty, .quest-empty { margin: 8px 0 12px; font-size: 10px; color: #7a6248; }
.rarity-Common { color: #8a8577; }
.rarity-Uncommon { color: #5f7f32; }
.rarity-Rare { color: #2E6E6B; }
.rarity-Epic { color: #7a4fa3; }
.rarity-SR { color: #a86515; }
.rarity-SSR { color: #C4553B; }
.rarity-UR { color: #CE1126; }

.quest-list { display: grid; gap: 6px; margin: 6px 0 10px; }
.quest-row { display: flex; gap: 8px; padding: 7px 8px; background: #efe0c0; border: 2px solid #a58a63; }
.quest-row.done { border-color: #7FA24B; background: #e2ecd4; }
.quest-row.daily { border-color: #E8A24B; background: #f6e7c4; }
.quest-mark { width: 16px; height: 16px; flex-shrink: 0; display: grid; place-items: center; background: #12303a; color: #F2E3C2; font-family: var(--font-num); font-size: 8px; border: 1px solid #07151b; }
.quest-row.done .quest-mark { background: #7FA24B; }
.quest-copy b { display: block; font-family: var(--font-display); font-size: 14px; color: #2e6e6b; }
.quest-copy span { display: block; font-size: 8px; line-height: 1.35; color: #6d5842; }

.travel-list { display: grid; gap: 7px; margin: 8px 0 12px; }
.travel-dest {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 8px 9px;
  text-align: left;
  background: #efe0c0;
  border: 2px solid #a58a63;
  color: #3b2a20;
  cursor: pointer;
}
.travel-dest:hover { border-color: #2e6e6b; }
.travel-dest.here { border-color: #2e6e6b; background: #dfead0; }
.travel-dest.locked { opacity: 0.62; cursor: default; }
.travel-copy { flex: 1; min-width: 0; }
.travel-copy b { display: block; font-family: var(--font-display); font-size: 16px; color: #2e6e6b; }
.travel-copy span { display: block; font-size: 8px; line-height: 1.35; color: #6d5842; }
.travel-tag { flex-shrink: 0; font-family: var(--font-num); font-size: 7px; font-weight: 700; letter-spacing: 0.06em; color: #a86515; }

@media (max-width: 560px) {
  .job-choices { grid-template-columns: 1fr; }
  .pack-item, .market-item { align-items: flex-start; }
  .pack-actions { flex-direction: column; }
  .boss-bar { top: max(104px, 14vh); }
  .sheet-tab { font-size: 7px; }
}
body.adventure-open .skill-dock,
body.adventure-open .touch-actions,
body.travel-open .skill-dock,
body.travel-open .touch-actions,
body.market-open .skill-dock,
body.market-open .touch-actions { display: none !important; }

/* The adventurer panel keeps its primary action on screen at every height. */
.adventure-card {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  max-height: 92vh;
}
#adventure-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding-right: 2px;
}
.adventure-foot {
  flex: 0 0 auto;
  display: flex;
  gap: 6px;
  padding-top: 8px;
  border-top: 1px solid rgba(59, 42, 32, 0.2);
}
.adventure-foot .event-go { flex: 1 1 auto; margin: 0; }
.adventure-foot:empty { display: none; }
@media (max-width: 560px) {
  .adventure-foot { flex-direction: column; }
}
.adventure-card { max-height: calc(100vh - 32px); }
.job-choice.locked { opacity: 0.62; cursor: default; }
.job-choice[disabled], .event-go[disabled] { cursor: default; opacity: 0.5; }
@media (max-height: 560px) {
  .adventure-card .event-panel-head { margin-bottom: 7px; padding: 6px 12px; }
  .adventure-card .sheet-tabs { margin-bottom: 6px; padding-bottom: 4px; }
  .adventure-card .job-name { font-size: 24px; }
  .job-head .job-passive { margin-top: 5px; }
  .job-role { margin: 4px 0 0; }
  .job-passive { margin: 5px 0 0; padding: 5px 8px; font-size: 10px; line-height: 1.35; }
  .job-status, .job-passive + .job-role { margin-top: 3px; }
  .job-state { margin: 4px 0 0; }
  .job-row { margin: 4px 0; }
  .job-meta { gap: 4px; }
  .job-actions { margin-top: 6px; }
  .job-list { gap: 4px; }
  .job-note { margin: 3px 0 0; }
  .job-desc { font-size: 9px; }
  .job-card { padding: 5px 7px; }
  .adventure-tabs { margin-bottom: 5px; }
  .adv-hint { margin: 4px 0; }
}


@media (max-height: 560px) {
  .job-progress { margin: 5px 0 0; font-size: 7px; }
  .job-bar { margin: 2px 0 5px; }
  .job-section-title { margin: 6px 0 3px; }
  .job-skill-list { gap: 3px; margin: 0 0 4px; }
  .job-pill { padding: 2px 5px; font-size: 6.5px; }
  .adventure-foot { padding-top: 6px; }
}

@media (max-height: 560px) {
  .adventure-card .event-panel-head { margin-bottom: 6px; padding: 5px 12px; }
  .adventure-card .sheet-tabs { margin-bottom: 5px; padding-bottom: 3px; }
  .adventure-card .job-name { font-size: 22px; }
  .job-role { margin: 3px 0 0; font-size: 7px; }
  .job-passive { margin: 4px 0 0; padding: 4px 7px; font-size: 9px; line-height: 1.25; }
  .job-progress { margin: 3px 0 0; font-size: 6.5px; }
  .job-bar { height: 6px; margin: 2px 0 4px; }
  .job-section-title { margin: 5px 0 2px; font-size: 7px; }
  .job-skill-list { gap: 2px; margin: 0 0 3px; }
  .job-pill { padding: 2px 4px; font-size: 6px; }
  .job-note { margin: 2px 0 0; font-size: 8.5px; line-height: 1.3; }
  .adventure-foot { padding-top: 5px; }
}

@media (max-height: 560px) {
  #adventure.event-overlay { padding: 6px 10px; }
  #adventure .event-card { max-height: calc(100vh - 12px); }
}

.job-summary, .job-detail { min-width: 0; }
@media (min-width: 700px) and (max-height: 560px) {
  #adventure-body {
    display: grid;
    grid-template-columns: minmax(0, 0.92fr) minmax(0, 1.08fr);
    gap: 14px;
    align-items: start;
  }
  .job-detail {
    padding-left: 12px;
    border-left: 1px solid rgba(59, 42, 32, 0.22);
    max-height: 100%;
    overflow-y: auto;
  }
  .job-detail .job-choices { grid-template-columns: 1fr; }
  .job-detail .job-section-title:first-child { margin-top: 0; }
}
