* {
  box-sizing: border-box;
}

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

body {
  overflow: hidden;
  color: #1e293b;
  background: #d8d5cf;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

.app-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 56px;
  padding: 8px 14px;
  color: #f8fafc;
  background: #263238;
  border-bottom: 1px solid rgba(255, 255, 255, 0.16);
  gap: 12px;
}

.app-title {
  display: flex;
  align-items: baseline;
  min-width: 0;
  gap: 10px;
}

.title-main {
  font-size: 17px;
  font-weight: 700;
  white-space: nowrap;
}

.title-sub {
  overflow: hidden;
  color: #cfd8dc;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mode-toggle {
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  min-width: 190px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.26);
  border-radius: 8px;
}

.mode-button {
  min-height: 34px;
  padding: 0 14px;
  color: #e2e8f0;
  background: rgba(255, 255, 255, 0.08);
  border: 0;
  cursor: pointer;
}

.mode-button + .mode-button {
  border-left: 1px solid rgba(255, 255, 255, 0.22);
}

.mode-button.is-active {
  color: #102027;
  background: #f4c95d;
  font-weight: 700;
}

.app-shell {
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  height: calc(100vh - 56px);
  min-height: 360px;
}

.comparison-root,
.dual-layout,
.swipe-layout,
.map-pane,
.map-canvas {
  width: 100%;
  height: 100%;
}

.comparison-root {
  min-width: 0;
  min-height: 0;
}

.dual-layout {
  display: flex;
}

.map-pane {
  position: relative;
  overflow: hidden;
  background: #e9e6df;
}

.dual-layout .map-pane {
  flex: 1 1 50%;
  min-width: 0;
}

.dual-layout .map-pane + .map-pane {
  border-left: 2px solid #263238;
}

.map-canvas {
  position: absolute;
  inset: 0;
}

.side-badge,
.swipe-label {
  position: absolute;
  z-index: 5;
  top: 12px;
  max-width: min(360px, calc(100% - 24px));
  padding: 7px 10px;
  color: #ffffff;
  background: rgba(15, 23, 42, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 6px;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.3;
  white-space: normal;
}

.map-pane[data-side="left"] .side-badge {
  left: 12px;
}

.map-pane[data-side="right"] .side-badge {
  right: 12px;
}

.swipe-layout {
  position: relative;
  overflow: hidden;
}

.swipe-layout .map-pane {
  position: absolute;
  inset: 0;
}

.map-pane-base {
  z-index: 1;
}

.map-pane-clip {
  z-index: 2;
}

.swipe-label {
  top: 12px;
  pointer-events: none;
}

.swipe-label-left {
  left: 50px;
  z-index: 7;
}

.swipe-label-right {
  right: 50px;
  z-index: 3;
}

.mode-swipe .side-badge {
  display: none;
}

.swipe-layer-controls {
  position: absolute;
  z-index: 9;
  inset: 0;
  pointer-events: none;
}

.swipe-layer-slot {
  position: absolute;
  right: 12px;
  width: min(235px, 42vw);
  pointer-events: none;
}

.swipe-layer-slot-left {
  right: 259px;
  bottom: 12px;
}

.swipe-layer-slot-right {
  bottom: 12px;
}

.swipe-layer-slot .layer-panel {
  position: relative;
  top: auto;
  right: auto;
  bottom: auto;
  width: 100%;
  max-height: none;
  pointer-events: auto;
}

.swipe-handle {
  position: absolute;
  z-index: 8;
  top: 0;
  bottom: 0;
  width: 34px;
  padding: 0;
  transform: translateX(-50%);
  background: transparent;
  border: 0;
  cursor: ew-resize;
}

.swipe-handle::before {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 16px;
  width: 3px;
  content: "";
  background: #f4c95d;
  box-shadow: 0 0 0 1px rgba(38, 50, 56, 0.78);
}

.swipe-handle::after {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 30px;
  height: 54px;
  content: "";
  transform: translate(-50%, -50%);
  background: #263238;
  border: 2px solid #f4c95d;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.28);
}

.layer-panel {
  position: absolute;
  z-index: 9;
  right: 12px;
  bottom: 12px;
  width: min(245px, calc(100% - 24px));
  max-height: calc(100% - 24px);
  overflow: auto;
  padding: 10px;
  color: #1f2937;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(15, 23, 42, 0.15);
  border-radius: 8px;
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.22);
}

