:root {
  --ink: #173f4d;
  --ink-soft: #4d6b75;
  --card: rgba(255, 255, 255, 0.88);
  --card-solid: #ffffff;
  --line: rgba(23, 63, 77, 0.12);
  --sea: #19a7b5;
  --sea-soft: #dff6f3;
  --coral: #ff7a59;
  --coral-deep: #e8613f;
  --sand: #fbf3dc;
  --shadow: 0 10px 30px rgba(18, 52, 66, 0.16), 0 2px 6px rgba(18, 52, 66, 0.08);
  --radius: 18px;
  --gutter: 16px;
  --dock-h: 74px;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #cfeef0;
  color: var(--ink);
  font: 14px/1.4 "Nunito", system-ui, sans-serif;
}

#map {
  position: fixed;
  inset: 0;
}

h1,
h2,
.eyebrow,
.dock-label,
summary {
  font-family: "Fredoka", "Nunito", system-ui, sans-serif;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

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

.card {
  background: var(--card);
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px) saturate(1.3);
  -webkit-backdrop-filter: blur(14px) saturate(1.3);
}

/* ---------- HUD (top left) ---------- */

/* The island card and the fact card stack in one column, so the fact always sits right below. */
#left-col {
  position: fixed;
  top: var(--gutter);
  left: var(--gutter);
  width: 268px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 3;
}

#hud {
  padding: 14px 14px 10px;
}

.hud-top {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo {
  width: 40px;
  height: 40px;
  flex: none;
}

.hud-title {
  flex: 1;
  min-width: 0;
}

h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
  line-height: 1.05;
  letter-spacing: 0.01em;
}

.coords {
  margin: 2px 0 0;
  font-size: 11px;
  font-weight: 700;
  color: var(--ink-soft);
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
}

.icon-btn {
  flex: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--card-solid);
  font-weight: 800;
  display: grid;
  place-items: center;
  transition: transform 0.15s, background 0.15s;
}

.icon-btn:hover {
  transform: scale(1.08);
  background: var(--sea-soft);
}

.icon-btn.small {
  width: 30px;
  height: 30px;
  font-size: 14px;
}

.name-row {
  display: flex;
  gap: 6px;
  margin: 12px 0 10px;
}

#island-name {
  flex: 1;
  min-width: 0;
  border: 1.5px dashed rgba(23, 63, 77, 0.25);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.6);
  padding: 5px 10px;
  font: 600 16px "Fredoka", sans-serif;
  color: var(--ink);
}

#island-name:focus {
  outline: none;
  border-style: solid;
  border-color: var(--sea);
  background: #fff;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, auto);
  gap: 5px;
  margin: 0 0 10px;
}

.stats div {
  background: var(--sand);
  border-radius: 10px;
  padding: 6px 7px;
  min-width: 0;
}

.stats dt {
  font-size: 9.5px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #9a7f45;
}

.stats dd {
  margin: 0;
  font: 600 14px "Fredoka", sans-serif;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.goal {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  background: var(--sea-soft);
  border-radius: 12px;
  padding: 8px 10px;
}

.goal-icon {
  font-size: 22px;
  line-height: 1.2;
}

.goal small {
  display: block;
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #138795;
}

.goal b {
  display: block;
  font-size: 14px;
}

.goal span:not(.goal-icon) {
  font-size: 12px;
  color: var(--ink-soft);
}

.goal.is-done {
  background: #fff1c9;
}

.link-btn {
  margin-top: 6px;
  border: 0;
  background: none;
  padding: 4px 2px;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-soft);
}

.link-btn:hover {
  color: var(--ink);
}

#badge-count {
  background: var(--ink);
  color: #fff;
  border-radius: 99px;
  padding: 1px 7px;
  margin-left: 2px;
  font-size: 11px;
}

.badge-list {
  list-style: none;
  margin: 4px 0 2px;
  padding: 0;
  display: grid;
  gap: 4px;
  max-height: 34vh;
  overflow: auto;
}

