/* ModelMaker */
* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #0f172a;
  --panel: #ffffff;
  --line: #e2e8f0;
  --text: #0f172a;
  --dim: #64748b;
  --accent: #2563eb;
  --accent-soft: #dbeafe;
  --danger: #dc2626;
  --radius: 10px;
  --shadow: 0 4px 18px rgba(15, 23, 42, .14);
}
html, body { height: 100%; overflow: hidden; }
body {
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: #f2f6fb;
  display: flex;
  flex-direction: column;
  touch-action: manipulation;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input { font: inherit; }

/* ---------------- top bar ---------------- */
#topbar {
  height: 52px;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  background: var(--bg);
  color: #e2e8f0;
  z-index: 30;
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #fff;
  text-decoration: none;
  font-family: ui-monospace, "Roboto Mono", monospace;
  font-weight: 700;
  letter-spacing: .3px;
  white-space: nowrap;
}
#designName {
  flex: 1 1 120px;
  min-width: 60px;
  max-width: 300px;
  background: rgba(255, 255, 255, .08);
  border: 1px solid rgba(255, 255, 255, .14);
  border-radius: 7px;
  color: #fff;
  padding: 6px 10px;
  outline: none;
}
#designName:focus { border-color: var(--accent); background: rgba(255, 255, 255, .12); }
.top-actions { display: flex; align-items: center; gap: 5px; margin-left: auto; }
.top-btn {
  padding: 7px 11px;
  border-radius: 7px;
  color: #dbe4f0;
  background: rgba(255, 255, 255, .07);
  white-space: nowrap;
}
.top-btn:hover { background: rgba(255, 255, 255, .16); }
.top-btn.accent { background: var(--accent); color: #fff; font-weight: 600; }
.top-btn.accent:hover { background: #1d4ed8; }
.icon-btn {
  width: 34px; height: 34px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 7px;
  color: inherit;
}
#topbar .icon-btn { color: #dbe4f0; }
#topbar .icon-btn:hover { background: rgba(255, 255, 255, .14); }
#topbar .icon-btn:disabled { opacity: .35; cursor: default; background: none; }
.vsep { width: 1px; height: 22px; background: rgba(255, 255, 255, .18); margin: 0 3px; }
.drawer-btn { display: none; }

/* ---------------- layout ---------------- */
#main { flex: 1; display: flex; min-height: 0; position: relative; }

/* palette */
#palette {
  width: 224px;
  flex: 0 0 auto;
  background: var(--panel);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  z-index: 25;
}
#paletteBody { padding: 12px; }
.pal-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--dim);
  margin: 14px 0 8px;
}
.pal-title:first-child { margin-top: 2px; }
.shape-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.shape-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 7px 4px 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f8fafc;
  font-size: 12px;
  color: #334155;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.shape-btn:hover { border-color: var(--accent); background: var(--accent-soft); }
.shape-thumb { width: 58px; height: 58px; pointer-events: none; }

/* viewport */
#viewport { flex: 1; position: relative; min-width: 0; overflow: hidden; }
#c { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.overlay { position: absolute; display: flex; gap: 6px; z-index: 10; }
#viewbar { top: 12px; left: 12px; }
#modebar { top: 60px; left: 12px; flex-direction: column; }
#zoombar { bottom: 18px; right: 14px; flex-direction: column; }

.tool {
  min-width: 46px; min-height: 42px;
  padding: 4px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  color: #334155;
  font-size: 10px;
}
.tool.txt { font-size: 12px; font-weight: 600; }
.tool:hover { border-color: var(--accent); color: var(--accent); }
.tool.on { background: var(--accent); border-color: var(--accent); color: #fff; }
#zoombar .tool { font-size: 20px; font-weight: 600; min-height: 44px; }
.hsep { height: 6px; }
.tool-select {
  appearance: none;
  -webkit-appearance: none;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 2px;
}
.tool-select:focus { outline: 2px solid var(--accent-soft); }

#hint {
  position: absolute;
  bottom: 14px; left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, .62);
  color: #e8eef6;
  font-size: 12px;
  padding: 6px 14px;
  border-radius: 999px;
  pointer-events: none;
  white-space: nowrap;
  z-index: 5;
}

