:root {
  --paper: #efeae1;
  --ink: #1b1a17;
  --muted: #5c574f;
  --line: #d5cec2;
  --tray: #2a3340;
  --cream: #f4efe6;
  --white: #fffcf7;
  --seal: #8e2f28;
  --font: "Figtree", "Avenir Next", "Segoe UI", sans-serif;
  --serif: "Fraunces", "Iowan Old Style", Palatino, serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(900px 420px at 0% -10%, #f7f3eb 0%, transparent 55%),
    var(--paper);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
}

.top {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px 24px;
  padding: 28px 28px 8px;
}

.display-field {
  margin-left: auto;
  align-items: flex-end;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--seal);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

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

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 16px 18px;
  align-items: start;
  padding: 18px 28px 0;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.field[hidden],
.hint[hidden] {
  display: none;
}

.field > span,
.field > label,
.field-head {
  min-height: 22px;
}

.field > span,
.field > label {
  display: flex;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

select,
.amount-box,
.modes button {
  height: 46px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--white);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
}

select {
  min-width: 220px;
  padding: 0 12px;
}

.amount-box {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 220px;
  padding: 0 12px;
}

.symbol {
  color: var(--seal);
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 600;
  line-height: 1;
}

.amount-box input {
  width: 140px;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-family: var(--serif);
  font-size: 28px;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  outline: none;
}

.amount-box input::placeholder {
  color: #b3ab9f;
}

.modes {
  display: flex;
  gap: 6px;
}

.modes button {
  padding: 0 14px;
  cursor: pointer;
}

.modes button[aria-checked="true"] {
  border-color: var(--tray);
  background: var(--tray);
  color: var(--cream);
}

.settings-open,
.settings-close {
  height: 46px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--white);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}

.settings {
  width: min(440px, calc(100vw - 32px));
  padding: 22px 22px 18px;
  border: 0;
  border-radius: 16px;
  background: var(--white);
  color: var(--ink);
}

.settings::backdrop {
  background: rgba(27, 26, 23, 0.46);
}

.settings h2 {
  margin: 0 0 16px;
  font-family: var(--serif);
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.settings fieldset {
  margin: 0;
  padding: 0;
  border: 0;
}

.settings fieldset + fieldset {
  margin-top: 16px;
}

.settings legend {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.settings-close {
  margin-top: 18px;
  border: 0;
  background: var(--tray);
  color: var(--cream);
}

.source-dialog {
  width: min(420px, calc(100vw - 32px));
  padding: 20px 20px 16px;
  border: 0;
  border-radius: 16px;
  background: var(--white);
  color: var(--ink);
}

.source-dialog::backdrop {
  background: rgba(27, 26, 23, 0.46);
}

.source-kicker {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.source-dialog h2 {
  margin: 4px 0 14px;
  font-family: var(--serif);
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.source-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.source-side {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.source-list a {
  color: var(--seal);
  font-weight: 700;
}

.source-meta {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.source-close {
  margin-top: 16px;
  height: 40px;
  padding: 0 14px;
  border: 0;
  border-radius: 10px;
  background: var(--tray);
  color: var(--cream);
  font-family: var(--font);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}

.hint,
.rate,
.scale-note {
  margin: 8px 28px 0;
  color: var(--muted);
  font-size: 14px;
}

.summary {
  margin: 22px 28px 0;
  font-family: var(--serif);
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.summary:empty,
.rate:empty {
  display: none;
}

.input-quote {
  margin: 0;
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
  text-transform: none;
}

.tray {
  display: flex;
  flex-direction: column;
  gap: 26px;
  margin: 18px 20px 0;
  padding: 32px 28px 26px;
  overflow-x: auto;
  border-radius: 16px;
  background: var(--tray);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.05);
}

.tray-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 18px;
}

.tray-tools[hidden] {
  display: none;
}

.tray-check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--cream);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

.tray-check[hidden] {
  display: none;
}

.tray-check input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--cream);
}

.note-stack {
  position: relative;
  flex: 0 0 auto;
}

.note-stack.is-sizes {
  background: var(--cream);
}

.note-layer {
  position: absolute;
  top: 0;
  left: 0;
}

.note-layer > .art {
  width: 100%;
  height: 100%;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.55);
}

.note-layer .face {
  filter: none;
}

.note-layer.is-outline {
  box-sizing: border-box;
  border: 2px solid #3a3834;
  background: transparent;
}

.note-edge-label {
  position: absolute;
  top: 50%;
  left: 100%;
  transform: translateY(-50%) translateX(calc(-50% + 7px)) rotate(-90deg);
  transform-origin: center;
  color: #3a3834;
  font-size: 10px;
  font-weight: 500;
  line-height: 1;
  letter-spacing: 0.01em;
  white-space: nowrap;
  pointer-events: none;
}

.tray-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 26px 28px;
  width: 100%;
}

