﻿:root {
  --bg-deep: #061218;
  --bg-mid: #102532;
  --panel: rgba(6, 20, 30, 0.86);
  --line: #f1c96b;
  --text: #f8f5de;
  --accent: #48d597;
  --danger: #f1634f;
  --info: #77c9ff;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "VT323", monospace;
  color: var(--text);
  min-height: 100vh;
  background:
    radial-gradient(circle at 20% 10%, rgba(72, 213, 151, 0.2), transparent 35%),
    radial-gradient(circle at 80% 15%, rgba(241, 201, 107, 0.18), transparent 30%),
    linear-gradient(140deg, var(--bg-deep) 0%, #081b24 45%, var(--bg-mid) 100%);
  padding: 16px;
}

.layout {
  max-width: 1500px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 16px;
  align-items: start;
}

.game-column {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#game-container {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 2;
  border: 4px solid #23495d;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  background: #0a1c26;
}

#gameCanvas {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
}

#ui-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.hud-box {
  position: absolute;
  background: var(--panel);
  border: 2px solid #29617d;
  border-radius: 10px;
  padding: 8px 10px;
  box-shadow: 0 6px 10px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(1px);
}

#top-hud {
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
  min-width: 160px;
  font-size: 16px;
  line-height: 1.1;
}

#ui-time {
  font-family: "Press Start 2P", monospace;
  font-size: 14px;
  margin: 4px 0;
  color: var(--line);
}

#left-hud {
  top: 12px;
  left: 12px;
  font-size: 18px;
  line-height: 1.1;
  min-width: 190px;
}

#right-hud {
  top: 12px;
  right: 12px;
  width: 220px;
  font-size: 16px;
  line-height: 1.1;
}

#ui-stage {
  color: var(--line);
  font-size: 14px;
  margin-bottom: 4px;
}

#ui-tracker {
  margin-top: 6px;
  font-size: 13px;
  color: #b8f7ff;
  line-height: 1.2;
}

#mobile-mission {
  display: none;
  left: 50%;
  transform: translateX(-50%);
  bottom: 14px;
  min-width: 220px;
  max-width: calc(100% - 20px);
  text-align: center;
  font-size: 12px;
  z-index: 2;
}

#miniMap {
  width: 100%;
  height: auto;
  margin-top: 8px;
  border: 2px solid #3f7e9d;
  border-radius: 6px;
  background: #0d1b24;
  image-rendering: pixelated;
}

#interaction-prompt {
  position: absolute;
  left: 50%;
  bottom: 122px;
  transform: translateX(-50%);
  display: none;
  background: linear-gradient(180deg, rgba(23, 70, 86, 0.98) 0%, rgba(7, 35, 47, 0.96) 100%);
  border: 2px solid #9cf7d4;
  border-radius: 999px;
  padding: 7px 14px 8px;
  font-family: "Press Start 2P", monospace;
  font-size: 10px;
  letter-spacing: 0.5px;
  color: #effff8;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.45);
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.32);
}

#interaction-prompt::before {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -10px;
  transform: translateX(-50%);
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-top: 10px solid #9cf7d4;
}

#interaction-prompt::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -7px;
  transform: translateX(-50%);
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
  border-top: 9px solid #0d3b4d;
}

#dialog-box {
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  width: min(760px, calc(100% - 24px));
  background: rgba(8, 20, 32, 0.96);
  border: 3px solid #f2d68c;
  border-radius: 10px;
  display: none;
  pointer-events: auto;
}

#dialog-speaker {
  margin: 0;
  padding: 8px 14px 2px;
  font-family: "Press Start 2P", monospace;
  font-size: 10px;
  line-height: 1.2;
  color: #ffe59a;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.45);
  border-bottom: 1px solid rgba(255, 229, 154, 0.35);
}

#dialog-text {
  margin: 0;
  padding: 6px 14px 10px;
  font-size: 20px;
  line-height: 1.15;
}

.dialog-choices {
  display: flex;
  gap: 6px;
  padding: 0 12px 10px;
  flex-wrap: wrap;
  pointer-events: auto;
}

.dialog-choices.hidden {
  display: none;
}

