/* HartForge: GridRealms — Sleek Translucent Overlay Navigation & Party Popover UI (v6.0)
 * Matches the uploaded PokéMMO-style navigation HUD & 2-column Party Action Popover
 */

:root {
  --ui-font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --pixel-font: 'Silkscreen', monospace;
  --slate-bg: rgba(22, 25, 34, 0.95);
  --slate-card: rgba(30, 34, 45, 0.92);
  --slate-btn: rgba(36, 41, 54, 0.95);
  --slate-btn-hover: rgba(50, 57, 74, 0.98);
  --glass-hud: rgba(34, 38, 48, 0.62);
  --glass-dock: rgba(24, 27, 36, 0.84);
  --border-subtle: rgba(255, 255, 255, 0.09);
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --hp-green: #4ade80;
  --exp-blue: #60a5fa;
  --amber-ring: rgba(234, 179, 8, 0.7);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

html, body {
  width: 100dvw;
  height: 100dvh;
  background-color: #090b10;
  color: var(--text-main);
  font-family: var(--ui-font);
  overflow: hidden;
  position: fixed;
}

#app-container {
  width: 100dvw;
  height: 100dvh;
  position: relative;
  overflow: hidden;
  container-type: inline-size;
}

/* ============================================================================
   TRUE LANDSCAPE-FIRST WIDESCREEN & 90-DEG ROTATION LOCK ON PORTRAIT
   ============================================================================ */
@media (orientation: portrait) {
  #app-container {
    width: 100dvh !important;
    height: 100dvw !important;
    transform: rotate(90deg) translateY(-100%) !important;
    transform-origin: top left !important;
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
  }
}

#screen-wrapper {
  position: relative;
  width: 100%;
  height: 100%;
  background: #090b10;
  overflow: hidden;
}

#game-canvas {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  cursor: pointer;
}

/* ============================================================================
   1. TOP-LEFT CLEAN LOCATION & TIME/WEATHER OVERLAY (Screenshot 1 & Orna)
   ============================================================================ */
#top-left-info {
  position: absolute;
  top: max(12px, env(safe-area-inset-top, 12px));
  left: 16px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  z-index: 30;
  pointer-events: none;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.9), 0 0 2px rgba(0, 0, 0, 0.95);
  max-width: min(380px, calc(50vw - 200px));
}

.loc-row {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
}

#zone-floor-badge, .floor-badge {
  background: rgba(245, 158, 11, 0.22);
  border: 1px solid rgba(251, 191, 36, 0.65);
  border-radius: 4px;
  padding: 2px 7px;
  font-family: var(--pixel-font);
  font-size: 10px;
  font-weight: 700;
  color: #fbbf24;
  text-shadow: 0 0 6px rgba(245, 158, 11, 0.6);
  display: inline-flex;
  align-items: center;
  white-space: nowrap;
  letter-spacing: 0.2px;
}

.loc-title {
  font-size: clamp(14px, 2vw, 17px);
  font-weight: 700;
  color: #ffffff;
  letter-spacing: -0.2px;
  white-space: nowrap;
}

.loc-sub {
  font-size: clamp(10px, 1.3vw, 11px);
  font-weight: 600;
  color: rgba(226, 232, 240, 0.8);
  letter-spacing: 0.4px;
  white-space: nowrap;
}

.weather-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: clamp(11px, 1.4vw, 13px);
  font-weight: 500;
  color: rgba(241, 245, 249, 0.92);
}

.boss-hud-pill {
  margin-top: 6px;
  background: var(--glass-dock);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 6px 10px;
  width: 190px;
  backdrop-filter: blur(6px);
}

.boss-pill-top {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  font-weight: 700;
  margin-bottom: 4px;
}

.boss-cr-tag, .monster-lvl-badge {
  background: rgba(239, 68, 68, 0.2);
  border: 1px solid rgba(239, 68, 68, 0.6);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 9px;
  font-weight: 700;
  color: #fca5a5;
  font-family: var(--pixel-font);
  display: inline-flex;
  align-items: center;
}

.boss-hp-track {
  width: 100%;
  height: 6px;
  background: rgba(0, 0, 0, 0.6);
  border-radius: 3px;
  overflow: hidden;
}

