:root {
  --font-ui: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-display: 'Fraunces', Georgia, serif;
  --radius: 16px;
  --gutter: 16px;
  --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);

  /* Pin colors. Read by pins.js for the map icons too. */
  --regular: #8f96a0;
  --epic: #8b5cf6;
  --legendary: #f5b800;

  color-scheme: light;
  --land: #f2efe9;
  --surface: rgba(255, 253, 249, 0.86);
  --surface-solid: #fffdf9;
  --border: rgba(40, 32, 20, 0.1);
  --text: #23201b;
  --muted: #6f695f;
  --hover: rgba(40, 32, 20, 0.06);
  --ink: #23201b;
  --ink-text: #fffdf9;
  --shadow: 0 1px 2px rgba(40, 32, 20, 0.06), 0 10px 30px rgba(40, 32, 20, 0.12);
  --regular-text: #6f757e;
  --epic-text: #7442e0;
  --legendary-text: #9a7300;
}

:root[data-theme='dark'] {
  color-scheme: dark;
  --land: #1a1d24;
  --surface: rgba(28, 31, 39, 0.84);
  --surface-solid: #22262e;
  --border: rgba(255, 255, 255, 0.08);
  --text: #ecebe7;
  --muted: #989da7;
  --hover: rgba(255, 255, 255, 0.06);
  --ink: #ecebe7;
  --ink-text: #16181d;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 12px 32px rgba(0, 0, 0, 0.4);
  --regular-text: #a7adb6;
  --epic-text: #a98bff;
  --legendary-text: #ffcf3d;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  font-family: var(--font-ui);
  font-size: 14px;
  color: var(--text);
  background: var(--land);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

svg {
  display: block;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

#map {
  position: fixed;
  inset: 0;
  background: var(--land);
  transition: background-color 0.4s;
}

[data-mode='placing'] #map .maplibregl-canvas-container,
[data-mode='choosing'] #map .maplibregl-canvas-container {
  cursor: crosshair;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(16px) saturate(1.3);
  backdrop-filter: blur(16px) saturate(1.3);
  transition:
    background-color 0.4s,
    border-color 0.4s,
    color 0.4s;
}

/* --- Brand --- */

.brand {
  position: fixed;
  top: max(var(--gutter), env(safe-area-inset-top));
  left: var(--gutter);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px 10px 10px;
  max-width: calc(100% - 2 * var(--gutter) - 56px);
}

.brand__logo {
  flex: none;
}

.brand h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.15;
}

.brand p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

/* --- Theme toggle --- */

.theme-toggle {
  position: fixed;
  top: max(var(--gutter), env(safe-area-inset-top));
  right: var(--gutter);
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  padding: 0;
  border-radius: 999px;
}

.theme-toggle:hover {
  background: var(--surface-solid);
}

.theme-toggle svg {
  grid-area: 1 / 1;
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition:
    transform 0.4s var(--ease-out),
    opacity 0.25s;
}

.icon-sun,
[data-theme='dark'] .icon-moon {
  opacity: 0;
  transform: rotate(-60deg) scale(0.6);
}

[data-theme='dark'] .icon-sun {
  opacity: 1;
  transform: none;
}

/* --- Legend --- */

.legend {
  position: fixed;
  left: var(--gutter);
  bottom: max(24px, env(safe-area-inset-bottom));
  padding: 10px 14px;
}

