:root {
  --primary: #1d4ed8;
  --primary-dark: #1e3a8a;
  --bg: #f4f5f7;
  --card-bg: #ffffff;
  --border: #e2e4e9;
  --text: #1a1c23;
  --text-muted: #6b7280;
  --danger: #dc2626;
  --negative-fan: #1e3a8a;
  --side-fan: #dc2626;
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: #d8dae0;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang TC", "Microsoft JhengHei", sans-serif;
  color: var(--text);
}

.phone {
  max-width: 430px;
  margin: 0 auto;
  min-height: 100vh;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  position: relative;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
}

.topbar .back {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
  font-size: 20px;
  flex-shrink: 0;
}
.topbar .back:active { background: var(--border); }

.topbar h1 {
  font-size: 17px;
  font-weight: 600;
  margin: 0;
  flex: 1;
}

.topbar .step {
  font-size: 12px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.content {
  flex: 1;
  padding: 16px;
  padding-bottom: 100px;
  overflow-y: auto;
}

.bottom-bar {
  position: sticky;
  bottom: 0;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 60%, transparent);
  display: flex;
  gap: 10px;
}

.btn {
  display: block;
  width: 100%;
  padding: 14px 16px;
  border-radius: var(--radius);
  border: none;
  font-size: 16px;
  font-weight: 600;
  text-align: center;
  cursor: pointer;
  text-decoration: none;
  box-sizing: border-box;
}

.btn-primary {
  background: var(--primary);
  color: white;
}
.btn-primary:active { background: var(--primary-dark); }

.btn-secondary {
  background: var(--card-bg);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-ghost {
  background: transparent;
  color: var(--primary);
  border: none;
}

.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 16px;
  margin-bottom: 14px;
}

.card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin: 0 0 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.field {
  margin-bottom: 14px;
}
.field:last-child { margin-bottom: 0; }

.field label {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.field input,
.field select {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 16px;
  background: #fafbfc;
  color: var(--text);
}
.field input:focus,
.field select:focus {
  outline: none;
  border-color: var(--primary);
  background: white;
}

.field-row {
  display: flex;
  gap: 10px;
}
.field-row .field { flex: 1; }

.stepper {
  display: flex;
  align-items: center;
  gap: 12px;
}
.stepper button {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: white;
  font-size: 20px;
  color: var(--primary);
  flex-shrink: 0;
}
.stepper button:active { background: var(--border); }
.stepper .value {
  flex: 1;
  text-align: center;
  font-size: 18px;
  font-weight: 600;
}

.site-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.site-item {
  display: block;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
  text-decoration: none;
  color: var(--text);
}
.site-item .name {
  font-weight: 600;
  font-size: 15px;
  margin-bottom: 4px;
}
.site-item .meta {
  font-size: 13px;
  color: var(--text-muted);
}
.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: #eef2ff;
  color: var(--primary);
  margin-left: 6px;
}

.hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 8px;
  line-height: 1.5;
}

.progress-dots {
  display: flex;
  gap: 6px;
  padding: 0 16px 10px;
}
.progress-dots span {
  flex: 1;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
}
.progress-dots span.active {
  background: var(--primary);
}

/* --- Diagram canvas --- */
.diagram-wrap {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 14px;
}

.diagram-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  border: 2px solid #222;
  background: #fafbfc;
  touch-action: none;
}

