:root {
  --bg-primary: #0a0a0f;
  --bg-secondary: #14141f;
  --bg-tertiary: #1e1e2e;
  --text-primary: #ffffff;
  --text-secondary: #a0a0b0;
  --text-muted: #606070;
  --accent: #00d4ff;
  --accent-secondary: #00ff88;
  --danger: #ff4466;
  --focus-ring: #00d4ff;
  --focus-glow: rgba(0, 212, 255, 0.4);
  --radius-md: 12px;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body {
  width: 600px; height: 600px; overflow: hidden;
  background: #000;
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
}
#app { width: 100%; height: 100%; position: relative; }
.screen { width: 100%; height: 100%; position: absolute; top: 0; left: 0; display: flex; flex-direction: column; }
.screen.hidden { display: none; }
.focusable { transition: all 0.15s ease; border: 2px solid transparent; cursor: pointer; outline: none; }
.focusable:focus { border-color: var(--focus-ring); box-shadow: 0 0 20px var(--focus-glow); }
.hidden { display: none !important; }

/* ---------- headers ---------- */
.hd { padding: 22px 24px 14px; flex: 0 0 auto; }
.hd.sm { padding: 18px 22px 10px; }
.hd-title { font-size: 22px; font-weight: 700; letter-spacing: -0.4px; }
.home .hd-title { font-size: 32px; }
.hd-sub { font-size: 14px; color: var(--text-secondary); margin-top: 4px; }

/* ---------- home menu ---------- */
.menu {
  flex: 1 1 auto; min-height: 0;
  display: flex; flex-direction: column; justify-content: center;
  gap: 14px; padding: 0 24px;
}
.menu-btn {
  display: flex; align-items: center; gap: 16px;
  min-height: 96px; padding: 0 20px;
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  text-align: left;
}
.mb-ic {
  font-size: 30px; line-height: 1;
  width: 52px; height: 52px; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-tertiary); border-radius: 10px;
  color: var(--accent);
}
.mb-tx { display: flex; flex-direction: column; gap: 3px; }
.mb-tx b { font-size: 20px; font-weight: 700; }
.mb-tx small { font-size: 13px; color: var(--text-secondary); }

.ft {
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px 20px;
  font-size: 13px; color: var(--text-muted);
}
#homePpi { color: var(--accent-secondary); font-weight: 600; }

/* ---------- ruler readout ---------- */
.readout {
  flex: 0 0 auto;
  padding: 14px 22px 12px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--bg-tertiary);
}
.ro-big {
  font-size: 34px; font-weight: 800; letter-spacing: -0.5px;
  font-variant-numeric: tabular-nums; line-height: 1.05;
}
.ro-sub { font-size: 15px; color: var(--text-secondary); margin-top: 4px; font-variant-numeric: tabular-nums; }
.ro-stat { font-size: 12px; color: var(--text-muted); margin-top: 4px; font-variant-numeric: tabular-nums; }

/* ---------- ruler canvas ---------- */
.canvas-wrap {
  flex: 1 1 auto; min-height: 0;
  position: relative;
  border-radius: 6px;
  margin: 6px;
}
#rulerCanvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.ctl-hint {
  position: absolute; left: 50%; bottom: 8px; transform: translateX(-50%);
  font-size: 12px; color: var(--text-secondary);
  background: rgba(10, 10, 15, 0.7);
  padding: 4px 12px; border-radius: 999px;
  white-space: nowrap; pointer-events: none;
}

/* ---------- toolbar ---------- */
.toolbar {
  flex: 0 0 auto;
  display: flex; flex-wrap: wrap; gap: 8px;
  padding: 10px 12px 14px;
  border-top: 1px solid var(--bg-tertiary);
}
.tb-btn {
  flex: 1 1 calc(33.333% - 8px);
  min-height: 58px; padding: 8px 6px;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border-radius: 10px;
  font-size: 15px; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
  text-align: center;
}
.tb-btn.good { background: rgba(0, 255, 136, 0.16); color: var(--accent-secondary); }
.tb-btn.good:focus { border-color: var(--accent-secondary); box-shadow: 0 0 20px rgba(0, 255, 136, 0.4); }

/* ---------- calibrate ---------- */
.cal-bar-track {
  flex: 0 0 auto;
  position: relative;
  height: 120px; margin: 8px 16px;
  border-radius: 10px;
  background: var(--bg-secondary);
  display: flex; align-items: center; justify-content: center;
}
.cal-bar {
  position: relative;
  height: 8px; width: 220px;
  background: var(--accent);
  border-radius: 4px;
  box-shadow: 0 0 16px rgba(0, 212, 255, 0.45);
}
.cal-bar .cap {
  position: absolute; top: 50%; transform: translateY(-50%);
  font-size: 20px; color: var(--accent);
}
.cal-bar .cap.l { left: -22px; }
.cal-bar .cap.r { right: -22px; }

.cal-info {
  flex: 1 1 auto; min-height: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; padding: 6px 20px;
}
.ci-line { font-size: 30px; font-weight: 800; font-variant-numeric: tabular-nums; }
.ci-sub { font-size: 16px; color: var(--text-secondary); }
.ci-ppi { font-size: 18px; font-weight: 700; color: var(--accent-secondary); font-variant-numeric: tabular-nums; }

/* ---------- about ---------- */
.about-body {
  flex: 1 1 auto; min-height: 0; overflow-y: auto;
  padding: 6px 24px 12px;
  font-size: 15px; line-height: 1.5; color: var(--text-secondary);
}
.about-body p { margin-bottom: 12px; }
.about-body b { color: var(--text-primary); }
.about-ppi { color: var(--text-muted); }
.about-ppi span { color: var(--accent-secondary); font-weight: 700; }

/* ---------- toast ---------- */
.toast {
  position: absolute; left: 50%; bottom: 92px; transform: translateX(-50%);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  padding: 12px 22px; border-radius: 999px;
  font-size: 15px; font-weight: 600;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.6);
  border: 1px solid rgba(0, 255, 136, 0.3);
}
