:root {
  color-scheme: dark;
  --bg: #061016;
  --panel: rgba(7, 15, 20, .92);
  --panel-soft: rgba(7, 15, 20, .74);
  --gold: #d9a43b;
  --gold-light: #f2cd79;
  --text: #f8f2e5;
  --muted: #aeb9bd;
  --border: rgba(217, 164, 59, .34);
  --danger: #d96f61;
  --blue: #6ca7cf;
  --success: #8fc58a;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; background: var(--bg); }
body { font-family: Tahoma, Arial, sans-serif; color: var(--text); }
button, input, a { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

#game { position: relative; width: 100%; height: 100dvh; min-height: 520px; overflow: hidden; background: #061016; }
#viewer { position: absolute; inset: 0; touch-action: none; }
#viewer canvas { display: block; width: 100%; height: 100%; }

.screen-layer, .modal-layer {
  position: absolute; inset: 0; z-index: 50; display: grid; place-items: center;
  padding: 20px; background: rgba(1, 5, 8, .72); backdrop-filter: blur(12px);
}
.loading-screen { text-align: center; }
.loading-screen h1 { margin: 18px 0 8px; font-size: clamp(22px, 4vw, 38px); }
.loading-screen p { margin: 0 0 18px; color: var(--muted); }
.brand-mark {
  display: grid; place-items: center; width: 88px; height: 88px; margin: 0 auto;
  border: 1px solid var(--border); border-radius: 50%; color: var(--gold-light);
  font-size: 25px; letter-spacing: .08em; background: rgba(217, 164, 59, .08);
}
.loading-track, .progress-track { overflow: hidden; border-radius: 999px; background: rgba(255,255,255,.1); }
.loading-track { width: min(360px, 76vw); height: 7px; margin: 0 auto 10px; }
.loading-track > div, .progress-track > div { width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #a36e18, var(--gold-light)); transition: width .25s ease; }

.start-card, .question-card, .result-card {
  width: min(680px, 100%); max-height: calc(100dvh - 36px); overflow: auto;
  border: 1px solid var(--border); border-radius: 24px; background: var(--panel);
  padding: clamp(24px, 4vw, 42px); box-shadow: 0 30px 80px rgba(0,0,0,.38);
}
.start-card { text-align: center; }
.start-card h1 { margin: 8px 0 15px; font-size: clamp(28px, 5vw, 52px); }
.start-card p { color: var(--muted); line-height: 1.9; }
.start-card small { display: block; margin-top: 18px; color: var(--muted); line-height: 1.7; }
.kicker { margin: 0 0 7px; color: var(--gold-light); font-size: 12px; letter-spacing: .08em; }
.start-actions, .modal-actions, .result-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 24px; }
.primary-button, .secondary-button {
  min-height: 48px; padding: 0 20px; border-radius: 13px; cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center;
}
.primary-button { border: 1px solid #e5b85b; color: #13100a; background: linear-gradient(135deg, #f0ca77, #c88622); font-weight: 700; }
.secondary-button { border: 1px solid var(--border); color: var(--gold-light); background: rgba(255,255,255,.035); }

.hud {
  position: absolute; z-index: 20; top: max(12px, env(safe-area-inset-top)); left: 14px; right: 14px;
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(180px, 360px) auto;
  align-items: center; gap: 14px; padding: 12px 14px; border: 1px solid rgba(255,255,255,.09);
  border-radius: 17px; background: var(--panel-soft); backdrop-filter: blur(14px);
}
.hud-brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.hud-brand > span { display: grid; place-items: center; flex: 0 0 42px; height: 42px; border: 1px solid var(--border); border-radius: 50%; color: var(--gold-light); font-size: 12px; }
.hud-brand strong, .hud-brand small { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-brand small { margin-top: 3px; color: var(--muted); font-size: 11px; }
.hud-progress > div:first-child { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 7px; font-size: 12px; }
.hud-progress span { color: var(--muted); }
.hud-progress strong { direction: ltr; }
.progress-track { height: 6px; }
.hud-actions { display: flex; gap: 7px; }
.hud-actions button { min-height: 38px; padding: 0 12px; border: 1px solid rgba(255,255,255,.1); border-radius: 10px; color: var(--text); background: rgba(0,0,0,.18); cursor: pointer; }

.movement-hint {
  position: absolute; z-index: 15; bottom: max(28px, env(safe-area-inset-bottom)); left: 50%;
  transform: translateX(-50%); padding: 9px 14px; border: 1px solid var(--border);
  border-radius: 999px; color: var(--gold-light); background: rgba(4,10,13,.76); font-size: 12px;
  white-space: nowrap; backdrop-filter: blur(10px);
}

.question-card, .result-card { position: relative; }
.question-card h2, .result-card h2 { margin: 5px 0 10px; font-size: clamp(22px, 4vw, 34px); line-height: 1.45; }
.modal-description, .result-text { color: var(--muted); line-height: 1.85; }
.close-button { position: absolute; top: 13px; left: 13px; width: 38px; height: 38px; border: 1px solid rgba(255,255,255,.11); border-radius: 50%; color: var(--text); background: rgba(255,255,255,.04); cursor: pointer; font-size: 23px; }
.modal-error { min-height: 22px; margin: 14px 0 0; color: #ffb6aa; font-size: 13px; }

.field-label { display: block; margin: 18px 0 8px; color: var(--text); font-weight: 700; }
.text-input { width: 100%; min-height: 50px; border: 1px solid rgba(255,255,255,.14); border-radius: 13px; padding: 0 14px; color: var(--text); background: rgba(255,255,255,.045); outline: none; }
.text-input:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(217,164,59,.12); }

.choice-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 10px; margin-top: 18px; }
.choice-card, .check-card {
  position: relative; display: flex; gap: 10px; align-items: flex-start; padding: 14px;
  border: 1px solid rgba(255,255,255,.11); border-radius: 14px; background: rgba(255,255,255,.035); cursor: pointer;
}
.choice-card input, .check-card input { margin-top: 4px; accent-color: var(--gold); }
.choice-card:has(input:checked), .check-card:has(input:checked) { border-color: var(--gold); background: rgba(217,164,59,.09); }
.choice-card strong, .choice-card small { display: block; }
.choice-card small { margin-top: 4px; color: var(--muted); line-height: 1.6; }
.check-list { display: grid; gap: 8px; margin-top: 12px; }
.check-card { line-height: 1.65; }
.exception-block { margin-top: 20px; padding-top: 18px; border-top: 1px solid rgba(255,255,255,.09); }
.exception-block h3 { margin: 0 0 5px; font-size: 17px; }
.exception-block > p { margin: 0; color: var(--muted); font-size: 13px; }

.rating-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; direction: ltr; }
.rating-row label { cursor: pointer; }
.rating-row input { position: absolute; opacity: 0; pointer-events: none; }
.rating-row span { display: grid; place-items: center; width: 48px; height: 48px; border: 1px solid rgba(255,255,255,.14); border-radius: 12px; color: var(--text); background: rgba(255,255,255,.035); transition: .15s ease; }
.rating-row input:checked + span { border-color: var(--gold); color: #161008; background: var(--gold-light); transform: translateY(-2px); }
.rating-help { display: flex; justify-content: space-between; margin-top: 8px; color: var(--muted); font-size: 11px; }
.comparison-box { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 18px; }
.comparison-column { padding: 14px; border: 1px solid rgba(255,255,255,.1); border-radius: 14px; background: rgba(255,255,255,.025); }
.comparison-column h3 { margin: 0 0 8px; font-size: 15px; }
.comparison-column .rating-row span { width: 42px; height: 42px; }

.result-card { text-align: center; }
.result-icon { display: grid; place-items: center; width: 76px; height: 76px; margin: 0 auto 18px; border: 1px solid var(--border); border-radius: 50%; color: var(--gold-light); background: rgba(217,164,59,.09); font-size: 30px; }
.result-note { margin: 16px 0; padding: 13px; border: 1px solid var(--border); border-radius: 13px; color: var(--gold-light); background: rgba(217,164,59,.07); line-height: 1.7; }
.score-list { display: grid; gap: 13px; margin-top: 23px; text-align: right; }
.score-list > div > div { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 7px; }
.score-list strong { direction: ltr; }
.score-list i { display: block; height: 9px; overflow: hidden; border-radius: 999px; background: rgba(255,255,255,.1); }
.score-list i b { display: block; width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #a36e18, var(--gold-light)); transition: width .5s ease; }
.copy-status { min-height: 20px; color: var(--muted); font-size: 12px; }

.mobile-controls { position: absolute; z-index: 18; left: 18px; right: 18px; bottom: max(18px, env(safe-area-inset-bottom)); align-items: flex-end; justify-content: space-between; pointer-events: none; }
.joystick { position: relative; width: 116px; height: 116px; border: 1px solid rgba(255,255,255,.13); border-radius: 50%; background: rgba(4,10,13,.5); pointer-events: auto; touch-action: none; backdrop-filter: blur(8px); }
.joystick > div { position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; transform: translate(-50%,-50%); border: 1px solid var(--border); border-radius: 50%; background: rgba(217,164,59,.22); }
.run-button { width: 78px; height: 78px; border: 1px solid var(--border); border-radius: 50%; color: #17110a; background: var(--gold-light); font-weight: 700; pointer-events: auto; touch-action: none; }

.webgl-error { position: absolute; z-index: 100; inset: 0; display: grid; place-items: center; padding: 30px; text-align: center; background: #071016; }
.webgl-error a { color: var(--gold-light); }

@media (max-width: 760px) {
  .hud { grid-template-columns: minmax(0,1fr) auto; gap: 9px; padding: 9px; }
  .hud-progress { grid-column: 1 / -1; grid-row: 2; }
  .hud-actions button:first-child { display: none; }
  .hud-brand > span { flex-basis: 37px; height: 37px; }
  .hud-brand strong { font-size: 13px; }
  .hud-brand small { font-size: 10px; }
  .movement-hint { bottom: 150px; }
  .choice-grid, .comparison-box { grid-template-columns: 1fr; }
  .start-card, .question-card, .result-card { border-radius: 18px; padding: 24px 18px; }
  .modal-layer { padding: 10px; }
  .rating-row { justify-content: center; }
  .mobile-controls { display: flex; }
}

@media (max-height: 650px) {
  .movement-hint { display: none !important; }
  .start-card, .question-card, .result-card { max-height: calc(100dvh - 12px); }
}


/* =========================================================
   PSM VISION GATE V7
   ========================================================= */
.modal-layer.vision-mode .question-card {
  width: min(1060px, 100%);
}

.vision-game-intro {
  margin-top: 14px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 13px;
  color: var(--gold-light);
  background: rgba(217, 164, 59, .07);
  line-height: 1.75;
}

.vision-game-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.vision-game-field {
  position: relative;
  display: block;
  padding: 15px;
  border: 1px solid rgba(255, 255, 255, .11);
  border-radius: 15px;
  background: rgba(255, 255, 255, .03);
}

.vision-game-field > span {
  display: grid;
  place-items: center;
  width: 29px;
  height: 29px;
  margin-bottom: 9px;
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--gold-light);
  font-size: 12px;
}

.vision-game-field strong,
.vision-game-field small {
  display: block;
}

.vision-game-field strong {
  line-height: 1.55;
}

.vision-game-field small {
  min-height: 38px;
  margin-top: 5px;
  color: var(--muted);
  line-height: 1.6;
}

.vision-game-field textarea {
  width: 100%;
  min-height: 105px;
  margin-top: 10px;
  padding: 12px;
  resize: vertical;
  border: 1px solid rgba(255, 255, 255, .14);
  border-radius: 12px;
  color: var(--text);
  background: rgba(0, 0, 0, .18);
  font: inherit;
  line-height: 1.7;
  outline: none;
}

.vision-game-field textarea:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(217, 164, 59, .12);
}

.vision-game-summary {
  grid-column: 1 / -1;
}

.vision-game-summary textarea {
  min-height: 145px;
}

@media (max-width: 760px) {
  .vision-game-grid {
    grid-template-columns: 1fr;
  }

  .vision-game-summary {
    grid-column: auto;
  }

  .modal-layer.vision-mode {
    padding: 6px;
  }
}


/* =========================================================
   PSM CHARACTER SELECT V8
   ========================================================= */
.character-select-card {
  width: min(1180px, 100%);
  max-height: calc(100dvh - 30px);
  overflow: auto;
  padding: clamp(20px, 3vw, 34px);
  border: 1px solid var(--border);
  border-radius: 24px;
  background: var(--panel);
  box-shadow: 0 30px 80px rgba(0, 0, 0, .42);
  text-align: center;
}

.character-select-card h2 {
  margin: 6px 0 8px;
  font-size: clamp(25px, 4vw, 42px);
}

.character-select-intro {
  margin: 0 auto;
  color: var(--muted);
  line-height: 1.8;
}

.character-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 13px;
  margin-top: 22px;
}

.character-option {
  position: relative;
  min-width: 0;
  padding: 8px 8px 13px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, .12);
  border-radius: 17px;
  color: var(--text);
  background: rgba(255, 255, 255, .035);
  cursor: pointer;
  transition: transform .18s ease, border-color .18s ease, background .18s ease;
}

.character-option:hover:not(:disabled) {
  transform: translateY(-4px);
  border-color: rgba(217, 164, 59, .65);
}

.character-option.selected {
  border-color: var(--gold);
  background: rgba(217, 164, 59, .12);
  box-shadow: 0 0 0 3px rgba(217, 164, 59, .10);
}

.character-option:disabled {
  cursor: wait;
  opacity: .62;
}

.character-image {
  display: block;
  height: min(39vh, 360px);
  overflow: hidden;
  border-radius: 12px;
  background:
    radial-gradient(circle at 50% 32%, rgba(217, 164, 59, .16), transparent 36%),
    #121719;
}

.character-image img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center bottom;
  display: block;
}

.character-option strong,
.character-option small,
.character-option i {
  display: block;
}

.character-option strong {
  min-height: 44px;
  margin-top: 11px;
  line-height: 1.45;
}

.character-option small {
  min-height: 35px;
  margin-top: 4px;
  color: var(--muted);
  line-height: 1.45;
}

.character-option i {
  width: max-content;
  margin: 10px auto 0;
  padding: 6px 11px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--gold-light);
  font-size: 11px;
  font-style: normal;
}