.dialog-choice-btn {
  border: 2px solid #86f0c7;
  border-radius: 8px;
  background: rgba(14, 54, 45, 0.95);
  color: #ecfff6;
  font-family: "Press Start 2P", monospace;
  font-size: 9px;
  padding: 8px 10px;
  cursor: pointer;
}

.dialog-choice-btn:hover {
  filter: brightness(1.05);
}

#toast {
  position: absolute;
  right: 16px;
  bottom: 18px;
  max-width: 280px;
  background: rgba(20, 88, 61, 0.95);
  border: 2px solid #9dffd6;
  border-radius: 9px;
  padding: 8px 10px;
  font-size: 18px;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

#toast.show {
  opacity: 1;
  transform: translateY(0);
}

#mobile-controls {
  display: none;
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 6;
  justify-content: space-between;
  align-items: flex-end;
  width: 100%;
  pointer-events: auto;
}

#joystick-zone {
  width: 150px;
  height: 150px;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  pointer-events: auto;
}

#joystick-base {
  width: 124px;
  height: 124px;
  border-radius: 50%;
  border: 2px solid #5b9dbf;
  background:
    radial-gradient(circle at 40% 35%, rgba(167, 237, 255, 0.18), transparent 58%),
    rgba(4, 31, 44, 0.82);
  position: relative;
}

#joystick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 2px solid #a7e6ff;
  background: rgba(22, 88, 121, 0.95);
  transform: translate(-50%, -50%);
  transition: transform 0.05s linear;
}

.act-btn {
  border: 2px solid #5b9dbf;
  background: rgba(4, 31, 44, 0.95);
  color: #d5eeff;
  font-family: "Press Start 2P", monospace;
  border-radius: 10px;
}

.act-btn {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  font-size: 12px;
  border-color: #7bffcc;
  touch-action: none;
  pointer-events: auto;
}

.act-btn:active {
  transform: translateY(2px);
}

.side-panel {
  border: 2px solid #2a5b74;
  border-radius: 12px;
  padding: 14px;
  background: rgba(6, 20, 30, 0.75);
  box-shadow: inset 0 0 0 1px rgba(123, 255, 204, 0.12);
  max-height: calc(100vh - 40px);
  overflow: auto;
}

h1,
h2 {
  margin: 0;
  font-family: "Press Start 2P", monospace;
  line-height: 1.3;
}

h1 {
  font-size: 20px;
  color: var(--line);
}

h2 {
  font-size: 13px;
  margin-bottom: 6px;
  color: #aff1ff;
}

.subtitle {
  margin: 8px 0 12px;
  font-size: 20px;
  line-height: 1.05;
}

.panel-card {
  border: 1px solid #315d73;
  border-radius: 8px;
  padding: 9px;
  margin-bottom: 10px;
  background: rgba(8, 31, 45, 0.7);
}

.panel-card p,
.panel-card li {
  margin: 4px 0;
  font-size: 18px;
  line-height: 1;
}

.panel-card ol {
  margin: 0;
  padding-left: 22px;
}

.quest-list {
  margin: 0;
  padding-left: 20px;
}

.quest-list li {
  margin: 6px 0;
}

.quest-done {
  color: #9af8c9;
}

.quest-active {
  color: #ffe8a9;
}

#story-title {
  color: #ffe8a9;
  font-size: 19px;
}

#story-objective {
  color: #d8f7ff;
}

#tracker-detail,
#title-detail {
  color: #d6f8ff;
}

.profile-gate {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(3, 14, 20, 0.88);
  backdrop-filter: blur(2px);
}

.profile-gate.hidden {
  display: none;
}

.profile-card {
  width: min(460px, 100%);
  border: 2px solid #3d809f;
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(10, 35, 48, 0.95) 0%, rgba(7, 25, 36, 0.98) 100%);
  padding: 14px;
  box-shadow: 0 16px 32px rgba(0, 0, 0, 0.42);
}

.profile-card h2 {
  font-size: 16px;
  color: var(--line);
  margin-bottom: 8px;
}

.profile-card p {
  margin: 0 0 8px;
  font-size: 24px;
  line-height: 1;
}

.profile-card label {
  display: block;
  margin: 8px 0 4px;
  font-size: 22px;
}

