/* Blade of the Ruin — 16-Bit Action-Adventure Stylesheet */
*, *::before, *::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --bg-deep: #0b111e;
  --panel: #131c2e;
  --panel-alt: #1b2840;
  --border: rgba(148, 163, 184, 0.24);
  --gold: #fbbf24;
  --emerald: #34d399;
  --cyan: #38bdf8;
  --crimson: #f43f5e;
  --purple: #c084fc;
  --text: #f8fafc;
  --muted: #94a3b8;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  min-height: 100dvh;
  background: radial-gradient(circle at top, #17243c 0%, var(--bg-deep) 68%);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overflow-x: hidden;
  user-select: none;
  -webkit-user-select: none;
}

.hidden {
  display: none !important;
}

.app-shell {
  width: 100%;
  max-width: 920px;
  min-height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding: 8px 10px 6px;
  gap: 7px;
}

/* Top HUD */
.hud-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: rgba(19, 28, 46, 0.94);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 6px 10px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
}

.hud-left, .hud-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.hud-center {
  text-align: center;
  min-width: 0;
  flex: 1;
}

.room-title {
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: #fef3c7;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.room-sub {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hud-hearts {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-wrap: wrap;
  max-width: 150px;
}

.heart-unit {
  width: 16px;
  height: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  line-height: 1;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.65));
}

.heart-empty { opacity: 0.25; filter: grayscale(1); }
.heart-half  { opacity: 0.68; }

.hud-seals {
  display: flex;
  align-items: center;
  gap: 3px;
  background: rgba(9, 14, 26, 0.72);
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 8px;
  padding: 2px 5px;
}

.seal-pip {
  font-size: 13px;
  opacity: 0.22;
  filter: grayscale(1);
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.seal-pip.lit {
  opacity: 1;
  filter: drop-shadow(0 0 6px rgba(251, 191, 36, 0.75));
  transform: scale(1.08);
}

.hud-key-pill, .timer-pill, .score-pill {
  font-size: 12px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  padding: 3px 8px;
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid rgba(148, 163, 184, 0.25);
  white-space: nowrap;
}

.hud-key-pill { color: var(--gold); border-color: rgba(251, 191, 36, 0.45); }
.timer-pill   { color: #bae6fd; }
.score-pill   { color: var(--emerald); }

.icon-btn {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: 1px solid rgba(148, 163, 184, 0.28);
  background: rgba(30, 41, 59, 0.85);
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.14s, border-color 0.14s, transform 0.12s;
}

.icon-btn:hover { background: #334155; border-color: var(--cyan); transform: translateY(-1px); }

/* Stage & Canvas */
.stage-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 0;
  width: 100%;
}

.canvas-frame {
  position: relative;
  width: 100%;
  max-width: 800px;
  aspect-ratio: 640 / 440;
  background: #0c1220;
  border: 2px solid rgba(251, 191, 36, 0.32);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.55), inset 0 0 0 1px rgba(255,255,255,0.06);
}

#game-canvas {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: none;
}

.minimap {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 84px;
  height: 84px;
  border-radius: 8px;
  border: 1px solid rgba(251, 191, 36, 0.42);
  background: rgba(9, 14, 24, 0.78);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.48);
  pointer-events: none;
  image-rendering: pixelated;
}

.toast-banner {
  position: absolute;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  max-width: calc(100% - 24px);
  padding: 6px 13px;
  border-radius: 999px;
  background: rgba(9, 14, 26, 0.92);
  border: 1px solid rgba(251, 191, 36, 0.6);
  color: #fef3c7;
  font-size: 12px;
  font-weight: 700;
  text-align: center;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.55);
  pointer-events: none;
  z-index: 10;
}

.boss-hud {
  position: absolute;
  left: 50%;
  top: 10px;
  transform: translateX(-50%);
  width: min(360px, calc(100% - 116px));
  background: rgba(11, 17, 30, 0.9);
  border: 1px solid rgba(244, 63, 94, 0.55);
  border-radius: 10px;
  padding: 5px 10px;
  pointer-events: none;
  z-index: 9;
}

.boss-hud-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 4px;
}

.boss-name { font-size: 12px; font-weight: 900; color: #fda4af; letter-spacing: 0.05em; }
.boss-sub  { font-size: 10px; color: #cbd5e1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.boss-bar-track {
  height: 8px;
  background: rgba(30, 41, 59, 0.9);
  border-radius: 999px;
  overflow: hidden;
}

.boss-bar-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #f43f5e, #fb923c, #fbbf24);
  transition: width 0.12s ease;
}

/* Relic Belt */
.relic-belt {
  width: 100%;
  max-width: 800px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px 10px;
  background: rgba(19, 28, 46, 0.9);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 6px 10px;
}

.relic-slots {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: nowrap;
  flex-shrink: 0;
}

.relic-slot {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 8px 4px 6px;
  border-radius: 9px;
  border: 1px solid rgba(148, 163, 184, 0.25);
  background: rgba(15, 23, 42, 0.78);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  opacity: 0.48;
  transition: transform 0.12s, border-color 0.14s, background 0.14s, opacity 0.14s;
  white-space: nowrap;
}

