:root {
  --bg: #f4f6fb;
  --panel: #fff;
  --ink: #101828;
  --muted: #667085;
  --brand: #3b5bdb;
  --brand-2: #2f49b2;
  --border: #e4e7ec;
  --shadow: 0 8px 24px rgba(16, 24, 40, .08);
  --sidebar-w: 290px;
  --input-bg: #f8fafc;
  --hover-bg: #eef2ff;
  --modal-bg: rgba(16, 24, 40, .55);
  --modal-body-bg: #eef2fa;
  --kbd-bg: #eef2ff;
  --kbd-border: #dbe3ff;
  --kbd-color: #2f49b2;
  --page-bg: #ffffff;
}

[data-theme="dark"] {
  --bg: #0d1117;
  --panel: #161b22;
  --ink: #e6edf3;
  --muted: #8b949e;
  --brand: #5b7ce8;
  --brand-2: #7d99ec;
  --border: #30363d;
  --shadow: 0 8px 24px rgba(0, 0, 0, .5);
  --input-bg: #21262d;
  --hover-bg: #1f2937;
  --modal-bg: rgba(0, 0, 0, .75);
  --modal-body-bg: #0d1117;
  --kbd-bg: #21262d;
  --kbd-border: #30363d;
  --kbd-color: #7d99ec;
  --page-bg: #ffffff;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  display: flex;
  height: 100vh;
  overflow: hidden;
  transition: background .2s, color .2s;
}

/* Sidebar */
aside {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

aside .brand {
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}

aside .brand h1 {
  font-size: 18px;
  margin: 0;
  font-weight: 800;
  letter-spacing: -.01em;
}

aside .brand h1 span {
  color: var(--brand);
}

aside .brand .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 0 4px rgba(34, 197, 94, .15);
}

.side-section {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.side-section h2 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  margin: 0 0 10px;
  font-weight: 700;
}

.side-section p {
  font-size: 13px;
  line-height: 1.6;
  color: var(--ink);
  margin: 0 0 10px;
}

.side-section p:last-child {
  margin-bottom: 0;
}

.step {
  display: flex;
  gap: 10px;
  padding: 8px 0;
  font-size: 13px;
  line-height: 1.5;
}

.step .n {
  flex: 0 0 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
}

.step .t {
  flex: 1;
}

.step .t b {
  display: block;
  margin-bottom: 2px;
}

.step .t small {
  color: var(--muted);
  font-size: 12px;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 13px;
  padding: 4px 0;
}

.stat-row .k {
  color: var(--muted);
}

.stat-row .v {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* Main Layout */
main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

header.topbar {
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  box-shadow: var(--shadow);
  z-index: 20;
}

header .left-side {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex-wrap: wrap;
}

header .center-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
}

header .right-side {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
}

header .file-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

header .file-chip.hidden {
  display: none;
}

header .info {
  font-size: 12px;
  color: var(--muted);
}

/* Buttons */
button,
label.btn {
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 14px;
  transition: .15s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

button:hover:not(:disabled),
label.btn:hover {
  border-color: var(--brand);
  color: var(--brand);
}

button.primary {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
  box-shadow: 0 2px 6px rgba(59, 91, 219, .25);
}

button.primary:hover:not(:disabled) {
  background: var(--brand-2);
  color: #fff;
}

button.ghost {
  background: transparent;
}

button:disabled {
  opacity: .5;
  cursor: not-allowed;
  box-shadow: none;
}

#file {
  display: none;
}

.theme-toggle {
  width: 36px;
  height: 36px;
  padding: 0;
  justify-content: center;
  background: var(--input-bg);
}

.theme-toggle svg {
  width: 16px;
  height: 16px;
}

.theme-toggle .icon-sun {
  display: none;
}

.theme-toggle .icon-moon {
  display: block;
}

[data-theme="dark"] .theme-toggle .icon-sun {
  display: block;
}

[data-theme="dark"] .theme-toggle .icon-moon {
  display: none;
}