.profile-card input {
  width: 100%;
  border: 2px solid #4a87a6;
  border-radius: 8px;
  background: rgba(5, 19, 28, 0.9);
  color: #e9fcff;
  font-family: "VT323", monospace;
  font-size: 30px;
  padding: 6px 8px;
  outline: none;
}

.profile-card input:focus {
  border-color: #85ffd4;
  box-shadow: 0 0 0 2px rgba(133, 255, 212, 0.2);
}

.profile-error {
  min-height: 22px;
  color: #ff9c89;
  font-size: 22px;
}

.profile-submit {
  width: 100%;
  border: 2px solid #8af8cf;
  border-radius: 8px;
  background: #124b3a;
  color: #e9fff4;
  font-family: "Press Start 2P", monospace;
  font-size: 11px;
  padding: 12px 10px;
  cursor: pointer;
}

.profile-submit:active {
  transform: translateY(1px);
}

.rotate-lock {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(2, 12, 18, 0.92);
  padding: 16px;
}

.rotate-lock.show {
  display: flex;
}

.rotate-card {
  width: min(360px, 100%);
  border: 2px solid #4a8db0;
  border-radius: 12px;
  background: rgba(8, 30, 43, 0.95);
  padding: 14px;
  text-align: center;
}

.rotate-card h2 {
  margin: 0 0 10px;
  font-size: 15px;
  color: var(--line);
}

.rotate-card p {
  margin: 0;
  font-size: 24px;
  line-height: 1;
}

.minigame-overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(4, 14, 20, 0.9);
  padding: 14px;
}

.minigame-overlay.hidden {
  display: none;
}

.minigame-card {
  width: min(520px, 100%);
  border: 2px solid #3f82a3;
  border-radius: 12px;
  background: rgba(7, 27, 40, 0.97);
  padding: 14px;
}

.minigame-card h2 {
  margin: 0 0 8px;
  color: var(--line);
  font-size: 15px;
}

.minigame-card p {
  margin: 0 0 10px;
  font-size: 24px;
  line-height: 1;
}

.minigame-meter {
  position: relative;
  width: 100%;
  height: 22px;
  border: 2px solid #4f89ab;
  border-radius: 99px;
  background: #0a1e2b;
  overflow: hidden;
}

#minigame-zone {
  position: absolute;
  top: 0;
  height: 100%;
  background: rgba(107, 233, 163, 0.65);
}

#minigame-cursor {
  position: absolute;
  top: 0;
  width: 8px;
  height: 100%;
  background: #ffe5a3;
}

.minigame-stats {
  margin-top: 8px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 22px;
}

.mini-action {
  margin-top: 10px;
  width: 100%;
  height: 74px;
  border-radius: 12px;
  border: 2px solid #91ffd4;
  background: #1b6f53;
  color: #f1fff8;
  font-family: "Press Start 2P", monospace;
  font-size: 14px;
  touch-action: manipulation;
}

.mini-row {
  margin-top: 8px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.mini-btn {
  height: 42px;
  border-radius: 8px;
  border: 2px solid #4f89ab;
  background: #103a52;
  color: #def3ff;
  font-family: "Press Start 2P", monospace;
  font-size: 10px;
  touch-action: manipulation;
}

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

  .side-panel {
    order: 2;
    max-height: none;
  }
}

