* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --ink: #08142b;
  --muted: #53657f;
  --line: #d9e2ee;
  --line-dark: #63748e;
  --panel: #eef3f9;
  --paper: #ffffff;
  --control: #ffffff;
  --accent: #0b1530;
  --accent-hover: #17233f;
  --trace: #9cadc3;
  --radius: 8px;
  --shadow-card: 0 1px 3px rgba(15, 33, 60, 0.08);
  --shadow-paper: 0 1px 0 rgba(15, 33, 60, 0.04);
}

html,
body {
  min-height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
}

body {
  font-family: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", "Helvetica Neue", Arial, sans-serif;
  background: var(--panel);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

button,
input,
select,
textarea {
  font: inherit;
}

.topbar {
  height: 52px;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 42px;
  padding: 0 22px;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
  z-index: 50;
}

.topbar-left {
  flex: 0 0 auto;
}

.topbar-brand {
  display: inline-flex;
  align-items: center;
  height: 42px;
  padding: 2px 0;
  background: #fff;
  text-decoration: none;
}

.topbar-brand img {
  display: block;
  width: auto;
  height: 34px;
  object-fit: contain;
}

.topbar-nav {
  flex: 0 1 auto;
  display: flex;
  align-items: center;
  gap: 26px;
  height: 100%;
}

.nav-menu {
  position: relative;
  height: 100%;
  display: flex;
  align-items: center;
}

.panel-tab,
.nav-link,
.nav-trigger {
  border: 0;
  background: transparent;
  color: #233a5f;
  cursor: pointer;
  white-space: nowrap;
  font-size: 14px;
}

.nav-trigger,
.nav-link {
  min-height: 34px;
  padding: 0 11px;
  border-radius: 8px;
}

.panel-tab.active,
.nav-trigger:hover,
.nav-link:hover,
.nav-menu:hover .nav-trigger {
  background: #eef3f8;
  color: #07142e;
}

.nav-trigger span {
  margin-left: 4px;
  color: #6b7b95;
}

.nav-dropdown {
  position: absolute;
  left: 0;
  top: 50px;
  width: 318px;
  display: none;
  padding: 8px 0;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 0 0 10px 10px;
  box-shadow: 0 12px 28px rgba(19, 38, 67, 0.12);
}

.nav-menu:hover .nav-dropdown {
  display: block;
}

.nav-dropdown button {
  width: 100%;
  border: 0;
  background: transparent;
  display: block;
  padding: 13px 20px;
  text-align: left;
  cursor: pointer;
}

.nav-dropdown button:hover {
  background: #f5f8fc;
}

.nav-dropdown strong {
  display: block;
  font-size: 14px;
  color: var(--ink);
  margin-bottom: 8px;
}

.nav-dropdown small {
  display: block;
  font-size: 13px;
  color: #506889;
}

.main-layout {
  flex: 1;
  min-height: calc(100vh - 52px);
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: 18px;
  overflow: visible;
  padding: 18px 16px 28px;
}

.preview-panel {
  width: 794px;
  max-width: calc(100vw - 330px);
  overflow: visible;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 0;
  background: var(--panel);
  flex: 0 1 794px;
}

.paper-stage {
  width: min(794px, 100%);
  min-height: 1123px;
  background: var(--paper);
  box-shadow: var(--shadow-paper);
  line-height: 0;
  position: relative;
}

.paper-stage canvas {
  display: block;
  width: 100%;
  height: auto;
}

.paper-stage.paged-preview canvas {
  background-color: var(--panel);
}

.control-panel {
  width: 260px;
  flex: 0 0 260px;
  background: var(--panel);
  overflow-y: auto;
  padding: 0 0 28px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  height: calc(100vh - 98px);
  max-height: calc(100vh - 98px);
  position: sticky;
  top: 70px;
}

.panel-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.export-menu-wrap {
  position: relative;
}

.btn-topbar {
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 1px;
  transition: background 0.18s ease, border-color 0.18s ease, transform 0.18s ease;
}

.btn-topbar:hover {
  transform: translateY(-1px);
}

.btn-export {
  width: 100%;
  background: #fff;
  color: var(--ink);
}

.btn-export:hover {
  border-color: #c7d2e2;
  background: #f8fbff;
}

.btn-print {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.export-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 132px;
  display: none;
  padding: 6px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 10px 24px rgba(19, 38, 67, 0.14);
  z-index: 20;
}

.export-menu.open {
  display: block;
}

.export-menu button {
  width: 100%;
  min-height: 34px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  text-align: left;
  padding: 0 10px;
  cursor: pointer;
}

.export-menu button:hover {
  background: #f1f5fb;
}

.btn-print:hover {
  background: var(--accent-hover);
}

.btn-icon {
  flex-shrink: 0;
}

.panel-content {
  display: none;
  flex-direction: column;
  gap: 12px;
}

.panel-content.active {
  display: flex;
}

.ctrl-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  background: var(--control);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
}

