@font-face {
  font-family: 'StarfruitCelesSerif-Bold';
  src: url('../../pdf/assets/fonts/StarfruitCelesSerif-Bold.otf') format('opentype');
  font-weight: bold;
  font-style: normal;
}

:root {
  --brand: #732634;
  --brand-deep: #8c2641;
  --brand-pink: #faacc4;
  --panel: #ffffff;
  --bg: #eef0f3;
  --text: #1a202c;
  --muted: #64748b;
  --line: #e2e8f0;
  --ok: #2f855a;
  --warn: #c05621;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  font-family: "Segoe UI", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
}

/* 全站唯一廣告：編輯器頂部（長方形 728×90） */
.ad-banner {
  flex-shrink: 0;
  height: 98px;
  max-height: 98px;
  background: #1a1a1a;
  color: #aaa;
  display: flex;
  align-items: center;
  justify-content: center;
  border-bottom: 1px solid #333;
  position: relative;
  z-index: 50;
  overflow: hidden;
}
.ad-banner .ad-label {
  position: absolute;
  left: 8px;
  top: 4px;
  font-size: 10px;
  color: #777;
  letter-spacing: .05em;
  z-index: 1;
}
.ad-banner .ad-slot {
  width: 728px;
  max-width: 96vw;
  height: 90px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #111;
  border: 1px solid #333;
  border-radius: 4px;
  overflow: hidden;
  padding: 0;
}
.ad-banner .ad-slot.live {
  border-style: solid;
  background: #111;
}
.ad-banner .ad-slot .adsbygoogle {
  display: inline-block !important;
  width: 728px !important;
  height: 90px !important;
  max-width: 100%;
}
@media (max-width: 760px) {
  .ad-banner { height: 58px; max-height: 58px; }
  .ad-banner .ad-slot {
    width: 320px;
    height: 50px;
  }
  .ad-banner .ad-slot .adsbygoogle {
    width: 320px !important;
    height: 50px !important;
  }
}

.app {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.topbar {
  flex-shrink: 0;
  height: 52px;
  background: var(--brand);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 14px;
}
.topbar a.back {
  color: var(--brand-pink);
  text-decoration: none;
  font-size: 14px;
  white-space: nowrap;
}
.topbar a.back:hover { text-decoration: underline; }
.topbar h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.topbar .engine-tag {
  font-size: 11px;
  background: rgba(255,255,255,.15);
  border-radius: 999px;
  padding: 3px 8px;
  color: #f3d5df;
}

.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 0;
}

.panel {
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.panel-scroll {
  flex: 1;
  overflow: auto;
  padding: 16px;
}
.panel-actions {
  border-top: 1px solid var(--line);
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.preview {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  min-height: 0;
  overflow: auto;
  background: #e0e4e8;
}
.preview-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  max-width: 100%;
  max-height: 100%;
}
.preview-sheet {
  width: min(460px, 90vw);
  max-height: min(78vh, 760px);
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
}
.preview-sheet svg.page-preview {
  display: block;
  width: 100%;
  height: auto;
  max-height: min(78vh, 760px);
  background: #fff;
  box-shadow: 0 12px 40px rgba(0,0,0,.15);
}
.bind-switch {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  background: #e2e8f0;
  border-radius: 10px;
  padding: 4px;
  margin-bottom: 8px;
}
.bind-btn {
  flex: 1 1 42%;
  border: none;
  background: transparent;
  border-radius: 8px;
  padding: 8px 6px;
  font-size: 12px;
  font-weight: 700;
  color: #475569;
  cursor: pointer;
}
.bind-btn.active {
  background: #fff;
  color: var(--brand);
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
}
.preview-meta {
  font-size: 12px;
  color: #64748b;
  text-align: center;
  line-height: 1.5;
  max-width: 420px;
}
.paper-fill-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: #64748b;
  margin: 4px 0 10px;
  cursor: pointer;
}
.paper-fill-toggle input { width: auto; }
.hidden { display: none !important; }

.section {
  margin-bottom: 18px;
}
.section h2 {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 700;
  color: #475569;
  text-transform: none;
  letter-spacing: 0;
}
.field {
  margin-bottom: 10px;
}
.field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: #555;
  margin-bottom: 5px;
}
.field input[type="color"],
.field input[type="text"],
.field input[type="number"],
.field select {
  width: 100%;
  padding: 8px;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-size: 14px;
  outline: none;
}
.field input:focus, .field select:focus { border-color: #2b6cb0; }
.row2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.color-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  margin-bottom: 8px;
}
.color-row input[type="color"] {
  width: 36px;
  height: 28px;
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
}
.color-row .name {
  flex: 1;
  font-size: 13px;
  font-weight: 600;
}

