:root {
  --bg: #f6fbfc;
  --panel: #ffffff;
  --ink: #16191d;
  --muted: #66737f;
  --line: #d8e3e8;
  --blue: #2457d6;
  --green: #18a84a;
  --red: #d72835;
  --amber: #f2a915;
  --shadow: 0 18px 48px rgba(35, 61, 79, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(180deg, #e9f9fb 0%, var(--bg) 42%, #ffffff 100%);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

.app-shell {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 18px 28px;
}

.topbar {
  display: grid;
  grid-template-columns: 48px 52px 1fr;
  gap: 12px;
  align-items: center;
  min-height: 68px;
}

.topbar h1,
.section-head h2 {
  margin: 0;
  font-size: 24px;
  line-height: 1.05;
}

.topbar p,
.section-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.icon-button,
.secondary-button,
.primary-button,
.mode-button,
.file-button {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  transition: transform 140ms ease, border-color 140ms ease, background 140ms ease;
}

.icon-button {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-size: 42px;
  line-height: 1;
}

.icon-button:disabled {
  opacity: 0.35;
  cursor: default;
}

.brand-mark {
  position: relative;
  width: 50px;
  height: 50px;
  border: 2px solid var(--line);
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 8px 22px rgba(35, 61, 79, 0.1);
}

.brand-arc {
  position: absolute;
  left: 9px;
  top: 14px;
  width: 28px;
  height: 18px;
  border-top: 4px solid var(--blue);
  border-radius: 28px 28px 0 0;
}

.brand-needle {
  position: absolute;
  left: 24px;
  top: 10px;
  width: 4px;
  height: 27px;
  border-radius: 999px;
  background: var(--red);
  transform: rotate(18deg);
  transform-origin: 50% 100%;
}

.brand-hub {
  position: absolute;
  left: 20px;
  bottom: 10px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 3px #ffffff;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.home-hero {
  display: grid;
  min-height: calc(100vh - 230px);
  place-items: center;
  padding: 28px 0;
}

.spine-logo {
  position: relative;
  width: 170px;
  height: 248px;
  margin: 0 auto 32px;
}

.spine-logo .head {
  position: absolute;
  left: 91px;
  top: 18px;
  width: 54px;
  height: 76px;
  border: 8px solid #050505;
  border-radius: 50%;
  transform: rotate(30deg);
}

.spine-logo .curve {
  position: absolute;
  left: 73px;
  top: 74px;
  width: 54px;
  height: 132px;
  border-left: 10px solid #050505;
  border-radius: 54% 0 0 48%;
  transform: rotate(-15deg);
}

.spine-logo .base {
  position: absolute;
  left: 55px;
  bottom: 0;
  width: 78px;
  height: 78px;
  background: #050505;
  clip-path: polygon(50% 100%, 0 0, 100% 0);
}

.spine-logo::before {
  content: "";
  position: absolute;
  left: 15px;
  top: 31px;
  width: 138px;
  height: 138px;
  border-top: 8px solid var(--blue);
  border-radius: 50%;
  opacity: 0.2;
}

.spine-logo::after {
  content: "";
  position: absolute;
  left: 78px;
  top: 53px;
  width: 7px;
  height: 74px;
  border-radius: 999px;
  background: var(--red);
  transform: rotate(-24deg);
  transform-origin: 50% 100%;
}

.home-actions {
  display: grid;
  gap: 16px;
  width: min(520px, 100%);
}

.mode-button {
  display: grid;
  gap: 6px;
  padding: 18px 22px;
  border-radius: 8px;
  text-align: center;
}

.mode-button strong {
  font-size: 24px;
  text-transform: uppercase;
}

.mode-button span {
  color: var(--muted);
}

.mode-button:hover,
.icon-button:hover,
.secondary-button:hover,
.primary-button:hover,
.file-button:hover {
  transform: translateY(-1px);
  border-color: #a7bcc8;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin: 22px 0 16px;
}

.section-head.compact {
  margin-top: 26px;
}

.meter-stage,
.cobb-layout,
.history-section {
  background: rgba(255, 255, 255, 0.84);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.meter-stage {
  position: relative;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  align-items: end;
  justify-items: center;
  min-height: min(560px, calc(100vh - 210px));
  padding: 22px 18px 30px;
  overflow: hidden;
}

.meter-readout {
  position: relative;
  transform: none;
  display: grid;
  justify-items: center;
  margin-top: 18px;
  z-index: 1;
}

.meter-readout span {
  font-size: clamp(104px, 17vw, 156px);
  font-weight: 800;
  line-height: 0.9;
  transition: color 120ms ease;
}

.meter-readout small {
  color: var(--muted);
  font-size: 22px;
  line-height: 1.2;
  margin-top: 4px;
  transition: color 120ms ease;
}

.meter-readout .danger {
  color: var(--red);
}

.gauge {
  align-self: end;
  width: min(100%, 680px);
  height: auto;
}

.gauge-arc,
.tick-line,
.needle {
  fill: none;
  stroke: #272327;
  stroke-linecap: round;
}

.gauge-arc {
  stroke-width: 9;
}

.tick-line {
  stroke-width: 2;
}

.tick-line.major {
  stroke-width: 5;
}

.tick-label {
  fill: #272327;
  font-size: 16px;
  font-weight: 750;
  text-anchor: middle;
  dominant-baseline: central;
}

.needle {
  stroke: var(--red);
  stroke-width: 5;
  transform-origin: 210px 228px;
  transition: transform 120ms ease;
}

.needle-hub {
  fill: var(--red);
}

.control-panel {
  display: grid;
  grid-template-columns: auto minmax(140px, max-content) 1fr auto;
  gap: 14px;
  align-items: center;
  margin-top: 14px;
}

.sensor-status {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.primary-button,
.secondary-button,
.file-button {
  min-height: 44px;
  padding: 0 16px;
  border-radius: 8px;
  display: inline-grid;
  place-items: center;
  font-weight: 750;
}

.primary-button {
  background: var(--blue);
  border-color: var(--blue);
  color: #ffffff;
}

.file-button input {
  display: none;
}

.range-control {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  align-items: center;
  padding: 0 14px;
  min-height: 44px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
}

.range-control input {
  width: 100%;
}

.cobb-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 260px;
  gap: 16px;
  padding: 14px;
}

.canvas-wrap {
  min-height: 540px;
  background: #f8fbfc;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  touch-action: none;
}

#cobbCanvas {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 540px;
  cursor: grab;
  touch-action: none;
}

.measure-panel {
  display: grid;
  align-content: start;
  gap: 12px;
}

.angle-card,
.mini-grid > div {
  display: grid;
  gap: 6px;
  padding: 16px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.angle-card span,
.mini-grid span {
  color: var(--muted);
  font-size: 13px;
}

.angle-card strong {
  font-size: 52px;
  line-height: 1;
}

.mini-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.mini-grid strong {
  font-size: 22px;
}

.line-stat-green strong {
  color: var(--green);
}

.line-stat-blue strong {
  color: var(--blue);
}

.photo-tools,
.line-tools {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.photo-tools .secondary-button:last-child {
  grid-column: 1 / -1;
}

.filter-tools {
  display: grid;
  gap: 10px;
  padding: 12px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.filter-tools label {
  display: grid;
  grid-template-columns: 44px 1fr;
  gap: 10px;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
}

.filter-tools input {
  width: 100%;
}

.filter-tools .secondary-button {
  min-height: 38px;
}

.line-tools .secondary-button.active {
  color: #ffffff;
}

.line-lock-green.active {
  background: var(--green);
  border-color: var(--green);
}

.line-lock-blue.active {
  background: var(--blue);
  border-color: var(--blue);
}

.history-section {
  padding: 14px;
}

.history-list {
  display: grid;
  gap: 10px;
}

.history-item {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.history-item {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
}

.history-item strong {
  font-size: 22px;
}

.history-item span {
  color: var(--muted);
}

@media (max-width: 760px) {
  .app-shell {
    padding-left: 14px;
    padding-right: 14px;
  }

  .topbar {
    grid-template-columns: 44px 44px 1fr;
  }

  .section-head,
  .control-panel,
  .cobb-layout {
    grid-template-columns: 1fr;
  }

  .section-head {
    align-items: stretch;
  }

  .meter-stage {
    min-height: min(500px, calc(100vh - 240px));
    padding: 16px 10px 28px;
  }

  .meter-readout {
    margin-top: 16px;
  }

  .meter-readout span {
    font-size: clamp(104px, 28vw, 148px);
  }

  .meter-readout small {
    font-size: 20px;
  }

  .gauge {
    width: min(100%, 500px);
  }

  .canvas-wrap,
  #cobbCanvas {
    min-height: 500px;
  }

  .range-control {
    grid-template-columns: 1fr;
    padding: 10px 14px;
  }
}
