@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@400;600;700&family=Cormorant+Garamond:ital,wght@0,300;0,400;0,600;1,300;1,400;1,600&family=EB+Garamond:ital,wght@0,400;0,500;1,400;1,500&family=Noto+Serif+TC:wght@200;300;400;500;600&display=swap');

/* ─── Reset & Base ─────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* ── Colour ─────────────────────────────── */
  --bg:            #f5f0e8;
  --bg-warm:       #ede8dd;
  --bg-panel:      #ffffff;
  --bg-header:     rgba(250,246,239,0.97);
  --border:        rgba(160,135,100,0.22);
  --border-strong: rgba(140,115,80,0.45);
  --gold:          #aa7820;
  --gold-light:    #d4a640;
  --gold-pale:     #f0d898;
  --purple:        #5a3090;
  --purple-light:  #8a60c8;
  --text-primary:  #251810;
  --text-strong:   #1a0e06;
  --text-secondary:#7a6248;
  --text-muted:    #b0997a;
  --radius-lg:     18px;
  --radius-md:     12px;
  --radius-sm:     7px;
  --shadow-card:   0 2px 20px rgba(120,80,30,0.10), 0 1px 4px rgba(80,50,15,0.08);

  /* ── Typography — Font Families ────────── */
  /* Brand logo & Roman numerals / Cinzel — classical inscription, premium */
  --f-brand:   'Cinzel', 'Noto Serif TC', serif;
  /* Decorative headings, italic accents — Cormorant, lush & editorial */
  --f-decor:   'Cormorant Garamond', 'Noto Serif TC', serif;
  /* Body copy (EN) — EB Garamond, warm old-style, easy to read */
  --f-body-en: 'EB Garamond', serif;
  /* Body copy (ZH) — Noto Serif TC light, refined & readable */
  --f-body-zh: 'Noto Serif TC', serif;
  /* Default: ZH-first with EN fallback */
  --f-body:    'EB Garamond', 'Noto Serif TC', serif;

  /* ── Typography — Scale ─────────────────── */
  --ts-xl:   1.15rem;  /* brand logo                    */
  --ts-lg:   0.96rem;  /* panel section headers          */
  --ts-md:   0.86rem;  /* category names, bead names     */
  --ts-base: 0.80rem;  /* general body, steps            */
  --ts-sm:   0.74rem;  /* small labels, chips, hints     */
  --ts-xs:   0.67rem;  /* micro labels, panel titles     */

  /* ── Typography — Weight ────────────────── */
  --fw-thin:    200;
  --fw-light:   300;
  --fw-regular: 400;
  --fw-medium:  500;
  --fw-semi:    600;
  --fw-bold:    700;

  /* ── Typography — Line-height ───────────── */
  --lh-tight:   1.25;
  --lh-snug:    1.45;
  --lh-normal:  1.65;
  --lh-relaxed: 1.85;

  /* ── Typography — Letter-spacing ────────── */
  --ls-tight:  -0.01em;
  --ls-normal:  0.01em;
  --ls-wide:    0.06em;
  --ls-wider:   0.12em;
  --ls-widest:  0.18em;

  font-size: 16px;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text-primary);
  font-family: var(--f-body);
  font-size: var(--ts-base);
  line-height: var(--lh-normal);
}
/* Desktop: lock viewport to prevent scroll */
@media (min-width: 1025px) {
  html, body { overflow: hidden; }
}


/* ─── App Shell ────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  background:
    radial-gradient(ellipse at 10% 0%, rgba(90,48,144,0.05) 0%, transparent 55%),
    radial-gradient(ellipse at 90% 100%, rgba(170,120,32,0.06) 0%, transparent 55%),
    var(--bg);
}

/* ─── Top Bar ──────────────────────────────────────────── */
#topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 10px 28px;
  background: var(--bg-header);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 12px rgba(120,80,30,0.10);
  z-index: 50;
  flex-shrink: 0;
  justify-content: center;
}

