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

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #20252b;
  background: #eef2f5;
}

#app {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) auto;
  overflow: hidden;
}

#app.layers-panel-open,
#app.has-feature-detail {
  grid-template-columns: clamp(280px, 26vw, 430px) minmax(0, 1fr);
}

#app.layers-panel-open {
  grid-template-columns: clamp(220px, 20vw, 360px) minmax(0, 1fr);
}

#app.layers-panel-open.has-feature-detail {
  grid-template-columns: clamp(220px, 20vw, 360px) clamp(280px, 26vw, 430px) minmax(0, 1fr);
}

.sidebar {
  display: flex;
  grid-column: 1;
  grid-row: 1 / -1;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  overflow: hidden;
  background: white;
  border-right: 1px solid #bbc4ca;
}

.sidebar[hidden] {
  display: none;
}

.sidebar-header {
  display: grid;
  gap: 8px;
  padding: 10px;
  background: #f8fafb;
  border-bottom: 1px solid #ccd3d8;
}

.brand {
  font-weight: 700;
}

.selectors,
.selectors label {
  display: flex;
  min-width: 0;
}

.selectors label {
  width: 100%;
  gap: 5px;
  align-items: center;
  font-size: 13px;
}

select, button {
  font: inherit;
}

select {
  min-width: 0;
  max-width: 100%;
  flex: 1;
  padding: 4px 6px;
}

.panel-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  background: white;
  border-bottom: 1px solid #d9dfe3;
}

.panel-title span {
  color: #73808a;
  font-size: 12px;
}

.panel-help,
.panel-empty {
  margin: 0;
  padding: 8px 10px;
  color: #52616b;
  font-size: 12px;
  border-bottom: 1px solid #edf0f2;
}

#layersList {
  min-height: 0;
  overflow: auto;
}

.layers-tabs {
  position: sticky;
  z-index: 5;
  top: 0;
  display: grid;
  grid-template-columns: repeat(var(--layer-tab-count, 3), minmax(0, 1fr));
  background: white;
  border-bottom: 1px solid #bfc9cf;
}

.layers-tab {
  display: grid;
  gap: 1px;
  min-width: 0;
  padding: 8px 3px 6px;
  color: #52616b;
  background: #f4f7f9;
  border: 0;
  border-bottom: 3px solid transparent;
  cursor: pointer;
  font-size: 12px;
}

.layers-tab + .layers-tab {
  border-left: 1px solid #d9dfe3;
}

.layers-tab small {
  color: #73808a;
  font-size: 10px;
}

.layers-tab.is-active {
  color: #005b96;
  background: white;
  border-bottom-color: #0077b6;
  font-weight: 700;
}

.layers-tab-panel[hidden] {
  display: none;
}

.tab-empty {
  border-bottom: 0;
}

.layer-group-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  color: #34434d;
  background: #f4f7f9;
  border-bottom: 1px solid #d9dfe3;
  font-size: 12px;
}

details > .layer-group-heading {
  cursor: pointer;
  user-select: none;
}

.layer-group-heading span {
  color: #73808a;
  font-weight: 400;
}

.layer-group-selected {
  border-bottom: 3px solid #cbd5db;
}

.layer-group-selected .layer-row {
  background: #eef8ff;
}

.layer-group-selected .layer-row:hover {
  background: #e1f2ff;
}

.layer-group-selected.is-empty .layer-group-heading {
  color: #73808a;
}

.source-group {
  border-bottom: 1px solid #cbd5db;
}

.source-group-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  color: #24343f;
  background: #e8eef2;
  cursor: pointer;
  font-size: 12px;
  user-select: none;
}

.source-group-heading span,
.semantic-group-heading span:last-child {
  color: #667680;
  font-weight: 400;
}

.semantic-group-heading {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 5px 10px 5px 22px;
  color: #52616b;
  background: #f7f9fa;
  border-bottom: 1px solid #e2e7ea;
  font-size: 11px;
  font-weight: 600;
}

.layer-row {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 7px 10px;
  border-bottom: 1px solid #edf0f2;
  font-size: 13px;
}

.layer-row:hover {
  background: #f4f8fa;
}

.layer-row.is-loading {
  opacity: .6;
}

.layer-row input {
  flex: 0 0 auto;
}

.layer-row > .layer-text {
  cursor: pointer;
}

.layer-text {
  display: flex;
  min-width: 0;
  flex: 1;
  flex-direction: column;
  gap: 2px;
}

.layer-main {
  display: flex;
  min-width: 0;
  justify-content: space-between;
  gap: 8px;
}

.layer-name {
  overflow-wrap: anywhere;
}

.layer-meta {
  flex: 0 0 auto;
  color: #73808a;
}

.layer-summary {
  color: #52616b;
  font-size: 12px;
  line-height: 1.35;
}

