:root {
  --bg: #0b0d12;
  --panel: rgba(13, 17, 26, 0.88);
  --gold: #d97706;
  --gold-bright: #facc15;
  --text: #f3f4f6;
  --muted: #9ca3af;
}

* { box-sizing: border-box; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0; width: 100%; height: 100%;
  background: var(--bg); color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  display: grid; place-items: center; overflow: hidden;
  overscroll-behavior: none;
}

#game-shell {
  position: relative;
  width: min(1280px, 100vw);
  aspect-ratio: 16 / 9;
  background: #07090d;
  border: 2px solid var(--gold);
  box-shadow: 0 0 42px rgba(217, 119, 6, 0.22);
  overflow: hidden;
  touch-action: none;
}

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

.hud-panel {
  background: var(--panel); border: 1.5px solid rgba(217, 119, 6, 0.72);
  border-radius: 6px; padding: 7px 9px; backdrop-filter: blur(4px);
}

#hud-top-left { position: absolute; top: 8px; left: 8px; min-width: 220px; z-index: 10; }
#hud-top-center {
  position: absolute; top: 8px; left: 50%; transform: translateX(-50%);
  text-align: center; min-width: 340px; max-width: 500px; z-index: 10;
}
#hud-top-right { position: absolute; top: 8px; right: 8px; display: flex; flex-direction: column; gap: 5px; align-items: flex-end; z-index: 10; }

.hud-row { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin-bottom: 5px; }
.hearts-row { display: flex; flex-wrap: wrap; gap: 2px; max-width: 170px; }
.heart-svg { width: 16px; height: 16px; }
.mono-dim { font-family: monospace; font-size: 11px; color: var(--muted); }

