* { box-sizing: border-box; }
html, body, #root { margin: 0; padding: 0; height: 100%; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: #fff;
  color: #1a1a1e;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "ss01", "cv11";
}

.cf-app {
  display: grid;
  grid-template-columns: 440px 1fr;
  height: 100vh;
  height: 100dvh;
  width: 100vw;
  --accent: #3D6BFF;
  --line: #ececea;
  --muted: #8a8a90;
}

/* LEFT PANEL */
.cf-left {
  background: #fff;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
  position: relative;
}

.cf-header {
  padding: 22px 28px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}
.cf-brand { display: flex; align-items: center; gap: 10px; }
.cf-brand-link { display: inline-block; line-height: 0; transition: opacity 0.15s; }
.cf-brand-link:hover { opacity: 0.75; }
.cf-brand-logo { height: 28px; width: auto; display: block; }
.cf-step {
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 500;
}

.cf-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 8px 28px 24px;
  scrollbar-width: thin;
  scrollbar-color: #ee8b1a transparent;
}
.cf-scroll::-webkit-scrollbar { width: 8px; }
.cf-scroll::-webkit-scrollbar-track { background: transparent; }
.cf-scroll::-webkit-scrollbar-thumb { background: #ee8b1a; border-radius: 4px; }

.cf-section {
  padding: 18px 0;
  border-bottom: 1px solid var(--line);
}
.cf-section:last-child { border-bottom: none; }

.cf-row-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 12px;
}
.cf-label {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.cf-value {
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.cf-input {
  width: 100%;
  padding: 14px 16px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  font-family: 'JetBrains Mono', 'SF Mono', monospace;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0.12em;
  background: #fafaf8;
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}
.cf-input:focus {
  border-color: var(--accent);
  background: #fff;
}
.cf-input::placeholder { color: #c0c0bc; letter-spacing: 0.12em; }

.cf-hint {
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
}

.cf-len-bar {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 4px;
}
.cf-len-cell {
  height: 8px;
  background: #f0efeb;
  border-radius: 3px;
  transition: background 0.2s;
}

.cf-swatches {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
}
.cf-swatch {
  aspect-ratio: 1;
  border-radius: 10px;
  border: 1.5px solid rgba(0,0,0,0.06);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  position: relative;
  transition: transform 0.12s, box-shadow 0.12s;
  padding: 0;
}
.cf-swatch:hover { transform: scale(1.05); }
.cf-swatch.is-on {
  box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--accent);
  transform: scale(1.05);
}

.cf-extras {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

/* DISABLED SECTION (greyed out when per-letter is open) */
.cf-section.is-disabled .cf-label { color: #b0b0b4; }
.cf-section.is-disabled .cf-value {
  color: var(--accent);
  font-style: italic;
  font-size: 12px;
  opacity: 0.85;
}
.cf-section.is-disabled .cf-swatches {
  opacity: 0.32;
  pointer-events: none;
  filter: saturate(0.5);
  transition: opacity 0.25s ease, filter 0.25s ease;
}

/* NEXT-LEVEL CUSTOMIZATION DROPDOWN */
.cf-custom { padding: 0; }
.cf-custom.is-open { padding-bottom: 18px; }
.cf-custom-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 0;
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  text-align: left;
  color: inherit;
}
.cf-custom-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.cf-custom-spark {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px; height: 22px;
  border-radius: 7px;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  color: var(--accent);
  flex-shrink: 0;
}
.cf-custom-meta {
  display: flex;
  align-items: center;
  gap: 8px;
}
.cf-custom-sub {
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.cf-custom-caret {
  color: var(--muted);
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}
.cf-custom.is-open .cf-custom-caret {
  transform: rotate(180deg);
  color: var(--accent);
}
.cf-custom-body {
  overflow: hidden;
  max-height: 0;
  transition: max-height 0.32s cubic-bezier(0.4, 0, 0.2, 1);
}
.cf-custom-inner {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 4px;
}
.cf-custom-empty {
  font-size: 13px;
  color: var(--muted);
  padding: 14px 14px;
  background: #fafaf8;
  border: 1px dashed var(--line);
  border-radius: 10px;
  text-align: center;
}

/* PER-LETTER CARD */
.cf-letter-card {
  background: #fafaf8;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  animation: cf-letter-in 0.3s cubic-bezier(0.4, 0, 0.2, 1) backwards;
}
.cf-custom.is-open .cf-letter-card:nth-child(1) { animation-delay: 0.04s; }
.cf-custom.is-open .cf-letter-card:nth-child(2) { animation-delay: 0.08s; }
.cf-custom.is-open .cf-letter-card:nth-child(3) { animation-delay: 0.12s; }
.cf-custom.is-open .cf-letter-card:nth-child(4) { animation-delay: 0.16s; }
.cf-custom.is-open .cf-letter-card:nth-child(5) { animation-delay: 0.20s; }
.cf-custom.is-open .cf-letter-card:nth-child(n+6) { animation-delay: 0.22s; }
@keyframes cf-letter-in {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.cf-letter-head {
  display: flex;
  align-items: center;
  gap: 12px;
}
.cf-letter-glyph {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'JetBrains Mono', 'SF Mono', monospace;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0;
  border: 1px solid rgba(0,0,0,0.08);
  flex-shrink: 0;
  transition: background 0.2s, color 0.2s;
}
.cf-letter-meta { display: flex; flex-direction: column; gap: 1px; }
.cf-letter-pos {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  font-weight: 600;
}
.cf-letter-name {
  font-size: 13px;
  font-weight: 600;
}

.cf-letter-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.cf-letter-row-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.cf-letter-row-dot {
  width: 8px; height: 8px;
  border-radius: 3px;
  border: 1px solid rgba(0,0,0,0.08);
  transition: background 0.18s;
}
.cf-letter-swatches {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 4px;
}
.cf-mini-swatch {
  aspect-ratio: 1;
  border-radius: 6px;
  border: 1px solid rgba(0,0,0,0.08);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  padding: 0;
  transition: transform 0.12s, box-shadow 0.12s;
}
.cf-mini-swatch:hover { transform: scale(1.1); }
.cf-mini-swatch.is-on {
  box-shadow: 0 0 0 1.5px #fff, 0 0 0 3px var(--accent);
  transform: scale(1.1);
}
.cf-extra-btn {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 12px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: #1a1a1e;
  font-family: inherit;
  transition: background 0.15s, border-color 0.15s;
}
.cf-extra-btn:hover { background: #fafaf8; border-color: #d8d8d4; }
.cf-extra-btn.is-on { border-color: var(--accent); color: var(--accent); }

.cf-footer {
  padding: 18px 28px 22px;
  padding-bottom: calc(22px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: #fff;
}
.cf-price-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.cf-price-label {
  font-size: 13px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 500;
}
.cf-price-sub {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}
.cf-price {
  font-size: 32px;
  font-weight: 600;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}
.cf-checkout {
  width: 100%;
  padding: 16px;
  border: none;
  border-radius: 14px;
  background: var(--accent);
  color: #fff;
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  transition: filter 0.15s, transform 0.1s;
}
.cf-checkout:hover { filter: brightness(1.08); }
.cf-checkout:active { transform: scale(0.98); }

/* RIGHT — STAGE */
.cf-right {
  background: linear-gradient(180deg, #fbfbf9 0%, #f4f3ef 100%);
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}
.cf-stage-meta {
  position: absolute;
  top: 24px; left: 28px; right: 28px;
  display: flex; justify-content: space-between;
  z-index: 5;
}
.cf-stage-title {
  display: flex; align-items: center; gap: 12px;
}
.cf-stage-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  font-weight: 600;
}
.cf-stage-sku {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--muted);
  background: #fff;
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid var(--line);
}

.cf-legend {
  position: absolute;
  bottom: 24px; left: 28px;
  display: flex; gap: 16px;
  z-index: 5;
}
.cf-chip {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px;
  color: #555;
  font-weight: 500;
}
.cf-chip-dot {
  width: 14px; height: 14px;
  border-radius: 4px;
  border: 1px solid rgba(0,0,0,0.08);
}

/* 3D STAGE */
.kb-stage {
  flex: 1;
  min-height: 420px;
  display: flex; align-items: center; justify-content: center;
  position: relative;
  user-select: none;
  touch-action: none;
}
.kb-platter {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.three-mount {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.three-mount canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}
.kb-hint {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  color: rgba(0,0,0,0.4);
  letter-spacing: 0.04em;
  pointer-events: none;
  z-index: 2;
}

/* Comic-style hint bubble over the 3D viewer. Disappears on first press. */
.cf-hint-bubble {
  position: absolute;
  top: 28%;
  left: 50%;
  z-index: 4;
  padding: 14px 24px;
  background: rgba(255, 255, 255, 0.82);
  border: 2px solid rgba(0, 0, 0, 0.12);
  border-radius: 28px;
  font-size: 17px;
  font-weight: 500;
  color: rgba(0, 0, 0, 0.6);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.07);
  pointer-events: none;
  white-space: nowrap;
  opacity: 0;
  transform: translate(-50%, -6px);
  animation: cfHintIn 0.5s ease 0.6s forwards;
  transition: opacity 0.35s ease;
}
.cf-hint-bubble.is-hidden {
  opacity: 0 !important;
  animation: none;
}
.cf-hint-bubble::after {
  content: "";
  position: absolute;
  bottom: -10px;
  left: 50%;
  margin-left: -9px;
  width: 18px;
  height: 18px;
  background: rgba(255, 255, 255, 0.82);
  border-right: 2px solid rgba(0, 0, 0, 0.12);
  border-bottom: 2px solid rgba(0, 0, 0, 0.12);
  transform: rotate(45deg);
  border-bottom-right-radius: 4px;
}
.cf-hint-icon { margin-left: 4px; font-size: 1.05em; }
@keyframes cfHintIn {
  from { opacity: 0; transform: translate(-50%, -6px); }
  to   { opacity: 0.9; transform: translate(-50%, 0); }
}
.kb-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: #9aa0a8;
  text-align: center;
  padding: 0 32px;
}
.kb-empty-icon { color: #c8ccd2; }
.kb-empty-title { font-size: 18px; font-weight: 600; color: #4a4f57; }
.kb-empty-sub { font-size: 14px; max-width: 320px; line-height: 1.5; }
.kb-hint-x {
  position: absolute;
  bottom: 60px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 500;
  pointer-events: none;
}

/* responsive guard */
@media (max-width: 880px) {
  .cf-app { grid-template-columns: 1fr; grid-template-rows: 50dvh 1fr; }
  .cf-right { order: 1; }
  .cf-left {
    order: 2;
    border-right: none;
    border-top: 1px solid var(--line);
    border-bottom: none;
  }
  .cf-scroll { overflow-y: scroll; }
  .cf-scroll { scrollbar-width: none; }
  .cf-scroll::-webkit-scrollbar { width: 0; }
  .cf-fake-sb {
    position: absolute;
    right: 4px;
    width: 6px;
    background: rgba(238, 139, 26, 0.18);
    border-radius: 3px;
    pointer-events: none;
    z-index: 6;
  }
  .cf-fake-sb-thumb {
    position: absolute;
    left: 0;
    right: 0;
    min-height: 28px;
    background: #ee8b1a;
    border-radius: 3px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
  }
  .kb-hint { display: none; }
}
@media (min-width: 881px) {
  .cf-fake-sb { display: none; }
}