@media (pointer: coarse), (max-width: 900px) {
  html,
  body {
    height: 100%;
    overscroll-behavior: none;
  }

  body {
    --mobile-controls-height: clamp(72px, 14svh, 100px);
    padding: 0;
    min-height: 100dvh;
    height: 100dvh;
    overflow: hidden;
  }

  .layout {
    grid-template-columns: 1fr;
    gap: 0;
    max-width: none;
    margin: 0;
    min-height: 100dvh;
    height: 100dvh;
  }

  .side-panel {
    display: none;
  }

  .game-column {
    gap: 0;
    width: 100%;
    min-height: 100dvh;
    height: 100dvh;
  }

  #game-container {
    width: 100%;
    min-height: 100dvh;
    height: 100dvh;
    border-width: 0;
    border-radius: 0;
    aspect-ratio: auto;
    box-shadow: none;
  }

  #top-hud {
    top: calc(env(safe-area-inset-top) + 6px);
    min-width: 128px;
    font-size: 13px;
    padding: 6px 8px;
  }

  #left-hud {
    top: calc(env(safe-area-inset-top) + 6px);
    left: 6px;
    font-size: 13px;
    min-width: 118px;
    padding: 6px 8px;
  }

  #left-hud div:nth-child(4),
  #left-hud div:nth-child(5),
  #left-hud div:nth-child(6),
  #left-hud div:nth-child(7),
  #left-hud div:nth-child(8) {
    display: none;
  }

  #right-hud {
    display: none;
  }

  #mobile-mission {
    display: block;
    bottom: calc(var(--mobile-controls-height) + env(safe-area-inset-bottom) + 6px);
    font-size: 10px;
    min-width: 160px;
    padding: 5px 8px;
  }

  #dialog-box {
    width: calc(100% - 12px);
    bottom: calc(var(--mobile-controls-height) + env(safe-area-inset-bottom) + 2px);
    border-width: 2px;
  }

  #dialog-speaker {
    font-size: 8px;
    padding: 7px 10px 2px;
  }

  #dialog-text {
    font-size: 14px;
    padding: 5px 10px 8px;
  }

  .dialog-choices {
    padding: 0 8px 8px;
    gap: 4px;
  }

  .dialog-choice-btn {
    font-size: 7px;
    padding: 6px 8px;
  }

  #interaction-prompt {
    bottom: calc(var(--mobile-controls-height) + env(safe-area-inset-bottom) + 40px);
    font-size: 9px;
    padding: 5px 10px 6px;
  }

  #toast {
    right: 8px;
    bottom: calc(var(--mobile-controls-height) + env(safe-area-inset-bottom) + 10px);
    font-size: 13px;
    max-width: 180px;
    padding: 6px 8px;
  }

  #mobile-controls {
    display: flex;
    min-height: var(--mobile-controls-height);
    padding: 4px max(8px, env(safe-area-inset-right)) calc(6px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
    background: linear-gradient(180deg, rgba(6, 20, 30, 0) 0%, rgba(6, 20, 30, 0.6) 42%, rgba(6, 20, 30, 0.9) 100%);
    backdrop-filter: blur(2px);
  }

  #joystick-zone {
    width: clamp(96px, 17vmin, 132px);
    height: clamp(96px, 17vmin, 132px);
  }

  #joystick-base {
    width: clamp(80px, 14vmin, 108px);
    height: clamp(80px, 14vmin, 108px);
  }

  #joystick-knob {
    width: clamp(36px, 6.5vmin, 46px);
    height: clamp(36px, 6.5vmin, 46px);
  }

  .act-btn {
    width: clamp(56px, 9vmin, 72px);
    height: clamp(56px, 9vmin, 72px);
    font-size: clamp(9px, 1.6vmin, 10px);
  }

  .profile-card {
    padding: 12px;
  }

  .profile-card p,
  .profile-card label,
  .profile-error {
    font-size: 20px;
  }

  .profile-card input {
    font-size: 26px;
  }

  .minigame-card p {
    font-size: 18px;
  }

  .minigame-stats {
    font-size: 16px;
  }

  .mini-action {
    height: 58px;
    font-size: 12px;
  }

  .mini-btn {
    font-size: 9px;
    height: 38px;
  }
}

@media (pointer: coarse) and (max-height: 500px), (max-width: 900px) and (max-height: 500px) {
  body {
    --mobile-controls-height: clamp(62px, 16svh, 76px);
  }

  #top-hud {
    min-width: 112px;
    font-size: 11px;
    padding: 5px 6px;
  }

  #ui-time {
    font-size: 11px;
    margin: 3px 0;
  }

  #left-hud {
    min-width: 106px;
    font-size: 11px;
    padding: 5px 6px;
  }

  #dialog-text {
    font-size: 12px;
    line-height: 1.08;
  }
}

/* JS-driven mobile mode: reliable fallback for touch devices */
html.mobile-game-mode {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body.mobile-game-mode {
  --mobile-controls-height: clamp(72px, 14svh, 100px);
  padding: 0 !important;
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

body.mobile-game-mode .layout {
  grid-template-columns: 1fr !important;
  gap: 0 !important;
  max-width: none;
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  height: 100vh;
  height: 100dvh;
}

body.mobile-game-mode .side-panel {
  display: none !important;
}

body.mobile-game-mode .game-column {
  gap: 0 !important;
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  height: 100vh;
  height: 100dvh;
}

body.mobile-game-mode #game-container {
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  height: 100vh;
  height: 100dvh;
  border-width: 0;
  border-radius: 0;
  aspect-ratio: auto;
  box-shadow: none;
}

body.mobile-game-mode #right-hud {
  display: none;
}