.versions-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 16px;
  width: 100%;
}

.versions-back {
  display: inline-flex;
  align-items: center;
  padding: 8px 14px;
  border: 0;
  border-radius: 10px;
  background: var(--cream);
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.versions-back:hover,
.versions-back:focus-visible {
  background: #e4ddd2;
  color: var(--ink);
}

.versions-title {
  margin: 0;
  color: var(--cream);
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 600;
}

.empty {
  margin: 12px 0 28px;
  color: var(--cream);
  font-size: 16px;
}

.piece {
  display: flex;
  flex: 0 0 auto;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin: 0;
}

.copies {
  position: relative;
  display: flex;
  flex-wrap: nowrap;
  gap: 10px;
  align-items: flex-end;
}

.copies.is-fan {
  display: block;
}

.fan {
  position: relative;
}

.fan > .fan-sheet {
  position: absolute;
  top: var(--pivot-top);
  left: 0;
  transform-origin: top left;
  transform: rotate(var(--fan));
  pointer-events: none;
}

.fan-sheet.fan-front {
  z-index: 2;
  pointer-events: auto;
}

.fan-tools {
  position: absolute;
  top: calc(var(--pivot-top) - 40px);
  right: var(--fan-inset);
  z-index: 3;
}

.fan > .badge {
  z-index: 4;
}

.art-stack {
  display: flex;
  flex: 0 0 auto;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

.art {
  position: relative;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  perspective: 900px;
}

.art.can-flip {
  cursor: pointer;
}

.tools {
  display: flex;
  gap: 2px;
  padding: 3px;
  border-radius: 10px;
  background: var(--cream);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.32);
}

.tool {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}

.tool svg {
  width: 16px;
  height: 16px;
  display: block;
}

.tool:hover:not(:disabled),
.tool:focus-visible:not(:disabled) {
  background: #e4ddd2;
  color: var(--ink);
}

.tool:focus-visible {
  outline: 2px solid var(--seal);
  outline-offset: 1px;
}

.tool:disabled {
  background: #d9d3c8;
  color: #7a746a;
  cursor: default;
}

.flip {
  position: relative;
  display: grid;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.55s cubic-bezier(0.2, 0.7, 0.2, 1);
}

.art.is-flipped .flip {
  transform: rotateY(180deg);
}

.face {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  backface-visibility: hidden;
  filter: drop-shadow(0 10px 12px rgba(0, 0, 0, 0.38));
}

.face.back {
  transform: rotateY(180deg);
}

.art.note.lay-flat .face {
  position: absolute;
  inset: auto;
  left: 50%;
  top: 50%;
  width: calc(100% / var(--flat-ratio, 1));
  height: calc(100% * var(--flat-ratio, 1));
  object-fit: cover;
  transform: translate(-50%, -50%) rotate(-90deg);
}

.art.note.lay-flat .face.back {
  transform: translate(-50%, -50%) rotate(-90deg) rotateY(180deg);
}

@media (prefers-reduced-motion: reduce) {
  .flip {
    transition: none;
  }
}

.missing-label {
  grid-area: 1 / 1;
  display: grid;
  place-items: center;
  padding: 8px;
  color: var(--cream);
  font-family: var(--serif);
  font-size: 18px;
  text-align: center;
}

.art.is-missing {
  border: 1px dashed rgba(244, 239, 230, 0.45);
  border-radius: 4px;
  color: var(--cream);
  font-family: var(--serif);
  font-size: 18px;
  text-align: center;
}

.art.coin.is-missing {
  border-radius: 50%;
}

.badge {
  position: absolute;
  top: -10px;
  left: -10px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--cream);
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
}

