:root {
  --desk-bg: #e4e1da;
  --chrome: #f7f6f2;
  --surface: #ffffff;
  --surface-subtle: #efede7;
  --border: #d7d4cb;
  --border-strong: #b9b5aa;
  --ink: #18181b;
  --ink-muted: #57564f;
  --accent: #1d4ed8;
  --accent-hover: #1e40af;
  --accent-soft: rgba(29, 78, 216, 0.08);
  --lock: #0f766e;
  --lock-soft: rgba(15, 118, 110, 0.1);
  --warn: #b45309;
  --danger: #b91c1c;
  --danger-soft: rgba(185, 28, 28, 0.08);
  --mono: "Cascadia Mono", "Consolas", "SFMono-Regular", ui-monospace, monospace;
  --sans: "Segoe UI", -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  --serif: Georgia, "Times New Roman", serif;
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
}

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

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--desk-bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

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

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Top Studio Bar */
.topbar {
  min-height: 54px;
  background: var(--chrome);
  border-bottom: 1px solid var(--border);
  padding: 6px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.brand-mark {
  display: block;
  flex-shrink: 0;
}

.brand-copy {
  display: flex;
  flex-direction: column;
}

.brand-title {
  font-weight: 600;
  font-size: 14.5px;
  letter-spacing: -0.015em;
  line-height: 1.15;
  color: var(--ink);
}

.brand-sub {
  font-size: 11.5px;
  color: var(--ink-muted);
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.toolbar-group[hidden] {
  display: none;
}

.toolbar-cluster {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.file-pill {
  max-width: 190px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px 9px;
  font-size: 12px;
  font-family: var(--mono);
  color: var(--ink);
}

.divider {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 2px;
}

.metric-indicator {
  font-size: 12px;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  color: var(--ink-muted);
  min-width: 46px;
  text-align: center;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  border-radius: var(--radius-md);
  padding: 6px 12px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.2;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

.btn:hover:not(:disabled) {
  background: var(--surface-subtle);
  border-color: var(--border-strong);
}

.btn:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--surface-subtle);
}

.btn-danger-ghost {
  background: transparent;
  border-color: rgba(185, 28, 28, 0.35);
  color: var(--danger);
}

.btn-danger-ghost:hover:not(:disabled) {
  background: var(--danger-soft);
  border-color: var(--danger);
}

.btn-mode {
  background: var(--surface);
  border-color: var(--border);
  color: var(--ink);
}

.btn-mode.is-active {
  background: #18181b;
  border-color: #18181b;
  color: #ffffff;
}

.btn-mode.is-active:hover:not(:disabled) {
  background: #27272a;
  border-color: #27272a;
}

.btn-icon {
  min-width: 30px;
  height: 30px;
  padding: 0 7px;
  font-size: 13px;
}

.btn-sm {
  height: 30px;
  padding: 0 10px;
  font-size: 12.5px;
}

.btn-xs {
  height: 26px;
  padding: 0 8px;
  font-size: 11.5px;
}

.btn-lg {
  height: 40px;
  padding: 0 18px;
  font-size: 14px;
}

.toggle-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 10px;
  font-size: 12.5px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  user-select: none;
}

.toggle-chip input {
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

/* Main Workspace */
.workspace {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* Entry / Open Document Screen */
.drop-screen {
  flex: 1;
  overflow-y: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 36px 28px;
  background: var(--chrome);
}

.drop-screen[hidden] {
  display: none;
}

.drop-layout {
  width: 100%;
  max-width: 1020px;
  display: grid;
  grid-template-columns: 1.08fr 0.92fr;
  gap: 48px;
  align-items: center;
}

.eyebrow {
  font-family: var(--mono);
  font-size: 11.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--lock);
  margin-bottom: 10px;
}

.drop-intro h1 {
  margin: 0 0 14px;
  font-family: var(--serif);
  font-size: clamp(26px, 3vw, 35px);
  font-weight: 700;
  line-height: 1.18;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.lead {
  margin: 0 0 26px;
  font-size: 15px;
  line-height: 1.6;
  color: var(--ink-muted);
  max-width: 52ch;
}

.spec-list {
  margin: 0;
  padding: 0;
  border-top: 1px solid var(--border);
}

.spec-item {
  display: grid;
  grid-template-columns: 155px 1fr;
  gap: 14px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.spec-item dt {
  font-weight: 600;
  font-size: 13px;
  color: var(--ink);
}

.spec-item dd {
  margin: 0;
  font-size: 13px;
  color: var(--ink-muted);
  line-height: 1.45;
}

.drop-card {
  background: var(--surface);
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 28px;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.drop-card.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.drop-sheet-preview {
  background: var(--chrome);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px 20px;
  margin-bottom: 22px;
}

.sheet-line {
  height: 8px;
  background: #dad7ce;
  border-radius: 2px;
  margin-bottom: 9px;
}

.sheet-line:last-child {
  margin-bottom: 0;
}

.sheet-line-title {
  width: 58%;
  height: 11px;
  background: #27272a;
}

.sheet-line-sub {
  width: 38%;
  height: 7px;
  background: #a19e95;
  margin-bottom: 14px;
}

.sheet-rule {
  height: 1px;
  background: var(--border);
  margin-bottom: 14px;
}

.sheet-line-active {
  width: 82%;
  height: 24px;
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 8px;
}

.sheet-line-active span {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--accent);
  font-weight: 600;
}

.sheet-line-short {
  width: 64%;
}

.drop-card-title {
  margin: 0 0 6px;
  font-size: 17px;
  font-weight: 600;
  color: var(--ink);
}

.drop-card-sub {
  margin: 0 0 20px;
  font-size: 13.5px;
  color: var(--ink-muted);
}

.drop-card-sub code {
  font-family: var(--mono);
  font-size: 12.5px;
  background: var(--surface-subtle);
  padding: 1px 5px;
  border-radius: 3px;
}

.drop-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* Editor Split Layout */
.editor-shell {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 340px;
  overflow: hidden;
}

.editor-shell[hidden] {
  display: none;
}

.canvas-scroll {
  overflow: auto;
  padding: 28px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  background: var(--desk-bg);
}

.page-stage {
  position: relative;
  background: #ffffff;
  border: 1px solid rgba(24, 24, 27, 0.12);
  box-shadow: 0 1px 3px rgba(24, 24, 27, 0.08), 0 14px 34px rgba(24, 24, 27, 0.12);
  flex-shrink: 0;
  user-select: none;
}

#pageImage {
  display: block;
  width: 100%;
  height: 100%;
}

.span-layer {
  position: absolute;
  inset: 0;
}

.span-box {
  position: absolute;
  border: 1px solid transparent;
  border-radius: 2px;
  cursor: text;
  transition: background-color 0.08s ease, border-color 0.08s ease;
}

.span-layer.show-boxes .span-box {
  border-color: rgba(29, 78, 216, 0.25);
  background: rgba(29, 78, 216, 0.025);
}

.span-box:hover {
  border-color: rgba(29, 78, 216, 0.85) !important;
  background: rgba(29, 78, 216, 0.09) !important;
}

.span-box.selected {
  border: 1.5px solid var(--accent) !important;
  background: rgba(29, 78, 216, 0.12) !important;
}

body.move-mode .span-box {
  cursor: grab;
  touch-action: none;
  border-style: dashed;
  border-color: rgba(24, 24, 27, 0.35);
  background: rgba(24, 24, 27, 0.025);
}

body.move-mode .span-box:hover {
  border-color: #18181b !important;
  background: rgba(24, 24, 27, 0.08) !important;
}

body.move-mode .span-box.selected {
  border: 1.5px solid #18181b !important;
  background: rgba(24, 24, 27, 0.09) !important;
}

body.move-mode .span-box.is-dragging-origin {
  opacity: 0.32;
  border-style: dashed !important;
  cursor: grabbing;
}

.span-box.snap-target {
  border-color: #db2777 !important;
  background: rgba(219, 39, 119, 0.07) !important;
}

/* Photoshop-style Smart Alignment Guides Layer */
.snap-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 25;
  overflow: hidden;
}

.drag-ghost {
  position: absolute;
  border: 1.5px solid #1d4ed8;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 6px 18px rgba(24, 24, 27, 0.18);
  border-radius: 2px;
  display: flex;
  align-items: center;
  padding: 0 2px;
  white-space: nowrap;
  overflow: hidden;
  color: var(--ink);
  font-weight: 500;
}

.drag-ghost-text {
  line-height: 1;
  pointer-events: none;
}

.snap-line-v,
.snap-line-h {
  position: absolute;
  background: #db2777;
  pointer-events: none;
}

.snap-line-v {
  width: 1px;
}

.snap-line-h {
  height: 1px;
}

.snap-badge {
  position: absolute;
  background: #db2777;
  color: #ffffff;
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 600;
  line-height: 1;
  padding: 3px 5px;
  border-radius: 3px;
  white-space: nowrap;
}

/* Inline Popover Editor */
.inline-popover {
  position: absolute;
  z-index: 30;
  min-width: 320px;
  max-width: min(820px, calc(100% - 16px));
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-top: 3px solid var(--accent);
  border-radius: var(--radius-lg);
  padding: 12px 14px;
  box-shadow: 0 12px 32px rgba(24, 24, 27, 0.18);
}

.inline-popover[hidden] {
  display: none;
}

.inline-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--ink-muted);
  margin-bottom: 8px;
  cursor: grab;
  touch-action: none;
  user-select: none;
}

