:root {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  color: #22283a;
  background: #f5f6f8;
  font-synthesis: none;
}

* { box-sizing: border-box; }
*[hidden] { display: none !important; }
body { min-width: 320px; margin: 0; }
button, input, textarea { font: inherit; }
button { cursor: pointer; }
h1, h2, h3, p { margin: 0; }
.workspace { min-height: 100vh; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 16px clamp(18px, 3vw, 48px);
  background: rgba(255, 255, 255, .94);
  box-shadow: 0 1px 0 rgba(35, 45, 70, .055);
  backdrop-filter: blur(16px);
}
.topbar-title { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-square { width: 38px; height: 38px; display: grid; place-items: center; flex: none; }
.brand-square img { width: 32px; height: 32px; object-fit: contain; }
h1 { font-size: 17px; font-weight: 700; line-height: 1.3; letter-spacing: .015em; white-space: nowrap; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.button {
  min-height: 40px;
  padding: 9px 16px;
  border: 0;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 650;
  white-space: nowrap;
  transition: background .2s ease, color .2s ease, transform .2s ease, box-shadow .2s ease;
}
.button:hover, .upload-button:hover { transform: translateY(-1px); }
.button:disabled { opacity: .55; cursor: wait; transform: none; }
.button-quiet { background: #f2f3f6; color: #5e6677; }
.button-quiet:hover { background: #e9ebf0; }
.button-primary { background: #2f367f; color: #fff; box-shadow: 0 7px 18px rgba(47, 54, 127, .16); }
.button-primary:hover { background: #252b70; box-shadow: 0 9px 22px rgba(47, 54, 127, .2); }

.main-grid {
  display: grid;
  grid-template-columns: minmax(350px, 410px) minmax(0, 1fr);
  gap: 24px;
  max-width: 1600px;
  margin: 0 auto;
  padding: 26px;
}
.editor-panel, .preview-panel {
  min-width: 0;
  background: #fff;
  border-radius: 20px;
  box-shadow: 0 16px 50px rgba(30, 39, 70, .055);
}
.editor-panel { align-self: start; padding: 27px 28px 30px; }
.panel-heading { padding: 0 0 3px; }
h2 { font-size: 20px; font-weight: 700; line-height: 1.35; letter-spacing: .01em; }

fieldset { min-width: 0; margin: 0; padding: 26px 0 0; border: 0; }
fieldset + fieldset { margin-top: 10px; }
legend { padding: 0; color: #7d869a; font-size: 13px; font-weight: 700; letter-spacing: .045em; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 17px 12px; margin-top: 17px; }
label { display: block; color: #657084; font-size: 12px; font-weight: 600; }
label.wide { grid-column: 1 / -1; }
input:not([type=file]):not([type=range]):not([type=checkbox]), textarea {
  display: block;
  width: 100%;
  min-height: 44px;
  margin-top: 8px;
  padding: 11px 13px;
  border: 0;
  border-radius: 10px;
  outline: none;
  background: #f5f6f8;
  color: #252b3c;
  font-size: 14px;
  font-weight: 400;
  line-height: 1.45;
  transition: background .2s ease, box-shadow .2s ease;
}
input:not([type=file]):not([type=range]):not([type=checkbox]):hover, textarea:hover { background: #eff1f5; }
input:not([type=file]):not([type=range]):not([type=checkbox]):focus, textarea:focus {
  background: #fff;
  box-shadow: 0 0 0 2px rgba(53, 66, 147, .24);
}
textarea { min-height: 76px; resize: vertical; }
.option-toggle { display: flex; align-items: center; gap: 11px; width: fit-content; margin: -1px 0 1px; color: #39435f; cursor: pointer; font-size: 13px; font-weight: 600; }
.option-toggle input[type=checkbox] { appearance: none; display: grid; place-items: center; width: 20px; height: 20px; margin: 0; border: 1px solid #cbd1e0; border-radius: 6px; background: #fff; cursor: pointer; transition: background .18s ease, border-color .18s ease, box-shadow .18s ease; }
.option-toggle input[type=checkbox]::after { content: ''; width: 8px; height: 4px; border: solid #fff; border-width: 0 0 2px 2px; transform: translateY(-1px) rotate(-45deg) scale(.4); opacity: 0; transition: transform .18s ease, opacity .18s ease; }
.option-toggle input[type=checkbox]:checked { border-color: #333b82; background: #333b82; }
.option-toggle input[type=checkbox]:checked::after { transform: translateY(-1px) rotate(-45deg) scale(1); opacity: 1; }
.option-toggle input[type=checkbox]:focus-visible { outline: 2px solid #5864b2; outline-offset: 3px; }
.field-label-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 17px; }
.field-with-action > input { margin-top: 8px; }
.field-label-row .text-button { font-size: 11px; }
.field-with-action input.auto-appear { animation: title-input-arrive .55s cubic-bezier(.2, .8, .2, 1) both; }
@keyframes title-input-arrive {
  0% { opacity: .35; transform: translateY(5px); background: #e6ebfb; }
  60% { opacity: 1; transform: translateY(0); background: #edf0fb; }
  100% { opacity: 1; transform: translateY(0); background: #f5f6f8; }
}

.qr-control { display: flex; gap: 14px; align-items: center; margin-top: 17px; padding: 14px; border-radius: 14px; background: #f5f6f8; }
.qr-control img, .qr-thumbnail-placeholder { width: 84px; height: 84px; flex: none; border-radius: 10px; background: #fff; }
.qr-control img { padding: 4px; object-fit: contain; }
.qr-thumbnail-placeholder { display: grid; place-items: center; color: #9ba4b3; font-size: 12px; }
.qr-control > div { min-width: 0; }
.upload-button {
  display: inline-block;
  padding: 9px 12px;
  border-radius: 9px;
  background: #fff;
  color: #313a86;
  box-shadow: 0 2px 9px rgba(35, 45, 70, .055);
  cursor: pointer;
  font-size: 13px;
  font-weight: 650;
  transition: transform .2s ease, background .2s ease;
}
.upload-button:hover { background: #fafbff; }
input[type=file] { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; }
.qr-control:has(#qr-upload:focus-visible) .upload-button { outline: 2px solid #5864b2; outline-offset: 2px; }
#qr-file-name { margin: 7px 0 3px; color: #8892a4; font-size: 11px; word-break: break-all; }
.text-button { padding: 0; border: 0; background: none; color: #4553a3; font-size: 12px; font-weight: 600; }
.text-button:hover { color: #28347f; text-decoration: underline; text-underline-offset: 3px; }
.text-button:disabled { color: #a3acb9; cursor: not-allowed; text-decoration: none; }
#edit-qr { margin-right: 12px; }
.status { min-height: 18px; margin-top: 15px; color: #4553a3; font-size: 12px; line-height: 1.5; }
.status.error { color: #b34b58; }

.preview-panel { align-self: start; padding: 24px 25px 28px; }
.preview-heading { padding: 0 3px 18px; }
.preview-surface {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  min-width: 0;
  padding: 25px 12px;
  overflow: hidden;
  border-radius: 14px;
  background: #f3f5f8;
}
.scaled-card { position: relative; flex: none; box-shadow: 0 25px 65px rgba(26, 35, 70, .17); }

.page-drop-overlay { position: fixed; inset: 0; z-index: 12; display: grid; place-items: center; padding: 24px; pointer-events: none; background: rgba(244, 247, 255, .88); backdrop-filter: blur(8px); }
.page-drop-card { display: flex; flex-direction: column; align-items: center; gap: 9px; width: min(100%, 470px); padding: 44px 28px; border: 2px dashed #727fbd; border-radius: 24px; background: rgba(255, 255, 255, .97); color: #313b83; box-shadow: 0 22px 70px rgba(37, 49, 105, .13); text-align: center; }
.page-drop-symbol { display: grid; place-items: center; width: 60px; height: 60px; margin-bottom: 5px; border-radius: 18px; background: #eff2ff; color: #3b4796; }
.page-drop-symbol svg { width: 35px; height: 35px; }
.page-drop-card strong { font-size: 20px; font-weight: 750; line-height: 1.35; }
.page-drop-card > span:last-child { color: #69738c; font-size: 13px; }
.page-drop-overlay[data-state=loading] .page-drop-symbol { animation: drop-loading 1s ease-in-out infinite alternate; }
.page-drop-overlay[data-state=error] .page-drop-card { border-color: #d78d95; color: #aa4957; }
.page-drop-overlay[data-state=error] .page-drop-symbol { background: #fff0f1; color: #b34b58; }
@keyframes drop-loading { to { transform: translateY(-5px); background: #e2e9ff; } }

.qr-editor-backdrop { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 14px; background: rgba(20, 26, 45, .58); }
.qr-editor-panel { width: min(100%, 430px); max-height: calc(100vh - 28px); overflow: auto; padding: 22px; border-radius: 19px; background: #fff; box-shadow: 0 24px 75px rgba(0, 0, 0, .24); }
.qr-editor-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.qr-editor-heading p { margin-top: 5px; color: #677286; font-size: 12px; line-height: 1.45; }
.qr-close { width: 32px; height: 32px; border: 0; border-radius: 8px; background: #f1f2f5; font-size: 24px; line-height: 1; }
.qr-editor-help { margin: 15px 0 12px; color: #677286; font-size: 12px; line-height: 1.5; }
#qr-crop-canvas { display: block; width: min(320px, 100%); height: auto; aspect-ratio: 1; margin: 0 auto; touch-action: none; cursor: grab; background: #fff; box-shadow: 0 0 0 5px #f0f2f8; }
#qr-crop-canvas:active { cursor: grabbing; }
.qr-zoom-label { display: flex; justify-content: space-between; margin-top: 17px; }
#qr-zoom { width: 100%; margin: 9px 0 15px; accent-color: #303785; }
.qr-editor-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.qr-editor-actions #qr-auto-center { margin-right: auto; }
.button:focus-visible, .upload-button:focus-visible, .text-button:focus-visible { outline: 2px solid #5864b2; outline-offset: 3px; }
@media (prefers-reduced-motion: reduce) {
  .field-with-action input.auto-appear { animation: none; }
  .page-drop-overlay[data-state=loading] .page-drop-symbol { animation: none; }
  .button, .upload-button, input, textarea { transition: none; }
}
@media (max-width: 1040px) {
  .topbar { position: static; }
  .main-grid { grid-template-columns: minmax(0, 1fr); }
  .editor-panel { order: 2; }
  .preview-panel { order: 1; }
  .editor-panel, .preview-panel { width: 100%; max-width: 780px; margin: auto; }
}
@media (max-width: 620px) {
  .topbar { flex-wrap: wrap; gap: 13px; padding: 15px; }
  .topbar-actions { width: 100%; }
  .topbar-actions .button { flex: 1; }
  .main-grid { gap: 12px; padding: 12px; }
  .editor-panel { padding: 23px 20px; }
  .preview-panel { padding: 18px 14px; }
  .preview-surface { padding: 12px 5px; }
  .field-grid { grid-template-columns: 1fr; }
  .field-grid > * { grid-column: 1 / -1; }
  .qr-editor-actions .button { flex: 0 1 auto; }
}
