* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #0a0a0a;
  --surface: #141414;
  --surface2: #1e1e1e;
  --border: #2a2a2a;
  --text: #e0e0e0;
  --text2: #888;
  --accent: #00e676;
  --accent2: #00c853;
  --danger: #ff5252;
  --warn: #ffd740;
  --blue: #448aff;
  --radius: 16px;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro', 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

/* ===== APP LAYOUT ===== */
#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  height: 100dvh;
}

/* ===== HEADER ===== */
.header {
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.header h1 {
  font-size: 17px;
  font-weight: 600;
  color: var(--accent);
}

.header .lock-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text2);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  transition: all .2s;
}
.header .lock-btn.active {
  border-color: var(--accent);
  color: var(--accent);
}

/* ===== TOOL SCREENS ===== */
.screens {
  flex: 1;
  position: relative;
  overflow: hidden;
}

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s;
}
.screen.active {
  opacity: 1;
  pointer-events: auto;
}

/* ===== BOTTOM NAV ===== */
.nav {
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 6px 0;
  padding-bottom: max(6px, env(safe-area-inset-bottom));
  flex-shrink: 0;
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 0;
  background: none;
  border: none;
  color: var(--text2);
  font-size: 10px;
  cursor: pointer;
  transition: color .2s;
}
.nav-item svg {
  width: 24px;
  height: 24px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.nav-item.active {
  color: var(--accent);
}

/* ===== SPIRIT LEVEL ===== */
.level-container {
  width: 100%;
  max-width: 340px;
  aspect-ratio: 1;
  position: relative;
}

.level-circle {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 2px solid var(--border);
  position: relative;
  background: radial-gradient(circle, var(--surface2) 0%, var(--bg) 100%);
}

.level-circle::before,
.level-circle::after {
  content: '';
  position: absolute;
  background: var(--border);
}
.level-circle::before {
  width: 1px;
  height: 100%;
  left: 50%;
}
.level-circle::after {
  width: 100%;
  height: 1px;
  top: 50%;
}

.level-target {
  position: absolute;
  width: 40px;
  height: 40px;
  border: 2px solid var(--accent);
  border-radius: 50%;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  opacity: .4;
}

.level-bubble {
  position: absolute;
  width: 30px;
  height: 30px;
  background: var(--accent);
  border-radius: 50%;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  transition: transform .1s ease-out;
  box-shadow: 0 0 20px rgba(0, 230, 118, .4);
}
.level-bubble.centered {
  box-shadow: 0 0 30px rgba(0, 230, 118, .8);
}

.level-readout {
  margin-top: 24px;
  text-align: center;
}
.level-readout .degrees {
  font-size: 48px;
  font-weight: 200;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}
.level-readout .label {
  font-size: 13px;
  color: var(--text2);
  margin-top: 4px;
}

/* ===== CLINOMETER ===== */
.clino-display {
  width: 100%;
  max-width: 340px;
  aspect-ratio: 1;
  position: relative;
}

.clino-arc {
  width: 100%;
  height: 100%;
}

.clino-readout {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.clino-readout .degrees {
  font-size: 56px;
  font-weight: 200;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}
.clino-readout .unit-toggle {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}
.clino-readout .unit-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text2);
  padding: 4px 14px;
  border-radius: 20px;
  font-size: 13px;
  cursor: pointer;
}
.clino-readout .unit-btn.active {
  border-color: var(--accent);
  color: var(--accent);
}

/* ===== NOISE METER ===== */
.noise-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  width: 100%;
}

.noise-gauge {
  width: 280px;
  height: 160px;
  position: relative;
}

