/* Fantasy Adventure — page-specific styles. Background comes from styles.css. */

:root {
  --fa-ink: #f4e6c8;
  --fa-muted: #c9b48a;
  --fa-deep: #1a120c;
  --fa-panel: rgba(22, 14, 10, 0.72);
  --fa-gold: #d4a017;
  --fa-gold-2: #8a5a12;
  --fa-hp: #b42318;
  --fa-hp-low: #7f1d1d;
}

html {
  height: 100%;
}

body {
  background: #000 !important;
  margin: 0;
  padding: 0;
  min-height: 100vh;
  min-height: 100dvh;
  height: 100dvh;
  font-family: Georgia, "Times New Roman", serif;
  text-align: center;
  overflow: hidden;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
}

/* .bg-video-layer is the second playlist layer added by scripts/videos.js. */
#background-video,
.bg-video-layer {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 0;
  background-color: #000;
}

.page-scrim {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background:
    radial-gradient(circle at 50% 0%, rgba(244, 230, 200, 0.14), transparent 45%),
    linear-gradient(180deg, rgba(10, 6, 4, 0.3), rgba(10, 6, 4, 0.72));
}

#gameContainer {
  position: relative;
  z-index: 2;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  width: min(100%, 1400px);
  margin: 0 auto;
  height: 100%;
  max-height: 100dvh;
  min-height: 0;
  overflow: hidden;
  padding: clamp(0.4rem, 1.5vw, 1.25rem);
  background-color: var(--fa-panel);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  color: var(--fa-ink);
}

.game-header {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}

#gameContainer h1 {
  margin: 0.15rem 0 0.35rem;
  font-size: clamp(1.15rem, 3.5vw, 2.1rem);
  color: var(--fa-ink);
  text-shadow: 0 1px 2px #000;
  line-height: 1.2;
}

.fa-map-link {
  padding: 0;
  border: 0;
  background: none;
  color: var(--fa-ink);
  font-family: inherit;
  font-size: 0.7rem;
  text-decoration: underline;
  cursor: pointer;
  white-space: nowrap;
  text-underline-offset: 0.15em;
}

.fa-map-link:focus-visible {
  outline: 2px solid var(--fa-gold);
  outline-offset: 3px;
}

.fa-map-dialog {
  box-sizing: border-box;
  width: min(1200px, 96vw);
  max-width: 96vw;
  max-height: 94dvh;
  padding: 0;
  border: 1px solid #d4a017;
  border-radius: 12px;
  background: #20180f;
  color: #f4e6c8;
}

.fa-map-dialog[open] { display: flex; flex-direction: column; }
.fa-map-dialog::backdrop { background: rgba(0, 0, 0, 0.78); }
.fa-map-head { display: flex; align-items: center; gap: 0.5rem; padding: 0.6rem; }
.fa-map-head h2 { flex: 1; margin: 0; font-size: clamp(0.85rem, 3vw, 1.1rem); }
.fa-map-head button {
  flex-shrink: 0;
  padding: 0.4rem 0.6rem;
  border: 1px solid #d4a017;
  border-radius: 6px;
  background: #f4e6c8;
  color: #3b2a10;
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
}
.fa-map-view { min-height: 0; overflow: auto; overscroll-behavior: contain; }
.fa-map-view img { display: block; width: 100%; height: auto; }
.fa-map-view.is-zoomed img { width: 1536px; max-width: none; }
.fa-map-dialog :focus-visible { outline: 2px solid #d4a017; outline-offset: -2px; }

.game-intro {
  flex: 0 0 auto;
  width: 100%;
  max-width: 720px;
  margin: 0 auto 0.4rem;
  font-size: 0.85rem;
  color: var(--fa-ink);
}

.game-intro summary {
  list-style: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.75rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: #3b2a10;
  background: rgba(244, 230, 200, 0.9);
  border: 1px solid var(--fa-gold);
  border-radius: 999px;
}

.game-intro summary::-webkit-details-marker { display: none; }

.game-intro[open] summary .intro-arrow { transform: rotate(180deg); }

.game-intro .intro-arrow {
  display: inline-block;
  transition: transform 0.2s ease;
}

.game-intro .intro-content {
  margin-top: 0.4rem;
  padding: 0.5rem 0.75rem;
  border-radius: 12px;
  background: rgba(244, 230, 200, 0.92);
  border: 1px solid rgba(212, 160, 23, 0.45);
  font-size: 0.85rem;
  line-height: 1.4;
  color: #3b2a10;
  text-align: left;
  max-height: 140px;
  overflow-y: auto;
}

#faHud {
  flex: 0 0 auto;
  margin: 0.25rem 0 0.55rem;
  padding: 0.6rem 0.8rem;
  border-radius: 12px;
  background: linear-gradient(145deg, rgba(24, 15, 8, 0.82) 0%, rgba(14, 9, 5, 0.92) 100%);
  border: 1px solid rgba(212, 160, 23, 0.35);
  box-shadow: inset 0 1px 0 rgba(255, 235, 180, 0.08), 0 4px 16px rgba(0, 0, 0, 0.4);
  text-align: left;
  font-size: 0.82rem;
}