.character-option.selected i {
  color: #17110a;
  background: var(--gold-light);
}

.character-loading {
  margin: 18px auto 0;
  width: min(480px, 100%);
}

.character-loading-track {
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, .1);
}

.character-loading-track > div {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #a36e18, var(--gold-light));
  transition: width .25s ease;
}

.character-loading span {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

.character-select-actions {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
}

.character-select-actions button:disabled {
  cursor: not-allowed;
  opacity: .48;
}

@media (max-width: 1050px) {
  .character-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .character-image {
    height: 310px;
  }
}

@media (max-width: 700px) {
  .character-screen {
    padding: 7px;
  }

  .character-select-card {
    max-height: calc(100dvh - 14px);
    padding: 20px 12px;
    border-radius: 18px;
  }

  .character-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 9px;
  }

  .character-image {
    height: 245px;
  }

  .character-option strong {
    min-height: 39px;
    font-size: 13px;
  }

  .character-option small {
    min-height: 31px;
    font-size: 10px;
  }
}

@media (max-width: 410px) {
  .character-grid {
    grid-template-columns: 1fr;
  }

  .character-image {
    height: 310px;
  }
}


/* =========================================================
   PSM CHARACTER IMAGE NORMALIZATION V13
   ========================================================= */

.character-option {
  display: flex;
  flex-direction: column;
  height: 440px;
}

