:root {
  color-scheme: light;
  --paper: #f4f1ea;
  --paper-2: #efebe1;
  --ink: #26241e;
  --muted: #6a6353;
  --faint: #9b9279;
  --line: #e3dccb;
  --line-2: #d8cfb8;
  --gold: #9c7c3c;
  --card: #fbf9f3;
  --serif: "Cormorant Garamond", Georgia, serif;
  --body: "Spectral", Georgia, serif;
  --label: "Archivo", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --t-S: oklch(60% 0.098 55);
  --t-A: oklch(60% 0.098 135);
  --t-B: oklch(60% 0.098 235);
  --t-C: oklch(60% 0.098 305);
  --t-F: oklch(56% 0.028 60);
  --shadow: 0 18px 42px rgba(60, 45, 25, 0.16);
  --tile-w: 164px;
  --tile-img-h: 120px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--body);
  letter-spacing: 0;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body.is-sorting {
  cursor: grabbing;
  user-select: none;
}

button,
input,
select {
  font: inherit;
}

img {
  display: block;
  max-width: 100%;
}

a {
  color: inherit;
}

::selection {
  background: rgba(156, 124, 60, 0.22);
}

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

.masthead {
  max-width: 1340px;
  margin: 0 auto;
  padding: 30px 40px 18px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 30px;
}

.mast-left {
  min-width: 0;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--gold);
  font-family: var(--label);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.34em;
  text-transform: uppercase;
}

.mast-title {
  margin: 0;
  font-family: var(--serif);
  font-size: 60px;
  font-weight: 700;
  line-height: 0.94;
  letter-spacing: 0;
}

.mast-sub {
  max-width: 620px;
  margin: 10px 0 0;
  color: var(--muted);
  font-family: var(--body);
  font-size: 16px;
  font-style: italic;
  line-height: 1.42;
}

.mast-stats {
  display: flex;
  flex-shrink: 0;
  gap: 26px;
  padding-bottom: 4px;
}

.stat {
  text-align: right;
}

.stat b {
  display: block;
  font-family: var(--serif);
  font-size: 30px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0;
}

