/* =========================================================
   PHYSICAL PHONE RULER - REDESIGNED STYLESHEET
   Unobstructed Ruler Scales, Centered HUD, and 100% Usability
   ========================================================= */

:root {
  --bg-primary: #07080c;
  --bg-surface: rgba(13, 17, 26, 0.88);
  --bg-surface-elevated: rgba(22, 30, 46, 0.95);
  --border-subtle: rgba(255, 255, 255, 0.1);
  --accent-cyan: #00f2fe;
  --accent-blue: #38bdf8;
  --accent-emerald: #10b981;
  --accent-rose: #f43f5e;
  --accent-purple: #a855f7;
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  touch-action: none;
}

.app-container {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ================= Top Navigation Bar ================= */
.top-nav {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(var(--safe-top) + 6px) 10px 6px 10px;
  pointer-events: none; /* Let touches on sides pass to ruler */
}

.model-select-pill {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--bg-surface);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(0, 242, 254, 0.35);
  border-radius: 9999px;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
  max-width: 58%;
  text-align: left;
}

.model-select-pill:active {
  transform: scale(0.96);
  background: var(--bg-surface-elevated);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-dot.exact {
  background: var(--accent-emerald);
  box-shadow: 0 0 8px var(--accent-emerald);
}

.status-dot.medium {
  background: #f59e0b;
  box-shadow: 0 0 8px #f59e0b;
}

.status-dot.fallback {
  background: var(--accent-rose);
  box-shadow: 0 0 8px var(--accent-rose);
}

.pill-text-wrap {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.device-name {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.device-sub {
  font-size: 10px;
  color: var(--accent-cyan);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 500;
}

.header-actions {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 5px;
}

.action-pill {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  border-radius: 9999px;
  background: var(--bg-surface);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.action-pill:active {
  transform: scale(0.94);
  background: var(--bg-surface-elevated);
}

.action-pill.verify-btn {
  border-color: rgba(16, 185, 129, 0.4);
  color: #6ee7b7;
}

.action-icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--bg-surface);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.action-icon-btn:active {
  transform: scale(0.92);
}

/* ================= Centered Floating HUD ================= */
/* Placed strictly in the middle 60% of the screen so left/right ruler scales are 100% visible */
.center-hud {
  position: absolute;
  top: calc(var(--safe-top) + 54px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  width: clamp(230px, 58%, 290px);
  background: var(--bg-surface);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(0, 242, 254, 0.25);
  border-radius: 18px;
  padding: 10px 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: center;
}

.hud-readout {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.15;
}

.hud-main-val {
  display: flex;
  align-items: baseline;
  gap: 3px;
}

.hud-num {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, monospace;
  font-size: 32px;
  font-weight: 800;
  color: var(--accent-cyan);
  letter-spacing: -0.5px;
}

.hud-unit {
  font-size: 15px;
  font-weight: 700;
  color: var(--accent-cyan);
}

.hud-sub-vals {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  color: var(--text-secondary);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, monospace;
}

.hud-divider {
  color: var(--text-muted);
}

.hud-buttons {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  padding-top: 6px;
}

.hud-btn {
  padding: 4px 7px;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  font-size: 11px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, monospace;
  cursor: pointer;
  transition: all 0.15s ease;
}

.hud-btn:active {
  background: rgba(0, 242, 254, 0.25);
  border-color: var(--accent-cyan);
}

.hud-btn.reset {
  background: rgba(244, 63, 94, 0.15);
  border-color: rgba(244, 63, 94, 0.3);
  color: #fda4af;
}

/* ================= Card Verification Overlay ================= */
.card-verify-overlay {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 35;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.verify-card-box {
  /* Width and Height dynamically assigned by JS according to 85.60mm x 53.98mm */
  border: 2.5px dashed #10b981;
  background: rgba(16, 185, 129, 0.15);
  border-radius: 10px;
  box-shadow: 0 0 35px rgba(16, 185, 129, 0.3);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 10px;
}

.verify-card-label {
  display: flex;
  flex-direction: column;
  color: #6ee7b7;
  font-size: 13px;
}

.verify-card-label strong {
  font-size: 14px;
}

.verify-card-tip {
  font-size: 11px;
  color: #a7f3d0;
  margin-top: 6px;
  max-width: 90%;
}

.close-verify-btn {
  padding: 6px 16px;
  border-radius: 9999px;
  background: #10b981;
  color: #022c22;
  font-size: 12px;
  font-weight: 700;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

/* Tip when in body mode */
.body-mode-tip {
  position: absolute;
  bottom: calc(var(--safe-bottom) + 40px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 25;
  background: rgba(244, 63, 94, 0.15);
  border: 1px solid rgba(244, 63, 94, 0.35);
  border-radius: 8px;
  padding: 4px 10px;
  font-size: 10.5px;
  color: #fecdd3;
  white-space: nowrap;
}

/* ================= Ruler Canvas ================= */
.canvas-container {
  flex: 1;
  width: 100%;
  height: 100%;
  position: relative;
  touch-action: none;
}

#rulerCanvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* ================= Minimal Bottom Bar ================= */
.minimal-bottom-bar {
  position: absolute;
  bottom: calc(var(--safe-bottom) + 8px);
  left: 0;
  right: 0;
  z-index: 25;
  display: flex;
  justify-content: center;
  pointer-events: none; /* Never covers ruler ticks on left/right corners */
}

.center-hint-pill {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  background: rgba(13, 17, 26, 0.85);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-subtle);
  border-radius: 9999px;
  font-size: 11px;
  color: var(--text-secondary);
}

.mini-fullscreen-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 9999px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  font-size: 10.5px;
  font-weight: 600;
  cursor: pointer;
}

/* ================= MODAL DIALOGS ================= */
.modal-dialog {
  border: none;
  background: transparent;
  padding: 0;
  width: 100%;
  height: 100%;
  max-width: 100vw;
  max-height: 100vh;
  margin: 0;
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.modal-dialog[open] {
  display: flex;
}

.modal-content {
  background: #0f1420;
  border: 1px solid var(--border-subtle);
  border-radius: 24px;
  width: calc(100% - 28px);
  max-width: 480px;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.8);
  animation: modalIn 0.22s cubic-bezier(0.16, 1, 0.3, 1);
  overflow: hidden;
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.96) translateY(12px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.close-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  padding: 4px;
}

.close-btn:hover {
  color: var(--text-primary);
}

.modal-body {
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Tabs */
.tab-nav {
  display: flex;
  gap: 4px;
  background: rgba(0, 0, 0, 0.4);
  padding: 3px;
  border-radius: 12px;
  border: 1px solid var(--border-subtle);
}

.dialog-tab {
  padding: 6px 10px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 11.5px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
}

.dialog-tab.active {
  background: var(--bg-surface-elevated);
  color: var(--accent-cyan);
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.tab-pane {
  display: none;
  flex-direction: column;
  gap: 14px;
}

.tab-pane.active {
  display: flex;
}

/* Popular Grid */
.quick-pick-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.section-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent-cyan);
}

.popular-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.popular-card {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-subtle);
  cursor: pointer;
  transition: all 0.15s ease;
  text-align: left;
}

.popular-card:active {
  background: rgba(0, 242, 254, 0.15);
  border-color: var(--accent-cyan);
  transform: scale(0.97);
}

.card-icon {
  font-size: 20px;
  flex-shrink: 0;
}

.card-info {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.card-info strong {
  font-size: 12px;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-info span {
  font-size: 10.5px;
  color: var(--text-muted);
}

/* Search */
.search-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  padding-top: 10px;
}

.search-input-wrap input {
  width: 100%;
  padding: 10px 14px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  font-size: 13px;
  outline: none;
}

.search-input-wrap input:focus {
  border-color: var(--accent-cyan);
}

.brand-filter-row {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.brand-chip {
  padding: 4px 10px;
  border-radius: 9999px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  font-size: 11px;
  cursor: pointer;
  white-space: nowrap;
}

.brand-chip.active {
  background: rgba(255, 255, 255, 0.16);
  color: var(--text-primary);
  font-weight: 600;
}

.model-list-container {
  max-height: 240px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.model-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid transparent;
  cursor: pointer;
}

.model-item:active {
  background: rgba(0, 242, 254, 0.12);
  border-color: var(--accent-cyan);
}

.model-item-title {
  font-weight: 600;
  font-size: 13px;
  color: var(--text-primary);
}

.model-item-sub {
  font-size: 11px;
  color: var(--text-muted);
}

.model-item-ppi {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, monospace;
  font-size: 12px;
  color: var(--accent-cyan);
}

/* Custom Input Tab */
.custom-guide-card {
  background: rgba(0, 242, 254, 0.08);
  border: 1px solid rgba(0, 242, 254, 0.2);
  border-radius: 12px;
  padding: 10px 14px;
}

.custom-guide-card h4 {
  font-size: 13px;
  color: var(--accent-cyan);
  margin-bottom: 4px;
}

.custom-guide-card p {
  font-size: 11.5px;
  color: var(--text-secondary);
  line-height: 1.4;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 600;
}

.form-group input {
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  font-size: 14px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, monospace;
  outline: none;
}

.form-group input:focus {
  border-color: var(--accent-cyan);
}

.quick-preset-row {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.preset-btn {
  padding: 5px 10px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 11px;
  cursor: pointer;
  white-space: nowrap;
}

.preset-btn:active {
  background: rgba(0, 242, 254, 0.2);
  color: var(--accent-cyan);
}

.res-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.res-input-row input {
  flex: 1;
}

.res-input-row span {
  color: var(--text-muted);
  font-size: 14px;
  font-weight: bold;
}

.quick-res-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.res-preset-btn {
  padding: 6px 8px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 10.5px;
  cursor: pointer;
  text-align: left;
}

.res-preset-btn:active {
  background: rgba(0, 242, 254, 0.15);
  color: var(--accent-cyan);
}

.custom-calc-result {
  background: rgba(0, 0, 0, 0.3);
  border: 1px dashed rgba(255, 255, 255, 0.15);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 12px;
  color: var(--text-secondary);
  text-align: center;
}

.custom-calc-result strong {
  color: var(--accent-cyan);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, monospace;
}

/* Card Calibration Stage */
.calibration-stage {
  min-height: 200px;
  background: #090a0f;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  position: relative;
  overflow: hidden;
}

.target-visual-box {
  border: 2px dashed var(--accent-cyan);
  border-radius: 8px;
  background: rgba(0, 242, 254, 0.06);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 10px;
  box-shadow: 0 0 25px rgba(0, 242, 254, 0.15);
}

.target-spec-tag {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, monospace;
  font-size: 13px;
  font-weight: 700;
  color: var(--accent-cyan);
  margin-bottom: 4px;
}

.target-guide-text {
  font-size: 11px;
  color: var(--text-secondary);
}

.slider-control-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.slider-header {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-secondary);
}

.slider-header strong {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, monospace;
  color: var(--accent-cyan);
}

.slider-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.step-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
}

input[type="range"] {
  flex: 1;
  height: 6px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.15);
  outline: none;
  -webkit-appearance: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent-cyan);
  box-shadow: 0 0 10px var(--accent-cyan);
  cursor: pointer;
}

/* Modal Actions */
.modal-actions {
  display: flex;
  gap: 10px;
}

.modal-actions.space-between {
  justify-content: space-between;
}

.btn {
  flex: 1;
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-primary {
  background: linear-gradient(135deg, #00f2fe 0%, #0284c7 100%);
  color: #00121e;
  box-shadow: 0 4px 14px rgba(0, 242, 254, 0.3);
}

.btn-danger {
  background: rgba(244, 63, 94, 0.15);
  border: 1px solid rgba(244, 63, 94, 0.3);
  color: #fda4af;
}

.full-width {
  width: 100%;
}

/* Settings Modal */
.setting-item {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.toggle-row strong {
  font-size: 13px;
}

.toggle-row p {
  font-size: 11px;
  color: var(--text-muted);
}

.theme-picker {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.theme-opt {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
}

.theme-opt.active {
  background: rgba(0, 242, 254, 0.12);
  border-color: var(--accent-cyan);
  color: var(--text-primary);
  font-weight: 600;
}

.color-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

.modern-toggle {
  width: 44px;
  height: 24px;
  appearance: none;
  -webkit-appearance: none;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 12px;
  position: relative;
  cursor: pointer;
}

.modern-toggle::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: white;
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.modern-toggle:checked {
  background: var(--accent-emerald);
}

.modern-toggle:checked::after {
  transform: translateX(20px);
}

/* QR Modal */
.qr-intro {
  font-size: 12px;
  color: var(--text-secondary);
}

.qr-wrapper {
  margin: 16px auto;
  display: flex;
  justify-content: center;
  padding: 10px;
  background: #0b0f19;
  border-radius: 16px;
  border: 1px solid rgba(0, 242, 254, 0.3);
  width: fit-content;
}

.qr-url-box {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: rgba(0, 0, 0, 0.4);
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid var(--border-subtle);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, monospace;
  font-size: 12px;
  color: var(--text-secondary);
}

.copy-url-btn {
  background: rgba(0, 242, 254, 0.15);
  border: 1px solid rgba(0, 242, 254, 0.3);
  color: var(--accent-cyan);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  cursor: pointer;
}

.qr-hint {
  font-size: 11px;
  color: var(--text-muted);
}