.layer-classification {
  color: #7a8790;
  font-size: 10px;
  line-height: 1.3;
}

.favorite-button {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  padding: 0;
  color: #7a8790;
  background: transparent;
  border: 0;
  border-radius: 5px;
  cursor: pointer;
  font-size: 21px;
  line-height: 28px;
}

.favorite-button:hover,
.favorite-button:focus-visible {
  color: #b77900;
  background: #fff4cf;
  outline: none;
}

.favorite-button[aria-pressed="true"] {
  color: #e09b00;
}

.trash-button,
.restore-button {
  flex: 0 0 auto;
  min-width: 28px;
  height: 28px;
  padding: 0 5px;
  color: #687780;
  background: transparent;
  border: 0;
  border-radius: 5px;
  cursor: pointer;
  line-height: 28px;
}

.trash-button {
  font-size: 17px;
}

.trash-button:hover,
.trash-button:focus-visible {
  color: #a12b2b;
  background: #ffeaea;
  outline: none;
}

.restore-button {
  padding-inline: 7px;
  color: #006a78;
  background: #e8f7f9;
  font-size: 12px;
  font-weight: 700;
}

.restore-button:hover,
.restore-button:focus-visible {
  background: #cceff3;
  outline: 2px solid #6bbbc5;
  outline-offset: -2px;
}

.map-area {
  grid-column: 1;
  grid-row: 1;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

#app.layers-panel-open .map-area,
#app.layers-panel-open .statusbar,
#app.has-feature-detail .map-area,
#app.has-feature-detail .statusbar {
  grid-column: 2;
}

#app.layers-panel-open.has-feature-detail .map-area,
#app.layers-panel-open.has-feature-detail .statusbar {
  grid-column: 3;
}

.feature-detail-panel {
  display: flex;
  grid-column: 1;
  grid-row: 1 / -1;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  overflow: hidden;
  background: #fff;
  border-right: 1px solid #bbc4ca;
  box-shadow: 5px 0 16px rgb(31 47 58 / .09);
}

#app.layers-panel-open .feature-detail-panel {
  grid-column: 2;
}

.feature-detail-panel[hidden] {
  display: none;
}

.feature-detail-header {
  display: flex;
  flex: 0 0 auto;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 13px 14px 11px;
  background: #f4f8fa;
  border-bottom: 1px solid #d9dfe3;
}

.feature-detail-header small {
  color: #64737d;
  font-size: 11px;
  font-weight: 700;
}

.feature-detail-header h2 {
  margin: 3px 0 0;
  overflow-wrap: anywhere;
  font-size: 18px;
  line-height: 1.3;
}

.feature-detail-close {
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  padding: 0;
  color: #52616b;
  background: #fff;
  border: 1px solid #bbc4ca;
  border-radius: 5px;
  cursor: pointer;
  font-size: 22px;
  line-height: 26px;
}

.feature-detail-body {
  min-height: 0;
  padding: 12px 14px 24px;
  overflow: auto;
  overflow-wrap: anywhere;
  font-size: 13px;
}

.feature-detail-section {
  margin: 0 0 16px;
}

.feature-detail-section h3 {
  margin: 0 0 7px;
  padding-bottom: 5px;
  color: #34434d;
  border-bottom: 1px solid #dfe5e8;
  font-size: 13px;
}

.feature-detail-list {
  display: grid;
  grid-template-columns: minmax(86px, .42fr) minmax(0, 1fr);
  gap: 0;
  margin: 0;
}

.feature-detail-list dt,
.feature-detail-list dd {
  margin: 0;
  padding: 6px 0;
  border-bottom: 1px solid #edf0f2;
}

.feature-detail-list dt {
  padding-right: 10px;
  color: #667680;
  font-size: 11px;
  font-weight: 700;
}

.feature-detail-list dd {
  color: #20252b;
  white-space: pre-wrap;
}

.feature-detail-list a,
.feature-popup-content a {
  color: #006da8;
  text-decoration: underline;
}

.feature-popup-content {
  min-width: 220px;
  max-width: 360px;
  line-height: 1.45;
}

.feature-popup-dataset {
  margin: 4px 0;
  color: #667680;
  font-size: 11px;
}

#map {
  width: 100%;
  height: 100%;
}

.maplibregl-ctrl-group .maplibregl-ctrl-japan,
.maplibregl-ctrl-group .maplibregl-ctrl-world,
.maplibregl-ctrl-group .maplibregl-ctrl-location,
.maplibregl-ctrl-group .maplibregl-ctrl-tiles,
.maplibregl-ctrl-group .maplibregl-ctrl-place {
  width: auto;
  min-width: 58px;
  padding: 0 8px;
  font-weight: 700;
  line-height: 29px;
}

.maplibregl-ctrl-group .maplibregl-ctrl-tiles.is-active {
  color: #fff;
  background: #006da8;
}