.stat span {
  color: var(--faint);
  font-family: var(--label);
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.about-castle {
  max-width: 1340px;
  margin: 0 auto 14px;
  padding: 0 40px;
}

.about-castle summary {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  width: fit-content;
  cursor: pointer;
  list-style: none;
  color: var(--muted);
  font-family: var(--label);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.about-castle summary::-webkit-details-marker {
  display: none;
}

.about-castle summary::before {
  content: "›";
  display: inline-block;
  font-size: 15px;
  line-height: 1;
  transform: rotate(0deg);
  transition: transform 140ms ease;
}

.about-castle[open] summary::before {
  transform: rotate(90deg);
}

.about-castle summary:hover {
  color: var(--ink);
}

.about-castle .about-body {
  max-width: 760px;
  margin: 10px 0 0;
  padding: 12px 16px;
  border: 1px solid var(--line-2);
  border-radius: 5px;
  background: var(--card);
}

.about-castle .about-body p {
  margin: 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.55;
}

.about-castle .about-body p + p {
  margin-top: 10px;
}

.dist {
  max-width: 1340px;
  margin: 0 auto;
  padding: 0 40px;
}

.dist-bar {
  display: flex;
  height: 7px;
  overflow: hidden;
  border: 1px solid var(--line-2);
  border-radius: 4px;
  background: var(--card);
}

.dist-seg {
  height: 100%;
}

.dist-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  margin-top: 8px;
}

.dist-key {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-family: var(--label);
  font-size: 10.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.dist-dot {
  width: 9px;
  height: 9px;
  border-radius: 2px;
}

.toolbar {
  position: sticky;
  top: 0;
  z-index: 30;
  margin-top: 18px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: rgba(244, 241, 234, 0.92);
  backdrop-filter: blur(8px);
}

.toolbar-inner {
  max-width: 1340px;
  margin: 0 auto;
  padding: 11px 40px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

.search-wrap {
  position: relative;
  flex: 1;
  min-width: 220px;
}

.search-wrap svg {
  position: absolute;
  left: 13px;
  top: 50%;
  width: 15px;
  height: 15px;
  transform: translateY(-50%);
  color: var(--faint);
}

.search {
  width: 100%;
  border: 1px solid var(--line-2);
  border-radius: 3px;
  padding: 9px 13px 9px 36px;
  background: var(--card);
  color: var(--ink);
  font-family: var(--body);
  font-size: 15px;
}

.search::placeholder {
  color: var(--faint);
  font-style: italic;
}

.search:focus {
  border-color: var(--gold);
  outline: none;
  box-shadow: 0 0 0 3px rgba(156, 124, 60, 0.12);
}

.selectwrap {
  position: relative;
}

.country {
  appearance: none;
  min-width: 160px;
  border: 1px solid var(--line-2);
  border-radius: 3px;
  padding: 9px 32px 9px 13px;
  background: var(--card);
  color: var(--ink);
  font-family: var(--label);
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
}

.selectwrap::after {
  content: "v";
  position: absolute;
  top: 50%;
  right: 12px;
  transform: translateY(-55%);
  color: var(--faint);
  font-family: var(--label);
  font-size: 10px;
  pointer-events: none;
}

.country:focus {
  border-color: var(--gold);
  outline: none;
}

.seg {
  display: flex;
  overflow: hidden;
  border: 1px solid var(--line-2);
  border-radius: 3px;
}

.seg button,
.btn-reset {
  border: 0;
  color: var(--muted);
  font-family: var(--label);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  cursor: pointer;
}

.seg button {
  padding: 9px 15px;
  border-left: 1px solid var(--line-2);
  background: var(--card);
}

.seg button:first-child {
  border-left: 0;
}

.seg button.on {
  background: var(--ink);
  color: var(--paper);
}

.seg button:focus-visible,
.btn-reset:focus-visible {
  outline: 2px solid rgba(156, 124, 60, 0.38);
  outline-offset: 2px;
}

.btn-reset {
  padding: 9px 15px;
  border: 1px solid var(--line-2);
  border-radius: 3px;
  background: transparent;
}

.btn-reset:hover {
  border-color: var(--gold);
  color: var(--gold);
}

.result-note {
  margin-left: auto;
  color: var(--faint);
  font-family: var(--label);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.sheet {
  max-width: 1340px;
  margin: 0 auto;
  padding: 8px 40px 80px;
}

.tier-row {
  display: grid;
  grid-template-columns: 128px 1fr;
  gap: 28px;
  padding: 24px 0;
  border-top: 1px solid var(--line);
}

.tier-row:first-child {
  border-top: 0;
}

.tier-label {
  position: sticky;
  top: 76px;
  align-self: start;
  height: max-content;
}

.tier-label span {
  display: block;
  color: var(--ink);
  font-family: var(--serif);
  font-size: 84px;
  font-weight: 700;
  line-height: 0.78;
}

.tier-underline {
  width: 46px;
  height: 3px;
  margin: 4px 0 9px;
  border-radius: 2px;
}

.tier-name {
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 13px;
  font-style: italic;
  line-height: 1.3;
}

.tier-count {
  color: var(--faint);
  font-family: var(--label);
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.tier-strip {
  display: flex;
  align-content: flex-start;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 18px;
  min-height: 172px;
  padding: 2px;
  border-radius: 5px;
  transition: background 150ms ease, box-shadow 150ms ease;
}

.tier-strip.is-drag-over {
  background: rgba(156, 124, 60, 0.07);
  box-shadow: inset 0 0 0 1.5px rgba(156, 124, 60, 0.35);
}

.tier-strip.empty {
  align-items: center;
  justify-content: center;
}

.empty-hint {
  color: var(--faint);
  font-size: 15px;
  font-style: italic;
}

.castle-tile {
  position: relative;
  width: var(--tile-w);
  min-width: var(--tile-w);
  height: 194px;
  overflow: hidden;
  border: 1px solid var(--line-2);
  border-radius: 4px;
  padding: 0;
  background: var(--card);
  color: var(--ink);
  cursor: pointer;
  touch-action: none;
  text-align: left;
  box-shadow: 0 1px 2px rgba(60, 45, 25, 0.05);
  transition: transform 160ms ease, border-color 160ms ease, box-shadow 160ms ease, opacity 160ms ease;
}

.castle-tile.can-drag {
  cursor: grab;
}

.castle-tile.can-drag:active {
  cursor: grabbing;
}

.castle-tile:hover,
.castle-tile:focus-visible {
  border-color: var(--gold);
  box-shadow: var(--shadow);
  outline: none;
  transform: translateY(-3px);
}

.castle-tile.is-dragging {
  display: none;
}

.tile-image {
  position: relative;
  width: 100%;
  height: var(--tile-img-h);
  overflow: hidden;
  background: var(--paper-2);
}

.tile-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: saturate(0.94);
  pointer-events: none;
  user-select: none;
  transition: transform 400ms ease;
}

.castle-tile:hover .tile-image img {
  transform: scale(1.05);
}

.card-grip {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 3px;
  background: rgba(38, 36, 30, 0.5);
  color: var(--paper);
  opacity: 0;
  font-family: var(--label);
  font-size: 13px;
  line-height: 1;
  transition: opacity 150ms ease;
}

.castle-tile.can-drag:hover .card-grip,
.castle-tile.can-drag:focus-visible .card-grip {
  opacity: 1;
}

.tile-title {
  display: -webkit-box;
  min-height: 42px;
  padding: 9px 11px 0;
  overflow: hidden;
  color: var(--ink);
  font-family: var(--serif);
  font-size: 18px;
  font-weight: 600;
  line-height: 1.03;
  letter-spacing: 0;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.tile-country {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 42px 11px 11px;
  color: var(--faint);
  font-family: var(--label);
  font-size: 9.5px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

.tile-dot {
  width: 4px;
  height: 4px;
  flex-shrink: 0;
  border-radius: 50%;
}

.tile-flag {
  position: absolute;
  right: 8px;
  bottom: 8px;
  width: 26px;
  height: 18px;
  object-fit: cover;
  border: 1px solid rgba(38, 36, 30, 0.18);
  border-radius: 3px;
  background: rgba(251, 249, 243, 0.92);
  box-shadow: 0 2px 8px rgba(60, 45, 25, 0.12);
}

.tile-tier {
  position: absolute;
  right: 8px;
  bottom: 8px;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.7);
  color: #fff;
  font-family: var(--label);
  font-size: 12px;
  font-weight: 700;
  box-shadow: 0 2px 6px rgba(40, 30, 15, 0.32);
}

/* By-country view: reuses .tier-row / .tier-strip; only the left label differs. */
.country-label {
  position: sticky;
  top: 76px;
  align-self: start;
  height: max-content;
}

.country-flag {
  width: 56px;
  height: 38px;
  object-fit: cover;
  margin-bottom: 9px;
  border: 1px solid var(--line-2);
  border-radius: 4px;
  box-shadow: 0 2px 8px rgba(60, 45, 25, 0.12);
}

.country-name {
  margin-bottom: 6px;
  color: var(--ink);
  font-family: var(--serif);
  font-size: 26px;
  font-weight: 700;
  line-height: 1.04;
}

.drag-placeholder {
  flex: 0 0 var(--tile-w);
  width: var(--tile-w);
  min-width: var(--tile-w);
  height: 194px;
  border: 2px dashed rgba(156, 124, 60, 0.7);
  border-radius: 4px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.68), rgba(255, 255, 255, 0.34)),
    repeating-linear-gradient(
      -45deg,
      rgba(156, 124, 60, 0.1) 0,
      rgba(156, 124, 60, 0.1) 8px,
      rgba(106, 99, 83, 0.06) 8px,
      rgba(106, 99, 83, 0.06) 16px
    );
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.8), 0 8px 22px rgba(60, 45, 25, 0.08);
  animation: placeholder-pop 130ms ease-out;
}

.drag-ghost {
  position: fixed;
  z-index: 100;
  pointer-events: none;
  opacity: 0.92;
  transform-origin: top left;
  box-shadow: 0 24px 58px rgba(40, 30, 15, 0.28);
  transition: none;
}

@keyframes placeholder-pop {
  from {
    opacity: 0.2;
    transform: scaleX(0.72);
  }
  to {
    opacity: 1;
    transform: scaleX(1);
  }
}

.mapview {
  max-width: 1340px;
  margin: 0 auto;
  padding: 18px 40px 80px;
}

.map-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 20px;
  margin-bottom: 14px;
}

.map-title {
  font-family: var(--serif);
  font-size: 30px;
  font-weight: 700;
}

.map-note {
  color: var(--muted);
  font-size: 15px;
  font-style: italic;
}

.map-canvas {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line-2);
  border-radius: 6px;
  background: var(--paper-2);
}