.fa-hud-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  width: 100%;
  margin-bottom: 0.45rem;
  overflow-x: auto;
  scrollbar-width: none;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.fa-hud-summary::-webkit-scrollbar { display: none; }

.fa-summary-item {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  white-space: nowrap;
  min-width: 0;
}

.fa-summary-label {
  font-size: 0.68rem;
  color: var(--fa-muted);
  text-transform: uppercase;
  font-weight: 600;
}

.fa-summary-val {
  font-weight: 700;
  color: var(--fa-ink);
  font-size: 0.8rem;
}

.fa-summary-hp { flex: 0 0 auto; }

.fa-summary-companion,
.fa-summary-location {
  flex: 0 0 auto;
}

.fa-summary-companion .fa-summary-val,
.fa-summary-location .fa-summary-val {
  white-space: nowrap;
  display: block;
  font-size: 0.76rem;
  font-weight: 500;
}

.fa-companion-summary-hp-bar {
  flex: 0 0 42px;
  width: 42px;
  height: 6px;
  margin-top: 0;
}

.fa-summary-companion-short {
  display: none;
}

.fa-summary-toggle {
  display: flex;
  align-items: center;
  gap: 0.2rem;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  background: rgba(212, 160, 23, 0.25);
  border: 1px solid rgba(212, 160, 23, 0.4);
  color: var(--fa-ink);
  font-size: 0.7rem;
  flex: 0 0 auto;
}

.fa-toggle-arrow {
  transition: transform 0.2s ease;
  font-size: 0.65rem;
  display: inline-block;
}

.fa-hud-summary.is-expanded .fa-toggle-arrow {
  transform: rotate(180deg);
}

.fa-hud-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 0.45rem 0.65rem;
}

.fa-hud-grid.is-collapsed {
  display: none;
}

.fa-hud-grid .fa-stat {
  min-width: 0;
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid rgba(212, 160, 23, 0.18);
  border-radius: 7px;
  padding: 0.35rem 0.5rem;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03), 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: border-color 0.15s ease, background 0.15s ease;
}

.fa-hud-grid .fa-stat:hover {
  border-color: rgba(212, 160, 23, 0.4);
  background: rgba(255, 255, 255, 0.06);
}

.fa-hud-grid .fa-label {
  display: block;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #d4a017;
  margin-bottom: 0.12rem;
}

.fa-hud-grid .fa-value {
  display: block;
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
  overflow-wrap: anywhere;
  color: #fff8e7;
  font-weight: 600;
  font-size: 0.85rem;
  line-height: 1.2;
}

.fa-hud-grid .fa-stat:not(.fa-stat-wide):not(.fa-stat-full) { grid-column: span 3; }
.fa-hud-grid .fa-stat-wide { grid-column: span 2; }
.fa-hud-grid .fa-stat-full { grid-column: 1 / -1; }

.fa-stat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  margin-bottom: 0.12rem;
}

.fa-stat-head .fa-label {
  margin-bottom: 0;
}

.fa-comp-badge {
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  border: 1px solid transparent;
  line-height: 1.2;
}

.fa-comp-badge.is-novice {
  background: rgba(245, 158, 11, 0.2);
  border-color: rgba(245, 158, 11, 0.5);
  color: #fbbf24;
}

.fa-comp-badge.is-proficient {
  background: rgba(59, 130, 246, 0.2);
  border-color: rgba(59, 130, 246, 0.5);
  color: #93c5fd;
}

.fa-comp-badge.is-master {
  background: rgba(16, 185, 129, 0.2);
  border-color: rgba(16, 185, 129, 0.5);
  color: #6ee7b7;
}

.fa-comp-badge.is-fallen {
  background: rgba(239, 68, 68, 0.2);
  border-color: rgba(239, 68, 68, 0.5);
  color: #fca5a5;
}

.fa-companion-details {
  margin-top: 0.22rem;
  font-size: 0.76rem;
  color: #f6e0b5;
  white-space: normal;
  overflow: visible;
  overflow-wrap: anywhere;
}

#faCompanionStat.has-companion {
  background: rgba(16, 32, 28, 0.45);
  border-color: rgba(94, 234, 212, 0.35);
}

