/* =============================================
   True Size China — map-first control interface
   ============================================= */

:root {
  --map-ink: #1c2d3d;
  --map-ink-raised: #263b4d;
  --map-ink-hover: #30495d;
  --map-ink-muted: #9eb0bd;
  --map-border: rgba(255, 255, 255, 0.16);
  --map-divider: rgba(255, 255, 255, 0.12);
  --surface: #ffffff;
  --surface-muted: #edf2f4;
  --text: #ffffff;
  --text-dark: #203243;
  --text-dim: #bdc9d1;
  --text-muted: #8093a0;
  --accent: #63cbed;
  --accent-strong: #22b6df;
  --accent-dim: rgba(99, 203, 237, 0.16);
  --danger: #f16e6e;
  --radius: 12px;
  --radius-sm: 7px;
  --panel-shadow: 0 12px 30px rgba(25, 42, 56, 0.24);
  --transition: 0.18s ease;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  min-width: 320px;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: #aab7bb;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Noto Sans SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

button,
input {
  font: inherit;
}

button,
a,
input,
.ci {
  -webkit-tap-highlight-color: transparent;
}

:focus-visible {
  outline: 3px solid rgba(99, 203, 237, 0.66);
  outline-offset: 2px;
}

#map {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  touch-action: none;
}

/* ========== Watermark ========== */
#watermark {
  position: fixed;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(8px, env(safe-area-inset-bottom));
  z-index: 1002;
  color: rgba(28, 45, 61, 0.58);
  font-size: 14px;
  font-weight: 600;
  line-height: 18px;
  letter-spacing: 0.6px;
  text-shadow: 0 0 3px rgba(255, 255, 255, 0.9);
  white-space: nowrap;
  pointer-events: none;
}

/* ========== Globe View ========== */
[hidden] {
  display: none !important;
}

.view-switch {
  position: fixed;
  top: 24px;
  left: 18px;
  z-index: 1001;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  width: 256px;
  gap: 4px;
  padding: 4px;
  border: 2px solid var(--accent);
  border-radius: var(--radius);
  background: var(--map-ink);
  box-shadow: 0 6px 20px rgba(25, 42, 56, 0.32);
}

.view-switch button {
  min-height: 44px;
  padding: 8px 12px;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--map-ink-raised);
  color: var(--text);
  cursor: pointer;
  font-weight: 700;
  white-space: nowrap;
}

.view-switch button:not([aria-pressed="true"]):not(:disabled):hover {
  background: var(--map-ink-hover);
}

.view-switch button[aria-pressed="true"] {
  background: var(--accent);
  color: var(--map-ink);
}

.view-switch button:focus-visible {
  outline: 3px solid var(--surface);
  outline-offset: -3px;
}

.view-switch button:disabled {
  opacity: 0.45;
  cursor: wait;
}

#globeView {
  position: fixed;
  inset: 0;
  background: radial-gradient(ellipse at 65% 42%, #f4f5ef, #dce4e3 70%, #cbd7d9);
  color: var(--text-dark);
}

.globe-heading {
  position: absolute;
  top: 28px;
  left: 364px;
  pointer-events: none;
}

.globe-kicker {
  color: #547581;
  font-size: 11px;
  letter-spacing: 2px;
}

.globe-heading h2 {
  margin-top: 6px;
  font-size: 27px;
  font-weight: 650;
  letter-spacing: 1px;
}

.globe-heading p {
  margin-top: 5px;
  color: #647b83;
  font-size: 12px;
}

#globeCanvas {
  position: absolute;
  top: 134px;
  left: 340px;
  width: calc(100% - 356px);
  height: calc(100% - 210px);
  touch-action: none;
  cursor: grab;
}

#globeCanvas.is-dragging {
  cursor: grabbing;
}

.globe-controls {
  position: absolute;
  top: 24px;
  right: 18px;
  display: flex;
  overflow: hidden;
  border-radius: var(--radius-sm);
  background: var(--map-ink);
  box-shadow: var(--panel-shadow);
}

.globe-controls button {
  width: 44px;
  height: 44px;
  border: 0;
  border-right: 1px solid var(--map-divider);
  background: transparent;
  color: white;
  cursor: pointer;
  font-size: 24px;
}