.inline-meta:active {
  cursor: grabbing;
}

.lock-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--lock);
  flex-shrink: 0;
}

.inline-font-label {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--ink);
  font-weight: 600;
}

.inline-hint {
  margin-left: auto;
  font-size: 11px;
  color: var(--ink-muted);
}

#inlineInput {
  width: 100%;
  min-height: 64px;
  max-height: 240px;
  background: var(--chrome);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  font-family: inherit;
  font-size: 15px;
  line-height: 1.45;
  resize: vertical;
  overflow-y: auto;
}

#inlineInput:focus {
  outline: none;
  background: var(--surface);
  border-color: var(--accent);
}

.inline-footer {
  margin-top: 9px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.inline-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.inline-subset-status {
  font-size: 12px;
  min-height: 16px;
  line-height: 1.35;
}

/* Inspector Sidebar */
.inspector {
  background: var(--chrome);
  border-left: 1px solid var(--border);
  padding: 18px;
  overflow-y: auto;
}

.inspector-section[hidden] {
  display: none;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 14px;
}

.panel-head h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.panel-tag {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-muted);
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  padding: 2px 7px;
  border-radius: var(--radius-sm);
}

.inspector h3 {
  margin: 20px 0 8px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-muted);
}

.kv-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.kv {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 9px 11px;
  border-radius: var(--radius-md);
}