.btn {
  width: 100%;
  border: none;
  border-radius: 8px;
  padding: 12px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: .15s;
}
.btn-primary { background: #2b6cb0; color: #fff; }
.btn-primary:hover { background: #2c5282; }
.btn-ai { background: var(--brand); color: #fff; }
.btn-ai:hover { background: var(--brand-deep); }
.btn-ai:disabled, .btn-primary:disabled {
  opacity: .55;
  cursor: not-allowed;
}
.btn-ghost {
  background: #f1f5f9;
  color: #334155;
}
.btn-ghost:hover { background: #e2e8f0; }

.ai-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}
.ai-tab {
  flex: 1;
  border: 1px solid var(--line);
  background: #f8fafc;
  border-radius: 8px;
  padding: 7px 8px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  color: var(--muted);
}
.ai-tab.active {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}
.ai-layout-box {
  margin-top: 10px;
  padding: 10px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  background: #fafbfc;
}
.layout-item .note { margin-top: 2px; }

/* AI 30s 倒數進度條 */
.ai-wait {
  margin-top: 10px;
  padding: 10px 10px 12px;
  border-radius: 10px;
  background: linear-gradient(180deg, #fff8fa 0%, #f8f0f3 100%);
  border: 1px solid #eddde2;
}
.ai-wait.hidden { display: none !important; }
.ai-wait-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 8px;
  gap: 8px;
}
.ai-wait-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--brand-deep);
}
.ai-wait-sec {
  font-size: 18px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--brand);
  letter-spacing: 0.02em;
  min-width: 2.6em;
  text-align: right;
}
.ai-wait-sec.done {
  color: var(--ok);
}
.ai-wait-track {
  height: 8px;
  border-radius: 999px;
  background: #e8d5db;
  overflow: hidden;
  position: relative;
}
.ai-wait-bar {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, #8c2641 0%, #c45a72 55%, #faacc4 100%);
  transition: width 0.9s linear;
  box-shadow: 0 0 8px rgba(115, 38, 52, 0.25);
}
.ai-wait-bar.rush {
  transition: width 0.45s cubic-bezier(0.22, 1, 0.36, 1);
  background: linear-gradient(90deg, #2f855a 0%, #48bb78 50%, #9ae6b4 100%);
}
.ai-wait-bar.pulse {
  animation: ai-bar-pulse 0.7s ease-in-out 1;
}
@keyframes ai-bar-pulse {
  0% { filter: brightness(1); }
  40% { filter: brightness(1.25); }
  100% { filter: brightness(1); }
}

.palette-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.palette-item {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s;
  background: #fff;
}
.palette-item:hover {
  border-color: var(--brand-pink);
  box-shadow: 0 4px 12px rgba(115,38,52,.08);
}
.palette-item .title {
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 6px;
}
.palette-item .sw {
  display: flex;
  gap: 4px;
  margin-bottom: 6px;
}
.palette-item .sw i {
  flex: 1;
  height: 18px;
  border-radius: 4px;
}
.palette-item .note {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.4;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 16px;
}
.modal.hidden { display: none !important; }
.modal-card {
  background: #fff;
  border-radius: 14px;
  padding: 20px 22px;
  max-width: 400px;
  width: 100%;
  box-shadow: 0 20px 50px rgba(0,0,0,.2);
}
.modal-card h3 {
  margin: 0 0 10px;
  font-size: 16px;
  color: #1a202c;
}
.modal-card p {
  margin: 0 0 10px;
  font-size: 13px;
  line-height: 1.55;
  color: #475569;
}
.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}
.modal-actions .btn { flex: 1; }

.xy-mini-help {
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  margin-bottom: 10px;
}
.xy-mini-help p {
  margin: 0 0 4px;
  font-size: 12px;
  color: #475569;
  line-height: 1.45;
}
.xy-mini-help p:last-child { margin-bottom: 0; }
.field-note {
  display: block;
  font-size: 11px;
  color: #94a3b8;
  margin-top: 3px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%) translateY(20px);
  background: #1e293b;
  color: #fff;
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 14px;
  max-width: min(420px, 92vw);
  text-align: center;
  line-height: 1.5;
  opacity: 0;
  pointer-events: none;
  transition: .25s;
  z-index: 100;
  box-shadow: 0 10px 30px rgba(0,0,0,.2);
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.busy { background: #7c2d3a; }
.toast.ok { background: var(--ok); }

.hint {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
  margin: 0 0 10px;
}

@media (max-width: 860px) {
  body { overflow: auto; }
  .app { height: auto; min-height: 100%; }
  .workspace {
    grid-template-columns: 1fr;
    min-height: auto;
  }
  .panel {
    border-right: none;
    border-bottom: 1px solid var(--line);
    max-height: none;
  }
  .panel-scroll { max-height: none; }
  .preview {
    min-height: 420px;
  }
}