.legend ul {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.legend li {
  display: grid;
  grid-template-columns: 14px 1fr auto;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}

.legend b {
  min-width: 2ch;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: right;
  color: var(--muted);
}

.legend__pin {
  width: 13px;
  height: 17px;
}

.legend__legal {
  margin-top: 9px;
  padding-top: 7px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.legend__legal a {
  display: inline-block;
  padding: 2px 0;
  color: inherit;
  text-decoration: none;
}

.legend__legal a:hover,
.legend__legal a:focus-visible {
  color: var(--text);
  text-decoration: underline;
  text-underline-offset: 2px;
}

[data-tier='regular'] {
  --tier: var(--regular);
  --tier-text: var(--regular-text);
}
[data-tier='epic'] {
  --tier: var(--epic);
  --tier-text: var(--epic-text);
}
[data-tier='legendary'] {
  --tier: var(--legendary);
  --tier-text: var(--legendary-text);
}

[data-pin] {
  display: block;
  color: var(--tier);
}
[data-pin] svg {
  width: 100%;
  height: 100%;
}
[data-pin='regular'] {
  color: var(--regular);
}
[data-pin='epic'] {
  color: var(--epic);
  filter: drop-shadow(0 0 3px color-mix(in srgb, var(--epic) 55%, transparent));
}
[data-pin='legendary'] {
  color: var(--legendary);
  filter: drop-shadow(0 0 5px color-mix(in srgb, var(--legendary) 70%, transparent));
}

/* --- Call to action --- */

.cta {
  position: fixed;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 15px 26px 15px 20px;
  border: 0;
  border-radius: 999px;
  background: var(--ink);
  color: var(--ink-text);
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.005em;
  box-shadow: var(--shadow);
  transform: translateX(-50%);
  transition:
    transform 0.35s var(--ease-out),
    opacity 0.25s,
    background-color 0.4s,
    color 0.4s;
}

.cta:hover {
  transform: translateX(-50%) translateY(-2px);
}

.cta:active {
  transform: translateX(-50%) scale(0.97);
}

.cta__pin {
  width: 15px;
  height: 20px;
}

body:not([data-mode='idle']) .cta {
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%) translateY(16px);
}

/* --- Placing hint --- */

.hint {
  position: fixed;
  top: max(84px, calc(env(safe-area-inset-top) + 72px));
  left: 50%;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 10px;
  width: max-content;
  max-width: calc(100% - 2 * var(--gutter));
  padding: 8px 8px 8px 18px;
  border-radius: 999px;
  font-weight: 500;
  transform: translateX(-50%);
  transition:
    opacity 0.25s,
    transform 0.35s var(--ease-out);
}

body:not([data-mode='placing']) .hint {
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%) translateY(-10px);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-solid);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

.chip:hover {
  background: var(--hover);
}

.chip:disabled {
  opacity: 0.55;
  cursor: progress;
}

.chip svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
}

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

.chip--solid {
  border-color: transparent;
  background: var(--ink);
  color: var(--ink-text);
}

.chip--solid:hover {
  background: var(--ink);
  opacity: 0.9;
}

/* --- Tier sheet --- */

.sheet {
  position: fixed;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  width: min(420px, calc(100% - 2 * var(--gutter)));
  padding: 18px;
  border-radius: 22px;
  transform: translateX(-50%);
  transition:
    opacity 0.25s,
    transform 0.4s var(--ease-out),
    background-color 0.4s,
    border-color 0.4s;
}

body:not([data-mode='choosing']):not([data-mode='submitting']) .sheet {
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%) translateY(24px);
}

.sheet__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 0 14px 4px;
}

.sheet h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
}

.icon-btn:hover {
  background: var(--hover);
  color: var(--text);
}

.icon-btn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

.tiers {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  border: 0;
}

.tier {
  position: relative;
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: 14px;
  padding: 12px 16px 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: 14px;
  background: var(--surface-solid);
  cursor: pointer;
  transition:
    border-color 0.15s,
    background-color 0.15s,
    transform 0.15s;
}

.tier:hover {
  border-color: color-mix(in srgb, var(--tier) 45%, var(--border));
}

.tier:active {
  transform: scale(0.99);
}

.tier input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.tier:has(input:checked) {
  border-color: var(--tier);
  background: color-mix(in srgb, var(--tier) 10%, var(--surface-solid));
}

.tier:has(input:focus-visible) {
  outline: 2px solid var(--tier);
  outline-offset: 2px;
}

.tier:has(input:disabled) {
  opacity: 0.5;
  cursor: not-allowed;
}

.tier[data-tier='legendary']:has(input:checked) {
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--legendary) 16%, transparent);
}

.tier__pin {
  justify-self: center;
  width: 22px;
  height: 29px;
}

.tier[data-tier='regular'] .tier__pin {
  width: 18px;
  height: 24px;
}

.tier[data-tier='legendary'] .tier__pin {
  width: 26px;
  height: 34px;
}

.tier__text {
  display: grid;
  gap: 1px;
}