.kv span {
  display: block;
  font-size: 11.5px;
  color: var(--ink-muted);
  margin-bottom: 2px;
}

.kv strong {
  font-family: var(--mono);
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}

.font-pill-list,
.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.font-pill-list li {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 7px 10px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink);
  word-break: break-word;
}

.history-list li {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 7px 10px;
  font-size: 12px;
  color: var(--ink-muted);
}

.history-list li strong {
  display: block;
  color: var(--ink);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.move-banner {
  margin: 16px 0 0;
  padding: 11px 12px;
  border-radius: var(--radius-md);
  background: #18181b;
  color: #fafaf8;
  font-size: 12.5px;
  line-height: 1.48;
}

.move-banner[hidden] {
  display: none;
}

.move-banner strong {
  display: block;
  margin-bottom: 4px;
  font-size: 12.5px;
}

.move-banner code {
  font-family: var(--mono);
  font-size: 11.5px;
  background: rgba(255, 255, 255, 0.14);
  padding: 1px 5px;
  border-radius: 3px;
}

.tip-box {
  margin: 18px 0 0;
  padding: 11px 12px;
  border-radius: var(--radius-md);
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  color: var(--ink-muted);
  font-size: 12.5px;
  line-height: 1.5;
}

.font-lock-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--lock);
  border-radius: var(--radius-md);
  padding: 11px 12px;
  margin-bottom: 14px;
}

