:root {
  color-scheme: light;
  --ink: #17201c;
  --muted: #64706a;
  --line: #d9dfdb;
  --surface: #ffffff;
  --panel: #f7f8f5;
  --panel-strong: #edf2ee;
  --teal: #007f79;
  --green: #3f7d20;
  --amber: #b76a00;
  --red: #b13b3b;
  --violet: #5b4bb2;
  --blue: #2f6690;
  --shadow: 0 18px 38px rgb(23 32 28 / 12%);
  font-family:
    "Yu Gothic UI", "Hiragino Sans", Meiryo, system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background: #e9ece7;
  color: var(--ink);
  overflow-x: hidden;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: clamp(318px, 26vw, 390px) minmax(0, 1fr);
  min-height: 100vh;
  width: 100%;
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 20px;
  overflow-y: auto;
}

.brand-row,
.topbar,
.panel-title,
.toolbar,
.split-fields,
.preset-row,
.source-row {
  display: flex;
  align-items: center;
}

.brand-row,
.topbar,
.panel-title,
.source-row {
  justify-content: space-between;
  gap: 12px;
}

.brand-row {
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--teal);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.35rem, 3vw, 1.75rem);
  line-height: 1.25;
}

h2 {
  margin-bottom: 0;
  font-size: 1rem;
}

.mode-badge,
.source-tag {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 9px;
  color: var(--muted);
  background: var(--panel);
  font-size: 0.75rem;
  white-space: nowrap;
}

.panel,
.result-panel,
.metric-tile,
.chart-panel,
.source-panel,
.report-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.panel {
  padding: 14px;
  margin-bottom: 12px;
}

.panel-title {
  margin-bottom: 12px;
}

.advanced-panel {
  padding: 0;
}

.advanced-panel[open] {
  padding-bottom: 14px;
}

.details-title {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  margin-bottom: 0;
  padding: 14px;
  list-style: none;
  cursor: pointer;
}

.details-title::-webkit-details-marker {
  display: none;
}

.details-title::after {
  content: "+";
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--muted);
  background: #fff;
  font-weight: 900;
}

.details-title .source-tag {
  justify-self: end;
}

.advanced-panel[open] > .details-title {
  margin-bottom: 6px;
}

.advanced-panel[open] > .details-title::after {
  content: "−";
}

.advanced-panel > label,
.advanced-panel > .split-fields,
.advanced-panel > .advanced-note {
  margin-left: 14px;
  margin-right: 14px;
}

.advanced-note {
  margin-bottom: 4px;
}

label {
  display: grid;
  gap: 6px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

label.is-disabled {
  opacity: 0.72;
}

label.is-disabled input {
  background: var(--panel);
}

.field-note {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.55;
}

input,
select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 10px;
  background: #fff;
  color: var(--ink);
}

input:focus,
select:focus,
button:focus-visible {
  outline: 3px solid rgb(0 127 121 / 22%);
  outline-offset: 2px;
}

input[type="range"] {
  min-height: 26px;
  padding: 0;
  accent-color: var(--teal);
}

output {
  justify-self: end;
  color: var(--ink);
  font-size: 0.82rem;
}

.split-fields {
  gap: 10px;
}

.split-fields > label {
  flex: 1 1 0;
}

.unit-input {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.unit-input input {
  border: 0;
  min-width: 0;
}

.unit-input span {
  padding-right: 10px;
  color: var(--muted);
  font-size: 0.82rem;
}

.check-row {
  grid-template-columns: 18px 1fr;
  align-items: center;
  color: var(--ink);
}

.check-row input {
  width: 18px;
  min-height: 18px;
  accent-color: var(--teal);
}

.segmented {
  display: inline-grid;
  grid-auto-flow: column;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}

.segment,
.text-button,
.icon-button,
.primary-button {
  border: 0;
  min-height: 36px;
  padding: 0 12px;
  background: transparent;
  color: var(--ink);
  font-weight: 800;
}

.segment {
  border-right: 1px solid var(--line);
  font-size: 0.78rem;
}

.segment:last-child {
  border-right: 0;
}

.segment.is-active {
  background: var(--ink);
  color: #fff;
}

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

.text-button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  font-size: 0.8rem;
}

