:root {
  color-scheme: light;
  --ink: #17212b;
  --muted: #596673;
  --line: rgba(23, 33, 43, .14);
  --panel: rgba(255, 255, 255, .9);
  --land: #fac591;
  --land-edge: rgba(255, 255, 255, .86);
  --active: #e03131;
  --active-dark: #9d1b1b;
  --focus: #0b7285;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  height: 100vh;
  overflow: hidden;
  font-family: "Segoe UI", "Noto Sans TC", system-ui, sans-serif;
  background: #d9f0f2;
  color: var(--ink);
}

button,
select {
  font: inherit;
}

.app {
  height: 100vh;
  padding: 4px;
  display: grid;
  min-height: 0;
}

.map-shell {
  height: calc(100vh - 8px);
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
  border: 1px solid var(--line);
  background: #d9f0f2;
  box-shadow: 0 18px 40px rgba(16, 82, 91, .12);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 18px;
  background: var(--panel);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.topbar {
  position: relative;
  display: grid;
  grid-template-columns: minmax(300px, .9fr) minmax(260px, 440px) max-content;
}

.topbar > div:first-child {
  min-width: 0;
}

.home-link {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  margin-top: 0;
  padding: 0 12px;
  color: var(--muted);
  background: rgba(255, 255, 255, .74);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 13px;
  font-weight: 750;
  text-decoration: none;
  white-space: nowrap;
}

.home-link:hover {
  color: var(--active);
  border-color: rgba(224, 49, 49, .45);
}

.home-link:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.eyebrow {
  margin: 0 0 2px;
  color: #087f5b;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  max-width: 520px;
  color: var(--muted);
  font-size: clamp(14px, 1.45vw, 18px);
  font-weight: 650;
  line-height: 1.3;
  letter-spacing: 0;
}

.toolbar {
  display: flex;
  align-items: end;
  gap: 10px;
  justify-self: end;
  flex-shrink: 0;
}

.country-picker,
.shape-picker {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
}

.country-picker {
  width: 280px;
}

.shape-picker {
  width: 136px;
  align-self: end;
}

.shape-buttons {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
}

.shape-button {
  height: 38px;
  min-width: 0;
  padding: 0 6px;
  font-weight: 800;
}

.shape-button.is-active {
  border-color: #087f8c;
  background: #087f8c;
  color: #ffffff;
}

select {
  width: 100%;
  min-width: 0;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 34px 0 10px;
  background: white;
  color: var(--ink);
}

button {
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 14px;
  background: #ffffff;
  color: var(--ink);
  cursor: pointer;
}

button:hover,
select:hover {
  border-color: rgba(23, 33, 43, .32);
}

button:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(11, 114, 133, .28);
  outline-offset: 2px;
}

#resetButton,
#rotateLeftButton,
#rotateRightButton,
#colorButton,
#nameButton,
#zoomOutButton,
#zoomInButton {
  width: 42px;
  padding: 0;
  display: grid;
  place-items: center;
  font-size: 22px;
}

#resetAllButton {
  min-width: 82px;
  font-weight: 700;
}

#languageToggleButton {
  min-width: 84px;
  font-weight: 800;
  white-space: nowrap;
}

#helpButton {
  width: 42px;
  padding: 0;
  display: grid;
  place-items: center;
  font-weight: 900;
}

#globeButton {
  min-width: 76px;
  background: #17212b;
  color: #ffffff;
  font-weight: 700;
}

.map-stage {
  position: relative;
  min-height: 0;
  background: #c8eef3;
}

.mobile-country-summary {
  display: none;
}

.map-stage.globe-active #map,
.map-stage.globe-active .readout,
.map-stage.globe-active .map-tools {
  filter: blur(2px);
  opacity: .28;
}

#map {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
  touch-action: none;
  cursor: grab;
}

#map.is-panning {
  cursor: grabbing;
}

