@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700;800&display=swap');

:root {
  --bg: #faf7f2;
  --card: #ffffff;
  --text: #3a3330;
  --text-soft: #8a8280;
  --accent: #f06449;
  --accent-hover: #d9533b;
  --accent-light: #fff0ed;
  --mint: #36c9a7;
  --mint-light: #e8faf4;
  --purple: #9b7bf7;
  --purple-light: #f3eeff;
  --yellow: #ffc53d;
  --yellow-light: #fff8e6;
  --border: #ece7e1;
  --shadow: 0 2px 16px rgba(60,50,40,0.06);
  --shadow-lg: 0 8px 32px rgba(60,50,40,0.10);
  --radius: 16px;
  --radius-sm: 10px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'Nunito', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ===== Header ===== */
header {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  text-align: center;
  padding: 2rem 1rem 1.8rem;
  position: relative;
  overflow: hidden;
}

header::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 4px;
  background: linear-gradient(90deg, var(--accent), var(--yellow), var(--mint), var(--purple), var(--accent));
  background-size: 200% 100%;
  animation: shimmer 4s linear infinite;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

header h1 {
  font-size: 1.9rem;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.02em;
}

.subtitle {
  color: var(--text-soft);
  font-size: 0.95rem;
  margin-top: 0.3rem;
  font-weight: 400;
}

/* ===== Layout ===== */
main {
  max-width: 960px;
  margin: 0 auto;
  padding: 2rem 1.2rem;
}

.controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin-bottom: 2rem;
}

@media (max-width: 700px) {
  .controls { grid-template-columns: 1fr; }
}

/* ===== Upload Area ===== */
.upload-area {
  border: 2.5px dashed var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  text-align: center;
  cursor: pointer;
  transition: all 0.25s ease;
  background: var(--card);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 300px;
  position: relative;
  box-shadow: var(--shadow);
}

.upload-area:hover {
  border-color: var(--accent);
  background: var(--accent-light);
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.upload-area.dragover {
  border-color: var(--mint);
  background: var(--mint-light);
  transform: scale(1.01);
}

.upload-placeholder { pointer-events: none; }

.upload-icon {
  font-size: 3.2rem;
  display: block;
  margin-bottom: 0.6rem;
  filter: grayscale(0.2);
}

.upload-placeholder p {
  font-weight: 600;
  font-size: 1rem;
  color: var(--text);
}

.hint {
  font-size: 0.82rem;
  color: var(--text-soft);
  margin-top: 0.25rem;
  font-weight: 400;
}

.preview-img {
  max-width: 100%;
  max-height: 280px;
  border-radius: var(--radius-sm);
  display: none;
  object-fit: contain;
}

/* ===== Settings Panel ===== */
.settings {
  background: var(--card);
  border-radius: var(--radius);
  padding: 1.6rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.setting-group {
  margin-bottom: 0.85rem;
}

.setting-group label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.35rem;
  font-size: 0.88rem;
  color: var(--text);
}

.setting-group select,
.setting-group input[type="number"] {
  width: 100%;
  padding: 0.55rem 0.7rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-family: inherit;
  background: var(--bg);
  color: var(--text);
  transition: border-color 0.2s, box-shadow 0.2s;
  appearance: none;
  -webkit-appearance: none;
}

.setting-group select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%238a8280' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.7rem center;
  padding-right: 2rem;
}

.setting-group select:focus,
.setting-group input[type="number"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

/* Range slider */
.setting-group input[type="range"] {
  width: 100%;
  height: 6px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--border);
  border-radius: 3px;
  outline: none;
}

.setting-group input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 3px solid var(--card);
  box-shadow: 0 1px 4px rgba(0,0,0,0.15);
  transition: transform 0.15s;
}

.setting-group input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}

/* Checkbox */
.setting-group input[type="checkbox"] {
  margin-right: 0.5rem;
  vertical-align: middle;
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.setting-group label:has(input[type="checkbox"]) {
  display: flex;
  align-items: center;
  cursor: pointer;
  font-weight: 500;
  font-size: 0.88rem;
  padding: 0.2rem 0;
}

/* ===== Advanced Toggle ===== */
.advanced-toggle {
  margin-top: 0.3rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.8rem;
  background: var(--bg);
}

.advanced-toggle summary {
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--accent);
  cursor: pointer;
  user-select: none;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.advanced-toggle summary::-webkit-details-marker { display: none; }

.advanced-toggle summary::before {
  content: '▸';
  display: inline-block;
  transition: transform 0.2s;
  font-size: 0.8rem;
}

.advanced-toggle[open] summary::before {
  transform: rotate(90deg);
}

.advanced-toggle .setting-group {
  margin-top: 0.6rem;
}

/* ===== Primary Button ===== */
.btn-primary {
  width: 100%;
  padding: 0.85rem;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 1.05rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  margin-top: 0.6rem;
  transition: all 0.2s ease;
  letter-spacing: 0.01em;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(240,100,73,0.3);
}

.btn-primary:active:not(:disabled) {
  transform: translateY(0);
}

.btn-primary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ===== Result Section ===== */
.result {
  background: var(--card);
  border-radius: var(--radius);
  padding: 1.6rem;
  box-shadow: var(--shadow);
}

.result h2 {
  margin-bottom: 1rem;
  color: var(--text);
  font-size: 1.3rem;
  font-weight: 700;
}

.result-toolbar {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.btn-small {
  padding: 0.45rem 0.9rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card);
  cursor: pointer;
  font-size: 0.85rem;
  font-family: inherit;
  font-weight: 600;
  color: var(--text);
  transition: all 0.2s;
}

.btn-small:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-light);
}