.badge-list[hidden] {
  display: none;
}

.badge-list li {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 5px 8px;
  border-radius: 10px;
  background: rgba(23, 63, 77, 0.05);
  opacity: 0.55;
}

.badge-list li > span {
  font-size: 18px;
  filter: grayscale(1);
}

.badge-list li.is-earned {
  opacity: 1;
  background: #fff1c9;
}

.badge-list li.is-earned > span {
  filter: none;
}

.badge-list b {
  display: block;
  font-size: 12px;
}

.badge-list small {
  font-size: 11px;
  color: var(--ink-soft);
}

/* ---------- panel (right) ---------- */

#panel {
  position: fixed;
  top: var(--gutter);
  right: var(--gutter);
  width: 288px;
  max-height: calc(100vh - var(--gutter) * 2 - 150px);
  overflow: auto;
  padding: 14px;
  z-index: 3;
  scrollbar-width: thin;
}

.tool-head {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin-bottom: 10px;
}

.tool-icon {
  font-size: 22px;
  width: 42px;
  height: 42px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: var(--sand);
}

.tool-head h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

.tool-head p {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: var(--ink-soft);
}

.section {
  border-top: 1px solid var(--line);
  margin-top: 12px;
  padding-top: 10px;
}

summary {
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

summary::-webkit-details-marker {
  display: none;
}

summary::after {
  content: "▾";
  font-size: 12px;
  color: var(--ink-soft);
  transition: transform 0.2s;
}

details:not([open]) summary::after {
  transform: rotate(-90deg);
}

.label {
  margin: 10px 0 5px;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.chip {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 99px;
  padding: 4px 10px;
  font-size: 12.5px;
  font-weight: 700;
  transition: background 0.15s, border-color 0.15s, transform 0.15s;
}

.chip:hover {
  transform: translateY(-1px);
  border-color: rgba(23, 63, 77, 0.3);
}

.chip.is-active {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}

.swatches {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.swatch {
  border: 2px solid transparent;
  background: #fff;
  border-radius: 12px;
  padding: 5px 2px 4px;
  display: grid;
  justify-items: center;
  gap: 3px;
  font-size: 11px;
  font-weight: 700;
  transition: transform 0.15s, border-color 0.15s;
}

.swatch i {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12);
}

.swatch:hover {
  transform: translateY(-1px);
}

.swatch.is-active {
  border-color: var(--coral);
  background: #fff4ef;
}

.slider {
  display: block;
  margin: 10px 0 4px;
}

.slider span {
  display: flex;
  justify-content: space-between;
  font-size: 12.5px;
  font-weight: 700;
}

.slider output {
  font-variant-numeric: tabular-nums;
  color: var(--ink-soft);
}

input[type="range"] {
  width: 100%;
  margin: 6px 0 0;
  accent-color: var(--coral);
}

.seg {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: rgba(23, 63, 77, 0.07);
  border-radius: 12px;
  padding: 3px;
  gap: 2px;
}

.seg button {
  border: 0;
  background: none;
  border-radius: 9px;
  padding: 6px 0;
  font-size: 11.5px;
  font-weight: 700;
  white-space: nowrap;
}

.seg button.is-active {
  background: #fff;
  box-shadow: 0 1px 4px rgba(18, 52, 66, 0.15);
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
}

.tool-note {
  margin: 8px 0 0;
  font-size: 11.5px;
  color: var(--ink-soft);
}

.row .btn {
  flex: 1 1 auto;
  white-space: nowrap;
}

.btn {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  padding: 8px 10px;
  font-weight: 800;
  font-size: 12.5px;
  transition: transform 0.15s, box-shadow 0.15s, background 0.15s;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(18, 52, 66, 0.12);
}

.btn:active {
  transform: translateY(1px);
}

.btn.primary {
  background: var(--coral);
  border-color: var(--coral-deep);
  color: #fff;
  box-shadow: 0 3px 0 var(--coral-deep);
}

.btn.primary:hover {
  background: #ff8a6c;
}

.btn.danger:hover {
  background: #e9f3ff;
}

.btn.wide {
  width: 100%;
  margin-top: 12px;
  padding: 10px;
  font-size: 14px;
}

/* ---------- dock (bottom) ---------- */

#dock {
  position: fixed;
  left: 50%;
  bottom: calc(var(--gutter) + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 6px;
  z-index: 4;
  max-width: calc(100vw - var(--gutter) * 2);
}

#dock-tools {
  display: flex;
  align-items: center;
  gap: 2px;
}

#dock button {
  border: 0;
  background: none;
  border-radius: 13px;
  width: 64px;
  height: 60px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 2px;
  transition: background 0.15s, transform 0.15s;
  position: relative;
}

