:root {
  --bg: #f0eee6;
  --surface: #ffffff;
  --surface-2: #f6f4ec;
  --text: #201e1a;
  --text-2: #46423a;
  --muted: #7a746a;
  --border: #e6e1d4;
  --border-strong: #d7d1c1;
  --accent: #d97757;
  --accent-deep: #bd5a3a;
  --accent-tint: #f4e5db;
  --good: #5f7350;
  --radius: 16px;
  --radius-sm: 9px;
  --maxw: 680px;
  --serif: 'Newsreader', Georgia, 'Times New Roman', serif;
  --sans: 'Hanken Grotesk', system-ui, -apple-system, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
}

main {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 76px 24px 150px;
}

/* ---------- Masthead ---------- */
.masthead {
  margin-bottom: 40px;
  animation: rise 0.7s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}

.kicker {
  margin: 0 0 16px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--accent-deep);
}

.wordmark {
  margin: 0;
  font-family: var(--serif);
  font-optical-sizing: auto;
  font-weight: 500;
  font-size: clamp(2.8rem, 9vw, 4.4rem);
  line-height: 0.98;
  letter-spacing: -0.02em;
}

.wordmark em {
  font-style: italic;
  font-weight: 400;
  color: var(--accent);
}

.lede {
  margin: 22px 0 0;
  max-width: 48ch;
  font-size: 1.05rem;
  color: var(--text-2);
}

/* ---------- Step cards ---------- */
.step {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 30px;
  margin-bottom: 16px;
  box-shadow: 0 1px 2px rgba(32, 30, 26, 0.04);
  animation: rise 0.7s cubic-bezier(0.2, 0.7, 0.2, 1) both;
  animation-delay: calc(var(--i) * 0.06s);
}

/* Bước mở dần: bước sau chỉ hiện khi bước trước đã xong (JS gỡ [hidden]). */
.step[hidden],
.guide[hidden] {
  display: none;
}

/* Khi được mở, các bước sau reveal nhanh gọn thay vì theo stagger --i ban đầu. */
#step-threshold,
#step-voices,
#step-build,
#guide {
  animation-delay: 0.04s;
}

.step-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}

.step-num {
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--accent-deep);
  background: var(--accent-tint);
  padding: 4px 9px;
  border-radius: 6px;
  letter-spacing: 0.04em;
}

.step-head h2 {
  margin: 0;
  font-family: var(--serif);
  font-optical-sizing: auto;
  font-weight: 500;
  font-size: 1.4rem;
  letter-spacing: -0.01em;
}

.hint {
  margin: 0 0 18px;
  max-width: 56ch;
  font-size: 0.94rem;
  color: var(--muted);
}

.hint em,
.items-note em {
  font-style: normal;
  color: var(--accent-deep);
  font-weight: 500;
}

/* ---------- Dropzone + preset ---------- */
.dropzone {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 24px 22px;
  background: var(--surface-2);
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--muted);
  transition: border-color 0.2s, background 0.2s, color 0.2s;
}

.dropzone:hover,
.dropzone.drag {
  border-color: var(--accent);
  color: var(--text);
  background: var(--accent-tint);
}

.dz-glyph {
  font-size: 1.35rem;
  line-height: 1;
  color: var(--accent);
}

.dz-text code {
  color: var(--text);
}

.preset {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 16px;
}

.preset-label {
  font-size: 0.9rem;
  color: var(--muted);
  white-space: nowrap;
}

.preset .voice-select {
  flex: 1;
}

.filter-info {
  margin: 14px 0 0;
  min-height: 18px;
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--good);
}

/* ---------- Threshold ---------- */
.readout {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 16px;
}

.readout output {
  font-family: var(--serif);
  font-optical-sizing: auto;
  font-weight: 500;
  font-size: clamp(2.8rem, 9vw, 3.8rem);
  line-height: 1;
  letter-spacing: -0.02em;
  font-feature-settings: 'tnum';
}

.readout .unit {
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.2rem;
  color: var(--accent);
}

.items-meta {
  margin: 16px 0 0;
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--muted);
}

/* ---------- Slider ---------- */
.slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 3px;
  background: linear-gradient(
    to right,
    var(--accent) 0 calc(var(--pct, 45) * 1%),
    var(--border-strong) calc(var(--pct, 45) * 1%) 100%
  );
  outline: none;
  cursor: pointer;
}

.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  border: 4px solid var(--surface);
  box-shadow: 0 0 0 1px var(--accent), 0 2px 5px rgba(32, 30, 26, 0.2);
  transition: transform 0.12s;
}

.slider::-webkit-slider-thumb:hover {
  transform: scale(1.12);
}

.slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 4px solid var(--surface);
  box-shadow: 0 0 0 1px var(--accent);
}

/* ---------- Bulk voice toggle ---------- */
.bulk-toggle {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin: 4px 0 16px;
}

.bulk-label {
  font-size: 0.85rem;
  color: var(--muted);
}

.toggle-group {
  display: inline-flex;
  gap: 3px;
  padding: 3px;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
}

.toggle-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text-2);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  padding: 6px 15px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.toggle-btn:hover {
  color: var(--text);
}