.globe-controls button:hover {
  background: var(--map-ink-hover);
}

.globe-controls button:disabled {
  opacity: 0.4;
  cursor: default;
}

.globe-actions {
  position: absolute;
  right: 18px;
  bottom: 80px;
  display: flex;
  gap: 8px;
}

.globe-actions .action-btn {
  min-width: 88px;
  padding: 8px 12px;
  border: 1px solid rgba(28, 45, 61, 0.18);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.72);
  color: var(--text-dark);
  cursor: pointer;
  font-size: 12px;
  font-weight: 650;
}

.globe-actions .action-btn:hover {
  background: #fff;
}

.globe-help {
  position: absolute;
  bottom: 28px;
  left: 340px;
  width: calc(100% - 356px);
  color: #496975;
  text-align: center;
  font-size: 12px;
  line-height: 1.9;
  pointer-events: none;
}

.globe-help span {
  color: #71858d;
  font-size: 11px;
}

.globe-info {
  position: absolute;
  bottom: 132px;
  right: 20px;
  max-width: calc(100% - 32px);
  border: 1px solid var(--map-border);
  border-radius: var(--radius);
  background: var(--map-ink);
  box-shadow: var(--panel-shadow);
}

#globeInfoClose {
  position: absolute;
  z-index: 3;
  top: 3px;
  right: 4px;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 22px;
}

.globe-info .country-info-popup {
  padding-top: 30px;
}

body.is-globe #sp,
body.is-globe .sb-actions,
body.is-globe #inset-map {
  display: none !important;
}

body.is-globe .ci .ab {
  display: inline-block;
  width: auto;
  min-width: 32px;
  font-size: 11px;
}

body.is-globe .ci.globe-selected {
  background: var(--accent-dim);
  color: #a9edff;
}

@media (max-width: 900px) and (min-width: 601px) {
  .globe-heading { left: 340px; top: 90px; }
  .globe-heading h2 { font-size: 22px; }
  #globeCanvas { top: 180px; height: calc(100% - 270px); }
}

@media (max-width: 600px) {
  .view-switch { top: 12px; left: auto; right: 16px; width: 224px; }
  .globe-heading { top: 80px; left: 24px; }
  .globe-heading h2 { font-size: 23px; }
  #globeCanvas {
    top: 145px;
    left: 16px;
    width: calc(100% - 32px);
    height: calc(100% - 240px);
  }
  .globe-controls { top: 80px; right: 16px; flex-direction: column; }
  .globe-controls button { width: 38px; height: 38px; border-right: 0; }
  .globe-actions { right: 16px; bottom: 68px; }
  .globe-help { left: 16px; bottom: 26px; width: calc(100% - 32px); font-size: 11px; }
  .globe-help span { font-size: 10px; }
  /* 手机端信息面板改为底部抽屉，按实际高度为地球仪和操作按钮留出空间 */
  .globe-info {
    right: 0;
    bottom: 0;
    left: 0;
    max-width: 100%;
    max-height: 40vh;
    overflow-y: auto;
    border-radius: 14px 14px 0 0;
  }
  .globe-info .country-info-popup {
    width: 276px;
    margin: 0 auto;
  }
  .globe-info .country-learning.is-collapsed {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    column-gap: 8px;
    row-gap: 5px;
    margin: 8px 0;
    padding: 8px;
  }
  .globe-info .country-learning.is-collapsed .country-facts {
    min-width: 0;
    padding-top: 0;
    padding-left: 8px;
    border-top: 0;
    border-left: 1px solid rgba(99, 203, 237, 0.14);
  }
  .globe-info .country-learning.is-collapsed .country-learning-text {
    display: -webkit-box;
    overflow: hidden;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 1;
  }
  .globe-info .country-learning.is-collapsed .country-learning-toggle {
    grid-column: 1 / -1;
  }
  .globe-info .country-learning-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    max-width: 100%;
  }
  #globeView.is-info-open #globeCanvas {
    bottom: calc(var(--globe-info-height, 40vh) + 16px);
    height: calc(100% - var(--globe-info-height, 40vh) - 161px);
  }
  #globeView.is-info-open .globe-actions {
    bottom: calc(var(--globe-info-height, 40vh) + 8px);
  }
  body:not(.is-globe) .leaflet-top.leaflet-right { top: 72px; }
}