.fa-hp-bar {
  margin-top: 0.2rem;
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  overflow: hidden;
}

.fa-hp-bar-sm {
  flex: 0 0 48px;
  width: 48px;
  height: 6px;
  margin: 0 0 0 0.2rem;
  display: inline-block;
  vertical-align: middle;
}

.fa-hp-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #da3a2a, #f0c14b);
}

.fa-hp-fill.is-low { background: var(--fa-hp-low); }

#faPlay {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  text-align: left;
  border-radius: 16px;
  background: rgba(28, 18, 12, 0.82);
  border: 1px solid rgba(212, 160, 23, 0.28);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.fa-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 0.9rem;
  color: #fff8e7;
  background: linear-gradient(135deg, #5c3b12 0%, #8a5a12 55%, #d4a017 100%);
}

.fa-header .fa-mark {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #1a120c;
  border: 2px solid rgba(255, 255, 255, 0.85);
  font-size: 1.2rem;
}

.fa-header .fa-name { font-weight: 700; font-size: 1.05rem; }
.fa-header .fa-name-wrap { display: flex; flex-direction: column; min-width: 0; }
.fa-player-name-input {
  font-family: inherit;
  font-size: 1.05rem;
  font-weight: 700;
  color: #fff;
  background: rgba(0, 0, 0, 0.25);
  border: 1px dashed rgba(255, 255, 255, 0.45);
  border-radius: 6px;
  padding: 0.15rem 0.45rem;
  width: 120px;
  max-width: 26vw;
  box-sizing: border-box;
  outline: none;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}
.fa-player-name-input:hover {
  border-color: rgba(255, 255, 255, 0.8);
  background: rgba(0, 0, 0, 0.35);
}
.fa-player-name-input:focus {
  border: 1px solid var(--fa-gold, #d4a017);
  background: rgba(0, 0, 0, 0.6);
  box-shadow: 0 0 6px rgba(212, 160, 23, 0.6);
}
.fa-player-name-input::placeholder {
  color: rgba(255, 255, 255, 0.65);
  font-style: italic;
  font-weight: normal;
}
.fa-summary-player-item {
  cursor: pointer;
}
.fa-summary-player-item .fa-summary-val {
  color: var(--fa-gold, #f4e6c8);
  max-width: 65px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.fa-header .fa-tag { font-size: 0.8rem; opacity: 0.9; }

.fa-mute {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.3rem 0.7rem;
  font: inherit;
  font-size: 0.78rem;
  color: #fff;
  cursor: pointer;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.6);
  background: rgba(255, 255, 255, 0.16);
  transition: background 0.15s, border-color 0.15s;
}

.fa-mute:hover { background: rgba(255, 255, 255, 0.3); }

.fa-mute.is-muted {
  background: rgba(180, 35, 24, 0.5);
  border-color: rgba(255, 120, 120, 0.7);
  color: #ffe0e0;
}

.fa-tts-controls {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.fa-tts-controls[hidden],
.fa-tts-toggle[hidden],
.fa-tts-voice-block[hidden] { display: none; }

.fa-tts-voice-block {
  padding-top: 0.7rem;
  border-top: 1px solid rgba(212, 160, 23, 0.45);
}

.fa-tts-toggle,
.fa-tts-settings {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  padding: 0.3rem 0.62rem;
  min-height: 30px;
  font: inherit;
  font-size: 0.78rem;
  color: #fff;
  cursor: pointer;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.6);
  background: rgba(255, 255, 255, 0.16);
  transition: background 0.15s, border-color 0.15s;
}

.fa-tts-toggle:hover,
.fa-tts-settings:hover { background: rgba(255, 255, 255, 0.3); }

.fa-tts-toggle.is-on {
  background: rgba(42, 118, 70, 0.62);
  border-color: rgba(170, 240, 190, 0.8);
  color: #ecfff1;
}

.fa-tts-toggle.is-muted {
  background: rgba(180, 35, 24, 0.36);
  border-color: rgba(255, 165, 145, 0.7);
  color: #ffe0e0;
}

#faTtsIcon {
  position: relative;
  width: 0.92rem;
  height: 0.7rem;
  border: 1px solid currentColor;
  border-radius: 0.28rem;
}

#faTtsIcon::after {
  content: "";
  position: absolute;
  left: 0.12rem;
  bottom: -0.22rem;
  width: 0.26rem;
  height: 0.26rem;
  border-left: 1px solid currentColor;
  border-bottom: 1px solid currentColor;
  background: inherit;
  transform: skewY(-35deg);
}

.fa-tts-settings {
  width: 32px;
  padding-inline: 0.35rem;
  font-size: 0.66rem;
}

.fa-tts-settings::before {
  content: "\2699";
  font-size: 0.82rem;
  line-height: 1;
}

