:root {
  --bg-deep: #090b10;
  --bg-panel: rgba(18, 22, 31, 0.88);
  --bg-card: rgba(24, 29, 41, 0.86);
  --bg-card-hover: rgba(32, 39, 55, 0.95);
  --gold: #d8ad58;
  --gold-bright: #f2cc7e;
  --gold-dim: rgba(216, 173, 88, 0.28);
  --crimson: #b93a2c;
  --text-main: #f1ece1;
  --text-muted: #9ca3b5;
  --border-subtle: rgba(216, 173, 88, 0.22);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

*, *::before, *::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg-deep);
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  user-select: none;
  -webkit-user-select: none;
}

/* ==================== 4-IN-1 LAUNCHER ==================== */
#launcher {
  position: fixed;
  inset: 0;
  z-index: 20;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  background:
    radial-gradient(ellipse 80% 50% at 50% -10%, rgba(216, 173, 88, 0.16), transparent 65%),
    radial-gradient(ellipse 60% 50% at 85% 100%, rgba(185, 58, 44, 0.14), transparent 60%),
    linear-gradient(180deg, #0b0e15 0%, #111622 50%, #090b10 100%);
  padding: calc(20px + var(--safe-top)) calc(20px + var(--safe-right)) calc(28px + var(--safe-bottom)) calc(20px + var(--safe-left));
  display: flex;
  flex-direction: column;
  align-items: center;
}

#launcher.hidden {
  display: none;
}

.launcher-inner {
  width: 100%;
  max-width: 1080px;
  margin: auto 0;
}

.hero-header {
  text-align: center;
  margin-bottom: 24px;
}

.hero-seal {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 14px;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  background: rgba(216, 173, 88, 0.08);
  color: var(--gold);
  font-size: 12px;
  letter-spacing: 0.12em;
  margin-bottom: 12px;
}

.hero-title {
  margin: 0;
  font-family: "Noto Serif SC", "Songti SC", "STSong", "SimSun", serif;
  font-size: clamp(28px, 5vw, 44px);
  font-weight: 700;
  letter-spacing: 0.12em;
  background: linear-gradient(180deg, #fff6e0 0%, #d8ad58 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 8px 28px rgba(216, 173, 88, 0.18);
}

.hero-subtitle {
  margin: 8px auto 0;
  max-width: 640px;
  color: var(--text-muted);
  font-size: clamp(13px, 2vw, 15px);
  line-height: 1.6;
}

/* Cards Grid */
.games-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

@media (max-width: 720px) {
  .games-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }
}

.game-card {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 14px;
  backdrop-filter: blur(12px);
  transition: transform 0.2s ease, border-color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
}

.game-card:hover {
  transform: translateY(-2px);
  background: var(--bg-card-hover);
  border-color: rgba(216, 173, 88, 0.55);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.42);
}

.card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.card-title {
  margin: 0;
  font-family: "Noto Serif SC", "Songti SC", "STSong", serif;
  font-size: 21px;
  font-weight: 700;
  color: #fbf5e8;
  letter-spacing: 0.04em;
}

.card-badge {
  flex-shrink: 0;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: rgba(216, 173, 88, 0.14);
  color: var(--gold-bright);
  border: 1px solid rgba(216, 173, 88, 0.32);
}

.card-badge.hd {
  background: rgba(185, 58, 44, 0.22);
  color: #ff9c8f;
  border-color: rgba(225, 92, 77, 0.45);
}

.card-desc {
  margin: 6px 0 0;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.55;
}

.card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
}

.meta-pill {
  padding: 3px 9px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.045);
  border: 1px solid rgba(255, 255, 255, 0.07);
  font-variant-numeric: tabular-nums;
}

.meta-pill.cached {
  color: #7ee2a8;
  border-color: rgba(126, 226, 168, 0.3);
  background: rgba(126, 226, 168, 0.08);
}

.card-actions {
  display: flex;
  gap: 10px;
}

.btn-primary {
  flex: 1;
  appearance: none;
  border: 1px solid rgba(242, 204, 126, 0.55);
  background: linear-gradient(135deg, #c9963b 0%, #9f6d1d 100%);
  color: #fffaf0;
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0.06em;
  padding: 11px 16px;
  border-radius: 10px;
  cursor: pointer;
  transition: filter 0.15s ease, transform 0.1s ease;
}

.btn-primary:hover {
  filter: brightness(1.1);
}

.btn-primary:active {
  transform: scale(0.98);
}

.btn-secondary {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-main);
  font-size: 13px;
  padding: 11px 14px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--gold-dim);
}

.launcher-footer {
  margin-top: 20px;
  padding: 12px 16px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--text-muted);
}