.ocean {
  fill: url(#oceanGradient);
}

.water-lines {
  fill: url(#waterLines);
  opacity: .35;
}

.graticule-line {
  fill: none;
  stroke: rgba(0, 122, 140, .12);
  stroke-width: 1;
}

.equator-line {
  fill: none;
  stroke: #e03131;
  stroke-linecap: round;
  stroke-width: 3;
  vector-effect: non-scaling-stroke;
}

.graticule-label {
  fill: rgba(0, 122, 140, .44);
  font-size: 12px;
  user-select: none;
}

.land {
  fill: var(--area-color, var(--land));
  stroke: var(--land-edge);
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
}

.political-area {
  cursor: grab;
  filter: drop-shadow(0 1px 0 rgba(55, 116, 128, .2));
}

.political-area:hover,
.selected-area,
.selected-country .svg-country {
  stroke: #ffffff;
  stroke-width: 3.2;
}

.political-area:active {
  cursor: grabbing;
}

.country-group {
  cursor: grab;
}

.country-group:active {
  cursor: grabbing;
}

.svg-country {
  fill: var(--area-color, var(--land));
  stroke: rgba(255, 255, 255, .74);
  stroke-linejoin: round;
  stroke-width: 1.2;
  vector-effect: non-scaling-stroke;
}

.country-hit-target {
  fill: none;
  pointer-events: stroke;
  stroke: rgba(0, 0, 0, 0);
  stroke-width: 22;
  vector-effect: non-scaling-stroke;
}

.svg-country.is-shape-hidden {
  display: none;
}

.equal-area-shape {
  fill: var(--area-color, var(--land));
}

.map-label {
  fill: rgba(255, 255, 255, .95);
  font-size: 15px;
  font-weight: 700;
  paint-order: stroke;
  pointer-events: none;
  stroke: rgba(0, 91, 103, .2);
  stroke-width: 3px;
  text-anchor: middle;
  user-select: none;
}

.map-label-large {
  font-size: 34px;
  font-weight: 500;
}

.active-country {
  fill: var(--active-fill, var(--active));
  stroke: #ffffff;
  stroke-width: 4;
  vector-effect: non-scaling-stroke;
  cursor: grab;
  filter: drop-shadow(0 12px 16px rgba(45, 72, 77, .34));
}

.active-country:active {
  cursor: grabbing;
}

.country-label {
  fill: #ffffff;
  dominant-baseline: central;
  paint-order: stroke;
  stroke: rgba(0, 74, 84, .38);
  stroke-width: 5px;
  font-weight: 800;
  font-size: 18px;
  text-anchor: middle;
  pointer-events: none;
  user-select: none;
}

.pinned-country-label {
  fill: #ffffff;
  dominant-baseline: central;
  paint-order: stroke;
  stroke: rgba(0, 74, 84, .5);
  stroke-width: 5px;
  font-size: 15px;
  font-weight: 900;
  pointer-events: none;
  text-anchor: middle;
  user-select: none;
}

.country-label-leader,
.pinned-country-label-leader {
  fill: none;
  stroke: rgba(0, 74, 84, .55);
  stroke-linecap: round;
  stroke-width: 2;
  pointer-events: none;
  vector-effect: non-scaling-stroke;
}

.readout {
  position: absolute;
  right: 18px;
  top: 18px;
  width: min(300px, calc(100% - 36px));
  display: grid;
  gap: 8px;
}

.map-tools {
  position: absolute;
  right: 18px;
  top: 292px;
  z-index: 2;
  width: min(300px, calc(100% - 36px));
  display: flex;
  align-items: end;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  pointer-events: auto;
}

.map-tools button {
  background: rgba(255, 255, 255, .86);
  border-color: rgba(23, 33, 43, .14);
  backdrop-filter: blur(8px);
}

.map-tools button.is-active {
  border-color: #087f8c;
  background: #087f8c;
  color: #ffffff;
}

#equatorButton {
  min-width: 44px;
  padding: 0 10px;
  color: #c92a2a;
  font-weight: 900;
}

#nameButton {
  width: auto;
  min-width: 58px;
  padding: 0 10px;
  color: #087f8c;
  font-size: 13px;
  font-weight: 900;
}

#nameButton.is-active {
  color: #ffffff;
}

#colorButton {
  position: relative;
  width: auto;
  min-width: 58px;
  padding: 0 10px 0 24px;
  color: #17212b;
  font-size: 13px;
  font-weight: 900;
}