.relic-slot.unlocked {
  opacity: 1;
  color: var(--text);
  border-color: rgba(56, 189, 248, 0.42);
}

.relic-slot.active {
  background: rgba(16, 185, 129, 0.22);
  border-color: var(--emerald);
  box-shadow: 0 0 12px rgba(52, 211, 153, 0.35);
  color: #ecfdf5;
}

.passive-slot { cursor: default; }
.passive-slot.unlocked { border-color: rgba(56, 189, 248, 0.7); background: rgba(56, 189, 248, 0.15); }

.slot-key {
  font-size: 10px;
  font-weight: 900;
  width: 16px;
  height: 16px;
  border-radius: 5px;
  background: rgba(30, 41, 59, 0.95);
  color: var(--gold);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.slot-icon {
  width: 24px;
  height: 24px;
  image-rendering: pixelated;
  flex-shrink: 0;
}

.controls-hint {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--muted);
  flex-wrap: wrap;
  justify-content: flex-end;
}

.controls-hint kbd {
  background: rgba(30, 41, 59, 0.95);
  border: 1px solid rgba(148, 163, 184, 0.3);
  border-radius: 4px;
  padding: 1px 4px;
  color: #e2e8f0;
  font-family: inherit;
  font-size: 10px;
  font-weight: 700;
}

/* Mobile Touch Pad */
.touch-pad {
  display: none;
  width: 100%;
  max-width: 800px;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px 10px;
  gap: 10px;
}

.dpad-zone {
  width: 124px;
  height: 124px;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
}

.dpad-ring {
  width: 114px;
  height: 114px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(30, 41, 59, 0.72), rgba(15, 23, 42, 0.9));
  border: 2px solid rgba(148, 163, 184, 0.34);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.dpad-nub {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #6ee7b7, #059669);
  border: 2px solid #ecfdf5;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.45);
  transition: transform 0.05s linear;
}

.action-pad {
  display: grid;
  grid-template-columns: repeat(2, 68px);
  gap: 8px;
}