.character-image {
  display: flex;
  flex: 0 0 285px;
  align-items: flex-end;
  justify-content: center;
  height: 285px;
  overflow: hidden;
}

.character-image img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center bottom;
  transform-origin: center bottom;
}

/* Normalize the apparent character heights */
.character-option[data-character="1"] .character-image img {
  transform: scale(1);
}

.character-option[data-character="2"] .character-image img {
  transform: scale(1);
}

.character-option[data-character="3"] .character-image img {
  transform: scale(1.10);
}

.character-option[data-character="4"] .character-image img {
  transform: scale(1.10);
}

.character-option[data-character="5"] .character-image img {
  transform: scale(1.06);
}

.character-option strong {
  display: flex;
  min-height: 52px;
  align-items: center;
  justify-content: center;
}

.character-option small {
  display: flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
}

.character-option i {
  margin-top: auto;
  margin-right: auto;
  margin-left: auto;
}

@media (max-width: 700px) {
  .character-option {
    height: 405px;
  }

  .character-image {
    flex-basis: 250px;
    height: 250px;
  }
}


/* =========================================================
   MOBILE CHARACTER IMAGE TEST V15
   ========================================================= */
@media (max-width: 768px) {
  .character-image {
    overflow: hidden !important;
  }

  .character-option[data-character] .character-image img {
    width: 100% !important;
    height: 100% !important;
    object-fit: contain !important;
    object-position: center bottom !important;
    transform: scale(1) !important;
  }
}
