:root {
  --ui-scale: 1;
  --bg-deep: #0f1a15;
  --bg-mid: #1f2f27;
  --bg-accent: #415a46;
  --panel: rgba(17, 29, 24, 0.88);
  --line: rgba(200, 223, 173, 0.34);
  --line-strong: rgba(232, 242, 200, 0.58);
  --text: #f6f8ec;
  --muted: #c9d4bc;
  --good: #8fd39f;
  --warn: #e8c577;
  --bad: #e58f8f;
  --funding: #e8c577;
  --credibility: #9fc6ff;
  --trust: #8fd39f;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  height: 100%;
  overflow: hidden;
}

body {
  font-family: "Palatino Linotype", "Book Antiqua", Georgia, serif;
  color: var(--text);
  background: #0a0d08;
  padding: 0;
  display: flex;
  align-items: stretch;
  justify-content: stretch;
}

.gameShell {
  width: 100%;
  height: 100%;
  border: none;
  border-radius: 0;
  overflow: hidden;
  background: #0a0d08;
  display: flex;
  flex-direction: column;
}

.hudTop {
  display: none;
}

.brand h1 {
  margin: 0;
  font-family: "Book Antiqua", "Palatino Linotype", Georgia, serif;
  font-size: calc(1.35rem * var(--ui-scale));
  letter-spacing: 0.45px;
}

.brand p {
  margin: 3px 0 0;
  font-size: calc(0.85rem * var(--ui-scale));
  color: var(--muted);
}

.hudStats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
  align-items: center;
  flex: 1;
}

.hudTools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  max-width: 360px;
}

.toolBtn {
  appearance: none;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  font: 700 calc(0.72rem * var(--ui-scale)) "Trebuchet MS", sans-serif;
  letter-spacing: 0.15px;
  padding: calc(6px * var(--ui-scale)) calc(10px * var(--ui-scale));
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.toolBtn:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: var(--line-strong);
  color: var(--text);
}

.toolBtn.active {
  background: rgba(255, 219, 159, 0.16);
  border-color: rgba(255, 219, 159, 0.72);
  color: #fff4dd;
}

.statBar {
  display: flex;
  align-items: center;
  gap: calc(6px * var(--ui-scale));
  padding: calc(6px * var(--ui-scale)) calc(10px * var(--ui-scale));
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.05);
  font-size: calc(0.8rem * var(--ui-scale));
}

.statLabel {
  color: var(--muted);
  min-width: 52px;
  font-size: calc(0.74rem * var(--ui-scale));
}

