/* style.css - 主样式（含响应式） */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #6d4aff;
  --primary-g: linear-gradient(135deg, #6d4aff, #a855f7);
  --bg: #f5f5f7;
  --card: #ffffff;
  --border: #e0e0e0;
  --text: #1a1a1a;
  --muted: #666;
  --radius: 16px;
  --shadow: 0 2px 12px rgba(0,0,0,.08);
  --panel-w: 300px;
}

html, body { height: 100%; font-family: -apple-system,'PingFang SC','Microsoft YaHei',sans-serif; background: var(--bg); color: var(--text); }

/* ─── Header ─────────────────────────────────────── */
header {
  position: sticky; top: 0; z-index: 100;
  background: rgba(255,255,255,.92); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px; height: 52px;
}
.logo { font-size: 1.05rem; font-weight: 700; white-space: nowrap; background: var(--primary-g); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.header-right { display: flex; align-items: center; gap: 10px; }
#activate-status { font-size: .8rem; padding: 3px 10px; border-radius: 20px; background: #f3f3f3; color: var(--muted); cursor: pointer; border: 1px solid var(--border); transition: .2s; }
#activate-status.activated { background: #e8f5e9; color: #2e7d32; border-color: #a5d6a7; }
#activate-btn { background: var(--primary-g); color:#fff; border:none; border-radius:20px; padding:4px 14px; font-size:.8rem; cursor:pointer; transition:.2s; }
#activate-btn:hover { opacity:.9; }

/* ─── Upload Section ─────────────────────────────── */
#upload-section { display:flex; align-items:center; justify-content:center; min-height: calc(100vh - 52px); padding: 20px; }
#drop-zone {
  width: 100%; max-width: 480px;
  border: 2.5px dashed var(--primary);
  border-radius: var(--radius); padding: 56px 24px;
  text-align: center; cursor: pointer;
  background: white; transition: .2s;
}
#drop-zone:hover, #drop-zone.drag-over { background: #f0ebff; border-style: solid; }
.drop-icon { font-size: 3rem; margin-bottom: 12px; }
.drop-title { font-size: 1.1rem; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.drop-sub { font-size: .85rem; color: var(--muted); }

/* ─── Work Section ───────────────────────────────── */
#work-section { display: flex; min-height: calc(100vh - 52px); }

/* Settings panel */
aside.settings-panel {
  width: var(--panel-w); flex-shrink: 0;
  background: var(--card); border-right: 1px solid var(--border);
  overflow-y: auto; padding: 16px;
  display: flex; flex-direction: column; gap: 14px;
}
.panel-block { background: var(--bg); border-radius: 12px; padding: 12px 14px; }
.panel-block h3 { font-size: .78rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 10px; }
.preview-thumb { width: 100%; border-radius: 8px; object-fit: cover; max-height: 140px; display: block; }
#change-img-btn { width:100%; margin-top:8px; padding:6px; border:1px solid var(--border); border-radius:8px; background:white; font-size:.82rem; cursor:pointer; }
#change-img-btn:hover { border-color: var(--primary); color: var(--primary); }

label { display:block; font-size:.82rem; color:var(--muted); margin-bottom:3px; margin-top:8px; }
label:first-child { margin-top:0; }
select, input[type=number], input[type=text] {
  width:100%; padding:6px 10px; border:1px solid var(--border);
  border-radius:8px; font-size:.85rem; background:white; outline:none;
  transition: border-color .2s;
}
select:focus, input:focus { border-color: var(--primary); }
#custom-size { margin-top: 6px; display:flex; gap:8px; }
#custom-size input { flex:1; }
.toggle-row { display:flex; justify-content:space-between; align-items:center; margin-top:8px; }
.toggle-row span { font-size:.85rem; }
.slider-row { display:flex; align-items:center; gap:8px; margin-top:8px; }
.slider-row input[type=range] { flex:1; accent-color: var(--primary); }
.slider-val { font-size:.8rem; color:var(--muted); min-width:30px; }
.hint { font-size:.72rem; color:var(--muted); margin:4px 0 12px; line-height:1.45; }

/* Toggle switch */
.toggle { position:relative; display:inline-block; width:36px; height:20px; }
.toggle input { opacity:0; width:0; height:0; }
.toggle-slider { position:absolute; inset:0; border-radius:20px; background:#ccc; transition:.3s; cursor:pointer; }
.toggle-slider::before { content:''; position:absolute; width:14px; height:14px; left:3px; top:3px; background:white; border-radius:50%; transition:.3s; }
.toggle input:checked + .toggle-slider { background: var(--primary); }
.toggle input:checked + .toggle-slider::before { transform: translateX(16px); }

#convert-btn {
  width:100%; padding:10px; border:none; border-radius:10px;
  background: var(--primary-g); color:#fff; font-size:.95rem; font-weight:600;
  cursor:pointer; transition:.2s;
}
#convert-btn:hover { opacity:.9; }
#convert-btn:disabled { opacity:.5; cursor:not-allowed; }

/* Progress */
#progress-wrap { background: var(--bg); border-radius:8px; padding:8px 10px; }
.progress-track { height:6px; background:#e0e0e0; border-radius:3px; overflow:hidden; }
#progress-bar { height:100%; width:0%; background: var(--primary-g); border-radius:3px; transition: width .1s; }
#progress-text { font-size:.75rem; color:var(--muted); margin-top:4px; text-align:center; }

/* Canvas area */
.canvas-area {
  flex:1; overflow:auto; padding:20px;
  display:flex; align-items:flex-start; justify-content:flex-start;
}
#preview-canvas { display:block; border-radius:8px; box-shadow: var(--shadow); background:white; flex-shrink:0; }

/* ─── Footer / Legend ────────────────────────────── */
#footer-section { background: var(--card); border-top: 1px solid var(--border); padding: 16px 20px; }
.footer-top { display:flex; align-items:center; justify-content:space-between; flex-wrap:wrap; gap:10px; margin-bottom:14px; }
.footer-title { font-size:.9rem; font-weight:700; }
#total-count { font-size:.85rem; color:var(--muted); margin-left:8px; }
.export-btns { display:flex; gap:8px; }
.btn-primary { padding:8px 18px; border:none; border-radius:10px; background: var(--primary-g); color:#fff; font-size:.85rem; font-weight:600; cursor:pointer; transition:.2s; }
.btn-primary:hover { opacity:.9; }
.btn-primary:disabled { opacity:.45; cursor:not-allowed; }
.btn-outline { padding:8px 18px; border:1.5px solid var(--primary); border-radius:10px; background:transparent; color:var(--primary); font-size:.85rem; font-weight:600; cursor:pointer; transition:.2s; }
.btn-outline:hover { background:#f0ebff; }

#legend-area { display:flex; flex-wrap:wrap; gap:8px; }
.legend-item { display:flex; align-items:center; gap:5px; background: var(--bg); border-radius:8px; padding:4px 10px; font-size:.8rem; }
.legend-swatch { width:16px; height:16px; border-radius:3px; border:1px solid rgba(0,0,0,.12); flex-shrink:0; }
.legend-code { font-weight:700; font-family:monospace; }
.legend-name { color:var(--muted); }
.legend-count { color:var(--primary); font-weight:600; }
.legend-item { cursor:pointer; transition:opacity .15s, box-shadow .15s; }
.legend-item:hover { box-shadow: 0 0 0 2px var(--primary) inset; }
.legend-item.excluded { opacity:.45; text-decoration:line-through; }
.legend-item.excluded .legend-count { color:#c62828; text-decoration:none; }
.legend-hint { font-size:.72rem; color:var(--muted); margin-top:8px; line-height:1.45; }
.link-btn { background:none; border:none; color:var(--primary); cursor:pointer; font-size:.72rem; padding:0 0 0 6px; text-decoration:underline; }

/* ─── 像素编辑 ───────────────────────────────────── */
#preview-canvas { cursor:crosshair; image-rendering:pixelated; }
#edit-modal { display:none; position:fixed; inset:0; z-index:1000; background:rgba(0,0,0,.45); align-items:center; justify-content:center; }
.modal-box.edit-box { width:min(560px,94vw); max-height:86vh; display:flex; flex-direction:column; }
.modal-box.edit-box p { margin-bottom:10px; }
.edit-modes { display:flex; gap:6px; margin-bottom:10px; }
.mode-btn { flex:1; padding:7px 6px; border:1px solid var(--border); background:#fff; border-radius:8px; font-size:.8rem; cursor:pointer; }
.mode-btn.active { border-color:var(--primary); color:var(--primary); background:#f0ebff; font-weight:600; }
.mode-btn:disabled { opacity:.4; cursor:not-allowed; }
.edit-scroll { overflow-y:auto; }
.edit-group-title { font-size:.72rem; color:var(--muted); margin:8px 0 6px; }
.edit-colors { display:grid; grid-template-columns:repeat(auto-fill,minmax(46px,1fr)); gap:6px; }
.edit-swatch { display:flex; flex-direction:column; align-items:center; gap:2px; background:none; border:none; padding:0; cursor:pointer; }
.edit-swatch .sw-color { width:100%; aspect-ratio:1; border-radius:5px; border:1px solid rgba(0,0,0,.12); }
.edit-swatch .sw-code { font-size:.58rem; line-height:1; color:#555; font-family:monospace; }
.edit-swatch.current .sw-color { outline:2px solid var(--primary); outline-offset:1px; }
.edit-swatch:hover .sw-color { box-shadow:0 0 0 2px rgba(109,74,255,.45); }
#brush-bar { position:fixed; left:50%; bottom:16px; transform:translateX(-50%); z-index:900; display:flex; align-items:center; gap:8px; background:rgba(30,30,30,.92); color:#fff; padding:8px 12px; border-radius:24px; font-size:.82rem; box-shadow:0 6px 20px rgba(0,0,0,.25); }
.brush-swatch { width:16px; height:16px; border-radius:4px; border:1px solid rgba(255,255,255,.6); }
#brush-exit { background:#fff; color:#222; border:none; border-radius:16px; padding:4px 12px; font-size:.78rem; cursor:pointer; }

/* ─── Activation Modal ───────────────────────────── */
#activate-modal {
  display:none; position:fixed; inset:0; z-index:1000;
  background:rgba(0,0,0,.45); align-items:center; justify-content:center;
}
.modal-box {
  background:white; border-radius:20px; padding:28px 24px;
  width: min(380px, 92vw); box-shadow:0 8px 40px rgba(0,0,0,.18);
}
.modal-box h2 { font-size:1.1rem; margin-bottom:6px; }
.modal-box p { font-size:.85rem; color:var(--muted); margin-bottom:16px; }
.modal-box input { margin-bottom:10px; letter-spacing:.08em; font-family:monospace; }
.modal-actions { display:flex; gap:8px; }
.modal-actions button { flex:1; padding:9px; border-radius:10px; font-size:.88rem; font-weight:600; cursor:pointer; border:none; transition:.2s; }
#activate-submit { background: var(--primary-g); color:#fff; }
#activate-submit:hover { opacity:.9; }
#activate-submit:disabled { opacity:.5; }
#activate-close { background:#f3f3f3; color:var(--text); }
#activate-close:hover { background:#e8e8e8; }
.activate-msg { font-size:.82rem; margin-top:8px; min-height:18px; }
.activate-msg.ok { color:#2e7d32; }
.activate-msg.err { color:#c62828; }

/* ─── Toast 提示 ─────────────────────────────────── */
#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(80px);
  background: rgba(30,30,30,.92); color: #fff; padding: 10px 20px;
  border-radius: 24px; font-size: .85rem; white-space: nowrap;
  pointer-events: none; z-index: 2000;
  transition: transform .25s ease, opacity .25s ease; opacity: 0;
}
#toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
@media (max-width: 767px) {
  :root { --panel-w: 100%; }
  #work-section { flex-direction: column; }

  aside.settings-panel {
    width: 100%; border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 48px; overflow: hidden;
    transition: max-height .35s ease;
    position: relative;
  }
  aside.settings-panel.drawer-open { max-height: 70vh; overflow-y: auto; }

  .drawer-handle {
    display: flex; align-items: center; justify-content: center;
    width: 100%; padding: 10px; border: none; background: var(--bg);
    font-size: .82rem; color: var(--primary); cursor: pointer;
    font-weight: 600; border-bottom: 1px solid var(--border);
  }

  .canvas-area { padding: 12px; touch-action: pan-x pan-y; }
  #preview-canvas { transform-origin: top left; }
  #footer-section { padding: 12px; }
  .footer-top { flex-direction: column; align-items: flex-start; }
  .export-btns { width: 100%; }
  .btn-primary, .btn-outline { flex: 1; text-align: center; padding: 10px; }
}
@media (min-width: 768px) {
  .drawer-handle { display: none; }
}
@media (min-width: 768px) and (max-width: 1023px) {
  :root { --panel-w: 240px; }
}
