:root {
  --bg: #fdf6ec;
  --ink: #2c2418;
  --primary: #d9772e;
  --primary-dark: #b85e1c;
  --outline: #8a6a3f;
  --card-bg: #ffffff;
  --border: #e3d5bd;
  --success: #3a7d44;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  font-size: 20px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.hidden { display: none !important; }

/* ---------- LINE 瀏覽器提示 ---------- */
.line-banner {
  background: #fff3d6;
  border-bottom: 3px solid var(--primary);
  padding: 14px 16px;
  text-align: center;
}

.line-banner p {
  margin: 0 0 10px;
  font-size: 18px;
}

.line-banner .btn {
  max-width: 320px;
  margin: 0 auto 10px;
}

.line-banner-hint {
  font-size: 15px !important;
  color: var(--outline);
  margin: 0 !important;
}

/* ---------- 頂部 ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg);
  padding: 12px 16px 8px;
  border-bottom: 1px solid var(--border);
}

.app-title {
  margin: 0 0 8px;
  font-size: 26px;
  text-align: center;
}

.step-indicator {
  list-style: none;
  display: flex;
  justify-content: center;
  gap: 8px;
  margin: 0;
  padding: 0;
}

.step-indicator li {
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--border);
  color: var(--ink);
  font-size: 16px;
  opacity: 0.6;
  cursor: pointer;
}

.step-indicator li.active {
  background: var(--primary);
  color: #fff;
  opacity: 1;
  font-weight: bold;
}

.step-indicator li.done {
  background: var(--success);
  color: #fff;
  opacity: 0.85;
}

/* ---------- 預覽區 ---------- */
.preview-slot {
  background: var(--bg);
  text-align: center;
  padding: 10px 0 6px;
}

.preview-slot canvas {
  width: 130px;
  height: auto;
  aspect-ratio: 2 / 3;
  border-radius: 12px;
  border: 3px solid var(--border);
  box-shadow: 0 4px 10px rgba(0,0,0,0.12);
  background: #eee;
  transition: width 0.25s ease, height 0.25s ease;
}

body[data-step="3"] .preview-slot canvas {
  width: auto;
  height: min(38vh, 400px);
}

.preview-hint {
  margin: 6px 0 0;
  font-size: 16px;
  color: var(--outline);
}

/* ---------- 主內容 ---------- */
main {
  padding: 12px 16px 110px;
  max-width: 560px;
  margin: 0 auto;
}

/* ---------- 固定在畫面底部的主要按鈕 ---------- */
.btn-sticky-bottom {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  margin: 0;
  border-radius: 0;
  width: 100%;
  max-width: 100%;
  box-shadow: 0 -4px 14px rgba(0,0,0,0.18);
  padding: 16px 20px;
  min-height: 64px;
}

.step-title {
  font-size: 24px;
  margin: 8px 0 16px;
  text-align: center;
}

.sub-title {
  font-size: 20px;
  margin: 20px 0 10px;
}

.section-label {
  text-align: center;
  margin: 18px 0 10px;
  color: var(--outline);
}

/* ---------- 按鈕 ---------- */
button, .btn {
  font: inherit;
  cursor: pointer;
}

.btn {
  display: block;
  width: 100%;
  min-height: 56px;
  padding: 14px 20px;
  margin: 10px 0;
  border-radius: 14px;
  border: none;
  font-size: 21px;
  text-align: center;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  font-weight: bold;
  box-shadow: 0 4px 10px rgba(217,119,46,0.35);
}
.btn-primary:active { background: var(--primary-dark); }

.btn-outline {
  background: #fff;
  border: 3px dashed var(--outline);
  color: var(--ink);
}

.btn-ghost {
  background: transparent;
  color: var(--outline);
  text-decoration: underline;
  min-height: 48px;
}

.btn-small {
  min-height: 48px;
  font-size: 18px;
  width: auto;
  display: inline-block;
  padding: 10px 18px;
}

.btn-photo {
  font-size: 22px;
  font-weight: bold;
}

.btn-save {
  font-size: 24px;
  min-height: 68px;
}

.btn-next { margin-top: 20px; }
.btn-back { margin-top: 8px; }

.quick-swap {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin: 8px 0 4px;
}

/* ---------- 直向格子 ---------- */
.grid-2col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 10px 0;
}