.statTrack {
  width: calc(64px * var(--ui-scale));
  height: calc(8px * var(--ui-scale));
  border-radius: 999px;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.statFill {
  height: 100%;
  transition: width 0.4s ease;
}

.statBar[data-stat="funding"] .statFill {
  background: linear-gradient(90deg, #f8e096, var(--funding));
}

.statBar[data-stat="credibility"] .statFill {
  background: linear-gradient(90deg, #bfd5ff, var(--credibility));
}

.statBar[data-stat="trust"] .statFill {
  background: linear-gradient(90deg, #9ef1c0, var(--trust));
}

.statNum {
  font-weight: 700;
  min-width: 14px;
  text-align: center;
}

.chip {
  padding: calc(6px * var(--ui-scale)) calc(10px * var(--ui-scale));
  border-radius: 999px;
  border: 1px solid var(--line);
  font-size: calc(0.8rem * var(--ui-scale));
  color: var(--muted);
  background: rgba(255, 255, 255, 0.05);
  white-space: nowrap;
}

.chip b {
  color: var(--text);
}

.helpChip {
  min-width: 260px;
  max-width: 460px;
  white-space: normal;
  line-height: 1.25;
}

.roleChip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.hudAvatar {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #edf6d8, #88b77d);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.2);
}

.arena {
  padding: 0;
  background: #0a0d08;
  flex: 1;
  display: flex;
}

.sceneWrap {
  position: relative;
  border: none;
  border-radius: 0;
  overflow: hidden;
  background: #0a0d08;
  flex: 1;
  min-height: 0;
}

#sceneCanvas {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: auto;
  filter: saturate(1.04) contrast(1.03);
}

.sceneWrap::before,
.sceneWrap::after {
  display: none;
}

.touchControls {
  position: absolute;
  inset: auto 10px 10px 10px;
  display: none;
  justify-content: space-between;
  align-items: flex-end;
  pointer-events: none;
  z-index: 6;
}

.touchPad {
  display: grid;
  gap: 6px;
  pointer-events: auto;
}

.touchMove {
  grid-template-columns: repeat(3, 62px);
  grid-template-rows: repeat(3, 54px);
  grid-template-areas:
    ". up ."
    "left down right"
    ". . .";
}

.touchAction {
  grid-template-columns: repeat(3, 74px);
  grid-template-areas: "jump attack skill";
}

.touchBtn {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.34);
  border-radius: 12px;
  background: rgba(19, 31, 26, 0.74);
  color: #f4f7ea;
  font: 700 0.76rem "Trebuchet MS", sans-serif;
  letter-spacing: 0.2px;
  user-select: none;
  touch-action: manipulation;
  min-height: 54px;
}

.touchBtn[data-touch="up"] {
  grid-area: up;
}

.touchBtn[data-touch="left"] {
  grid-area: left;
}

.touchBtn[data-touch="down"] {
  grid-area: down;
}

.touchBtn[data-touch="right"] {
  grid-area: right;
}

.touchBtn[data-touch="jump"] {
  grid-area: jump;
  min-height: 58px;
}

.touchBtn[data-touch="attack"] {
  grid-area: attack;
  min-height: 58px;
}

.touchBtn[data-touch="skill"] {
  grid-area: skill;
  min-height: 58px;
}

.touchBtn:active,
.touchBtn.active {
  background: rgba(63, 100, 80, 0.88);
}

.overlayTop,
.overlayBottom {
  position: absolute;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  pointer-events: none;
  padding: 10px;
}

.overlayTop {
  top: 0;
}

.overlayBottom {
  bottom: 0;
}

.episodeBanner,
.objectiveBanner {
  max-width: min(920px, 100%);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: rgba(15, 24, 20, 0.88);
  padding: 8px 12px;
  text-align: center;
  line-height: 1.35;
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.35);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.episodeBanner.hidden,
.objectiveBanner.hidden {
  opacity: 0;
  transform: translateY(-8px);
}

.episodeBanner .title {
  display: block;
  font-size: 0.93rem;
  color: var(--warn);
}

.episodeBanner .text,
.objectiveBanner {
  font-size: 0.84rem;
  color: var(--muted);
}

.notifyLayer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 50;
}

.floatNotify {
  position: absolute;
  pointer-events: none;
  font-weight: 700;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.72);
  animation: floatUp 1.2s ease-out forwards;
}

.floatNotify.good {
  color: var(--good);
}

.floatNotify.bad {
  color: var(--bad);
}

.floatNotify.score {
  color: var(--warn);
  font-size: 1.1rem;
}

.floatNotify.crit {
  color: #ffe8a8;
  font-size: 1.18rem;
  letter-spacing: 0.3px;
}

.floatNotify.info {
  color: var(--text);
}

@keyframes floatUp {
  0% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }

  100% {
    opacity: 0;
    transform: translateY(-56px) scale(1.1);
  }
}

@media (max-width: 1080px) {
  #sceneCanvas {
    height: 100%;
  }
}

@media (max-width: 760px) {
  #sceneCanvas {
    height: 100%;
  }
}

@media (pointer: coarse), (max-width: 860px) {
  .touchControls {
    display: flex;
  }
}

@media (max-width: 520px) {
  .statTrack {
    width: 50px;
  }

  .chip,
  .statBar {
    font-size: 0.73rem;
  }

  .helpChip {
    min-width: 160px;
  }

  .sceneWrap {
    min-height: 0;
  }

  .touchMove {
    grid-template-columns: repeat(3, 52px);
    grid-template-rows: repeat(3, 46px);
  }

  .touchAction {
    grid-template-columns: repeat(3, 64px);
  }

  .touchBtn {
    min-height: 46px;
    font-size: 0.74rem;
  }

  .touchBtn[data-touch="jump"],
  .touchBtn[data-touch="attack"],
  .touchBtn[data-touch="skill"] {
    min-height: 50px;
  }
}

body.a11y-large-text {
  font-size: 112%;
}