.map-canvas {
  width: 100%;
  max-height: 74vh;
  aspect-ratio: 1.32 / 1;
}

.map-leaflet {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  background: var(--paper-2);
}

.map-leaflet .leaflet-container {
  font: inherit;
  background: var(--paper-2);
}

.map-leaflet .leaflet-interactive {
  cursor: pointer;
}

.map-preview {
  position: absolute;
  z-index: 1100;
  pointer-events: none;
  width: min(300px, calc(100% - 28px));
  display: grid;
  grid-template-columns: 108px 1fr;
  overflow: hidden;
  border: 1px solid rgba(38, 36, 30, 0.18);
  border-radius: 5px;
  background: var(--card);
  box-shadow: 0 16px 44px rgba(30, 24, 14, 0.28);
  transform: translate(18px, -50%);
}

.map-preview.is-left {
  transform: translate(calc(-100% - 18px), -50%);
}

.map-preview.is-top {
  transform: translate(18px, calc(-100% + 18px));
}

.map-preview.is-left.is-top {
  transform: translate(calc(-100% - 18px), calc(-100% + 18px));
}

.map-preview > img {
  width: 108px;
  height: 100%;
  min-height: 104px;
  object-fit: cover;
  background: var(--paper-2);
}

.map-preview-body {
  padding: 10px 12px 12px;
}