#colorButton::before {
  content: "";
  position: absolute;
  left: 9px;
  top: 50%;
  width: 10px;
  height: 20px;
  border: 1px solid rgba(23, 33, 43, .18);
  border-radius: 5px;
  background: var(--selected-color, #e03131);
  transform: translateY(-50%);
}

.help-dialog {
  width: min(520px, calc(100vw - 32px));
  max-height: min(760px, calc(100vh - 32px));
  overflow: auto;
  border: 1px solid rgba(23, 33, 43, .16);
  border-radius: 8px;
  padding: 22px;
  color: var(--ink);
  box-shadow: 0 24px 80px rgba(12, 58, 70, .28);
}

.help-dialog::backdrop {
  background: rgba(12, 58, 70, .32);
  backdrop-filter: blur(3px);
}

.help-dialog h2 {
  margin: 0 42px 14px 0;
  color: #087f8c;
  font-size: 24px;
}

.help-dialog h3 {
  margin: 16px 0 8px;
  color: var(--ink);
  font-size: 16px;
}

.help-dialog p {
  margin: 0 0 12px;
  color: var(--muted);
  line-height: 1.55;
}

.help-close {
  position: absolute;
  right: 12px;
  top: 12px;
  width: 36px;
  padding: 0;
  display: grid;
  place-items: center;
  font-size: 24px;
}