.boss-hp-fill {
  height: 100%;
  background: linear-gradient(90deg, #ef4444, #f87171);
  transition: width 0.2s ease;
}

/* ============================================================================
   1B. TURN-BASED 5e INITIATIVE TRACKER RIBBON (Active During Combat)
   ============================================================================ */
#initiative-tracker {
  position: absolute;
  top: max(8px, env(safe-area-inset-top, 8px));
  left: 50%;
  transform: translateX(-50%);
  background: rgba(18, 21, 30, 0.94);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  padding: 4px 8px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  z-index: 22;
  backdrop-filter: blur(8px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.7);
  width: auto;
  min-width: 260px;
  max-width: 380px; /* CRITICAL: Never exceeds 380px on 844px screens! */
  pointer-events: auto;
}

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

.init-round-pill {
  background: rgba(234, 179, 8, 0.22);
  border: 1px solid rgba(250, 204, 21, 0.55);
  color: #fde047;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 5px;
  white-space: nowrap;
}

.init-turn-text {
  font-size: 11px;
  font-weight: 600;
  color: #f8fafc;
  flex: 1;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.init-end-btn {
  background: linear-gradient(180deg, #2563eb, #1d4ed8);
  border: 1px solid rgba(147, 197, 253, 0.5);
  color: #ffffff;
  font-family: var(--ui-font);
  font-size: 10px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 5px;
  cursor: pointer;
  white-space: nowrap;
}

.init-end-btn:hover, .init-end-btn:active {
  background: #3b82f6;
}

.init-order-strip {
  display: flex;
  align-items: center;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
}

.init-chip {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 7px;
  border-radius: 6px;
  background: rgba(34, 39, 52, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 10px;
  font-weight: 600;
  color: #cbd5e1;
  white-space: nowrap;
}

.init-chip.active-turn {
  background: rgba(234, 179, 8, 0.25);
  border-color: #fde047;
  color: #ffffff;
  box-shadow: 0 0 8px rgba(250, 204, 21, 0.35);
}

.init-chip.enemy-chip {
  border-color: rgba(248, 113, 113, 0.35);
  color: #fca5a5;
}

.init-chip.enemy-chip.active-turn {
  background: rgba(220, 38, 38, 0.35);
  border-color: #f87171;
  color: #ffffff;
}

.init-roll-num {
  font-size: 9px;
  color: #94a3b8;
  font-weight: 700;
}

@container (max-width: 720px) {
  #initiative-tracker {
    top: max(54px, calc(48px + env(safe-area-inset-top, 8px)));
    max-width: min(380px, calc(100% - 20px));
    min-width: 0;
  }
}

/* Optional Floating Automap */
#automap-overlay {
  position: absolute;
  top: 72px;
  left: 16px;
  width: 96px;
  height: 72px;
  border: 2px solid rgba(255, 255, 255, 0.22);
  border-radius: 6px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.75);
  z-index: 20;
  background: rgba(24, 28, 38, 0.85);
}

/* ============================================================================
   2. TOP-RIGHT TRANSLUCENT SYSTEM PILL (Chat, Grid Menu, Status — Screenshot 1)
   ============================================================================ */
#top-right-pill {
  position: absolute;
  top: max(12px, env(safe-area-inset-top, 12px));
  right: 14px;
  background: rgba(34, 38, 48, 0.68);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 4px 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 30;
  backdrop-filter: blur(6px);
}

.sys-icon-btn {
  background: transparent;
  border: none;
  color: rgba(241, 245, 249, 0.9);
  width: 32px;
  height: 30px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  pointer-events: auto;
  transition: background 0.15s;
}

#hud-zoom-btn {
  pointer-events: auto;
  cursor: pointer;
}

.sys-icon-btn:hover, .sys-icon-btn:active {
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
}

.status-indicator {
  width: auto;
  padding: 0 6px;
  flex-direction: column;
  gap: 1px;
  font-size: 9px;
  font-weight: 600;
}

.battery-icon {
  font-size: 11px;
}

/* ============================================================================
   2B. TOP-RIGHT DUNGEON OBJECTIVE PILL TRACKER
   ============================================================================ */
#dungeon-objective-pill, .objective-pill {
  position: absolute;
  top: max(48px, env(safe-area-inset-top, 48px));
  right: 16px;
  background: rgba(18, 22, 30, 0.88);
  border: 1px solid rgba(245, 158, 11, 0.45);
  border-radius: 8px;
  padding: 5px 12px;
  font-size: 11px;
  font-weight: 600;
  color: #fde047;
  backdrop-filter: blur(8px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.6);
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 6px;
}