.fa-tts-panel[hidden] { display: none !important; }

/* New game confirmation (reuses the sound panel overlay) */
.fa-confirm-panel { z-index: 90; }
.fa-confirm-dialog p { margin: 0.55rem 0 0.9rem; font-size: 0.88rem; line-height: 1.4; }
.fa-confirm-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 0.5rem; }
.fa-confirm-actions button {
  min-height: 40px;
  padding: 0.45rem 0.95rem;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  border-radius: 999px;
  cursor: pointer;
}
.fa-confirm-cancel { color: #3b2a10; background: #f7ecd4; border: 1px solid #d4a017; }
.fa-confirm-ok { color: #fff; background: #9b2c1f; border: 1px solid #7a1f15; }
.fa-confirm-actions button:focus-visible { outline: 2px solid #d4a017; outline-offset: 2px; }
@media (max-width: 420px) { .fa-confirm-actions button { flex: 1 1 100%; } }

.fa-tts-panel {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 1rem;
  box-sizing: border-box;
}

.fa-tts-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.42);
}

.fa-tts-dialog {
  position: relative;
  z-index: 1;
  box-sizing: border-box;
  width: min(360px, calc(100vw - 2rem));
  max-width: 100%;
  padding: 0.85rem;
  color: #2a1c10;
  background: #fff8e7;
  border: 1px solid #d4a017;
  border-radius: 10px;
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.45);
}

.fa-tts-dialog-head {
  position: sticky;
  top: 0;
  z-index: 2;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 0.5rem;
  margin: -0.15rem 0 0.65rem;
  padding: 0.15rem 0 0.45rem;
  background: #fff8e7;
}

.fa-tts-dialog {
  text-align: left;
}

.fa-tts-dialog-head h2 {
  flex: 1 1 auto;
  min-width: 0;
  text-align: left;
}

#faTtsClose,
#faVolDefault {
  flex-shrink: 0;
}

.fa-tts-dialog h2 {
  margin: 0;
  font-size: 1rem;
  line-height: 1.2;
}

#faTtsClose {
  width: 32px;
  height: 32px;
  color: #3b2a10;
  background: #f7ecd4;
  border: 1px solid #d4a017;
  border-radius: 999px;
  cursor: pointer;
}

.fa-tts-dialog label {
  display: block;
  margin-bottom: 0.25rem;
  font-size: 0.78rem;
  font-weight: 700;
}

.fa-tts-select-wrap {
  position: relative;
}

.fa-tts-select-wrap::after {
  content: "\25be";
  position: absolute;
  top: 50%;
  right: 0.7rem;
  color: #5c3b12;
  pointer-events: none;
  transform: translateY(-50%);
}

#faTtsVoice {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  min-height: 38px;
  padding: 0.45rem 2rem 0.45rem 0.55rem;
  color: #2a1c10;
  background: #fffdf6;
  border: 1px solid #d4a017;
  border-radius: 7px;
}

.fa-tts-preview-row {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin-top: 0.7rem;
}

#faTtsPreview {
  flex: 0 0 auto;
  padding: 0.45rem 0.8rem;
  font: inherit;
  font-weight: 700;
  color: #fff8e7;
  cursor: pointer;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(135deg, #8a5a12 0%, #d4a017 100%);
}

#faTtsPreview:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

#faTtsStatus {
  min-width: 0;
  font-size: 0.78rem;
  color: #5c3b12;
}

.fa-tts-queue-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.6rem;
}

.fa-tts-queue-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: #3b240e;
  cursor: pointer;
  user-select: none;
}

.fa-tts-queue-label input[type="checkbox"] {
  accent-color: #d4a017;
  cursor: pointer;
  width: 1rem;
  height: 1rem;
}

.fa-vol-list {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  margin-bottom: 0.85rem;
}

.fa-tts-dialog .fa-vol-row {
  display: flex;
  flex-direction: column;
  gap: 0.18rem;
  margin: 0;
  min-width: 0;
  font-size: 0.78rem;
  font-weight: 700;
}

.fa-vol-meta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
}

.fa-vol-pct {
  font-weight: 600;
  color: #5c3b12;
  font-variant-numeric: tabular-nums;
}

.fa-vol-row input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  height: 22px;
  margin: 0;
  background: transparent;
  cursor: pointer;
}

.fa-vol-row input[type="range"]:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.fa-vol-row input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 999px;
  background: #e6d3a8;
  border: 1px solid #d4a017;
}