.selected-country-name {
  position: static;
  align-self: center;
  justify-self: start;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  transform: none;
  border: 1px solid rgba(255, 255, 255, .84);
  border-radius: 8px;
  background: rgba(255, 255, 255, .78);
  backdrop-filter: blur(8px);
  color: #087f8c;
  font-size: clamp(18px, 2.2vw, 30px);
  font-weight: 800;
  line-height: 1.05;
  overflow: hidden;
  padding: 7px 16px 9px;
  pointer-events: none;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.globe-demo {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: radial-gradient(circle at center, rgba(231, 248, 250, .88), rgba(133, 211, 224, .74));
  opacity: 0;
  pointer-events: none;
  transition: opacity .28s ease;
}

.globe-demo.is-active {
  opacity: 1;
  pointer-events: auto;
}

.globe-close {
  position: absolute;
  right: 18px;
  top: 18px;
  z-index: 2;
  width: 42px;
  padding: 0;
  display: grid;
  place-items: center;
  border-color: rgba(23, 33, 43, .18);
  background: rgba(255, 255, 255, .86);
  font-size: 28px;
  line-height: 1;
}

.globe-copy {
  position: absolute;
  left: 50%;
  top: 22px;
  transform: translateX(-50%);
  color: #087f8c;
  font-size: clamp(14px, 2vw, 22px);
  font-weight: 800;
  text-align: center;
}

.globe-sphere {
  position: relative;
  width: min(58vmin, 560px);
  aspect-ratio: 1;
  overflow: hidden;
  border-radius: 50%;
  background: #b5e5ed;
  box-shadow: 0 28px 70px rgba(15, 88, 102, .34), inset -26px -20px 48px rgba(12, 58, 70, .24);
  transform-origin: center;
}

.globe-demo.is-active .globe-sphere {
  animation: globeFoldIn 1.25s cubic-bezier(.2, .8, .2, 1) both;
}

.globe-map-strip {
  position: absolute;
  inset: 0;
  display: flex;
  width: 300%;
  height: 100%;
  animation: globeSpin 16s linear infinite;
  transform: translateX(-33.333%);
}

.globe-map-strip svg {
  width: 33.333%;
  height: 100%;
  opacity: .95;
  flex: 0 0 33.333%;
}

.globe-shade,
.globe-highlight {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  pointer-events: none;
}

.globe-shade {
  background:
    radial-gradient(circle at 32% 28%, rgba(255, 255, 255, .1), transparent 30%),
    radial-gradient(circle at 72% 60%, transparent 34%, rgba(0, 39, 52, .32) 100%),
    linear-gradient(90deg, rgba(0, 60, 72, .22), transparent 32%, transparent 68%, rgba(0, 37, 48, .34));
}

.globe-highlight {
  box-shadow: inset 18px 14px 28px rgba(255, 255, 255, .35), inset -28px -18px 42px rgba(0, 47, 61, .18);
}

@keyframes globeFoldIn {
  0% {
    border-radius: 8px;
    opacity: .2;
    transform: scaleX(1.6) scaleY(.72);
  }
  58% {
    border-radius: 38%;
    opacity: 1;
    transform: scaleX(1.08) scaleY(.94);
  }
  100% {
    border-radius: 50%;
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes globeSpin {
  from {
    transform: translateX(-33.333%);
  }
  to {
    transform: translateX(-66.666%);
  }
}

.readout div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid rgba(255, 255, 255, .84);
  border-radius: 8px;
  background: rgba(255, 255, 255, .76);
  backdrop-filter: blur(8px);
}

.readout span {
  color: var(--muted);
  font-size: 13px;
}

.readout strong {
  font-size: 22px;
  font-variant-numeric: tabular-nums;
}

.map-title {
  fill: #0891a4;
  font-size: 34px;
  font-weight: 800;
  text-anchor: middle;
  user-select: none;
}

@media (max-width: 980px) {
  .topbar {
    display: flex;
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar {
    justify-self: stretch;
    flex-wrap: wrap;
  }

  .country-picker {
    width: min(280px, 100%);
  }

  .shape-picker {
    width: min(180px, 100%);
  }

  .selected-country-name {
    width: 100%;
    max-width: none;
  }
}

@media (max-width: 760px) {
  .app {
    padding: 0;
  }

  .map-shell {
    height: 100vh;
    min-height: 0;
    border: 0;
  }

  .topbar {
    display: flex;
    align-items: stretch;
    flex-direction: column;
    gap: 12px;
    padding: 14px;
  }

  .topbar > div:first-child {
    order: 1;
  }

  .toolbar {
    order: 2;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    align-items: stretch;
    flex-wrap: wrap;
    gap: 8px;
  }

  .country-picker {
    order: 6;
    grid-column: 1 / -1;
    width: 100%;
  }

  .country-picker span {
    font-size: 13px;
  }

  select {
    width: 100%;
    min-width: 0;
    height: 48px;
    font-size: 16px;
  }

  #languageToggleButton,
  #resetAllButton,
  #globeButton,
  #helpButton {
    width: 100%;
    min-width: 0;
    height: 48px;
    padding: 0 8px;
    font-size: 18px;
  }

  #languageToggleButton {
    order: 1;
  }

  #resetAllButton {
    order: 2;
  }

  #globeButton {
    order: 3;
  }

  #helpButton {
    order: 4;
    font-size: 24px;
  }

  .selected-country-name {
    display: none;
  }

  .mobile-country-summary {
    position: absolute;
    left: 12px;
    right: 12px;
    top: 8px;
    z-index: 3;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border: 1px solid rgba(255, 255, 255, .84);
    border-radius: 8px;
    background: rgba(255, 255, 255, .8);
    backdrop-filter: blur(8px);
  }

  .mobile-country-summary span {
    min-width: 0;
    overflow: hidden;
    color: #087f8c;
    font-size: 18px;
    font-weight: 900;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-country-summary strong {
    color: var(--ink);
    font-size: 15px;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
  }

  .readout {
    left: 12px;
    right: 12px;
    top: 58px;
    width: auto;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .readout div:nth-child(4) {
    display: none;
  }

  .map-tools {
    left: 12px;
    right: 12px;
    top: 130px;
    width: auto;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 8px;
    justify-content: stretch;
  }

  .map-tools button,
  .shape-button {
    width: 100%;
    height: 44px;
    min-width: 0;
    padding: 0;
  }

  #equatorButton,
  #resetButton,
  #rotateLeftButton,
  #rotateRightButton {
    grid-column: span 1;
  }

  #nameButton,
  #colorButton {
    grid-column: span 2;
  }

  #colorButton {
    padding: 0 8px 0 22px;
  }

  .shape-picker {
    grid-column: span 3;
    width: auto;
  }

  #zoomOutButton,
  #zoomInButton {
    grid-column: span 1;
  }

  .readout div {
    display: grid;
    gap: 2px;
    padding: 8px;
  }

  .readout span {
    font-size: 11px;
  }

  .readout strong {
    font-size: 16px;
  }

  .map-title {
    font-size: 24px;
  }
}