/* Push controls to center by giving logo and langToggle equal flex basis */
#topbar #logo { margin-right: auto; }
#topbar #langToggle { margin-left: auto; }

#logo {
  font-family: var(--f-brand);
  font-size: var(--ts-xl);
  font-weight: var(--fw-bold);
  letter-spacing: var(--ls-wide);
  background: linear-gradient(135deg, var(--gold) 0%, var(--purple) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  white-space: nowrap;
}

.ctrl-group {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 6px 16px;
  box-shadow: var(--shadow-card);
}

.ctrl-label {
  font-family: var(--f-decor);
  font-size: 0.85rem;
  font-weight: var(--fw-regular);
  font-style: italic;
  color: var(--text-muted);
  letter-spacing: var(--ls-wide);
  white-space: nowrap;
}

.ctrl-value {
  font-family: var(--f-brand);
  font-size: 0.90rem;
  color: var(--gold);
  min-width: 80px;
  text-align: center;
  font-weight: var(--fw-semi);
  letter-spacing: var(--ls-normal);
}

/* Slider */
input[type=range] {
  -webkit-appearance: none;
  appearance: none;
  height: 3px;
  border-radius: 2px;
  background: linear-gradient(to right, var(--gold) var(--pct, 40%), rgba(160,135,100,0.25) var(--pct, 40%));
  cursor: pointer;
  outline: none;
  width: 120px;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: radial-gradient(circle at 38% 32%, var(--gold-pale), var(--gold));
  box-shadow: 0 1px 6px rgba(170,120,32,0.5);
  cursor: grab;
  transition: transform 0.15s, box-shadow 0.15s;
}
input[type=range]::-webkit-slider-thumb:active {
  transform: scale(1.22);
  cursor: grabbing;
}

/* Bead size select */
#beadSizeSelect {
  background: transparent;
  border: none;
  color: var(--gold);
  font-family: var(--f-brand);
  font-size: 0.90rem;
  font-weight: var(--fw-semi);
  cursor: pointer;
  outline: none;
  padding: 2px 4px;
  letter-spacing: var(--ls-normal);
}
#beadSizeSelect option { background: #faf7f2; color: var(--text-primary); font-family: var(--f-body); }

/* Language toggle */
#langToggle {
  display: flex;
  align-items: center;
  background: var(--bg-panel);
  border: 1px solid var(--border-strong);
  border-radius: 20px;
  overflow: hidden;
  box-shadow: var(--shadow-card);
  flex-shrink: 0;
}
.lang-btn {
  padding: 5px 16px;
  font-family: var(--f-brand);
  font-size: 0.78rem;
  font-weight: var(--fw-bold);
  letter-spacing: var(--ls-wide);
  color: var(--text-muted);
  cursor: pointer;
  border: none;
  background: transparent;
  transition: all 0.2s;
}
.lang-btn.active {
  background: linear-gradient(135deg, var(--purple), #3d1f6e);
  color: #fff;
}
.lang-btn:hover:not(.active) { color: var(--text-primary); }

/* ─── Main Layout ──────────────────────────────────────── */
#main {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ─── Stats Panel (between guide and canvas) ───────────── */
#statsPanel {
  width: 190px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: rgba(248,244,238,0.55);
  overflow-y: auto;
  overflow-x: hidden;
}

.sp-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px;
  padding: 12px 12px 7px;
  border-bottom: 1px solid rgba(170,120,32,0.14);
  flex-shrink: 0;
}

.sp-title {
  font-family: 'Cinzel', serif;
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--gold);
  white-space: nowrap;
}

.sp-count {
  font-family: 'Cinzel', serif;
  font-size: 0.66rem;
  color: var(--text-muted);
  white-space: nowrap;
}

#beadStats {
  display: flex;
  flex-direction: column;
  padding: 6px 0 8px;
  overflow-y: auto;
  flex: 1;
}

