* { box-sizing: border-box; }

:root {
  --navy: #0a1233;
  --navy-soft: #16224d;
  --blue: #0b63ff;
  --blue-dark: #0a4fd0;
  --blue-tint: #eaf1ff;
  --bg: #f2f5fa;
  --panel: #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; }

/* Topbar */
.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; gap: 10px; }
.brand-logo { height: 34px; display: block; }
.brand-tag { font-size: 12px; font-weight: 700; color: var(--blue); background: var(--blue-tint);
  padding: 3px 9px; border-radius: 999px; letter-spacing: 0.03em; }
.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; text-decoration: none;
  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; }
.btn:active { transform: translateY(1px); }
.btn-ico { font-size: 15px; line-height: 1; }
.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.danger { color: var(--danger); border-color: #f0c4c0; background: #fff; }
.btn.danger:hover { background: var(--danger-tint); border-color: var(--danger); }

/* Floating bar */
.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 .btn.icon:disabled { opacity: 0.35; cursor: default; }
.floating-bar .btn.icon:disabled:hover { background: transparent; color: #cdd6ea; }
.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; }

/* App shell */
.app-shell { display: flex; align-items: stretch; flex: 1; min-height: 0; }
.sidebar { width: 320px; flex-shrink: 0; background: var(--panel); 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; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.note-box { margin: 14px 0 0; padding: 10px 12px; background: #fff7e8; border: 1px solid #f3e2bd;
  border-radius: 10px; line-height: 1.5; color: #7a5a16; }

/* Font summary */
.badge { margin-left: auto; background: var(--blue-tint); color: var(--blue-dark); font-size: 11px;
  font-weight: 700; padding: 2px 8px; border-radius: 999px; letter-spacing: 0; text-transform: none; }
.font-list { list-style: none; margin: 0 0 4px; padding: 0; display: flex; flex-direction: column; gap: 7px; }
.font-item {
  border: 1px solid var(--border); border-radius: 10px; padding: 9px 11px; cursor: pointer;
  transition: border-color 0.12s, background 0.12s; background: #fff;
}
.font-item:hover { border-color: var(--blue); background: var(--blue-tint); }
.font-item.active { border-color: var(--blue); box-shadow: 0 0 0 2px rgba(11,99,255,0.18); }
.font-item .fi-name { font-size: 13px; font-weight: 600; color: var(--text); word-break: break-word; }
.font-item .fi-meta { font-size: 11px; color: var(--muted); margin-top: 3px; display: flex; flex-wrap: wrap; gap: 4px 10px; }
.fi-tag { background: #eef1f7; border-radius: 5px; padding: 1px 6px; }
.fi-tag.emb { background: #e4f6e9; color: #1d7a3b; }
.fi-tag.sub { background: #fdeedd; color: #9a5a12; }

/* Highlight runs of the active font */
.text-run.font-hi { background: rgba(255, 193, 7, 0.35); box-shadow: 0 0 0 1px rgba(214, 158, 0, 0.7); }

/* Inspector rows */
.insp-row { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.insp-row:first-of-type { padding-top: 0; }
.insp-row span { color: var(--muted); flex-shrink: 0; }
.insp-row strong { font-weight: 600; text-align: right; word-break: break-word; }
#inspText { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#startEditBtn { margin-top: 14px; }

/* Fields */
.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: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="color"] { width: 100%; height: 38px; border: 1px solid var(--border-strong); border-radius: 9px; background: #fff; cursor: pointer; padding: 3px; }
.field input[type="color"]:disabled { opacity: 0.4; cursor: not-allowed; }
.chk { display: flex; align-items: flex-start; gap: 8px; font-size: 12.5px; color: var(--text); line-height: 1.4; cursor: pointer; }
.chk input { margin-top: 1px; accent-color: var(--blue); }
.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); }

/* Credit */
.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); }
.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; }

/* Workspace */
.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 .text-run { pointer-events: none; }
.workspace.pan-mode .edit-box { pointer-events: none; }

.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; }

/* Clickable text layer */
.text-layer { position: absolute; inset: 0; overflow: hidden; line-height: 1; }
.text-run {
  position: absolute;
  cursor: pointer;
  color: transparent;            /* invisible; the canvas shows the real glyphs */
  white-space: pre;
  transform-origin: 0 0;
  border-radius: 2px;
  transition: background 0.1s, box-shadow 0.1s;
}
.text-run:hover { background: rgba(11, 99, 255, 0.14); box-shadow: 0 0 0 1px rgba(11,99,255,0.4); }
.text-run.selected { background: rgba(11, 99, 255, 0.2); box-shadow: 0 0 0 2px var(--blue); }

/* Edit boxes (whiteout + replacement text) */
.edit-box { position: absolute; cursor: move; border: 1px dashed transparent; touch-action: none; display: flex; align-items: center; }
.edit-box .whiteout { position: absolute; inset: 0; background: #fff; z-index: 0; }
.edit-box .edit-text { position: relative; z-index: 1; width: 100%; white-space: pre; pointer-events: none; line-height: 1.1; }
.edit-box .edit-text.editing { outline: none; cursor: text; caret-color: var(--blue); }
.edit-box.editing-active { cursor: text; }
.edit-box.selected { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(11,99,255,0.15); }
.edit-box .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; z-index: 2; }
.edit-box.selected .handle { display: block; }

/* 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; }

/* Status */
.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); }

/* Dialog */
.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: 420px; max-width: calc(100vw - 40px); box-shadow: var(--shadow-lg); overflow: hidden; animation: popIn 0.16s ease; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 20px; border-top: 1px solid var(--border); }
.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; }
.modal.dialog.danger .dialog-icon { background: var(--danger-tint); }
.modal.dialog.danger #dialogOk { background: var(--danger); border-color: var(--danger); }