.canvas-wrapper {
  overflow: auto;
  max-height: 70vh;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
  background: #f5f3ef;
}

#beadCanvas { display: block; }

/* ===== Color Legend ===== */
.color-legend {
  margin-top: 1.5rem;
}

.color-legend h3 {
  margin-bottom: 0.8rem;
  color: var(--text);
  font-size: 1rem;
  font-weight: 700;
}

#legendItems {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--bg);
  padding: 0.35rem 0.65rem;
  border-radius: 8px;
  font-size: 0.82rem;
  border: 1px solid var(--border);
  font-weight: 500;
}

.legend-swatch {
  width: 16px;
  height: 16px;
  border-radius: 4px;
  border: 1px solid rgba(0,0,0,0.1);
  flex-shrink: 0;
}

.legend-symbol {
  font-weight: 700;
  font-size: 0.8rem;
  color: var(--text);
}

/* ===== Bead Count ===== */
.bead-count {
  margin-top: 1rem;
  padding: 1rem 1.2rem;
  background: var(--yellow-light);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 500;
  border: 1px solid #f5e6b8;
  color: #7a6520;
}

/* ===== Buy Section ===== */
.buy-section {
  margin-top: 1.2rem;
  text-align: center;
}

.btn-buy {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.8rem 2rem;
  background: var(--mint);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 1.05rem;
  font-weight: 700;
  font-family: inherit;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-buy:hover {
  background: #2ab893;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(54,201,167,0.3);
}

.buy-hint {
  margin-top: 0.5rem;
  font-size: 0.8rem;
  color: var(--text-soft);
}

/* ===== Footer ===== */
footer {
  text-align: center;
  padding: 2rem 1rem 1.5rem;
  color: var(--text-soft);
  font-size: 0.82rem;
  border-top: 1px solid var(--border);
  margin-top: 1rem;
}

.footer-links {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.4rem 1.2rem;
  margin-bottom: 0.8rem;
}

.footer-links a {
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.82rem;
  transition: color 0.2s;
}

.footer-links a:hover {
  color: var(--accent);
}

.footer-copy {
  margin-bottom: 0.3rem;
}

.footer-contact {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  margin-bottom: 0.8rem;
  font-size: 0.88rem;
  font-weight: 600;
}

.footer-contact svg {
  color: var(--accent);
  flex-shrink: 0;
}

.footer-contact a {
  color: var(--text);
  text-decoration: none;
  transition: color 0.2s;
}

.footer-contact a:hover {
  color: var(--accent);
}

.footer-copy a {
  color: var(--text-soft);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.footer-copy a:hover {
  color: var(--accent);
}

.footer-note {
  color: var(--text-soft);
  font-size: 0.75rem;
  opacity: 0.7;
  margin-top: 0.3rem;
}

/* ===== Scrollbar ===== */
.canvas-wrapper::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.canvas-wrapper::-webkit-scrollbar-track {
  background: transparent;
}

.canvas-wrapper::-webkit-scrollbar-thumb {
  background: #d5cfc8;
  border-radius: 4px;
}

.canvas-wrapper::-webkit-scrollbar-thumb:hover {
  background: #b8b0a6;
}

/* ===== Language Selector ===== */
.lang-select {
  padding: 0.35rem 0.6rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 0.8rem;
  font-family: inherit;
  font-weight: 600;
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 12 12'%3E%3Cpath fill='%238a8280' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.5rem center;
  padding-right: 1.6rem;
  transition: border-color 0.2s;
}

.lang-select:hover {
  border-color: var(--accent);
}

.lang-select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.lang-wrap {
  display: flex;
  align-items: center;
  margin-left: 0.8rem;
}

.lang-wrap-header {
  position: absolute;
  top: 1rem;
  right: 1rem;
}

/* ===== Logo Canvas ===== */
.logo-canvas {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  flex-shrink: 0;
  vertical-align: middle;
}