.stats-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px 5px 12px;
  border-bottom: 1px solid rgba(170,120,32,0.07);
  transition: background 0.12s;
}
.stats-row:last-child { border-bottom: none; }
.stats-row:hover { background: rgba(90,48,144,0.05); }

.stats-row-cnt {
  font-family: 'Cinzel', serif;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--purple-light);
  min-width: 16px;
  text-align: center;
  flex-shrink: 0;
}

.stats-row-name {
  font-family: var(--f-body);
  font-size: var(--ts-sm);
  color: var(--text-primary);
  line-height: var(--lh-snug);
  word-break: break-all;
  font-weight: var(--fw-light);
}

/* ─── Left Hint Panel ──────────────────────────────────── */

/* Outer wrapper: panel + tab button sit side by side */
#leftHintOuter {
  display: flex;
  align-items: stretch;
  flex-shrink: 0;
}

/* The panel itself */
#leftHint {
  width: 248px;            /* 1.5× previous 165px */
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  overflow: hidden;
  background: rgba(245,240,232,0.60);
  transition: width 0.28s ease;
  border-right: 1px solid var(--border);
}

/* Collapsed: panel vanishes completely — zero width, all content hidden */
#leftHint.collapsed {
  width: 0;
  border-right: none;
}

/* Panel header row */
#leftHintHeader {
  display: flex;
  align-items: center;
  padding: 12px 16px 8px;
  border-bottom: 1px solid rgba(170,120,32,0.15);
  flex-shrink: 0;
  min-width: 248px;   /* prevents squish during CSS transition */
}

.lh-panel-title {
  font-family: var(--f-brand);
  font-size: var(--ts-xs);
  font-weight: var(--fw-bold);
  letter-spacing: var(--ls-widest);
  text-transform: uppercase;
  color: var(--gold);
  white-space: nowrap;
}

/* Toggle TAB — lives OUTSIDE the panel on its right edge, always visible */
#leftToggleBtn {
  width: 26px;
  flex-shrink: 0;
  align-self: stretch;
  border: 1px solid var(--border-strong);
  border-left: none;
  border-radius: 0 8px 8px 0;
  background: rgba(252,248,242,0.96);
  color: var(--purple);
  font-family: var(--f-brand);
  font-size: 0.68rem;
  line-height: 1;
  cursor: pointer;
  padding: 10px 4px;
  transition: background 0.15s, color 0.15s;
  writing-mode: vertical-lr;
  letter-spacing: var(--ls-wider);
  box-shadow: 2px 0 8px rgba(120,80,30,0.07);
  display: flex;
  align-items: center;
  justify-content: center;
}
#leftToggleBtn:hover {
  background: rgba(90,48,144,0.10);
  color: var(--purple);
}

/* Icon + content area */
#leftHint .lh-icon {
  font-size: 2.0rem;
  opacity: 0.32;
  animation: floatPulse 3.5s ease-in-out infinite;
  text-align: center;
  padding: 10px 0 4px;
  white-space: nowrap;
}

/* Usage guide */
.lh-guide {
  padding: 4px 18px 18px;
  overflow-y: auto;
  flex: 1;
  min-width: 248px;   /* prevents content squish during animation */
}

.lh-guide-title {
  font-family: var(--f-brand);
  font-size: var(--ts-xs);
  font-weight: var(--fw-bold);
  letter-spacing: var(--ls-widest);
  text-transform: uppercase;
  color: var(--gold);
  text-align: center;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(170,120,32,0.18);
  margin-bottom: 12px;
}

.lh-step {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  margin-bottom: 12px;
  line-height: var(--lh-normal);
}

.lh-step-num {
  font-family: var(--f-brand);
  font-size: var(--ts-sm);
  color: var(--purple-light);
  font-weight: var(--fw-bold);
  flex-shrink: 0;
  margin-top: 2px;
}