/* ========== Loading ========== */
#loading {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: #d9e1e3;
  color: var(--text-dark);
  transition: opacity 0.28s ease;
}

#loading[style*="display: none"] {
  pointer-events: none;
}

#loading .spinner {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(28, 45, 61, 0.2);
  border-top-color: var(--accent-strong);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

#loading p {
  color: #486071;
  font-size: 13px;
  font-weight: 600;
}

#loading .progress-bar {
  width: 210px;
  height: 4px;
  overflow: hidden;
  border-radius: 99px;
  background: rgba(28, 45, 61, 0.14);
}

#loading .progress-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--accent-strong);
  transition: width 0.2s;
}

#loading.error .spinner {
  border-color: rgba(241, 110, 110, 0.2);
  border-top-color: var(--danger);
  animation: none;
}

#loading.error p:last-of-type {
  color: #bf4c4c;
  font-size: 12px;
}

#loading .retry {
  padding: 7px 18px;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--map-ink);
  color: #fff;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
}

/* ========== Map Control Card ========== */
#sidebar {
  position: fixed;
  top: 102px;
  left: 18px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  width: min(304px, calc(100vw - 36px));
  max-height: calc(100vh - 124px);
  max-height: calc(100dvh - 124px);
  cursor: default;
  pointer-events: auto;
  transition: transform var(--transition), opacity var(--transition);
}

.sidebar-inner {
  display: flex;
  flex-direction: column;
  overflow: hidden auto;
  border: 1px solid rgba(17, 36, 50, 0.2);
  border-radius: var(--radius);
  background: var(--map-ink);
  box-shadow: var(--panel-shadow);
  scrollbar-color: rgba(206, 223, 231, 0.42) transparent;
  scrollbar-width: thin;
}

.sidebar-inner::-webkit-scrollbar,
.country-list::-webkit-scrollbar {
  width: 5px;
}

.sidebar-inner::-webkit-scrollbar-track,
.country-list::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar-inner::-webkit-scrollbar-thumb,
.country-list::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: rgba(206, 223, 231, 0.42);
}

/* ========== Header ========== */
.sb-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px 8px;
}

.sb-logo {
  font-size: 22px;
  line-height: 1;
}

.sb-header h1 {
  color: #fff;
  font-size: 18px;
  font-weight: 760;
  letter-spacing: -0.3px;
}

.sb-subtitle {
  margin-top: 2px;
  color: var(--map-ink-muted);
  font-size: 11px;
}

.sb-hook {
  margin-top: 5px;
  padding: 3px 7px;
  border-left: 2px solid var(--accent);
  border-radius: 0 4px 4px 0;
  background: rgba(99, 203, 237, 0.08);
  color: #b7e8f6;
  font-size: 10.5px;
  line-height: 1.45;
}

.sb-hook b {
  color: #d5f8ff;
  font-size: 11.5px;
}

/* ========== Search ========== */
.sb-search {
  position: relative;
  margin: 6px 16px 11px;
}

.sb-search .search-icon {
  position: absolute;
  top: 50%;
  left: 12px;
  width: 16px;
  transform: translateY(-50%);
  color: #8092a0;
  pointer-events: none;
}

#sb {
  width: 100%;
  padding: 9px 12px 9px 35px;
  border: 1px solid rgba(255, 255, 255, 0.76);
  border-radius: var(--radius-sm);
  outline: none;
  background: #fff;
  color: var(--text-dark);
  font-size: 13.5px;
  font-weight: 600;
  user-select: text;
  transition: box-shadow var(--transition), border-color var(--transition);
}

#sb::placeholder {
  color: #93a2ac;
  font-weight: 500;
}

#sb:focus {
  border-color: #fff;
  box-shadow: 0 0 0 3px rgba(99, 203, 237, 0.38);
}