.kbd-hint kbd {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.09);
  border: 1px solid rgba(255, 255, 255, 0.16);
  color: var(--text-main);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
}

/* ==================== GAME STAGE & CANVAS ==================== */
#stage {
  position: fixed;
  inset: 0;
  z-index: 1;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
}

#canvas {
  display: block;
  width: 100vw;
  height: 100dvh;
  outline: none;
  touch-action: none;
}

/* ==================== BOOT LOADING OVERLAY ==================== */
#boot-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(9, 11, 16, 0.94);
  backdrop-filter: blur(14px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

#boot-overlay.hidden {
  display: none;
}

.boot-box {
  width: 100%;
  max-width: 420px;
  text-align: center;
}

.boot-title {
  font-family: "Noto Serif SC", "Songti SC", serif;
  font-size: 22px;
  color: var(--gold-bright);
  margin: 0 0 8px;
}

.boot-step {
  font-size: 13px;
  color: var(--text-muted);
  margin: 0 0 16px;
  min-height: 20px;
}

.progress-track {
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
  border: 1px solid rgba(216, 173, 88, 0.22);
}

.progress-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, #b88428, #f2cc7e);
  transition: width 0.18s ease;
}

/* ==================== IN-GAME FLOATING HUD ==================== */
#hud {
  position: fixed;
  top: calc(10px + var(--safe-top));
  right: calc(10px + var(--safe-right));
  z-index: 15;
  display: flex;
  align-items: center;
  gap: 6px;
}

#hud.hidden {
  display: none;
}

.hud-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 6px;
  border-radius: 999px;
  background: rgba(12, 15, 22, 0.72);
  border: 1px solid rgba(216, 173, 88, 0.28);
  backdrop-filter: blur(8px);
}

.hud-bar.collapsed .hud-item {
  display: none;
}

.hud-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text-main);
  font-size: 12px;
  padding: 5px 9px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s ease, color 0.15s ease;
}

.hud-btn:hover, .hud-btn.active {
  background: rgba(216, 173, 88, 0.2);
  color: var(--gold-bright);
}

/* Subtle Lazy Asset Spinner Badge */
#net-badge {
  position: fixed;
  bottom: calc(10px + var(--safe-bottom));
  left: calc(12px + var(--safe-left));
  z-index: 16;
  padding: 5px 12px;
  border-radius: 999px;
  background: rgba(12, 15, 22, 0.82);
  border: 1px solid var(--border-subtle);
  color: var(--gold-bright);
  font-size: 12px;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

#net-badge.hidden {
  opacity: 0;
  pointer-events: none;
}

/* Portrait Orientation Tip on Mobile */
#portrait-tip {
  position: fixed;
  bottom: calc(14px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 17;
  padding: 7px 14px;
  border-radius: 999px;
  background: rgba(18, 22, 31, 0.9);
  border: 1px solid var(--border-subtle);
  color: var(--gold-bright);
  font-size: 12px;
  white-space: nowrap;
  display: none;
  align-items: center;
  gap: 8px;
}

@media (orientation: portrait) and (max-width: 768px) {
  body.in-game #portrait-tip:not(.dismissed) {
    display: inline-flex;
  }
}

/* ==================== MODALS (TEXT INPUT, VOLUME, SAVES) ==================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(6, 8, 12, 0.78);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-backdrop.hidden {
  display: none;
}

.modal-card {
  width: 100%;
  max-width: 460px;
  background: #151a26;
  border: 1px solid rgba(216, 173, 88, 0.4);
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.65);
  max-height: 86dvh;
  overflow-y: auto;
}

.modal-title {
  margin: 0 0 12px;
  font-family: "Noto Serif SC", "Songti SC", serif;
  font-size: 19px;
  color: var(--gold-bright);
}

.wuxia-input-row {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.wuxia-input {
  flex: 1;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(216, 173, 88, 0.38);
  background: rgba(0, 0, 0, 0.35);
  color: #fff;
  font-size: 16px;
  outline: none;
}

.wuxia-input:focus {
  border-color: var(--gold-bright);
}

.save-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 12px 0;
}

.save-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.07);
  font-size: 13px;
}

.slider-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 12px 0;
  font-size: 13px;
}

.slider-row input[type="range"] {
  flex: 1;
  accent-color: var(--gold);
}

#toast {
  position: fixed;
  top: calc(54px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  padding: 7px 16px;
  border-radius: 999px;
  background: rgba(20, 26, 38, 0.92);
  border: 1px solid rgba(126, 226, 168, 0.4);
  color: #9bf0be;
  font-size: 12px;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

#toast.hidden {
  opacity: 0;
}