.lh-step span:last-child {
  font-family: var(--f-body);
  font-size: var(--ts-sm);
  font-weight: var(--fw-light);
  color: var(--text-secondary);
  line-height: var(--lh-relaxed);
  white-space: normal;
}

.lh-step b {
  color: var(--text-primary);
  font-weight: var(--fw-medium);
}

@keyframes floatPulse {
  0%, 100% { transform: translateY(0); opacity: 0.32; }
  50%       { transform: translateY(-5px); opacity: 0.50; }
}



/* ─── Canvas Section ───────────────────────────────────── */
#canvasSection {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;   /* canvas is anchored at top — does NOT shift */
  padding: 36px 24px 0;          /* breathing room above canvas (pushed down slightly) */
  position: relative;
  min-width: 0;
  overflow-y: auto;
  background:
    radial-gradient(ellipse at 50% 50%, rgba(230,220,200,0.6) 30%, var(--bg) 100%);
}

#trayWrapper {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

#braceletCanvas {
  display: block;
  cursor: crosshair;
  filter: drop-shadow(0 12px 40px rgba(60,30,10,0.35)) drop-shadow(0 4px 12px rgba(60,30,10,0.25));
  touch-action: none;  /* prevent browser gestures on the canvas */
}

/* Hint below canvas */
#canvasHint {
  margin-top: 10px;
  font-size: 0.74rem;
  color: var(--text-muted);
  letter-spacing: 0.07em;
  text-align: center;
  font-family: 'Cormorant Garamond', serif;
  font-style: italic;
}

/* ─── Canvas Bottom Zone ───────────────────────────────── */
/* hint + clear button below the canvas */
#canvasBottom {
  width: 100%;
  max-width: 520px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  min-height: 72px;   /* hint line + clear button */
  padding-bottom: 14px;
}

/* ─── Clear Tray Button ────────────────────────────────── */
#clearTrayBtn {
  margin-top: 10px;
  padding: 8px 32px;
  background: rgba(120,80,30,0.07);
  border: 1px solid rgba(140,100,40,0.28);
  border-radius: 30px;
  color: var(--text-secondary);
  font-family: 'Noto Serif TC', serif;
  font-size: 0.82rem;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 2px 8px rgba(120,80,30,0.06);
  flex-shrink: 0;   /* never gets squeezed by stats chips */
}
#clearTrayBtn:hover {
  background: rgba(160,40,40,0.10);
  border-color: rgba(160,40,40,0.35);
  color: #b04040;
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(160,40,40,0.12);
}
#clearTrayBtn:active { transform: translateY(0); }

/* ─── Bead Tooltip ─────────────────────────────────────── */
#beadTooltip {
  position: fixed;
  background: rgba(255,252,245,0.97);
  border: 1px solid var(--gold-light);
  border-radius: var(--radius-sm);
  padding: 5px 13px;
  font-size: 0.82rem;
  color: var(--text-strong);
  pointer-events: none;
  z-index: 9999;
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 0.15s, transform 0.15s;
  white-space: nowrap;
  font-family: 'Noto Serif TC', serif;
  box-shadow: 0 3px 14px rgba(120,80,30,0.18);
}
#beadTooltip.visible { opacity: 1; transform: translateY(0); }