.grid-3col {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 10px 0;
}

.grid-1col {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin: 10px 0;
}

.grid-2col button, .grid-3col button, .grid-1col button {
  min-height: 60px;
  border-radius: 14px;
  border: 3px solid var(--border);
  background: #fff;
  color: var(--ink);
  font-size: 19px;
  padding: 10px;
}

.grid-2col button.selected,
.grid-3col button.selected,
.grid-1col button.selected {
  border-color: var(--primary);
  background: #fbe9d8;
  font-weight: bold;
  position: relative;
}

.grid-2col button.selected::after,
.grid-3col button.selected::after,
.grid-1col button.selected::after {
  content: "✓";
  position: absolute;
  top: 4px;
  right: 8px;
  color: var(--primary);
  font-weight: bold;
  font-size: 20px;
}

/* ---------- 底圖縮圖格 ---------- */
.image-grid button {
  padding: 0;
  overflow: hidden;
  aspect-ratio: 2 / 3;
  border: 4px solid var(--border);
}

.image-grid button.selected {
  border-color: var(--primary);
}

.image-grid button img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* ---------- 句子清單 ---------- */
.sentence-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 10px 0;
}

.sentence-list button {
  min-height: 60px;
  border-radius: 14px;
  border: 3px solid var(--border);
  background: #fff;
  color: var(--ink);
  font-size: 21px;
  padding: 14px 18px;
  text-align: left;
}

.sentence-list button.selected {
  border-color: var(--primary);
  background: #fbe9d8;
  font-weight: bold;
}

/* ---------- 顏色配色預覽 ---------- */
.color-swatch {
  display: flex;
  align-items: center;
  gap: 14px;
  text-align: left;
}

.color-swatch .swatch-box {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  flex-shrink: 0;
  border: 2px solid rgba(0,0,0,0.15);
}

/* ---------- 自訂輸入 ---------- */
#customInputWrap input {
  width: 100%;
  min-height: 56px;
  font-size: 21px;
  padding: 12px 16px;
  border-radius: 12px;
  border: 3px solid var(--border);
  margin-top: 10px;
}

.char-count {
  text-align: right;
  color: var(--outline);
  margin: 4px 0 0;
}

/* ---------- 更多調整 ---------- */
.more-adjust {
  margin-top: 16px;
  padding: 16px;
  background: var(--card-bg);
  border-radius: 16px;
  border: 2px solid var(--border);
}

.switch-row {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 20px;
  margin: 10px 0;
}

.switch-row input[type="checkbox"] {
  width: 28px;
  height: 28px;
}

#signatureFields input {
  width: 100%;
  min-height: 52px;
  font-size: 20px;
  padding: 10px 14px;
  border-radius: 10px;
  border: 3px solid var(--border);
  margin: 8px 0;
}

/* ---------- 覆蓋層 ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(44, 36, 24, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.overlay-card {
  background: #fff;
  border-radius: 20px;
  padding: 28px 24px;
  max-width: 420px;
  width: 100%;
  text-align: center;
  max-height: 90vh;
  overflow-y: auto;
}

.check-icon {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--success);
  color: #fff;
  font-size: 40px;
  line-height: 72px;
  margin: 0 auto 14px;
}

.complete-title {
  font-size: 24px;
  font-weight: bold;
  margin: 0 0 16px;
}

.complete-img {
  width: 100%;
  border-radius: 12px;
  margin-bottom: 12px;
  border: 2px solid var(--border);
}

.complete-hint {
  font-size: 18px;
  color: var(--outline);
  margin-bottom: 16px;
}

.spinner {
  width: 56px;
  height: 56px;
  margin: 0 auto 16px;
  border: 6px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@media (min-width: 600px) {
  .image-grid { grid-template-columns: repeat(3, 1fr); }
}
