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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #e8e4de;
  color: #2d2d2d;
  height: 100vh;
  overflow: hidden;
}

/* ── App shell ───────────────────────────────────────────── */

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.app-header {
  background: #262320;
  color: #f0ede8;
  padding: 0 16px;
  height: 50px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 50;
  position: relative;
}

.app-header h1 {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.3px;
}

.app-home-link {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  opacity: 0.75;
  transition: opacity 0.15s;
}
.app-home-link:hover  { opacity: 1; }
.app-home-link:active { opacity: 1; }

.app-logo {
  width: 30px;
  height: 30px;
  object-fit: contain;
  display: block;
}

.app-body {
  display: flex;
  flex: 1;
  overflow: hidden;
  position: relative;
}

/* ── Hamburger button ─────────────────────────────────────── */

.hamburger-btn {
  display: none; /* shown only on mobile */
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  width: 44px;
  height: 44px;
  background: none;
  border: none;
  cursor: pointer;
  flex-shrink: 0;
  padding: 4px;
  border-radius: 6px;
}
.hamburger-btn:active { background: rgba(255,255,255,0.1); }

.hamburger-btn span {
  display: block;
  width: 20px;
  height: 2px;
  background: #f0ede8;
  border-radius: 2px;
}

/* ── Sidebar overlay (mobile backdrop) ───────────────────── */

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 90;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}

.sidebar-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

/* ── Sidebar ─────────────────────────────────────────────── */

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: #ffffff;
  border-right: 1px solid #d8d5d0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform 0.28s cubic-bezier(.4,0,.2,1);
}

.sidebar-header {
  display: none; /* shown on mobile */
  align-items: center;
  justify-content: space-between;
  padding: 14px 14px 10px;
  border-bottom: 1px solid #eee;
  flex-shrink: 0;
}

.sidebar-title {
  font-size: 14px;
  font-weight: 600;
  color: #333;
}

.sidebar-close {
  background: none;
  border: none;
  font-size: 18px;
  color: #888;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
}
.sidebar-close:active { background: #f0eeec; color: #333; }

/* ── Workspace bar ───────────────────────────────────────── */

.workspace-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  background: #f5f3f0;
  border-bottom: 1px solid #eceae6;
  flex-shrink: 0;
}