.fa-vol-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  margin-top: -6px;
  border-radius: 50%;
  border: 1px solid #8a5a12;
  background: linear-gradient(135deg, #fff8e7 0%, #d4a017 100%);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}

.fa-vol-row input[type="range"]::-moz-range-track {
  height: 6px;
  border-radius: 999px;
  background: #e6d3a8;
  border: 1px solid #d4a017;
}

.fa-vol-row input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1px solid #8a5a12;
  background: linear-gradient(135deg, #fff8e7 0%, #d4a017 100%);
}

#faVolStatus {
  min-height: 1.1em;
  margin: 0 0 0.35rem;
  font-size: 0.78rem;
  color: #5c3b12;
}

#faVolStatus:empty {
  display: none;
}

#faVolDefault {
  flex: 0 0 auto;
  padding: 0.28rem 0.7rem;
  font: inherit;
  font-size: 0.74rem;
  font-weight: 700;
  color: #3b2a10;
  cursor: pointer;
  background: #f7ecd4;
  border: 1px solid #d4a017;
  border-radius: 999px;
}

#faVolDefault:hover {
  background: #fff3d4;
}

.fa-reset {
  margin-left: 0.35rem;
  padding: 0.3rem 0.7rem;
  font: inherit;
  font-size: 0.78rem;
  color: #fff;
  cursor: pointer;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.6);
  background: rgba(255, 255, 255, 0.16);
}

.fa-reset:hover { background: rgba(255, 255, 255, 0.3); }

.fa-messages-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#faMessages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 0.9rem;
  background: rgba(42, 28, 16, 0.45);
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  touch-action: pan-y;
}

#faScrollBottom,
.fa-scroll-bottom {
  position: absolute;
  bottom: 12px;
  right: 16px;
  width: 36px !important;
  height: 36px !important;
  min-width: 36px !important;
  max-width: 36px !important;
  border-radius: 50% !important;
  background: linear-gradient(135deg, #8a5a12 0%, #d4a017 100%) !important;
  color: #fff8e7 !important;
  border: 1px solid rgba(255, 235, 180, 0.75) !important;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.4), 0 0 10px rgba(212, 160, 23, 0.3) !important;
  cursor: pointer;
  display: flex !important;
  align-items: center;
  justify-content: center;
  font-size: 18px !important;
  font-weight: bold;
  line-height: 1 !important;
  z-index: 20;
  opacity: 0;
  pointer-events: none;
  transform: translateY(6px);
  transition: opacity 0.2s ease, transform 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
  padding: 0 !important;
  margin: 0 !important;
}

#faScrollBottom.visible,
#faScrollBottom.is-visible,
.fa-scroll-bottom.visible,
.fa-scroll-bottom.is-visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

#faScrollBottom:hover,
.fa-scroll-bottom:hover {
  background: linear-gradient(135deg, #a16b17 0%, #e5b026 100%) !important;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5), 0 0 14px rgba(229, 176, 38, 0.5) !important;
  transform: translateY(-2px);
}

.fa-row {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  margin-bottom: 0.7rem;
}

.fa-row.user { flex-direction: row-reverse; }

.fa-row.system {
  justify-content: center;
}

.fa-avatar {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid #d4a017;
  background: #fff;
}

.fa-avatar-dm {
  display: grid;
  place-items: center;
  font-size: 1rem;
  background: #1a120c;
  color: #f4e6c8;
}

.fa-bubble {
  max-width: min(78%, 60ch);
  padding: 0.55rem 0.8rem;
  border-radius: 14px;
  line-height: 1.45;
  font-size: 0.98rem;
  overflow-wrap: anywhere;
  color: #2a1c10;
  background: #f7ecd4;
  border: 1px solid #d4a017;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.fa-bubble:not(.fa-savebox):hover {
  filter: brightness(1.03);
}

.fa-bubble.is-speaking {
  border-color: #f59e0b !important;
  box-shadow: 0 0 12px rgba(245, 158, 11, 0.6), inset 0 0 8px rgba(245, 158, 11, 0.15) !important;
  animation: fa-speaking-pulse 1.6s ease-in-out infinite alternate;
}

@keyframes fa-speaking-pulse {
  0% { transform: scale(1); box-shadow: 0 0 6px rgba(245, 158, 11, 0.4); }
  100% { transform: scale(1.01); box-shadow: 0 0 14px rgba(245, 158, 11, 0.75); }
}

.fa-row.user .fa-bubble {
  color: #fff8e7;
  border-color: transparent;
  background: linear-gradient(135deg, #8a5a12 0%, #d4a017 100%);
}

.fa-row.system .fa-bubble {
  max-width: 90%;
  font-size: 0.9rem;
  color: #f4e6c8;
  background: rgba(0, 0, 0, 0.35);
  border-style: dashed;
}

#faCombat {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: center;
  padding: 0.55rem 0.9rem;
  background: rgba(90, 18, 18, 0.55);
  border-top: 1px solid rgba(212, 160, 23, 0.3);
}

#faCombat[hidden] { display: none !important; }

#faMonster {
  flex: 1 1 100%;
  display: flex;
  align-items: center;
  gap: 0.65rem;
  font-size: 0.9rem;
  color: #f4e6c8;
}