.objective-icon {
  font-size: 13px;
  line-height: 1;
}

#objective-text {
  font-family: var(--ui-font);
  letter-spacing: 0.2px;
  white-space: nowrap;
}

/* ============================================================================
   3. RIGHT-EDGE VERTICAL PARTY SIDEBAR DOCK (6 Slots — Screenshot 1 & 2)
   ============================================================================ */
#party-sidebar {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(22, 26, 35, 0.88);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 5px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  z-index: 25;
  backdrop-filter: blur(6px);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.65);
}

.party-slot {
  position: relative;
  width: 48px;
  height: 48px;
  background: rgba(35, 40, 52, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 7px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 3px 4px 5px 4px;
  transition: background 0.15s, border-color 0.15s;
}

.party-slot:hover, .party-slot.active {
  background: rgba(52, 60, 78, 0.96);
  border-color: rgba(255, 255, 255, 0.25);
}

.party-slot-sprite {
  width: 32px;
  height: 32px;
  object-fit: contain;
  image-rendering: pixelated;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.6));
}

.follower-paw {
  position: absolute;
  top: 2px;
  left: 3px;
  font-size: 9px;
  line-height: 1;
}

.status-mini-icon {
  position: absolute;
  bottom: 9px;
  left: 3px;
  font-size: 9px;
  line-height: 1;
}

.party-hp-track {
  position: absolute;
  bottom: 3px;
  left: 5px;
  right: 5px;
  height: 3.5px;
  background: rgba(12, 15, 22, 0.85);
  border-radius: 2px;
  overflow: hidden;
}

.party-hp-fill {
  height: 100%;
  background: var(--hp-green);
  border-radius: 2px;
}

/* ============================================================================
   4. 2-COLUMN PARTY DETAIL & ACTIONS POPOVER (Exact Match to Screenshot 2!)
   ============================================================================ */
.poke-popover-card {
  background: var(--slate-bg);
  border: 1px solid rgba(255, 255, 255, 0.11);
  border-radius: 12px;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(10px);
  color: var(--text-main);
}

#party-detail-modal {
  position: absolute;
  right: 76px;
  bottom: max(14px, env(safe-area-inset-bottom, 14px));
  width: min(510px, calc(100% - 90px));
  max-height: 92dvh;
  overflow-y: auto;
  display: grid;
  grid-template-columns: 1fr 1.15fr;
  gap: 12px;
  padding: 12px;
  z-index: 38;
}

@container (max-width: 540px) {
  #party-detail-modal {
    grid-template-columns: 1fr;
    right: 64px;
    width: calc(100% - 74px);
    padding: 10px;
    gap: 10px;
    max-height: 92dvh;
  }
}

.poke-col-left, .poke-col-right {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.poke-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 2px;
}

.poke-mini-sprite {
  width: 36px;
  height: 36px;
  object-fit: contain;
  image-rendering: pixelated;
}

.poke-title {
  font-size: 14px;
  font-weight: 700;
  color: #ffffff;
  letter-spacing: 0.3px;
}

.poke-sub {
  font-size: 12px;
  color: var(--text-muted);
}

.poke-bar-row {
  display: grid;
  grid-template-columns: 28px 1fr 48px;
  align-items: center;
  gap: 8px;
  font-size: 11px;
}

.poke-bar-label {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 10px;
}

.poke-bar-track {
  height: 5px;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 3px;
  overflow: hidden;
}

.poke-bar-fill.hp-green { background: var(--hp-green); height: 100%; }
.poke-bar-fill.exp-blue { background: var(--exp-blue); height: 100%; }

.poke-bar-val {
  text-align: right;
  font-size: 11px;
  font-weight: 600;
  color: #e2e8f0;
}

.poke-section-hdr {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.5px;
  margin-top: 4px;
}

.poke-moves-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.poke-move-row {
  display: grid;
  grid-template-columns: 48px 1fr auto;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  padding: 3px 4px;
  border-radius: 5px;
  cursor: pointer;
}

.poke-move-row:hover {
  background: rgba(255, 255, 255, 0.07);
}

.move-type-pill {
  font-size: 9px;
  font-weight: 700;
  text-align: center;
  padding: 2px 4px;
  border-radius: 3px;
  color: #fff;
  letter-spacing: 0.4px;
}