.bar-wrap { position: relative; height: 14px; background: #1e293b; border-radius: 3px; border: 1px solid rgba(56, 189, 248, 0.5); overflow: hidden; }
.dharma-fill { height: 100%; width: 100%; background: linear-gradient(90deg, #0284c7, #38bdf8); transition: width 0.08s; }
.bar-label { position: absolute; inset: 0; font-family: monospace; font-size: 10px; display: flex; align-items: center; justify-content: center; text-shadow: 0 1px 2px #000; }

.hud-meta-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 5px; font-family: monospace; font-size: 11px; align-items: center; }
.punya-tag { color: var(--gold-bright); font-weight: 700; }
.items-tag { color: #cbd5e1; font-size: 10px; }
.flow-tag { background: #7c2d12; border: 1px solid #f59e0b; color: #fef08a; padding: 0 5px; border-radius: 4px; font-weight: 700; }

.region-title { font-size: 13px; font-weight: 700; color: var(--gold-bright); letter-spacing: 0.3px; }
.quest-hint { font-size: 11px; color: #e5e7eb; margin-top: 2px; }

.boss-bar { margin-top: 5px; }
.boss-name { font-size: 11px; font-weight: 700; color: #fda4af; margin-bottom: 2px; text-transform: uppercase; }
.boss-track { height: 9px; background: #27121a; border: 1px solid #f43f5e; border-radius: 3px; overflow: hidden; }
.boss-fill { height: 100%; background: linear-gradient(90deg, #be123c, #f43f5e); transition: width 0.08s; }

.minimap-box { padding: 4px; display: flex; flex-direction: column; align-items: center; }
#minimap-canvas { border: 1px solid rgba(250, 204, 21, 0.45); image-rendering: pixelated; }
.debug-line { font-family: monospace; font-size: 10px; color: #38bdf8; margin-top: 3px; }

.quick-btns { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; max-width: 210px; }
.hud-btn, .pill-btn {
  background: rgba(17, 24, 39, 0.92); color: #fef3c7; border: 1px solid var(--gold);
  border-radius: 4px; padding: 4px 7px; font-size: 11px; font-family: monospace; cursor: pointer;
}
.hud-btn:hover, .pill-btn:hover, .pill-btn.active { background: var(--gold); color: #0b0d12; font-weight: 700; }

.toast-banner {
  position: absolute; top: 92px; left: 50%; transform: translateX(-50%) translateY(-8px);
  background: rgba(15, 23, 42, 0.95); border: 1.5px solid var(--gold-bright);
  color: #fef08a; padding: 6px 14px; border-radius: 6px; font-size: 12px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; z-index: 25; text-align: center; max-width: 90%;
}
.toast-banner.visible { opacity: 1; transform: translateX(-50%) translateY(0); }

#hud-bottom {
  position: absolute; bottom: 8px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 5px; width: 96%; pointer-events: none; z-index: 12;
}
.astra-bar { display: flex; gap: 5px; pointer-events: auto; }
.astra-slot {
  position: relative; width: 54px; height: 54px; padding: 2px;
  background: rgba(11, 13, 18, 0.9); border: 1.5px solid #475569; border-radius: 6px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; cursor: pointer;
}
.astra-slot.active { border-color: var(--gold-bright); box-shadow: 0 0 12px rgba(250, 204, 21, 0.5); }
.astra-slot img { width: 30px; height: 30px; image-rendering: pixelated; }
.slot-key { position: absolute; top: 2px; left: 4px; font-family: monospace; font-size: 9px; color: var(--gold-bright); }
.slot-name { font-family: monospace; font-size: 8px; color: #e2e8f0; }

.controls-strip {
  display: flex; gap: 10px; flex-wrap: wrap; justify-content: center;
  background: rgba(11, 13, 18, 0.82); border: 1px solid rgba(217, 119, 6, 0.45);
  border-radius: 4px; padding: 3px 9px; font-size: 11px; color: #cbd5e1;
}
.controls-strip b { color: var(--gold-bright); font-family: monospace; }

/* Touch Controls Overlay (Hidden on Desktop until Touch Mode active) */
.touch-controls { display: none; position: absolute; inset: 0; pointer-events: none; z-index: 18; }
#game-shell.touch-active .touch-controls { display: block; }
#game-shell.touch-active .controls-strip { display: none; }

.touch-joy {
  position: absolute; bottom: max(18px, env(safe-area-inset-bottom)); left: max(16px, env(safe-area-inset-left));
  width: 118px; height: 118px; border-radius: 50%;
  background: rgba(15, 23, 42, 0.48); border: 2px solid rgba(250, 204, 21, 0.55);
  display: grid; place-items: center; pointer-events: auto; touch-action: none;
}
.touch-knob {
  width: 46px; height: 46px; border-radius: 50%;
  background: radial-gradient(circle, #fde047, #d97706); border: 2px solid #fff; opacity: 0.88;
}

.touch-actions {
  position: absolute; bottom: max(14px, env(safe-area-inset-bottom)); right: max(14px, env(safe-area-inset-right));
  width: 210px; height: 196px; pointer-events: none;
}
.t-bow {
  position: absolute; right: 6px; bottom: 8px; width: 84px; height: 84px; border-radius: 50%;
  background: rgba(217, 119, 6, 0.42); border: 2.5px solid #facc15; color: #fef08a;
  display: grid; place-items: center; text-align: center; font-family: monospace; font-size: 11px; font-weight: 800;
  pointer-events: auto; touch-action: none;
}
.t-bow.perfect-glow { background: rgba(250, 204, 21, 0.85); color: #0b0d12; box-shadow: 0 0 24px #facc15; transform: scale(1.06); }

.t-btn {
  position: absolute; min-width: 52px; height: 44px; border-radius: 22px; padding: 0 8px;
  background: rgba(15, 23, 42, 0.72); border: 1.5px solid rgba(250, 204, 21, 0.7);
  color: #fef3c7; font-family: monospace; font-size: 10px; font-weight: 700;
  pointer-events: auto; touch-action: none;
}
.t-btn:active { background: var(--gold); color: #0b0d12; }
.t-sweep { right: 100px; bottom: 8px; }
.t-dash { right: 104px; bottom: 60px; }
.t-astra { right: 54px; bottom: 102px; border-color: #38bdf8; color: #bae6fd; }
.t-act { right: 4px; bottom: 102px; }
.t-act.ready { background: #d97706; color: #0b0d12; box-shadow: 0 0 14px #facc15; }
.t-heal { right: 106px; bottom: 112px; border-color: #fb7185; color: #fecdd3; }
.t-lock { right: 4px; bottom: 150px; border-color: #facc15; color: #fef08a; }
.t-lock.ready { background: #facc15; color: #0b0d12; box-shadow: 0 0 14px #facc15; }
.t-cycle { right: 158px; bottom: 60px; min-width: 44px; font-size: 9px; }

.dialogue-box {
  position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%);
  width: 86%; max-width: 940px; display: flex; gap: 14px; align-items: center;
  background: rgba(10, 12, 18, 0.96); border: 2px solid var(--gold-bright);
  border-radius: 8px; padding: 12px; z-index: 35; cursor: pointer;
}
.dlg-portrait { width: 96px; height: 96px; border: 2px solid var(--gold); border-radius: 6px; image-rendering: pixelated; flex-shrink: 0; }
.dlg-content { flex: 1; }
.dlg-speaker { font-size: 14px; font-weight: 700; color: var(--gold-bright); margin-bottom: 4px; }
.dlg-text { font-size: 13px; line-height: 1.45; color: #f8fafc; }
.dlg-hint { margin-top: 6px; font-family: monospace; font-size: 11px; color: var(--muted); }
.dlg-choices { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.btn-dilemma { text-align: left; background: #1e293b; color: #fef08a; border: 1px solid var(--gold); border-radius: 5px; padding: 8px 10px; font-size: 12px; cursor: pointer; }
.btn-dilemma:hover { background: var(--gold); color: #0b0d12; font-weight: 700; }

.modal-backdrop { position: absolute; inset: 0; background: rgba(5, 7, 12, 0.8); display: grid; place-items: center; z-index: 45; padding: 10px; }
.modal-card { width: min(840px, 100%); max-height: 90%; overflow-y: auto; background: #10141f; border: 2px solid var(--gold); border-radius: 8px; padding: 14px; -webkit-overflow-scrolling: touch; }
.modal-header { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 10px; }
.modal-header h2 { margin: 0; font-size: 15px; color: var(--gold-bright); }
.modal-section { margin-bottom: 12px; }
.modal-section h3 { margin: 0 0 6px; font-size: 12px; color: #fbbf24; text-transform: uppercase; letter-spacing: 0.5px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.pill-row { display: flex; flex-wrap: wrap; gap: 6px; }
.muted-note { color: var(--muted); font-size: 12px; margin: 4px 0; }

.card-btn {
  display: flex; flex-direction: column; gap: 3px; text-align: left; min-height: 44px;
  background: #171e2e; color: #f1f5f9; border: 1.5px solid #334155; border-radius: 6px; padding: 9px; cursor: pointer;
}
.card-btn:hover, .card-btn.selected { border-color: var(--gold-bright); background: #1e2638; }
.card-btn small { color: var(--muted); font-size: 11px; line-height: 1.3; }
.relic-head { display: flex; align-items: center; gap: 6px; }
.relic-head img { width: 24px; height: 24px; image-rendering: pixelated; }
.rarity-rare { border-color: #38bdf8; }
.rarity-epic { border-color: #c084fc; }
.rarity-legendary { border-color: #facc15; box-shadow: 0 0 10px rgba(250, 204, 21, 0.25); }
.vow-tag { font-family: monospace; font-size: 10px; color: #38bdf8; }
.hidden { display: none !important; }

.pill-strip { display: flex; gap: 5px; justify-content: center; flex-wrap: wrap; margin-top: 4px; }
.terrain-pill, .target-pill {
  display: inline-block; padding: 1px 7px; border-radius: 4px;
  border: 1px solid #facc15; background: rgba(11, 13, 18, 0.85);
  font-family: monospace; font-size: 10px; font-weight: 700;
}
.target-pill { color: #fef08a; border-color: #facc15; cursor: pointer; }
.target-pill:hover { background: #facc15; color: #0b0d12; }
.save-badge {
  background: rgba(15, 23, 42, 0.92); border: 1px solid #facc15; color: #fde047;
  padding: 2px 8px; border-radius: 4px; font-family: monospace; font-size: 10px; font-weight: 700;
}
.ms-list { display: flex; flex-direction: column; gap: 5px; }
.ms-row { background: #171e2e; border: 1px solid #334155; border-radius: 5px; padding: 6px 9px; font-size: 12px; color: #cbd5e1; }
.ms-row.done { border-color: #22c55e; color: #dcfce7; }
.ms-row span { font-family: monospace; color: var(--gold-bright); margin-right: 6px; }
.terrain-chip { border: 1px solid; border-radius: 4px; padding: 4px 7px; font-family: monospace; font-size: 10px; background: #141a28; }

/* Start Menu Overlay */
.start-screen {
  position: absolute; inset: 0; background: rgba(7, 9, 15, 0.84); backdrop-filter: blur(5px);
  display: grid; place-items: center; z-index: 38; padding: 12px; overflow-y: auto;
}
.start-card {
  width: min(680px, 100%); background: rgba(14, 18, 30, 0.96);
  border: 2px solid var(--gold); border-radius: 10px; padding: 18px;
  box-shadow: 0 0 40px rgba(217, 119, 6, 0.25);
}
.start-crest { display: flex; gap: 14px; align-items: center; margin-bottom: 14px; }
.start-crest img { width: 76px; height: 76px; border: 2px solid var(--gold-bright); border-radius: 8px; image-rendering: pixelated; flex-shrink: 0; }
.start-kicker { font-family: monospace; font-size: 11px; color: #38bdf8; letter-spacing: 1px; font-weight: 700; }
.start-card h1 { margin: 2px 0 4px; font-size: 20px; color: var(--gold-bright); letter-spacing: 0.6px; }
.start-sub { margin: 0; font-size: 12px; color: #cbd5e1; line-height: 1.35; }
.start-primary-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.start-btn-main {
  flex: 1; min-width: 180px; min-height: 44px; padding: 10px 14px; border-radius: 6px;
  background: linear-gradient(180deg, #f59e0b, #b45309); color: #0b0d12;
  border: 1.5px solid #fef08a; font-weight: 800; font-size: 13px; cursor: pointer;
}
.start-btn-main:hover { filter: brightness(1.1); }
.start-slots-title { font-family: monospace; font-size: 11px; color: #fbbf24; margin-bottom: 6px; text-transform: uppercase; }
.start-slots { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.slot-card {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  background: #171e2e; border: 1px solid #334155; border-radius: 6px; padding: 8px 10px;
}
.slot-meta { display: flex; flex-direction: column; font-size: 12px; }
.slot-meta strong { color: var(--gold-bright); }
.slot-meta small { color: var(--muted); font-size: 10px; }
.slot-actions { display: flex; gap: 6px; flex-shrink: 0; }
.start-footer-row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

/* Mobile & Small Phone Responsive UI (Portrait + Landscape) */
@media (max-width: 920px), (max-height: 560px) {
  #game-shell { width: 100vw; height: 100dvh; aspect-ratio: auto; border: none; box-shadow: none; }
  .desktop-only { display: none !important; }
  .hud-panel { padding: 5px 7px; }
  #hud-top-left { min-width: 152px; max-width: 48vw; }
  .heart-svg { width: 13px; height: 13px; }
  .mono-dim { font-size: 10px; }
  #hud-top-center {
    top: auto; bottom: 136px; left: 50%; min-width: 0; max-width: 88vw; padding: 4px 8px;
    background: rgba(11, 13, 18, 0.72);
  }
  .region-title { font-size: 11px; }
  .quest-hint { font-size: 10px; }
  .quick-btns { max-width: 48vw; }
  .hud-btn { padding: 5px 7px; font-size: 10px; min-height: 30px; }
  #hud-bottom { bottom: auto; top: 68px; left: 8px; transform: none; width: auto; align-items: flex-start; }
  .astra-slot { width: 42px; height: 42px; }
  .astra-slot img { width: 22px; height: 22px; }
  .slot-name { display: none; }
  .toast-banner { top: 116px; font-size: 11px; }
  .dlg-portrait { width: 62px; height: 62px; }
  .dialogue-box { width: 95%; bottom: 12px; padding: 9px; gap: 10px; }
}

@media (max-width: 520px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .start-card { padding: 12px; }
  .start-crest img { width: 52px; height: 52px; }
  .start-card h1 { font-size: 16px; }
  .slot-card { flex-direction: column; align-items: flex-start; }
  .touch-joy { width: 100px; height: 100px; bottom: 12px; left: 10px; }
  .touch-knob { width: 40px; height: 40px; }
  .touch-actions { width: 186px; height: 178px; bottom: 10px; right: 8px; }
  .t-bow { width: 74px; height: 74px; font-size: 10px; }
  .t-btn { min-width: 46px; height: 38px; font-size: 9px; }
  .t-sweep { right: 86px; bottom: 8px; }
  .t-dash { right: 90px; bottom: 52px; }
  .t-astra { right: 48px; bottom: 90px; }
  .t-act { right: 2px; bottom: 90px; }
  .t-heal { right: 96px; bottom: 98px; }
  .t-lock { right: 2px; bottom: 134px; }
  .t-cycle { right: 138px; bottom: 52px; }
  #hud-top-center { bottom: 196px; }
}