body.lightbox-open {
  overflow: hidden;
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 24px;
}

.lightbox[hidden] {
  display: none;
}

.lightbox-backdrop {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 0;
  border: 0;
  background: rgba(16, 18, 22, 0.9);
  color: transparent;
  cursor: pointer;
}

.lightbox-frame {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  max-width: 100%;
  max-height: 100%;
}

.lightbox .tools {
  padding: 4px;
  border-radius: 12px;
}

.lightbox .tool {
  width: 36px;
  height: 36px;
  border-radius: 8px;
}

.lightbox .tool svg {
  width: 18px;
  height: 18px;
}

.lightbox-name {
  margin: 0;
  color: var(--cream);
  font-size: 18px;
  font-weight: 700;
}

figcaption {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  height: 5em;
  color: var(--cream);
  text-align: left;
}

.name {
  display: flex;
  flex-wrap: nowrap;
  align-items: baseline;
  gap: 0.4em;
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
}

.comp-value {
  font-weight: 600;
  white-space: nowrap;
}

.meta {
  color: rgba(244, 239, 230, 0.72);
  font-size: 12px;
}

.dimensions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  white-space: nowrap;
}

body:not(.show-sharpness) .sharpness {
  display: none;
}

.sharpness {
  --bar: 76px;
  position: relative;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--bar);
  height: 11px;
  border-radius: 999px;
  background: rgba(255, 252, 247, 0.14);
  box-shadow: inset 0 0 0 1px rgba(255, 252, 247, 0.2);
  overflow: hidden;
}

.sharpness-fill {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: calc(var(--score) * 1%);
  border-radius: inherit;
  background-image: linear-gradient(
    90deg,
    hsl(0 84% 52%) 0%,
    hsl(28 88% 52%) 33%,
    hsl(52 92% 50%) 66%,
    hsl(122 72% 40%) 100%
  );
  background-repeat: no-repeat;
  background-size: var(--bar) 100%;
}

.sharpness-value {
  position: relative;
  z-index: 1;
  color: #fffcf7;
  font-size: 8px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  text-shadow:
    0 0.5px 0 #1b1a17,
    0 -0.5px 0 #1b1a17,
    0.5px 0 0 #1b1a17,
    -0.5px 0 0 #1b1a17;
}

.scale-block {
  padding: 18px 28px 36px;
}

.ruler-row {
  margin-bottom: 8px;
}

.ruler {
  position: relative;
  height: 14px;
  border-bottom: 2px solid var(--ink);
  border-left: 2px solid var(--ink);
  border-right: 2px solid var(--ink);
}