.tier__rarity {
  color: var(--tier-text);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.tier__name {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.tier__meta {
  display: grid;
  justify-items: end;
  gap: 1px;
}

.tier__price {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.tier__life {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.tier[data-tier='regular'] .tier__price {
  color: var(--muted);
}

.currency {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 12px 4px 0;
  color: var(--muted);
  font-size: 13px;
}

.currency[hidden] {
  display: none;
}

.segmented {
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--hover);
}

.segmented label {
  position: relative;
  cursor: pointer;
}

.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented span {
  display: block;
  padding: 5px 14px;
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  transition:
    background-color 0.15s,
    color 0.15s;
}

.segmented input:checked + span {
  background: var(--surface-solid);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.14);
}

.segmented input:focus-visible + span {
  outline: 2px solid var(--text);
  outline-offset: 1px;
}

.drop-btn {
  width: 100%;
  margin-top: 14px;
  padding: 15px;
  border: 0;
  border-radius: 14px;
  background: var(--ink);
  color: var(--ink-text);
  font-size: 16px;
  font-weight: 600;
  transition:
    background-color 0.2s,
    color 0.2s,
    transform 0.15s,
    opacity 0.2s;
}

.drop-btn[data-tier='epic'] {
  background: var(--epic);
  color: #fff;
}

.drop-btn[data-tier='legendary'] {
  background: var(--legendary);
  color: #241a00;
}

.drop-btn:active {
  transform: scale(0.98);
}

.drop-btn:disabled {
  opacity: 0.7;
  cursor: progress;
}

.sheet__note {
  margin: 12px 4px 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  text-align: center;
}

.sheet__legal {
  margin: 6px 4px 0;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.sheet__legal a {
  color: inherit;
  text-decoration-color: color-mix(in srgb, currentColor 40%, transparent);
  text-underline-offset: 2px;
}

.sheet__legal a:hover {
  color: var(--text);
}

/* --- Pins in the DOM (draft, drop-in, live ping) --- */

.draft-pin {
  color: var(--tier);
  cursor: grab;
}

.draft-pin:active {
  cursor: grabbing;
}

.draft-pin__body {
  width: 100%;
  height: 100%;
  animation: draft-in 0.5s var(--ease-out) both;
  filter: drop-shadow(0 6px 6px rgba(0, 0, 0, 0.25));
}

.draft-pin[data-tier='epic'] .draft-pin__body {
  filter: drop-shadow(0 0 6px color-mix(in srgb, var(--epic) 60%, transparent))
    drop-shadow(0 6px 6px rgba(0, 0, 0, 0.25));
}

.draft-pin[data-tier='legendary'] .draft-pin__body {
  filter: drop-shadow(0 0 10px color-mix(in srgb, var(--legendary) 75%, transparent))
    drop-shadow(0 6px 6px rgba(0, 0, 0, 0.25));
}

.draft-pin svg,
.drop svg {
  width: 100%;
  height: 100%;
}

@keyframes draft-in {
  from {
    transform: translateY(-14px) scale(0.85);
    opacity: 0;
  }
}

.drop {
  color: var(--tier);
  pointer-events: none;
}

.drop__pin {
  width: 100%;
  height: 100%;
  animation: drop-in 0.7s cubic-bezier(0.3, 1.5, 0.5, 1) both;
}

.drop[data-tier='legendary'] .drop__pin {
  filter: drop-shadow(0 0 8px color-mix(in srgb, var(--legendary) 75%, transparent));
}

.drop[data-tier='epic'] .drop__pin {
  filter: drop-shadow(0 0 5px color-mix(in srgb, var(--epic) 60%, transparent));
}

.drop__ring {
  position: absolute;
  left: 50%;
  bottom: 0;
  width: 16px;
  height: 16px;
  margin: 0 0 -8px -8px;
  border: 2px solid var(--tier);
  border-radius: 50%;
  opacity: 0;
  animation: ring 1.1s 0.45s ease-out both;
}

@keyframes drop-in {
  0% {
    transform: translateY(-70px);
    opacity: 0;
  }
  35% {
    opacity: 1;
  }
  100% {
    transform: none;
  }
}

@keyframes ring {
  0% {
    transform: scale(0.6);
    opacity: 0.9;
  }
  100% {
    transform: scale(4.5);
    opacity: 0;
  }
}

.ping {
  width: 14px;
  height: 14px;
  border: 2px solid var(--tier);
  border-radius: 50%;
  pointer-events: none;
  animation: ring 1.8s ease-out both;
}

/* --- Popup --- */

.pin-popup .maplibregl-popup-content {
  display: grid;
  gap: 2px;
  padding: 10px 14px 11px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-solid);
  color: var(--text);
  box-shadow: var(--shadow);
  font-family: var(--font-ui);
}

.pin-popup .maplibregl-popup-tip {
  border-top-color: var(--surface-solid);
}

.pin-popup strong {
  font-size: 15px;
  font-weight: 600;
}

.pin-popup__rarity {
  color: var(--tier-text);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.pin-popup__ago {
  color: var(--muted);
  font-size: 12px;
}

/* --- Toast --- */

.toast {
  position: fixed;
  left: 50%;
  bottom: max(96px, calc(env(safe-area-inset-bottom) + 80px));
  max-width: calc(100% - 2 * var(--gutter));
  padding: 12px 18px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--ink-text);
  font-weight: 500;
  text-align: center;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%) translateY(10px);
  transition:
    opacity 0.25s,
    transform 0.35s var(--ease-out);
}

.toast.is-visible {
  opacity: 1;
  transform: translateX(-50%);
}

.toast[data-tone='error'] {
  background: #c2410c;
  color: #fff;
}

body:is([data-mode='choosing'], [data-mode='submitting']) .toast {
  bottom: auto;
  top: max(84px, calc(env(safe-area-inset-top) + 72px));
}

/* --- Demo checkout --- */

.demo {
  width: min(380px, calc(100% - 2 * var(--gutter)));
  padding: 22px;
  background: var(--surface-solid);
  color: var(--text);
}

.demo::backdrop {
  background: rgba(10, 12, 16, 0.45);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}

.demo h2 {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-size: 20px;
}

.demo p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.demo__actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}