#panel-chinese .ctrl-group {
  gap: 0;
}

#panel-chinese .ctrl-card-content {
  padding: 0;
  overflow: visible;
  background: transparent;
  border: 0;
  box-shadow: none;
}

.cn-input-title {
  display: block;
  margin: 0 0 8px;
  color: #07142e;
  font-size: 16px;
  font-weight: 800;
  text-align: center;
}

.cn-input-hint {
  display: none;
  margin: -2px 0 10px;
  color: #516078;
  font-size: 13px;
  line-height: 1.45;
  text-align: center;
}

.cn-input-hint.active {
  display: block;
}

#panel-chinese .ctrl-textarea {
  min-height: 94px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow-card);
}

#panel-chinese .ctrl-label,
#panel-chinese .ctrl-label-row {
  min-height: 38px;
  border-bottom: 1px solid var(--line);
}

#panel-chinese .ctrl-label:last-child,
#panel-chinese .ctrl-label-row:last-child {
  border-bottom: 0;
}

#panel-chinese .ctrl-label {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

#panel-chinese .ctrl-label-row {
  display: grid;
  grid-template-columns: 64px minmax(64px, 1fr) 54px;
  gap: 8px;
}

#panel-chinese .ctrl-label-row .ctrl-val {
  white-space: nowrap;
  text-align: right;
}

#panel-chinese .cn-layout-card,
#panel-chinese .cn-font-card,
#panel-chinese .cn-color-card {
  padding-top: 0;
  padding-bottom: 0;
}

#panel-chinese .cn-options-card {
  padding-top: 0;
  padding-bottom: 0;
}

#panel-chinese .ctrl-select {
  min-width: 92px;
}

#panel-chinese .ctrl-slider {
  min-width: 0;
}

.hidden-color-value {
  display: none;
}

.ctrl-label,
.ctrl-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 24px;
  font-size: 14px;
  font-weight: 500;
  color: #182842;
}

.ctrl-val,
.color-hex {
  font-size: 13px;
  color: #14223a;
  font-weight: 500;
}

.margin-control {
  gap: 8px;
}

.margin-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 24px;
  font-size: 14px;
  cursor: pointer;
  user-select: none;
}

.margin-summary::after {
  content: "⌄";
  margin-left: 6px;
  color: #7b8aa2;
  font-size: 13px;
}

.margin-control.open .margin-summary::after {
  content: "⌃";
}

.margin-control:not(.open) .ctrl-label-row,
.margin-control:not(.open) .margin-actions {
  display: none !important;
}

.margin-control .ctrl-label-row {
  display: grid;
  grid-template-columns: 54px minmax(80px, 1fr) 42px;
  gap: 8px;
  align-items: center;
}

.margin-control .ctrl-val {
  text-align: right;
  color: #5b6f91;
}

.margin-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding-top: 4px;
}

.margin-action {
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-size: 14px;
}