.type-steel   { background: #64748b; }
.type-fire    { background: #ea580c; }
.type-radiant { background: #ca8a04; }
.type-heal    { background: #16a34a; }

.move-name {
  font-weight: 500;
  color: #f1f5f9;
}

.move-pp {
  font-size: 11px;
  color: var(--text-muted);
}

.poke-nature-row {
  font-size: 11px;
  color: #cbd5e1;
  padding-top: 4px;
  border-top: 1px solid var(--border-subtle);
}

.poke-held-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255, 255, 255, 0.04);
  padding: 7px 9px;
  border-radius: 8px;
}

.held-icon {
  font-size: 18px;
}

.held-title {
  font-size: 12px;
  font-weight: 600;
  color: #ffffff;
}

.held-sub {
  font-size: 10px;
  color: var(--text-muted);
}

/* Right Column Action Buttons */
.poke-btn-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.poke-btn-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.poke-action-btn {
  background: var(--slate-btn);
  border: 1px solid rgba(255, 255, 255, 0.06);
  color: #f1f5f9;
  font-family: var(--ui-font);
  font-size: 11px;
  font-weight: 500;
  padding: 9px 10px;
  border-radius: 7px;
  cursor: pointer;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s;
}

.poke-action-btn:hover, .poke-action-btn:active {
  background: var(--slate-btn-hover);
}

.poke-action-btn.full-width {
  width: 100%;
}

.poke-action-btn.center-text {
  justify-content: center;
  font-weight: 600;
}

.btn-sub-note {
  font-size: 10px;
  color: var(--text-muted);
  margin-left: auto;
}

/* ============================================================================
   5. BOTTOM-LEFT TRANSLUCENT ROUNDED CROSS D-PAD (Exact Match to Screenshot 1!)
   ============================================================================ */
#translucent-dpad {
  position: absolute;
  left: 16px;
  bottom: max(14px, env(safe-area-inset-bottom, 14px));
  width: 156px;
  height: 156px;
  display: grid;
  grid-template-columns: 52px 52px 52px;
  grid-template-rows: 52px 52px 52px;
  z-index: 25;
}

/* Unified Translucent Cross Background */
.dpad-cross-bg {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.dpad-cross-bg::before,
.dpad-cross-bg::after {
  content: '';
  position: absolute;
  background: rgba(42, 46, 56, 0.64);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 12px;
  backdrop-filter: blur(4px);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45);
}

/* Vertical bar of cross */
.dpad-cross-bg::before {
  left: 52px;
  top: 0;
  width: 52px;
  height: 156px;
}

/* Horizontal bar of cross */
.dpad-cross-bg::after {
  left: 0;
  top: 52px;
  width: 156px;
  height: 52px;
}

.tdpad-btn {
  position: relative;
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.94);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 2;
  touch-action: none;
}

.tdpad-btn svg {
  width: 24px;
  height: 24px;
}

.tdpad-btn:active {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.14);
  border-radius: 8px;
}

.tdpad-up    { grid-column: 2; grid-row: 1; }
.tdpad-left  { grid-column: 1; grid-row: 2; }
.tdpad-center-dot {
  grid-column: 2;
  grid-row: 2;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.35);
  margin: auto;
  z-index: 2;
  pointer-events: none;
}
.tdpad-right { grid-column: 3; grid-row: 2; }
.tdpad-down  { grid-column: 2; grid-row: 3; }

/* ============================================================================
   6. BOTTOM-RIGHT TRANSLUCENT CIRCULAR A & B BUTTONS (Screenshot 1)
   ============================================================================ */
#translucent-ab {
  position: absolute;
  right: 88px;
  bottom: max(16px, env(safe-area-inset-bottom, 16px));
  display: flex;
  align-items: center;
  gap: 14px;
  z-index: 25;
}

.tab-circle-btn {
  border-radius: 50%;
  background: rgba(42, 46, 56, 0.58);
  color: #ffffff;
  font-family: var(--ui-font);
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  backdrop-filter: blur(4px);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45);
  transition: transform 0.1s, background 0.15s;
}

.tab-circle-btn:active {
  transform: scale(0.94);
  background: rgba(65, 72, 88, 0.78);
}

.btn-circle-a {
  width: 64px;
  height: 64px;
  font-size: 20px;
  border: 1.5px solid var(--amber-ring);
}

.btn-circle-b {
  width: 56px;
  height: 56px;
  font-size: 18px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  transform: translateY(-6px);
}