body.a11y-large-text .chip,
body.a11y-large-text .statBar,
body.a11y-large-text .toolBtn {
  font-size: 0.9rem;
}

body.a11y-large-text .brand h1 {
  font-size: 1.55rem;
}

body.a11y-high-contrast {
  --text: #ffffff;
  --muted: #f0f4dc;
  --line: rgba(255, 255, 255, 0.7);
  --line-strong: rgba(255, 255, 255, 0.95);
  --panel: rgba(0, 0, 0, 0.95);
  --funding: #ffe06d;
  --credibility: #9fd1ff;
  --trust: #9cf7b0;
}

body.a11y-high-contrast .sceneWrap {
  filter: contrast(1.18) saturate(1.12);
}

body.a11y-reduced-motion * {
  transition-duration: 0ms !important;
  animation-duration: 0ms !important;
}

body.quality-low #sceneCanvas {
  filter: saturate(0.96) contrast(1.01);
}

body.quality-low .sceneWrap::before {
  opacity: 0.5;
}

body.quality-high #sceneCanvas {
  filter: saturate(1.1) contrast(1.08);
}

/* ── Login Overlay ── */
.loginOverlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0a0e1a 0%, #1a1040 50%, #0d1520 100%);
}

.loginOverlay.hidden {
  display: none;
}

.loginCard {
  width: 100%;
  max-width: 420px;
  margin: 20px;
  background: rgba(20, 16, 36, 0.95);
  border: 1px solid rgba(200, 180, 255, 0.3);
  border-radius: 18px;
  padding: 40px 36px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.6), 0 0 80px rgba(140, 120, 220, 0.08);
}

.loginHeader {
  text-align: center;
  margin-bottom: 32px;
}

.loginHeader h2 {
  margin: 0;
  font-family: "Book Antiqua", "Palatino Linotype", Georgia, serif;
  font-size: 2rem;
  color: #f5d37e;
  letter-spacing: 1px;
}

.loginHeader p {
  margin: 8px 0 0;
  color: #c9b8e6;
  font-size: 0.95rem;
}

.loginField {
  margin-bottom: 20px;
}

.loginField label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.85rem;
  font-weight: 700;
  color: #d4c8ee;
  letter-spacing: 0.3px;
}

.loginField input {
  width: 100%;
  padding: 12px 14px;
  font-size: 1rem;
  font-family: inherit;
  color: #f0eaff;
  background: rgba(30, 24, 52, 0.9);
  border: 1px solid rgba(180, 160, 230, 0.35);
  border-radius: 10px;
  outline: none;
  transition: border-color 0.2s;
}

.loginField input:focus {
  border-color: rgba(200, 180, 255, 0.8);
  box-shadow: 0 0 0 3px rgba(180, 160, 240, 0.15);
}

.loginField input::placeholder {
  color: rgba(180, 170, 210, 0.5);
}

