/* ============ 基礎 ============ */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #ff8a3d;
  --primary-dark: #f0741f;
  --accent: #4ec3c9;
  --bg: #fdf6ee;
  --card: #ffffff;
  --ink: #3a3a3a;
  --line: #f0e4d5;
  --radius: 16px;
}

body {
  font-family: "Noto Sans TC", "Baloo 2", sans-serif;
  background: var(--bg);
  color: var(--ink);
  display: flex;
  min-height: 100vh;
}

/* ============ 左側控制面板 ============ */
.panel {
  width: 400px;
  min-width: 400px;
  background: var(--card);
  border-right: 1px solid var(--line);
  padding: 28px 24px 40px;
  overflow-y: auto;
  height: 100vh;
  position: sticky;
  top: 0;
}

.panel-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 26px;
}

.logo {
  font-size: 40px;
  background: linear-gradient(135deg, #ffe3c4, #ffd1d1);
  border-radius: 14px;
  width: 64px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.panel-header h1 {
  font-family: "Baloo 2", sans-serif;
  font-size: 20px;
  line-height: 1.15;
  color: var(--primary-dark);
}

.subtitle { font-size: 12px; color: #a08c74; margin-top: 4px; }

.lang-switch {
  margin-left: auto;
  align-self: flex-start;
  display: flex;
  gap: 4px;
}

.lang-switch button {
  border: 1.5px solid var(--line);
  background: #fff;
  border-radius: 8px;
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  color: #8a7a63;
  font-family: inherit;
  transition: all .15s;
}

.lang-switch button.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

/* ============ 登入頁 ============ */
.auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: linear-gradient(135deg, #fdf6ee 0%, #ffe8d1 55%, #d8f3f4 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

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

.auth-card {
  position: relative;
  width: 100%;
  max-width: 380px;
  background: #fff;
  border-radius: 24px;
  padding: 38px 34px 30px;
  box-shadow: 0 18px 50px rgba(240, 116, 31, .18);
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.auth-lang { position: absolute; top: 16px; right: 16px; margin-left: 0; }

.auth-logo { font-size: 44px; }

.auth-title {
  font-family: "Baloo 2", sans-serif;
  font-size: 24px;
  line-height: 1.2;
  color: var(--primary-dark);
}

.auth-subtitle { font-size: 13px; color: #a08c74; margin-bottom: 6px; }

.auth-card input {
  border: 1.5px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color .15s;
}

.auth-card input:focus { border-color: var(--primary); }

.auth-submit {
  margin-top: 4px;
  border: none;
  border-radius: 12px;
  padding: 13px;
  font-size: 15px;
  font-weight: 700;
  font-family: inherit;
  color: #fff;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  cursor: pointer;
  transition: transform .12s, box-shadow .12s;
}

.auth-submit:hover { transform: translateY(-1px); box-shadow: 0 8px 18px rgba(240, 116, 31, .3); }
.auth-submit:disabled { opacity: .6; cursor: wait; transform: none; }

.auth-error { font-size: 12.5px; color: #d64545; min-height: 16px; }

.auth-toggle a {
  font-size: 13px;
  color: var(--accent);
  font-weight: 700;
  cursor: pointer;
  text-decoration: underline;
}

.auth-form, .auth-status {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.auth-form[hidden], .auth-status[hidden] { display: none; }

.auth-status-icon { font-size: 46px; }

.auth-status-msg {
  font-size: 14px;
  color: #8a7a63;
  line-height: 1.6;
  white-space: pre-line;
}

/* ============ 使用者列 ============ */
.user-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: #fff7ef;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  padding: 8px 12px;
  margin: -12px 0 20px;
}

.user-bar[hidden] { display: none; }

.user-email {
  font-size: 12px;
  color: #8a7a63;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-btns { display: flex; gap: 6px; flex-shrink: 0; }

.user-btn {
  border: 1.5px solid var(--line);
  background: #fff;
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 700;
  font-family: inherit;
  color: #8a7a63;
  cursor: pointer;
  transition: all .15s;
}

.user-btn:hover { border-color: var(--primary); color: var(--primary-dark); }

/* ============ 歷史頁 ============ */
.history-overlay {
  position: fixed;
  inset: 0;
  z-index: 150;
  background: rgba(58, 42, 24, .45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 26px;
}

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

.history-panel {
  width: 100%;
  max-width: 980px;
  max-height: 88vh;
  background: var(--bg);
  border-radius: 20px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .3);
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  background: #fff;
  border-bottom: 1.5px solid var(--line);
}

.history-header h2 {
  font-family: "Baloo 2", sans-serif;
  font-size: 20px;
  color: var(--primary-dark);
}

.icon-btn {
  border: none;
  background: #f4ede3;
  border-radius: 10px;
  width: 34px;
  height: 34px;
  font-size: 15px;
  cursor: pointer;
  color: #8a7a63;
  transition: all .15s;
}

.icon-btn:hover { background: var(--primary); color: #fff; }

.history-content {
  overflow-y: auto;
  padding: 20px 24px 28px;
  flex: 1;
}

.history-msg { text-align: center; color: #a08c74; font-size: 14px; padding: 40px 0; }
.history-msg.error { color: #d64545; }

.history-group { margin-bottom: 26px; }

.history-date {
  font-family: "Baloo 2", sans-serif;
  font-size: 16px;
  color: var(--primary-dark);
  margin-bottom: 10px;
}

.history-gen {
  background: #fff;
  border: 1.5px solid var(--line);
  border-radius: 14px;
  padding: 14px 16px;
  margin-bottom: 12px;
}

.history-meta {
  font-size: 12.5px;
  color: #8a7a63;
  margin-bottom: 10px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 10px;
}

.history-thumb {
  width: 100%;
  aspect-ratio: 210 / 297;
  object-fit: cover;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  transition: transform .12s, box-shadow .12s, border-color .12s;
}

.history-thumb:hover {
  transform: translateY(-2px);
  border-color: var(--primary);
  box-shadow: 0 6px 16px rgba(240, 116, 31, .25);
}

/* ============ 圖片預覽彈窗 ============ */
.img-modal {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(20, 14, 8, .72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 26px;
}

.img-modal[hidden] { display: none; }

.img-modal-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  max-width: min(92vw, 560px);
}

.img-modal-box img {
  max-width: 100%;
  max-height: 74vh;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 20px 50px rgba(0, 0, 0, .5);
}

.img-modal-actions { display: flex; gap: 10px; }

/* ---- 步驟 ---- */
.step { margin-bottom: 24px; }

.step h2 {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.step-num {
  background: var(--primary);
  color: #fff;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  flex-shrink: 0;
}

.hint { font-size: 12px; font-weight: 400; color: #b0a08c; }

/* ---- 等級卡片 ---- */
.level-cards { display: flex; gap: 10px; }

.level-card {
  flex: 1;
  background: #faf5ec;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 8px 12px;
  cursor: pointer;
  text-align: center;
  transition: all .15s ease;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-family: inherit;
}

.level-card:hover { border-color: #ffc89b; transform: translateY(-2px); }

.level-card.selected {
  background: linear-gradient(160deg, #fff3e4, #ffe8d2);
  border-color: var(--primary);
  box-shadow: 0 4px 14px rgba(255, 138, 61, .25);
}

.level-name {
  font-family: "Baloo 2", sans-serif;
  font-size: 24px;
  font-weight: 800;
  color: var(--primary-dark);
}

.level-desc { font-size: 13px; color: #7a6a55; }
.level-dots { font-size: 10px; letter-spacing: 2px; color: var(--primary); }

/* ---- 主題輸入 ---- */
#topicInput {
  width: 100%;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  font-family: inherit;
  font-size: 13px;
  line-height: 1.6;
  resize: vertical;
  background: #fffdf9;
  transition: border-color .15s;
}

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

/* ---- Worksheet 類型 ---- */
.type-list { display: flex; flex-direction: column; gap: 8px; }

.type-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #faf5ec;
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  cursor: pointer;
  transition: all .15s;
  user-select: none;
}

.type-item:hover { border-color: #a7dee1; }

.type-item.checked {
  background: #e9f8f8;
  border-color: var(--accent);
}

.type-item input { display: none; }

.type-check {
  width: 20px;
  height: 20px;
  border-radius: 6px;
  border: 2px solid #cbbfa9;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  color: #fff;
  flex-shrink: 0;
  transition: all .15s;
}

.type-item.checked .type-check { background: var(--accent); border-color: var(--accent); }

.type-icon { font-size: 20px; }
.type-label { font-size: 14px; font-weight: 500; }
.type-label small { display: block; font-size: 11px; color: #a08c74; font-weight: 400; }

/* ---- 生成按鈕 ---- */
.generate-btn {
  width: 100%;
  margin-top: 4px;
  padding: 15px;
  border: none;
  border-radius: var(--radius);
  background: linear-gradient(135deg, var(--primary), #ff6b6b);
  color: #fff;
  font-family: inherit;
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(255, 122, 61, .35);
  transition: transform .15s, box-shadow .15s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.generate-btn:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 8px 22px rgba(255, 122, 61, .45); }
.generate-btn:disabled { opacity: .6; cursor: wait; }

.status { font-size: 13px; text-align: center; margin-top: 10px; min-height: 18px; color: #7a6a55; }
.status.error { color: #d64545; }

/* ============ 預覽區頂端列（History 按鈕） ============ */
.preview-topbar {
  display: flex;
  justify-content: flex-end;
  padding: 12px 20px 0;
  min-height: 42px;
}

.topbar-history-btn {
  border: 1.5px solid var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 700;
  font-family: inherit;
  color: #8a7a63;
  cursor: pointer;
  transition: all .15s;
}

.topbar-history-btn:hover {
  border-color: var(--primary);
  color: var(--primary-dark);
  background: #fff7ef;
}

.topbar-history-btn[hidden] { display: none; }

/* ============ 歷史（內嵌在右側） ============ */
#historyView { display: flex; flex-direction: column; height: 100%; }
#historyView[hidden] { display: none; }
#worksheetView[hidden] { display: none; }

.history-inline-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px 12px;
  border-bottom: 1.5px solid var(--line);
  flex-shrink: 0;
}

.history-inline-header h2 {
  font-family: "Baloo 2", sans-serif;
  font-size: 18px;
  color: var(--primary-dark);
}

/* ---- 生成進度條 ---- */
.progress-wrap {
  margin-top: 12px;
  height: 14px;
  background: #f1e6d6;
  border-radius: 99px;
  overflow: hidden;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, .08);
}

.progress-wrap[hidden] { display: none; }

.progress-bar {
  height: 100%;
  width: 0%;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  background-size: 200% 100%;
  animation: progress-shimmer 1.6s linear infinite;
  transition: width .4s ease;
}

@keyframes progress-shimmer {
  0%   { background-position: 0% 0; }
  100% { background-position: -200% 0; }
}

/* ---- 設定 ---- */
.settings {
  margin-top: 22px;
  border: 1px dashed #dccdb5;
  border-radius: 12px;
  padding: 10px 14px;
  background: #fffdf8;
}

.settings summary { cursor: pointer; font-size: 13px; font-weight: 500; color: #8a7a63; }

.settings-body { padding-top: 12px; display: flex; flex-direction: column; gap: 10px; }

.settings-body label { font-size: 12px; color: #7a6a55; display: flex; flex-direction: column; gap: 4px; }

.settings-body input {
  border: 1.5px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 13px;
}

.save-key-btn {
  align-self: flex-start;
  border: none;
  background: var(--accent);
  color: #fff;
  border-radius: 8px;
  padding: 7px 16px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.settings-note { font-size: 11px; color: #b0a08c; line-height: 1.5; }

.settings-body select {
  border: 1.5px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 13px;
  background: #fff;
}

.key-status { font-size: 12px; color: #8a7a63; }
.key-status.ok { color: #2e9e63; }
.key-status.warn { color: #d68a2e; }

/* ============ 右側預覽區 ============ */
.preview-area {
  flex: 1;
  padding: 28px 36px 60px;
  overflow-y: auto;
  height: 100vh;
}

.preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--bg);
  padding: 8px 0;
}

.page-count { font-size: 14px; color: #8a7a63; }

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

.toolbar-btns { display: flex; gap: 10px; }

.download-btn, .print-btn {
  border: none;
  border-radius: 12px;
  padding: 11px 22px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: transform .15s;
}

.download-btn {
  background: var(--ink);
  color: #fff;
  box-shadow: 0 4px 12px rgba(0,0,0,.18);
}

.print-btn {
  background: #fff;
  color: var(--ink);
  border: 2px solid var(--ink);
}

.download-btn:hover:not(:disabled), .print-btn:hover { transform: translateY(-2px); }
.download-btn:disabled { opacity: .6; cursor: wait; }

.preview-empty {
  height: 80%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: #b8a88f;
  text-align: center;
  font-size: 15px;
  line-height: 1.8;
}

.empty-icon { font-size: 64px; opacity: .7; }

/* ============ A4 頁面 ============ */
.a4-page {
  width: 210mm;
  min-height: 297mm;
  background: #fff;
  margin: 0 auto 28px;
  box-shadow: 0 4px 24px rgba(90, 70, 40, .15);
  padding: 16mm 15mm 14mm;
  position: relative;
  display: flex;
  flex-direction: column;
  font-family: "Comic Neue", "Baloo 2", sans-serif;
  color: #222;
}

/* 頁首：姓名/日期 */
.ws-meta {
  display: flex;
  justify-content: space-between;
  font-size: 12pt;
  color: #555;
  margin-bottom: 6mm;
}

.ws-meta span { border-bottom: 1.5px solid #999; padding: 0 24mm 2px 4px; }

/* 標題列 */
.ws-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8mm;
  margin-bottom: 8mm;
}

.ws-header .ws-emoji { font-size: 44pt; line-height: 1; }

.ws-title {
  font-family: "Baloo 2", sans-serif;
  font-size: 36pt;
  font-weight: 800;
  letter-spacing: 3px;
  text-transform: uppercase;
}

.ws-instruction {
  font-size: 14pt;
  margin: 4mm 0 6mm;
  font-weight: 700;
}

.ws-body { flex: 1; }

/* 頁尾 */
.ws-footer {
  margin-top: auto;
  padding-top: 4mm;
  font-size: 9pt;
  color: #aaa;
  text-align: center;
}

/* ---- Tracing ---- */
.trace-row {
  position: relative;
  height: 22mm;
  border-top: 2px solid #444;
  border-bottom: 2px solid #444;
  margin-bottom: 9mm;
  display: flex;
  align-items: center;
  justify-content: space-around;
}

.trace-row::before {
  content: "";
  position: absolute;
  left: 0; right: 0; top: 50%;
  border-top: 1.5px dashed #bbb;
}

.trace-word {
  font-family: "Comic Neue", sans-serif;
  font-size: 34pt;
  font-weight: 700;
  color: #c9c9c9;
  letter-spacing: 6px;
  position: relative;
  z-index: 1;
}

.trace-word.empty { color: transparent; }

/* ---- 數字 ---- */
.num-grid {
  display: grid;
  gap: 4mm;
  justify-content: center;
}

.num-cell {
  border: 2px solid #444;
  border-radius: 4mm;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "Baloo 2", sans-serif;
  font-weight: 700;
  background: #fff;
}

.num-cell.trace { color: #c9c9c9; }
.num-cell.blank { color: transparent; background: #fafafa; }

/* ---- Matching 連連看 ---- */
.match-wrap {
  display: flex;
  justify-content: space-between;
  padding: 0 14mm;
}

.match-col { display: flex; flex-direction: column; gap: 12mm; }

.match-item {
  display: flex;
  align-items: center;
  gap: 5mm;
  font-size: 20pt;
  font-weight: 700;
}

.match-item .m-emoji { font-size: 34pt; }
.match-dot { width: 5mm; height: 5mm; border-radius: 50%; background: #444; flex-shrink: 0; }

/* ---- 圈選 ---- */
.circle-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8mm 4mm;
  border: 2px solid #444;
  border-radius: 5mm;
  padding: 8mm;
}

.circle-item { text-align: center; }
.circle-item .c-emoji { font-size: 38pt; line-height: 1.2; }
.circle-item .c-word { font-size: 11pt; color: #666; margin-top: 1mm; }

/* ---- 著色 ---- */
.color-word {
  font-family: "Baloo 2", sans-serif;
  font-size: 72pt;
  font-weight: 800;
  text-align: center;
  color: #fff;
  -webkit-text-stroke: 2.5px #333;
  text-transform: uppercase;
  letter-spacing: 6px;
  margin: 6mm 0;
}

.color-shapes {
  display: flex;
  justify-content: center;
  gap: 10mm;
  flex-wrap: wrap;
  margin-top: 8mm;
}

/* ---- 找不同（兩圖比較） ---- */
.diff-wrap { display: flex; gap: 8mm; justify-content: center; }

.diff-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5mm;
  border: 2.5px solid #444;
  border-radius: 5mm;
  padding: 6mm;
  flex: 1;
}

.diff-grid .d-emoji { font-size: 30pt; text-align: center; }
.diff-label { text-align: center; font-size: 14pt; font-weight: 700; margin-bottom: 3mm; }

/* ---- 相同配對 ---- */
.same-row {
  display: flex;
  align-items: center;
  justify-content: space-around;
  border: 2px dashed #999;
  border-radius: 5mm;
  padding: 5mm;
  margin-bottom: 6mm;
}

.same-row .s-emoji { font-size: 32pt; }

/* ---- 填空 ---- */
.wordbank {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4mm 8mm;
  border: 2.5px solid #444;
  border-radius: 5mm;
  padding: 5mm 8mm;
  margin-bottom: 8mm;
  font-size: 17pt;
  font-weight: 700;
}

.fill-sentence {
  font-size: 17pt;
  line-height: 2.4;
  margin-bottom: 6mm;
  font-weight: 400;
}

.fill-sentence .blank {
  display: inline-block;
  min-width: 34mm;
  border-bottom: 2.5px solid #444;
}

.fill-sentence .f-emoji { font-size: 22pt; }

/* ---- 剪貼 ---- */
.cut-targets { display: flex; gap: 8mm; margin-bottom: 10mm; }

.cut-box {
  flex: 1;
  border: 3px solid #444;
  border-radius: 5mm;
  min-height: 55mm;
  padding: 4mm;
  text-align: center;
}

.cut-box h4 { font-size: 15pt; margin-bottom: 2mm; }

.cut-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 5mm;
  justify-content: center;
  padding-top: 6mm;
  border-top: 2.5px dashed #888;
  position: relative;
}

.cut-strip::before {
  content: "✂️";
  position: absolute;
  top: -5mm;
  left: 2mm;
  font-size: 14pt;
  background: #fff;
}

.cut-card {
  border: 2.5px dashed #888;
  border-radius: 3mm;
  padding: 4mm 6mm;
  text-align: center;
}

.cut-card .k-emoji { font-size: 28pt; }
.cut-card .k-word { font-size: 11pt; color: #555; }

/* ---- 加法數一數 ---- */
.add-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5mm;
}

.add-cell {
  border: 2px solid #444;
  border-radius: 4mm;
  padding: 5mm 4mm;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4mm;
}

.add-vis {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2mm;
  flex-wrap: wrap;
}

.add-group {
  max-width: 34mm;
  font-size: 15pt;
  line-height: 1.5;
  letter-spacing: 1.5mm;
  text-align: center;
}

.add-op {
  font-family: "Baloo 2", sans-serif;
  font-size: 20pt;
  font-weight: 800;
  margin: 0 1mm;
}

.add-num {
  font-family: "Baloo 2", sans-serif;
  font-size: 22pt;
  font-weight: 800;
}

.add-eq {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2mm;
}

.add-box {
  display: inline-block;
  border: 2.5px solid #444;
  border-radius: 2.5mm;
  background: #fafafa;
  vertical-align: middle;
}

.add-box.big { width: 13mm; height: 13mm; }
.add-box.small { width: 10mm; height: 10mm; }

/* ---- 形狀 ---- */
.shape-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10mm;
  justify-items: center;
}

.shape-cell { text-align: center; }
.shape-cell svg { display: block; margin: 0 auto 2mm; }
.shape-cell .sh-name { font-size: 14pt; font-weight: 700; }

/* ---- AI 圖像頁 ---- */
.a4-page.image-page { padding: 6mm; }

.a4-page.image-page img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.png-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  border: none;
  background: rgba(0, 0, 0, .65);
  color: #fff;
  border-radius: 8px;
  padding: 6px 12px;
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  opacity: 0;
  transition: opacity .15s;
}

.a4-page.image-page:hover .png-btn { opacity: 1; }

/* ============ 列印（A4 PDF） ============ */
@page { size: A4; margin: 0; }

@media print {
  body { background: #fff; display: block; }
  .panel, .preview-toolbar, .preview-empty, .png-btn,
  .auth-overlay, .img-modal, .user-bar, .preview-topbar,
  .history-inline-header, #historyView { display: none !important; }
  .preview-area { padding: 0; height: auto; overflow: visible; }
  .a4-page {
    box-shadow: none;
    margin: 0;
    width: 210mm;
    height: 297mm;
    page-break-after: always;
    break-after: page;
  }
}

/* ============ 響應式 ============ */
@media (max-width: 900px) {
  body { flex-direction: column; }
  .panel { width: 100%; min-width: 0; height: auto; position: static; }
  .preview-area { height: auto; padding: 20px 8px; }
  .a4-page { transform-origin: top left; }
}
