:root {
  color-scheme: light;
  --bg: #f6fbff;
  --surface: #ffffff;
  --surface-muted: #f2f7fb;
  --line: #dbe8ef;
  --line-strong: #b8ccd8;
  --text: #11242d;
  --muted: #5d7180;
  --primary: #07808a;
  --primary-strong: #05626c;
  --accent: #c63e7a;
  --speed: #2c74d6;
  --road: #c87916;
  --relation: #6f54c9;
  --danger: #c64040;
  --shadow: 0 18px 44px rgba(27, 69, 89, 0.12);
  font-family: "Segoe UI", "Yu Gothic UI", "Meiryo", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  width: 100vw;
  height: 100vh;
  background:
    linear-gradient(135deg, rgba(7, 128, 138, 0.1), transparent 34%),
    linear-gradient(315deg, rgba(198, 121, 22, 0.09), transparent 38%),
    var(--bg);
  color: var(--text);
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--text);
  min-height: 38px;
  border-radius: 7px;
  cursor: pointer;
  transition: border-color 160ms ease, background 160ms ease, color 160ms ease, transform 160ms ease;
}

button:hover {
  border-color: var(--primary);
  background: #f8fcff;
}

button:active {
  transform: translateY(1px);
}

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

input,
select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  padding: 8px 10px;
  background: #fff;
  color: var(--text);
}