.noise-value {
  font-size: 72px;
  font-weight: 200;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.noise-unit {
  font-size: 14px;
  color: var(--text2);
  margin-top: 4px;
}
.noise-label {
  font-size: 16px;
  font-weight: 500;
  margin-top: 12px;
  padding: 6px 16px;
  border-radius: 20px;
  background: var(--surface2);
}

.noise-bars {
  display: flex;
  gap: 3px;
  align-items: flex-end;
  height: 100px;
  padding: 0 20px;
}
.noise-bar {
  width: 6px;
  border-radius: 3px;
  background: var(--accent);
  transition: height .1s;
  min-height: 4px;
}

.noise-btn {
  padding: 14px 40px;
  border-radius: 30px;
  border: none;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  background: var(--accent);
  color: var(--bg);
  transition: all .2s;
}
.noise-btn.recording {
  background: var(--danger);
  color: white;
}

.noise-stats {
  display: flex;
  gap: 20px;
}
.noise-stat {
  text-align: center;
}
.noise-stat .val {
  font-size: 24px;
  font-weight: 300;
  font-variant-numeric: tabular-nums;
}
.noise-stat .lbl {
  font-size: 11px;
  color: var(--text2);
  margin-top: 2px;
}

/* ===== COMPASS ===== */
.compass-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.compass-heading {
  font-size: 52px;
  font-weight: 200;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}
.compass-direction {
  font-size: 18px;
  color: var(--text2);
}

.compass-ring {
  width: 280px;
  height: 280px;
  position: relative;
}

.compass-svg {
  width: 100%;
  height: 100%;
  transition: transform .15s ease-out;
}

.compass-needle {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 4px;
  height: 100px;
  margin-left: -2px;
  margin-top: -80px;
  background: linear-gradient(to bottom, var(--danger) 50%, var(--text2) 50%);
  border-radius: 2px;
}

.compass-center {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 12px;
  height: 12px;
  background: var(--accent);
  border-radius: 50%;
  transform: translate(-50%, -50%);
}

/* ===== RULER ===== */
.ruler-container {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
}

.ruler-display {
  font-size: 48px;
  font-weight: 200;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  padding: 16px 0;
  flex-shrink: 0;
}
.ruler-display .unit {
  font-size: 16px;
  color: var(--text2);
}

.ruler-track {
  flex: 1;
  width: 100%;
  overflow: hidden;
  position: relative;
  touch-action: none;
}

.ruler-scale {
  position: absolute;
  top: 0;
  left: 50%;
  width: 2px;
  background: var(--accent);
  opacity: .3;
}

.ruler-marks {
  position: absolute;
  left: 0;
  width: 100%;
}

.ruler-mark {
  position: absolute;
  right: 0;
  height: 1px;
  background: var(--text2);
}
.ruler-mark.cm {
  width: 40%;
  background: var(--accent);
}
.ruler-mark.half {
  width: 25%;
}
.ruler-mark.mm {
  width: 15%;
  opacity: .4;
}
.ruler-mark-label {
  position: absolute;
  right: 45%;
  font-size: 12px;
  color: var(--text2);
  transform: translateY(-50%);
}

.ruler-unit-toggle {
  display: flex;
  gap: 8px;
  padding: 12px 0;
  flex-shrink: 0;
}
.ruler-unit-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text2);
  padding: 8px 20px;
  border-radius: 20px;
  font-size: 14px;
  cursor: pointer;
}
.ruler-unit-btn.active {
  border-color: var(--accent);
  color: var(--accent);
}

/* ===== PERMISSION OVERLAY ===== */
.permission-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 10;
  padding: 40px;
  text-align: center;
}
.permission-overlay svg {
  width: 48px;
  height: 48px;
  stroke: var(--accent);
  fill: none;
  stroke-width: 1.5;
}
.permission-overlay p {
  color: var(--text2);
  font-size: 14px;
  line-height: 1.6;
}
.permission-overlay button {
  padding: 12px 32px;
  border-radius: 25px;
  border: none;
  background: var(--accent);
  color: var(--bg);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

/* ===== CALIBRATE TOAST ===== */
.toast {
  position: fixed;
  top: 60px;
  left: 50%;
  transform: translateX(-50%) translateY(-100px);
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 20px;
  border-radius: 12px;
  font-size: 14px;
  z-index: 100;
  transition: transform .3s;
  white-space: nowrap;
}
.toast.show {
  transform: translateX(-50%) translateY(0);
}

/* ===== RESPONSIVE ===== */
@media (max-height: 600px) {
  .level-container, .clino-display, .compass-ring {
    max-width: 240px;
  }
  .level-readout .degrees, .clino-readout .degrees, .compass-heading {
    font-size: 36px;
  }
  .noise-value { font-size: 48px; }
}