/* --- MapLibre controls --- */

.maplibregl-ctrl-bottom-right {
  bottom: max(16px, env(safe-area-inset-bottom));
  right: calc(var(--gutter) - 10px);
}

.maplibregl-ctrl-group {
  border: 1px solid var(--border);
  border-radius: 12px !important;
  background: var(--surface) !important;
  box-shadow: var(--shadow) !important;
  overflow: hidden;
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
}

.maplibregl-ctrl-group button {
  width: 36px;
  height: 36px;
}

.maplibregl-ctrl-group button + button {
  border-top: 1px solid var(--border);
}

[data-theme='dark'] .maplibregl-ctrl-group .maplibregl-ctrl-icon {
  filter: invert(1);
}

.maplibregl-ctrl-attrib.maplibregl-compact {
  background: var(--surface);
  color: var(--muted);
}

.maplibregl-ctrl-attrib a {
  color: inherit;
}

[data-theme='dark'] .maplibregl-ctrl-attrib-button {
  filter: invert(1);
}

/* --- Small screens --- */

@media (max-width: 640px) {
  :root {
    --gutter: 12px;
  }

  .brand {
    gap: 10px;
    padding: 8px 14px 8px 8px;
  }

  .brand__logo {
    width: 28px;
    height: 28px;
  }

  .brand h1 {
    font-size: 16px;
  }

  .brand p {
    font-size: 12px;
  }

  .theme-toggle {
    width: 44px;
    height: 44px;
  }

  .legend {
    top: max(74px, calc(env(safe-area-inset-top) + 62px));
    bottom: auto;
    padding: 7px 12px 4px;
    border-radius: 16px;
  }

  .legend__legal {
    margin-top: 6px;
    padding-top: 2px;
    font-size: 11px;
  }

  .legend__legal a {
    padding: 4px 0;
  }

  .legend ul {
    display: flex;
    gap: 14px;
  }

  .legend li {
    display: flex;
    gap: 6px;
    font-size: 12px;
  }

  .legend li > span:not([data-pin]) {
    display: none;
  }

  .maplibregl-ctrl-group {
    display: none;
  }

  /* Attribution starts expanded (it collapses on the first drag), so keep it clear of the button. */
  .maplibregl-ctrl-bottom-right {
    bottom: max(84px, calc(env(safe-area-inset-bottom) + 72px));
  }

  .hint {
    top: max(146px, calc(env(safe-area-inset-top) + 134px));
    border-radius: 18px;
    padding: 10px;
  }

  .hint > span {
    width: 100%;
    text-align: center;
  }

  .sheet {
    bottom: max(12px, env(safe-area-inset-bottom));
    padding: 16px;
  }

  body:is([data-mode='choosing'], [data-mode='submitting']) .toast {
    top: max(146px, calc(env(safe-area-inset-top) + 134px));
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