/* ─── Context Menu ─────────────────────────────────────── */
#contextMenu {
  position: fixed;
  background: rgba(255,252,246,0.98);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  z-index: 9998;
  display: none;
  box-shadow: 0 8px 32px rgba(120,80,30,0.22);
  min-width: 220px;
}
#contextMenu.visible { display: block; animation: popIn 0.15s ease; }
#contextMenuTitle {
  font-size: 0.76rem;
  color: var(--text-muted);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-bottom: 6px;
  font-family: 'Cormorant Garamond', serif;
}
#contextMenu .bead-name {
  font-size: 0.95rem;
  color: var(--purple);
  margin-bottom: 14px;
  font-weight: 600;
}
#contextMenu .size-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
#contextMenu .size-row input { width: 100%; }
#contextMenu .size-val {
  font-family: 'Cinzel', serif;
  font-size: 0.90rem;
  color: var(--gold);
  min-width: 40px;
  text-align: right;
}
.ctx-remove {
  margin-top: 14px;
  width: 100%;
  padding: 8px;
  background: rgba(160,40,40,0.07);
  border: 1px solid rgba(160,40,40,0.25);
  border-radius: var(--radius-sm);
  color: #b04040;
  font-size: 0.82rem;
  cursor: pointer;
  transition: all 0.15s;
  font-family: 'Noto Serif TC', serif;
}
.ctx-remove:hover { background: rgba(160,40,40,0.15); }

/* ─── Side Panel ───────────────────────────────────────── */
#sidePanel {
  width: 290px;
  flex-shrink: 0;
  background: var(--bg-panel);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  overflow-x: visible;
  padding: 10px 9px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  box-shadow: -2px 0 12px rgba(120,80,30,0.05);
}

/* ─── Browse Mode Toggle ──────────────────────────────── */
#browseToggle {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-warm);
  border: 1px solid var(--border);
  border-radius: 22px;
  overflow: hidden;
  margin: 2px 4px 8px;
  box-shadow: var(--shadow-card);
}
.browse-btn {
  flex: 1;
  padding: 6px 10px;
  font-family: var(--f-brand);
  font-size: 0.74rem;
  font-weight: var(--fw-bold);
  letter-spacing: var(--ls-wide);
  color: var(--text-muted);
  cursor: pointer;
  border: none;
  background: transparent;
  transition: all 0.25s;
  white-space: nowrap;
}
.browse-btn.active {
  background: linear-gradient(135deg, var(--gold), #c08a18);
  color: #fff;
  box-shadow: 0 2px 8px rgba(170,120,32,0.3);
}
.browse-btn:hover:not(.active) {
  color: var(--text-primary);
  background: rgba(170,120,32,0.06);
}

#sidePanel::-webkit-scrollbar { width: 4px; }
#sidePanel::-webkit-scrollbar-track { background: transparent; }
#sidePanel::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 2px; }

/* ─── Section Title ────────────────────────────────────── */
.section-title {
  font-family: 'Cinzel', serif;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold);
  padding: 7px 13px 5px;
  border-bottom: 1px solid rgba(170,120,32,0.18);
  margin-bottom: 2px;
  background: linear-gradient(90deg, rgba(170,120,32,0.05), transparent);
}

/* Category block */
.category-block {
  border-radius: var(--radius-md);
  position: relative;
}

.cat-header {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 10px 13px;
  cursor: pointer;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  transition: all 0.2s;
  user-select: none;
  position: relative;
  z-index: 1;
}
.cat-header:hover {
  background: rgba(90,48,144,0.05);
  border-color: rgba(90,48,144,0.22);
}
.cat-header.open {
  border-radius: var(--radius-md);
  border-color: rgba(90,48,144,0.3);
  background: rgba(90,48,144,0.06);
}

.cat-icon { font-size: 1.05rem; }
.cat-name {
  flex: 1;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: 0.03em;
}
.cat-count {
  font-size: 0.72rem;
  color: var(--text-muted);
  background: var(--bg-warm);
  border-radius: 10px;
  padding: 2px 8px;
  font-family: 'Cinzel', serif;
}
.cat-chevron {
  font-size: 0.62rem;
  color: var(--text-muted);
  transition: transform 0.25s;
}
.cat-header.open .cat-chevron { transform: rotate(180deg); }

/* Floating dropdown body */
.cat-body {
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  z-index: 100;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.35s ease, opacity 0.2s ease;
  background: #faf8f4;
  border: 1px solid rgba(90,48,144,0.18);
  border-top: none;
  border-radius: 0 0 var(--radius-md) var(--radius-md);
  box-shadow: 0 8px 24px rgba(90,48,144,0.12);
  opacity: 0;
}
.cat-body.open {
  max-height: 320px;
  overflow-y: auto;
  opacity: 1;
}