input:focus,
select:focus,
button:focus-visible {
  outline: 3px solid rgba(23, 107, 98, 0.2);
  outline-offset: 1px;
  border-color: var(--primary);
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(300px, 360px) minmax(460px, 1fr) minmax(300px, 380px);
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

.control-panel,
.result-panel {
  background: rgba(255, 255, 255, 0.92);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  overscroll-behavior: contain;
  backdrop-filter: blur(14px);
}

.result-panel {
  border-right: 0;
  border-left: 1px solid var(--line);
}

.panel-header,
.result-header {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px;
  background: rgba(255, 255, 255, 0.9);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.panel-header h1,
.result-header h2 {
  margin: 3px 0 0;
  font-size: 22px;
  line-height: 1.2;
}

.eyebrow {
  margin: 0;
  color: var(--primary);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.status-dot {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 999px;
  background: var(--danger);
  box-shadow: 0 0 0 5px rgba(183, 51, 51, 0.12);
}

.status-dot.ready {
  background: #15864f;
  box-shadow: 0 0 0 5px rgba(21, 134, 79, 0.12);
}

.control-section {
  padding: 19px 20px;
  border-bottom: 1px solid var(--line);
}

.control-section h2 {
  margin: 0 0 12px;
  font-size: 14px;
  line-height: 1.35;
}

.section-title-row,
.inline-row,
.readout-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.inline-row {
  margin-top: 10px;
}

.field {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.field + .field {
  margin-top: 10px;
}

.check-field {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.check-field input {
  width: 16px;
  min-height: 16px;
}

.block-check {
  margin-top: 10px;
  min-height: 34px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #ffffff;
}

.text-button {
  border-color: transparent;
  color: var(--primary);
  background: transparent;
  padding: 0 4px;
  font-weight: 700;
}

.text-button:hover {
  border-color: transparent;
  background: rgba(23, 107, 98, 0.08);
}

.compact {
  min-height: 30px;
}

.readout-row {
  min-height: 38px;
  padding: 9px 10px;
  background: var(--surface-muted);
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--muted);
  font-size: 12px;
}

.readout-row strong {
  color: var(--text);
  font-size: 13px;
}

.endpoint-readout {
  min-height: 38px;
  display: flex;
  align-items: center;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: linear-gradient(180deg, #ffffff, var(--surface-muted));
  color: var(--primary);
  font-size: 13px;
  font-weight: 900;
}

.coord-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.coord-grid .field + .field {
  margin-top: 0;
}

.button-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}

.hint,
.status-message {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.status-message {
  min-height: 38px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-muted);
}

.status-message.error {
  border-color: rgba(183, 51, 51, 0.32);
  background: rgba(183, 51, 51, 0.07);
  color: var(--danger);
}

.status-message.success {
  border-color: rgba(21, 134, 79, 0.28);
  background: rgba(21, 134, 79, 0.07);
  color: #11693f;
}

.primary-button {
  width: 100%;
  margin-top: 12px;
  background: linear-gradient(135deg, var(--primary), #12a0a8);
  border-color: var(--primary);
  color: #fff;
  font-weight: 800;
  box-shadow: 0 10px 22px rgba(7, 128, 138, 0.22);
}

.primary-button:hover {
  background: var(--primary-strong);
  border-color: var(--primary-strong);
}

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

.filter-chip {
  min-height: 31px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 800;
  border-radius: 999px;
}

.filter-chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  box-shadow: 0 8px 18px rgba(7, 128, 138, 0.18);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 14px;
}

.summary-grid div {
  display: grid;
  gap: 4px;
  padding: 10px;
  background: linear-gradient(180deg, #ffffff, var(--surface-muted));
  border: 1px solid var(--line);
  border-radius: 7px;
  box-shadow: 0 8px 18px rgba(27, 69, 89, 0.06);
}

.summary-grid span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.summary-grid strong {
  font-size: 18px;
}

.map-area {
  position: relative;
  min-height: 0;
  height: 100vh;
  overflow: hidden;
  overscroll-behavior: contain;
}

.map-toolbar {
  position: absolute;
  z-index: 4;
  top: 16px;
  left: 16px;
  right: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  pointer-events: none;
}

.legend,
.source-note {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 36px;
  padding: 8px 12px;
  border: 1px solid rgba(23, 33, 31, 0.12);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  backdrop-filter: blur(12px);
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend-swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 3px;
}

.legend-swatch.turn {
  background: var(--accent);
}

.legend-swatch.restriction-point {
  border-radius: 999px;
  background: var(--accent);
  box-shadow: inset 0 0 0 2px #ffffff, 0 0 0 1px rgba(198, 62, 122, 0.45);
}

.legend-swatch.flow {
  border-radius: 999px;
  background: linear-gradient(90deg, var(--primary) 0 33%, var(--accent) 33% 66%, var(--road) 66% 100%);
}

.legend-swatch.speed {
  background: var(--speed);
}

.legend-swatch.road {
  background: var(--road);
}

.legend-swatch.relation {
  background: var(--relation);
}

.map-canvas {
  width: 100%;
  height: 100%;
  background: #e7f1f5;
}

.map-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(90deg, rgba(255,255,255,0.65) 1px, transparent 1px),
    linear-gradient(rgba(255,255,255,0.65) 1px, transparent 1px),
    #e7f1f5;
  background-size: 44px 44px;
  color: var(--text);
  text-align: center;
}

.map-placeholder.hidden {
  display: none;
}

.map-placeholder h2 {
  margin: 0 0 8px;
  font-size: 24px;
}

.map-placeholder p {
  max-width: 430px;
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.copy-toast {
  position: absolute;
  z-index: 8;
  right: 18px;
  top: 68px;
  display: grid;
  gap: 3px;
  max-width: min(360px, calc(100% - 36px));
  padding: 10px 12px;
  border: 1px solid rgba(7, 128, 138, 0.18);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 16px 34px rgba(27, 69, 89, 0.16);
  color: var(--text);
  pointer-events: none;
  opacity: 0;
  transform: translateY(-8px) scale(0.98);
  transition: opacity 170ms ease, transform 170ms ease;
  backdrop-filter: blur(12px);
}

.copy-toast.visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.copy-toast.warning {
  border-color: rgba(198, 64, 64, 0.25);
}

.copy-toast strong {
  color: var(--primary);
  font-size: 12px;
}

.copy-toast.warning strong {
  color: var(--danger);
}

.copy-toast span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.result-header {
  min-height: 78px;
}

.result-header span {
  color: var(--muted);
  font-weight: 800;
  white-space: nowrap;
}

.result-list {
  padding: 14px;
}

.empty-state {
  padding: 24px 10px;
  color: var(--muted);
  text-align: center;
}

.empty-state h3 {
  margin: 0 0 8px;
  color: var(--text);
  font-size: 16px;
}

.empty-state p {
  margin: 0 auto;
  max-width: 280px;
  font-size: 13px;
  line-height: 1.6;
}

.change-card {
  width: 100%;
  display: grid;
  gap: 8px;
  margin-bottom: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-left: 5px solid var(--relation);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.96);
  text-align: left;
  box-shadow: 0 10px 26px rgba(27, 69, 89, 0.08);
  transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.change-card:hover,
.change-card.selected {
  border-color: var(--primary);
  border-left-color: var(--primary);
  box-shadow: 0 16px 34px rgba(27, 69, 89, 0.12);
  transform: translateY(-1px);
}

.change-card.turn {
  border-left-color: var(--accent);
}

.change-card.speed {
  border-left-color: var(--speed);
}

.change-card.road {
  border-left-color: var(--road);
}

.change-card.other {
  border-left-color: #6f7d79;
}

.change-card-main {
  display: grid;
  gap: 8px;
  width: 100%;
  min-height: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.change-card-main:hover {
  border-color: transparent;
  background: transparent;
}

.change-title-row,
.change-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.change-title-row strong {
  font-size: 14px;
  line-height: 1.35;
}

.badge {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--surface-muted);
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
}

.change-summary {
  color: var(--text);
  font-size: 12px;
  line-height: 1.5;
}

.change-overview,
.overview-text {
  padding: 9px 10px;
  border: 1px solid rgba(7, 128, 138, 0.16);
  border-radius: 7px;
  background: #f2fbfc;
  color: #174c55;
  font-size: 12px;
  font-weight: 750;
  line-height: 1.55;
}

.element-facts {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.element-facts span {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  max-width: 100%;
  padding: 0 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f9fcff;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.osm-link-row {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.osm-link-row a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: #ffffff;
  color: var(--primary);
  font-size: 12px;
  font-weight: 900;
  text-decoration: none;
  box-shadow: 0 6px 14px rgba(27, 69, 89, 0.07);
}

.osm-link-row a:hover {
  border-color: var(--primary);
  background: #eefbfc;
}

.osm-link-row .primary-link {
  border-color: var(--primary);
  background: var(--primary);
  color: #ffffff;
}

.osm-link-row .primary-link:hover {
  background: var(--primary-strong);
}

.info-link-row {
  margin: 8px 0;
}

.speed-accordion {
  border: 1px solid rgba(44, 116, 214, 0.18);
  border-radius: 7px;
  background: #f4f8ff;
  overflow: hidden;
}

.speed-accordion summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 38px;
  padding: 9px 10px;
  color: var(--speed);
  font-size: 12px;
  font-weight: 900;
  cursor: pointer;
}

.speed-accordion summary::-webkit-details-marker {
  display: none;
}

.speed-accordion summary::after {
  content: "+";
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: #ffffff;
  color: var(--speed);
  box-shadow: inset 0 0 0 1px rgba(44, 116, 214, 0.22);
}

.speed-accordion[open] summary::after {
  content: "-";
}

.speed-accordion small {
  margin-left: auto;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.speed-accordion p {
  margin: 0;
  padding: 0 10px 10px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.speed-accordion .diff-table {
  margin: 0 10px 10px;
  width: calc(100% - 20px);
  background: #ffffff;
}

.change-meta {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.diff-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 8px;
  font-size: 12px;
}

.diff-table th,
.diff-table td {
  padding: 6px;
  border: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.diff-table th {
  background: var(--surface-muted);
  color: var(--muted);
}

.detail-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 8px;
  font-size: 12px;
}

.detail-table th,
.detail-table td {
  padding: 6px;
  border: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  overflow-wrap: anywhere;
}

.detail-table th {
  width: 34%;
  background: var(--surface-muted);
  color: var(--muted);
}

.member-table th,
.member-table td {
  font-size: 11px;
}

.info-window {
  max-width: 420px;
  color: var(--text);
}

.info-window h3 {
  margin: 0 0 8px;
  font-size: 15px;
}

.info-window p {
  margin: 0 0 6px;
  font-size: 12px;
  line-height: 1.45;
}

.info-window a {
  color: var(--primary);
  font-weight: 800;
}

.relation-analysis {
  margin-top: 8px;
}

.restriction-flow {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: stretch;
  gap: 6px;
  margin: 10px 0;
}

.flow-step {
  display: grid;
  gap: 3px;
  min-width: 0;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #ffffff;
}

.flow-step.from {
  border-color: rgba(7, 128, 138, 0.25);
  background: #f1fbfc;
}

.flow-step.via {
  border-color: rgba(198, 62, 122, 0.25);
  background: #fff4f8;
}

.flow-step.to {
  border-color: rgba(200, 121, 22, 0.25);
  background: #fff8ef;
}

.flow-role {
  display: inline-flex;
  width: max-content;
  padding: 2px 6px;
  border-radius: 999px;
  background: var(--text);
  color: #ffffff;
  font-size: 10px;
  font-weight: 900;
  text-transform: uppercase;
}

.flow-step strong {
  font-size: 12px;
}

.flow-step small {
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.flow-arrow {
  display: grid;
  place-items: center;
  color: var(--primary);
  font-weight: 900;
}

.warning-text {
  color: var(--danger);
  font-weight: 800;
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 330px 1fr;
    grid-template-rows: minmax(0, 1fr) minmax(220px, 34vh);
  }

  .result-panel {
    grid-column: 1 / -1;
    min-height: 0;
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .result-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 10px;
  }

  .change-card {
    margin-bottom: 0;
  }
}

@media (max-width: 820px) {
  body {
    overflow: auto;
  }

  .app-shell {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .control-panel,
  .result-panel {
    max-height: none;
    overflow: visible;
  }

  .map-area {
    min-height: 70vh;
    height: 70vh;
  }

  .map-canvas {
    height: 100%;
  }

  .map-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .legend {
    flex-wrap: wrap;
  }

  .coord-grid,
  .button-grid {
    grid-template-columns: 1fr;
  }

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

  .restriction-flow {
    grid-template-columns: 1fr;
  }

  .flow-arrow {
    transform: rotate(90deg);
  }
}