/* ---------------- properties panel ---------------- */
#props {
  position: absolute;
  top: 64px; right: 12px;
  width: 246px;
  max-height: calc(100% - 140px);
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 12px 14px 14px;
  z-index: 20;
  display: none;
}
#props.open { display: block; }
.props-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 700;
  margin-bottom: 8px;
}
.props-head .icon-btn:hover { background: #eef2f7; }
#props h4 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .7px;
  color: var(--dim);
  margin: 12px 0 5px;
}
.fld { display: block; font-size: 12px; color: var(--dim); margin-bottom: 8px; }
.fld input[type="text"] {
  width: 100%;
  margin-top: 3px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--text);
}
.row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.row3 label { font-size: 11px; color: var(--dim); display: flex; flex-direction: column; gap: 2px; }
.row3 input {
  width: 100%;
  padding: 6px 6px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--text);
}
input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.color-row { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
#swatches { display: grid; grid-template-columns: repeat(5, 22px); gap: 5px; }
.swatch {
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px var(--line);
}
.swatch:hover { transform: scale(1.15); }
#pColor {
  width: 34px; height: 30px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 2px;
  background: #fff;
}
.props-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; }
.btn {
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #f8fafc;
  color: var(--text);
  font-weight: 600;
  font-size: 13px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #1d4ed8; color: #fff; }
.btn.danger { color: var(--danger); }
.btn.danger:hover { border-color: var(--danger); background: #fef2f2; }

/* ---------------- modal ---------------- */
#modal[hidden] { display: none; }
#modal {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, .55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}
.modal-card {
  background: var(--panel);
  border-radius: 14px;
  box-shadow: 0 12px 50px rgba(15, 23, 42, .35);
  width: 100%;
  max-width: 400px;
  max-height: 84vh;
  display: flex;
  flex-direction: column;
}
.modal-card.wide { max-width: 560px; }
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px 8px;
}
.modal-title { font-size: 17px; }
.modal-head .icon-btn:hover { background: #eef2f7; }
.modal-body { padding: 6px 18px 18px; overflow-y: auto; }
.modal-text { margin: 6px 0 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.dim { color: var(--dim); font-size: 12px; }
.text-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-top: 4px;
}
.file-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 2px;
  border-bottom: 1px solid var(--line);
}
.file-info { display: flex; flex-direction: column; min-width: 0; }
.file-info strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-actions { display: flex; gap: 6px; flex: 0 0 auto; }
.opt-group { margin-bottom: 10px; }
.radio { display: block; padding: 5px 2px; cursor: pointer; }
.help-table { border-collapse: collapse; width: 100%; }
.help-table td { padding: 5px 8px 5px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.help-table td:first-child { font-weight: 600; white-space: nowrap; }

/* ---------------- toasts & loader ---------------- */
#toasts {
  position: fixed;
  bottom: 64px; left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 200;
  pointer-events: none;
}
.toast {
  background: #0f172a;
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(8px);
  transition: all .25s ease;
  max-width: 90vw;
}
.toast.show { opacity: 1; transform: translateY(0); }

#loader {
  position: fixed; inset: 0;
  background: #f2f6fb;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  z-index: 300;
  color: var(--dim);
  transition: opacity .4s ease;
}
#loader.done { opacity: 0; pointer-events: none; }
.spin {
  width: 42px; height: 42px;
  border: 4px solid var(--accent-soft);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------- mobile ---------------- */
@media (max-width: 860px) {
  .drawer-btn { display: inline-flex; }
  .brand span { display: none; }
  #palette {
    position: absolute;
    top: 0; bottom: 0; left: 0;
    width: min(78vw, 300px);
    transform: translateX(-102%);
    transition: transform .22s ease;
    box-shadow: var(--shadow);
  }
  #palette.open { transform: translateX(0); }
  .shape-grid { grid-template-columns: repeat(3, 1fr); }
  .shape-thumb { width: 48px; height: 48px; }

  #props {
    top: auto;
    right: 0; left: 0; bottom: 0;
    width: 100%;
    max-height: 46vh;
    border-radius: 16px 16px 0 0;
    border: 0;
    border-top: 1px solid var(--line);
    padding-bottom: max(14px, env(safe-area-inset-bottom));
  }
  #modebar { top: 60px; }
  #viewbar .tool.txt { display: none; }
  #hint { display: none; }
  .tool { min-width: 42px; min-height: 40px; }
  .top-btn { padding: 6px 8px; font-size: 12px; }
}
@media (max-width: 560px) {
  .hide-sm { display: none; }
  #topbar { gap: 6px; padding: 0 6px; }
  .vsep { display: none; }
}
