/* =========================================================
   一鍵去背修圖・手機版（PWA）樣式表
   專為單手大按鈕、大字體、一欄式手機操作設計
   ========================================================= */

:root {
  --bg-page: #f5f6f8;
  --bg-card: #ffffff;
  --bg-stage: #171920;
  --bg-soft: #eef0f4;
  --border: #e2e6ee;
  --text-main: #111827;
  --text-sub: #4b5563;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --success: #059669;
  --danger: #dc2626;
  --radius: 14px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: "Microsoft JhengHei", "PingFang TC", "Noto Sans TC", system-ui, -apple-system, sans-serif;
  background: var(--bg-page);
  color: var(--text-main);
  display: flex;
  flex-direction: column;
  font-size: 16px;
}

.hidden {
  display: none !important;
}

/* ---------- 頂部標題列 ---------- */
.app-header {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-shrink: 0;
}

.header-title {
  display: flex;
  align-items: center;
  gap: 8px;
}

.app-badge {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: linear-gradient(135deg, #4f46e5, #7c3aed);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 17px;
}

.app-header h1 {
  font-size: 18px;
  font-weight: 700;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pill-btn {
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text-main);
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}

/* ---------- 中央畫布區 ---------- */
.stage-area {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: var(--bg-stage);
  min-height: 0;
}

/* 未選圖時的大卡片 */
.empty-card {
  width: min(92%, 400px);
  background: var(--bg-card);
  border-radius: 20px;
  padding: 28px 22px;
  text-align: center;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.28);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.empty-icon {
  font-size: 48px;
  line-height: 1;
}

.empty-card h2 {
  font-size: 21px;
  font-weight: 700;
}

.empty-desc {
  font-size: 15px;
  color: var(--text-sub);
  line-height: 1.5;
}

.pick-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 6px;
}

.pwa-tip {
  font-size: 13px;
  color: var(--text-sub);
  background: #f5f7ff;
  border-radius: 10px;
  padding: 10px 12px;
  line-height: 1.5;
}

/* 大按鈕樣式（方便手機拇指點擊） */
.big-btn {
  width: 100%;
  min-height: 50px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: 17px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
}

.big-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

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

.big-btn-primary:active:not(:disabled) {
  background: var(--primary-dark);
}

.big-btn-secondary {
  background: #eef2ff;
  color: var(--primary);
  border-color: #c7d2fe;
}

.big-btn-success {
  background: var(--success);
  color: #fff;
}

.big-btn-ghost {
  background: var(--bg-soft);
  color: var(--text-main);
  border-color: var(--border);
}

.text-btn {
  border: none;
  background: transparent;
  color: var(--primary);
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  padding: 6px;
  cursor: pointer;
  align-self: center;
}

/* 編輯畫布區 */
.editor-viewport {
  width: 100%;
  height: 100%;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 46px 14px 14px;
  touch-action: none;
  overflow: hidden;
}

.floating-bar {
  position: absolute;
  top: 10px;
  left: 12px;
  right: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  z-index: 12;
  pointer-events: none;
}

.floating-bar > * {
  pointer-events: auto;
}