.map-preview-tier {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--faint);
  font-family: var(--label);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.map-preview-tier span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
}

.map-preview h3 {
  margin: 7px 0 5px;
  color: var(--ink);
  font-family: var(--serif);
  font-size: 21px;
  font-weight: 700;
  line-height: 0.98;
  letter-spacing: 0;
}

.map-preview p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.28;
}

.preview-country-flag {
  display: inline-block;
  width: 18px;
  height: 12px;
  object-fit: cover;
  margin: 0 5px 0 3px;
  border-radius: 2px;
  border: 1px solid rgba(38, 36, 30, 0.15);
  vertical-align: -1px;
}

.map-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-top: 14px;
}

.map-legend-note {
  color: var(--faint);
  font-family: var(--label);
  font-size: 10.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.map-tier-toggle {
  border: 1px solid var(--line-2);
  border-radius: 999px;
  padding: 5px 12px 5px 9px;
  background: var(--card);
  cursor: pointer;
  transition: opacity 120ms ease, border-color 120ms ease;
}

.map-tier-toggle:hover {
  border-color: var(--gold);
}

.map-tier-toggle.off {
  opacity: 0.4;
  text-decoration: line-through;
}

.modal {
  position: fixed;
  inset: 0;
  display: none;
  z-index: 100;
}

.modal.is-open {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(28, 26, 21, 0.55);
  backdrop-filter: blur(3px);
}

.modal-panel {
  position: relative;
  z-index: 1;
  width: min(1300px, calc(100vw - 56px));
  max-height: 94vh;
  display: grid;
  grid-template-columns: minmax(0, 1.28fr) minmax(360px, 0.82fr);
  overflow: hidden;
  border-radius: 7px;
  background: var(--paper);
  box-shadow: 0 30px 80px rgba(20, 16, 8, 0.4);
  animation: rise 260ms cubic-bezier(0.2, 0.7, 0.3, 1) forwards;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.modal-close {
  position: absolute;
  top: 16px;
  right: 18px;
  z-index: 3;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line-2);
  border-radius: 50%;
  background: var(--card);
  color: var(--muted);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
}

.modal-close:hover,
.modal-close:focus-visible {
  border-color: var(--gold);
  color: var(--gold);
  outline: none;
}

.gallery-panel {
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: #080705;
}

.gallery-stage {
  position: relative;
  flex: 1;
  min-height: 560px;
  background: #050403;
}

.gallery-stage img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.gallery-thumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding: 9px;
  max-height: 124px;
  overflow-y: auto;
  background: #0b0a08;
}