.icon-button {
  width: 40px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  font-size: 1.1rem;
}

.primary-button {
  border-radius: 6px;
  background: var(--teal);
  color: #fff;
}

.locate-button {
  min-width: 150px;
  min-height: 42px;
  padding: 0 14px;
  white-space: nowrap;
}

.main-stage {
  min-width: 0;
  max-width: 100%;
  padding: 22px;
  overflow-x: hidden;
}

.topbar {
  margin-bottom: 18px;
  min-width: 0;
}

.topbar > div:first-child {
  min-width: 0;
}

.topbar h2 {
  font-size: clamp(1.4rem, 3vw, 2.1rem);
  line-height: 1.22;
  overflow-wrap: anywhere;
}

.toolbar {
  gap: 8px;
}

.hero-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 420px);
  gap: 16px;
  min-width: 0;
}

.map-panel {
  min-height: 382px;
}

.map {
  position: relative;
  height: 100%;
  min-height: 382px;
  border: 1px solid #bac8bf;
  border-radius: 8px;
  overflow: hidden;
  background: #dce8df;
  box-shadow: var(--shadow);
  cursor: grab;
  touch-action: none;
}

.map.is-locked {
  cursor: default;
  touch-action: pan-y;
}

.map.is-dragging {
  cursor: grabbing;
}

.tile-layer {
  position: absolute;
  inset: 0;
}

.tile-layer img {
  position: absolute;
  width: 256px;
  height: 256px;
  pointer-events: none;
  user-select: none;
}

.map-marker {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 22px;
  height: 22px;
  border: 4px solid #fff;
  border-radius: 50%;
  background: var(--red);
  box-shadow: 0 6px 16px rgb(0 0 0 / 25%);
  transform: translate(-50%, -50%);
}

.map-marker::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 18px;
  width: 2px;
  height: 18px;
  background: var(--red);
  transform: translateX(-50%);
}

.map-controls {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 3;
  display: grid;
  gap: 8px;
}

.map-control-button {
  min-width: 40px;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgb(255 255 255 / 94%);
  color: var(--ink);
  box-shadow: 0 8px 20px rgb(23 32 28 / 12%);
  font-weight: 900;
}

.map-lock-button {
  min-width: 86px;
  padding: 0 10px;
  background: var(--ink);
  color: #fff;
  font-size: 0.78rem;
}

.map-lock-button.is-unlocked {
  background: var(--teal);
}

.map-overlay {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  border-radius: 6px;
  padding: 8px 10px;
  background: rgb(255 255 255 / 88%);
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 800;
  pointer-events: none;
}

.result-panel {
  display: grid;
  align-content: space-between;
  min-height: 382px;
  min-width: 0;
  overflow: hidden;
  padding: 22px;
  box-shadow: var(--shadow);
}

.metric-label,
.metric-tile span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.hero-value {
  margin-top: 8px;
  max-width: 100%;
  font-size: clamp(2.35rem, 3.2vw, 3.8rem);
  font-weight: 900;
  line-height: 1;
  white-space: nowrap;
  letter-spacing: 0;
}

.hero-delta {
  margin-top: 10px;
  color: var(--green);
  font-weight: 900;
}

.score-ring {
  position: relative;
  width: 140px;
  height: 140px;
  justify-self: end;
}

.score-ring svg {
  width: 140px;
  height: 140px;
  transform: rotate(-90deg);
}

.ring-bg,
.ring-arc {
  fill: none;
  stroke-width: 12;
}

.ring-bg {
  stroke: var(--panel-strong);
}