.map-pane[data-side="left"] .layer-panel {
  right: 12px;
}

.map-pane[data-side="right"] .layer-panel {
  right: 12px;
}

.mode-swipe .map-pane[data-side="left"] .layer-panel {
  right: 12px;
  width: min(235px, 42vw);
}

.mode-swipe .map-pane[data-side="right"] .layer-panel {
  right: 12px;
  width: min(235px, 42vw);
}

.layer-panel h2 {
  margin: 0 0 8px;
  color: #0f172a;
  font-size: 13px;
  line-height: 1.3;
}

.layer-group + .layer-group {
  margin-top: 9px;
  padding-top: 8px;
  border-top: 1px solid #e5e7eb;
}

.layer-group-title {
  margin-bottom: 4px;
  color: #64748b;
  font-size: 11px;
  font-weight: 700;
}

.layer-toggle {
  display: grid;
  grid-template-columns: 18px 14px minmax(0, 1fr);
  align-items: center;
  min-height: 26px;
  gap: 7px;
  color: #1f2937;
  font-size: 12px;
  line-height: 1.25;
}

.layer-toggle input {
  width: 16px;
  height: 16px;
  margin: 0;
}

.layer-swatch {
  width: 13px;
  height: 13px;
  border: 1px solid rgba(15, 23, 42, 0.28);
  border-radius: 3px;
}

.layer-label {
  min-width: 0;
  overflow-wrap: anywhere;
}

.legend-panel {
  position: relative;
  z-index: 10;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  width: clamp(240px, 22vw, 300px);
  height: 100%;
  max-height: none;
  color: #1f2937;
  background: rgba(255, 255, 255, 0.94);
  border: 0;
  border-right: 1px solid rgba(15, 23, 42, 0.22);
  border-radius: 0;
  box-shadow: 4px 0 16px rgba(15, 23, 42, 0.14);
}

.legend-panel.is-collapsed {
  width: 86px;
}

.legend-header {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  min-height: 38px;
  padding: 8px 10px;
  border-bottom: 1px solid #e2e8f0;
  gap: 8px;
}

.legend-header h2 {
  margin: 0;
  font-size: 14px;
  white-space: nowrap;
}

.legend-collapse {
  justify-self: end;
  min-height: 26px;
  padding: 0 9px;
  color: #334155;
  background: #f8fafc;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  cursor: pointer;
}

.legend-content.is-hidden {
  display: none;
}

.legend-content {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-height: 0;
}

.legend-body {
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  overflow: auto;
  padding: 10px;
}

.legend-current {
  min-width: 0;
  overflow: hidden;
  padding: 4px 7px;
  color: #0f172a;
  background: #fef3c7;
  border: 1px solid #fde68a;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.legend-tree-major,
.legend-tree-middle {
  margin: 0;
}

.legend-tree-major + .legend-tree-major {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid #e2e8f0;
}

.legend-tree-major > summary,
.legend-tree-middle > summary {
  cursor: pointer;
  list-style-position: inside;
  overflow-wrap: anywhere;
}

.legend-tree-major > summary {
  color: #0f172a;
  font-size: 13px;
  font-weight: 800;
}

.legend-tree-middle {
  margin-top: 6px;
  padding-left: 12px;
}

.legend-tree-middle > summary {
  color: #334155;
  font-size: 12px;
  font-weight: 700;
}

.legend-tree-items {
  display: grid;
  gap: 4px;
  margin: 6px 0 0;
}

.legend-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  min-height: 24px;
  gap: 10px;
  padding: 3px 0;
  font-size: 11px;
}

.legend-item.is-muted {
  color: #94a3b8;
}

.legend-item-name {
  overflow-wrap: anywhere;
}

.zoom-marks {
  display: inline-grid;
  grid-template-columns: repeat(3, 26px);
  gap: 3px;
}

.zoom-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 20px;
  color: #94a3b8;
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  border-radius: 5px;
  font-size: 10px;
  font-weight: 700;
}

.zoom-mark.is-on {
  color: #0f172a;
  background: #e0f2fe;
  border-color: #7dd3fc;
}

.zoom-mark.is-current {
  outline: 2px solid #f59e0b;
  outline-offset: 1px;
}

.legend-empty {
  color: #64748b;
  font-size: 12px;
}

.fukidashi-popup h4 {
  margin: 0 0 7px;
  color: #0f172a;
  font-size: 14px;
}