.ruler span {
  position: absolute;
  top: 14px;
  left: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.scale-note {
  margin: 22px 0 0;
}

.sources {
  margin: 0 28px 40px;
  color: var(--muted);
  font-size: 13px;
}

.sources summary {
  cursor: pointer;
  font-weight: 700;
}

.sources ul {
  margin: 10px 0 0;
  padding-left: 18px;
}

.sources a {
  color: var(--ink);
}

.sources-all {
  margin: 14px 0 4px;
}

.sources-all a {
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.sources-page {
  max-width: 1100px;
  padding: 28px 28px 64px;
}

.sources-page h2 {
  margin: 28px 0 8px;
  font-family: var(--serif);
  font-size: 28px;
  font-weight: 600;
}

.sources-page .back {
  color: var(--ink);
  font-weight: 700;
}

.sources-page table {
  width: 100%;
  border-collapse: collapse;
  margin: 0 0 8px;
  font-size: 14px;
}

.sources-page th,
.sources-page td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.sources-page th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.sources-page td:first-child,
.sources-page th:first-child {
  width: 2.5em;
}

.sources-page a {
  color: var(--ink);
}

.sources-page .url {
  word-break: break-all;
}

@media (max-width: 720px) {
  h1 { font-size: 32px; }
  .summary { font-size: 22px; }
  select,
  .amount-box,
  .currency-picker { min-width: 0; width: 100%; }
  .controls .field { width: 100%; }
  .amount-box input { width: 100%; }
}

/* On a phone, keep each coin on its own row and on the same left edge
   as its caption. A shorter caption would otherwise let the next coin
   sit beside it, and the column would break. */
@media (max-width: 560px) {
  .piece:not(:has(.art.note)) {
    flex: 0 0 100%;
    min-width: 0;
    align-items: flex-start;
  }

  .art-stack:has(.art.coin) {
    align-items: flex-start;
  }
}

.input-currency-row {
  display: flex;
  align-items: stretch;
  flex-wrap: wrap;
  gap: 8px;
}

.native-currency {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  border: 0;
  white-space: nowrap;
}

.currency-picker {
  position: relative;
  flex: 0 1 auto;
  min-width: 240px;
}

.currency-picker-button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-width: 240px;
  height: 46px;
  padding: 0 32px 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='none' stroke='%235c574f' stroke-width='1.6' d='M1 1.5l5 5 5-5'/%3E%3C/svg%3E")
    right 12px center / 12px 8px no-repeat,
    var(--white);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  text-align: left;
  cursor: pointer;
}

.currency-picker-button:focus-visible,
.segment button:focus-visible,
.currency-option:focus-visible {
  outline: 2px solid var(--tray);
  outline-offset: 2px;
}

.currency-picker-menu {
  display: none;
  position: absolute;
  z-index: 30;
  top: calc(100% + 4px);
  left: 0;
  width: max-content;
  min-width: 100%;
  max-width: min(440px, 80vw);
  max-height: 320px;
  overflow: auto;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--white);
  box-shadow: 0 12px 28px rgba(27, 26, 23, 0.16);
}

.currency-picker-menu.is-open {
  display: block;
}

.currency-option {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  margin: 0;
  padding: 7px 8px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  text-align: left;
  cursor: pointer;
}

.currency-option:hover,
.currency-option:focus-visible {
  background: #f3efe6;
}

.currency-option[aria-selected="true"] {
  background: #ebe4d6;
}

.currency-check {
  flex: none;
  width: 1em;
  color: var(--ink);
  font-weight: 700;
  text-align: center;
}

.unit-pill {
  flex: none;
  min-width: 4.8em;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--tray);
  color: var(--cream);
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.55;
  text-align: center;
}

.currency-picker-button .unit-pill[hidden] {
  display: none;
}

.segment {
  display: flex;
  flex: none;
  height: 22px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--white);
}

.segment button {
  height: 100%;
  margin: 0;
  padding: 0 7px;
  border: 0;
  border-right: 1px solid var(--line);
  background: var(--white);
  color: var(--ink);
  font-family: var(--font);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: none;
  cursor: pointer;
}

.segment button:last-child {
  border-right: 0;
}

.segment button[aria-checked="true"] {
  background: var(--tray);
  color: var(--cream);
}

.comp-field {
  flex: 1 1 320px;
}

.comp-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 10px;
}

.comp-line > select {
  flex: 0 0 auto;
}

.module-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 10px;
  width: 100%;
}

.module-row > .face-group,
.other-settings {
  flex: 0 0 auto;
}

.face-group {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 46px;
  padding: 0 6px 0 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--white);
}

.face-name {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
}

.face-group .segment {
  height: 32px;
  border-radius: 8px;
}

.face-group .segment button {
  padding: 0 12px;
  font-size: 14px;
}

.other-settings {
  display: inline-flex;
  align-items: center;
  height: 46px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--white);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}

.other-settings:hover {
  border-color: #b7b0a4;
  background: #f7f3eb;
  color: var(--ink);
}

.other-settings:focus-visible {
  outline: 2px solid var(--tray);
  outline-offset: 2px;
}

.setting-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
}

.setting-copy {
  min-width: 0;
  flex: 1;
}

.setting-row + .setting-row {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.settings .segment {
  height: 32px;
  border-radius: 8px;
}

.settings .segment button {
  padding: 0 12px;
  font-size: 14px;
}

#load-source-label {
  font-size: 16px;
  font-weight: 700;
}

.setting-copy p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 14px;
}

#sharpness-switch-label {
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}

