/* ============================================================================
   ĐẾ CHẾ LOÀI KIẾN 3D — PHONG CÁCH GAME CHIẾN THUẬT TƯƠI SÁNG & DỄ THƯƠNG
   Hỗ trợ chuẩn Tiếng Việt (Baloo 2 + Be Vietnam Pro) & Responsive Mobile
   (cả Portrait Mode lẫn Landscape Mode)
   ============================================================================ */

:root {
  --wood-dark: #4a2e1b;
  --wood-mid: #7c4d2b;
  --wood-light: #a66c3f;
  --parchment: #fff9eb;
  --parchment-2: #f7ebd2;
  --ink-dark: #2c1e16;
  --ink-muted: #6b5344;
  --font-display: 'Baloo 2', 'Be Vietnam Pro', system-ui, sans-serif;
  --font-body: 'Be Vietnam Pro', system-ui, -apple-system, sans-serif;
}

* {
  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%;
  overflow: hidden;
  font-family: var(--font-body);
  background: #7cc6fe;
  color: var(--ink-dark);
}

h1, h2, h3,
.crest-title, .cmd-name, .deck-tab, .card-title, .insp-name,
.raid-title, .season-tag, .tech-name, .action-btn, .float-pop {
  font-family: var(--font-display);
}

.hidden {
  display: none !important;
}

/* Sân khấu 3D */
#game-container {
  position: fixed;
  inset: 0;
  z-index: 1;
}

canvas#three-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
}

canvas#three-canvas:active {
  cursor: grabbing;
}

/* Lớp chữ nổi sát thương / chiến lợi phẩm 3D -> 2D */
#floating-labels-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 5;
}

.float-pop {
  position: absolute;
  font-weight: 800;
  font-size: 14px;
  text-shadow: 0 2px 0 rgba(44, 30, 22, 0.88), 0 0 6px rgba(0, 0, 0, 0.35);
  white-space: nowrap;
  transform: translate(-50%, -50%);
  animation: floatUpFade 1.15s ease-out forwards;
}

@keyframes floatUpFade {
  0% { opacity: 1; transform: translate(-50%, -50%) scale(0.85); }
  20% { opacity: 1; transform: translate(-50%, -85%) scale(1.1); }
  100% { opacity: 0; transform: translate(-50%, -180%) scale(0.95); }
}

/* Khung Game kiểu gỗ & giấy da chiến thuật sáng sủa */
.game-frame {
  background: linear-gradient(180deg, rgba(255, 251, 240, 0.95) 0%, rgba(248, 237, 214, 0.94) 100%);
  border: 2.5px solid var(--wood-dark);
  border-radius: 18px;
  box-shadow:
    0 4px 0 rgba(74, 46, 27, 0.45),
    0 8px 20px rgba(34, 20, 10, 0.2),
    inset 0 2px 0 rgba(255, 255, 255, 0.95),
    inset 0 -2px 0 rgba(196, 155, 102, 0.45);
}

/* Bố cục HUD chính */
#hud-layer {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding:
    max(10px, env(safe-area-inset-top))
    max(12px, env(safe-area-inset-right))
    max(10px, env(safe-area-inset-bottom))
    max(12px, env(safe-area-inset-left));
  gap: 8px;
}

.pointer-auto {
  pointer-events: auto;
}

/* ==================== HÀNG TRÊN ==================== */
.hud-top {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.hud-top-secondary {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  flex-wrap: wrap;
}

.empire-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px 6px 8px;
  max-width: 100%;
}

.empire-crest {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 12px;
  flex-shrink: 0;
  transition: transform 0.12s ease;
}

.empire-crest:hover {
  transform: scale(1.03);
}