.font-lock-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.lock-badge {
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--lock);
  background: var(--lock-soft);
  padding: 2px 7px;
  border-radius: var(--radius-sm);
}

.font-size-pill {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
}

.font-name-main {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 8px;
  word-break: break-word;
  color: var(--ink);
}

.font-sub-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
}

.color-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--mono);
}

.color-chip i {
  width: 13px;
  height: 13px;
  border-radius: 2px;
  border: 1px solid var(--border-strong);
  display: inline-block;
}

.subset-pill {
  color: var(--ink-muted);
  font-size: 11.5px;
}

.field-label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-muted);
  margin-bottom: 6px;
}

#inspTextarea {
  width: 100%;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 11px;
  font-family: inherit;
  font-size: 14.5px;
  line-height: 1.45;
  resize: vertical;
}

#inspTextarea:focus {
  outline: none;
  border-color: var(--accent);
}

.subset-live {
  margin-top: 6px;
  margin-bottom: 14px;
  font-size: 12px;
  line-height: 1.4;
}

.status-ok {
  color: var(--lock);
  font-weight: 500;
}

.status-warn {
  color: var(--warn);
  font-weight: 500;
}

.status-info {
  color: var(--accent);
  font-weight: 500;
}

.anchor-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.anchor-row .field-label {
  margin: 0;
}

.seg-control {
  display: inline-flex;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 2px;
}

.seg {
  border: none;
  background: transparent;
  color: var(--ink-muted);
  font-family: inherit;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
}

.seg.active {
  background: var(--surface);
  color: var(--ink);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(24, 24, 27, 0.08);
}

.original-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 9px 10px;
  font-size: 12px;
  margin-bottom: 14px;
  word-break: break-word;
}

.original-box span {
  display: block;
  color: var(--ink-muted);
  font-size: 11px;
  margin-bottom: 3px;
}

.original-box code {
  font-family: var(--mono);
  color: var(--ink);
}

.action-row {
  display: flex;
  gap: 8px;
}

.action-row .btn-primary {
  flex: 1;
}

/* Global Drop Overlay */
.drop-overlay {
  position: fixed;
  inset: 0;
  background: rgba(247, 246, 242, 0.88);
  display: grid;
  place-items: center;
  z-index: 90;
}

.drop-overlay[hidden] {
  display: none;
}

.drop-overlay-box {
  background: var(--surface);
  border: 2px dashed var(--accent);
  border-radius: var(--radius-lg);
  padding: 28px 42px;
  font-size: 16px;
  font-weight: 600;
  color: var(--ink);
}

/* Status Toast */
.toast {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.12);
  padding: 9px 16px;
  border-radius: var(--radius-md);
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(24, 24, 27, 0.22);
  z-index: 100;
  max-width: calc(100vw - 24px);
}

.toast[hidden] {
  display: none;
}

.toast.error {
  background: #7f1d1d;
  border-color: #991b1b;
}

.toast.ok {
  background: #134e4a;
  border-color: #115e59;
}

/* Responsive Breakpoints */
@media (max-width: 1080px) {
  .topbar {
    flex-wrap: wrap;
    padding: 8px 12px;
  }

  .toolbar-group {
    width: 100%;
    justify-content: flex-start;
  }

  .editor-shell {
    grid-template-columns: 1fr 296px;
  }

  .drop-layout {
    gap: 28px;
  }
}

@media (max-width: 820px) {
  body {
    overflow: auto;
  }

  .workspace {
    min-height: calc(100dvh - 54px);
  }

  .drop-screen {
    padding: 24px 16px;
    align-items: flex-start;
  }

  .drop-layout {
    grid-template-columns: 1fr;
    gap: 24px;
  }

  .spec-item {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .editor-shell {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(52dvh, 1fr) auto;
    overflow: visible;
  }

  .canvas-scroll {
    padding: 16px 12px;
  }

  .inspector {
    border-left: none;
    border-top: 1px solid var(--border);
  }

  .inline-popover {
    min-width: 0;
    width: calc(100% - 16px) !important;
    left: 8px !important;
  }

  .inline-hint {
    display: none;
  }

  .file-pill {
    max-width: 130px;
  }

  .divider {
    display: none;
  }
}
