/* 中国制霸 · China Experience — paper full-bleed + mobile-first */

:root {
  --paper: #f0ebe3;
  --paper-soft: #f7f3ec;
  --surface: #e8e2d8;
  --ink: #141413;
  --ink-soft: #252523;
  --body: #3d3d3a;
  --muted: #6c6a64;
  --muted-light: #8e8b82;
  --hairline: color-mix(in srgb, #2c2a26 12%, transparent);
  --line: color-mix(in srgb, #2c2a26 16%, transparent);
  --accent: #1890ff;
  --accent-dark: #096dd9;
  --on-dark: #f7f3ec;
  --shadow: 0 1px 2px rgba(20, 20, 19, 0.06);
  --shadow-lg: 0 10px 30px rgba(20, 20, 19, 0.12);
  --radius: 12px;
  --radius-sm: 8px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);

  --lv-5: #b85c5c;
  --lv-4: #c8885a;
  --lv-3: #c9a85c;
  --lv-2: #6a9a92;
  --lv-1: #8a9eb5;
  --lv-0: #f7f5f0;

  --map-bg: #f0ebe3;
  --map-stroke: #2c2a26;
  --font: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Segoe UI",
    "Microsoft YaHei", sans-serif;

  --topbar-h: 52px;
  --footer-h: 40px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  height: 100%;
  margin: 0;
  background: var(--map-bg);
}

html {
  background: var(--map-bg);
}

body {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 100%;
  min-height: 100dvh;
  overflow: hidden;
  font-family: var(--font);
  color: var(--ink);
  background: var(--map-bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  color: var(--accent-dark);
}

button,
.btn {
  font: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

/* —— topbar —— */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: var(--topbar-h);
  padding: calc(8px + var(--safe-t)) calc(16px + var(--safe-r)) 8px
    calc(16px + var(--safe-l));
  border-bottom: 1px solid var(--hairline);
  background: var(--map-bg);
  z-index: 5;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}

.brand strong {
  font-size: 1rem;
  font-weight: 650;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.brand .tag {
  white-space: nowrap;
}

.tag {
  color: var(--muted);
  font-size: 0.86rem;
}

.actions {
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  justify-content: flex-end;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  min-width: 40px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--paper-soft);
  color: var(--ink-soft);
  font-size: 0.88rem;
  font-weight: 500;
  box-shadow: none;
  text-decoration: none;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
  touch-action: manipulation;
  user-select: none;
}

.btn:hover {
  background: var(--surface);
}

.btn:active {
  background: var(--surface);
}

.btn-primary {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--on-dark);
}

.btn-primary:hover,
.btn-primary:active {
  background: var(--ink-soft);
  border-color: var(--ink-soft);
  color: var(--on-dark);
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}

.btn-ghost:hover,
.btn-ghost:active {
  background: var(--surface);
  color: var(--ink);
}

/* —— stage / map —— */
.stage {
  position: relative;
  min-height: 0;
  padding: 0;
  background: var(--map-bg);
}

.map-host {
  height: 100%;
  width: 100%;
  margin: 0;
  border-radius: 0;
  overflow: hidden;
  background: var(--map-bg);
  border: none;
  box-shadow: none;
}

.map-host svg {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.map-host text {
  font-family: var(--font);
  fill: var(--ink-soft);
  font-size: 28px;
  pointer-events: none;
}

.map-host #title,
.map-host #score {
  font-size: 44px;
  font-weight: 650;
  fill: var(--ink);
}

.map-host .fs24 {
  font-size: 22px;
}

.map-host #labels text {
  font-size: 28px;
  font-weight: 500;
  fill: var(--body);
}

.map-host #legend text {
  font-size: 22px;
  fill: var(--body);
  font-weight: 500;
}

.map-host #credit {
  font-size: 22px;
  fill: var(--muted-light);
}

.map-host #regions path {
  fill: var(--lv-0);
  stroke: var(--map-stroke);
  stroke-width: 2.5;
  stroke-linejoin: round;
  stroke-linecap: round;
  fill-rule: evenodd;
  cursor: pointer;
  transition: fill 0.16s ease, opacity 0.16s ease;
  pointer-events: auto;
}

.map-host #regions path:hover {
  opacity: 0.92;
}

.map-host #regions path[data-level="5"] {
  fill: var(--lv-5);
}
.map-host #regions path[data-level="4"] {
  fill: var(--lv-4);
}
.map-host #regions path[data-level="3"] {
  fill: var(--lv-3);
}
.map-host #regions path[data-level="2"] {
  fill: var(--lv-2);
}
.map-host #regions path[data-level="1"] {
  fill: var(--lv-1);
}
.map-host #regions path[data-level="0"],
.map-host #regions path:not([data-level]) {
  fill: var(--lv-0);
}


/* —— picker —— */
.picker {
  position: absolute;
  z-index: 6;
  min-width: 240px;
  max-width: min(320px, calc(100vw - 24px));
  padding: 0;
  border-radius: var(--radius);
  background: var(--paper-soft);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.16s ease, transform 0.16s ease;
  pointer-events: none;
}

.picker.is-open {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.picker-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  background: color-mix(in srgb, var(--surface) 80%, var(--paper-soft));
  border-bottom: 1px solid var(--hairline);
}

.picker-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.picker-icons {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

.picker-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  color: var(--muted-light);
  text-decoration: none;
  touch-action: manipulation;
}

