* { box-sizing: border-box; }

:root {
  /* Inkly palette */
  --navy: #0a1233;
  --navy-soft: #16224d;
  --blue: #0b63ff;
  --blue-dark: #0a4fd0;
  --blue-tint: #eaf1ff;

  --bg: #f2f5fa;
  --panel: #ffffff;
  --sidebar: #ffffff;
  --border: #e4e8f0;
  --border-strong: #d3d9e6;
  --text: #0f1729;
  --muted: #6b7488;
  --danger: #e0483d;
  --danger-tint: #fdecea;

  --radius: 14px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 3px rgba(15, 23, 41, 0.06), 0 1px 2px rgba(15, 23, 41, 0.04);
  --shadow-md: 0 6px 20px rgba(15, 23, 41, 0.1);
  --shadow-lg: 0 18px 48px rgba(10, 18, 51, 0.24);
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ---- Top bar ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 50;
}
.brand { display: flex; align-items: center; }
.brand-logo { height: 34px; display: block; }

.topbar-actions { display: flex; gap: 10px; align-items: center; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 15px;
  border: 1px solid var(--border-strong);
  background: var(--panel);
  color: var(--text);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s, transform 0.05s, opacity 0.15s;
  user-select: none;
}
.btn:hover { background: #f6f8fc; border-color: var(--border-strong); }
.btn:active { transform: translateY(1px); }
.btn-ico { font-size: 15px; line-height: 1; }

.btn.ghost { background: var(--panel); }
.btn.ghost:hover { background: var(--blue-tint); border-color: var(--blue); color: var(--blue-dark); }

.btn.primary {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
  box-shadow: 0 2px 8px rgba(11, 99, 255, 0.28);
}
.btn.primary:hover { background: var(--blue-dark); border-color: var(--blue-dark); }
.btn.primary:disabled { opacity: 0.45; cursor: not-allowed; box-shadow: none; }

.btn.block { width: 100%; }
.btn.small { padding: 6px 11px; font-size: 13px; }
.btn.icon { padding: 6px 11px; font-size: 16px; line-height: 1; border-radius: 9px; }

.btn.tool {
  justify-content: flex-start;
  padding: 12px 14px;
  font-weight: 600;
  background: var(--panel);
}
.btn.tool:hover { background: var(--blue-tint); border-color: var(--blue); }

.btn.danger { color: var(--danger); border-color: #f0c4c0; background: #fff; }
.btn.danger:hover { background: var(--danger-tint); border-color: var(--danger); }

/* ---- Floating bottom toolbar ---- */
.floating-bar {
  position: fixed;
  bottom: 52px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 5px;
  background: var(--navy);
  border-radius: 14px;
  padding: 7px 9px;
  box-shadow: var(--shadow-md);
  z-index: 70;
}
.floating-bar .btn.icon {
  background: transparent;
  border-color: transparent;
  color: #cdd6ea;
}
.floating-bar .btn.icon:hover { background: rgba(255, 255, 255, 0.12); color: #fff; }
.floating-bar span#zoomLabel {
  font-size: 13px;
  color: #cdd6ea;
  min-width: 46px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.floating-bar .divider { width: 1px; height: 20px; background: rgba(255, 255, 255, 0.18); margin: 0 3px; }
.floating-bar .btn.icon.active { background: var(--blue); color: #fff; }

/* ---- Cursor preview ---- */
.cursor-preview {
  position: fixed;
  top: 0; left: 0;
  pointer-events: none;
  z-index: 90;
  opacity: 0.62;
}
.cursor-preview[hidden] { display: none; }
.cursor-preview.sig img {
  display: block;
  max-width: 220px;
  max-height: 120px;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.28));
}
.cursor-preview.text {
  background: rgba(11, 99, 255, 0.12);
  border: 1px dashed var(--blue);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 22px;
  color: var(--text);
}

/* ---- Floating item toolbar ---- */
.item-toolbar {
  position: fixed;
  display: flex;
  gap: 4px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 5px;
  box-shadow: var(--shadow-md);
  z-index: 65;
}
.item-toolbar[hidden] { display: none; }

/* ---- App shell ---- */
.app-shell {
  display: flex;
  align-items: stretch;
  flex: 1;
  min-height: 0;
}

.sidebar {
  width: 312px;
  flex-shrink: 0;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow-sm);
}
.card h3 {
  margin: 0 0 14px;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 8px;
}
.card-ico { font-size: 15px; }

.steps {
  margin: 0;
  padding-left: 20px;
  font-size: 13px;
  line-height: 1.65;
  color: var(--text);
}
.steps li { margin-bottom: 6px; }
.steps li::marker { color: var(--blue); font-weight: 700; }

.tool-buttons { display: flex; flex-direction: column; gap: 9px; }

/* ---- Credit (pinned to bottom of sidebar) ---- */
.credit {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 2px;
  text-align: center;
}
.credit-label {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.02em;
}
.credit-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--navy);
  text-decoration: none;
}
.credit-name:hover { color: var(--blue); }
.credit-url {
  font-size: 12px;
  font-weight: 500;
  color: var(--blue);
  text-decoration: none;
}
.credit-url:hover { text-decoration: underline; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.muted.small { margin: 12px 0 0; line-height: 1.5; }

/* ---- Fields / properties ---- */
.field { margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }
.field > label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 6px;
}
.field.row { display: flex; gap: 10px; }
.field.row > div { flex: 1; }