#faMonsterInfo {
  min-width: 0;
  overflow-wrap: anywhere;
}

.fa-monster-hp-bar {
  flex: 0 1 180px;
  width: min(180px, 35%);
  margin-top: 0;
}

#faActions {
  flex: 0 0 auto;
  display: flex;
  gap: 0.5rem;
  padding: 0.5rem 0.9rem 0;
}

#faActions[hidden] { display: none !important; }

#faCombat button,
#faChoices button,
#faActions button,
#faSaveRow button,
#faSend {
  padding: 0.4rem 0.85rem;
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  color: #3b2a10;
  background: #f7ecd4;
  border: 1px solid #d4a017;
  border-radius: 999px;
}

#faCombat button:hover,
#faChoices button:hover,
#faSaveRow button:hover { background: #fff6e0; }

#faCombat button:disabled,
#faChoices button:disabled,
#faActions button:disabled,
#faSend:disabled,
#faInput:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

#faSave {
  flex: 0 0 auto;
  padding: 0 0.9rem 0.6rem;
  font-size: 0.82rem;
  color: #f4e6c8;
}

#faSave > summary {
  cursor: pointer;
  padding: 0.35rem 0;
  color: #e8d49a;
  list-style: none;
}

#faSave > summary::-webkit-details-marker { display: none; }
#faSave > summary::before { content: "\25B8  "; }
#faSave[open] > summary::before { content: "\25BE  "; }
#faSave > summary:hover { color: #fff6e0; }

#faSaveNote {
  margin: 0.2rem 0 0.45rem;
  line-height: 1.45;
  color: #d9c7a0;
}

#faSaveCode {
  display: block;
  width: 100%;
  padding: 0.4rem 0.5rem;
  font-family: ui-monospace, "Cascadia Mono", Menlo, Consolas, monospace;
  font-size: 0.72rem;
  line-height: 1.35;
  word-break: break-all;
  color: #3b2a10;
  background: #fffdf6;
  border: 1px solid #d4a017;
  border-radius: 6px;
  resize: vertical;
}

#faSaveRow {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-top: 0.45rem;
}

#faSaveMsg {
  font-size: 0.78rem;
  color: #d9c7a0;
}

#faSaveMsg.is-bad { color: #ffb3a7; }
#faSaveMsg.is-good { color: #b6e3a0; }
#faSaveMsg a,
.fa-bubble a {
  color: #ffd166;
  text-decoration: underline;
  font-weight: 600;
}
#faSaveMsg a:hover,
.fa-bubble a:hover {
  color: #ffffff;
}

.fa-savebox { max-width: 100%; }

.fa-savecode {
  display: block;
  width: 100%;
  margin: 0.45rem 0;
  padding: 0.4rem 0.5rem;
  font-family: ui-monospace, "Cascadia Mono", Menlo, Consolas, monospace;
  font-size: 0.72rem;
  line-height: 1.35;
  word-break: break-all;
  color: #3b2a10;
  background: #fffdf6;
  border: 1px solid #d4a017;
  border-radius: 6px;
  resize: vertical;
}

.fa-savecopy {
  padding: 0.3rem 0.8rem;
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
  color: #3b2a10;
  background: #f7ecd4;
  border: 1px solid #d4a017;
  border-radius: 999px;
}

.fa-savecopy:hover { background: #fff6e0; }

#faActions #faPotion,
#faActions #faPotion2 {
  border-color: #7bbf6a;
  background: #eaf7e4;
  color: #24401c;
}

#faActions #faPotion:hover,
#faActions #faPotion2:hover { background: #f5fff0; }

#faChoices {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0 0.9rem 0.6rem;
}

#faForm {
  flex: 0 0 auto;
  display: flex;
  gap: 0.5rem;
  padding: 0.6rem 0.9rem 0.8rem;
  border-top: 1px solid rgba(212, 160, 23, 0.25);
  background: rgba(0, 0, 0, 0.25);
}

#faInput {
  flex: 1 1 auto;
  min-width: 0;
  padding: 0.6rem 0.85rem;
  font: inherit;
  border-radius: 999px;
  border: 1px solid #d4a017;
  background: #f7ecd4;
  color: #2a1c10;
}

#faInput:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(212, 160, 23, 0.28);
}

#faSend {
  font-weight: 600;
  color: #fff8e7;
  border: 0;
  background: linear-gradient(135deg, #8a5a12 0%, #d4a017 100%);
}