.crest-avatar {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: radial-gradient(circle at 30% 25%, #475569, #1e1b4b);
  border: 2.5px solid #fbbf24;
  box-shadow: inset 0 2px 4px rgba(255, 255, 255, 0.3), 0 3px 0 #78350f;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 19px;
}

.crest-info {
  line-height: 1.15;
}

.crest-title {
  font-size: 15px;
  font-weight: 800;
  color: var(--ink-dark);
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.lv-badge {
  font-family: var(--font-body);
  font-size: 10.5px;
  font-weight: 800;
  padding: 1px 7px;
  border-radius: 999px;
  background: linear-gradient(180deg, #fde047, #f59e0b);
  color: #451a03;
  border: 1.5px solid #92400e;
}

.pop-row {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11px;
  font-weight: 700;
  color: #15803d;
  margin-top: 2px;
  white-space: nowrap;
}

.caste-mini {
  color: var(--ink-muted);
  display: flex;
  gap: 5px;
}

.res-divider {
  width: 2px;
  height: 28px;
  background: rgba(124, 77, 43, 0.25);
  border-radius: 2px;
  flex-shrink: 0;
}

.resource-strip {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 5px;
  overflow-x: auto;
  max-width: 100%;
  scrollbar-width: none;
}

.resource-strip::-webkit-scrollbar { display: none; }

.res-pill {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border-radius: 10px;
  font-size: 12.5px;
  font-weight: 800;
  border: 2px solid rgba(74, 46, 27, 0.28);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.75);
  white-space: nowrap;
}

.res-ico { font-size: 13.5px; }
.res-cap { font-size: 10px; opacity: 0.65; font-weight: 700; }

.res-food  { background: #ffe4e6; color: #9f1239; border-color: #fda4af; }
.res-honey { background: #fef3c7; color: #92400e; border-color: #fcd34d; }
.res-soil  { background: #ffedd5; color: #9a3412; border-color: #fdba74; }
.res-wood  { background: #ecfccb; color: #3f6212; border-color: #bef264; }
.res-stone { background: #e2e8f0; color: #334155; border-color: #cbd5e1; }
.res-evo   { background: #f3e8ff; color: #6b21a8; border-color: #d8b4fe; }

/* Đồng hồ Thời tiết & Mùa */
.env-dial {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 9px;
}

.weather-orb {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(180deg, #e0f2fe, #bae6fd);
  border: 2px solid #0284c7;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  box-shadow: inset 0 2px 4px rgba(255, 255, 255, 0.8);
}

.env-meta {
  line-height: 1.2;
  white-space: nowrap;
}

.env-top-line {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
  font-weight: 800;
}

.season-tag { color: #15803d; }
.day-tag { color: var(--wood-dark); font-size: 12px; }
.dot-sep { opacity: 0.4; }

.env-sub-line {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 700;
  color: var(--ink-muted);
}

.speed-group {
  display: flex;
  gap: 3px;
  padding-left: 7px;
  border-left: 2px solid rgba(124, 77, 43, 0.2);
}

.spd-btn {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  border: 2px solid rgba(74, 46, 27, 0.3);
  background: #fff;
  color: var(--ink-dark);
  font-family: var(--font-body);
  font-size: 10.5px;
  font-weight: 800;
  cursor: pointer;
  transition: all 0.12s ease;
  padding: 0;
}

.spd-btn:hover { background: #fef3c7; }
.spd-btn.active {
  background: linear-gradient(180deg, #4ade80, #16a34a);
  color: #fff;
  border-color: #14532d;
  box-shadow: 0 2px 0 #14532d;
}

/* Nút Hệ thống */
.sys-cluster {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px;
}

.icon-btn {
  position: relative;
  width: 34px;
  height: 34px;
  border-radius: 11px;
  border: 2px solid var(--wood-dark);
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(44, 30, 22, 0.55), inset 0 2px 0 rgba(255, 255, 255, 0.45);
  transition: transform 0.1s ease, box-shadow 0.1s ease, filter 0.1s ease;
  padding: 0;
}

.icon-btn:hover { transform: translateY(-2px); filter: brightness(1.06); }
.icon-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(44, 30, 22, 0.55); }

.notif-dot {
  position: absolute;
  top: -3px;
  right: -3px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #ef4444;
  border: 2px solid #fff;
  animation: pulseDot 1.2s infinite;
}

@keyframes pulseDot {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.3); }
}

.btn-amber  { background: linear-gradient(180deg, #fcd34d, #f59e0b); color: #451a03; }
.btn-purple { background: linear-gradient(180deg, #c084fc, #9333ea); color: #fff; }
.btn-teal   { background: linear-gradient(180deg, #2dd4bf, #0d9488); color: #fff; }
.btn-lime   { background: linear-gradient(180deg, #a3e635, #65a30d); color: #1a2e05; }
.btn-sky    { background: linear-gradient(180deg, #38bdf8, #0284c7); color: #fff; }
.btn-green  { background: linear-gradient(180deg, #4ade80, #16a34a); color: #fff; }
.btn-indigo { background: linear-gradient(180deg, #818cf8, #4f46e5); color: #fff; }
.btn-rose   { background: linear-gradient(180deg, #fb7185, #e11d48); color: #fff; }
.btn-neutral{ background: linear-gradient(180deg, #e2e8f0, #cbd5e1); color: #334155; }

/* ==================== BANNER CẢNH BÁO ==================== */
.hud-banners {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  pointer-events: none;
}

.raid-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  background: linear-gradient(90deg, rgba(136, 19, 55, 0.95), rgba(185, 28, 28, 0.95));
  color: #fff;
  border: 2.5px solid #fde047;
  border-radius: 15px;
  padding: 6px 12px;
  box-shadow: 0 6px 20px rgba(185, 28, 28, 0.45);
  cursor: pointer;
  animation: raidPulse 1.4s infinite;
  max-width: 96vw;
}

@keyframes raidPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7), 0 6px 18px rgba(0,0,0,0.3); }
  50% { box-shadow: 0 0 18px 6px rgba(253, 224, 71, 0.75), 0 6px 18px rgba(0,0,0,0.3); }
}

.raid-pulse-icon { font-size: 22px; }
.raid-title { font-size: 14px; font-weight: 800; color: #fef08a; }
.raid-sub { font-size: 11px; font-weight: 600; opacity: 0.95; }

.boss-hp-wrap {
  margin-top: 4px;
  width: 180px;
  height: 7px;
  background: rgba(0, 0, 0, 0.45);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.35);
}

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

.raid-focus-btn {
  padding: 5px 9px;
  border-radius: 9px;
  border: 2px solid #fef08a;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 11px;
  cursor: pointer;
  white-space: nowrap;
}

.mode-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(44, 30, 22, 0.92);
  color: #fff9eb;
  border: 2px solid #fbbf24;
  border-radius: 13px;
  padding: 6px 12px;
  font-size: 12.5px;
  font-weight: 700;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
  max-width: 96vw;
}

.cancel-mode-btn {
  padding: 4px 9px;
  border-radius: 8px;
  border: none;
  background: #f43f5e;
  color: #fff;
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 11px;
  cursor: pointer;
  white-space: nowrap;
}

/* ==================== KHU VỰC GIỮA ==================== */
.hud-middle {
  flex: 1;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 8px;
  min-height: 0;
  position: relative;
}

.hud-left-col {
  display: flex;
  flex-direction: column;
  gap: 7px;
  max-width: 280px;
  max-height: 100%;
  overflow-y: auto;
  scrollbar-width: none;
}

.hud-left-col::-webkit-scrollbar { display: none; }

.hud-spacer { flex: 1; }

/* Thẻ Nhiệm vụ */
.quest-card {
  width: 256px;
  padding: 8px 10px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 5px;
}

.card-title {
  font-size: 14px;
  font-weight: 800;
  color: var(--wood-dark);
}

.mini-close {
  width: 22px;
  height: 22px;
  border-radius: 7px;
  border: 1.5px solid rgba(74, 46, 27, 0.3);
  background: rgba(255, 255, 255, 0.8);
  color: var(--wood-dark);
  font-weight: 800;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

.quest-item {
  background: rgba(255, 255, 255, 0.8);
  border: 1.5px solid rgba(124, 77, 43, 0.22);
  border-radius: 10px;
  padding: 5px 8px;
  font-size: 11px;
}

.quest-item.done {
  background: #dcfce7;
  border-color: #4ade80;
}

.quest-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  color: var(--ink-dark);
}

.quest-prog {
  font-size: 10px;
  color: var(--ink-muted);
  margin-top: 2px;
  display: flex;
  justify-content: space-between;
}

.quest-claim-btn {
  margin-top: 4px;
  width: 100%;
  padding: 4px 8px;
  border-radius: 8px;
  border: 1.5px solid #15803d;
  background: linear-gradient(180deg, #4ade80, #16a34a);
  color: #fff;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 12px;
  cursor: pointer;
  animation: pulseGlow 1.5s infinite;
}

/* Thẻ Inspector */
.inspector-card {
  width: 268px;
  padding: 9px 11px;
}

.insp-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 7px;
}

.insp-avatar {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: #fef3c7;
  border: 2px solid #d97706;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 19px;
  flex-shrink: 0;
}

.insp-titles { flex: 1; line-height: 1.2; min-width: 0; }
.insp-name { font-size: 15px; font-weight: 800; color: var(--ink-dark); }
.insp-sub { font-size: 11px; font-weight: 700; color: #15803d; }

.hp-block { margin-bottom: 6px; }
.hp-labels {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  font-weight: 700;
  color: var(--ink-muted);
  margin-bottom: 3px;
}

.hp-track {
  width: 100%;
  height: 8px;
  background: rgba(74, 46, 27, 0.16);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid rgba(74, 46, 27, 0.25);
}

.hp-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #4ade80, #16a34a);
  transition: width 0.2s ease;
}

.insp-state {
  background: rgba(255, 255, 255, 0.85);
  border: 1.5px solid rgba(124, 77, 43, 0.22);
  border-radius: 9px;
  padding: 5px 8px;
  font-size: 11px;
  font-weight: 700;
  margin-bottom: 6px;
}

.insp-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 5px;
}

.stat-chip {
  font-size: 10.5px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 7px;
  background: #f1f5f9;
  color: #334155;
  border: 1px solid #cbd5e1;
}

.insp-desc {
  font-size: 11px;
  color: var(--ink-muted);
  line-height: 1.38;
  margin-bottom: 6px;
}

.insp-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.insp-btn {
  padding: 5px 10px;
  border-radius: 9px;
  border: 2px solid var(--wood-dark);
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  color: #fff;
  background: linear-gradient(180deg, #4ade80, #16a34a);
}

/* Cột phải: Buff mùa & Minimap */
.hud-right-col {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

.season-buff-pill {
  padding: 5px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 700;
  color: var(--wood-dark);
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: 340px;
}

.minimap-frame {
  padding: 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.minimap-wrap {
  position: relative;
  border: 2px solid var(--wood-dark);
  border-radius: 11px;
  overflow: hidden;
  line-height: 0;
}

#minimap-canvas {
  display: block;
  cursor: crosshair;
  background: #4fa96c;
}

.coords-tag {
  position: absolute;
  bottom: 4px;
  left: 4px;
  background: rgba(24, 24, 27, 0.72);
  color: #fff;
  font-size: 9.5px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 6px;
  pointer-events: none;
  line-height: 1.2;
}

.map-expand-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 20px;
  height: 20px;
  border-radius: 6px;
  border: 1.5px solid var(--wood-dark);
  background: rgba(255, 255, 255, 0.88);
  font-size: 10px;
  font-weight: 800;
  cursor: pointer;
}

.minimap-legend {
  display: flex;
  gap: 7px;
  font-size: 9.5px;
  font-weight: 700;
  color: var(--ink-muted);
}

.minimap-legend span {
  display: flex;
  align-items: center;
  gap: 3px;
}

.dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  border: 1px solid #1e293b;
}
.dot-nest  { background: #f59e0b; }
.dot-relic { background: #38bdf8; }
.dot-lair  { background: #9333ea; }
.dot-pred  { background: #ef4444; }

.cam-controls {
  display: flex;
  width: 100%;
  gap: 4px;
}

.cam-controls button {
  flex: 1;
  padding: 4px 5px;
  border-radius: 8px;
  border: 1.5px solid rgba(74, 46, 27, 0.35);
  background: #fff;
  color: var(--wood-dark);
  font-family: var(--font-body);
  font-size: 10.5px;
  font-weight: 800;
  cursor: pointer;
}

.cam-controls button:hover { background: #fef3c7; }

/* ==================== HÀNG DƯỚI: COMMAND DECK ==================== */
.hud-bottom {
  display: flex;
  justify-content: center;
  width: 100%;
}

.command-deck {
  padding: 7px 10px 8px;
  max-width: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.deck-tabs {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.tab-strip {
  display: flex;
  gap: 5px;
  flex-wrap: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
}

.tab-strip::-webkit-scrollbar { display: none; }

.deck-tab {
  flex-shrink: 0;
  padding: 4px 12px;
  border-radius: 10px;
  border: 2px solid transparent;
  background: rgba(124, 77, 43, 0.12);
  color: var(--wood-dark);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.12s ease;
}

.deck-tab:hover { background: rgba(245, 158, 11, 0.22); }

.deck-tab.active {
  background: linear-gradient(180deg, #fbbf24, #d97706);
  color: #fff;
  border-color: var(--wood-dark);
  box-shadow: 0 2px 0 var(--wood-dark);
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.25);
}

.deck-hints {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 700;
  color: var(--ink-muted);
  white-space: nowrap;
}

.deck-items {
  display: flex;
  align-items: center;
  gap: 7px;
  overflow-x: auto;
  padding: 3px 2px 4px;
}

.cmd-card {
  position: relative;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 11px;
  border-radius: 14px;
  border: 2.5px solid var(--wood-dark);
  text-align: left;
  cursor: pointer;
  box-shadow: 0 4px 0 rgba(44, 30, 22, 0.55), inset 0 2px 0 rgba(255, 255, 255, 0.42);
  transition: transform 0.1s ease, box-shadow 0.1s ease, filter 0.1s ease;
}

.cmd-card:hover:not(:disabled) {
  transform: translateY(-2px);
  filter: brightness(1.06);
}

.cmd-card:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 1px 0 rgba(44, 30, 22, 0.55);
}

.cmd-card.active-tool {
  outline: 3px solid #fde047;
  outline-offset: 2px;
  transform: translateY(-2px);
}

.cmd-card:disabled {
  opacity: 0.55;
  filter: grayscale(0.4);
  cursor: not-allowed;
}

.hotkey {
  position: absolute;
  top: -6px;
  left: -5px;
  width: 18px;
  height: 18px;
  border-radius: 6px;
  background: var(--wood-dark);
  color: #fef08a;
  font-family: var(--font-body);
  font-size: 10px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1.5px solid #fff;
}

.cmd-ico { font-size: 20px; }
.cmd-text { line-height: 1.18; }
.cmd-name { font-size: 14px; font-weight: 800; }
.cmd-cost { font-family: var(--font-body); font-size: 10.5px; font-weight: 700; opacity: 0.94; }

.card-emerald { background: linear-gradient(180deg, #34d399, #059669); color: #fff; }
.card-rose    { background: linear-gradient(180deg, #fb7185, #e11d48); color: #fff; }
.card-sky     { background: linear-gradient(180deg, #38bdf8, #0284c7); color: #fff; }
.card-purple  { background: linear-gradient(180deg, #c084fc, #9333ea); color: #fff; }
.card-gold    { background: linear-gradient(180deg, #fde047, #f59e0b); color: #451a03; }
.card-amber   { background: linear-gradient(180deg, #fbbf24, #d97706); color: #451a03; }
.card-pink    { background: linear-gradient(180deg, #f472b6, #db2777); color: #fff; }
.card-slate   { background: linear-gradient(180deg, #64748b, #334155); color: #fff; }
.card-lime    { background: linear-gradient(180deg, #a3e635, #65a30d); color: #1a2e05; }
.card-neutral { background: linear-gradient(180deg, #e2e8f0, #cbd5e1); color: #334155; }

@keyframes pulseGlow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(250, 204, 21, 0.75), 0 4px 0 rgba(44, 30, 22, 0.55); }
  50% { box-shadow: 0 0 18px 6px rgba(250, 204, 21, 0.9), 0 4px 0 rgba(44, 30, 22, 0.55); }
}

.nuptial-ready {
  animation: pulseGlow 1.5s infinite;
}

/* ==================== TOASTS & MODALS ==================== */
#toast-container {
  position: fixed;
  top: 72px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 40;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
  width: min(92vw, 440px);
}

.toast-item {
  background: rgba(44, 30, 22, 0.93);
  color: #fff9eb;
  border: 2px solid #fbbf24;
  border-radius: 13px;
  padding: 7px 14px;
  font-size: 12.5px;
  font-weight: 700;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.32);
  text-align: center;
  animation: toastPop 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes toastPop {
  from { opacity: 0; transform: translateY(-10px) scale(0.92); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(24, 16, 10, 0.58);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
}

.modal-box {
  width: 100%;
  max-width: 460px;
  max-height: 86vh;
  overflow-y: auto;
  padding: 16px 18px;
}

.modal-wide {
  max-width: 600px;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.modal-head h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 800;
  line-height: 1.2;
  color: var(--wood-dark);
}

.modal-close {
  width: 30px;
  height: 30px;
  flex-shrink: 0;
  border-radius: 10px;
  border: 2px solid var(--wood-dark);
  background: #fee2e2;
  color: #991b1b;
  font-weight: 800;
  cursor: pointer;
}

.modal-desc {
  margin: 0 0 12px;
  font-size: 12.5px;
  color: var(--ink-muted);
  line-height: 1.5;
}

.status-box {
  background: #dcfce7;
  border: 2px solid #86efac;
  color: #166534;
  border-radius: 12px;
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 12px;
}

.modal-btn-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 10px;
}

.action-btn {
  padding: 8px 12px;
  border-radius: 12px;
  border: 2px solid var(--wood-dark);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(44, 30, 22, 0.5);
  transition: transform 0.1s ease;
}

.action-btn:hover { transform: translateY(-1px); }
.action-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(44, 30, 22, 0.5); }
.full-w { width: 100%; }

.import-area textarea {
  width: 100%;
  border-radius: 10px;
  border: 2px solid var(--wood-light);
  padding: 8px;
  font-family: monospace;
  font-size: 11px;
  margin-bottom: 6px;
}

.modal-footer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 2px solid rgba(124, 77, 43, 0.18);
  padding-top: 10px;
  margin-top: 8px;
}

.seed-label { font-size: 12px; font-weight: 700; color: var(--ink-muted); }

.danger-soft-btn {
  padding: 6px 10px;
  border-radius: 10px;
  border: 2px solid #fda4af;
  background: #ffe4e6;
  color: #be123c;
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.reset-confirm {
  margin-top: 10px;
  padding: 10px;
  border-radius: 12px;
  background: #fff1f2;
  border: 2px solid #f43f5e;
  font-size: 12px;
  font-weight: 700;
  color: #9f1239;
}

.reset-actions { display: flex; gap: 8px; margin-top: 8px; }
.reset-actions button { flex: 1; }

/* Tech Tree Grid */
.tech-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 9px;
}

.tech-card {
  background: rgba(255, 255, 255, 0.88);
  border: 2px solid rgba(124, 77, 43, 0.32);
  border-radius: 14px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 8px;
}

.tech-card.unlocked {
  background: #dcfce7;
  border-color: #22c55e;
}

.tech-top { display: flex; align-items: center; gap: 8px; }
.tech-ico {
  width: 34px; height: 34px; flex-shrink: 0;
  border-radius: 10px;
  background: #f3e8ff;
  border: 2px solid #c084fc;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
}
.tech-name { font-size: 15px; font-weight: 800; line-height: 1.2; }
.tech-desc { font-size: 11.5px; color: var(--ink-muted); line-height: 1.42; }

/* Help cards */
.help-sections { display: flex; flex-direction: column; gap: 8px; }
.help-card {
  border-radius: 13px;
  padding: 10px 12px;
  font-size: 12px;
  line-height: 1.5;
  border: 2px solid transparent;
}
.help-card h3 { margin: 0 0 4px; font-size: 15px; font-weight: 800; }
.help-card p, .help-card ul { margin: 0; }
.help-card ul { padding-left: 18px; }
.help-green { background: #ecfdf5; border-color: #6ee7b7; }
.help-amber { background: #fffbeb; border-color: #fcd34d; }
.help-sky   { background: #f0f9ff; border-color: #7dd3fc; }

/* Thanh cuộn đẹp */
.custom-scroll::-webkit-scrollbar { width: 5px; height: 5px; }
.custom-scroll::-webkit-scrollbar-thumb { background: rgba(124, 77, 43, 0.35); border-radius: 999px; }

/* ============================================================================
   RESPONSIVE LAYOUT: TABLET, MOBILE PORTRAIT & MOBILE LANDSCAPE
   ============================================================================ */

@media (max-width: 960px) {
  .deck-hints, .season-buff-pill, .caste-mini { display: none; }
  .quest-card { width: 225px; }
}

/* 1. MOBILE PORTRAIT (Màn hình dọc hẹp <= 680px) */
@media (max-width: 680px) {
  #hud-layer {
    padding:
      max(6px, env(safe-area-inset-top))
      max(6px, env(safe-area-inset-right))
      max(8px, env(safe-area-inset-bottom))
      max(6px, env(safe-area-inset-left));
    gap: 5px;
  }

  .game-frame {
    border-width: 2px;
    border-radius: 14px;
    box-shadow: 0 3px 0 rgba(74, 46, 27, 0.4), 0 5px 12px rgba(34, 20, 10, 0.18);
  }

  .hud-top {
    flex-direction: column;
    gap: 5px;
  }

  /* Hàng 1 siêu gọn: Huy hiệu thu nhỏ + dải tài nguyên cuộn ngang 1 dòng */
  .empire-bar {
    width: 100%;
    padding: 4px 7px;
    gap: 6px;
    flex-wrap: nowrap;
  }

  .crest-avatar {
    width: 30px;
    height: 30px;
    font-size: 15px;
    border-radius: 9px;
  }

  .crest-title { font-size: 12.5px; gap: 4px; }
  .crest-title > span:first-child { display: none; }
  .lv-badge { font-size: 10px; padding: 1px 6px; }
  .pop-row { font-size: 10px; margin-top: 1px; }
  .res-divider { height: 22px; }

  .res-pill {
    padding: 3px 6px;
    font-size: 11px;
    border-radius: 8px;
    gap: 3px;
  }
  .res-ico { font-size: 12px; }
  .res-cap { display: none; }

  /* Hàng 2: Thời tiết + Nút hệ thống trên cùng 1 hàng hoặc siêu gọn */
  .hud-top-secondary {
    width: 100%;
    justify-content: space-between;
    flex-wrap: nowrap;
    gap: 5px;
  }

  .env-dial {
    padding: 4px 6px;
    gap: 5px;
    flex: 1;
    min-width: 0;
  }

  .weather-orb {
    width: 26px;
    height: 26px;
    font-size: 14px;
  }

  .env-top-line { font-size: 11px; gap: 3px; }
  .day-tag { font-size: 10.5px; }
  .env-sub-line { font-size: 9.5px; gap: 3px; }
  #hud-weather-text, #hud-temp { display: none; }

  .speed-group { padding-left: 5px; gap: 2px; }
  .spd-btn { width: 22px; height: 22px; font-size: 9.5px; border-radius: 6px; }

  .sys-cluster {
    padding: 3px 4px;
    gap: 3px;
    flex-shrink: 0;
  }

  .icon-btn {
    width: 28px;
    height: 28px;
    font-size: 13px;
    border-radius: 8px;
    box-shadow: 0 2px 0 rgba(44, 30, 22, 0.5);
  }

  /* Inspector & Minimap nổi gọn gàng khi mở trên Mobile */
  .hud-left-col { max-width: 215px; }
  .quest-card { width: 210px; padding: 7px 8px; }
  .inspector-card { width: 215px; padding: 8px 9px; }
  .insp-desc { display: none; }

  .minimap-frame { padding: 5px; }
  .minimap-legend { display: none; }

  /* Command Deck 1 hàng tab + thẻ gọn cho ngón tay */
  .command-deck {
    width: 100%;
    padding: 5px 7px 6px;
    gap: 4px;
  }

  .deck-tab {
    padding: 4px 9px;
    font-size: 11.5px;
    border-radius: 8px;
  }

  .hotkey { display: none; }
  .cmd-card {
    padding: 6px 9px;
    gap: 6px;
    border-radius: 11px;
    box-shadow: 0 3px 0 rgba(44, 30, 22, 0.5);
  }
  .cmd-ico { font-size: 17px; }
  .cmd-name { font-size: 12.5px; }
  .cmd-cost { font-size: 9.5px; }

  #toast-container { top: 126px; }
  .toast-item { font-size: 11.5px; padding: 5px 11px; }
  .modal-box { padding: 13px 14px; max-height: 84vh; }
  .modal-head h2 { font-size: 17px; }
}

/* 2. MOBILE LANDSCAPE (Màn hình ngang thấp <= 520px chiều cao) */
@media (max-height: 520px) and (orientation: landscape) {
  #hud-layer {
    padding:
      max(5px, env(safe-area-inset-top))
      max(10px, env(safe-area-inset-right))
      max(5px, env(safe-area-inset-bottom))
      max(10px, env(safe-area-inset-left));
    gap: 4px;
  }

  .game-frame {
    border-width: 2px;
    border-radius: 13px;
    box-shadow: 0 3px 0 rgba(74, 46, 27, 0.4);
  }

  .hud-top {
    flex-wrap: nowrap;
    align-items: center;
    gap: 6px;
  }

  .empire-bar {
    padding: 3px 7px;
    gap: 6px;
    flex: 1;
    min-width: 0;
  }

  .crest-avatar { width: 28px; height: 28px; font-size: 14px; border-radius: 8px; }
  .crest-title { font-size: 12px; }
  .crest-title > span:first-child, .caste-mini, .res-cap, .deck-hints, .season-buff-pill { display: none; }
  .pop-row { font-size: 10px; margin-top: 0; }
  .res-divider { height: 20px; }
  .res-pill { padding: 2px 6px; font-size: 11px; border-radius: 8px; }

  .hud-top-secondary {
    flex-wrap: nowrap;
    gap: 5px;
    flex-shrink: 0;
  }

  .env-dial { padding: 3px 7px; gap: 5px; }
  .weather-orb { width: 24px; height: 24px; font-size: 13px; }
  .env-top-line { font-size: 11px; }
  .env-sub-line { font-size: 9.5px; }
  #hud-weather-text, #hud-temp { display: none; }
  .spd-btn { width: 22px; height: 22px; font-size: 9.5px; }

  .sys-cluster { padding: 3px 4px; gap: 3px; }
  .icon-btn { width: 28px; height: 28px; font-size: 13px; border-radius: 8px; }

  /* Giữ không gian 3D thoáng tối đa theo chiều dọc */
  .hud-left-col { max-width: 220px; }
  .quest-card { width: 215px; padding: 6px 8px; }
  .inspector-card { width: 220px; padding: 7px 9px; }
  .insp-desc { display: none; }

  .minimap-frame { padding: 4px; }
  .minimap-legend { display: none; }
  .cam-controls button { padding: 2px 4px; font-size: 9.5px; }

  /* Command Deck ngang siêu mỏng */
  .command-deck {
    flex-direction: row;
    align-items: center;
    padding: 4px 8px;
    gap: 8px;
    max-width: 98vw;
  }

  .deck-tabs { flex-shrink: 0; }
  .tab-strip { gap: 4px; }
  .deck-tab { padding: 4px 8px; font-size: 11px; border-radius: 8px; }

  .deck-items { padding: 2px 1px; gap: 5px; }
  .hotkey { display: none; }
  .cmd-card { padding: 4px 8px; gap: 5px; border-radius: 10px; box-shadow: 0 2px 0 rgba(44, 30, 22, 0.5); }
  .cmd-ico { font-size: 16px; }
  .cmd-name { font-size: 12px; }
  .cmd-cost { font-size: 9.5px; }

  #toast-container { top: 112px; }
  .modal-box { max-height: 92vh; padding: 12px 16px; }
  .modal-head h2 { font-size: 17px; }
}

/* ==================== CHẾ ĐỘ LÒNG ĐẤT (UNDERGROUND UI) ==================== */
.view-toggle-btn {
  height: 34px;
  padding: 0 11px;
  border-radius: 11px;
  border: 2px solid var(--wood-dark);
  background: linear-gradient(180deg, #b45309, #78350f);
  color: #fef3c7;
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 5px;
  box-shadow: 0 3px 0 rgba(44, 30, 22, 0.6), inset 0 2px 0 rgba(255, 255, 255, 0.3);
  transition: transform 0.1s ease, filter 0.1s ease;
}

.view-toggle-btn:hover { transform: translateY(-2px); filter: brightness(1.08); }
.view-toggle-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(44, 30, 22, 0.6); }

.view-toggle-btn.is-underground {
  background: linear-gradient(180deg, #38bdf8, #0284c7);
  color: #ffffff;
}

.strata-pill {
  padding: 5px 11px;
  border-radius: 12px;
  font-size: 11.5px;
  font-weight: 800;
  color: #fef3c7;
  background: linear-gradient(180deg, rgba(68, 43, 28, 0.94), rgba(44, 28, 18, 0.94));
  border-color: #d97706;
  display: flex;
  align-items: center;
  gap: 6px;
}

@media (max-width: 680px) {
  .view-toggle-btn {
    height: 28px;
    padding: 0 7px;
    font-size: 11px;
    border-radius: 8px;
  }
  .strata-pill {
    font-size: 10px;
    padding: 4px 8px;
  }
}

@media (max-height: 520px) and (orientation: landscape) {
  .view-toggle-btn {
    height: 28px;
    padding: 0 8px;
    font-size: 11px;
    border-radius: 8px;
  }
}

/* Bổ sung hiển thị độ sâu & thống kê sinh thái lòng đất */
.strata-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.strata-sub {
  font-size: 0.72rem;
  opacity: 0.85;
  color: #fde68a;
  font-weight: 600;
}

/* v5.0: Fix Toast không che thanh HUD trên + style Tinh Thể & Tier Công trình */
#toast-container {
  top: 128px !important;
}
.res-crystal {
  background: linear-gradient(180deg, #e0f2fe, #bae6fd);
  border-color: #38bdf8;
  color: #0369a1;
}
.tech-tier-tag {
  display: inline-block;
  margin-top: 2px;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 800;
}
.tech-tier-tag.tier-1 { background: #dcfce7; color: #166534; }
.tech-tier-tag.tier-2 { background: #fef3c7; color: #92400e; }
.tech-tier-tag.tier-3 { background: #ede9fe; color: #5b21b6; }
.tier-max-tag {
  text-align: center;
  font-size: 11.5px;
  font-weight: 800;
  color: #b45309;
  background: #fef3c7;
  border: 1px solid #f59e0b;
  border-radius: 10px;
  padding: 5px 8px;
}