.toggle-btn.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 1px 2px rgba(189, 90, 58, 0.25);
}

/* ---------- Item list ---------- */
.items-note {
  margin: 0 0 6px;
  font-size: 0.95rem;
  color: var(--text-2);
}

.items-note strong {
  color: var(--accent-deep);
}

.items {
  display: flex;
  flex-direction: column;
}

.item-row {
  display: grid;
  grid-template-columns: 40px 1fr auto minmax(160px, 210px) auto;
  align-items: center;
  gap: 14px;
  padding: 12px 0;
  border-top: 1px solid var(--border);
}

.item-icon {
  width: 40px;
  height: 40px;
  object-fit: contain;
  flex: none;
}

.item-name {
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
  line-height: 1.3;
}

.item-name:hover {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.item-price {
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
  text-align: right;
}

.item-price b {
  color: var(--text);
  font-weight: 500;
}

.voice-select {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 9px 32px 9px 12px;
  font: inherit;
  font-size: 0.88rem;
  cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 16px) 53%, calc(100% - 11px) 53%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  transition: border-color 0.15s;
}

.voice-select:hover {
  border-color: var(--muted);
}

.voice-select:focus {
  outline: none;
  border-color: var(--accent);
}

.play-btn {
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--text);
  font-size: 0.7rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.1s;
}

.play-btn:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.play-btn:active {
  transform: scale(0.92);
}

/* ---------- Build ---------- */
.build-step {
  display: flex;
  flex-direction: column;
}

.build {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 14px 24px;
  font-family: var(--sans);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, opacity 0.2s, box-shadow 0.2s;
}

.build:hover:not(:disabled) {
  background: var(--accent-deep);
  box-shadow: 0 4px 14px rgba(189, 90, 58, 0.28);
}

.build:disabled {
  background: var(--border-strong);
  color: var(--muted);
  cursor: not-allowed;
}

.build .arrow {
  transition: transform 0.2s cubic-bezier(0.2, 0.7, 0.2, 1);
}

.build:hover:not(:disabled) .arrow {
  transform: translateX(5px);
}

/* ---------- Guide ---------- */
.guide {
  padding: 8px 6px 0;
  animation: rise 0.7s cubic-bezier(0.2, 0.7, 0.2, 1) both;
  animation-delay: calc(var(--i) * 0.06s);
}

.guide-title {
  margin: 0 0 18px;
  font-family: var(--serif);
  font-weight: 500;
  font-size: 1.2rem;
}

.guide ol {
  margin: 0;
  padding-left: 0;
  list-style: none;
  counter-reset: g;
}

.guide li {
  position: relative;
  padding: 0 0 14px 32px;
  color: var(--text-2);
  font-size: 0.93rem;
  counter-increment: g;
}

.guide li::before {
  content: counter(g, decimal-leading-zero);
  position: absolute;
  left: 0;
  top: 0.15em;
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--accent);
}

code {
  font-family: var(--mono);
  font-size: 0.82em;
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: 5px;
  color: var(--accent-deep);
}

/* ---------- Loading overlay ---------- */
/* Chặn toàn màn cho hai bước blocking: tải giá item, tải filter. Hiện mặc định
   (trang mở ra là đang tải giá), JS gỡ khi xong. Status bar dưới chân lo kết quả. */
.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  transition: opacity 0.3s ease;
}

.loading-overlay.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loading-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  padding: 0 24px;
  text-align: center;
}

.loading-spinner {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 3px solid var(--border-strong);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}

.loading-msg {
  margin: 0;
  font-family: var(--serif);
  font-optical-sizing: auto;
  font-weight: 500;
  font-size: 1.35rem;
  letter-spacing: -0.01em;
  color: var(--text);
}

.loading-hint {
  margin: 0;
  max-width: 34ch;
  font-size: 0.9rem;
  color: var(--muted);
}

.loading-hint:empty {
  display: none;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---------- Status bar ---------- */
.status-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 5;
  display: flex;
  justify-content: center;
  padding: 16px;
  pointer-events: none;
}

.status {
  margin: 0;
  max-width: var(--maxw);
  font-size: 0.85rem;
  background: var(--text);
  color: var(--bg);
  padding: 11px 20px;
  border-radius: 100px;
  box-shadow: 0 8px 28px rgba(32, 30, 26, 0.22);
  transition: opacity 0.3s, transform 0.3s;
}

.status:empty {
  opacity: 0;
  transform: translateY(10px);
}

.status.ok {
  background: var(--good);
  color: #fff;
}

.status.warn {
  background: var(--accent-deep);
  color: #fff;
}

/* ---------- Motion ---------- */
@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}

/* ---------- Responsive ---------- */
@media (max-width: 620px) {
  main {
    padding: 52px 18px 130px;
  }
  .step {
    padding: 22px 20px;
  }
  .item-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    column-gap: 12px;
    row-gap: 10px;
  }
  .item-name {
    flex: 1 1 40%;
  }
  .item-price {
    margin-left: auto;
  }
  .voice-select {
    flex: 1 1 200px;
  }
  .preset {
    flex-direction: column;
    align-items: stretch;
  }
}