.thumb-button {
  flex: 0 0 auto;
  width: 62px;
  height: 46px;
  overflow: hidden;
  border: 1.5px solid transparent;
  border-radius: 3px;
  padding: 0;
  background: #050403;
  cursor: pointer;
  opacity: 0.6;
  transition: opacity 150ms ease, border-color 150ms ease;
}

.thumb-button.is-active {
  border-color: var(--gold);
  opacity: 1;
}

.thumb-button img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.detail-panel {
  position: relative;
  overflow-y: auto;
  padding: 30px 32px;
}

.modal-tier {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  color: var(--muted);
  font-family: var(--label);
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.modal-tier::first-letter {
  color: var(--ink);
}

.detail-panel h2 {
  margin: 14px 34px 6px 0;
  font-family: var(--serif);
  font-size: 38px;
  font-weight: 700;
  line-height: 0.98;
  letter-spacing: 0;
}

.modal-location {
  margin: 0 0 18px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  color: var(--gold);
  font-family: var(--label);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.modal-country-flag {
  display: inline-block;
  width: 22px;
  height: 15px;
  object-fit: cover;
  margin-left: 6px;
  border-radius: 2px;
  border: 1px solid rgba(38, 36, 30, 0.15);
  vertical-align: -2px;
}

.modal-description {
  margin: 0 0 22px;
  color: #3b372e;
  font-size: 16px;
  line-height: 1.6;
}

.modal-description p {
  margin: 0 0 12px;
}

.modal-description p:last-child {
  margin-bottom: 0;
}

.vote-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 16px;
  padding: 10px 14px;
  border: 1px solid var(--line-2);
  border-radius: 5px;
  background: var(--card);
}

.vote-row[hidden] {
  display: none;
}

.vote-label {
  color: var(--muted);
  font-family: var(--label);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.vote-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 12px;
  border: 1px solid var(--line-2);
  border-radius: 15px;
  background: var(--paper);
  color: var(--muted);
  font-family: var(--label);
  font-size: 11px;
  letter-spacing: 0.04em;
  line-height: 1;
  cursor: pointer;
  transition: border-color 120ms ease, color 120ms ease, background 120ms ease, transform 80ms ease;
}

.vote-arrow {
  font-size: 11px;
  line-height: 1;
}

.vote-text {
  white-space: nowrap;
}

.vote-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  border-color: var(--gold);
  color: var(--ink);
}

.vote-btn:disabled {
  cursor: default;
  opacity: 0.55;
}

.vote-up.is-active {
  border-color: #3f8f54;
  background: #3f8f54;
  color: #fff;
}

.vote-down.is-active {
  border-color: #b5462f;
  background: #b5462f;
  color: #fff;
}

.vote-score {
  min-width: 30px;
  text-align: center;
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 700;
  color: var(--ink);
}