.crystal-list { padding: 4px 0; }

.crystal-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 13px;
  cursor: pointer;
  transition: background 0.15s;
}
.crystal-item:hover { background: rgba(90,48,144,0.07); }
.crystal-item:hover .crystal-name { color: var(--purple); }

/* Accessory items */
.accessory-item {
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
}
.accessory-item:hover {
  background: rgba(170,120,32,0.07);
  border-color: rgba(170,120,32,0.2);
}
.accessory-item:hover .crystal-name { color: var(--gold); }

.crystal-bead-preview {
  width: 30px; height: 30px;
  border-radius: 50%;
  flex-shrink: 0;
  overflow: visible;
}

.crystal-name {
  font-size: 0.84rem;
  color: var(--text-primary);
  transition: color 0.15s;
  line-height: 1.3;
  font-family: 'Noto Serif TC', serif;
}

/* ─── Crystal Image Preview ───────────────────────────── */
.crystal-img-wrap {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
}

.crystal-img-preview {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.crystal-text-wrap {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}

.crystal-effect {
  font-size: 0.66rem;
  color: var(--text-muted);
  line-height: 1.35;
  font-family: 'Noto Serif TC', serif;
  font-weight: var(--fw-light);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.crystal-item:hover .crystal-effect {
  color: var(--text-secondary);
}

/* ─── Animations ───────────────────────────────────────── */
@keyframes popIn {
  from { opacity: 0; transform: scale(0.92); }
  to   { opacity: 1; transform: scale(1); }
}

* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }

/* ─── Bead Stats Panel ─────────────────────────────────── */
#beadStats {
  margin-top: 8px;
  width: 100%;
  max-width: 520px;
  font-family: 'Noto Serif TC', serif;
  animation: fadeIn 0.3s ease;
}

.stats-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  padding: 0 2px;
}

.stats-title {
  font-size: 0.78rem;
  color: var(--text-muted);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-family: 'Cormorant Garamond', serif;
  font-style: italic;
}

.stats-count {
  font-family: 'Cinzel', serif;
  font-size: 0.82rem;
  color: var(--gold);
  font-weight: 600;
  background: rgba(170,120,32,0.08);
  border: 1px solid rgba(170,120,32,0.2);
  border-radius: 20px;
  padding: 2px 12px;
}

.stats-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.stats-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(90,48,144,0.06);
  border: 1px solid rgba(90,48,144,0.16);
  border-radius: 20px;
  padding: 3px 12px;
  font-size: 0.76rem;
  color: var(--text-primary);
  transition: all 0.15s;
}

.stats-chip b {
  color: var(--purple-light);
  font-weight: 700;
  font-family: 'Cinzel', serif;
  font-size: 0.80rem;
}

.stats-chip:hover {
  background: rgba(90,48,144,0.12);
  border-color: rgba(90,48,144,0.3);
}

/* ─── Over-Limit Notification ──────────────────────────── */
#overLimitNotif {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: linear-gradient(135deg, rgba(180,40,40,0.95), rgba(140,20,20,0.95));
  color: #fff;
  font-family: 'Noto Serif TC', serif;
  font-size: 0.88rem;
  letter-spacing: 0.04em;
  padding: 13px 28px;
  border-radius: 30px;
  box-shadow: 0 6px 24px rgba(140,20,20,0.35), 0 2px 8px rgba(0,0,0,0.2);
  z-index: 99999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
  white-space: nowrap;
}

#overLimitNotif.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

#overLimitNotif.hide {
  opacity: 0;
  transform: translateX(-50%) translateY(10px);
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ═══════════════════════════════════════════════════════════
   Mobile / Tablet  (≤ 1024px)  — Responsive Layout
   ═══════════════════════════════════════════════════════════ */