/* ============================================================================
   7. BOTTOM-CENTER 5-SLOT QUICK HOTBAR DOCK (1/3 | 1..5 | 1-5 — Screenshot 1)
   ============================================================================ */
#bottom-hotbar {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: max(12px, env(safe-area-inset-bottom, 12px));
  background: var(--glass-dock);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 5px;
  display: flex;
  align-items: center;
  gap: 5px;
  z-index: 25;
  backdrop-filter: blur(8px);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.7);
}

.hotbar-end-btn {
  width: 44px;
  height: 44px;
  background: rgba(38, 43, 56, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 7px;
  color: #e2e8f0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  font-family: var(--ui-font);
}

.hb-icon { font-size: 13px; line-height: 1; }
.hb-sub  { font-size: 9px; color: var(--text-muted); font-weight: 600; }

.hotbar-slot {
  position: relative;
  width: 44px;
  height: 44px;
  background: rgba(18, 21, 29, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.hotbar-slot:hover, .hotbar-slot:active {
  background: rgba(40, 46, 62, 0.95);
  border-color: rgba(255, 255, 255, 0.28);
}

.slot-num {
  position: absolute;
  top: 3px;
  left: 5px;
  font-size: 9px;
  font-weight: 700;
  color: var(--text-muted);
}

.slot-art {
  font-size: 19px;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.6));
}

/* Toast Log Pill & Floating Context Prompt Pill */
#toast-log-pill {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: max(68px, calc(62px + env(safe-area-inset-bottom, 8px)));
  background: rgba(18, 22, 30, 0.75);
  border: 1px solid var(--border-subtle);
  padding: 4px 12px;
  border-radius: 14px;
  font-size: 11px;
  color: rgba(241, 245, 249, 0.9);
  white-space: nowrap;
  pointer-events: none;
  z-index: 20;
  backdrop-filter: blur(4px);
}

#context-prompt {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: max(72px, calc(66px + env(safe-area-inset-bottom, 8px)));
  background: rgba(22, 26, 36, 0.92);
  border: 1px solid rgba(245, 158, 11, 0.75);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.8), 0 0 12px rgba(245, 158, 11, 0.35);
  padding: 6px 14px;
  border-radius: 16px;
  color: #fde047;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  z-index: 22;
  cursor: pointer;
  backdrop-filter: blur(6px);
}

/* Mobile Landscape & Compact Viewport Optimizations (Zero Overlap Guaranteed!) */
@media (max-height: 520px) {
  #top-left-info {
    max-width: 210px;
  }
  .loc-sub {
    display: none;
  }
  .loc-title {
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  #zone-floor-badge, .floor-badge {
    font-size: 8px;
    padding: 1px 5px;
  }
  #initiative-tracker {
    max-width: 360px;
    font-size: 10px;
  }
  #top-right-pill {
    right: 58px;
  }
  #dungeon-objective-pill {
    right: 58px;
  }
  .party-slot {
    width: 38px;
    height: 38px;
    padding: 2px 3px 4px 3px;
  }
  .party-slot-sprite {
    width: 26px;
    height: 26px;
  }
  #translucent-dpad {
    bottom: 12px;
    left: 14px;
    width: 144px;
    height: 144px;
    grid-template-columns: 48px 48px 48px;
    grid-template-rows: 48px 48px 48px;
  }
  .dpad-cross-bg::before { left: 48px; width: 48px; height: 144px; }
  .dpad-cross-bg::after  { top: 48px; width: 144px; height: 48px; }

  #translucent-ab {
    right: 76px;
    bottom: 12px;
    gap: 12px;
  }
  .btn-circle-a { width: 62px; height: 62px; font-size: 19px; }
  .btn-circle-b { width: 54px; height: 54px; font-size: 17px; }

  .hotbar-end-btn, .hotbar-slot {
    width: 38px;
    height: 38px;
  }
  .slot-art {
    font-size: 17px;
  }
  #context-prompt {
    bottom: max(58px, calc(52px + env(safe-area-inset-bottom, 8px)));
  }
  #toast-log-pill {
    display: none;
  }
}