.field input[type="text"],
.field input[type="number"],
.field select {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  font-family: inherit;
  font-size: 14px;
  background: #fff;
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field input[type="text"]:focus,
.field input[type="number"]:focus,
.field select:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(11, 99, 255, 0.15);
}

.field input[type="range"] { width: 100%; accent-color: var(--blue); }
.field input[type="color"] {
  width: 100%;
  height: 38px;
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  background: #fff;
  cursor: pointer;
  padding: 3px;
}

.text-props { margin-bottom: 14px; }
.text-props .field:last-child { margin-bottom: 0; }
.prop-delete { margin-top: 6px; }

.toggle-group { display: flex; gap: 8px; }
.toggle {
  flex: 1;
  padding: 8px;
  border: 1px solid var(--border-strong);
  background: #fff;
  border-radius: 9px;
  cursor: pointer;
  font-size: 15px;
  transition: background 0.15s, border-color 0.15s;
}
.toggle:hover { border-color: var(--blue); }
.toggle.active { background: var(--blue); color: #fff; border-color: var(--blue); }

/* ---- Workspace / viewer ---- */
.workspace {
  position: relative;
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  padding: 28px;
}
.workspace.pan-mode { cursor: grab; }
.workspace.pan-mode.panning { cursor: grabbing; }
.workspace.pan-mode .item { pointer-events: none; }
.workspace.pan-mode .page-wrap canvas { cursor: grab; }

.empty-state {
  text-align: center;
  color: var(--muted);
  margin-top: 11vh;
}
.empty-logo {
  width: 96px;
  height: 96px;
  border-radius: 22px;
  box-shadow: var(--shadow-md);
  margin-bottom: 18px;
}
.empty-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  margin: 0 0 6px;
}
.empty-state p { margin: 6px 0; }

.viewer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
  min-width: min-content;
  margin: 0 auto;
}

.page-wrap {
  position: relative;
  border-radius: 6px;
  box-shadow: var(--shadow-md);
  background: #fff;
  line-height: 0;
}
.page-wrap canvas { display: block; border-radius: 6px; }

/* ---- Drag & drop overlay ---- */
.drop-overlay {
  position: absolute;
  inset: 0;
  z-index: 80;
  background: rgba(11, 99, 255, 0.08);
  backdrop-filter: blur(1px);
  pointer-events: none;
}
.drop-overlay[hidden] { display: none; }
.drop-inner {
  position: sticky;
  top: 50%;
  transform: translateY(-50%);
  width: max-content;
  margin: 0 auto;
  border: 3px dashed var(--blue);
  border-radius: 18px;
  padding: 42px 64px;
  background: rgba(255, 255, 255, 0.95);
  text-align: center;
  color: var(--blue-dark);
  font-size: 18px;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
}
.drop-icon { font-size: 46px; margin-bottom: 8px; }