.maplibregl-ctrl-group .maplibregl-ctrl-location {
  min-width: 72px;
}

.maplibregl-ctrl-location:disabled {
  color: #687780;
  cursor: wait;
}

.zoom-level-control {
  display: grid;
  justify-items: center;
  padding: 7px 5px 9px;
  color: #24343f;
  background: rgb(255 255 255 / .94);
  border-radius: 4px;
  box-shadow: 0 0 0 2px rgb(0 0 0 / .1);
}

.zoom-level-output {
  min-width: 42px;
  padding-bottom: 5px;
  color: #005b96;
  font-size: 14px;
  font-weight: 800;
  text-align: center;
}

.zoom-slider-area {
  position: relative;
  display: flex;
  height: 190px;
  align-items: stretch;
}

.zoom-level-slider {
  width: 28px;
  height: 190px;
  margin: 0 24px 0 0;
  padding: 0;
  accent-color: #0077b6;
  cursor: ns-resize;
  direction: rtl;
  writing-mode: vertical-lr;
}

.zoom-level-slider:focus-visible {
  outline: 2px solid #0077b6;
  outline-offset: 2px;
}

.zoom-slider-scale {
  position: absolute;
  top: 8px;
  right: 0;
  bottom: 8px;
  width: 22px;
  color: #5f6e77;
  font-size: 9px;
  pointer-events: none;
}

.zoom-slider-scale span {
  position: absolute;
  right: 0;
  line-height: 1;
  transform: translateY(50%);
}

.statusbar {
  display: flex;
  grid-column: 1;
  grid-row: 2;
  justify-content: space-between;
  gap: 12px;
  padding: 5px 9px;
  background: white;
  border-top: 1px solid #ccd3d8;
  font-size: 12px;
}

.status-main {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 10px;
}

#status {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-link {
  flex: 0 0 auto;
  min-width: 0;
  padding: 0;
  color: #005b96;
  background: transparent;
  border: 0;
  cursor: pointer;
  font-size: 12px;
  text-decoration: underline;
}

.status-link:hover,
.status-link:focus-visible {
  color: #003f69;
}

.display-settings-dialog {
  width: min(1500px, calc(100vw - 24px));
  max-height: min(90vh, 900px);
  padding: 0;
  overflow: hidden;
  border: 1px solid #9eabb3;
  border-radius: 10px;
  box-shadow: 0 18px 60px rgb(0 0 0 / .3);
}

.display-settings-dialog::backdrop {
  background: rgb(20 32 40 / .5);
}

.dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: #f4f7f9;
  border-bottom: 1px solid #d9dfe3;
}

.dialog-header h2 {
  margin: 0;
  font-size: 17px;
}

.dialog-close {
  width: 30px;
  height: 30px;
  padding: 0;
  background: white;
  border: 1px solid #bbc4ca;
  border-radius: 5px;
  cursor: pointer;
  font-size: 22px;
  line-height: 26px;
}

.dialog-intro {
  position: relative;
  padding: 9px 14px;
  border-bottom: 1px solid #d9dfe3;
}

.dialog-summary,
.dialog-help {
  margin: 0;
  color: #52616b;
  font-size: 13px;
}

.dialog-help {
  margin-top: 4px;
  padding-right: 360px;
  font-size: 12px;
}

.settings-global-actions {
  position: absolute;
  top: 12px;
  right: 14px;
  display: flex;
  gap: 5px;
}

.settings-scope-label {
  display: flex;
  align-items: center;
  gap: 5px;
  color: #40515c;
  font-size: 12px;
}

.settings-scope-label select {
  min-width: 100px;
  padding: 4px 6px;
}

.settings-reset-all {
  padding: 5px 8px;
  background: white;
  border: 1px solid #bbc4ca;
  border-radius: 5px;
  cursor: pointer;
  font-size: 12px;
}

.display-settings-list {
  max-height: calc(90vh - 142px);
  overflow: auto;
}

.zoom-matrix {
  width: max-content;
  min-width: 100%;
  border-spacing: 0;
  border-collapse: separate;
  color: #34434d;
  font-size: 11px;
}

.zoom-matrix th,
.zoom-matrix td {
  height: 34px;
  padding: 3px 5px;
  background: #fff;
  border-right: 1px solid #e1e6e9;
  border-bottom: 1px solid #e1e6e9;
  text-align: center;
}

.zoom-matrix thead th {
  position: sticky;
  z-index: 4;
  top: 0;
  min-width: 34px;
  color: #40515c;
  background: #eef3f6;
  cursor: pointer;
  font-weight: 700;
}

.zoom-matrix thead th:first-child {
  z-index: 6;
  left: 0;
  min-width: 300px;
  cursor: default;
  text-align: left;
}

.zoom-matrix tbody th {
  position: sticky;
  z-index: 2;
  left: 0;
  width: 300px;
  max-width: 300px;
  padding: 6px 9px;
  text-align: left;
}