#dock button:hover:not(:disabled) {
  background: rgba(23, 63, 77, 0.07);
  transform: translateY(-2px);
}

#dock button.is-active {
  background: var(--ink);
  color: #fff;
}

#dock button:disabled {
  opacity: 0.35;
  cursor: default;
}

.dock-icon {
  font-size: 22px;
  line-height: 1;
}

.dock-label {
  font-size: 12px;
  font-weight: 500;
}

.dock-sep {
  width: 1px;
  height: 40px;
  background: var(--line);
  margin: 0 4px;
  flex: none;
}

/* The town tools: a sandy tray with a small vertical "Town" tag on its left edge. */
.dock-group {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 0 2px 0 0;
  border-radius: 15px;
  background: var(--sand);
  flex: none;
}

.dock-group-label {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  padding: 0 1px 0 3px;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #9a7f45;
  pointer-events: none;
}

#panel-toggle {
  display: none !important;
}

#hint {
  position: fixed;
  left: 50%;
  bottom: calc(var(--gutter) + var(--dock-h) + 10px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  margin: 0;
  padding: 6px 14px;
  border-radius: 99px;
  background: rgba(23, 63, 77, 0.82);
  color: #fff;
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  max-width: calc(100vw - var(--gutter) * 2);
  overflow: hidden;
  text-overflow: ellipsis;
  z-index: 3;
  pointer-events: none;
}

body:not(.is-playing) #hint,
body:not(.is-playing) #dock,
body:not(.is-playing) #panel {
  opacity: 0;
  pointer-events: none;
}

#hint,
#dock,
#panel {
  transition: opacity 0.6s;
}

/* ---------- fact ticker (under the island card) ---------- */

#fact {
  margin: 0;
  padding: 10px 12px;
  font-size: 12.5px;
}

#fact b {
  display: block;
  font: 600 11px "Fredoka", sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--coral-deep);
}

#fact-text {
  transition: opacity 0.3s;
}

#fact-text.is-fading {
  opacity: 0;
}

/* ---------- toasts ---------- */

#toasts {
  position: fixed;
  top: var(--gutter);
  left: 50%;
  transform: translateX(-50%);
  display: grid;
  gap: 8px;
  justify-items: center;
  z-index: 10;
  pointer-events: none;
  width: min(420px, calc(100vw - var(--gutter) * 2));
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-radius: 14px;
  background: var(--card-solid);
  box-shadow: var(--shadow);
  font-weight: 600;
  animation: toast-in 0.45s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}

.toast small {
  display: block;
  font-size: 10.5px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
}

.toast b {
  display: block;
}

.toast-icon {
  font-size: 24px;
}

.toast.badge {
  background: linear-gradient(135deg, #fff6d6, #ffe3d6);
  border: 1px solid #ffd27a;
}

.toast.is-leaving {
  animation: toast-out 0.4s ease both;
}

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

@keyframes toast-out {
  to {
    opacity: 0;
    transform: translateY(-10px);
  }
}

/* ---------- intro ---------- */

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: var(--gutter);
  background: radial-gradient(circle at 50% 60%, rgba(23, 63, 77, 0.05), rgba(23, 63, 77, 0.35));
  z-index: 20;
  overflow: auto;
}