.float-chip {
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(17, 24, 39, 0.78);
  color: #fff;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}

.float-info {
  margin-left: auto;
  font-size: 12px;
  color: #e5e7eb;
  background: rgba(17, 24, 39, 0.68);
  padding: 5px 10px;
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
}

.canvas-pan-layer {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  max-width: 100%;
  max-height: 100%;
  transform-origin: center center;
  will-change: transform;
}

#editorCanvas {
  max-width: calc(100vw - 28px);
  max-height: 100%;
  width: auto;
  height: auto;
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  /* 透明棋盤格 */
  background-color: #ffffff;
  background-image:
    linear-gradient(45deg, #d1d5db 25%, transparent 25%),
    linear-gradient(-45deg, #d1d5db 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #d1d5db 75%),
    linear-gradient(-45deg, transparent 75%, #d1d5db 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
}

/* 筆刷圓圈提示 */
.brush-ring {
  position: absolute;
  pointer-events: none;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  border: 2px solid #10b981;
  background: rgba(16, 185, 129, 0.16);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.85);
  z-index: 10;
}

.brush-ring.erase {
  border-color: #ef4444;
  background: rgba(239, 68, 68, 0.18);
}

/* 裁切互動框 */
.crop-overlay {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border-radius: 10px;
  z-index: 9;
  touch-action: none;
}

.crop-box {
  position: absolute;
  border: 2px solid #ffffff;
  box-shadow: 0 0 0 9999px rgba(15, 23, 42, 0.65);
}

.crop-grid {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.crop-grid span:nth-child(1),
.crop-grid span:nth-child(2) {
  position: absolute;
  left: 0;
  right: 0;
  height: 1px;
  background: rgba(255, 255, 255, 0.45);
}

.crop-grid span:nth-child(1) { top: 33.333%; }
.crop-grid span:nth-child(2) { top: 66.666%; }

.crop-grid span:nth-child(3),
.crop-grid span:nth-child(4) {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 1px;
  background: rgba(255, 255, 255, 0.45);
}

.crop-grid span:nth-child(3) { left: 33.333%; }
.crop-grid span:nth-child(4) { left: 66.666%; }

.crop-handle {
  position: absolute;
  width: 28px;
  height: 28px;
  background: #ffffff;
  border: 3px solid var(--primary);
  border-radius: 50%;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}

.crop-handle.handle-nw { top: -14px; left: -14px; }
.crop-handle.handle-ne { top: -14px; right: -14px; }
.crop-handle.handle-sw { bottom: -14px; left: -14px; }
.crop-handle.handle-se { bottom: -14px; right: -14px; }

/* 載入遮罩 */
.loading-mask {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.78);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 30;
}

.loading-box {
  width: min(92%, 340px);
  background: var(--bg-card);
  border-radius: 18px;
  padding: 24px 20px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.spinner {
  width: 42px;
  height: 42px;
  border: 4px solid #e5e7eb;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.loading-title {
  font-size: 17px;
  font-weight: 700;
}

.loading-sub {
  font-size: 14px;
  color: var(--text-sub);
  line-height: 1.5;
}

.progress-track {
  width: 100%;
  height: 10px;
  background: var(--bg-soft);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 4px;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #4f46e5, #10b981);
  transition: width 0.2s ease;
}

/* ---------- 底部功能抽屜 ---------- */
.tool-drawer {
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  padding: 14px 16px 12px;
  max-height: 42vh;
  overflow-y: auto;
  flex-shrink: 0;
}

.drawer-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 520px;
  margin: 0 auto;
}

.panel-note {
  font-size: 13px;
  color: var(--text-sub);
  line-height: 1.5;
  text-align: center;
}

.row-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* 選項膠囊格線 */
.chip-grid {
  display: grid;
  gap: 8px;
}

.chip-grid-2 { grid-template-columns: repeat(2, 1fr); }
.chip-grid-3 { grid-template-columns: repeat(3, 1fr); }
.chip-grid-4 { grid-template-columns: repeat(4, 1fr); }

.choice-chip {
  min-height: 44px;
  border-radius: 11px;
  border: 1.5px solid var(--border);
  background: var(--bg-card);
  color: var(--text-main);
  font-size: 15px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
}

.choice-chip.active {
  border-color: var(--primary);
  background: #eef2ff;
  color: var(--primary);
}

.choice-chip.chip-restore.active {
  border-color: #059669;
  background: #ecfdf5;
  color: #047857;
}

.choice-chip.chip-erase.active {
  border-color: #dc2626;
  background: #fef2f2;
  color: #b91c1c;
}

/* 滑桿 */
.mobile-slider {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.slider-top {
  display: flex;
  justify-content: space-between;
  font-size: 15px;
  font-weight: 600;
}

.slider-top output {
  color: var(--primary);
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  width: 100%;
  height: 30px;
  accent-color: var(--primary);
}

/* 純色與餐廳質感背景 */
.sub-box {
  padding-top: 2px;
}

.swatch-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
  align-items: center;
}

.swatch-dot {
  aspect-ratio: 1;
  border-radius: 10px;
  border: 2px solid var(--border);
  cursor: pointer;
}

.swatch-picker {
  display: flex;
  flex-direction: column;
  align-items: center;
  font-size: 11px;
  color: var(--text-sub);
  gap: 2px;
}

.swatch-picker input[type="color"] {
  width: 34px;
  height: 28px;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.texture-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.texture-card {
  border: 2px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: var(--bg-card);
  padding: 0;
  cursor: pointer;
  font-family: inherit;
}

.texture-card.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.2);
}

.texture-card canvas {
  display: block;
  width: 100%;
  height: 52px;
}

.texture-card span {
  display: block;
  padding: 6px;
  font-size: 14px;
  font-weight: 700;
  color: var(--text-main);
  text-align: center;
}

/* ---------- 底部固定導覽列 ---------- */
.bottom-nav {
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  flex-shrink: 0;
}

.nav-item {
  border: none;
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 6px 2px;
  color: var(--text-sub);
  font-size: 12px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  border-radius: 10px;
}

.nav-ico {
  font-size: 20px;
  line-height: 1.1;
}

.nav-item.active {
  color: var(--primary);
  background: #eef2ff;
}

/* ---------- 關於彈窗 ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 60;
  padding: 12px;
}

.modal-sheet {
  width: min(100%, 480px);
  max-height: 85vh;
  overflow-y: auto;
  background: var(--bg-card);
  border-radius: 20px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-head h2 {
  font-size: 19px;
}

.close-btn {
  width: 36px;
  height: 36px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  font-size: 18px;
  cursor: pointer;
}

.modal-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.info-block {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 14px;
  line-height: 1.6;
}

.info-block h3 {
  font-size: 15px;
  margin-bottom: 6px;
  color: var(--primary);
}

.info-block a {
  color: var(--primary);
  word-break: break-all;
}

.info-block ul {
  padding-left: 18px;
}

/* ---------- 輕量提示吐司 ---------- */
.toast {
  position: fixed;
  top: 72px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(17, 24, 39, 0.92);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  z-index: 80;
  max-width: 90vw;
  text-align: center;
}