.picker-icon:hover,
.picker-icon:active {
  background: color-mix(in srgb, var(--ink) 6%, transparent);
  color: var(--ink-soft);
}

.picker-icon.search:hover,
.picker-icon.search:active {
  color: var(--accent);
}

.picker-list {
  display: grid;
  padding: 4px 0 6px;
}

.picker-item {
  display: block;
  width: 100%;
  text-align: left;
  min-height: 44px;
  padding: 11px 16px;
  font-size: 0.95rem;
  line-height: 1.35;
  color: var(--body);
  background: transparent;
  border: 0;
  font-weight: 400;
  touch-action: manipulation;
  transition: background 0.12s ease, color 0.12s ease;
}

.picker-item:hover,
.picker-item.is-selected {
  background: var(--surface);
  color: var(--ink);
}

.picker-item.lv-5:hover,
.picker-item.lv-5.is-selected {
  background: color-mix(in srgb, var(--lv-5) 20%, var(--paper-soft));
  color: #6b2c2c;
}
.picker-item.lv-4:hover,
.picker-item.lv-4.is-selected {
  background: color-mix(in srgb, var(--lv-4) 22%, var(--paper-soft));
  color: #6b3d1f;
}
.picker-item.lv-3:hover,
.picker-item.lv-3.is-selected {
  background: color-mix(in srgb, var(--lv-3) 26%, var(--paper-soft));
  color: #5c4a1a;
}
.picker-item.lv-2:hover,
.picker-item.lv-2.is-selected {
  background: color-mix(in srgb, var(--lv-2) 22%, var(--paper-soft));
  color: #1f4a44;
}
.picker-item.lv-1:hover,
.picker-item.lv-1.is-selected {
  background: color-mix(in srgb, var(--lv-1) 24%, var(--paper-soft));
  color: #2a3d52;
}

/* —— footer —— */
.footer {
  min-height: var(--footer-h);
  padding: 8px calc(16px + var(--safe-r)) calc(10px + var(--safe-b))
    calc(16px + var(--safe-l));
  border-top: 1px solid var(--hairline);
  color: var(--muted);
  font-size: 0.8rem;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  justify-content: space-between;
  align-items: center;
  background: var(--map-bg);
}

.footer p {
  margin: 0;
}

.footer code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.82em;
  background: var(--paper-soft);
  color: var(--ink-soft);
  padding: 1px 6px;
  border-radius: 5px;
  border: 1px solid var(--hairline);
}

.hint {
  color: var(--muted-light);
}

/* —— toast / modal —— */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + var(--safe-b));
  transform: translateX(-50%);
  z-index: 20;
  max-width: calc(100vw - 32px);
  background: var(--ink);
  color: var(--on-dark);
  padding: 11px 16px;
  border-radius: 999px;
  font-size: 0.9rem;
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: max(16px, var(--safe-t)) max(16px, var(--safe-r))
    max(16px, var(--safe-b)) max(16px, var(--safe-l));
  background: rgba(20, 20, 19, 0.28);
  backdrop-filter: blur(6px);
}

.modal[hidden],
.picker[hidden],
.toast[hidden] {
  display: none !important;
}

.modal-card {
  width: min(480px, 100%);
  max-height: min(90dvh, 100%);
  overflow: auto;
  background: var(--paper-soft);
  border-radius: calc(var(--radius) + 4px);
  padding: 16px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow-lg);
  text-align: center;
  color: var(--body);
}

.modal-card img {
  display: block;
  width: 100%;
  max-height: min(58vh, 58dvh);
  object-fit: contain;
  border-radius: var(--radius-sm);
  background: var(--map-bg);
  border: 1px solid var(--hairline);
}

.modal-card p {
  margin: 12px 0 0;
  font-size: 0.9rem;
  color: var(--muted);
}

.modal-actions {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.modal-actions .btn {
  min-height: 44px;
  padding-inline: 18px;
}

/* —— mobile —— */
@media (max-width: 720px) {
  .topbar {
    gap: 10px;
    padding-top: calc(6px + var(--safe-t));
    padding-bottom: 6px;
  }

  .brand strong {
    font-size: 0.95rem;
  }

  .tag {
    display: none;
  }

  .actions {
    gap: 6px;
  }

  .btn {
    min-height: 38px;
    padding: 7px 11px;
    font-size: 0.82rem;
  }

  .map-host #title,
  .map-host #score {
    font-size: 34px;
  }

  .map-host #labels text {
    font-size: 24px;
  }

  .map-host #legend text {
    font-size: 18px;
  }

  .footer {
    font-size: 0.74rem;
    gap: 2px 10px;
  }

  /* bottom sheet style picker for easier thumb reach */
  .picker {
    position: fixed;
    left: 12px !important;
    right: 12px;
    bottom: calc(12px + var(--safe-b)) !important;
    top: auto !important;
    width: auto;
    max-width: none;
    min-width: 0;
    max-height: min(70dvh, 520px);
    overflow: auto;
    border-radius: 16px;
    transform: translateY(8px);
  }

  .picker.is-open {
    transform: translateY(0);
  }

  .picker-item {
    min-height: 48px;
    padding: 12px 18px;
    font-size: 1rem;
  }
}

@media (max-width: 420px) {
  .btn-ghost {
    display: none;
  }

  .footer .hint {
    width: 100%;
  }
}

body.is-exporting {
  cursor: wait;
}

body.is-exporting .map-host #regions path {
  pointer-events: none;
}