.vote-breakdown {
  margin-left: auto;
  color: var(--muted);
  font-family: var(--label);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.source-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.source-row a {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 8px 11px;
  border: 1px solid var(--line-2);
  border-radius: 3px;
  color: var(--muted);
  font-family: var(--label);
  font-size: 10px;
  letter-spacing: 0.1em;
  text-decoration: none;
  text-transform: uppercase;
}

.source-row a:hover,
.source-row a:focus-visible {
  border-color: var(--gold);
  color: var(--gold);
  outline: none;
}

.source-row a.source-official {
  border-color: var(--gold);
  color: var(--gold);
}

.map-frame {
  position: relative;
  width: 100%;
  height: 180px;
  overflow: hidden;
  border: 1px solid var(--line-2);
  border-radius: 5px;
  background: var(--paper-2);
}

.map-frame iframe,
.modal-map-leaflet {
  width: 100%;
  height: 100%;
  border: 0;
}

.modal-map-leaflet .leaflet-container {
  background: var(--paper-2);
}

.footer {
  max-width: 1340px;
  margin: 0 auto;
  padding: 24px 40px 50px;
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  border-top: 1px solid var(--line);
  color: var(--faint);
  font-family: var(--label);
  font-size: 11px;
  letter-spacing: 0.06em;
}

[hidden] {
  display: none !important;
}

@media (max-width: 920px) {
  .masthead {
    align-items: flex-start;
    flex-direction: column;
    gap: 16px;
  }

  .mast-stats {
    gap: 22px;
  }

  .stat {
    text-align: left;
  }

  /* Stacked modal: scroll the whole panel so long descriptions are fully readable. */
  .modal-panel {
    display: block;
    max-height: 92dvh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .gallery-panel {
    height: 280px;
  }

  .gallery-stage {
    min-height: 0;
  }

  .detail-panel {
    overflow: visible;
  }

  /* Keep the close button in view while the panel scrolls. */
  .modal-close {
    position: fixed;
    top: 20px;
    right: 20px;
  }
}

@media (max-width: 760px) {
  :root {
    --tile-w: 146px;
    --tile-img-h: 104px;
  }

  .masthead,
  .dist,
  .about-castle,
  .toolbar-inner,
  .sheet,
  .mapview,
  .footer {
    padding-left: 18px;
    padding-right: 18px;
  }

  .mast-title {
    font-size: 46px;
  }

  .tier-row {
    grid-template-columns: 64px 1fr;
    gap: 14px;
  }

  .tier-label {
    top: 92px;
  }

  .tier-label span {
    font-size: 54px;
  }

  .tier-strip {
    gap: 12px;
  }

  .castle-tile,
  .drag-placeholder {
    height: 174px;
  }

  .tile-title {
    font-size: 16px;
  }
}

@media (max-width: 480px) {
  :root {
    --tile-w: 132px;
    --tile-img-h: 96px;
  }

  .mast-title {
    font-size: 40px;
  }

  .toolbar-inner {
    align-items: stretch;
  }

  .search-wrap,
  .selectwrap,
  .country,
  .seg,
  .btn-reset,
  .result-note {
    width: 100%;
  }

  .seg button {
    flex: 1;
  }

  .result-note {
    margin-left: 0;
  }

  .tier-row {
    grid-template-columns: 54px 1fr;
    gap: 10px;
  }

  .tier-label span {
    font-size: 46px;
  }

  .tier-name {
    display: none;
  }

  .modal.is-open {
    padding: 12px;
  }

  .detail-panel {
    padding: 24px 20px;
  }

  .detail-panel h2 {
    font-size: 30px;
  }
}

/* Phones: tier/country label sits ABOVE each group, cards in a 3-column grid. */
@media (max-width: 600px) {
  .tier-row {
    grid-template-columns: 1fr;
    gap: 10px;
    padding: 16px 0;
  }

  .tier-label {
    position: static;
    top: auto;
    display: flex;
    align-items: baseline;
    gap: 10px;
  }
  .tier-label span {
    font-size: 30px;
    line-height: 1;
  }
  .tier-underline {
    display: none;
  }
  .tier-name {
    display: none;
  }
  .tier-count {
    font-size: 9px;
  }

  .country-label {
    position: static;
    display: flex;
    align-items: center;
    gap: 9px;
  }
  .country-flag {
    width: 34px;
    height: 23px;
    margin: 0;
  }
  .country-name {
    margin: 0;
    font-size: 18px;
  }

  .tier-strip {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    min-height: 0;
  }
  .tier-strip.empty {
    min-height: 60px;
  }

  .castle-tile,
  .drag-placeholder {
    width: auto;
    min-width: 0;
    height: 150px;          /* uniform card height regardless of name length */
  }
  .tile-image {
    height: 82px;
  }
  .tile-title {
    min-height: 28px;       /* reserve 2 lines so every card aligns */
    padding: 6px 7px 0;
    font-size: 13px;
  }
  .tile-country {
    padding: 3px 22px 8px 7px;
    font-size: 8px;
    letter-spacing: 0.08em;
    white-space: nowrap;    /* keep "United Kingdom" etc. on one line */
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .tile-flag {
    right: 5px;
    bottom: 5px;
    width: 20px;
    height: 14px;
  }
  .tile-tier {
    right: 5px;
    bottom: 5px;
    min-width: 18px;
    height: 18px;
    font-size: 10px;
  }
  .card-grip {
    display: none;
  }
}