/* ========== Country List ========== */
.country-list {
  min-height: 120px;
  max-height: min(46vh, 400px);
  overflow: auto;
  margin: 0 8px 0 11px;
  padding: 0 4px 6px 2px;
  border-top: 1px solid var(--map-divider);
  border-bottom: 1px solid var(--map-divider);
  scrollbar-color: rgba(206, 223, 231, 0.42) transparent;
  scrollbar-width: thin;
}

.ci {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 33px;
  margin: 1px 0;
  padding: 4px 6px 4px 7px;
  border: 1px solid transparent;
  border-radius: 6px;
  color: #f6fbfd;
  cursor: pointer;
  font-size: 12.5px;
  transition: background var(--transition), border-color var(--transition), transform var(--transition);
}

.ci:hover {
  border-color: rgba(127, 216, 241, 0.24);
  background: var(--map-ink-hover);
}

.ci:active {
  transform: scale(0.985);
}

.ci .ci-name {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 8px;
}

.country-flag {
  display: block;
  width: 21px;
  height: 15px;
  flex: 0 0 auto;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 2px;
  object-fit: cover;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.22);
}

.country-flag[hidden] {
  display: none;
}

.ci .ci-name span:first-of-type {
  overflow: hidden;
  min-width: 0;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-weight: 650;
}

.ci .ci-area {
  flex: 0 0 auto;
  color: var(--map-ink-muted);
  font-size: 11px;
  font-weight: 500;
}

.ci .ab {
  display: grid;
  width: 22px;
  height: 22px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 50%;
  color: var(--accent);
  font-size: 17px;
  font-weight: 400;
  line-height: 1;
  transition: background var(--transition), color var(--transition), transform var(--transition);
}

.ci:hover .ab {
  background: var(--accent-dim);
  color: #d5f8ff;
  transform: scale(1.05);
}

/* ========== Selected Countries ========== */
.selected-panel {
  margin: 8px 16px 0;
  padding: 0 0 3px;
}

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

.sp-header h3 {
  color: var(--map-ink-muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.45px;
}

.clear-all {
  padding: 3px 0;
  border: 0;
  background: transparent;
  color: #f08b8b;
  cursor: pointer;
  font-size: 11px;
  font-weight: 650;
}

.clear-all:hover {
  color: #ffc2c2;
}

.selected-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  list-style: none;
}

.selected-list li {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 3px 6px;
  border: 1px solid var(--map-divider);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.06);
  color: #eef8fc;
  cursor: pointer;
  font-size: 11.5px;
  transition: background var(--transition), border-color var(--transition);
  animation: chip-in 0.2s ease-out;
}

.selected-list li:hover {
  border-color: rgba(127, 216, 241, 0.34);
  background: rgba(255, 255, 255, 0.1);
}

@keyframes chip-in {
  from { opacity: 0; transform: translateY(-3px); }
}

.selected-list li .cd {
  width: 7px;
  height: 7px;
  flex: 0 0 auto;
  border-radius: 50%;
}

.selected-list li small {
  color: var(--map-ink-muted) !important;
}

.selected-list li .rm {
  padding: 0 1px;
  color: #f08b8b;
  cursor: pointer;
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
  opacity: 0.75;
}

.selected-list li .rm:hover {
  opacity: 1;
}

/* ========== Comparison ========== */
.comparison-card {
  margin-top: 8px;
  padding: 8px 10px;
  border: 1px solid var(--map-divider);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.055);
  color: #eaf5f9;
  font-size: 11.5px;
  animation: fade-slide-in 0.25s ease-out;
}

@keyframes fade-slide-in {
  from { opacity: 0; transform: translateY(-4px); }
}

.comparison-card .cmp-title {
  margin-bottom: 6px;
  color: var(--map-ink-muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.65px;
}

.comparison-card .cmp-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 0;
}

.comparison-card .cmp-dot {
  width: 7px;
  height: 7px;
  flex: 0 0 auto;
  border-radius: 50%;
}

.comparison-card .cmp-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.comparison-card .cmp-area {
  flex: 0 0 auto;
  color: var(--map-ink-muted);
  font-size: 11px;
}

.comparison-card .cmp-verdict {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--map-divider);
  color: #9ee5f8;
  font-size: 12px;
  font-weight: 700;
  text-align: center;
}

