:root {
  --paper: #efe4d2;
  --paper-2: #fff8ee;
  --ink: #1c211e;
  --muted: #5a615c;
  --line: #d7c6ae;
  --mark: #d23b4a;
  --axis: #0e8f86;
  --focus: #0b6e86;
  --sans: "Avenir Next", "Segoe UI", Helvetica, Arial, sans-serif;
  --serif: "Iowan Old Style", Palatino, "Palatino Linotype", Georgia, serif;
  color-scheme: light;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  background:
    radial-gradient(1200px 400px at 10% -10%, #fde7c8 0%, transparent 55%),
    radial-gradient(900px 420px at 100% 0%, #d7f0f4 0%, transparent 50%),
    var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14.5px;
  line-height: 1.4;
}

button, input, select { font: inherit; color: inherit; }

button { cursor: pointer; }

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.app {
  height: 100dvh;
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.top {
  position: relative;
  display: grid;
  grid-template-columns: minmax(150px, 190px) minmax(0, 1fr) minmax(210px, 280px);
  gap: 18px 22px;
  align-items: end;
  padding: 12px 18px 11px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(100deg, rgba(255, 236, 206, 0.9), rgba(214, 240, 245, 0.85) 58%, rgba(255, 226, 232, 0.9));
}

.eyebrow {
  margin: 0 0 3px;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: 30px;
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 0.95;
}

.hint, .summary, .aspect, .place, .north-note, .euler, .keys, .more, .fun-line {
  margin: 0;
}

.hint {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
}

.proj-title {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: baseline;
  margin: 0 0 4px;
  font-family: var(--serif);
  font-size: 20px;
}

.pill {
  font-family: var(--sans);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #085e66;
  background: #d7f4f1;
  border: 1px solid #8ed4cc;
  border-radius: 999px;
  padding: 1px 7px;
}

.pill-equal-area { color: #8a3d12; background: #ffe3c4; border-color: #f0b27a; }
.pill-equidistant { color: #1d5c32; background: #d9f5e1; border-color: #8dcea0; }
.pill-compromise { color: #5c3488; background: #efe0fa; border-color: #c9afe4; }
.pill-perspective { color: #1a4578; background: #d9e8fa; border-color: #96bce4; }
.pill-great-circles { color: #8a2348; background: #fadbe6; border-color: #e7a8bf; }
.pill-polyhedral { color: #6b3a12; background: #f8e6c8; border-color: #e2c08a; }

.summary { font-size: 14px; }

.more { margin: 6px 0 4px; font-size: 13px; }

.more a {
  color: #0b5f93;
  font-weight: 600;
}

.more a:hover { color: var(--mark); }

.text-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
  border: 1px solid #0b5f93;
  background: #f4fbff;
  color: #0b4f78;
  font-weight: 700;
  font-size: 13px;
  line-height: 1.2;
  border-radius: 999px;
  padding: 6px 12px 6px 14px;
  box-shadow: 0 1px 0 rgba(28, 33, 30, 0.12);
}

.text-btn::after {
  content: "›";
  font-size: 1.25em;
  line-height: 1;
}

.text-btn:hover {
  background: #0b5f93;
  color: white;
}

.about-btn {
  display: inline-flex;
  align-items: center;
  margin-top: 8px;
  border: 1px solid #0b5f93;
  background: #f4fbff;
  color: #0b4f78;
  font-weight: 700;
  font-size: 13px;
  border-radius: 999px;
  padding: 5px 12px;
}

.about-btn:hover { background: #0b5f93; color: white; }

.about-compact { display: none; }

.xkcd-switch {
  position: absolute;
  top: 8px;
  right: 14px;
  z-index: 4;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 4px 8px 4px 10px;
  border: 1px solid #c9afe4;
  border-radius: 999px;
  background: rgba(255, 248, 238, 0.94);
  cursor: pointer;
  user-select: none;
}

.xkcd-switch-name {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.14em;
  color: #5c3488;
}

.switch-hit {
  position: relative;
  display: block;
  width: 44px;
  height: 26px;
}

.switch-hit input {
  position: absolute;
  inset: 0;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.switch-ui {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: #d9cfc2;
  box-shadow: inset 0 0 0 1px rgba(28, 33, 30, 0.16);
  pointer-events: none;
}

.switch-ui::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: white;
  box-shadow: 0 1px 2px rgba(28, 33, 30, 0.28);
  transition: transform 120ms ease;
}

.xkcd-switch input:checked + .switch-ui { background: #6d45a0; }

.xkcd-switch input:checked + .switch-ui::after { transform: translateX(18px); }

.xkcd-switch input:focus-visible + .switch-ui {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.xkcd-switch:has(input:checked) {
  background: #f6eefe;
  border-color: #6d45a0;
}

.fun-line {
  margin-top: 6px;
  padding-left: 8px;
  border-left: 3px solid #c9afe4;
  color: #4c3568;
  font-size: 13px;
}

dialog {
  width: min(640px, calc(100vw - 28px));
  max-height: min(82dvh, 780px);
  margin: auto;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper-2);
  color: var(--ink);
  box-shadow: 0 18px 50px rgba(28, 33, 30, 0.24);
}

dialog.projection-open { width: min(760px, calc(100vw - 28px)); }

dialog.with-comic { width: min(880px, calc(100vw - 28px)); }

dialog.about-open { width: min(760px, calc(100vw - 28px)); }

dialog::backdrop { background: rgba(28, 33, 30, 0.45); }

.sheet {
  display: flex;
  flex-direction: column;
  max-height: min(82dvh, 780px);
}

.sheet-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.sheet-bar h2 {
  margin: 0;
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 600;
  line-height: 1.15;
}

.sheet-bar button {
  border: 1px solid var(--line);
  background: white;
  border-radius: 999px;
  padding: 4px 12px;
}

.sheet-body {
  overflow: auto;
  padding: 4px 16px 16px;
}

.sheet-tabs {
  position: sticky;
  top: -4px;
  z-index: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 -16px 8px;
  padding: 10px 16px 8px;
  border-bottom: 1px solid var(--line);
  background: var(--paper-2);
}

.sheet-tab {
  border: 1px solid #b7c9d4;
  background: white;
  color: #0b4f78;
  font-weight: 700;
  font-size: 13px;
  border-radius: 999px;
  padding: 6px 12px;
}

.sheet-tab[aria-selected="true"] {
  border-color: #0b5f93;
  background: #0b5f93;
  color: white;
}

.sheet-body h3 {
  margin: 14px 0 4px;
  font-family: var(--serif);
  font-size: 16px;
  font-weight: 600;
}

.math {
  margin: 4px 0 12px;
  padding: 10px 12px;
  overflow: auto;
  white-space: pre-wrap;
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.45;
}

.sheet-body p { margin: 0 0 8px; }

.sheet-body a { color: #0b5f93; font-weight: 600; }

.about-lead {
  margin: 12px 0 6px;
  font-family: var(--serif);
  font-size: 20px;
  line-height: 1.3;
}

.about-purpose { margin: 0 0 12px; }

.mark-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 0 0 10px;
}

.mark-card {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  gap: 8px;
  align-items: start;
  margin: 0;
  padding: 10px 12px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.mark-card .swatch { margin-top: 7px; }

.mark-card h3,
.move-card h3 {
  margin: 0 0 4px;
  font-family: var(--serif);
  font-size: 15px;
  font-weight: 600;
}

.mark-card p,
.move-card p { margin: 0; font-size: 13.5px; }

.move-card p + p { margin-top: 8px; }

.move-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 0 0 10px;
}

.move-card {
  margin: 0;
  padding: 10px 12px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.move-card h3 {
  font-family: var(--sans);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.move-drag { background: #fff6ea; }
.move-switch { background: #e7f6f8; }
.move-carry { background: #fde8ee; }
.move-xkcd { background: #f6eefe; }

.about-compass {
  margin: 0 0 4px;
  padding: 10px 12px;
  background: #fff8f4;
  border: 1px solid #f0b4bc;
  border-radius: 10px;
}

.xkcd-notes { font-size: 14px; }

@media (max-width: 720px) {
  .mark-grid, .move-grid { grid-template-columns: 1fr; }
}

.xkcd {
  margin: 8px 0 12px;
}

.xkcd img {
  display: block;
  width: 100%;
  height: auto;
  background: white;
  border: 1px solid var(--line);
}

.xkcd figcaption {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12.5px;
}

.aspect {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.origin-card { text-align: right; }

.origin {
  margin: 0;
  font-family: var(--serif);
  font-size: 22px;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  color: #0e5f78;
}

.place, .north-note, .euler {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.euler { font-size: 12px; margin-top: 2px; }

.proj-select-label { display: none; }

.stage {
  display: grid;
  grid-template-columns: 268px minmax(0, 1fr);
  min-height: 0;
}

.rail {
  overflow: auto;
  border-right: 1px solid var(--line);
  padding: 6px 8px 16px;
  background: linear-gradient(#fff6ea, #f3efe4 40%, #e7f3f6);
  scrollbar-width: thin;
  scrollbar-color: #c8c0b4 transparent;
}

.group-label {
  margin: 12px 8px 4px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.group-cylindrical { color: #0c6e78; }
.group-pseudocylindrical { color: #6a3d8f; }
.group-azimuthal { color: #1d4e89; }
.group-conic { color: #a14a1a; }
.group-xkcd { color: #5c3488; }

.proj-btn.xkcd-only:not([aria-pressed="true"]) { background: rgba(92, 52, 136, 0.07); }

.proj-btn {
  display: flex;
  width: 100%;
  justify-content: space-between;
  gap: 8px;
  align-items: baseline;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 5px 8px;
  border-radius: 6px;
}

.proj-btn:hover { background: rgba(28, 33, 30, 0.05); }

.proj-btn[aria-pressed="true"] {
  background: var(--ink);
  color: var(--paper-2);
}

.proj-btn .prop {
  flex: none;
  color: var(--muted);
  font-size: 11px;
}

.prop-conformal { color: #0c7c86; }
.prop-equal-area { color: #b4532a; }
.prop-equidistant { color: #2a7a45; }
.prop-compromise { color: #6d45a0; }
.prop-perspective { color: #1d4e89; }
.prop-great-circles { color: #a13258; }
.prop-polyhedral { color: #8a4b16; }

.proj-btn[aria-pressed="true"] .prop { color: #f0d7c4; }

.map-wrap {
  position: relative;
  min-width: 0;
  min-height: 0;
  background: var(--paper);
  touch-action: none;
  overscroll-behavior: none;
}

.map-wrap::before,
.map-wrap::after {
  content: "";
  position: absolute;
  background: rgba(180, 51, 34, 0.16);
  pointer-events: none;
  z-index: 1;
}

.map-wrap::before {
  left: 50%;
  top: 0;
  bottom: 0;
  width: 1px;
}

.map-wrap::after {
  top: 50%;
  left: 0;
  right: 0;
  height: 1px;
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
  touch-action: none;
}

canvas.is-dragging { cursor: grabbing; }

.reticle {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 26px;
  height: 26px;
  transform: translate(-50%, -50%);
  border: 1.5px solid var(--mark);
  border-radius: 50%;
  pointer-events: none;
  z-index: 2;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.55);
}

.reticle::before,
.reticle::after {
  content: "";
  position: absolute;
  background: var(--mark);
  left: 50%;
  top: 50%;
}

.reticle::before {
  width: 1.5px;
  height: 44px;
  transform: translate(-50%, -50%);
}

.reticle::after {
  height: 1.5px;
  width: 44px;
  transform: translate(-50%, -50%);
}

.compass {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 78px;
  height: 78px;
  border-radius: 50%;
  border: 1px solid #f0b4bc;
  background:
    radial-gradient(circle at 50% 45%, #fffdf8 0%, #ffe8ec 42%, #d9f3f1 100%);
  box-shadow: 0 0 0 3px rgba(255, 248, 238, 0.72);
  display: grid;
  place-items: center;
  pointer-events: none;
  z-index: 3;
}

.rose {
  position: relative;
  width: 68px;
  height: 68px;
  transform-origin: center;
}

.needle {
  position: absolute;
  left: 50%;
  top: 18px;
  width: 2px;
  height: 32px;
  transform: translateX(-50%);
  background: linear-gradient(#d23b4a 0 46%, #1c211e 46% 100%);
  border-radius: 1px;
}

.dir {
  position: absolute;
  left: 50%;
  top: 50%;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  color: #1d4e89;
}

.dir[data-dir="n"] {
  color: #d23b4a;
  transform: translate(-50%, -50%) translateY(-24px);
}

.dir[data-dir="e"] { transform: translate(-50%, -50%) translateX(24px); }
.dir[data-dir="s"] { color: #1c211e; transform: translate(-50%, -50%) translateY(24px); }
.dir[data-dir="w"] { transform: translate(-50%, -50%) translateX(-24px); }

.pole-label {
  font-family: var(--serif);
  font-size: 18px;
  color: var(--mark);
}

.legend {
  position: absolute;
  left: 12px;
  bottom: 12px;
  margin: 0;
  padding: 8px 10px;
  list-style: none;
  background: rgba(255, 248, 238, 0.92);
  border: 1px solid #e7c9a4;
  border-radius: 8px;
  font-size: 12px;
  z-index: 3;
  pointer-events: none;
}

.legend li {
  display: flex;
  gap: 8px;
  align-items: center;
  margin: 3px 0;
}

.swatch {
  width: 22px;
  height: 0;
  border-top: 2px solid var(--ink);
  flex: none;
}

.swatch.grat { border-top-color: rgba(32, 74, 102, 0.7); border-top-width: 1px; }
.swatch.geo { border-top-color: var(--mark); }
.swatch.axis { border-top: 2px dashed var(--axis); height: 0; }
.swatch.circ { border-top-color: #243a82; border-radius: 50%; width: 12px; height: 12px; border: 1.5px solid #243a82; }
.swatch.moved {
  width: 16px;
  height: 11px;
  border: 1.5px dashed #b02a36;
  background: repeating-linear-gradient(-45deg, transparent, transparent 2px, rgba(176, 42, 54, 0.85) 2px, rgba(176, 42, 54, 0.85) 3.5px);
}

.coach, .tip, .status {
  position: absolute;
  z-index: 4;
}

.coach {
  left: 50%;
  top: calc(50% + 34px);
  transform: translateX(-50%);
  width: max-content;
  max-width: min(440px, calc(100% - 24px));
  margin: 0;
  padding: 6px 10px;
  text-align: center;
  background: rgba(246, 241, 231, 0.94);
  border: 1px solid var(--line);
  border-radius: 8px;
  pointer-events: none;
}

.tip {
  margin: 0;
  padding: 4px 8px;
  background: var(--ink);
  color: var(--paper-2);
  border-radius: 5px;
  font-size: 12.5px;
  pointer-events: none;
  white-space: nowrap;
}

.status {
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  color: var(--muted);
  pointer-events: none;
}

.status.error {
  pointer-events: auto;
  background: rgba(230, 223, 210, 0.94);
  color: var(--ink);
  padding: 24px;
  text-align: center;
}

.bottom {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px 14px 10px;
  border-top: 1px solid var(--line);
  background: linear-gradient(90deg, #e5f6f3, #fff3df 42%, #fde8ee);
}

.places {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.places button,
.controls button {
  border: 1px solid #f0b98a;
  background: #fff6ea;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12.5px;
}

.places button:nth-child(3n + 2) { background: #e7f6fb; border-color: #9ecae0; }
.places button:nth-child(3n) { background: #fde8ee; border-color: #f0b4c4; }

.places button:hover,
.controls button:hover { border-color: var(--ink); }

#move-country[aria-pressed="true"] {
  background: var(--ink);
  color: var(--paper-2);
  border-color: var(--ink);
}

.controls button:disabled {
  opacity: 0.45;
  cursor: default;
}

.move-note {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

canvas.is-moving.is-over-country { cursor: grab; }

.bottom-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  align-items: center;
  justify-content: space-between;
}

.center-form, .controls, .check, .zoom-label {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.center-form input[type="number"] {
  width: 92px;
  padding: 4px 6px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: white;
}

.center-form button {
  background: #0e5f78;
  color: #f7fbff;
  border: 1px solid #0e5f78;
  border-radius: 5px;
  padding: 4px 12px;
}

.zoom-label input { width: 120px; accent-color: var(--ink); }

.zoom-label span, .keys {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-size: 12.5px;
}

.form-error {
  margin: 0;
  color: var(--mark);
  font-size: 13px;
}

.noscript {
  margin: 0;
  padding: 12px 16px;
  background: #fff4f4;
  color: var(--ink);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

@media (max-width: 860px) {
  .app {
    height: 100dvh;
    min-height: 0;
    grid-template-rows: minmax(0, 42dvh) minmax(0, 1fr) auto;
  }
  .top, .stage, .bottom, .places, .proj-select-label, .proj-select-label select, .proj-copy {
    min-width: 0;
  }
  .top {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto auto;
    grid-template-areas:
      "brand"
      "copy"
      "picker"
      "origin";
    gap: 6px;
    padding: 8px 12px;
    height: 100%;
    min-height: 0;
    overflow: hidden;
    align-items: stretch;
  }
  .brand { grid-area: brand; padding-right: 118px; }
  .proj-copy { grid-area: copy; overflow: auto; }
  .origin-card { grid-area: origin; text-align: left; }
  .hint { display: none; }
  .coach {
    left: 12px;
    top: 10px;
    transform: none;
    max-width: calc(100% - 96px);
    text-align: left;
  }
  .stage {
    display: block;
    height: 100%;
    min-height: 0;
  }
  .map-wrap { height: 100%; }
  .rail { display: none; }
  .proj-select-label {
    grid-area: picker;
    display: flex;
    gap: 8px;
    align-items: center;
  }
  .proj-select-label select {
    flex: 1;
    padding: 6px;
    border: 1px solid var(--line);
    border-radius: 5px;
    background: white;
  }
  h1 { font-size: 26px; }
  .origin { font-size: 20px; }
  .places {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 2px;
    scrollbar-width: thin;
  }
  .places button { flex: none; }
  .legend { max-width: calc(100% - 24px); }
  .compass { width: 64px; height: 64px; }
  .rose { width: 56px; height: 56px; }
  .needle { top: 16px; height: 24px; }
  .dir { font-size: 11px; }
}

@media (max-width: 860px) and (max-height: 520px) {
  .app { grid-template-rows: minmax(0, 38%) minmax(0, 1fr) auto; }
  .top {
    grid-template-rows: auto auto auto;
    grid-template-areas:
      "copy"
      "picker"
      "origin";
  }
  .brand, .summary, .aspect, .fun-line, .euler, .place, .north-note, .keys, .move-note, .proj-title { display: none; }
  .proj-copy {
    padding-right: 118px;
    overflow: hidden;
  }
  .more { margin: 0; }
  .text-btn {
    padding: 4px 10px;
    white-space: nowrap;
  }
  .about-compact { display: inline-flex; }
  .controls .about-btn {
    margin-top: 0;
    border-color: #0b5f93;
    background: #f4fbff;
    color: #0b4f78;
    font-weight: 700;
  }
}