.modal[hidden] {
  display: none;
}

.modal-card {
  width: min(540px, 100%);
  background: var(--card-solid);
  border-radius: 24px;
  box-shadow: 0 24px 60px rgba(18, 52, 66, 0.35);
  padding: 26px 26px 20px;
  animation: pop 0.5s cubic-bezier(0.2, 1.3, 0.4, 1) both;
}

@keyframes pop {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.96);
  }
}

.eyebrow {
  margin: 0;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--coral-deep);
}

.modal-card h2 {
  margin: 4px 0 6px;
  font-size: 30px;
  font-weight: 600;
  line-height: 1.1;
}

.lede {
  margin: 0 0 14px;
  font-size: 15.5px;
  color: var(--ink-soft);
}

.facts {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.facts li {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  background: var(--sand);
  border-radius: 14px;
  padding: 10px 12px;
  font-size: 13.5px;
}

.facts li > span {
  font-size: 22px;
  line-height: 1.2;
}

.facts b {
  display: block;
  font-size: 14px;
}

.mission {
  margin: 14px 0;
  padding: 10px 12px;
  border-radius: 14px;
  background: var(--sea-soft);
  font-size: 14px;
}

.cta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.btn.big {
  flex: 1 1 180px;
  padding: 12px 14px;
  font-size: 15px;
}

.show-saved,
.show-playing {
  display: none;
}

.modal[data-mode="saved"] .show-saved,
.modal[data-mode="playing"] .show-playing {
  display: block;
  flex-basis: 100%;
}

.modal[data-mode="new"] [data-start="random"] {
  background: var(--coral);
  border-color: var(--coral-deep);
  color: #fff;
  box-shadow: 0 3px 0 var(--coral-deep);
}

#continue-name,
#visit-name,
#own-name {
  font-weight: 800;
}

/* Shared-link mode: invite banner, Visit / Back to mine, no new-island buttons. */
.show-shared,
.modal [hidden] {
  display: none !important;
}

.modal[data-mode="shared"] .show-shared:not([hidden]) {
  display: flex !important;
}

.modal[data-mode="shared"] .btn.show-shared {
  display: block !important;
  flex-basis: 100%;
}

.modal[data-mode="shared"] .hide-shared {
  display: none;
}

.invite {
  align-items: center;
  gap: 10px;
  margin: 0 0 14px;
  padding: 10px 12px;
  border-radius: 14px;
  background: linear-gradient(135deg, #fff6d6, #ffe3d6);
  border: 1px solid #ffd27a;
  font-size: 14px;
}

.invite > span:first-child {
  font-size: 22px;
}

.restore-btn {
  display: block;
  margin: 10px auto 0;
}

.modal-card.small {
  width: min(460px, 100%);
}

.share-row {
  display: flex;
  gap: 6px;
}

#share-url {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 10px;
  font: 12.5px ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--ink-soft);
  background: #f6fafa;
}

#share-dialog .cta {
  margin-top: 6px;
}

.tips {
  margin: 14px 0 0;
  font-size: 12px;
  color: var(--ink-soft);
}

/* ---------- map bits ---------- */

body:not([data-tool="explore"]) .mapboxgl-canvas-container.mapboxgl-interactive,
body:not([data-tool="explore"]) .mapboxgl-canvas-container {
  cursor: crosshair;
}

body[data-tool="draw"] .mapboxgl-canvas-container {
  cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='26' height='26' viewBox='0 0 26 26'%3E%3Cpath d='M3 23l2-7L18 3l5 5L10 21z' fill='%23ffd166' stroke='%23173f4d' stroke-width='1.6' stroke-linejoin='round'/%3E%3C/svg%3E") 3 23, crosshair;
}