@container (max-width: 560px) {
  .loc-sub {
    display: none;
  }
  #translucent-dpad {
    left: 12px;
    bottom: 10px;
    width: 132px;
    height: 132px;
    grid-template-columns: 44px 44px 44px;
    grid-template-rows: 44px 44px 44px;
  }
  .dpad-cross-bg::before { left: 44px; width: 44px; height: 132px; }
  .dpad-cross-bg::after  { top: 44px; width: 132px; height: 44px; }

  #translucent-ab {
    right: 70px;
    bottom: 10px;
    gap: 10px;
  }
  .btn-circle-a { width: 56px; height: 56px; font-size: 17px; }
  .btn-circle-b { width: 48px; height: 48px; font-size: 15px; }

  .hotbar-end-btn, .hotbar-slot {
    width: 34px;
    height: 34px;
  }
  #toast-log-pill {
    display: none;
  }
}

/* ============================================================================
   8. DIALOGUE CARD, LOOT DRAFT & CHARACTER CREATOR MODALS
   ============================================================================ */
.poke-dialogue-card {
  position: absolute;
  bottom: max(68px, calc(62px + env(safe-area-inset-bottom, 8px)));
  left: 16px;
  right: 72px;
  max-width: 680px;
  margin: 0 auto;
  background: var(--slate-bg);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 12px;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.88);
  backdrop-filter: blur(10px);
  display: none;
  z-index: 36;
  padding: 12px;
  max-height: 92dvh;
  overflow-y: auto;
}

#dialogue-box.active {
  display: block;
}

.dialogue-content {
  display: flex;
  gap: 12px;
  align-items: center;
}

.portrait-frame {
  width: 68px;
  height: 68px;
  background: rgba(36, 41, 54, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}

#dialogue-portrait-canvas {
  width: 64px;
  height: 64px;
  image-rendering: pixelated;
}

.dialogue-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.dialogue-text-line {
  font-size: 13px;
  line-height: 1.45;
}

.dialogue-speaker {
  color: #fbbf24;
  font-weight: 700;
  margin-right: 5px;
}

.dialogue-prose { color: #f8fafc; }

.dialogue-choices {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.choice-btn, .dialogue-choice-btn {
  background: var(--slate-btn);
  color: #f1f5f9;
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 6px 11px;
  font-family: var(--ui-font);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  border-radius: 6px;
}

.choice-btn:hover, .dialogue-choice-btn:hover {
  background: var(--slate-btn-hover);
  border-color: rgba(251, 191, 36, 0.5);
}

/* Loot Draft & Social Drawer */
#loot-draft-modal {
  position: absolute;
  inset: 0;
  background: rgba(6, 8, 14, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 42;
  padding: 14px;
}

.loot-modal-wrapper {
  width: 100%;
  max-width: 520px;
}

.loot-window {
  padding: 14px;
  max-height: 92dvh;
  overflow-y: auto;
}

.gba-window-header {
  font-size: 12px;
  font-weight: 700;
  color: #ffffff;
  padding-bottom: 8px;
  margin-bottom: 10px;
  border-bottom: 1px solid var(--border-subtle);
}

.loot-columns {
  display: grid;
  grid-template-columns: 1fr 1.2fr;
  gap: 10px;
}

.loot-col-order, .loot-col-items {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-subtle);
  padding: 10px;
  border-radius: 8px;
}

.loot-col-title {
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 700;
  margin-bottom: 6px;
}

.loot-turn { font-size: 11px; color: #cbd5e1; padding: 4px 0; }
.loot-turn.active { color: #fbbf24; font-weight: 700; }

.loot-item-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  background: var(--slate-btn);
  color: #ffffff;
  border: 1px solid var(--border-subtle);
  padding: 7px 9px;
  margin-bottom: 6px;
  font-family: var(--ui-font);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  border-radius: 6px;
}

.loot-item-btn:hover { background: var(--slate-btn-hover); }

.haversack-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
}

/* Social Drawer */
#social-drawer {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 280px;
  background: var(--slate-bg);
  border-left: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.22s ease;
  z-index: 45;
  backdrop-filter: blur(10px);
}

#social-drawer.open { transform: translateX(0); }
.drawer-tabs { display: flex; border-bottom: 1px solid var(--border-subtle); }
.drawer-tab {
  flex: 1;
  background: transparent;
  color: var(--text-muted);
  border: none;
  padding: 10px 0;
  font-family: var(--ui-font);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}
