/* pirix – Mobile-first Editor – Fixed for phones */
:root {
  --primary: #3b82f6;
  --primary-dark: #2563eb;
  --accent: #f59e0b;
  --surface: #ffffff;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
}

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

html, body {
  height: 100%;
  overflow: hidden;
}

body.editor-body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: #e2e8f0;
  color: var(--text);
  height: 100dvh;
  height: 100vh;
  max-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.top-bar {
  background: var(--surface);
  height: 48px;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 50;
}

.top-bar .brand {
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: 0.03em;
  color: #0f172a;
  text-decoration: none;
}

.top-bar .menu-btn {
  background: none;
  border: none;
  font-size: 1.35rem;
  cursor: pointer;
  padding: 6px 8px;
  color: #334155;
}

.canvas-wrap {
  flex: 1 1 auto;
  position: relative;
  overflow: hidden;
  background: #cbd5e1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  /* space for fixed bottom toolbar */
  padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px));
}

#canvas-container {
  max-width: 100%;
  max-height: 100%;
  line-height: 0;
}

#canvas-container canvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
}

.canvas-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: #64748b;
  padding: 1.5rem;
  pointer-events: auto;
  cursor: pointer;
  z-index: 5;
  -webkit-tap-highlight-color: transparent;
}

.canvas-empty h3 {
  font-size: 1.05rem;
  margin-bottom: 0.35rem;
  color: #334155;
}

.canvas-empty p {
  font-size: 0.85rem;
}

.zoom-controls {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255,255,255,0.95);
  border-radius: 22px;
  padding: 4px 3px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.12);
  z-index: 40;
}

.zoom-controls button {
  width: 34px;
  height: 34px;
  border: none;
  background: none;
  font-size: 1.15rem;
  cursor: pointer;
  border-radius: 50%;
  color: #334155;
}

.bottom-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 8px 4px calc(8px + env(safe-area-inset-bottom, 0px));
  display: flex;
  justify-content: space-around;
  align-items: center;
  flex-shrink: 0;
  z-index: 200;
  box-shadow: 0 -4px 16px rgba(0,0,0,0.1);
  min-height: 56px;
}

.tool-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 5px 6px;
  border-radius: 10px;
  color: #475569;
  font-size: 0.65rem;
  font-weight: 500;
  min-width: 52px;
}

.tool-item:active, .tool-item.active {
  background: #eff6ff;
  color: var(--primary);
}

.tool-item .icon {
  font-size: 1.25rem;
  line-height: 1;
}

.tool-item.upload-label { cursor: pointer; }
.tool-item input[type="file"] { display: none; }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,0.4);
  z-index: 100;
  display: none;
  align-items: flex-end;
  justify-content: center;
}

.modal-overlay.show { display: flex; }

.modal-sheet {
  background: var(--surface);
  border-radius: 18px 18px 0 0;
  width: 100%;
  max-width: 480px;
  max-height: 80dvh;
  overflow-y: auto;
  padding: 14px 16px 20px;
  box-shadow: 0 -8px 30px rgba(0,0,0,0.12);
  animation: slideUp 0.22s ease;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.modal-header h3 {
  font-size: 1rem;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: #94a3b8;
  padding: 2px 6px;
  line-height: 1;
}

.text-input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 12px;
  font-size: 1rem;
  margin-bottom: 12px;
  outline: none;
  font-family: inherit;
}

.text-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
}

.ctrl-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
  align-items: center;
}

.ctrl-chip {
  background: #f1f5f9;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.8rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  color: #334155;
}

.ctrl-chip.active {
  background: #dbeafe;
  border-color: var(--primary);
  color: var(--primary-dark);
}

.ctrl-chip select,
.ctrl-chip input[type="color"] {
  border: none;
  background: transparent;
  font-size: 0.8rem;
  cursor: pointer;
  outline: none;
}

.ctrl-chip input[type="color"] {
  width: 20px;
  height: 20px;
  padding: 0;
}

.slider-group {
  margin-bottom: 12px;
}

.slider-group label {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.slider-group input[type="range"] {
  width: 100%;
  accent-color: var(--primary);
  height: 5px;
}

.slider-group .val {
  font-weight: 600;
  color: var(--text);
  min-width: 32px;
  text-align: right;
}

.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

.btn {
  flex: 1;
  padding: 11px;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
}

.btn-outline {
  background: #f1f5f9;
  color: #475569;
  border: 1px solid var(--border);
}

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

.btn-danger {
  background: #fee2e2;
  color: #dc2626;
}

@media (min-width: 768px) {
  .modal-overlay { align-items: center; }
  .modal-sheet {
    border-radius: 14px;
    max-height: 75vh;
  }
  .bottom-bar {
    padding: 8px 16px;
    justify-content: center;
    gap: 10px;
  }
  .tool-item {
    min-width: 64px;
    font-size: 0.7rem;
  }
}