body.mobile-game-mode #left-hud {
  top: calc(env(safe-area-inset-top) + 6px);
  left: 6px;
  font-size: 13px;
  min-width: 118px;
  padding: 6px 8px;
}

body.mobile-game-mode #left-hud div:nth-child(4),
body.mobile-game-mode #left-hud div:nth-child(5),
body.mobile-game-mode #left-hud div:nth-child(6),
body.mobile-game-mode #left-hud div:nth-child(7),
body.mobile-game-mode #left-hud div:nth-child(8) {
  display: none;
}

body.mobile-game-mode #top-hud {
  top: calc(env(safe-area-inset-top) + 6px);
  min-width: 128px;
  font-size: 13px;
  padding: 6px 8px;
}

body.mobile-game-mode #mobile-mission {
  display: block;
  bottom: calc(var(--mobile-controls-height) + env(safe-area-inset-bottom) + 6px);
}

body.mobile-game-mode #dialog-box {
  width: calc(100% - 12px);
  bottom: calc(var(--mobile-controls-height) + env(safe-area-inset-bottom) + 2px);
  border-width: 2px;
}

body.mobile-game-mode #interaction-prompt {
  bottom: calc(var(--mobile-controls-height) + env(safe-area-inset-bottom) + 40px);
}

body.mobile-game-mode #toast {
  bottom: calc(var(--mobile-controls-height) + env(safe-area-inset-bottom) + 10px);
}

body.mobile-game-mode #mobile-controls {
  display: flex !important;
  min-height: var(--mobile-controls-height);
  padding: 4px max(8px, env(safe-area-inset-right)) calc(6px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
}

body.mobile-game-mode #joystick-zone {
  width: clamp(96px, 17vmin, 132px);
  height: clamp(96px, 17vmin, 132px);
}

body.mobile-game-mode #joystick-base {
  width: clamp(80px, 14vmin, 108px);
  height: clamp(80px, 14vmin, 108px);
}

body.mobile-game-mode #joystick-knob {
  width: clamp(36px, 6.5vmin, 46px);
  height: clamp(36px, 6.5vmin, 46px);
}

body.mobile-game-mode .act-btn {
  width: clamp(56px, 9vmin, 72px);
  height: clamp(56px, 9vmin, 72px);
  font-size: clamp(9px, 1.6vmin, 10px);
}

@media (max-height: 500px) {
  body.mobile-game-mode {
    --mobile-controls-height: clamp(62px, 16svh, 76px);
  }

  body.mobile-game-mode #top-hud {
    min-width: 112px;
    font-size: 11px;
    padding: 5px 6px;
  }

  body.mobile-game-mode #ui-time {
    font-size: 11px;
    margin: 3px 0;
  }

  body.mobile-game-mode #left-hud {
    min-width: 106px;
    font-size: 11px;
    padding: 5px 6px;
  }

  body.mobile-game-mode #dialog-text {
    font-size: 12px;
    line-height: 1.08;
  }
}

/* CSS-only fallback if JS class toggle fails on some mobile browsers */
@media (hover: none), (pointer: coarse) {
  body {
    --mobile-controls-height: clamp(72px, 14svh, 100px);
    overflow: hidden;
  }

  .layout {
    grid-template-columns: 1fr;
    gap: 0;
    max-width: none;
    margin: 0;
    min-height: 100vh;
    min-height: 100dvh;
    height: 100vh;
    height: 100dvh;
  }

  .side-panel {
    display: none;
  }

  .game-column {
    min-height: 100vh;
    min-height: 100dvh;
    height: 100vh;
    height: 100dvh;
  }

  #game-container {
    min-height: 100vh;
    min-height: 100dvh;
    height: 100vh;
    height: 100dvh;
    border-width: 0;
    border-radius: 0;
  }

  #mobile-controls {
    display: flex !important;
  }
}
