/* ===== Reset / base ===== */
* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: radial-gradient(ellipse 100% 80% at 50% 40%, #0a1230 0%, #04061a 60%, #02030c 100%);
  color: #e0e0ee;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overflow: hidden;
}

#app {
  position: relative;
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ===== Topbar ===== */
#topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 14px;
  height: 44px; flex-shrink: 0;
  background: rgba(10, 10, 20, 0.65);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(255,255,255,0.06);
  position: relative; z-index: 20;
}
.topbar-left {
  display: flex; align-items: center; gap: 14px;
  min-width: 0;
}
.app-brand {
  display: flex; align-items: center; gap: 9px;
  text-decoration: none; color: inherit;
}
.app-logo {
  width: 30px; height: 30px;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.4));
}
.app-title {
  font-weight: 700;
  font-size: 15px;
  color: #fff;
  letter-spacing: 0.2px;
}
.hint {
  font-size: 12px;
  color: #aaaabb;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.topbar-right {
  display: flex; align-items: center; gap: 6px;
}
.topbar-sep {
  width: 1px;
  background: #2a2a3a;
  margin: 0 4px;
  align-self: stretch;
}
.action-btn {
  background: #1c1c2a;
  color: #e0e0ee;
  border: 1px solid #2a2a3a;
  border-radius: 6px;
  padding: 5px 11px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 150ms, border-color 150ms, color 150ms;
  white-space: nowrap;
}
.action-btn:hover { background: #2a2a3a; border-color: #3a3a4a; }
.action-btn.toggle.on {
  background: #1c2a3a;
  border-color: #44aaff;
  color: #aaddff;
}

/* ===== Canvas area ===== */
#canvas-area {
  position: relative;
  flex: 1 1 auto;
  overflow: hidden;
}
#scene-canvas {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  display: block;
  cursor: grab;
}
#scene-canvas:active { cursor: grabbing; }

.loading {
  position: absolute; left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  font-size: 14px; color: #aaaabb;
  background: rgba(10, 12, 22, 0.7);
  padding: 10px 16px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.08);
  z-index: 4;
  pointer-events: none;
}

/* ===== Hover tip ===== */
.hover-tip {
  position: absolute;
  background: rgba(15, 18, 30, 0.92);
  border: 1px solid rgba(68,170,255,0.35);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 12px;
  pointer-events: none;
  z-index: 7;
  transform: translate(-50%, calc(-100% - 12px));
  box-shadow: 0 4px 14px rgba(0,0,0,0.4);
}
.tip-name { font-weight: 600; color: #fff; }
.tip-sub { font-size: 10.5px; color: #88a; margin-top: 2px; }

/* ===== Region tint legend (bottom-left) ===== */
.region-legend {
  position: absolute;
  left: 16px;
  bottom: 16px;
  z-index: 10;   /* above floating panels so the bottom-left corner is never hidden */
  background: rgba(18, 18, 28, 0.86);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 10px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.55);
  padding: 10px 12px;
  font-size: 12px;
  color: #cdd3e0;
  pointer-events: none;
}
.region-legend[hidden] { display: none; }
.region-legend .legend-title {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: #aab;
  margin-bottom: 7px;
}
.region-legend .legend-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 5px;
}
.region-legend .legend-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  line-height: 1.1;
}
.region-legend .legend-sw {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  flex: 0 0 auto;
  border: 1px solid rgba(255,255,255,0.18);
}

/* ===== Floating panels ===== */
.floating-panel {
  position: absolute;
  top: 56px;
  left: 16px;
  width: 320px;
  height: 540px;
  min-width: 240px;
  min-height: 200px;
  max-width: calc(100% - 32px);
  max-height: calc(100% - 32px);
  background: rgba(18, 18, 28, 0.86);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 10px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.55);
  z-index: 8;
  display: flex;
  flex-direction: column;
  resize: both;
  overflow: hidden;
}
.floating-panel[hidden] { display: none; }
.floating-panel.focused {
  border-color: rgba(68,170,255,0.55);
  box-shadow: 0 16px 50px rgba(0,0,0,0.6), 0 0 0 1px rgba(68,170,255,0.25);
  z-index: 9;
}
.floating-panel::after {
  content: '';
  position: absolute;
  right: 2px; bottom: 2px;
  width: 14px; height: 14px;
  pointer-events: none;
  background:
    linear-gradient(135deg, transparent 50%, rgba(255,255,255,0.18) 50%, rgba(255,255,255,0.18) 60%, transparent 60%),
    linear-gradient(135deg, transparent 75%, rgba(255,255,255,0.18) 75%, rgba(255,255,255,0.18) 85%, transparent 85%);
  border-bottom-right-radius: 10px;
}