.loginBtn {
  width: 100%;
  padding: 14px;
  margin-top: 8px;
  font-family: "Book Antiqua", "Palatino Linotype", Georgia, serif;
  font-size: 1.1rem;
  font-weight: 700;
  color: #fff7f0;
  background: linear-gradient(135deg, #7a5cc6, #5a3ea0);
  border: 1px solid rgba(200, 180, 255, 0.4);
  border-radius: 12px;
  cursor: pointer;
  letter-spacing: 0.5px;
  transition: background 0.2s, transform 0.1s;
}

.loginBtn:hover {
  background: linear-gradient(135deg, #8e6ed6, #6a4eb6);
}

.loginBtn:active {
  transform: scale(0.98);
}

.loginError {
  text-align: center;
  color: #ef8aa2;
  font-size: 0.85rem;
  margin-top: 12px;
}

.loginError.hidden {
  display: none;
}

/* ── Subjective Question Overlay ── */
.subjective-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 14, 26, 0.92);
  backdrop-filter: blur(6px);
  padding: 16px;
  animation: sqFadeIn 0.3s ease-out;
}
.subjective-overlay.hidden {
  display: none;
}
@keyframes sqFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
.subjective-panel {
  background: linear-gradient(145deg, rgba(20, 30, 50, 0.97), rgba(15, 22, 38, 0.98));
  border: 1px solid rgba(200, 180, 255, 0.2);
  border-radius: 18px;
  padding: 32px 28px;
  max-width: 620px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5), 0 0 60px rgba(122, 92, 198, 0.08);
}
.subjective-header {
  text-align: center;
  margin-bottom: 20px;
}
.subjective-icon {
  font-size: 2rem;
  display: block;
  margin-bottom: 6px;
  opacity: 0.7;
}
.subjective-title {
  font-family: 'Book Antiqua', Georgia, serif;
  font-size: 1.5rem;
  color: #c49bff;
  margin: 0 0 4px;
}
.subjective-episode {
  font-size: 0.85rem;
  color: #a0a8c0;
  margin: 0;
}
.subjective-prompt {
  font-family: 'Palatino Linotype', Georgia, serif;
  font-size: 1rem;
  color: #f0eaff;
  line-height: 1.6;
  margin-bottom: 18px;
  padding: 14px 16px;
  background: rgba(255, 255, 255, 0.04);
  border-left: 3px solid #c49bff;
  border-radius: 0 8px 8px 0;
}
.subjective-input {
  width: 100%;
  min-height: 120px;
  padding: 14px;
  border: 1px solid rgba(200, 180, 255, 0.2);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.05);
  color: #f0eaff;
  font-family: 'Palatino Linotype', Georgia, serif;
  font-size: 0.95rem;
  line-height: 1.6;
  resize: vertical;
  outline: none;
  transition: border-color 0.2s;
}
.subjective-input:focus {
  border-color: #c49bff;
}
.subjective-input::placeholder {
  color: rgba(160, 168, 192, 0.5);
}
.subjective-charcount {
  font-size: 0.78rem;
  color: #a0a8c0;
  text-align: right;
  margin: 4px 0 16px;
}
.subjective-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
}
.subjective-btn {
  padding: 10px 28px;
  border: none;
  border-radius: 999px;
  font-family: 'Book Antiqua', Georgia, serif;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}
.subjective-btn:hover {
  transform: translateY(-1px);
}
.submit-btn {
  background: linear-gradient(135deg, #7a5cc6, #5a3d8a);
  color: #f8f3e8;
  box-shadow: 0 4px 16px rgba(122, 92, 198, 0.3);
}
.submit-btn:hover {
  box-shadow: 0 6px 20px rgba(122, 92, 198, 0.45);
}
.skip-btn {
  background: rgba(255, 255, 255, 0.07);
  color: #a0a8c0;
  border: 1px solid rgba(255, 255, 255, 0.1);
}
.skip-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #f0eaff;
}
.continue-btn {
  background: linear-gradient(135deg, #2a8a55, #1d6b40);
  color: #f8f3e8;
  box-shadow: 0 4px 16px rgba(89, 217, 142, 0.25);
  margin-top: 8px;
}
.subjective-result {
  text-align: center;
  padding-top: 12px;
}
.subjective-result.hidden {
  display: none;
}
.subjective-score {
  margin-bottom: 12px;
  line-height: 1.3;
}
.subjective-feedback {
  font-family: 'Palatino Linotype', Georgia, serif;
  font-size: 0.9rem;
  color: #c9d4bc;
  line-height: 1.6;
  margin-bottom: 16px;
  padding: 12px 16px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 10px;
  text-align: left;
}
.subjective-loading {
  text-align: center;
  padding: 24px 0;
  color: #a0a8c0;
  font-size: 0.9rem;
}
.subjective-loading.hidden {
  display: none;
}
.subjective-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid rgba(196, 155, 255, 0.2);
  border-top-color: #c49bff;
  border-radius: 50%;
  animation: sqSpin 0.8s linear infinite;
  margin: 0 auto 12px;
}
@keyframes sqSpin {
  to { transform: rotate(360deg); }
}
.subjective-error {
  color: #FF6B6B;
  font-size: 0.85rem;
  text-align: center;
  margin-top: 10px;
}
.subjective-error.hidden {
  display: none;
}
.subjective-input.hidden,
.subjective-charcount.hidden {
  display: none;
}
@media (max-width: 500px) {
  .subjective-panel {
    padding: 22px 16px;
  }
  .subjective-title {
    font-size: 1.2rem;
  }
  .subjective-actions {
    flex-direction: column;
  }
}
