:root {
  color-scheme: dark;
  --surface: rgba(16, 20, 17, 0.86);
  --surface-strong: rgba(20, 25, 22, 0.96);
  --surface-soft: rgba(255, 255, 255, 0.08);
  --text: #f3f4ee;
  --muted: #b3baad;
  --line: rgba(255, 255, 255, 0.16);
  --accent: #8bd45f;
  --accent-strong: #c9f06e;
  --shadow: rgba(0, 0, 0, 0.34);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #101612;
  color: var(--text);
}

button {
  font: inherit;
}

a {
  color: inherit;
}

.app-shell {
  position: relative;
  width: 100vw;
  height: 100dvh;
  min-height: 560px;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 52%, rgba(114, 200, 217, 0.16), transparent 20rem),
    linear-gradient(145deg, #0f1713 0%, #10181d 50%, #161712 100%);
}

#map {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.gps-hex-canvas {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.maplibregl-canvas {
  outline: none;
}

.maplibregl-ctrl-top-right {
  top: calc(max(14px, env(safe-area-inset-top)) + 112px);
  right: max(14px, env(safe-area-inset-right));
}

.maplibregl-ctrl-group {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  box-shadow: 0 12px 32px var(--shadow);
}

.maplibregl-ctrl-group button {
  background-color: transparent;
}

.maplibregl-ctrl button .maplibregl-ctrl-icon {
  filter: invert(1);
}

.topbar,
.hud,
.perf,
.sheet,
.attribution,
.loading {
  position: absolute;
  z-index: 2;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.loading {
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--surface-strong);
  color: var(--muted);
}

.loading[hidden] {
  display: none;
}

.topbar {
  top: max(14px, env(safe-area-inset-top));
  left: max(14px, env(safe-area-inset-left));
  right: max(14px, env(safe-area-inset-right));
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  max-width: 760px;
  margin: 0 auto;
}

.tool-button,
.gps-toggle,
.primary-action,
.secondary-action {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: var(--surface);
  box-shadow: 0 12px 32px var(--shadow);
  cursor: pointer;
}

.tool-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 10px;
  white-space: nowrap;
}

.tool-button.is-active,
.gps-toggle[aria-pressed="true"] {
  color: #172011;
  background: linear-gradient(180deg, var(--accent-strong), var(--accent));
  border-color: transparent;
}

.tool-icon {
  width: 18px;
  text-align: center;
  font-weight: 500;
}

.hud {
  left: max(14px, env(safe-area-inset-left));
  right: max(14px, env(safe-area-inset-right));
  top: calc(max(14px, env(safe-area-inset-top)) + 54px);
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  max-width: 760px;
  margin: 0 auto;
}

.stat,
.perf,
.attribution {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 12px 32px var(--shadow);
}

.stat {
  min-width: 92px;
  padding: 8px 11px;
}

.hud .stat {
  min-width: 0;
}

.stat-label,
.eyebrow,
dt {
  display: block;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
}

.stat strong {
  display: block;
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
  font-size: 18px;
  line-height: 1.2;
}

.gps-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 8px;
}

.perf {
  right: max(14px, env(safe-area-inset-right));
  bottom: calc(max(14px, env(safe-area-inset-bottom)) + 34px);
  display: flex;
  gap: 10px;
  padding: 8px 10px;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.attribution {
  right: max(14px, env(safe-area-inset-right));
  top: auto;
  bottom: max(14px, env(safe-area-inset-bottom));
  margin: 0;
  padding: 6px 8px;
  color: var(--muted);
  font-size: 12px;
}

.sheet {
  right: max(14px, env(safe-area-inset-right));
  bottom: calc(max(14px, env(safe-area-inset-bottom)) + 42px);
  width: min(360px, calc(100vw - 28px));
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  box-shadow: 0 18px 48px var(--shadow);
  padding: 12px;
}

.sheet-grip {
  display: none;
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.eyebrow {
  margin: 0 0 4px;
  text-transform: uppercase;
  letter-spacing: 0;
}

h1 {
  margin: 0;
  font-size: 19px;
  line-height: 1.25;
  font-weight: 500;
  overflow-wrap: anywhere;
}

.biome-mark {
  display: grid;
  place-items: center;
  flex: 0 0 46px;
  width: 46px;
  height: 46px;
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--accent-strong);
  font-size: 24px;
}

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

.hex-details div {
  min-width: 0;
  padding: 8px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
}

dd {
  margin: 3px 0 0;
  min-height: 20px;
  font-size: 14px;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.sheet-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}

.primary-action,
.secondary-action {
  padding: 0 12px;
}

.primary-action {
  color: #172011;
  background: linear-gradient(180deg, var(--accent-strong), var(--accent));
  border-color: transparent;
}

.secondary-action {
  background: rgba(255, 255, 255, 0.09);
}

button:disabled {
  opacity: 0.46;
  cursor: not-allowed;
}

@media (max-width: 720px) {
  .topbar {
    gap: 6px;
  }

  .tool-button {
    padding: 7px 8px;
    font-size: 13px;
  }

  .hud {
    top: calc(max(14px, env(safe-area-inset-top)) + 52px);
    gap: 6px;
  }

  .perf {
    left: max(14px, env(safe-area-inset-left));
    right: auto;
    bottom: auto;
    top: calc(max(14px, env(safe-area-inset-top)) + 104px);
    max-width: calc(100vw - 28px);
    overflow: hidden;
  }

  .attribution {
    top: calc(max(14px, env(safe-area-inset-top)) + 138px);
    bottom: auto;
    left: auto;
    right: max(14px, env(safe-area-inset-right));
  }

  .sheet {
    left: max(14px, env(safe-area-inset-left));
    right: max(14px, env(safe-area-inset-right));
    bottom: max(14px, env(safe-area-inset-bottom));
    width: auto;
  }

  .sheet-grip {
    display: block;
    width: 42px;
    height: 4px;
    margin: 0 auto 10px;
    border-radius: 99px;
    background: rgba(255, 255, 255, 0.22);
  }
}

@media (max-width: 430px) {
  .app-shell {
    min-height: 620px;
  }

  .topbar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .hud {
    bottom: calc(max(14px, env(safe-area-inset-bottom)) + 218px);
    flex-wrap: wrap;
  }

  .stat {
    min-width: 84px;
  }

  .hex-details {
    grid-template-columns: 1fr;
  }
}