.zoom-matrix tbody th strong,
.zoom-matrix tbody th small {
  display: block;
  overflow-wrap: anywhere;
}

.zoom-matrix tbody th small {
  margin-top: 2px;
  color: #6a7881;
  font-size: 9px;
  font-weight: 400;
  line-height: 1.25;
}

.zoom-matrix tbody tr:hover th,
.zoom-matrix tbody tr:hover td {
  background: #f3f8fb;
}

.zoom-matrix tbody tr.is-currently-visible th,
.zoom-matrix tbody tr.is-currently-visible td {
  background: #edf9f1;
}

.zoom-matrix input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: #0077b6;
}

.zoom-matrix input[type="checkbox"]:disabled {
  opacity: .18;
}

.matrix-favorite,
.matrix-recommend {
  padding: 2px 5px;
  border: 0;
  border-radius: 4px;
  cursor: pointer;
}

.matrix-favorite {
  color: #d18c00;
  background: transparent;
  font-size: 18px;
}

.matrix-recommend {
  color: #005b96;
  background: #eaf5fb;
  font-size: 10px;
  font-weight: 700;
}

.display-setting-row {
  display: grid;
  grid-template-columns: minmax(230px, 1fr) auto auto auto auto auto;
  gap: 12px;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid #edf0f2;
  font-size: 13px;
}

.display-setting-row.is-outside-zoom {
  background: #f8fafb;
}

.setting-file {
  display: grid;
  min-width: 0;
  gap: 2px;
}

.setting-file strong {
  overflow-wrap: anywhere;
}

.setting-file small {
  color: #687780;
}

.setting-state {
  width: fit-content;
  padding: 1px 6px;
  color: #17643b;
  background: #e7f7ee;
  border-radius: 999px;
  font-size: 10px;
}

.setting-state.is-off {
  color: #687780;
  background: #e9eef1;
}

.setting-order-label {
  width: fit-content;
  color: #005b96;
  font-size: 10px;
  font-weight: 700;
}

.setting-order-controls {
  display: grid;
  gap: 3px;
}

.setting-order-button {
  min-width: 62px;
  padding: 3px 6px;
  color: #005b96;
  background: #f6fbff;
  border: 1px solid #9dbfd2;
  border-radius: 5px;
  cursor: pointer;
  font-size: 11px;
}

.setting-order-button:disabled {
  color: #9aa5ab;
  background: #f1f3f4;
  border-color: #d3d9dc;
  cursor: default;
}

.setting-control {
  display: flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}

.setting-control input[type="number"] {
  width: 52px;
  padding: 4px 5px;
}

.setting-reset {
  padding: 4px 7px;
  color: #40515c;
  background: white;
  border: 1px solid #bbc4ca;
  border-radius: 5px;
  cursor: pointer;
  font-size: 11px;
}

.setting-actions {
  display: flex;
  gap: 4px;
}

.settings-empty {
  margin: 0;
  padding: 24px 14px;
  color: #687780;
  text-align: center;
}

@media (max-width: 700px) {
  #app {
    grid-template-columns: minmax(0, 1fr);
  }

  #app.layers-panel-open,
  #app.layers-panel-open.has-feature-detail {
    grid-template-columns: minmax(170px, 42vw) minmax(0, 1fr);
  }

  #app.has-feature-detail {
    grid-template-columns: minmax(0, 1fr);
  }

  #app.has-feature-detail .map-area,
  #app.has-feature-detail .statusbar {
    grid-column: 1;
  }

  #app.layers-panel-open .map-area,
  #app.layers-panel-open .statusbar,
  #app.layers-panel-open.has-feature-detail .map-area,
  #app.layers-panel-open.has-feature-detail .statusbar {
    grid-column: 2;
  }

  .feature-detail-panel {
    position: absolute;
    z-index: 20;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(88vw, 380px);
    border-left: 1px solid #bbc4ca;
  }

  .brand {
    font-size: 14px;
  }

  .statusbar {
    flex-direction: column;
    gap: 2px;
  }

  .display-setting-row {
    grid-template-columns: 1fr 1fr;
  }

  .display-settings-dialog {
    width: calc(100vw - 8px);
    max-height: 94vh;
  }

  .display-settings-list {
    max-height: calc(94vh - 190px);
  }

  .zoom-matrix thead th:first-child,
  .zoom-matrix tbody th {
    min-width: 190px;
    width: 190px;
    max-width: 190px;
  }

  .setting-file {
    grid-column: 1 / -1;
  }

  .dialog-help {
    padding-right: 0;
  }

  .settings-global-actions {
    position: static;
    flex-wrap: wrap;
    margin-top: 8px;
  }

  .zoom-slider-area,
  .zoom-level-slider {
    height: 140px;
  }
}