@media (max-width: 1024px) {

  /* ── App Shell: vertical stack ── */
  #app {
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;  /* dynamic viewport height for mobile browsers */
  }

  /* ── Top Bar: compact ── */
  #topbar {
    gap: 8px;
    padding: 8px 12px;
    flex-wrap: wrap;
  }
  #logo { font-size: 0.92rem; }
  .ctrl-group { padding: 5px 10px; }
  .ctrl-label { font-size: 0.72rem; }
  .ctrl-value { font-size: 0.82rem; min-width: 64px; }
  input[type=range] { width: 80px; }
  #beadSizeSelect { font-size: 0.80rem; }

  /* ── Main: vertical stack ── */
  #main {
    display: flex;
    flex-direction: column;
    overflow: visible;
  }

  /* ── Canvas Section: sticky at top (order 1) ── */
  #canvasSection {
    order: 1;
    position: sticky;
    top: 0;
    z-index: 40;
    padding: 12px 8px 0;
    flex: none;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 4px 16px rgba(120,80,30,0.10);
  }

  #braceletCanvas {
    width: min(85vw, 340px);
    height: min(85vw, 340px);
  }

  #canvasBottom {
    min-height: auto;
    padding-bottom: 8px;
  }
  #canvasHint { font-size: 0.65rem; margin-top: 4px; }
  #clearTrayBtn {
    margin-top: 6px;
    padding: 6px 24px;
    font-size: 0.76rem;
    min-height: 36px;
  }

  /* ── Side Panel (Crystal Selection): order 2 ── */
  #sidePanel {
    order: 2;
    width: 100%;
    border-left: none;
    border-bottom: 1px solid var(--border);
    overflow-y: visible; /* Let it flow normally */
    overflow-x: hidden;
    padding: 10px 12px;
    max-height: none;
    flex: none;
  }

  /* Dropdown bodies: static flow instead of absolute overlay */
  .category-block { position: static; }
  .cat-body {
    position: static;
    border-radius: var(--radius-md);
    border: 1px solid rgba(90,48,144,0.14);
    margin-top: 2px;
  }
  .cat-body.open { max-height: 500px; }

  /* ── Stats Panel: order 3 ── */
  #statsPanel {
    order: 3;
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 250px;
  }

  /* ── Guide Panel: order 4 ── */
  #leftHintOuter {
    order: 4;
    width: 100%;
  }
  #leftHint {
    width: 100%;
    border-right: none;
  }
  #leftToggleBtn {
    display: none; /* Hide the toggle button on mobile */
  }

  /* Touch-friendly sizes (min 44px tap targets) */
  .cat-header { min-height: 44px; padding: 10px 12px; }
  .crystal-item { min-height: 44px; padding: 8px 12px; }
  .browse-btn { min-height: 38px; font-size: 0.78rem; }
  .lang-btn { min-height: 36px; padding: 6px 14px; }
  .ctx-remove { min-height: 44px; }
}

/* ── Extra small phones (≤ 480px) ── */
@media (max-width: 480px) {
  :root { font-size: 15px; }

  #topbar { gap: 6px; padding: 6px 8px; }
  #logo { display: none; }  /* hide logo on very small screens to save space */
  #topbar #logo { margin-right: 0; }

  .ctrl-group { gap: 6px; padding: 4px 8px; }
  .ctrl-value { min-width: 56px; font-size: 0.78rem; }
  input[type=range] { width: 60px; }

  #braceletCanvas {
    width: min(92vw, 300px);
    height: min(92vw, 300px);
  }

  .cat-name { font-size: 0.80rem; }
  .crystal-name { font-size: 0.78rem; }
  .crystal-effect { font-size: 0.62rem; }

  /* Context menu: center on screen */
  #contextMenu {
    left: 50% !important;
    top: 50% !important;
    transform: translate(-50%, -50%);
    max-width: 90vw;
  }
}