.touch-btn {
  height: 54px;
  border-radius: 14px;
  border: 2px solid rgba(255, 255, 255, 0.25);
  font-size: 11.5px;
  font-weight: 900;
  letter-spacing: 0.04em;
  color: #ffffff;
  cursor: pointer;
  touch-action: none;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.touch-btn:active, .touch-btn.pressed { transform: scale(0.94); filter: brightness(1.18); }
.touch-sword  { background: linear-gradient(135deg, #10b981, #047857); border-color: #6ee7b7; }
.touch-relic  { background: linear-gradient(135deg, #f59e0b, #b45309); border-color: #fde68a; }
.touch-shield { background: linear-gradient(135deg, #0284c7, #1d4ed8); border-color: #7dd3fc; }
.touch-dash   { background: linear-gradient(135deg, #9333ea, #6b21a8); border-color: #d8b4fe; }

/* Footer Bar (dock for studio-bar.js) */
.footer-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px 10px;
  padding: 6px 10px;
  border-radius: 10px;
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid rgba(148, 163, 184, 0.2);
  font-size: 11.5px;
  color: var(--muted);
}

.footer-brand { font-weight: 700; color: #cbd5e1; }
.footer-streak { color: var(--gold); font-weight: 700; }

/* Fixed Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 9000;
  background: rgba(5, 9, 18, 0.78);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  overflow-y: auto;
}

.overlay-card, .lb-card {
  width: 100%;
  max-width: 470px;
  max-height: min(92dvh, 720px);
  overflow-y: auto;
  background: linear-gradient(180deg, #152138 0%, #0e1627 100%);
  border: 1px solid rgba(251, 191, 36, 0.38);
  border-radius: 16px;
  padding: 18px 18px 14px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.65);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.badge-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.pill {
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.06em;
  padding: 3px 9px;
  border-radius: 999px;
}

.pill-emerald { background: rgba(16, 185, 129, 0.18); color: #6ee7b7; border: 1px solid rgba(52, 211, 153, 0.45); }
.pill-gold    { background: rgba(245, 158, 11, 0.18); color: #fde68a; border: 1px solid rgba(251, 191, 36, 0.45); }

.ov-title {
  margin: 0;
  font-size: 26px;
  font-weight: 900;
  letter-spacing: 0.04em;
  background: linear-gradient(90deg, #fef08a, #34d399, #38bdf8);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  line-height: 1.15;
}

.ov-subtitle {
  margin: 0;
  font-size: 13px;
  line-height: 1.45;
  color: #cbd5e1;
}

.challenge-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(192, 132, 252, 0.16);
  border: 1px solid rgba(192, 132, 252, 0.5);
  color: #f3e8ff;
  font-size: 12.5px;
  font-weight: 700;
}

.ov-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.stat-box {
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid rgba(148, 163, 184, 0.22);
  border-radius: 10px;
  padding: 7px 6px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat-k { font-size: 9.5px; font-weight: 800; color: var(--muted); letter-spacing: 0.06em; }
.stat-v { font-size: 15px; font-weight: 900; color: #fef3c7; font-variant-numeric: tabular-nums; }

.cliffhanger-box {
  background: rgba(16, 185, 129, 0.12);
  border: 1px solid rgba(52, 211, 153, 0.35);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.35;
  color: #d1fae5;
}

.cliff-label {
  font-weight: 900;
  color: var(--gold);
  margin-right: 4px;
}

.lb-submit-row {
  display: flex;
  gap: 6px;
}

.lb-submit-row input {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  border-radius: 9px;
  border: 1px solid rgba(148, 163, 184, 0.35);
  background: rgba(15, 23, 42, 0.9);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
}

.lb-submit-msg {
  font-size: 12px;
  color: #6ee7b7;
  font-weight: 700;
  text-align: center;
}

.btn-stack {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.btn-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}

.btn {
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13.5px;
  font-weight: 800;
  cursor: pointer;
  color: #fff;
  transition: transform 0.12s, filter 0.14s, opacity 0.14s;
}

.btn:hover:not(:disabled) { transform: translateY(-1px); filter: brightness(1.08); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary { background: linear-gradient(135deg, #10b981, #059669); border-color: #6ee7b7; font-size: 15px; }
.btn-daily   { background: linear-gradient(135deg, #0284c7, #2563eb); border-color: #7dd3fc; }
.btn-rush    { background: linear-gradient(135deg, #9333ea, #c026d3); border-color: #e9d5ff; }
.btn-gold    { background: linear-gradient(135deg, #f59e0b, #d97706); border-color: #fde68a; }
.btn-share   { background: linear-gradient(135deg, #0ea5e9, #0d9488); border-color: #99f6e4; }
.btn-ghost   { background: rgba(30, 41, 59, 0.85); border-color: rgba(148, 163, 184, 0.35); color: #cbd5e1; }

.share-preview {
  margin: 0;
  padding: 8px 10px;
  border-radius: 9px;
  background: rgba(9, 14, 26, 0.9);
  border: 1px solid rgba(56, 189, 248, 0.35);
  color: #e0f2fe;
  font-size: 11px;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Leaderboard Modal */
.lb-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.lb-title { margin: 0; font-size: 17px; font-weight: 900; color: #fef3c7; }
.lb-sub   { font-size: 12px; color: var(--muted); }

.lb-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
  max-height: 280px;
  overflow-y: auto;
}

.lb-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 10px;
  border-radius: 9px;
  background: rgba(30, 41, 59, 0.65);
  border: 1px solid rgba(148, 163, 184, 0.16);
  font-size: 13px;
}

.lb-rank  { font-weight: 900; color: var(--gold); width: 28px; }
.lb-name  { flex: 1; font-weight: 700; color: #f8fafc; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-score { font-weight: 900; color: var(--emerald); font-variant-numeric: tabular-nums; }
.lb-empty { text-align: center; padding: 20px 10px; font-size: 13px; color: var(--muted); }
.lb-foot  { display: flex; justify-content: flex-end; }
.lb-foot .btn { width: 100%; }

/* Mobile & Touch Responsive Layout (390x844 zero horizontal overflow) */
@media (max-width: 760px), (pointer: coarse) {
  .controls-hint { display: none; }
  .touch-pad { display: flex; }
}

@media (max-width: 560px) {
  .app-shell {
    padding: 5px 6px 6px;
    gap: 5px;
  }

  .hud-top {
    padding: 5px 7px;
    gap: 5px;
    flex-wrap: wrap;
  }

  .hud-center {
    order: 3;
    flex-basis: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    text-align: left;
    border-top: 1px solid rgba(148, 163, 184, 0.15);
    padding-top: 4px;
  }

  .room-title { font-size: 12.5px; }
  .room-sub   { font-size: 10.5px; }
  .hud-hearts { max-width: 118px; }
  .heart-unit { width: 13px; height: 13px; font-size: 12px; }
  .seal-pip   { font-size: 11.5px; }
  .timer-pill, .score-pill { font-size: 11px; padding: 2px 6px; }
  .icon-btn { width: 27px; height: 27px; font-size: 13px; }

  .minimap { width: 64px; height: 64px; top: 5px; right: 5px; }
  .boss-hud { width: calc(100% - 82px); left: 8px; transform: none; top: 6px; }

  .relic-belt { padding: 4px 6px; }
  .relic-slot { padding: 4px 6px; gap: 4px; font-size: 10.5px; }
  .slot-label { display: none; }
  .slot-icon  { width: 22px; height: 22px; }

  .dpad-zone { width: 112px; height: 112px; }
  .dpad-ring { width: 102px; height: 102px; }
  .dpad-nub  { width: 42px; height: 42px; }
  .action-pad { grid-template-columns: repeat(2, 64px); gap: 6px; }
  .touch-btn { height: 48px; font-size: 10.5px; }

  .footer-bar { font-size: 10.5px; padding: 5px 8px; }
  .ov-title { font-size: 22px; }
}