/* ========== Actions and Footer ========== */
.sb-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  padding: 8px 16px 2px;
}

.action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  gap: 5px;
  min-height: 32px;
  padding: 6px 8px;
  border: 1px solid rgba(99, 203, 237, 0.32);
  border-radius: var(--radius-sm);
  background: transparent;
  color: #a9edff;
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
  transition: background var(--transition), border-color var(--transition), transform var(--transition);
}

.action-btn:hover {
  border-color: var(--accent);
  background: var(--accent-dim);
}

.action-btn:active {
  transform: translateY(1px);
}

.action-btn.secondary {
  border-color: var(--map-divider);
  color: var(--map-ink-muted);
}

.sb-footer {
  padding: 10px 16px 13px;
  color: var(--map-ink-muted);
  font-size: 10.5px;
}

.footer-hint {
  display: block;
  color: var(--map-ink-muted);
}

.feedback-links {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  color: var(--map-ink-muted);
  font-size: 10.5px;
}

.footer-link {
  color: #a9edff;
  font-weight: 650;
  text-decoration: none;
}

.footer-link:hover,
.footer-link:focus-visible {
  color: #d3f7ff;
}

.footer-guide-link {
  display: block;
  margin-top: 6px;
  color: #a9edff;
  font-size: 10.5px;
  font-weight: 650;
  line-height: 1.4;
  text-decoration: none;
}

.footer-guide-link:hover,
.footer-guide-link:focus-visible {
  color: #d3f7ff;
}

/* ========== Toast ========== */
#tip {
  position: fixed;
  z-index: 2000;
  bottom: 22px;
  left: 50%;
  max-width: calc(100vw - 32px);
  overflow: hidden;
  padding: 9px 17px;
  border: 1px solid rgba(28, 45, 61, 0.16);
  border-radius: var(--radius-sm);
  background: var(--map-ink);
  box-shadow: 0 7px 20px rgba(25, 42, 56, 0.28);
  color: #f3fbff;
  font-size: 12px;
  font-weight: 650;
  pointer-events: none;
  text-align: center;
  text-overflow: ellipsis;
  transform: translate(-50%, 10px);
  transition: opacity 0.24s ease, transform 0.24s ease;
  white-space: nowrap;
  opacity: 0;
}

#tip.on {
  transform: translate(-50%, 0);
  opacity: 1;
}

/* ========== Leaflet Controls ========== */
.leaflet-top.leaflet-right {
  top: 102px;
  right: 16px;
}

.leaflet-control-zoom {
  overflow: hidden;
  margin: 0 !important;
  border: 0 !important;
  border-radius: var(--radius) !important;
  box-shadow: 0 6px 18px rgba(25, 42, 56, 0.24) !important;
}

.leaflet-control-zoom a {
  display: grid !important;
  width: 40px !important;
  height: 40px !important;
  place-items: center;
  border: 0 !important;
  border-bottom: 1px solid var(--map-divider) !important;
  background: var(--map-ink) !important;
  color: #fff !important;
  font-size: 24px !important;
  font-weight: 500 !important;
  line-height: 1 !important;
  transition: background var(--transition), color var(--transition);
}

.leaflet-control-zoom a:last-child {
  border-bottom: 0 !important;
}

.leaflet-control-zoom a:hover {
  background: var(--map-ink-hover) !important;
  color: var(--accent) !important;
}

.leaflet-control-scale-line {
  border-color: rgba(28, 45, 61, 0.5) !important;
  border-top: 0 !important;
  background: rgba(255, 255, 255, 0.72) !important;
  color: var(--text-dark) !important;
  font-weight: 650;
}

/* ========== Mobile ========== */
.panel-toggle {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 1001;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--map-ink);
  box-shadow: 0 5px 16px rgba(25, 42, 56, 0.28);
  color: #fff;
  cursor: pointer;
  font-size: 20px;
  transition: background var(--transition), transform var(--transition);
}

.panel-toggle:hover {
  background: var(--map-ink-hover);
  color: var(--accent);
}

.panel-toggle:active {
  transform: scale(0.94);
}

@media (max-width: 768px) {
  #sidebar {
    width: 280px;
  }
}