.panel-header {
  display: flex; align-items: center;
  padding: 7px 10px 7px 12px;
  background: rgba(10, 10, 18, 0.6);
  border-bottom: 1px solid rgba(255,255,255,0.06);
  cursor: move;
  user-select: none;
  flex-shrink: 0;
}
.panel-header-title {
  font-weight: 600; font-size: 13px; color: #fff;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  max-width: 240px;
}
.panel-header-spacer { flex: 1; }
.panel-header-search {
  background: #0e0e18;
  border: 1px solid #2a2a3a;
  color: #e0e0ee;
  border-radius: 4px;
  padding: 3px 7px;
  font-size: 11px;
  width: 110px;
  margin-right: 6px;
}
.panel-header-search:focus { outline: none; border-color: #44aaff; }
.panel-header-btn {
  background: transparent;
  border: none;
  color: #aaaabb;
  font-size: 16px;
  width: 22px; height: 22px;
  line-height: 1;
  border-radius: 4px;
  cursor: pointer;
}
.panel-header-btn:hover { background: rgba(255,255,255,0.08); color: #fff; }

.panel-body {
  flex: 1 1 auto;
  overflow: auto;
  padding: 10px 12px 14px;
}
.panel-sub-title {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: #777788;
  margin: 8px 0 4px;
}
.panel-sub-title:first-child { margin-top: 0; }

/* ===== Panel positions ===== */
.library-panel {
  width: 280px;
  height: auto;
  max-height: calc(100vh - 80px);
  min-width: 240px; min-height: 240px;
  top: 56px; left: auto; right: 16px;
}
.info-panel {
  width: 380px;
  height: auto;
  max-height: calc(100vh - 80px);
  min-width: 300px; min-height: 240px;
  top: 56px; left: 268px; right: auto; bottom: auto;
}
.overlays-panel {
  width: 240px;
  height: auto;
  max-height: calc(100vh - 190px);
  min-width: 200px; min-height: 240px;
  top: 56px; left: 16px;
}
.quiz-panel {
  width: 360px;
  height: auto;
  max-height: calc(100vh - 190px);
  min-width: 300px; min-height: 280px;
  top: auto; bottom: 16px; left: calc(50% - 180px); right: auto;
}

/* ===== Country library ===== */
.country-library {
  display: flex; flex-direction: column; gap: 2px;
}
.country-item {
  display: flex; align-items: center; gap: 8px;
  background: transparent;
  padding: 6px 8px;
  border-radius: 5px;
  cursor: pointer;
  min-width: 0;
  border: 1px solid transparent;
  transition: background 150ms, border-color 150ms;
}
.country-item:hover { background: #1a1a26; border-color: #2a2a3a; }
.country-item.selected { background: #1c2a3a; border-color: #44aaff; }
.country-flag {
  flex-shrink: 0;
  width: 24px; height: 16px;
  display: inline-flex; align-items: center; justify-content: center;
  overflow: hidden;
  border-radius: 2px;
  background: #0a0a14;
}
.country-flag img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}
.country-name {
  font-size: 12.5px; color: #e0e0ee;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  flex: 1;
}
.country-cap {
  font-size: 10.5px; color: #88a;
  margin-left: auto;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  max-width: 80px;
}
.lib-cat-section {
  margin-top: 6px;
}
.lib-cat-head {
  display: flex; align-items: center; gap: 6px;
  width: 100%;
  background: transparent;
  border: none;
  color: #ccc;
  padding: 5px 6px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  cursor: pointer;
  text-align: left;
}
.lib-cat-head:hover { color: #fff; }
.lib-cat-caret {
  display: inline-block;
  transition: transform 150ms;
  color: #777;
  font-size: 9px;
}
.lib-cat-section.open .lib-cat-caret { transform: rotate(90deg); }
.lib-cat-count {
  margin-left: auto;
  color: #666;
  font-size: 10px;
  background: #1a1a26;
  padding: 1px 6px;
  border-radius: 8px;
}
.lib-cat-body { display: none; flex-direction: column; gap: 1px; padding-left: 4px; }
.lib-cat-section.open .lib-cat-body { display: flex; }

/* ===== Overlay checkboxes ===== */
.ov-check {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 2px;
  cursor: pointer;
  font-size: 12.5px;
  color: #ddd;
}
.ov-check:hover { color: #fff; }
.ov-check input[type=checkbox] {
  appearance: none;
  -webkit-appearance: none;
  width: 14px; height: 14px;
  border: 1px solid #44aaff;
  border-radius: 3px;
  background: #0e0e18;
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
}
.ov-check input[type=checkbox]:checked {
  background: #44aaff;
}
.ov-check input[type=checkbox]:checked::after {
  content: '';
  position: absolute;
  left: 3px; top: 0;
  width: 4px; height: 8px;
  border: solid #0a0a14;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

/* ===== Fact card ===== */
.info-empty {
  padding: 12px;
  font-size: 12.5px;
  color: #888;
  text-align: center;
  font-style: italic;
}
.fc-head {
  display: flex; gap: 12px; align-items: flex-start;
  margin-bottom: 12px; padding-bottom: 12px;
  border-bottom: 1px solid #232333;
}
.fc-thumb {
  width: 110px; height: 110px;
  object-fit: cover;
  background: #fff;
  border-radius: 6px;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}
.fc-thumb.no-img {
  display: flex; align-items: center; justify-content: center;
  font-size: 48px;
  background: #1a1a26;
  border: 1px dashed #2a2a3a;
}
.fc-head-text { flex: 1; min-width: 0; }
.fc-name {
  font-size: 16px; font-weight: 700; color: #fff;
  margin-bottom: 2px;
}
.fc-sub {
  font-size: 11.5px; color: #88a;
}
.fc-section-title {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: #777788;
  margin: 12px 0 6px;
}
.fc-summary {
  font-size: 12.5px; line-height: 1.55; color: #cce6ff;
}
.fc-facts {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 4px 12px;
  font-size: 12px;
  margin-top: 4px;
}
.fc-facts dt {
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-size: 10.5px;
  padding-top: 1px;
}
.fc-facts dd {
  color: #e0e0ee;
  margin: 0;
  overflow-wrap: anywhere;
}
.fc-links {
  margin-top: 12px;
  display: flex; flex-wrap: wrap; gap: 8px;
}
.fc-link {
  background: transparent;
  border: 1px solid rgba(68,170,255,0.4);
  color: #aaddff;
  border-radius: 5px;
  padding: 3px 9px;
  font-size: 11px;
  text-decoration: none;
}
.fc-link:hover { background: rgba(68,170,255,0.10); border-color: #44aaff; }

.fc-locate-btn {
  background: #1c2a3a;
  border: 1px solid #44aaff;
  color: #aaddff;
  border-radius: 5px;
  padding: 4px 10px;
  font-size: 11px;
  cursor: pointer;
  margin-top: 4px;
}
.fc-locate-btn:hover { background: #244466; }

/* ===== Stats overlay ===== */
.stats-overlay {
  position: absolute;
  top: 12px; right: 12px;
  background: rgba(10, 10, 20, 0.7);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 11.5px;
  color: #e0e0ee;
  z-index: 5;
  pointer-events: none;
  min-width: 140px;
}
.stats-formula {
  font-size: 14px; font-weight: 700; color: #fff;
  margin-bottom: 4px;
}
.stats-row {
  display: flex; justify-content: space-between; gap: 8px;
  padding: 1.5px 0;
}
.stats-label {
  color: #777788;
  text-transform: uppercase;
  font-size: 10px;
  letter-spacing: 0.5px;
}

/* ===== Quiz panel ===== */
.quiz-body { display: flex; flex-direction: column; gap: 12px; }
.quiz-intro { font-size: 13px; color: #cce6ff; line-height: 1.5; }
.quiz-start {
  display: flex; gap: 8px;
  flex-wrap: wrap;
}
.quiz-mode-btn {
  flex: 1 1 0;
  background: #1c2a3a;
  border: 1px solid #44aaff;
  color: #aaddff;
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  text-align: center;
  min-width: 120px;
}
.quiz-mode-btn:hover { background: #244466; }
.quiz-q {
  background: rgba(10, 10, 20, 0.6);
  border-left: 3px solid #44aaff;
  border-radius: 4px;
  padding: 10px 12px;
  font-size: 13.5px; color: #fff;
  line-height: 1.45;
}
.quiz-choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.quiz-choice {
  background: #1c1c2a;
  border: 1px solid #2a2a3a;
  color: #e0e0ee;
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 12px;
  cursor: pointer;
  text-align: left;
}
.quiz-choice:hover { background: #2a2a3a; border-color: #44aaff; }
.quiz-choice.correct { background: #143;border-color: #5a5; color: #b6f9b6; }
.quiz-choice.wrong { background: #311; border-color: #a55; color: #f9b6b6; }
.quiz-status {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 11.5px; color: #aaa;
}
.quiz-next, .quiz-restart {
  background: #1c2a3a; border: 1px solid #44aaff;
  color: #aaddff; border-radius: 5px;
  padding: 4px 11px; font-size: 11.5px; cursor: pointer;
}
.quiz-next:hover, .quiz-restart:hover { background: #244466; }
.quiz-home { display: flex; flex-direction: column; gap: 12px; }
.quiz-title { font-size: 16px; font-weight: 600; color: #fff; }
.quiz-sub { font-size: 12.5px; color: #aabbcc; line-height: 1.45; }
.quiz-mode-list { display: flex; flex-direction: column; gap: 6px; }
.quiz-mode-list .quiz-mode-btn { min-width: 0; text-align: left; }
.quiz-flag-big { font-size: 36px; display: inline-block; margin-left: 6px; vertical-align: middle; }
.quiz-flag-wrap {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  text-align: center;
}
.quiz-flag-img {
  display: block;
  width: 160px; max-width: 100%;
  height: auto;
  border-radius: 4px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.5);
  border: 1px solid rgba(255,255,255,0.15);
  background: #0a0a14;
}
.quiz-find-hint { font-size: 12px; color: #aacceb; font-style: italic; }
.quiz-feedback {
  min-height: 18px;
  font-size: 12px;
  padding: 6px 8px;
  border-radius: 4px;
  background: transparent;
  color: #ccd;
}
.quiz-feedback.ok { background: #14331f; color: #b6f9b6; border-left: 3px solid #5a5; }
.quiz-feedback.no { background: #311; color: #f9b6b6; border-left: 3px solid #a55; }
.quiz-controls { display: flex; gap: 8px; justify-content: flex-end; }
.quiz-btn {
  background: #1c2a3a;
  border: 1px solid #44aaff;
  color: #aaddff;
  border-radius: 5px;
  padding: 5px 12px;
  font-size: 12px;
  cursor: pointer;
}
.quiz-btn:hover { background: #244466; }
.quiz-btn.primary { background: #2a5588; color: #fff; }
.quiz-btn.primary:hover { background: #336699; }
.quiz-results { display: flex; flex-direction: column; gap: 10px; align-items: center; text-align: center; }
.quiz-score { font-size: 28px; font-weight: 700; color: #fff; }
.quiz-pct { font-size: 16px; color: #aabbcc; font-weight: 400; }
.quiz-verdict { font-size: 13px; color: #cce6ff; font-style: italic; }

/* ===== Responsive ===== */
@media (max-width: 1100px) {
  .hint { display: none; }
}
@media (max-width: 900px) {
  .library-panel { width: 230px; }
  .info-panel { width: 320px; }
}