.fukidashi-popup p {
  margin: 0;
  color: #334155;
  font-size: 13px;
  line-height: 1.55;
}

.kp-popup h4 {
  margin: 0 0 8px;
  color: #0f172a;
  font-size: 14px;
}

.kp-popup-list {
  display: grid;
  gap: 8px;
}

.kp-popup-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 4px 10px;
  margin: 0;
}

.kp-popup-item + .kp-popup-item {
  padding-top: 8px;
  border-top: 1px solid #e2e8f0;
}

.kp-popup-item dt {
  color: #64748b;
  font-size: 12px;
  font-weight: 700;
}

.kp-popup-item dd {
  min-width: 0;
  margin: 0;
  color: #0f172a;
  font-size: 13px;
  overflow-wrap: anywhere;
}

.detail-panel {
  position: fixed;
  z-index: 20;
  top: 56px;
  right: 0;
  bottom: 0;
  display: flex;
  width: min(760px, 52vw);
  min-width: 420px;
  flex-direction: column;
  visibility: hidden;
  overflow: hidden;
  transform: translateX(100%);
  background: #ffffff;
  border-left: 1px solid rgba(15, 23, 42, 0.24);
  box-shadow: -12px 0 30px rgba(15, 23, 42, 0.24);
  pointer-events: none;
  transition: transform 220ms ease, visibility 0s linear 220ms;
}

.detail-panel.is-open {
  visibility: visible;
  transform: translateX(0);
  pointer-events: auto;
  transition: transform 220ms ease;
}

.detail-panel-header {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  min-height: 48px;
  padding: 8px 10px 8px 14px;
  background: #ffffff;
  border-bottom: 1px solid #e2e8f0;
  gap: 12px;
}

.detail-panel-header h2 {
  min-width: 0;
  margin: 0;
  color: #0f172a;
  font-size: 16px;
  overflow-wrap: anywhere;
}

.detail-panel-close {
  display: inline-flex;
  flex: 0 0 34px;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  color: #334155;
  background: #f8fafc;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  cursor: pointer;
  font-size: 24px;
  line-height: 1;
}

.detail-panel-close:hover,
.detail-panel-close:focus-visible {
  color: #0f172a;
  background: #e2e8f0;
}

.detail-panel-body {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
  align-items: center;
  justify-content: center;
  overflow: auto;
  padding: 12px;
  background: #e5e7eb;
}

.detail-panel-body img {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  max-height: calc(100vh - 128px);
  object-fit: contain;
}

@media (max-width: 780px) {
  .app-toolbar {
    align-items: stretch;
    flex-direction: column;
    min-height: 92px;
  }

  .app-shell {
    grid-template-columns: minmax(86px, 34vw) minmax(0, 1fr);
    height: calc(100vh - 92px);
  }

  .app-title {
    justify-content: space-between;
  }

  .title-main {
    font-size: 15px;
  }

  .mode-toggle {
    width: 100%;
  }

  .dual-layout {
    flex-direction: column;
  }

  .dual-layout .map-pane + .map-pane {
    border-top: 2px solid #263238;
    border-left: 0;
  }

  .legend-panel {
    width: 100%;
    height: 100%;
    border-right: 1px solid rgba(15, 23, 42, 0.22);
    box-shadow: 4px 0 16px rgba(15, 23, 42, 0.14);
  }

  .legend-panel.is-collapsed {
    width: 86px;
  }

  .layer-panel {
    width: min(230px, calc(100% - 24px));
  }

  .mode-swipe .layer-panel {
    width: min(210px, 44vw);
  }

  .swipe-layer-slot {
    right: 12px;
    width: min(210px, 44vw);
  }

  .swipe-layer-slot-left {
    right: 12px;
    bottom: 328px;
  }

  .swipe-layer-slot-right {
    bottom: 12px;
  }

  .swipe-label-left {
    left: 42px;
  }

  .swipe-label-right {
    right: 42px;
  }

  .detail-panel {
    top: auto;
    left: 0;
    width: 100%;
    min-width: 0;
    height: min(72vh, 640px);
    border-top: 1px solid rgba(15, 23, 42, 0.24);
    border-left: 0;
    box-shadow: 0 -12px 30px rgba(15, 23, 42, 0.24);
    transform: translateY(100%);
  }

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

  .detail-panel-body {
    padding: 6px;
  }

  .detail-panel-body img {
    max-height: calc(72vh - 62px);
  }
}