.margin-action.confirm {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.ctrl-textarea {
  width: 100%;
  min-height: 96px;
  padding: 10px 12px;
  border: 0;
  resize: vertical;
  outline: none;
  background: transparent;
  color: var(--ink);
  cursor: text;
  font-size: 15px;
  line-height: 1.65;
}

.ctrl-textarea::placeholder {
  color: #9aa8ba;
}

.input-dialog-backdrop {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(8, 20, 43, 0.48);
}

.input-dialog-backdrop.open {
  display: flex;
}

.input-dialog {
  position: relative;
  width: min(520px, 100%);
  padding: 24px;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 20px 60px rgba(8, 20, 43, 0.24);
}

.input-dialog h2 {
  margin: 0 32px 8px 0;
  color: var(--ink);
  font-size: 20px;
  line-height: 1.3;
}

.input-dialog p {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.input-dialog-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #5b6678;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}

.input-dialog-close:hover {
  background: #f1f5fa;
  color: var(--ink);
}

.input-dialog-textarea {
  width: 100%;
  min-height: 240px;
  padding: 12px;
  border: 1px solid #aebbd0;
  border-radius: 8px;
  outline: none;
  resize: vertical;
  color: var(--ink);
  background: #fff;
  font-size: 15px;
  line-height: 1.6;
  box-shadow: inset 0 0 0 2px rgba(80, 112, 154, 0.12);
}

.input-dialog-textarea:focus {
  border-color: #7f93ad;
  box-shadow: 0 0 0 3px rgba(127, 147, 173, 0.22);
}

.stroke-dialog-editor {
  display: none;
  flex-direction: column;
  gap: 10px;
}

.stroke-dialog-editor.active {
  display: flex;
}

.stroke-dialog-row {
  display: grid;
  grid-template-columns: 144px minmax(0, 1fr) 36px;
  gap: 8px;
  align-items: center;
}

.stroke-dialog-select,
.stroke-dialog-input {
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  outline: none;
  font-size: 14px;
}

.stroke-dialog-select {
  padding: 0 10px;
}

.stroke-dialog-input {
  padding: 0 12px;
}

.stroke-dialog-select:focus,
.stroke-dialog-input:focus {
  border-color: #9aaabe;
  box-shadow: 0 0 0 3px rgba(127, 147, 173, 0.16);
}

.stroke-dialog-remove,
.stroke-dialog-add {
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-size: 14px;
}

.stroke-dialog-remove {
  width: 36px;
  color: #516078;
}

.stroke-dialog-add {
  align-self: flex-start;
  padding: 0 12px;
}

.stroke-dialog-remove:hover,
.stroke-dialog-add:hover {
  background: #f6f8fb;
}

.input-dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

.input-dialog-btn {
  min-width: 66px;
  height: 36px;
  padding: 0 18px;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  cursor: pointer;
}

.input-dialog-confirm {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.input-dialog-confirm:hover {
  background: var(--accent-hover);
}

.input-dialog-cancel:hover {
  background: #f6f8fb;
}

.ctrl-select {
  border: 0;
  min-width: 98px;
  padding: 2px 22px 2px 8px;
  outline: none;
  text-align: left;
  text-align-last: left;
  color: #0f1c32;
  background-color: transparent;
  cursor: pointer;
}

.ctrl-select option {
  text-align: left;
}

.control-hidden {
  display: none;
}

.ctrl-section-title {
  margin: 2px 0 8px;
  text-align: center;
  font-size: 16px;
  font-weight: 700;
  color: var(--ink);
}

.segmented-control {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(64px, 1fr));
  gap: 6px;
  margin-top: 10px;
}

.segmented-control button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #f8fbff;
  color: #233a5f;
  cursor: pointer;
  font-size: 13px;
}

.segmented-control button.active {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.ctrl-slider {
  width: 100%;
  height: 4px;
  accent-color: var(--accent);
  cursor: pointer;
}

.toggle-list {
  display: flex;
  flex-direction: column;
}

.toggle-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 38px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}

.toggle-item:last-child {
  border-bottom: 0;
}

.toggle-text {
  font-size: 14px;
  color: #182842;
}

.switch-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.switch-wrap input {
  position: absolute;
  opacity: 0;
}

.switch-track {
  position: relative;
  display: block;
  width: 34px;
  height: 20px;
  border-radius: 999px;
  background: #e5ebf3;
  transition: background 0.2s ease;
}

.switch-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(8, 20, 43, 0.2);
  transition: transform 0.2s ease;
}

.switch-wrap input:checked + .switch-track {
  background: var(--accent);
}

.switch-wrap input:checked + .switch-track::after {
  transform: translateX(14px);
}

.color-pick-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 32px;
}

.ctrl-color {
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 5px;
  padding: 0;
  overflow: hidden;
  cursor: pointer;
  background: transparent;
}

.panel-footer {
  margin-top: auto;
  padding: 10px 4px 0;
  text-align: center;
}

.footer-logo {
  display: inline-block;
  width: auto;
  height: 34px;
  object-fit: contain;
  background: #fff;
}

.control-panel::-webkit-scrollbar,
.preview-panel::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

.control-panel::-webkit-scrollbar-thumb,
.preview-panel::-webkit-scrollbar-thumb {
  background: #b9c5d4;
  border-radius: 999px;
}

@media print {
  html,
  body {
    background: #fff;
    display: block;
    overflow: visible;
  }

  body > *:not(#__print_container__) {
    display: none !important;
  }

  #__print_container__ {
    display: block !important;
    position: static !important;
    left: auto !important;
    top: auto !important;
    width: 210mm !important;
    background: #fff !important;
  }

  .__print_page__ {
    width: 210mm;
    height: 297mm;
    margin: 0;
    padding: 0;
    overflow: hidden;
    break-after: page;
    page-break-after: always;
  }

  .__print_page__:last-child {
    break-after: auto;
    page-break-after: auto;
  }

  #__print_container__ img {
    display: block !important;
    width: 210mm !important;
    height: 297mm !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  @page { size: A4; margin: 0; }
}

@media (max-width: 900px) {
  html,
  body {
    overflow: auto;
  }

  .topbar {
    height: auto;
    flex-wrap: wrap;
    justify-content: flex-start;
    gap: 8px 14px;
    padding: 10px 14px;
  }

  .topbar-nav {
    flex: 1 1 100%;
    max-width: 100%;
    overflow-x: auto;
    gap: 8px;
    padding-bottom: 2px;
  }

  .nav-dropdown {
    display: none !important;
  }

  .main-layout {
    display: flex;
    flex-direction: column;
    height: auto;
    overflow: visible;
    padding: 12px;
    gap: 12px;
  }

  .preview-panel {
    width: 100%;
    max-width: 100%;
    height: 62vh;
  }

  .control-panel {
    width: 100%;
    flex: none;
    height: auto;
    max-height: none;
    display: block;
    padding-bottom: 18px;
  }

  .panel-actions,
  .panel-content.active {
    max-width: 520px;
    margin-left: auto;
    margin-right: auto;
  }
}