.fa-typing {
  display: inline-flex;
  gap: 4px;
  padding: 2px 0;
}

.fa-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #d4a017;
  animation: faBlink 1.2s infinite ease-in-out;
}

.fa-typing span:nth-child(2) { animation-delay: 0.2s; }
.fa-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes faBlink {
  0%, 80%, 100% { opacity: 0.3; }
  40% { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .fa-typing span { animation: none; }
}

@media (max-width: 900px) {
  .fa-hud-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .fa-hud-grid .fa-stat:not(.fa-stat-wide):not(.fa-stat-full) { grid-column: span 3; }
  .fa-hud-grid .fa-stat-wide { grid-column: span 3; }
  .fa-hud-grid .fa-stat-full { grid-column: span 6; }
}

@media (max-width: 767px) {
  body {
    padding: 0 !important;
    height: 100dvh;
    min-height: 100dvh;
    overflow: hidden;
    background-attachment: scroll;
  }

  #gameContainer {
    padding: 0.25rem 0.35rem 0.35rem;
    width: 100%;
    height: calc(100dvh - 76px);
    max-height: calc(100dvh - 76px);
    margin-bottom: 76px;
  }

  .game-header {
    margin-bottom: 0.1rem;
  }

  #gameContainer h1 {
    font-size: 0.95rem;
    margin: 0 0 0.1rem;
    line-height: 1.1;
  }

  .game-intro {
    margin: 0 auto 0.12rem;
    font-size: 0.72rem;
  }

  .game-intro summary {
    padding: 0.12rem 0.45rem;
    font-size: 0.68rem;
  }

  .game-intro .intro-content {
    max-height: 80px;
    font-size: 0.72rem;
    padding: 0.3rem 0.45rem;
  }

  /* Compact HUD on Mobile */
  #faHud {
    margin: 0.1rem 0 0.25rem;
    padding: 0.25rem 0.45rem;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.45);
    border: 1px solid rgba(212, 160, 23, 0.4);
    display: flex;
    flex-direction: column;
    gap: 0;
  }

  .fa-hud-summary {
    align-items: center;
    justify-content: space-between;
    gap: 0.3rem;
    width: 100%;
    cursor: pointer;
    font-size: 0.75rem;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
  }

  .fa-summary-label { font-size: 0.62rem; }
  .fa-summary-val { font-size: 0.75rem; }

  .fa-hp-bar-sm {
    width: 34px;
    height: 6px;
    margin: 0 0 0 0.2rem;
    display: inline-block;
    vertical-align: middle;
  }

  .fa-summary-companion .fa-summary-val,
  .fa-summary-location .fa-summary-val {
    font-size: 0.7rem;
  }

  .fa-companion-summary-hp-bar {
    flex-basis: 34px;
    width: 34px;
  }

  .fa-summary-toggle {
    font-size: 0.65rem;
  }

  .fa-hud-grid {
    display: none;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.2rem 0.45rem;
    margin-top: 0.3rem;
    padding-top: 0.3rem;
    border-top: 1px solid rgba(212, 160, 23, 0.25);
    font-size: 0.72rem;
  }

  .fa-hud-grid.is-expanded {
    display: grid;
  }

  .fa-hud-grid .fa-stat-wide {
    grid-column: span 1;
  }

  .fa-hud-grid .fa-stat:not(.fa-stat-wide):not(.fa-stat-full) {
    grid-column: span 1;
  }

  .fa-hud-grid .fa-stat-full {
    grid-column: span 3;
  }

  .fa-hud-grid .fa-label {
    font-size: 0.58rem;
  }

  .fa-hud-grid .fa-value {
    font-size: 0.7rem;
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
    overflow-wrap: anywhere;
    line-height: 1.2;
  }

  .fa-hud-grid .fa-companion-details {
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
    overflow-wrap: anywhere;
    line-height: 1.2;
  }

  /* Play area takes max height */
  #faPlay {
    flex: 1 1 0;
    min-height: 0;
    border-radius: 10px;
  }

  .fa-header {
    padding: 0.3rem 0.5rem;
    gap: 0.35rem;
  }

  .fa-header .fa-mark {
    width: 28px;
    height: 28px;
    font-size: 0.85rem;
    border-width: 1.5px;
  }

  .fa-header .fa-name {
    font-size: 0.85rem;
  }

  .fa-header .fa-name-wrap {
    min-width: 0;
  }

  .fa-player-name-input {
    font-size: 0.78rem;
    padding: 0.05rem 0.25rem;
    width: 56px;
    max-width: 16vw;
  }

  .fa-summary-player-item .fa-summary-val {
    max-width: 48px;
  }

  .fa-header .fa-tag {
    display: none;
  }

  .fa-mute,
  .fa-tts-toggle,
  .fa-tts-settings,
  .fa-reset {
    padding: 0.2rem 0.5rem;
    font-size: 0.7rem;
    gap: 0.2rem;
  }

  .fa-tts-settings {
    width: 28px;
    padding-inline: 0.25rem;
  }

  .fa-mute-text,
  .fa-tts-text,
  .fa-tts-settings span {
    display: none;
  }

  .fa-tts-panel {
    align-items: end;
    justify-items: stretch;
    padding: 0;
  }

  .fa-tts-dialog {
    width: 100%;
    max-width: 100%;
    max-height: 78vh;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 0.75rem 2rem 0.75rem 0.75rem;
    border-right: 0;
    border-bottom: 0;
    border-left: 0;
    border-radius: 12px 12px 0 0;
  }

  .fa-tts-dialog h2 {
    font-size: 0.95rem;
  }

  .fa-tts-dialog-head {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "title close"
      "default default";
  }

  .fa-tts-dialog-head h2 { grid-area: title; }

  #faTtsClose { grid-area: close; }

  #faVolDefault {
    grid-area: default;
    width: 100%;
    margin-top: 0.15rem;
  }

  .fa-vol-meta {
    justify-content: flex-start;
  }

  .fa-tts-preview-row {
    align-items: flex-start;
    flex-direction: column;
    gap: 0.35rem;
  }

  #faMessages {
    flex: 1 1 0;
    min-height: 0;
    padding: 0.45rem 0.55rem;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
  }

  .fa-row {
    margin-bottom: 0.4rem;
    gap: 0.3rem;
  }

  .fa-avatar {
    width: 26px;
    height: 26px;
    flex: 0 0 26px;
  }

  .fa-avatar-dm {
    font-size: 0.8rem;
  }

  .fa-bubble {
    max-width: 90%;
    padding: 0.4rem 0.55rem;
    font-size: 0.88rem;
    line-height: 1.35;
    border-radius: 10px;
  }

  .fa-row.system .fa-bubble {
    font-size: 0.8rem;
    padding: 0.3rem 0.45rem;
    max-width: 96%;
  }

  #faCombat {
    padding: 0.3rem 0.5rem;
    gap: 0.25rem;
  }

  #faMonster {
    font-size: 0.8rem;
  }

  .fa-monster-hp-bar {
    flex-basis: 90px;
    width: 90px;
  }

  #faCombat button,
  #faChoices button,
  #faActions button {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
  }

  #faActions {
    padding: 0.25rem 0.5rem 0;
  }

  #faChoices {
    padding: 0.25rem 0.5rem;
    gap: 0.3rem;
    max-height: 110px;
    overflow-y: auto;
  }

  #faForm {
    padding: 0.3rem 0.45rem 0.35rem;
    gap: 0.3rem;
  }

  #faInput {
    padding: 0.4rem 0.6rem;
    font-size: 0.82rem;
  }

  #faSend {
    padding: 0.4rem 0.65rem;
    font-size: 0.8rem;
  }

  #faSave {
    padding: 0 0.5rem 0.25rem;
    font-size: 0.7rem;
  }

  #faSave > summary {
    padding: 0.15rem 0;
  }
}

