:root {
  --paper: #FCEFE8;
  --red: #B04847;
  --ink: #1A120E;
  --line: #E4C7BC;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --sheet-peek: 64px;
  color-scheme: light;
}

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

html,
body {
  margin: 0;
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.4;
}

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

html[data-theme="midnight"] #map {
  background: #0E1A2B;
}

html[data-theme="blueprint"] #map {
  background: #0F3D7A;
}

button,
input {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  transition: transform 200ms var(--ease), opacity 200ms var(--ease);
}

button:active {
  transform: scale(0.97);
}

:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

.overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
  mix-blend-mode: multiply;
  z-index: 1;
}

.overlay[hidden] {
  display: none !important;
}

.map-title {
  position: fixed;
  z-index: 3;
  left: 20px;
  bottom: 20px;
  margin: 0;
  max-width: calc(100% - 40px);
  color: #0B85C2;
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(44px, 7vw, 88px);
  letter-spacing: 0.18em;
  line-height: 1;
  white-space: nowrap;
  pointer-events: none;
  user-select: none;
  transition: opacity 200ms var(--ease);
}

html[data-theme="midnight"] .map-title {
  color: #D4A84B;
}

html[data-theme="blueprint"] .map-title {
  color: #FFFFFF;
}

.map-title.is-off {
  opacity: 0;
}

.panel {
  position: fixed;
  z-index: 4;
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--line);
}

.panel h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: 28px;
  font-weight: 500;
  line-height: 1;
}

.back {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  margin: 4px 0 8px;
  color: var(--ink);
  font-weight: 600;
  text-decoration: none;
}

.back:hover {
  color: var(--red);
}

.group-label {
  margin: 12px 0 6px;
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1.2;
}

.segment {
  display: flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 12px;
}

.segment button {
  flex: 1 1 0;
  min-width: 0;
  min-height: 44px;
  padding: 8px 4px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.2;
}

.segment button[aria-pressed="true"] {
  background: var(--red);
  color: var(--paper);
}

.color-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 44px;
}

.color-row label {
  flex: 1;
  display: flex;
  align-items: center;
  min-height: 44px;
  font-weight: 600;
}

input[type="color"] {
  -webkit-appearance: none;
  appearance: none;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--ink);
  background: transparent;
  cursor: pointer;
}

input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
}

input[type="color"]::-webkit-color-swatch {
  border: 0;
}

.switch {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  margin-top: 8px;
  cursor: pointer;
  font-weight: 600;
}

.switch input {
  position: absolute;
  opacity: 0;
  width: 44px;
  height: 44px;
  margin: 0;
  cursor: pointer;
}

.switch-ui {
  width: 44px;
  height: 28px;
  flex: 0 0 auto;
  box-sizing: border-box;
  border: 1px solid var(--ink);
  border-radius: 999px;
  background: #F3DDD4;
  position: relative;
}

.switch-ui::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--ink);
  transition: transform 200ms var(--ease);
}

.switch input:checked + .switch-ui {
  background: #0B85C2;
  border-color: #0A6EA0;
}

.switch input:checked + .switch-ui::after {
  transform: translateX(16px);
  background: var(--paper);
}

.switch input:focus-visible {
  outline: none;
}

.switch input:focus-visible + .switch-ui {
  outline: 2px solid var(--ink);
  outline-offset: 3px;
}

.primary {
  width: 100%;
  min-height: 48px;
  margin-top: 12px;
  border: 0;
  border-radius: 10px;
  background: var(--red);
  color: var(--paper);
  font-weight: 600;
}

.primary:disabled {
  opacity: 0.65;
  cursor: progress;
}

.notice {
  margin: 12px 0 0;
  padding: 10px 12px;
  border-radius: 8px;
  background: #F6D5CF;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.35;
}

.sheet-toggle {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  height: var(--sheet-peek);
  border: 0;
  background: transparent;
  color: var(--ink);
  font-weight: 600;
}

.handle {
  width: 36px;
  height: 4px;
  border-radius: 999px;
  background: var(--red);
}

@media (min-width: 721px) {
  .panel {
    top: 16px;
    left: 16px;
    width: 300px;
    max-height: calc(100dvh - 130px);
    overflow: auto;
    border-radius: 16px;
  }

  .sheet-bar {
    display: none;
  }

  .panel-body {
    padding: 16px 16px 20px;
  }
}

@media (max-width: 720px) {
  .map-title {
    left: 16px;
    bottom: calc(var(--sheet-peek) + env(safe-area-inset-bottom, 0px) + 12px);
    font-size: clamp(34px, 11vw, 60px);
    letter-spacing: 0.12em;
  }

  .panel {
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-height: 70vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-bottom: 0;
    border-radius: 16px 16px 0 0;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    transform: translateY(calc(100% - var(--sheet-peek) - env(safe-area-inset-bottom, 0px)));
    transition: transform 220ms var(--ease);
  }

  .panel:not(.is-open) {
    padding-bottom: 0;
  }

  .panel:not(.is-open) .sheet-bar {
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  .panel.is-open {
    transform: translateY(0);
  }

  .sheet-bar {
    flex: 0 0 auto;
  }

  .panel-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: 4px 16px 16px;
  }

  .maplibregl-ctrl-bottom-right {
    top: calc(8px + env(safe-area-inset-top, 0px));
    right: auto;
    bottom: auto;
    left: 8px;
    max-width: calc(100% - 68px);
  }

  .maplibregl-ctrl-bottom-right .maplibregl-ctrl {
    float: left;
    margin: 0;
  }

  .maplibregl-ctrl-top-right {
    top: env(safe-area-inset-top, 0px);
  }

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

.maplibregl-ctrl-attrib {
  max-width: min(280px, calc(100% - 16px));
  white-space: normal;
  line-height: 1.35;
  font-family: var(--sans);
}

.maplibregl-ctrl-attrib,
.maplibregl-ctrl-attrib a {
  color: var(--ink);
}

.maplibregl-ctrl-group button:focus {
  box-shadow: none;
}

.maplibregl-ctrl-group button:focus:not(:focus-visible) {
  outline: none;
  box-shadow: none;
}

.maplibregl-ctrl-group button:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
  box-shadow: none;
}

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