body.is-panning .mapboxgl-canvas-container {
  cursor: grab !important;
}

body.is-camera .mapboxgl-canvas-container {
  cursor: move !important;
}

.zero-marker {
  border: 0;
  background: none;
  padding: 0;
  display: grid;
  justify-items: center;
  gap: 2px;
  cursor: pointer;
}

.zm-pin {
  position: relative;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 3px 10px rgba(18, 52, 66, 0.3);
  font-size: 20px;
  animation: bob 2.6s ease-in-out infinite;
}

.zm-pin::after {
  content: "";
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.85);
  animation: ping 2.6s ease-out infinite;
}

.zm-flag {
  display: none;
}

.zero-marker.on-land .zm-buoy {
  display: none;
}

.zero-marker.on-land .zm-flag {
  display: inline;
}

.zero-marker.on-land .zm-pin {
  animation: none;
}

.zm-label {
  font: 600 11px "Fredoka", sans-serif;
  background: var(--ink);
  color: #fff;
  border-radius: 99px;
  padding: 1px 7px;
  letter-spacing: 0.04em;
}

@keyframes bob {
  50% {
    transform: translateY(-4px) rotate(-4deg);
  }
}

@keyframes ping {
  from {
    opacity: 0.9;
    transform: scale(0.8);
  }
  to {
    opacity: 0;
    transform: scale(1.6);
  }
}

.zero-popup .mapboxgl-popup-content {
  border-radius: 14px;
  padding: 12px 14px;
  font: 13px/1.4 "Nunito", sans-serif;
  color: var(--ink);
  box-shadow: var(--shadow);
}

.zero-popup b {
  font-family: "Fredoka", sans-serif;
  font-size: 15px;
  font-weight: 600;
}

.zero-popup p {
  margin: 4px 0 0;
}

.mapboxgl-ctrl-bottom-right {
  bottom: calc(var(--gutter) - 10px);
  right: calc(var(--gutter) - 10px);
}

/* Night: the UI stays light, but the hint and dock go a little deeper so they don't glare. */
body[data-light="night"] .card,
body[data-light="dusk"] .card {
  background: rgba(255, 255, 255, 0.82);
}

/* ---------- small screens ---------- */

@media (max-width: 900px) {
  #fact {
    display: none;
  }
}

@media (max-width: 760px) {
  :root {
    --gutter: 10px;
    --dock-h: 58px;
  }

  #left-col {
    width: auto;
    right: var(--gutter);
  }

  #hud {
    padding: 10px 12px 6px;
  }

  .logo {
    width: 32px;
    height: 32px;
  }

  h1 {
    font-size: 18px;
  }

  .name-row {
    margin: 8px 0 6px;
  }

  .stats {
    margin-bottom: 6px;
  }

  .goal {
    display: none;
  }

  #panel {
    top: auto;
    left: var(--gutter);
    right: var(--gutter);
    width: auto;
    bottom: calc(var(--gutter) + var(--dock-h) + 12px);
    max-height: 52vh;
    transform: translateY(12px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s, transform 0.25s;
  }

  body.panel-open #panel {
    transform: none;
    opacity: 1;
    pointer-events: auto;
  }

  #panel-toggle {
    display: grid !important;
  }

  #dock {
    left: var(--gutter);
    right: var(--gutter);
    transform: none;
    overflow-x: auto;
    scrollbar-width: none;
  }

  #dock button {
    width: 54px;
    height: 48px;
    flex: none;
  }

  .dock-icon {
    font-size: 19px;
  }

  .dock-label {
    font-size: 10.5px;
  }

  #hint {
    white-space: normal;
    text-align: center;
    width: max-content;
  }

  body.panel-open #hint {
    display: none;
  }

  .mapboxgl-ctrl-bottom-right {
    display: none;
  }

  .modal-card {
    padding: 20px 18px 16px;
  }

  .modal-card h2 {
    font-size: 24px;
  }
}
