@import url('https://fonts.googleapis.com/css2?family=Fraunces:wght@500;600&family=Inter:wght@400;500;600&display=swap');

:root {
  --bg: #14151A;
  --panel: #1C1E26;
  --panel-alt: #20222C;
  --border: #2A2D38;
  --text: #ECEDEF;
  --text-muted: #8B90A0;
  --accent: #E8A33D;
  --accent-2: #4FD1C5;
  --danger: #E85D5D;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 14px;
  overflow: hidden;
}

#app {
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  height: 100vh;
}

/* ---- Top bar ----
   Toolbar.js renders three rows in the DOM: .row-combined (single row,
   everything together) and .row-top1 + .row-top2 (split two-row layout).
   Only one of these is shown, chosen purely by orientation — mirrors the
   reference app's landscape (one row) vs portrait (two rows) behavior. */
.topbar { background: var(--panel); border-bottom: 1px solid var(--border); }
.row { display: flex; align-items: center; gap: 4px; padding: 0 14px; height: 50px; }
.row + .row { border-top: 1px solid var(--border); }

.row-top1, .row-top2 { display: none; }

@media (orientation: portrait) {
  .row-combined { display: none; }
  .row-top1, .row-top2 { display: flex; }
}

.brand {
  display: flex; align-items: center; gap: 8px;
  font-family: 'Fraunces', serif; font-weight: 600; font-size: 18px;
  letter-spacing: 0.2px; margin-right: 6px; white-space: nowrap;
}
.brand-mark { color: var(--accent); }
.spacer { flex: 1; }

.tbtn {
  width: 32px; height: 32px; flex-shrink: 0;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.tbtn:hover:not(:disabled) { background: var(--panel-alt); border-color: var(--border); }
.tbtn:disabled { opacity: 0.3; cursor: not-allowed; }
.tbtn.active { color: var(--accent-2); border-color: var(--accent-2); }
.ic { width: 18px; height: 18px; }

.zoom-readout { width: 42px; text-align: center; color: var(--text-muted); font-variant-numeric: tabular-nums; font-size: 12px; }

.more-wrap { position: relative; }
.more-menu {
  display: none; position: absolute; top: 38px; right: 0; z-index: 30;
  background: var(--panel-alt); border: 1px solid var(--border); border-radius: 8px;
  min-width: 190px; padding: 6px; flex-direction: column; gap: 2px;
}
.more-menu.open { display: flex; }
.more-menu button {
  background: transparent; border: none; color: var(--text); text-align: left;
  padding: 8px 10px; border-radius: 6px; font-size: 13px; cursor: pointer; font-family: inherit;
}
.more-menu button:hover { background: var(--border); }

/* ---- Bottom main toolbar: spec §5's 5 shortcuts, always visible ---- */
.bottombar {
  grid-row: 4;
  background: var(--panel);
  border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-around;
  height: 52px;
}
.bbtn {
  background: transparent; border: none; color: var(--text-muted);
  width: 40px; height: 40px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.bbtn:hover { background: var(--panel-alt); color: var(--text); }
.bbtn.selected { color: var(--accent); background: var(--panel-alt); }

/* ---- Project shortcuts row: "my projects" + preset size templates ---- */
.project-shortcuts {
  grid-row: 3;
  background: var(--panel);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  overflow-x: auto;
}
.proj-folder, .tmpl-card {
  background: transparent;
  border: none;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  cursor: pointer;
  font-family: inherit;
}
.proj-folder .ic { width: 28px; height: 28px; }
.proj-folder span:last-child, .tmpl-label {
  font-size: 10px;
  color: var(--text-muted);
  max-width: 64px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tmpl-divider { width: 1px; align-self: stretch; background: var(--border); flex-shrink: 0; }
.tmpl-thumb {
  width: 52px;
  max-height: 52px;
  background: #0F1014;
  border: 1px solid var(--border);
  border-radius: 6px;
}
.tmpl-card:hover .tmpl-thumb, .proj-folder:hover { border-color: var(--accent); color: var(--text); }
.tmpl-card:hover .tmpl-thumb { border-color: var(--accent); }

/* ---- Toast ---- */
.toast {
  position: fixed; left: 50%; bottom: 72px; transform: translate(-50%, 8px);
  background: var(--panel-alt); border: 1px solid var(--border); color: var(--text);
  padding: 9px 16px; border-radius: 8px; font-size: 13px; z-index: 50;
  opacity: 0; transition: opacity 0.2s ease, transform 0.2s ease; pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---- Workspace layout ---- */
.workspace {
  display: grid;
  grid-template-columns: 220px 1fr 260px;
  height: 100%;
  min-height: 0;
}

.left-rail, .right-rail {
  background: var(--panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 14px;
}
.right-rail { border-right: none; border-left: 1px solid var(--border); }

.canvas-area {
  position: relative;
  background: #0F1014;
  overflow: hidden;
}
#main-canvas { width: 100%; height: 100%; display: block; cursor: default; }

/* ---- Bottom sheets (mobile/portrait panel presentation) ----
   Must come AFTER the base .workspace/.left-rail/.right-rail rules above —
   same-specificity CSS rules are resolved by source order, so a media
   query placed earlier in the file gets silently overridden by a later
   unconditional rule for the same property, even when the query matches. */
.sheet-backdrop {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 15;
}
.sheet-backdrop.open { display: block; }

@media (orientation: portrait), (max-width: 760px) {
  .workspace { grid-template-columns: 1fr; }
  .left-rail, .right-rail {
    position: fixed; left: 0; right: 0; bottom: 128px;
    max-height: 48vh; z-index: 20;
    border-right: none; border-left: none;
    border-radius: 16px 16px 0 0;
    transform: translateY(110%);
    transition: transform 0.22s ease;
  }
  .left-rail.open, .right-rail.open { transform: translateY(0); }
}

.panel-title {
  font-size: 12px;
  text-transform: none;
  color: var(--text-muted);
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

/* ---- Shape grid ---- */
.shape-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.shape-swatch {
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.shape-swatch:hover { border-color: var(--accent); }
.shape-swatch canvas { display: block; }

/* ---- Layers ---- */
.layer-row {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 4px;
  border-radius: 8px;
  cursor: default;
}
.layer-row:hover { background: var(--panel-alt); }
.layer-row.selected { background: #2a2440; outline: 1px solid var(--accent-2); }
.layer-name { flex: 1; padding: 0 4px; font-size: 13px; cursor: pointer; }
.icon-btn {
  background: transparent; border: none; color: var(--text-muted);
  cursor: pointer; font-size: 13px; width: 22px; height: 22px; border-radius: 5px;
}
.icon-btn:hover { background: var(--border); color: var(--text); }
.icon-btn.danger:hover { color: var(--danger); }
.empty-hint { color: var(--text-muted); font-size: 12.5px; line-height: 1.5; }

/* ---- Properties ---- */
.prop-group {
  border-bottom: 1px solid var(--border);
  padding: 10px 0;
}
.prop-group:last-child { border-bottom: none; }
.prop-subtitle { color: var(--text-muted); font-size: 12px; margin-bottom: 6px; }
.prop-row { display: flex; gap: 8px; }
.prop-field {
  display: flex; flex-direction: column; gap: 4px;
  font-size: 11.5px; color: var(--text-muted);
  flex: 1; margin-bottom: 8px;
}
.prop-field input[type="number"],
.prop-field input[type="color"] {
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 5px 6px;
  font-family: inherit;
  font-size: 12.5px;
}
.prop-field input[type="range"] { accent-color: var(--accent-2); }
.prop-field input[type="color"] { height: 30px; padding: 2px; }