@media (max-width: 767px) and (orientation: portrait) {
  /* Give the compact portrait HUD room to breathe. */
  #faHudGrid .fa-hp-bar {
    display: none;
  }

  .fa-summary-hp .fa-hp-bar-sm {
    display: none;
  }

  .fa-summary-companion .fa-companion-summary-hp-bar {
    display: none;
  }

  .fa-summary-companion-full {
    display: none;
  }

  .fa-summary-companion-short {
    display: inline;
  }

  .fa-hud-summary {
    flex-wrap: wrap;
    row-gap: 0.2rem;
  }
}

/* Potion belt: full labels on desktop, short one-liners on mobile.
 * Narrator choices: one line each on mobile, clipped with an ellipsis
 * (full text stays in the button's title and is what gets sent). */
.fa-lbl-short { display: none; }

@media (max-width: 767px) {
  #faActions {
    flex-wrap: nowrap;
    gap: 0.3rem;
  }

  #faActions button {
    flex: 0 1 auto;
    min-width: 0;
    padding: 0.2rem 0.55rem;
    font-size: 0.72rem;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  #faActions .fa-lbl-full { display: none; }
  #faActions .fa-lbl-short { display: inline; }

  #faChoices button {
    min-width: 0;
    max-width: 100%;
    padding: 0.22rem 0.6rem;
    font-size: 0.72rem;
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: left;
  }
}
