/* LINE Sticker Processor — 手機版樣式
   Mobile-first：所有 touch target >= 44px（iOS HIG 建議值）。 */

:root {
  --bg: #0f1216;
  --panel: #191e25;
  --panel-2: #212832;
  --line: #2c3542;
  --text: #eef2f7;
  --muted: #9aa7b6;
  --accent: #06c755;      /* LINE green */
  --accent-ink: #04351a;
  --warn: #ffb020;
  --danger: #ff5a5a;
  --radius: 14px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

/* hidden 屬性的瀏覽器預設是 display:none，但那是最低優先級，
   會被 .editor { display:flex } 這類 class 規則蓋掉。
   少了這一條，編輯器一載入就全螢幕蓋住整個選圖流程。 */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Helvetica Neue",
        "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  overscroll-behavior-y: contain;
}

body { padding-bottom: calc(24px + var(--safe-bottom)); }

.app-bar {
  padding: calc(env(safe-area-inset-top, 0px) + 14px) 16px 12px;
  background: linear-gradient(180deg, #151b22, #0f1216);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
}
.app-bar h1 { margin: 0; font-size: 19px; letter-spacing: .02em; }
.app-bar .sub { margin: 3px 0 0; font-size: 12px; color: var(--muted); }

main { padding: 16px; display: flex; flex-direction: column; gap: 16px; }

.step {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}
.step h2 {
  margin: 0 0 10px;
  font-size: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.step h2 .num {
  width: 24px; height: 24px;
  flex: none;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 13px;
  font-weight: 700;
  display: grid;
  place-items: center;
}
.hint { margin: 6px 0 0; font-size: 13px; color: var(--muted); }
.error { margin: 10px 0 0; font-size: 13px; color: var(--danger); }

/* ---------- 按鈕 ---------- */
.big-button {
  display: block;
  width: 100%;
  min-height: 52px;
  border: 0;
  border-radius: 12px;
  font-size: 17px;
  font-weight: 600;
  text-align: center;
  line-height: 52px;
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
}
.big-button.primary { background: var(--accent); color: var(--accent-ink); }
.big-button:disabled { opacity: .45; }

.text-button {
  background: none;
  border: 0;
  color: var(--muted);
  font-size: 15px;
  min-height: 44px;
  padding: 0 4px;
  cursor: pointer;
}
.text-button.strong { color: var(--accent); font-weight: 600; }

.tool-button {
  min-height: 46px;
  min-width: 52px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  font-size: 15px;
  cursor: pointer;
}
.tool-button.wide { flex: 1; }

input[type="text"] {
  width: 100%;
  min-height: 50px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  font-size: 17px; /* >=16px 避免 iOS 自動放大 */
}

/* ---------- source 排序清單 ---------- */
.source-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.source-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  border-radius: 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  touch-action: none; /* 讓自訂拖曳吃到 touchmove */
}
.source-item.dragging { opacity: .6; transform: scale(1.02); }
.source-item.drop-target { border-color: var(--accent); }
.source-item img {
  width: 56px; height: 56px; flex: none;
  object-fit: contain;
  border-radius: 8px;
  background:
    repeating-conic-gradient(#3a444f 0% 25%, #2b333c 0% 50%) 50% / 12px 12px;
}
.source-item .meta { flex: 1; min-width: 0; font-size: 13px; }
.source-item .meta .title { font-weight: 600; font-size: 14px; }
.source-item .meta .detail { color: var(--muted); }
.source-item .handle {
  flex: none;
  width: 44px; height: 44px;
  display: grid; place-items: center;
  color: var(--muted);
  font-size: 20px;
  cursor: grab;
}
.source-item .remove {
  flex: none;
  width: 44px; height: 44px;
  border: 0; background: none;
  color: var(--muted); font-size: 20px;
  cursor: pointer;
}
.numbering-preview { margin: 12px 0 0; font-size: 13px; color: var(--muted); }

/* ---------- QA ---------- */
.qa-summary {
  border-radius: 12px;
  padding: 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  font-size: 14px;
  margin-bottom: 14px;
}
.qa-summary .ok { color: var(--accent); font-weight: 600; }
.qa-summary .warn { color: var(--warn); font-weight: 600; }
.qa-summary ul { margin: 8px 0 0; padding-left: 18px; color: var(--muted); font-size: 13px; }

/* ---------- 40 張預覽 ---------- */
.sticker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 10px;
}
.sticker-cell {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
  padding: 6px;
  text-align: center;
  cursor: pointer;
}
.sticker-cell.warn { border-color: var(--warn); }
.sticker-cell img {
  width: 100%;
  aspect-ratio: 370 / 320;
  object-fit: contain;
  background:
    repeating-conic-gradient(#3a444f 0% 25%, #2b333c 0% 50%) 50% / 10px 10px;
  border-radius: 6px;
  display: block;
}
.sticker-cell .label { font-size: 12px; margin-top: 5px; color: var(--muted); }
.sticker-cell .label .code { color: var(--text); font-weight: 600; }
.sticker-cell .label .edited { color: var(--accent); }

.actions { margin-top: 16px; }

/* ---------- 進度 ---------- */
.progress { margin-top: 14px; }
.progress .bar { height: 8px; border-radius: 4px; background: var(--panel-2); overflow: hidden; }
.progress .fill { height: 100%; width: 0; background: var(--accent); transition: width .15s linear; }
.progress p { margin: 8px 0 0; font-size: 13px; color: var(--muted); }

/* ---------- 編輯器 ---------- */
.editor {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}
.editor-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: calc(env(safe-area-inset-top, 0px) + 6px) 12px 6px;
  border-bottom: 1px solid var(--line);
  font-size: 15px;
}
.canvas-wrap {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  position: relative;
  background:
    repeating-conic-gradient(#39424d 0% 25%, #2a323b 0% 50%) 50% / 16px 16px;
  touch-action: none;
}
.canvas-wrap canvas {
  position: absolute;
  top: 0; left: 0;
  transform-origin: 0 0;
  image-rendering: auto;
}
.editor-tools {
  padding: 12px 14px calc(12px + var(--safe-bottom));
  border-top: 1px solid var(--line);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.tool-row { display: flex; align-items: center; gap: 10px; }
.tool-row label { font-size: 13px; color: var(--muted); flex: none; }
.tool-row input[type="range"] { flex: 1; height: 44px; accent-color: var(--accent); }
.tool-row.zoom-row { justify-content: center; }
.tool-row.zoom-row span { min-width: 60px; text-align: center; font-size: 14px; color: var(--muted); }
.segmented { gap: 0; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg {
  flex: 1;
  min-height: 46px;
  border: 0;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 15px;
  cursor: pointer;
}
.seg.active { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