.dim-label {
  position: absolute;
  font-size: 11px;
  color: #444;
  white-space: nowrap;
}
.dim-top {
  top: -22px;
  left: 50%;
  transform: translateX(-50%);
}
.dim-arrow-row {
  position: absolute;
  top: -12px;
  left: 4%;
  right: 4%;
  height: 1px;
  background: #888;
}
.dim-arrow-row::before, .dim-arrow-row::after {
  content: "";
  position: absolute;
  top: -3px;
  width: 0;
  height: 0;
  border-top: 3px solid transparent;
  border-bottom: 3px solid transparent;
}
.dim-arrow-row::before { left: 0; border-right: 5px solid #888; }
.dim-arrow-row::after { right: 0; border-left: 5px solid #888; }

.zone-line {
  position: absolute;
  left: 0;
  right: 0;
  height: 1px;
  border-top: 1px dashed #b5b8c0;
}
.col-line {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 1px;
  border-left: 1px dashed #b5b8c0;
}

.door-mark {
  position: absolute;
  width: 20px;
  height: 10px;
  margin-left: -10px;
  margin-top: -5px;
  border-radius: 2px;
  border: 1px solid #333;
  background: #ddd;
  cursor: grab;
}
.door-mark.readonly { cursor: default; }
.door-mark.dragging {
  cursor: grabbing;
  box-shadow: 0 4px 10px rgba(0,0,0,0.35);
  z-index: 20;
}

.column-mark {
  position: absolute;
  width: 12px;
  height: 12px;
  margin-left: -6px;
  margin-top: -6px;
  background: #d8dae0;
  border: 1.5px solid #6b7280;
  cursor: grab;
}
.column-mark.readonly { cursor: default; }
.column-mark.dragging {
  cursor: grabbing;
  box-shadow: 0 4px 10px rgba(0,0,0,0.35);
  z-index: 20;
}

.compass {
  position: absolute;
  right: 8px;
  bottom: 8px;
  font-size: 12px;
  font-weight: 700;
  color: #333;
  background: rgba(255,255,255,0.85);
  border-radius: 6px;
  padding: 2px 6px;
}

.fan-icon {
  position: absolute;
  width: 30px;
  height: 30px;
  margin-left: -15px;
  margin-top: -15px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-size: 15px;
  font-weight: 700;
  color: white;
  user-select: none;
  cursor: grab;
  box-shadow: 0 1px 3px rgba(0,0,0,0.25);
}
.fan-icon.negative { background: var(--negative-fan); }
.fan-icon.side { background: var(--side-fan); }
.fan-icon.dragging {
  cursor: grabbing;
  box-shadow: 0 4px 10px rgba(0,0,0,0.35);
  z-index: 20;
  transform: scale(1.15);
}
.fan-icon.readonly { cursor: default; }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 18px;
  margin-top: 14px;
  font-size: 13px;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
}
.legend-swatch.column {
  border-radius: 3px;
  background: #d8dae0;
  border: 1.5px solid #6b7280;
}
.legend-swatch.door {
  width: 10px;
  height: 22px;
  border-radius: 2px;
  background: #ddd;
  border: 1px solid #333;
}
.legend-swatch {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}
.legend-swatch.negative { background: var(--negative-fan); }
.legend-swatch.side { background: var(--side-fan); }

.info-strip {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 10px;
  border-top: 1px dashed var(--border);
  padding-top: 10px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 90px;
  transform: translateX(-50%);
  background: #1a1c23;
  color: white;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  z-index: 50;
  white-space: nowrap;
}
.toast.show { opacity: 1; }

.section-title {
  font-size: 15px;
  font-weight: 600;
  margin: 4px 0 10px;
}

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.empty-state .icon { font-size: 40px; margin-bottom: 12px; }

/* --- Warning banner (in-app browser notice) --- */
.warn-banner {
  background: #fff7ed;
  border: 1px solid #fdba74;
  color: #9a3412;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 12.5px;
  line-height: 1.5;
  margin-bottom: 14px;
}

/* --- Export image modal --- */
.export-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.export-modal.show { display: flex; }
.export-modal-inner {
  background: white;
  border-radius: var(--radius);
  padding: 14px;
  max-width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.export-modal-inner img {
  max-width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  display: block;
}
.export-modal-hint {
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
}
.export-modal-actions {
  display: flex;
  gap: 10px;
}
.export-modal-actions .btn { flex: 1; }