/* Viewport & Pages */
.viewport {
  flex: 1;
  overflow: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
}

:root .viewport {
  background: radial-gradient(circle at 25% 10%, #fff, #eef2fa 60%);
}

[data-theme="dark"] .viewport {
  background: radial-gradient(circle at 25% 10%, #161b22, #0d1117 60%);
}

#pages {
  display: flex;
  flex-direction: column;
  gap: 24px;
  align-items: center;
}

.drop {
  width: 100%;
  max-width: 640px;
  border: 2px dashed var(--border);
  border-radius: 16px;
  padding: 60px 24px;
  text-align: center;
  background: var(--panel);
  cursor: pointer;
  transition: .2s;
  margin: auto;
}

.drop:hover,
.drop.over {
  border-color: var(--brand);
  background: var(--hover-bg);
}

.drop h2 {
  margin: 0 0 8px;
}

.drop p {
  color: var(--muted);
  margin: 0;
}

.drop .seo-hint {
  margin-top: 20px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.6;
  max-width: 520px;
  margin-left: auto;
  margin-right: auto;
}

.page {
  position: relative;
  background: var(--page-bg);
  box-shadow: var(--shadow);
  border-radius: 8px;
  overflow: hidden;
}

.page canvas {
  display: block;
}

/* Editable text */
.txt {
  position: absolute;
  margin: 0;
  padding: 1px 2px;
  color: transparent;
  background: transparent;
  border: 1px solid transparent;
  outline: none;
  white-space: pre;
  overflow: visible;
  font-family: Arial, Helvetica, sans-serif;
  z-index: 5;
  caret-color: #000;
  box-sizing: border-box;
}

.txt:hover {
  border-color: rgba(59, 91, 219, .4);
  background: rgba(59, 91, 219, .05);
}

.txt:focus {
  color: transparent;
  background: rgba(59, 91, 219, .08);
  border-color: var(--brand);
  box-shadow: 0 0 0 2px rgba(59, 91, 219, .18);
  z-index: 9999;
}

.txt.changed {
  color: #000;
  background: #fff;
  border-color: transparent;
}

.txt.changed:hover {
  border-color: rgba(59, 91, 219, .35);
}

.txt.changed:focus {
  color: #000;
  background: #fff;
  border-color: var(--brand);
}

/* Toolbar */
.align-toolbar {
  position: fixed;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px;
  display: none;
  gap: 2px;
  box-shadow: 0 10px 30px rgba(16, 24, 40, .25);
  z-index: 100000;
  user-select: none;
  align-items: center;
}

.align-toolbar.show {
  display: flex;
}

.align-toolbar button {
  padding: 7px;
  border: none;
  background: transparent;
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0;
  min-width: 32px;
  min-height: 32px;
}

.align-toolbar button:hover {
  background: var(--hover-bg);
  color: var(--brand);
}

.align-toolbar button.active {
  background: var(--brand);
  color: #fff;
}

.align-toolbar svg {
  width: 16px;
  height: 16px;
  display: block;
}

.align-toolbar .sep {
  width: 1px;
  background: var(--border);
  margin: 4px 3px;
  align-self: stretch;
}

.font-picker {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 0 6px 0 4px;
}

.font-picker span {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  font-weight: 600;
}

.font-picker select {
  font: inherit;
  font-size: 12px;
  padding: 5px 6px;
  background: var(--input-bg);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
}

.font-picker select:focus {
  outline: none;
  border-color: var(--brand);
}

/* Modals & Status */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.status {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: #111827;
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13px;
  opacity: 0;
  transition: .2s;
  pointer-events: none;
  z-index: 99999;
  max-width: 90vw;
  text-align: center;
}

.status.show {
  opacity: 1;
}

.modal {
  position: fixed;
  inset: 0;
  background: var(--modal-bg);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 99998;
  padding: 24px;
  backdrop-filter: blur(3px);
}

.modal.show {
  display: flex;
}

.modal-card {
  background: var(--panel);
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .4);
  width: min(1000px, 100%);
  height: min(90vh, 900px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
}

.modal-head h3 {
  margin: 0;
  font-size: 15px;
}

.modal-head .meta {
  font-size: 12px;
  color: var(--muted);
}

.modal-head .spacer {
  flex: 1;
}

.modal-body {
  flex: 1;
  background: var(--modal-body-bg);
}

.modal-body iframe {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
  background: #fff;
}

.modal-foot {
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  align-items: center;
}

.modal-foot .spacer {
  flex: 1;
}

.modal-foot small {
  color: var(--muted);
  font-size: 12px;
}

/* Merge Modal */
.merge-modal {
  position: fixed;
  inset: 0;
  background: var(--modal-bg);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 99999;
  padding: 24px;
  backdrop-filter: blur(4px);
}

.merge-modal.show {
  display: flex;
}

.merge-card {
  background: var(--panel);
  border-radius: 14px;
  box-shadow: 0 25px 70px rgba(0, 0, 0, .35);
  width: min(640px, 100%);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.merge-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.merge-head h2 {
  margin: 0;
  font-size: 16px;
}

.merge-head .merge-meta {
  font-size: 12px;
  color: var(--muted);
}

.merge-head .spacer {
  flex: 1;
}

.merge-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

.merge-drop {
  border: 2px dashed var(--border);
  border-radius: 12px;
  padding: 32px 20px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  transition: border-color .15s, background .15s;
  margin-bottom: 16px;
}

.merge-drop.over {
  border-color: var(--brand);
  background: var(--hover-bg);
}

.merge-drop p {
  margin: 0;
}

.merge-link {
  color: var(--brand);
  cursor: pointer;
  text-decoration: underline;
  font-weight: 600;
}

.merge-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.merge-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
}

.merge-item .grip {
  cursor: grab;
  color: var(--muted);
  padding: 0 4px;
  font-size: 16px;
  line-height: 1;
  user-select: none;
}

.merge-item .grip:active {
  cursor: grabbing;
}

.merge-item .name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.merge-item .size {
  font-size: 11px;
  color: var(--muted);
  margin-left: 4px;
  white-space: nowrap;
}

.merge-item .actions {
  display: flex;
  gap: 2px;
}

.merge-item .actions button {
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
  font-size: 14px;
  line-height: 1;
}

.merge-item .actions button:hover {
  background: var(--hover-bg);
  color: var(--brand);
}

.merge-item .actions button.danger:hover {
  color: #dc2626;
}

.merge-foot {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
}

.merge-foot .spacer {
  flex: 1;
}

/* Footer */
.side-footer {
  margin-top: auto;
  padding: 16px 20px 20px;
  border-top: 1px solid var(--border);
  text-align: center;
}

.side-footer .built-by {
  font-size: 11px;
  color: var(--muted);
  margin: 0 0 10px;
}

.side-footer .built-by b {
  color: var(--ink);
}

.side-footer .socials {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.side-footer .socials a {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  border: 1px solid var(--border);
  transition: .15s;
  text-decoration: none;
}

.side-footer .socials a:hover {
  color: #fff;
  background: var(--brand);
  border-color: var(--brand);
}

.side-footer .socials a svg {
  width: 16px;
  height: 16px;
}

/* Custom Logo Styling */
.side-footer .socials a img.footlink-logo {
  width: 16px;
  height: 16px;
  object-fit: contain;
  filter: grayscale(1) opacity(0.7);
  transition: .15s;
}

.side-footer .socials a:hover img.footlink-logo {
  filter: grayscale(0) opacity(1);
}

.side-footer .copy {
  margin-top: 12px;
  font-size: 10px;
  color: var(--muted);
}

/* Mobile */
@media (max-width: 780px) {
  body {
    flex-direction: column;
    height: auto;
    overflow: auto;
  }

  aside {
    width: 100%;
    flex: 0 0 auto;
  }

  main {
    overflow: visible;
  }

  header.topbar {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  header .left-side,
  header .center-actions,
  header .right-side {
    justify-content: center;
  }
}