:root {
  color-scheme: light;
  --ink: #132b2a;
  --muted: #65716f;
  --paper: #f5f0e7;
  --paper-deep: #e8dfd2;
  --panel: rgba(255, 253, 248, 0.96);
  --accent: #e86645;
  --accent-dark: #bd4328;
  --mint: #75b9a7;
  --rule: rgba(19, 43, 42, 0.78);
  --hairline: rgba(19, 43, 42, 0.18);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--paper);
  color: var(--ink);
}

button,
input {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.workspace {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(circle at 72% 22%, rgba(117, 185, 167, 0.18), transparent 34%),
    linear-gradient(135deg, rgba(255, 255, 255, 0.24), transparent 45%),
    var(--paper);
}

.ruler {
  position: fixed;
  z-index: 4;
  background: rgba(255, 253, 248, 0.88);
  box-shadow: 0 1px 0 var(--hairline);
  user-select: none;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.ruler::-webkit-scrollbar {
  display: none;
}

.ruler-content {
  position: relative;
  min-width: 100%;
  min-height: 100%;
}

.ruler-top {
  top: var(--safe-top);
  right: var(--safe-right);
  left: var(--safe-left);
  height: 52px;
  border-bottom: 1px solid var(--hairline);
  overflow-x: auto;
  overflow-y: hidden;
  touch-action: pan-x;
  cursor: ew-resize;
}

.ruler-left {
  top: var(--safe-top);
  bottom: var(--safe-bottom);
  left: var(--safe-left);
  width: 52px;
  border-right: 1px solid var(--hairline);
  overflow-x: hidden;
  overflow-y: auto;
  touch-action: pan-y;
  cursor: ns-resize;
}

.tick {
  position: absolute;
  background: var(--rule);
}

.ruler-top .tick {
  top: 0;
  width: 1px;
  height: 9px;
}

.ruler-top .tick.is-mid {
  height: 15px;
}

.ruler-top .tick.is-major {
  height: 22px;
  width: 2px;
}

.ruler-left .tick {
  left: 0;
  width: 9px;
  height: 1px;
}

.ruler-left .tick.is-mid {
  width: 15px;
}

.ruler-left .tick.is-major {
  width: 22px;
  height: 2px;
}

.tick-label {
  position: absolute;
  color: var(--ink);
  font-size: 10px;
  font-weight: 750;
  line-height: 1;
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.ruler-top .tick-label {
  top: 27px;
  transform: translateX(4px);
}

.ruler-left .tick-label {
  left: 27px;
  transform: translateY(4px);
}

.measure-stage {
  position: fixed;
  z-index: 1;
  top: calc(var(--safe-top) + 52px);
  right: var(--safe-right);
  bottom: calc(var(--safe-bottom) + 224px);
  left: calc(var(--safe-left) + 52px);
  display: grid;
  place-items: center;
  overflow: hidden;
}

.diameter-circle {
  position: relative;
  flex: none;
  width: 160px;
  height: 160px;
  border: 2px solid var(--accent);
  border-radius: 50%;
  background: rgba(255, 253, 248, 0.64);
  box-shadow:
    0 0 0 1px rgba(232, 102, 69, 0.08),
    0 16px 46px rgba(19, 43, 42, 0.1);
}

.diameter-circle::before,
.diameter-circle::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  background: rgba(19, 43, 42, 0.24);
  transform: translate(-50%, -50%);
}

.diameter-circle::before {
  width: calc(100% + 18px);
  height: 1px;
}

.diameter-circle::after {
  width: 1px;
  height: calc(100% + 18px);
}

.circle-label {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 1;
  min-width: max-content;
  padding: 5px 8px;
  border: 1px solid rgba(19, 43, 42, 0.12);
  border-radius: 999px;
  background: rgba(255, 253, 248, 0.9);
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
  transform: translate(-50%, -50%);
}

.control-deck {
  position: fixed;
  z-index: 6;
  right: 0;
  bottom: 0;
  left: 0;
  min-height: 224px;
  padding: 18px max(18px, var(--safe-right)) calc(16px + var(--safe-bottom)) max(18px, var(--safe-left));
  border-top: 1px solid rgba(19, 43, 42, 0.12);
  border-radius: 22px 22px 0 0;
  background: var(--panel);
  box-shadow: 0 -12px 48px rgba(19, 43, 42, 0.1);
  backdrop-filter: blur(18px);
}

.deck-heading,
.diameter-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.deck-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 7px;
  min-width: 0;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--accent-dark);
  font-size: 10px;
  font-weight: 850;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: -0.04em;
}

h1 {
  font-size: 25px;
  line-height: 1;
}

.status-button {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 38px;
  padding: 8px 11px;
  border: 1px solid rgba(19, 43, 42, 0.14);
  border-radius: 999px;
  background: #fffdf8;
  color: var(--ink);
  font-size: 12px;
  font-weight: 750;
  min-width: 0;
  max-width: 146px;
}

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

.quiet-button {
  min-height: 38px;
  padding: 8px 10px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #d58a3e;
  box-shadow: 0 0 0 3px rgba(213, 138, 62, 0.15);
}

.status-button.is-calibrated .status-dot {
  background: #31917a;
  box-shadow: 0 0 0 3px rgba(49, 145, 122, 0.15);
}

.unit-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin: 14px 0;
  padding: 4px;
  border-radius: 12px;
  background: var(--paper-deep);
}