.workspace-status {
  flex: 1;
  font-size: 10.5px;
  color: #b0aba4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.workspace-new-btn {
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 600;
  color: #555;
  background: #fff;
  border: 1px solid #d8d5d0;
  border-radius: 5px;
  padding: 4px 9px;
  min-height: 30px;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.12s, color 0.12s, background 0.12s;
}
.workspace-new-btn:hover  { border-color: #999; color: #222; }
.workspace-new-btn:active { background: #f0eeec; border-color: #777; }

/* ── Collapsible panels ───────────────────────────────────── */

.panel {
  border-bottom: 1px solid #f0eeec;
}

.panel-hd {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 14px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: #888;
  text-align: left;
  transition: background 0.1s;
}

.panel-hd:hover  { background: #fafafa; }
.panel-hd:active { background: #f0eeec; }

.chevron {
  font-size: 12px;
  transition: transform 0.2s;
  display: inline-block;
}

.panel.collapsed .chevron { transform: rotate(-90deg); }

.panel-body {
  overflow: hidden;
  max-height: 800px;
  transition: max-height 0.25s ease, padding 0.25s ease;
  padding: 0 12px 14px;
}

.panel.collapsed .panel-body {
  max-height: 0;
  padding-bottom: 0;
}

/* ── Tool buttons (sidebar) ───────────────────────────────── */

.tool-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.tool-btn {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border: 2px solid #e4e4e4;
  border-radius: 7px;
  background: white;
  cursor: pointer;
  font-size: 13px;
  color: #333;
  transition: border-color 0.12s, background 0.12s;
  text-align: left;
  width: 100%;
  min-height: 40px;
}

.tool-btn:hover  { border-color: #b0b0b0; background: #f8f8f8; }
.tool-btn:active { border-color: #888; background: #eeebe8; }
.tool-btn.active { border-color: #333; background: #f2f0ee; font-weight: 600; }

/* ── Swatches ─────────────────────────────────────────────── */

.swatch {
  width: 22px;
  height: 22px;
  border-radius: 4px;
  border: 1px solid #c8c8c8;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  line-height: 1;
}

.swatch--light      { background: #dedad4; }
.swatch--dark       { background: #565656; border-color: #444; }
.swatch--half-light { background: linear-gradient(90deg, #dedad4 50%, #f0eee8 50%); border-color: #b0aca6; }
.swatch--half-dark  { background: linear-gradient(90deg, #565656 50%, #c0bdb8 50%); border-color: #444; }
.swatch--erase      { background: #fff4f4; color: #cc4444; font-weight: bold; border-color: #f0c0c0; }

.tool-hint {
  font-size: 11px;
  color: #b0aba5;
  margin-top: 8px;
  line-height: 1.5;
}

/* ── Axis selector ─────────────────────────────────────────── */

.axis-selector {
  flex-direction: column;
  gap: 5px;
  margin-top: 8px;
  padding: 8px 10px;
  background: #f8f6f3;
  border-radius: 7px;
  border: 1px solid #e4e0dc;
}

.axis-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: #999;
}

.axis-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.axis-btn {
  flex: 1 0 calc(33.333% - 4px); /* 3 per row */
  min-height: 38px;
  border: 2px solid #e4e4e4;
  border-radius: 6px;
  background: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.12s, background 0.12s;
  color: #666;
  padding: 4px;
}

.axis-btn:hover  { border-color: #b0b0b0; background: #f8f8f8; }
.axis-btn:active { border-color: #888; background: #eeebe8; }
.axis-btn.active { border-color: #333; background: #f2f0ee; color: #222; }

/* ── Dimensions display ────────────────────────────────────── */

.dims-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 0;
  font-size: 13px;
  border-bottom: 1px solid #f0eeec;
}
.dims-row:last-child { border-bottom: none; }
.dims-row span   { color: #888; display: flex; align-items: center; gap: 5px; }
.dims-row strong { color: #222; font-weight: 600; }

.dims-row--divider { border-bottom: 1px solid #e8e5e1; padding: 0; height: 0; margin: 3px 0; }
.dims-row--stone span { color: #666; font-size: 12px; }
.dims-row--total { margin-top: 2px; }
.dims-row--total span  { color: #555; font-weight: 600; }
.dims-row--total strong { font-size: 14px; }

.stone-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  flex-shrink: 0;
  border: 1px solid rgba(0,0,0,0.12);
  font-style: normal;
}
.stone-dot--light { background: #dedad4; }
.stone-dot--dark  { background: #565656; }

.dims-empty { font-size: 12px; color: #b0aba5; }

/* ── Form rows ───────────────────────────────────────────── */

.form-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 13px;
}

.form-row label { flex: 1; color: #555; }

.form-row input[type="number"] {
  width: 58px;
  padding: 5px 6px;
  border: 1px solid #ddd;
  border-radius: 5px;
  font-size: 13px;
  text-align: center;
  color: #333;
}

.form-row input[type="number"]:focus { outline: none; border-color: #888; }

.form-row--slider { flex-wrap: nowrap; }
.form-row--slider input[type="range"] { flex: 1; accent-color: #444; }
.form-row--slider span { font-size: 11px; color: #888; width: 32px; flex-shrink: 0; text-align: right; }

/* ── Sidebar buttons ──────────────────────────────────────── */

.btn-primary {
  width: 100%;
  padding: 9px;
  background: #2d2a27;
  color: #f0ede8;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.12s;
  margin-top: 2px;
}
.btn-primary:hover  { background: #474340; }
.btn-primary:active { background: #1a1816; }
.btn-primary:disabled, .btn-secondary:disabled { opacity: 0.5; cursor: not-allowed; pointer-events: none; }

.btn-secondary {
  width: 100%;
  padding: 9px;
  background: white;
  color: #555;
  border: 1px solid #d8d8d8;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.12s, color 0.12s;
  margin-top: 6px;
}
.btn-secondary:hover  { border-color: #999; color: #222; }
.btn-secondary:active { border-color: #666; background: #f4f2f0; color: #111; }

.btn-toggle {
  width: 100%;
  padding: 9px;
  background: white;
  color: #444;
  border: 1px solid #d4d0cc;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
  display: block;
}
.btn-toggle:hover  { border-color: #999; color: #222; }
.btn-toggle:active { border-color: #666; background: #f0eeec; color: #111; }
.btn-toggle.active { background: #2d2a27; color: #f0ede8; border-color: #2d2a27; }

/* ── Drafts ───────────────────────────────────────────────── */

.drafts-list { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }

.draft-item {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 8px;
  background: #fafafa;
  border: 1px solid #e4e4e4;
  border-radius: 5px;
  font-size: 12px;
}

.draft-name { flex: 1; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #333; }

.draft-load {
  padding: 4px 9px;
  font-size: 11px;
  background: #2d2a27;
  color: #f0ede8;
  border: none;
  border-radius: 3px;
  cursor: pointer;
  flex-shrink: 0;
  min-height: 40px;
}
.draft-load:hover  { background: #474340; }
.draft-load:active { background: #1a1816; }

.draft-delete {
  padding: 4px 7px;
  font-size: 11px;
  background: none;
  color: #bb3333;
  border: 1px solid #bb3333;
  border-radius: 3px;
  cursor: pointer;
  flex-shrink: 0;
  min-height: 40px;
  transition: background 0.1s, color 0.1s;
}
.draft-delete:hover  { background: #bb3333; color: white; }
.draft-delete:active { background: #8a2222; color: white; }

/* ── Canvas area ──────────────────────────────────────────── */

.canvas-area {
  flex: 1;
  overflow: auto;
  min-width: 0;
  min-height: 0;
  background: #e8e4de;
  padding: 24px;
  position: relative;
}

.canvas-area::-webkit-scrollbar { width: 8px; height: 8px; }
.canvas-area::-webkit-scrollbar-track { background: #dedad4; }
.canvas-area::-webkit-scrollbar-thumb { background: #b8b4ae; border-radius: 4px; }
.canvas-area::-webkit-scrollbar-thumb:hover { background: #9a9690; }
.canvas-area::-webkit-scrollbar-corner { background: #dedad4; }

.canvas-area.final-mode { background: #d8d4ce; }

.canvas-scroll { display: inline-block; transform-origin: 0 0; }

#paver-grid {
  display: block;
  background: #f8f6f3;
  border-radius: 3px;
  box-shadow: 0 3px 16px rgba(0,0,0,0.18);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

#paver-grid.final-mode { background: #ffffff; }

/* ── Floating zoom buttons ────────────────────────────────── */

.zoom-fab {
  position: absolute;
  bottom: 20px;
  right: 20px;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.zoom-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: white;
  border: 1px solid #c8c4be;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  color: #333;
  transition: background 0.12s, box-shadow 0.12s;
  flex-shrink: 0;
}
.zoom-btn:hover { background: #f0ede8; box-shadow: 0 3px 10px rgba(0,0,0,0.2); }
.zoom-btn:active { background: #e0ddd8; }

/* ── Mobile bottom toolbar ────────────────────────────────── */

.mobile-toolbar {
  display: none; /* shown via media query */
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: 60px;
  background: #262320;
  z-index: 80;
  align-items: center;
  padding: 0 8px;
  gap: 4px;
  border-top: 1px solid #3a3734;
}

.mob-menu-btn {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 4px;
  width: 44px;
  height: 44px;
  background: none;
  border: none;
  cursor: pointer;
  flex-shrink: 0;
  border-radius: 8px;
  padding: 4px;
}
.mob-menu-btn span {
  display: block;
  width: 18px;
  height: 2px;
  background: #d0ccc8;
  border-radius: 2px;
}

.mob-tools {
  display: flex;
  align-items: center;
  gap: 3px;
  flex: 1;
  justify-content: center;
}

.mob-tool-btn {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  border: 2px solid transparent;
  background: rgba(255,255,255,0.07);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s, border-color 0.12s;
  flex-shrink: 0;
}
.mob-tool-btn .swatch { width: 26px; height: 26px; border-radius: 6px; }
.mob-tool-btn:hover  { background: rgba(255,255,255,0.14); }
.mob-tool-btn:active { background: rgba(255,255,255,0.28); }
.mob-tool-btn.active {
  border-color: #f0ede8;
  background: rgba(255,255,255,0.15);
}

.mob-actions {
  display: flex;
  align-items: center;
  gap: 3px;
  flex-shrink: 0;
}

.mob-act-btn {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.12);
  color: #d0ccc8;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.12s;
}
.mob-act-btn:hover  { background: rgba(255,255,255,0.16); }
.mob-act-btn:active { background: rgba(255,255,255,0.32); }
.mob-act-btn.active { background: rgba(255,255,255,0.25); border-color: #f0ede8; color: #fff; }

/* Pan button — icon + text label stacked */
.mob-act-btn--pan { flex-direction: column; gap: 1px; width: 44px; font-size: 15px; }
.mob-act-icon { line-height: 1; }
.mob-act-lbl  { font-size: 8px; letter-spacing: 0.4px; text-transform: uppercase; opacity: 0.8; line-height: 1; }

/* ── Portrait / mobile layout ─────────────────────────────── */
/* Uses orientation rather than a fixed breakpoint width.       */
/* Covers phones and tablets held in portrait regardless of px. */

@media (orientation: portrait) {
  .hamburger-btn  { display: flex; }
  .mobile-toolbar { display: flex; }
  .zoom-fab       { bottom: 72px; }

  .sidebar {
    position: fixed;
    top: 0; left: 0;
    width: 270px;
    height: 100%;
    transform: translateX(-100%);
    border-right: none;
    box-shadow: 4px 0 24px rgba(0,0,0,0.28);
  }

  .sidebar.open { transform: translateX(0); }

  .sidebar-overlay { display: block; }
  .sidebar-header  { display: flex; }

  .canvas-area { padding: 16px 12px 72px; }

  .form-row input[type="number"] { font-size: 16px; padding: 6px; }
  .btn-primary, .btn-secondary, .btn-toggle { padding: 11px; font-size: 14px; min-height: 44px; }
  .draft-load, .draft-delete { min-height: 44px; font-size: 13px; }
}

/* Landscape: sidebar always visible, toolbar hidden */
@media (orientation: landscape) {
  .hamburger-btn  { display: none; }
  .mobile-toolbar { display: none; }
  .zoom-fab       { bottom: 20px; }

  .sidebar {
    position: static;
    width: 220px;
    transform: none;
    box-shadow: none;
    border-right: 1px solid #d8d5d0;
  }

  .sidebar-overlay { display: none !important; }
  .sidebar-header  { display: none; }

  .canvas-area { padding: 24px; }
}

/* Prevent scrolling behind open sidebar */
body.sidebar-open { overflow: hidden; }

/* ── Mobile axis picker ───────────────────────────────────── */
/* Floats above the mobile toolbar; shown only when a half tool is active */

.mob-axis-picker {
  position: fixed;
  bottom: 60px;
  left: 0;
  right: 0;
  z-index: 79;
  background: #1e1c19;
  border-top: 1px solid #3a3734;
  padding: 6px 10px;
  align-items: center;
  gap: 6px;
  display: none; /* toggled by JS */
}

.mob-axis-label {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: #888;
  flex-shrink: 0;
}

.mob-axis-btns {
  display: flex;
  gap: 5px;
  flex: 1;
  justify-content: center;
}

.mob-axis-btn {
  width: 40px;
  height: 40px;
  border-radius: 7px;
  border: 2px solid rgba(255,255,255,0.15);
  background: rgba(255,255,255,0.07);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: border-color 0.12s, background 0.12s;
}
.mob-axis-btn:hover  { background: rgba(255,255,255,0.14); }
.mob-axis-btn:active { background: rgba(255,255,255,0.28); }
.mob-axis-btn.active { border-color: #f0ede8; background: rgba(255,255,255,0.18); }