:root {
  color-scheme: dark;
  font-family: Inter, "Noto Sans JP", "Yu Gothic UI", system-ui, sans-serif;
  background: #080b14;
  color: #edf2ff;
}

* { box-sizing: border-box; }

body {
  min-width: 320px;
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at 18% 0%, #182752 0, transparent 30rem), #080b14;
}

button, select, input { font: inherit; }

.app-shell { width: min(1100px, calc(100% - 32px)); margin: 0 auto; padding: 32px 0 60px; }

.app-header, .panel-heading, .camera-controls, .actions, .measurement-layout, .calibration-layout { display: flex; }

.app-header { align-items: end; justify-content: space-between; gap: 24px; }

.eyebrow, .section-kicker { margin: 0 0 4px; color: #75e6c8; font-size: .73rem; font-weight: 800; letter-spacing: .15em; }
h1, h2 { margin: 0; letter-spacing: -.025em; }
h1 { font-size: clamp(1.45rem, 4vw, 2rem); }
h2 { font-size: 1.12rem; }

.camera-controls { align-items: end; flex-wrap: wrap; justify-content: end; gap: 8px; }
label { color: #c5cce0; font-size: .82rem; }
.camera-controls label, .debug-select { display: grid; gap: 4px; }
select { min-height: 36px; max-width: 260px; border: 1px solid #35415f; border-radius: 7px; padding: 0 8px; background: #101728; color: #edf2ff; }

.button { min-height: 36px; border: 1px solid #42cdaa; border-radius: 7px; padding: 0 13px; background: #35b994; color: #06120f; font-weight: 800; cursor: pointer; }
.button:hover:not(:disabled) { background: #75e6c8; }
.button:disabled { cursor: not-allowed; opacity: .5; }
.button.secondary { border-color: #46536f; background: #182137; color: #e3e9fa; }
.button.danger { border-color: #743f53; background: #2d1521; color: #ffd8e2; }

.app-message { min-height: 24px; margin: 18px 0; color: #b7c1da; font-size: .9rem; }
.app-message.is-error { color: #ff9ab6; }

.tabs { display: flex; gap: 3px; border-bottom: 1px solid #2c3650; }
.tab { border: 0; border-bottom: 2px solid transparent; padding: 12px 18px 10px; background: transparent; color: #9da8c3; font-weight: 800; cursor: pointer; }
.tab.is-active { border-bottom-color: #60dfc1; color: #effffb; }
.tab-panel { padding-top: 24px; }
.is-hidden { display: none; }

.panel-heading { align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 13px; }
.actions { flex-wrap: wrap; justify-content: end; gap: 8px; }

.measurement-layout { align-items: stretch; gap: 18px; }
.canvas-card { overflow: hidden; border: 1px solid #2b3650; border-radius: 12px; background: #0c1221; box-shadow: 0 18px 45px rgba(0, 0, 0, .25); }
.primary-canvas-card { position: relative; flex: 0 1 560px; width: min(100%, 560px); }
canvas { display: block; width: 100%; height: auto; background: #090f1c; }
.canvas-legend { display: flex; position: absolute; right: 12px; bottom: 12px; align-items: center; gap: 7px; padding: 6px 8px; border: 1px solid #48536b; border-radius: 5px; background: rgba(6, 10, 19, .72); color: #dfe9ff; font-size: .68rem; }
.canvas-legend i { display: inline-block; width: 54px; height: 7px; border-radius: 8px; background: linear-gradient(90deg, #315ce6, #17233d 50%, #e54a43); }

.metrics { display: grid; flex: 1; grid-template-columns: repeat(2, minmax(105px, 1fr)); align-content: start; gap: 8px; }
.metrics div { min-height: 76px; border: 1px solid #2c3650; border-radius: 9px; padding: 12px; background: #0e1526; }
.metrics span { display: block; margin-bottom: 6px; color: #9eaac8; font-size: .75rem; }
.metrics strong { color: #e9fffa; font-size: 1.18rem; }
.metrics p { grid-column: 1 / -1; margin: 3px 0 0; color: #a6b1cd; font-size: .78rem; line-height: 1.55; }

.debug-heading { margin-top: 28px; }
.debug-card { width: min(100%, 560px); }

.help-text { margin: 0 0 18px; color: #b7c1d9; font-size: .9rem; line-height: 1.7; }
.calibration-layout { align-items: flex-start; gap: 24px; }
.calibration-card { flex: 1 1 460px; max-width: 560px; }
.canvas-caption { margin: 0; padding: 8px 11px; color: #a9b5d0; font-size: .76rem; }
.settings { display: grid; flex: 1 1 320px; gap: 12px; }
fieldset { display: grid; gap: 12px; margin: 0; border: 1px solid #2c3650; border-radius: 9px; padding: 13px; }
legend { padding: 0 5px; color: #75e6c8; font-size: .82rem; font-weight: 800; }
.setting-note { margin: -2px 0 2px; color: #abb7d0; font-size: .78rem; }
.setting-note output { margin-left: 7px; color: #f4f7ff; font-weight: 800; }
fieldset label { display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; align-items: center; }
fieldset input { grid-column: 1 / -1; width: 100%; accent-color: #57dbbd; }
fieldset label.toggle { display: flex; justify-content: space-between; }
fieldset label.toggle input { width: auto; margin: 0; }
output { color: #f4f7ff; font-variant-numeric: tabular-nums; }

@media (max-width: 760px) {
  .app-shell { width: min(100% - 22px, 680px); padding-top: 20px; }
  .app-header, .measurement-layout, .calibration-layout { align-items: stretch; flex-direction: column; }
  .camera-controls { justify-content: start; }
  .primary-canvas-card, .debug-card, .calibration-card { width: 100%; max-width: none; }
  .metrics { grid-template-columns: repeat(4, minmax(65px, 1fr)); }
  .metrics div { min-height: 65px; padding: 9px; }
  .metrics strong { font-size: 1rem; }
}

@media (max-width: 480px) {
  .panel-heading { align-items: start; flex-direction: column; }
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .actions { justify-content: start; }
}