@media (max-width: 600px) {
  .panel-toggle {
    display: grid;
    place-items: center;
  }

  #sidebar {
    top: 59px;
    left: 8px;
    width: min(302px, calc(100vw - 16px));
    max-height: calc(100vh - 70px);
    max-height: calc(100dvh - 70px);
    transform: translateX(-112%);
    opacity: 0;
    pointer-events: none;
  }

  #sidebar.open {
    transform: translateX(0);
    opacity: 1;
    pointer-events: auto;
  }

  .sidebar-inner {
    border-radius: var(--radius);
  }

  .leaflet-top.leaflet-right {
    top: 12px;
    right: 10px;
  }

  .leaflet-control-zoom a {
    width: 36px !important;
    height: 36px !important;
    font-size: 22px !important;
  }

  .country-list {
    max-height: 180px;
  }

  .sb-header {
    padding: 13px 16px 7px;
  }

  .sb-search {
    margin: 5px 14px 10px;
  }

  .selected-panel,
  .sb-actions,
  .sb-footer {
    margin-left: 14px;
    margin-right: 14px;
  }

  .sb-actions,
  .sb-footer {
    padding-left: 0;
    padding-right: 0;
  }

  #tip {
    bottom: calc(40px + env(safe-area-inset-bottom));
  }
}

@media (max-width: 380px) {
  #sidebar {
    width: min(252px, calc(100vw - 68px));
  }

  #sb {
    font-size: 16px;
  }

  .ci {
    min-height: 40px;
    font-size: 13.5px;
  }
}

/* ========== Country Information Popup ========== */
.country-info-leaflet-popup .leaflet-popup-content-wrapper {
  overflow: hidden;
  border: 1px solid rgba(117, 213, 241, 0.25);
  border-radius: var(--radius);
  background: var(--map-ink);
  box-shadow: 0 12px 30px rgba(20, 35, 47, 0.3);
}

.country-info-leaflet-popup .leaflet-popup-tip {
  border-color: transparent;
  background: var(--map-ink);
}

.country-info-leaflet-popup .leaflet-popup-content {
  width: auto !important;
  margin: 0;
  color: var(--text);
  line-height: normal;
}

.country-info-leaflet-popup .leaflet-popup-close-button {
  top: 9px;
  right: 9px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  color: var(--map-ink-muted);
  font-size: 19px;
  line-height: 20px;
  transition: background var(--transition), color var(--transition);
}

.country-info-leaflet-popup .leaflet-popup-close-button:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.country-info-popup {
  position: relative;
  width: 276px;
  overflow: hidden;
  padding: 16px;
  background: rgba(10, 22, 40, 0.96);
}

.country-info-header {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-right: 30px;
}

.country-rotate-button {
  position: absolute;
  top: -4px;
  right: -2px;
  display: grid;
  width: 26px;
  height: 26px;
  place-items: center;
  border: 1px solid rgba(99, 203, 237, 0.45);
  border-radius: 50%;
  background: rgba(99, 203, 237, 0.12);
  color: #a9edff;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  transition: background var(--transition), border-color var(--transition), color var(--transition), transform var(--transition);
}

.country-rotate-button.popup-rotate-left {
  top: 28px;
  right: -2px;
}

.country-rotate-button:hover,
.country-rotate-button:focus-visible {
  border-color: var(--accent);
  background: var(--accent-dim);
  color: #d5f8ff;
}

.country-rotate-button:active {
  transform: scale(0.94);
}

.country-info-title {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 8px;
}

.country-popup-flag {
  width: 25px;
  height: 18px;
  flex: 0 0 auto;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.26);
  border-radius: 2px;
  object-fit: cover;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.country-popup-flag[hidden] {
  display: none;
}

.country-info-title-text {
  display: flex;
  align-items: baseline;
  min-width: 0;
  gap: 6px;
}

