:root {
  --paper: #f5f4ec;
  --ink: #1f2a33;
  --son: #a6371f;
  --cham: #2e4a66;
  --muted: #5c6660;
  --line: #d9d8ca;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; } /* đảm bảo thuộc tính hidden luôn thắng CSS (sửa lỗi modal 3D che màn hình) */
html, body { margin: 0; height: 100%; font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: var(--paper); }
#map { position: absolute; inset: 64px 0 0 0; }

#topbar {
  position: absolute; inset: 0 0 auto 0; height: 64px; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 0 18px; background: var(--paper); border-bottom: 2px solid var(--ink);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo { color: var(--son); font-size: 22px; }
.brand strong { display: block; font-size: 1.05rem; }
.brand .sub { font-size: 0.78rem; color: var(--muted); }
.stats { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 0.78rem; color: var(--muted); text-align: right; white-space: nowrap; }
.stats b { color: var(--son); }

#legend {
  position: absolute; left: 12px; bottom: 12px; z-index: 5;
  background: var(--paper); border: 1px solid var(--line); border-radius: 4px;
  padding: 8px 10px; display: flex; gap: 14px; font-size: 0.78rem;
}
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; vertical-align: baseline; border: 1.5px solid #fff; box-shadow: 0 0 0 1px var(--ink); }
.legend-huyenthoai { background: var(--son); }
.legend-thuong { background: var(--cham); }

#panel {
  position: absolute; top: 80px; right: 12px; width: min(340px, calc(100% - 24px)); z-index: 6;
  background: var(--paper); border: 1.5px solid var(--ink); border-top: 4px solid var(--son);
  padding: 16px 18px 18px; box-shadow: 0 6px 24px rgba(0,0,0,.12);
}
#panel-close { position: absolute; top: 8px; right: 10px; background: none; border: none; font-size: 22px; cursor: pointer; color: var(--muted); line-height: 1; }
#panel h2 { margin: 6px 0 4px; font-size: 1.2rem; }
.badge { font-family: ui-monospace, monospace; font-size: 0.66rem; letter-spacing: .08em; text-transform: uppercase; padding: 2px 7px; border: 1px solid var(--son); color: var(--son); border-radius: 2px; }
.badge.thuong { border-color: var(--cham); color: var(--cham); }
.meta { color: var(--muted); font-size: 0.82rem; margin: 2px 0 10px; }
.p3d { font-size: 0.82rem; color: var(--son); border-top: 1px dashed var(--line); padding-top: 8px; }
.maplibregl-popup-content { font-family: inherit; }

.topright { display: flex; align-items: center; gap: 12px; }
.btn-ghost { background: none; border: 1.5px solid var(--ink); border-radius: 3px; padding: 6px 12px; font-size: 0.82rem; cursor: pointer; color: var(--ink); }
.btn-ghost:hover { background: var(--ink); color: var(--paper); }
.x { position: absolute; top: 8px; right: 10px; background: none; border: none; font-size: 22px; cursor: pointer; color: var(--muted); line-height: 1; }

.actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.btn { flex: 1; min-width: 120px; border: none; border-radius: 3px; padding: 9px 12px; font-size: 0.9rem; font-weight: 600; cursor: pointer; background: var(--cham); color: #fff; }
.btn:hover { filter: brightness(1.08); }
.btn-3d { background: var(--son); }
.result { margin-top: 10px; font-size: 0.85rem; padding: 8px 10px; border-radius: 3px; background: #ece9dc; }
.result.ok { background: #e2efe6; color: #2c5b40; }
.result.no { background: #f4e2dc; color: #8a3520; }

#journey, #submitgem {
  position: absolute; top: 80px; right: 12px; width: min(360px, calc(100% - 24px)); z-index: 7;
  background: var(--paper); border: 1.5px solid var(--ink); border-top: 4px solid var(--cham);
  padding: 16px 18px 18px; box-shadow: 0 6px 24px rgba(0,0,0,.12); max-height: calc(100% - 100px); overflow-y: auto;
}
#submitgem { border-top-color: var(--son); }
#submitgem h2 { margin: 4px 0 6px; font-size: 1.2rem; }
#submitgem label { display: flex; flex-direction: column; font-size: 13px; gap: 4px; margin: 8px 0; color: #333; }
#submitgem input, #submitgem select { padding: 8px; border: 1px solid #ccc4ad; border-radius: 4px; font-size: 14px; }
#submitgem .btn { width: 100%; background: var(--son); margin-top: 6px; }
#crosshair { position: absolute; top: calc(50% + 32px); left: 50%; transform: translate(-50%, -50%); z-index: 4; color: var(--son); font-size: 26px; pointer-events: none; text-shadow: 0 0 3px #fff; }
#journey h2 { margin: 4px 0 2px; font-size: 1.2rem; }
#journey h3 { margin: 16px 0 8px; font-size: 0.95rem; }
.season { margin: 10px 0; }
.season-top { display: flex; justify-content: space-between; font-size: 0.85rem; margin-bottom: 4px; }
.bar { height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--son); }
.badges-wrap { display: flex; flex-wrap: wrap; gap: 6px; }
.badge-chip { font-size: 0.8rem; border: 1px solid var(--son); color: var(--son); border-radius: 999px; padding: 3px 10px; }

#modal3d {
  position: absolute; inset: 0; z-index: 10; background: rgba(31,42,51,.5);
  display: flex; flex-direction: column; padding: max(24px, 4vh) max(24px, 4vw);
}
.modal-head { display: flex; justify-content: space-between; align-items: center; background: var(--ink); color: var(--paper); padding: 10px 14px; border-radius: 6px 6px 0 0; }
.modal-head .x { position: static; color: var(--paper); }
#modal3d-canvas { flex: 1; background: var(--paper); min-height: 300px; }
#modal3d-canvas canvas { display: block; width: 100%; height: 100%; }
.modal-foot { background: var(--paper); border-radius: 0 0 6px 6px; padding: 8px 14px; font-size: 0.8rem; color: var(--muted); font-family: ui-monospace, Menlo, monospace; }

#toast { position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 20; background: var(--ink); color: var(--paper); padding: 10px 18px; border-radius: 999px; font-size: 0.9rem; box-shadow: 0 4px 16px rgba(0,0,0,.25); }

@media (max-width: 560px) {
  .brand .sub { display: none; }
  #panel, #journey { top: auto; bottom: 0; right: 0; left: 0; width: 100%; border-radius: 0; max-height: 70%; overflow-y: auto; }
}