.switch {
  position: relative;
  flex: none;
  width: 48px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: #cfc8bc;
  cursor: pointer;
}

.switch[aria-checked="true"] {
  background: var(--tray);
}

.switch-knob {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--white);
  box-shadow: 0 1px 2px rgba(27, 26, 23, 0.28);
  transition: transform 0.15s ease;
}

.switch[aria-checked="true"] .switch-knob {
  transform: translateX(20px);
}

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

.field-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
}

.field-head > span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.display-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: none;
  cursor: pointer;
}

.display-toggle input {
  margin: 0;
  accent-color: var(--tray);
}

.display-toggle:has(input:disabled) {
  color: #a39c91;
  cursor: not-allowed;
}

.map-open {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 46px;
  padding: 0 8px 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--white);
  color: var(--ink);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.05;
  text-align: left;
  cursor: pointer;
  flex: none;
}

.map-open:hover {
  border-color: #b7b0a4;
  background: #f7f3eb;
}

.map-open:focus-visible {
  outline: 2px solid var(--tray);
  outline-offset: 2px;
}

.map-open-icon {
  width: 44px;
  height: 20px;
  display: block;
  border-radius: 3px;
}

.currency-map {
  width: min(1120px, calc(100vw - 24px));
  height: min(820px, calc(100vh - 24px));
  max-height: calc(100vh - 24px);
  padding: 18px 18px 16px;
  border: 0;
  border-radius: 16px;
  background: var(--white);
  color: var(--ink);
}

.currency-map[open] {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.currency-map::backdrop {
  background: rgba(27, 26, 23, 0.46);
}

.map-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.currency-map h2 {
  margin: 0;
  font-family: var(--serif);
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.map-caption {
  margin: 6px 0 0;
  font-size: 16px;
  font-weight: 700;
}

.map-detail {
  margin: 2px 0 0;
  color: var(--muted);
  min-height: 1.45em;
}

.map-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.map-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.swatch {
  width: 14px;
  height: 14px;
  border: 1px solid #8f877c;
  border-radius: 3px;
}

.swatch-in { background: #fbf6ee; }
.swatch-out { background: #e4ddd2; }
.swatch-same {
  background: #f2b7a8;
  border-color: #8e2f28;
}

.map-stage {
  position: relative;
  flex: 1;
  min-height: 240px;
  overflow: hidden;
  border-radius: 12px;
  background: #d5e3eb;
  touch-action: none;
  cursor: grab;
}

.map-stage.is-panning,
.map-stage.is-panning .place {
  cursor: grabbing;
}

.map-canvas {
  position: absolute;
  inset: 0;
  transform-origin: 0 0;
}

.map-canvas svg {
  width: 100%;
  height: 100%;
  display: block;
}

.map-zoom {
  position: absolute;
  right: 10px;
  bottom: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.map-zoom button {
  width: 40px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--white);
  color: var(--ink);
  font-family: var(--font);
  font-size: 18px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}

.map-zoom button:hover {
  background: #f7f3eb;
}

.map-zoom button:focus-visible {
  outline: 2px solid var(--tray);
  outline-offset: 2px;
}

#map-zoom-fit {
  font-size: 12px;
}

.world .country {
  fill: #fbf6ee;
  stroke: #8f877c;
  stroke-width: 0.8;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
  pointer-events: fill;
}

.world .dot {
  fill: #fbf6ee;
  stroke: #fffcf7;
  stroke-width: 1.4;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}

.world .hit {
  fill: none;
  stroke: none;
  pointer-events: fill;
}

.world .place {
  cursor: pointer;
}

.world .place.is-out .country,
.world .place.is-out .dot {
  fill: #e4ddd2;
}

.world .place.is-selected .country,
.world .place.is-selected .dot {
  stroke: #2a3340;
  stroke-width: 1.7;
}

.world .place.is-shared .country,
.world .place.is-shared .dot {
  fill: #f2b7a8;
  stroke: #8e2f28;
  stroke-width: 1.5;
}

.world .place.is-hovered .country,
.world .place.is-hovered .dot {
  fill: #8e2f28;
  stroke: #5c1e1a;
  stroke-width: 1.8;
}