.country-info-title strong {
  display: block;
  overflow: hidden;
  color: #fff;
  font-size: 18px;
  font-weight: 760;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.country-capital-name {
  flex: 0 0 auto;
  overflow: hidden;
  color: var(--map-ink-muted);
  font-size: 10.5px;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.country-capital-name::before {
  margin-right: 6px;
  color: rgba(158, 176, 189, 0.55);
  content: '·';
}

.country-info-popup > dl,
.country-info-popup > .country-learning,
.country-info-popup > .country-popup-actions {
  position: relative;
  z-index: 1;
}

.country-outline-background {
  position: absolute;
  inset: 0;
  z-index: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  opacity: 0.38;
  pointer-events: none;
}

.country-outline-background::after {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgba(10, 22, 40, 0.78), rgba(10, 22, 40, 0.2) 52%, rgba(10, 22, 40, 0.72));
  content: '';
}

.country-outline-map {
  display: block;
  width: 94%;
  height: 92%;
  max-width: none;
  color: inherit;
}

.country-outline-map path {
  fill: currentColor;
  fill-opacity: 0.42;
  stroke: currentColor;
  stroke-width: 1.8;
  vector-effect: non-scaling-stroke;
}

.country-fact-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 14px 0 12px;
}

.country-fact-stats > div {
  min-width: 0;
  padding: 8px 9px;
  border: 1px solid var(--map-divider);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.055);
}

.country-fact-stats dt {
  margin-bottom: 4px;
  color: var(--map-ink-muted);
  font-size: 10px;
  font-weight: 650;
}

.country-fact-stats dd {
  overflow: hidden;
  color: #f6fcff;
  font-size: 13px;
  font-weight: 720;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.country-learning {
  display: grid;
  gap: 8px;
  margin: 12px 0;
  padding: 10px;
  border: 1px solid rgba(99, 203, 237, 0.16);
  border-radius: var(--radius-sm);
  background: rgba(99, 203, 237, 0.055);
}

.country-learning p {
  margin: 0;
  color: var(--map-ink-muted);
  font-size: 11px;
  line-height: 1.55;
}

.country-learning-text {
  display: block;
}

.country-learning strong {
  display: block;
  margin-bottom: 2px;
  color: #a9edff;
  font-size: 10px;
  letter-spacing: 0.4px;
}

.country-facts {
  padding-top: 8px;
  border-top: 1px solid rgba(99, 203, 237, 0.14);
}

.country-facts p {
  color: #d4e1e7;
}

.country-learning-toggle {
  display: none;
  justify-self: end;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  font-size: 10px;
  font-weight: 700;
  line-height: 1.4;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.country-learning-toggle:hover,
.country-learning-toggle:focus-visible {
  background: transparent;
  color: #d5f8ff;
}

.country-popup-actions {
  display: flex;
  gap: 7px;
}

.country-popup-actions button {
  flex: 1;
  min-height: 31px;
  padding: 6px 7px;
  border-radius: var(--radius-sm);
  background: transparent;
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}

.country-popup-actions .popup-move-cn {
  border: 1px solid rgba(99, 203, 237, 0.35);
  color: #a9edff;
}

.country-popup-actions .popup-move-cn:hover {
  border-color: var(--accent);
  background: var(--accent-dim);
  color: #d5f8ff;
}

.country-popup-actions .popup-rm {
  border: 1px solid rgba(241, 110, 110, 0.35);
  color: #ffafaf;
}

.country-popup-actions .popup-rm:hover {
  border-color: #ff9494;
  background: rgba(241, 110, 110, 0.15);
  color: #ffe1e1;
}

.leaflet-interactive.country-shape {
  cursor: pointer;
}

@media (max-width: 380px) {
  .country-info-popup {
    width: 248px;
    padding: 14px;
  }

  .country-outline-map {
    width: 94%;
    height: 90%;
  }
}

/* ========== Labels ========== */
.country-label {
  border: 0 !important;
  background: transparent !important;
  color: #2b3a44;
  font-size: 10px;
  font-weight: 650;
  letter-spacing: 0.4px;
  pointer-events: none;
  text-align: center;
  text-shadow: 0 0 2px rgba(255,255,255,0.9), 0 0 5px rgba(255,255,255,0.55);
  white-space: nowrap;
}

.country-label span {
  display: inline-block;
  transform: translate(-50%, -50%);
}

@media print {
  body { background: #fff; }
  #sidebar, #tip, #loading, .panel-toggle, #inset-map { display: none !important; }
  #map { width: 100vw; height: 100vh; }
}