.unit-button {
  min-height: 38px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.unit-button.is-active {
  background: #fffdf8;
  color: var(--ink);
  box-shadow: 0 1px 4px rgba(19, 43, 42, 0.1);
}

.diameter-line label {
  font-size: 13px;
  font-weight: 750;
}

.number-wrap {
  display: flex;
  align-items: baseline;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.number-wrap input {
  width: 78px;
  min-height: 34px;
  padding: 5px 8px;
  border: 1px solid rgba(19, 43, 42, 0.16);
  border-radius: 8px;
  background: #fffdf8;
  color: var(--ink);
  font-size: 16px;
  font-weight: 800;
  text-align: right;
}

.diameter-range,
.calibration-adjuster input {
  width: 100%;
  accent-color: var(--accent);
}

.diameter-range {
  display: block;
  margin-top: 9px;
}

.calibration-overlay {
  position: fixed;
  z-index: 20;
  inset: 0;
  display: grid;
  place-items: end center;
  padding: 16px max(12px, var(--safe-right)) max(12px, var(--safe-bottom)) max(12px, var(--safe-left));
  background: rgba(19, 43, 42, 0.48);
  backdrop-filter: blur(8px);
}

.calibration-overlay[hidden] {
  display: none;
}

.calibration-card {
  width: min(100%, 520px);
  padding: 24px;
  border-radius: 24px;
  background: #fffdf8;
  box-shadow: 0 24px 70px rgba(10, 25, 24, 0.28);
}

.calibration-card h2 {
  font-size: 27px;
}

.device-label {
  display: block;
  margin-bottom: 7px;
  font-size: 12px;
  font-weight: 800;
}

.device-select {
  width: 100%;
  min-height: 48px;
  padding: 0 12px;
  border: 1px solid rgba(19, 43, 42, 0.18);
  border-radius: 12px;
  background: #fffdf8;
  color: var(--ink);
  font-size: 16px;
  font-weight: 700;
}

.calibration-copy,
.calibration-footnote {
  color: var(--muted);
  line-height: 1.45;
}

.calibration-copy {
  margin: 10px 0 20px;
  font-size: 14px;
}

.card-gauge {
  display: grid;
  place-items: center;
  min-height: 112px;
  padding: 18px 0 8px;
  border-radius: 16px;
  background: var(--paper);
  overflow: hidden;
}

.calibration-line {
  position: relative;
  height: 26px;
  border-top: 2px solid var(--ink);
}

.calibration-line span {
  position: absolute;
  top: -8px;
  width: 2px;
  height: 16px;
  background: var(--ink);
}

.calibration-line span:first-child {
  left: 0;
}

.calibration-line span:last-child {
  right: 0;
}

.card-gauge p {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
}

.calibration-adjuster {
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  gap: 10px;
  margin: 18px 0;
}

.calibration-adjuster button {
  width: 44px;
  height: 44px;
  border: 1px solid rgba(19, 43, 42, 0.14);
  border-radius: 12px;
  background: var(--paper);
  color: var(--ink);
  font-size: 22px;
  font-weight: 700;
}

.calibration-actions {
  display: grid;
  grid-template-columns: 1fr 1.25fr;
  gap: 10px;
}

.setup-actions {
  display: grid;
  gap: 9px;
  margin-top: 14px;
}

.calibration-actions button,
.setup-actions button {
  min-height: 48px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 800;
}

.setup-actions button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

.button-secondary {
  border: 1px solid rgba(19, 43, 42, 0.16);
  background: transparent;
  color: var(--ink);
}

.button-primary {
  border: 1px solid var(--ink);
  background: var(--ink);
  color: #fffdf8;
}

.button-plain {
  min-height: 38px !important;
  border: 0;
  background: transparent;
  color: var(--muted);
}

.calibration-footnote {
  margin: 12px 0 0;
  font-size: 11px;
  text-align: center;
}

.exit-focus-button {
  position: fixed;
  z-index: 10;
  right: max(12px, var(--safe-right));
  bottom: max(12px, var(--safe-bottom));
  min-height: 40px;
  padding: 8px 13px;
  border: 1px solid rgba(19, 43, 42, 0.15);
  border-radius: 999px;
  background: rgba(255, 253, 248, 0.9);
  color: var(--ink);
  box-shadow: 0 6px 22px rgba(19, 43, 42, 0.14);
  font-size: 12px;
  font-weight: 800;
  backdrop-filter: blur(12px);
}

.exit-focus-button[hidden] {
  display: none;
}

@media (min-width: 900px) {
  .control-deck {
    right: 20px;
    bottom: 20px;
    left: auto;
    width: 400px;
    min-height: 0;
    padding: 20px;
    border: 1px solid rgba(19, 43, 42, 0.12);
    border-radius: 20px;
  }

  .measure-stage {
    right: 420px;
    bottom: 0;
  }

  .calibration-overlay {
    place-items: center;
  }
}

@media (max-height: 560px) and (orientation: landscape) {
  .control-deck {
    top: calc(var(--safe-top) + 64px);
    right: calc(var(--safe-right) + 12px);
    bottom: auto;
    left: auto;
    width: min(360px, calc(100vw - 80px));
    min-height: 0;
    padding: 14px;
    border: 1px solid rgba(19, 43, 42, 0.12);
    border-radius: 18px;
  }

  .measure-stage {
    right: min(380px, calc(100vw - 72px));
    bottom: var(--safe-bottom);
  }

  .unit-switch {
    margin: 9px 0;
  }

  .calibration-card {
    max-height: calc(100vh - 24px);
    overflow-y: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
  }
}

.is-focus-mode .control-deck {
  display: none;
}

.is-focus-mode .measure-stage {
  right: var(--safe-right);
  bottom: var(--safe-bottom);
}
