/* ============== BASE ============== */
* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: "Segoe UI", "PingFang TC", "Microsoft JhengHei", -apple-system, BlinkMacSystemFont, sans-serif;
  background: #f5f6fa;
  color: #2d3436;
  line-height: 1.6;
  font-size: 14px;
}
.container { max-width: 1400px; margin: 0 auto; padding: 0 20px; }
.hint { color: #95a5a6; font-size: 12px; margin-top: 4px; }
.hint.safe { color: #27ae60; }
.link { color: #6c5ce7; cursor: pointer; text-decoration: underline; }
.link-sm { color: #6c5ce7; font-size: 13px; text-decoration: none; }
.link-sm:hover { text-decoration: underline; }
button { font-family: inherit; cursor: pointer; border: none; background: none; }
input, select { font-family: inherit; font-size: 14px; }

/* ============== HEADER ============== */
.site-header {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 18px 0;
  box-shadow: 0 2px 12px rgba(102,126,234,0.2);
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-inner { display: flex; justify-content: space-between; align-items: center; }
.brand { display: flex; align-items: center; gap: 14px; }
.logo {
  width: 48px; height: 48px;
  background: white;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}
.brand h1 { font-size: 20px; font-weight: 700; }
.subtitle { font-size: 13px; opacity: 0.9; }
.top-nav a {
  color: white;
  text-decoration: none;
  margin-left: 24px;
  font-weight: 500;
  opacity: 0.9;
  transition: opacity 0.2s;
}
.top-nav a:hover { opacity: 1; text-decoration: underline; }

/* ============== HERO ============== */
.hero {
  background: white;
  padding: 28px 0 16px;
  border-bottom: 1px solid #eee;
}
.hero-desc {
  font-size: 15px;
  color: #555;
  max-width: 1000px;
  margin-bottom: 18px;
  line-height: 1.8;
}
.badge {
  display: inline-block;
  background: linear-gradient(135deg, #fd79a8, #e84393);
  color: white;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  margin-right: 4px;
}
.mode-switch { display: flex; gap: 10px; }
.mode-btn {
  padding: 12px 24px;
  border: 2px solid #dfe6e9;
  background: white;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  color: #636e72;
  transition: all 0.2s;
}
.mode-btn:hover { border-color: #6c5ce7; color: #6c5ce7; }
.mode-btn.active {
  background: linear-gradient(135deg, #6c5ce7, #a29bfe);
  color: white;
  border-color: transparent;
  box-shadow: 0 4px 12px rgba(108,92,231,0.3);
}

/* ============== APP LAYOUT (Two-Column: Left Sidebar + Right Main) ============== */
.app { padding: 24px 0; }
.app-grid {
  display: grid;
  grid-template-columns: minmax(280px, 320px) 1fr; /* 左側邊欄固定寬度，右側主區域佔滿剩餘 */
  gap: 24px;
  align-items: start;
  min-height: 0;
}
.main-area { display: flex; flex-direction: column; gap: 18px; min-width: 0; }

/* ============== PANELS ============== */
.panel {
  background: white;
  border-radius: 14px;
  padding: 20px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.05);
  border: 1px solid #eee;
}
.panel h3 {
  font-size: 16px;
  margin-bottom: 14px;
  color: #2d3436;
}
.panel-title-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }

/* ============== UPLOAD ============== */
.dropzone {
  border: 2px dashed #b2bec3;
  border-radius: 12px;
  padding: 40px 20px;
  text-align: center;
  transition: all 0.25s;
  background: #fafbfc;
}
.dropzone:hover, .dropzone.dragover {
  border-color: #6c5ce7;
  background: #f0edff;
  transform: scale(1.01);
}
.dz-icon { font-size: 48px; margin-bottom: 12px; }

/* ============== CANVAS ============== */
.canvas-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.canvas-actions { display: flex; gap: 6px; }
.btn-small {
  padding: 6px 12px;
  border: 1px solid #dfe6e9;
  background: white;
  border-radius: 6px;
  font-size: 13px;
  transition: all 0.15s;
}
.btn-small:hover { background: #6c5ce7; color: white; border-color: #6c5ce7; }
.canvas-wrapper {
  background:
    linear-gradient(45deg, #ddd 25%, transparent 25%),
    linear-gradient(-45deg, #ddd 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #ddd 75%),
    linear-gradient(-45deg, transparent 75%, #ddd 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
  background-color: white;
  border-radius: 10px;
  padding: 20px;
  min-height: 500px;          /* 主區域預覽區高度加大 */
  display: block;
  overflow: auto;
  position: relative;
  cursor: crosshair;
}
.canvas-wrapper.is-panning {
  cursor: grabbing;
}
.empty-state {
  text-align: center;
  color: #b2bec3;
}
.empty-state p:first-child { font-size: 18px; font-weight: 600; }
#beadCanvas {
  max-width: 100%;
  display: block;
  image-rendering: pixelated;
  cursor: crosshair;
  background: white;
  margin: 0 auto;
}

/* ============== TEMPLATES ============== */
.templates-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}
.template-item {
  aspect-ratio: 1;
  border-radius: 8px;
  cursor: pointer;
  overflow: hidden;
  position: relative;
  border: 2px solid transparent;
  transition: all 0.2s;
}
.template-item:hover { border-color: #6c5ce7; transform: scale(1.03); }
.template-item canvas { width: 100%; height: 100%; display: block; image-rendering: pixelated; }
.template-item .tmpl-name {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  background: rgba(0,0,0,0.6);
  color: white;
  font-size: 11px;
  padding: 3px 6px;
}

/* ============== SIDEBAR (Left) ============== */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-right: 4px;
}
/* 上傳面板在側邊欄中的精簡樣式 */
.upload-side-panel .dropzone {
  padding: 24px 12px;
}
.upload-side-panel .dz-icon { font-size: 36px; margin-bottom: 8px; }
.upload-side-panel .dropzone-inner p { font-size: 13px; }
.side-panel {
  background: white;
  border-radius: 12px;
  border: 1px solid #eee;
  overflow: visible;
  flex-shrink: 0;
  position: relative;
}

/* ============== 浮動面板模式 ============== */
.side-panel.floating {
  position: fixed;
  z-index: 10000;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
  width: 300px;
  max-width: 90vw;
  max-height: 80vh;
  overflow-y: auto;
}
.side-panel.floating .sp-title {
  cursor: move;
  background: linear-gradient(135deg, #6c5ce7, #a29bfe);
  color: white;
}
.side-panel.floating .sp-title:hover {
  background: linear-gradient(135deg, #5b4bdc, #8f88f5);
}
.side-panel.floating .sp-title::after {
  color: rgba(255,255,255,0.7);
}
.side-panel.floating .sp-body {
  max-height: 60vh;
  overflow-y: auto;
}

/* 浮動還原按鈕 */
.float-restore-btn {
  position: absolute;
  top: 8px;
  right: 36px;
  font-size: 11px;
  background: rgba(255,255,255,0.25);
  color: white;
  border: 1px solid rgba(255,255,255,0.4);
  border-radius: 4px;
  padding: 2px 8px;
  cursor: pointer;
  z-index: 10;
  transition: background 0.15s;
}
.float-restore-btn:hover {
  background: rgba(255,255,255,0.4);
}

/* 浮動預留位（面板浮出後留在原位的佔位符） */
.side-panel-placeholder {
  border: 2px dashed #dfe6e9;
  border-radius: 12px;
  padding: 16px;
  text-align: center;
  color: #b2bec3;
  font-size: 12px;
  background: #f8f9fa;
  margin-bottom: 0;
}
.sp-title {
  font-size: 14px;
  font-weight: 700;
  padding: 14px 16px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 0;
  transition: background 0.15s;
  user-select: none;
}
.sp-title:hover { background: #f5f6fa; }
.sp-title::after { content: "▾"; font-size: 10px; transition: transform 0.2s; color: #95a5a6; }
.side-panel.collapsed .sp-title::after { transform: rotate(-90deg); }
.sp-body {
  padding: 0 16px 14px;
  overflow: visible;
  transition: max-height 0.3s ease, padding 0.3s ease, opacity 0.2s ease;
  max-height: 1000px;
  opacity: 1;
}
.side-panel.collapsed .sp-body {
  max-height: 0;
  padding-top: 0;
  padding-bottom: 0;
  opacity: 0;
  overflow: hidden;
}

.side-panel select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #dfe6e9;
  border-radius: 6px;
  margin-bottom: 6px;
  background: white;
  cursor: pointer;
  max-width: 100%;
}
/* Ensure dropdowns and tooltips aren't clipped */
.side-panel select,
.side-panel input[type="number"],
.tool-btn,
.dither-btn,
.btn-primary,
.btn-outline,
.btn-ghost {
  position: relative;
  z-index: 1;
}

/* ============== SLIDERS ============== */
.slider-row { display: flex; align-items: center; gap: 10px; margin: 8px 0; }
.slider-row input[type="range"] { flex: 1; accent-color: #6c5ce7; }
.slider-row input[type="number"] {
  width: 60px;
  padding: 4px 6px;
  border: 1px solid #dfe6e9;
  border-radius: 6px;
}
.slider-row label { min-width: 50px; font-size: 13px; color: #636e72; }
.slider-row span { min-width: 40px; text-align: right; font-size: 12px; color: #95a5a6; }

/* ============== DITHER BUTTONS ============== */
.dither-options { display: flex; gap: 6px; margin-bottom: 6px; }
.dither-btn {
  flex: 1;
  padding: 8px;
  border: 1px solid #dfe6e9;
  background: white;
  border-radius: 6px;
  font-size: 13px;
  transition: all 0.15s;
}
.dither-btn:hover { border-color: #6c5ce7; color: #6c5ce7; }
.dither-btn.active {
  background: #6c5ce7;
  color: white;
  border-color: #6c5ce7;
}

/* ============== BUTTONS ============== */
.btn-primary {
  background: linear-gradient(135deg, #6c5ce7, #a29bfe);
  color: white;
  padding: 10px 16px;
  border-radius: 8px;
  font-weight: 600;
  transition: transform 0.15s, box-shadow 0.15s;
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(108,92,231,0.3); }
.btn-outline {
  background: white;
  color: #6c5ce7;
  border: 1.5px solid #6c5ce7;
  padding: 10px 16px;
  border-radius: 8px;
  font-weight: 600;
  transition: all 0.15s;
}
.btn-outline:hover { background: #6c5ce7; color: white; }
.btn-ghost {
  background: #f5f6fa;
  color: #636e72;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  transition: all 0.15s;
}
.btn-ghost:hover { background: #dfe6e9; }
.btn-block { width: 100%; margin-top: 8px; }

/* ============== EDITOR TOOLS ============== */
.tools-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin: 8px 0;
}
.tool-btn {
  width: 38px; height: 38px;
  border-radius: 8px;
  border: 1.5px solid #dfe6e9;
  background: white;
  font-size: 18px;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s;
}
.tool-btn:hover { border-color: #6c5ce7; }
.tool-btn.active { background: #6c5ce7; border-color: #6c5ce7; }
.color-info { margin-top: 8px; }
.current-color {
  display: flex; align-items: center; gap: 8px;
  padding: 6px;
  background: #f5f6fa;
  border-radius: 6px;
}
.current-color > div {
  width: 24px; height: 24px;
  border-radius: 50%;
  border: 2px solid white;
  box-shadow: 0 0 0 1px #dfe6e9;
}
/* ============== COLOR PALETTE (選色盤) ============== */
.palette-row {
  display: flex; align-items: center; gap: 8px;
  margin-top: 10px;
  padding: 8px;
  background: #f5f6fa;
  border-radius: 6px;
}
.palette-label {
  font-size: 12px;
  color: #636e72;
  font-weight: 600;
}
#customColorPicker {
  width: 36px;
  height: 28px;
  border: 1px solid #dfe6e9;
  border-radius: 4px;
  cursor: pointer;
  padding: 0;
  background: white;
}
#customColorBtn {
  padding: 4px 10px;
  font-size: 12px;
}

.history-row {
  display: flex; align-items: center; gap: 8px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid #eee;
}

/* ============== PROGRESS ============== */
.progress-bar-wrap { margin-top: 10px; }
.progress-bar {
  height: 12px;
  background: #dfe6e9;
  border-radius: 6px;
  overflow: hidden;
  margin-bottom: 6px;
}
#progressFill {
  height: 100%;
  background: linear-gradient(90deg, #00b894, #55efc4);
  width: 0%;
  transition: width 0.3s;
}
.progress-text { text-align: center; }

/* ============== CHECKBOX ============== */
.checkbox-row {
  display: flex; align-items: center; gap: 8px;
  margin: 8px 0;
  font-size: 13px;
  color: #636e72;
}

/* ============== EXPORT SIZE ============== */
.export-size-row {
  margin: 10px 0;
  padding: 10px;
  background: #f5f6fa;
  border-radius: 8px;
}
.export-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: #2d3436;
  margin-bottom: 6px;
}
.export-size-row select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #dfe6e9;
  border-radius: 6px;
  background: white;
  cursor: pointer;
  font-size: 13px;
}
.export-size-row .hint {
  margin-top: 6px;
  color: #6c5ce7;
  font-weight: 500;
}

/* ============== SECTIONS ============== */
.section-title {
  font-size: 28px;
  font-weight: 800;
  text-align: center;
  margin-bottom: 32px;
  color: #2d3436;
  position: relative;
}
.section-title.left { text-align: left; margin-bottom: 16px; }
.section-title::after {
  content: "";
  display: block;
  width: 60px; height: 4px;
  background: linear-gradient(90deg, #6c5ce7, #a29bfe);
  margin: 12px auto 0;
  border-radius: 2px;
}
.section-title.left::after { margin-left: 0; }

/* HOW IT WORKS */
.how-it-works { padding: 60px 0; background: white; }
.steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 24px; }
.step {
  text-align: center;
  padding: 30px 20px;
  border-radius: 14px;
  background: linear-gradient(135deg, #f5f6fa, #dfe6e9);
  transition: transform 0.2s;
}
.step:hover { transform: translateY(-4px); }
.step-num {
  width: 60px; height: 60px;
  margin: 0 auto 16px;
  background: linear-gradient(135deg, #6c5ce7, #a29bfe);
  color: white;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 28px;
  font-weight: 800;
  box-shadow: 0 4px 12px rgba(108,92,231,0.3);
}
.step h3 { font-size: 18px; margin-bottom: 8px; }
.step p { color: #636e72; font-size: 14px; }

/* FEATURES */
.features { padding: 60px 0; background: #f5f6fa; }
.features-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 20px; }
.feature {
  background: white;
  padding: 24px;
  border-radius: 12px;
  border: 1px solid #eee;
  transition: all 0.2s;
}
.feature:hover { transform: translateY(-3px); box-shadow: 0 8px 24px rgba(0,0,0,0.08); }
.f-icon {
  font-size: 32px;
  margin-bottom: 12px;
  width: 56px; height: 56px;
  background: linear-gradient(135deg, #f0edff, #e8e3ff);
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
}
.feature h3 { font-size: 16px; margin-bottom: 6px; }
.feature p { color: #636e72; font-size: 13px; }

/* BEADS INFO */
.beads-info { padding: 60px 0; background: white; }
.two-col { display: grid; grid-template-columns: 1.3fr 1fr; gap: 40px; align-items: center; }
.beads-info p { margin-bottom: 14px; color: #636e72; line-height: 1.8; }
.bead-visual {
  background: linear-gradient(135deg, #f0edff, #e8e3ff);
  border-radius: 16px;
  padding: 30px;
  min-height: 200px;
  display: flex; align-items: center; justify-content: center;
}
.bead-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  width: 100%;
}
.bead-row::before, .bead-row::after {
  content: "";
  display: none;
}
.bead-row { display: grid; grid-template-columns: repeat(5, 1fr); grid-template-rows: repeat(3, 1fr); gap: 8px; }
.bead-row > * {
  aspect-ratio: 1;
  background: var(--c, #ccc);
  border-radius: 50%;
  box-shadow: inset -3px -3px 6px rgba(0,0,0,0.2), inset 3px 3px 6px rgba(255,255,255,0.4);
}
.bead-row > :nth-child(1) { --c: var(--c1); }
.bead-row > :nth-child(2) { --c: var(--c2); }
.bead-row > :nth-child(3) { --c: var(--c3); }
.bead-row > :nth-child(4) { --c: var(--c4); }
.bead-row > :nth-child(5) { --c: var(--c5); }
.bead-row > :nth-child(6) { --c: var(--c2); }
.bead-row > :nth-child(7) { --c: var(--c3); }
.bead-row > :nth-child(8) { --c: var(--c4); }
.bead-row > :nth-child(9) { --c: var(--c5); }
.bead-row > :nth-child(10) { --c: var(--c1); }
.bead-row > :nth-child(11) { --c: var(--c3); }
.bead-row > :nth-child(12) { --c: var(--c5); }
.bead-row > :nth-child(13) { --c: var(--c1); }
.bead-row > :nth-child(14) { --c: var(--c2); }
.bead-row > :nth-child(15) { --c: var(--c4); }

/* MORE TOOLS */
.more-tools { padding: 60px 0; background: #f5f6fa; }
.tools-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 20px; }
.tool-card {
  background: white;
  border-radius: 12px;
  padding: 24px;
  text-decoration: none;
  color: inherit;
  border: 1px solid #eee;
  transition: all 0.2s;
  display: block;
}
.tool-card:hover { transform: translateY(-4px); box-shadow: 0 8px 24px rgba(0,0,0,0.08); }
.t-icon { font-size: 40px; margin-bottom: 10px; }
.tool-card h3 { font-size: 17px; margin-bottom: 4px; }
.tool-card p { color: #636e72; font-size: 13px; }

/* FAQ */
.faq { padding: 60px 0; background: white; }
.faq-list { max-width: 900px; margin: 0 auto; }
.faq details {
  border: 1px solid #eee;
  border-radius: 10px;
  margin-bottom: 10px;
  padding: 16px 20px;
  background: #fafbfc;
  transition: all 0.2s;
}
.faq details[open] { background: white; box-shadow: 0 2px 8px rgba(0,0,0,0.04); }
.faq summary {
  font-weight: 600;
  cursor: pointer;
  list-style: none;
  font-size: 15px;
}
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after {
  content: "＋";
  float: right;
  color: #6c5ce7;
  transition: transform 0.2s;
}
.faq details[open] summary::after { content: "－"; }
.faq p { margin-top: 10px; color: #636e72; line-height: 1.7; }

/* FOOTER */
.site-footer {
  background: #2d3436;
  color: #b2bec3;
  padding: 30px 0;
  text-align: center;
}
.site-footer p { margin: 4px 0; font-size: 13px; }
.site-footer .hint { color: #636e72; }

/* ============== RESPONSIVE ============== */
@media (max-width: 1200px) {
  .app-grid { grid-template-columns: minmax(260px, 300px) 1fr; gap: 16px; }
}
@media (max-width: 1024px) {
  .app-grid { grid-template-columns: 1fr; }
  .sidebar { margin-bottom: 20px; }
  .two-col { grid-template-columns: 1fr; }
}
@media (max-width: 700px) {
  .steps { grid-template-columns: 1fr; }
  .top-nav { display: none; }
  .templates-grid { grid-template-columns: repeat(3, 1fr); }
  .app { padding: 16px 0; }
  .panel { padding: 14px; }
  .side-panel { flex-shrink: 0; }
}

/* ============== GUESS WHO (猜猜我是誰) ============== */
.guess-countdown {
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  background: #6c5ce7;
  padding: 4px 10px;
  border-radius: 6px;
  animation: guess-pulse 1s ease-in-out infinite;
}
@keyframes guess-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}
#guessWhoBtn.active {
  background: #e17055;
  color: white;
  border-color: #e17055;
}

/* ============== MAGNIFIER (放大鏡) ============== */
.magnifier {
  position: fixed;
  width: 100px;
  height: 100px;
  border: 2px solid #6c5ce7;
  border-radius: 50%;
  overflow: hidden;
  pointer-events: none;
  z-index: 9999;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
  background: white;
  /* transform: 中心點對齊游標後再上移（放大鏡顯示在游標上方） */
  transform: translate(-50%, calc(-100% - 16px));
}
.magnifier canvas {
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  display: block;
}
.magnifier-color-info {
  position: absolute;
  bottom: -22px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.8);
  color: white;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-family: monospace;
  white-space: nowrap;
}

/* ============== ORIGINAL IMAGE BUTTON (原圖按鈕) ============== */
#showOriginalBtn {
  font-size: 12px;
  padding: 6px 10px;
}
#showOriginalBtn.active {
  background: #6c5ce7;
  color: white;
  border-color: #6c5ce7;
}

/* ============== CUSTOM CURSOR FOR PICKER TOOL ============== */
#beadCanvas.picker-active {
  cursor: none;
}