.ring-arc {
  stroke: var(--teal);
  stroke-linecap: round;
  stroke-dasharray: 314;
  stroke-dashoffset: 314;
  transition: stroke-dashoffset 180ms ease, stroke 180ms ease;
}

.score-ring div {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
}

.score-ring strong {
  font-size: 2rem;
  line-height: 1;
}

.score-ring span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.metric-tile {
  padding: 15px;
}

.metric-tile strong {
  display: block;
  margin-top: 7px;
  font-size: clamp(1.15rem, 1.65vw, 1.45rem);
  white-space: nowrap;
}

.analysis-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 0.46fr);
  gap: 16px;
  margin-top: 16px;
}

.chart-panel,
.source-panel,
.report-panel {
  padding: 16px;
}

.driver-chart {
  display: grid;
  gap: 10px;
}

.driver-row {
  display: grid;
  grid-template-columns: 108px 1fr 64px;
  align-items: center;
  gap: 10px;
  font-size: 0.82rem;
}

.bar-track {
  position: relative;
  height: 18px;
  border-radius: 999px;
  background: var(--panel-strong);
  overflow: hidden;
}

.bar-track::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 1px;
  background: #9ca7a0;
}

.bar-fill {
  position: absolute;
  top: 3px;
  bottom: 3px;
  left: 50%;
  border-radius: 999px;
  background: var(--green);
}

.bar-fill.negative {
  left: auto;
  right: 50%;
  background: var(--red);
}

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

.source-row {
  min-height: 38px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.84rem;
}

.source-row:last-child {
  border-bottom: 0;
}

.source-row strong {
  color: var(--ink);
  font-size: 0.78rem;
  white-space: nowrap;
}

.report-panel {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-top: 16px;
  background: var(--panel);
}

.report-panel p {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.75;
}

@media (max-width: 1040px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    max-height: none;
  }
}

@media (max-width: 1280px) {
  .hero-grid {
    grid-template-columns: 1fr;
  }

  .result-panel {
    grid-template-columns: 1fr auto;
    min-height: auto;
    align-items: center;
    gap: 16px;
  }

  .score-ring {
    justify-self: end;
  }
}

@media (max-width: 760px) {
  .main-stage,
  .sidebar {
    padding: 14px;
  }

  .main-stage {
    order: -1;
  }

  .topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    margin: -14px -14px 12px;
    padding: 12px 14px;
    border-bottom: 1px solid var(--line);
    background: rgb(247 248 245 / 96%);
    backdrop-filter: blur(12px);
  }

  .hero-grid,
  .analysis-layout,
  .report-panel {
    grid-template-columns: 1fr;
  }

  .metrics-grid {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    padding-bottom: 4px;
    scroll-snap-type: x proximity;
  }

  .metric-tile {
    flex: 0 0 min(68vw, 230px);
    scroll-snap-align: start;
  }

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

  .result-panel {
    grid-template-columns: minmax(0, 1fr) auto;
    min-height: auto;
    padding: 14px;
    gap: 12px;
  }

  .score-ring {
    width: 88px;
    height: 88px;
    justify-self: end;
  }

  .score-ring svg {
    width: 88px;
    height: 88px;
  }

  .score-ring strong {
    font-size: 1.35rem;
  }

  .hero-value {
    font-size: clamp(1.65rem, 9vw, 2.35rem);
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .map-panel,
  .map {
    min-height: 278px;
  }

  .map-overlay {
    align-items: flex-start;
    flex-direction: column;
    gap: 3px;
  }

  .map-control-button {
    min-width: 38px;
    min-height: 38px;
  }
}

@media (max-width: 480px) {
  .split-fields,
  .brand-row {
    align-items: stretch;
    flex-direction: column;
  }

  .metrics-grid {
    grid-template-columns: 1fr;
  }

  .driver-row {
    grid-template-columns: 92px 1fr 52px;
  }
}