.drawer-tab.active {
  color: #ffffff;
  border-bottom: 2px solid #fbbf24;
}
.drawer-content { flex: 1; overflow-y: auto; padding: 10px; font-size: 12px; }
.chat-msg { margin-bottom: 8px; line-height: 1.4; }
.ping-bar { display: flex; gap: 4px; padding: 8px; border-top: 1px solid var(--border-subtle); justify-content: space-around; }
.ping-btn {
  background: var(--slate-btn);
  border: 1px solid var(--border-subtle);
  color: #fff;
  padding: 5px 8px;
  font-family: var(--ui-font);
  font-size: 11px;
  cursor: pointer;
  border-radius: 5px;
}
.chat-input-bar { display: flex; padding: 8px; border-top: 1px solid var(--border-subtle); }
.chat-input-bar input {
  flex: 1;
  background: rgba(0, 0, 0, 0.4);
  color: #fff;
  border: 1px solid var(--border-subtle);
  padding: 8px;
  border-radius: 6px;
  font-family: var(--ui-font);
  font-size: 12px;
}

/* Character Creator Modal */
.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(6, 9, 15, 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  backdrop-filter: blur(4px);
}

.pixel-card {
  padding: 12px 14px;
  width: 94%;
  max-width: 480px;
  max-height: 95dvh;
  overflow-y: auto;
}

.creator-header {
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  color: #ffffff;
  margin-bottom: 6px;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 5px;
}

.app-mode-banner {
  background: linear-gradient(135deg, rgba(30, 58, 138, 0.55), rgba(15, 23, 42, 0.85));
  border: 1px solid rgba(56, 189, 248, 0.5);
  border-radius: 8px;
  padding: 6px 8px;
  margin-bottom: 7px;
  text-align: center;
}

.app-mode-title {
  font-size: 11px;
  color: #fde047;
  margin-bottom: 2px;
}

.app-mode-desc {
  font-size: 10px;
  color: #cbd5e1;
  margin-bottom: 5px;
  line-height: 1.25;
}

.app-mode-actions {
  display: flex;
  gap: 6px;
}

.btn-app-install, .btn-app-fullscreen {
  flex: 1;
  padding: 6px 8px;
  border-radius: 6px;
  font-family: var(--ui-font);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid rgba(255, 255, 255, 0.18);
  transition: transform 0.1s, background 0.15s;
}

.btn-app-install {
  background: linear-gradient(180deg, #059669, #047857);
  color: #ffffff;
  border-color: rgba(52, 211, 153, 0.5);
}

.btn-app-fullscreen {
  background: linear-gradient(180deg, #4338ca, #3730a3);
  color: #ffffff;
  border-color: rgba(129, 140, 248, 0.5);
}

.btn-app-install:hover, .btn-app-fullscreen:hover {
  filter: brightness(1.12);
}

#hud-fullscreen-btn {
  font-size: 15px;
  font-weight: 700;
  color: #38bdf8;
}

.creator-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 6px; }
.creator-field label { display: block; font-size: 9px; font-weight: 600; color: var(--text-muted); margin-bottom: 2px; }
.creator-field select, .creator-field input {
  width: 100%;
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.14);
  padding: 5px 7px;
  font-family: var(--ui-font);
  font-size: 11px;
  border-radius: 6px;
}

.stat-preset-box {
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--border-subtle);
  padding: 6px 8px;
  border-radius: 8px;
  margin-bottom: 8px;
}
.stat-preset-title { font-size: 9px; font-weight: 700; color: #fbbf24; text-align: center; margin-bottom: 3px; }
.stat-grid-6 { display: grid; grid-template-columns: repeat(6, 1fr); gap: 3px; font-size: 10px; color: #cbd5e1; text-align: center; }
.stat-summary-bar { display: flex; justify-content: space-between; margin-top: 4px; padding-top: 4px; border-top: 1px solid var(--border-subtle); font-size: 10px; }

.btn-primary {
  width: 100%;
  background: #2563eb;
  color: #fff;
  border: none;
  padding: 8px;
  font-family: var(--ui-font);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  border-radius: 7px;
}
.btn-secondary { background: var(--slate-btn); border: 1px solid var(--border-subtle); }

/* Portrait 90-degree CSS Orientation Lock */
@media screen and (orientation: portrait) {
  #app-container {
    width: 100dvh !important;
    height: 100dvw !important;
    transform: rotate(90deg) !important;
    transform-origin: top left !important;
    position: absolute !important;
    top: 0 !important;
    left: 100dvw !important;
  }
}