/* ---- Overlay items ---- */
.item {
  position: absolute;
  top: 0; left: 0;
  cursor: move;
  border: 1px dashed transparent;
  border-radius: 3px;
  touch-action: none;
}
.item.selected { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(11, 99, 255, 0.15); }
.item img { width: 100%; height: 100%; display: block; pointer-events: none; }
.item.text {
  display: flex;
  align-items: center;
  white-space: nowrap;
  line-height: 1.1;
  padding: 2px 4px;
}
.item.text .text-content { pointer-events: none; width: 100%; }
.item .handle {
  position: absolute;
  width: 13px; height: 13px;
  right: -7px; bottom: -7px;
  background: var(--blue);
  border: 2px solid #fff;
  border-radius: 50%;
  cursor: nwse-resize;
  box-shadow: var(--shadow-sm);
  display: none;
}
.item.selected .handle { display: block; }

/* ---- Status footer ---- */
.status {
  flex-shrink: 0;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  min-height: 22px;
  padding: 9px 12px;
  background: var(--panel);
  border-top: 1px solid var(--border);
  z-index: 40;
}
.status.error { color: var(--danger); }

/* ---- Modals ---- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 18, 51, 0.55);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: fadeIn 0.14s ease;
}
.modal-backdrop[hidden] { display: none; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes popIn { from { opacity: 0; transform: translateY(8px) scale(0.98); } to { opacity: 1; transform: none; } }

.modal {
  background: var(--panel);
  border-radius: 18px;
  width: 560px;
  max-width: calc(100vw - 40px);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: popIn 0.16s ease;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-head h3 { margin: 0; font-size: 17px; font-weight: 700; }

.tabs { display: flex; gap: 4px; padding: 14px 20px 0; }
.tab {
  padding: 9px 18px;
  border: none;
  background: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--blue); border-bottom-color: var(--blue); font-weight: 600; }

.tab-panel { padding: 20px; }

#drawCanvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 500 / 180;
  border: 1px dashed var(--border-strong);
  border-radius: 12px;
  background: #fff;
  cursor: crosshair;
  touch-action: none;
}

.modal-controls { display: flex; align-items: center; gap: 14px; margin-top: 14px; }
.inline { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.inline input[type="color"] {
  width: 38px; height: 28px;
  border: 1px solid var(--border-strong);
  border-radius: 7px; padding: 0; cursor: pointer;
}

#typeInput {
  width: 100%;
  padding: 11px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  font-family: inherit;
  font-size: 15px;
}
#typeInput:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(11, 99, 255, 0.15); }
.font-choices { display: flex; gap: 9px; margin-top: 14px; }
.font-choice {
  flex: 1;
  padding: 12px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
  font-size: 22px;
}
.font-choice.active { border-color: var(--blue); box-shadow: 0 0 0 2px rgba(11, 99, 255, 0.18); }

.type-preview {
  margin-top: 16px;
  min-height: 72px;
  border: 1px dashed var(--border-strong);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Dancing Script', cursive;
  font-size: 42px;
  color: var(--blue-dark);
}

.upload-drop {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 124px;
  border: 2px dashed var(--border-strong);
  border-radius: 12px;
  cursor: pointer;
  color: var(--muted);
  font-size: 14px;
}
.upload-drop:hover { border-color: var(--blue); color: var(--blue); background: var(--blue-tint); }
.upload-preview { display: block; max-width: 100%; max-height: 140px; margin: 14px auto 0; }

.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

/* ---- Generic dialog ---- */
.modal.dialog { width: 420px; }
.dialog-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 22px 22px 6px;
}
.dialog-icon {
  font-size: 24px;
  width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  background: var(--blue-tint);
  border-radius: 12px;
  flex-shrink: 0;
}
.dialog-head h3 { margin: 0; font-size: 17px; font-weight: 700; }
.dialog-message {
  margin: 0;
  padding: 8px 22px 18px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
  white-space: pre-line;
}
.dialog-field { padding: 0 22px 8px; }
.dialog-field input {
  width: 100%;
  padding: 11px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  font-family: inherit;
  font-size: 15px;
}
.dialog-field input:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(11, 99, 255, 0.15); }
.dialog-error { margin: 8px 0 0; color: var(--danger); font-size: 13px; }
.dialog-error[hidden] { display: none; }

/* dialog tone variants */
.modal.dialog.danger .dialog-icon { background: var(--danger-tint); }
.modal.dialog.danger #dialogOk { background: var(--danger); border-color: var(--danger); box-shadow: 0 2px 8px rgba(224, 72, 61, 0.3); }
.modal.dialog.danger #dialogOk:hover { background: #c93a30; border-color: #c93a30; }
