:root {
  --bg: #0a0a0c;
  --bg-elev: #131318;
  --bg-elev-2: #1b1b22;
  --border: #2a2a33;
  --border-strong: #3a3a47;
  --text: #f5f5f7;
  --text-dim: #a1a1ac;
  --text-mute: #6e6e7a;
  --accent: #14b8c4;
  --accent-2: #1ea7b4;
  --accent-soft: rgba(20, 184, 196, 0.12);
  --danger: #ef4444;
  --card-aspect: 1.585;
  --card-radius: 18px;
  --shadow-lg: 0 30px 60px -20px rgba(0, 0, 0, 0.7), 0 12px 24px -12px rgba(0, 0, 0, 0.5);
  --shadow-card: 0 22px 50px -12px rgba(0, 0, 0, 0.75), 0 8px 24px -8px rgba(20, 184, 196, 0.12);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

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

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(20, 184, 196, 0.08), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(20, 184, 196, 0.05), transparent 60%),
    var(--bg);
}

/* ---------- Header ---------- */
.site-header {
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
  background: #ffffff;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: 0 1px 12px rgba(0, 0, 0, 0.06);
}

.header-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 16px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.brand {
  display: flex;
  align-items: center;
  text-decoration: none;
  color: #0f1932;
}

.logo-cbix {
  height: 36px;
  width: auto;
  display: block;
}

.logo-fallback {
  display: none;
  font-weight: 800;
  font-size: 26px;
  letter-spacing: -0.02em;
  color: #0f1932;
}

.partnership {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

.partnership-label {
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #0f1932;
  font-weight: 600;
}

.logo-cbi {
  height: 30px;
  width: auto;
  display: block;
}

.logo-fallback-cbi {
  font-size: 22px;
  color: #0f1932;
}

/* ---------- Main page ---------- */
.page {
  flex: 1;
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: 40px 32px 80px;
}

.module {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.02), rgba(255, 255, 255, 0)) , var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 24px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

/* ---------- Progress steps ---------- */
.module-progress {
  border-bottom: 1px solid var(--border);
  padding: 22px 36px;
  background: rgba(255, 255, 255, 0.015);
}

.steps {
  list-style: none;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.step {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-dim);
}

.step-num {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--border);
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.step-label {
  font-weight: 500;
}

.step.done {
  color: var(--text);
}

.step.done .step-num {
  background: var(--accent-soft);
  color: var(--accent);
}

.step.active {
  background: var(--accent-soft);
  border-color: rgba(20, 184, 196, 0.3);
  color: var(--text);
}

.step.active .step-num {
  background: var(--accent);
  color: #001316;
}

/* ---------- Module header ---------- */
.module-header {
  padding: 28px 36px 12px;
}

.module-header h1 {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 8px;
}

.subtitle {
  color: var(--text-dim);
  font-size: 14.5px;
  line-height: 1.55;
  max-width: 680px;
}

/* ---------- Workspace ---------- */
.workspace {
  padding: 28px 36px 36px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 36px;
  align-items: start;
}

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

/* ---------- Card preview ---------- */
.preview-panel {
  position: sticky;
  top: 100px;
}

.card-stage {
  background: linear-gradient(180deg, #0d0d10, #050507);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 380px;
}

.card {
  position: relative;
  width: 100%;
  max-width: 560px;
  aspect-ratio: var(--card-aspect);
  border-radius: var(--card-radius);
  background: #1a1a20;
  overflow: hidden;
  box-shadow: var(--shadow-card);
  user-select: none;
  -webkit-user-select: none;
  isolation: isolate;
}

.card-background {
  position: absolute;
  inset: 0;
  background-color: #1a1a20;
  overflow: hidden;
  z-index: 1;
}

.card-background.draggable {
  cursor: grab;
  /* Touching the uploaded-image area on mobile pans the image, not the page. */
  touch-action: none;
}

.card-background.dragging {
  cursor: grabbing;
}

.bg-img {
  position: absolute;
  top: 50%;
  left: 50%;
  /* width/height set by JS in pixels for deterministic layout */
  max-width: none;
  max-height: none;
  transform-origin: center center;
  transform: translate(-50%, -50%);
  pointer-events: none;
  display: none;
  -webkit-user-drag: none;
  user-select: none;
}

.bg-img.visible { display: block; }

.card-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
}

.card-cbi {
  position: absolute;
  top: 8.58%;
  left: 5.54%;
  width: 21.61%;
  height: auto;
  filter: drop-shadow(0 1px 3px rgba(0,0,0,0.35));
}

.card-chip {
  position: absolute;
  top: 41.83%;
  left: 10.17%;
  width: 12.93%;
  height: auto;
}

.card-mastercard {
  position: absolute;
  bottom: 6.67%;
  right: 5.10%;
  width: 20.31%;
  height: auto;
}

/* Hide pre-baked overlays when a default design is selected (the design image
   already contains the chip, CBI and Mastercard marks). */
.card.design-mode .card-cbi,
.card.design-mode .card-chip,
.card.design-mode .card-mastercard {
  display: none;
}

.card-handle {
  position: absolute;
  left: 6%;
  top: 92%;
  transform: translateY(-100%);
  max-width: 85%;
  font-family: 'Inter', sans-serif;
  font-weight: 700;
  font-size: 22px;
  color: #fff;
  letter-spacing: 0.02em;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.55);
  white-space: nowrap;
  line-height: 1.1;
  pointer-events: auto;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  z-index: 3;
}

.card-handle:empty {
  pointer-events: none;
}

.card-handle.dragging {
  cursor: grabbing;
}

/* Show a faint dashed outline on hover so users discover it's draggable. */
.card-handle:not(:empty):hover {
  outline: 1px dashed rgba(255, 255, 255, 0.5);
  outline-offset: 4px;
  border-radius: 2px;
}

.card-hint {
  position: absolute;
  inset: 0;
  z-index: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-mute);
  font-size: 14px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.card.has-bg .card-hint,
.card.initialized .card-hint {
  display: none;
}

.preview-caption {
  margin-top: 14px;
  text-align: center;
  color: var(--text-mute);
  font-size: 12.5px;
  letter-spacing: 0.02em;
}

/* ---------- Controls panel ---------- */
.controls-panel {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.25);
}

.tab {
  flex: 1;
  padding: 14px 12px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
  font-family: inherit;
}

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

.tab.active {
  color: var(--text);
  border-bottom-color: var(--accent);
  background: rgba(20, 184, 196, 0.06);
}

.tab-panes {
  padding: 22px;
}

.tab-pane { display: none; }
.tab-pane.active { display: block; }

.pane-hint {
  color: var(--text-dim);
  font-size: 12.5px;
  margin-bottom: 14px;
  letter-spacing: 0.02em;
}

/* ---------- Design grid ---------- */
.design-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.design-thumb {
  position: relative;
  aspect-ratio: var(--card-aspect);
  border-radius: 10px;
  background: var(--bg);
  background-size: cover;
  background-position: center;
  border: 2px solid var(--border);
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
  overflow: hidden;
}

.design-thumb:hover {
  border-color: var(--border-strong);
  transform: translateY(-1px);
}

.design-thumb.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.design-thumb.blank {
  background: repeating-linear-gradient(45deg, #1a1a20, #1a1a20 8px, #1f1f27 8px, #1f1f27 16px);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: var(--text-mute);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* ---------- Upload ---------- */
.upload-drop {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 28px 16px;
  border: 2px dashed var(--border-strong);
  border-radius: 12px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  text-align: center;
}

.upload-drop:hover,
.upload-drop.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.upload-icon {
  font-size: 28px;
  color: var(--accent);
  line-height: 1;
}

.upload-text {
  font-size: 14px;
  font-weight: 600;
}

.upload-sub {
  font-size: 12px;
  color: var(--text-mute);
}

.adjusters {
  margin-top: 18px;
  display: none;
  flex-direction: column;
  gap: 14px;
}

.adjusters.visible { display: flex; }

.adjuster {
  display: grid;
  grid-template-columns: 60px 1fr 50px;
  align-items: center;
  gap: 10px;
  font-size: 12.5px;
  color: var(--text-dim);
}

.adjuster-val {
  text-align: right;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  font-size: 12px;
}

.upload-note {
  font-size: 12px;
  line-height: 1.45;
  color: #f6c768;
  background: rgba(246, 199, 104, 0.08);
  border: 1px solid rgba(246, 199, 104, 0.25);
  padding: 9px 12px;
  border-radius: 8px;
  margin-top: 4px;
}

input[type="range"] {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  background: transparent;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  background: var(--border-strong);
  border-radius: 2px;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  margin-top: -6px;
  border: 2px solid #0a0a0c;
  box-shadow: 0 1px 3px rgba(0,0,0,0.5);
}

input[type="range"]::-moz-range-track {
  height: 4px;
  background: var(--border-strong);
  border-radius: 2px;
}

input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #0a0a0c;
}

/* ---------- Handle fields ---------- */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.field label {
  font-size: 12px;
  color: var(--text-dim);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-weight: 600;
}

.field input[type="text"] {
  background: var(--bg);
  border: 1px solid var(--border-strong);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  padding: 11px 14px;
  border-radius: 9px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.field input[type="text"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.field-hint {
  font-size: 11px;
  color: var(--text-mute);
  align-self: flex-end;
}

.field-error {
  font-size: 12px;
  color: var(--danger);
  margin-top: 4px;
}

/* ---------- Logo option radio cards ---------- */
.logo-options {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

@media (max-width: 1100px) {
  .logo-options { grid-template-columns: 1fr 1fr; }
}

.logo-option {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  padding: 14px 12px;
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.logo-option:hover { border-color: var(--border-strong); }

.logo-option.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.logo-option input[type="radio"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.logo-option-preview {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #ffffff;
  border-radius: 6px;
  padding: 10px 8px;
  min-height: 56px;
}

/* White-text logo needs a dark backdrop in its preview so the text is visible. */
.logo-option-preview.dark {
  background: #0f1932;
}

.logo-option-preview img {
  max-width: 100%;
  max-height: 36px;
  object-fit: contain;
}

.logo-option-label {
  font-size: 12px;
  color: var(--text-dim);
  text-align: center;
  font-weight: 500;
}

.logo-option.selected .logo-option-label {
  color: var(--text);
}

/* ---------- Material option radio cards ---------- */
.material-options {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.material-options.two-col {
  grid-template-columns: 1fr 1fr;
}

.material-option {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px 16px;
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.material-option:hover { border-color: var(--border-strong); }

.material-option.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.material-option input[type="radio"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.material-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.material-desc {
  font-size: 12px;
  color: var(--text-dim);
}

/* Indent the LED size sub-options so they read as a child of the LED option. */
.led-size-options {
  padding-left: 20px;
  border-left: 2px solid var(--accent-soft);
  margin: 4px 0 4px 4px;
}

/* ---------- LED substrate (UNDER the bg image) ---------- */
/* Renders a solid white panel at the LED position UNDERNEATH the uploaded
   image, so any transparent region in a PNG at the LED location reads as
   "fully lit" — mirroring how the real Starlight LED shines through ink
   cutouts. Sits inside .card-background, before .bg-img in document order
   so the image paints on top of it. */
.card-led-substrate {
  position: absolute;
  display: none;
  background: #ffffff;
}

.card.material-led .card-led-substrate {
  display: block;
  left: 42.99%;
  top: 38.88%;
  width: 14.02%;
  height: 22.23%;
}

.card.material-led.led-small .card-led-substrate {
  left: 47.66%;
  top: 46.29%;
  width: 4.67%;
  height: 7.41%;
}

/* ---------- LED panel overlay on card ---------- */
.card-led {
  position: absolute;
  display: none;
  /* Translucent fill — the underlying design shows through. No hard border so
     the box reads as one unified translucent shape. */
  background: rgba(255, 255, 255, 0.42);
  border-radius: 1px;
  box-shadow: 0 0 14px rgba(255, 255, 255, 0.45);
  z-index: 3;
  pointer-events: none;
}

/* Default = large LED panel (12×12mm centered on a 85.6×53.98mm card) */
.card.material-led .card-led {
  display: block;
  left: 42.99%;
  top: 38.88%;
  width: 14.02%;
  height: 22.23%;
}

.card.material-led.led-small .card-led {
  left: 47.66%;
  top: 46.29%;
  width: 4.67%;
  height: 7.41%;
}

/* ---------- Brushed metal overlay on card ---------- */
.card-metal {
  position: absolute;
  inset: 0;
  display: none;
  z-index: 2;
  pointer-events: none;
  background:
    /* Prominent HORIZONTAL brushed grain — hard-edged bands of light & dark. */
    repeating-linear-gradient(
      0deg,
      rgba(255, 255, 255, 0.20) 0px,
      rgba(255, 255, 255, 0.20) 1px,
      rgba(0, 0, 0, 0.26) 1px,
      rgba(0, 0, 0, 0.26) 2px,
      rgba(255, 255, 255, 0.10) 2px,
      rgba(255, 255, 255, 0.10) 3px,
      rgba(0, 0, 0, 0.14) 3px,
      rgba(0, 0, 0, 0.14) 4px
    ),
    /* Subtle vertical luminance — top brighter, bottom darker (light from above). */
    linear-gradient(180deg,
      rgba(255, 255, 255, 0.32) 0%,
      rgba(255, 255, 255, 0.06) 32%,
      rgba(0, 0, 0, 0.12) 68%,
      rgba(0, 0, 0, 0.34) 100%);
  mix-blend-mode: overlay;
  opacity: 1;
}

.card.material-metal .card-metal {
  display: block;
}

/* Silver outer edge when the card is metal — emphasises the material change. */
.card.material-metal {
  box-shadow:
    0 0 0 2px #b0b0b0,
    0 0 0 3px rgba(255, 255, 255, 0.30),
    var(--shadow-card);
}

.color-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

input[type="color"] {
  width: 38px;
  height: 38px;
  padding: 0;
  border: 1px solid var(--border-strong);
  background: transparent;
  border-radius: 8px;
  cursor: pointer;
}

input[type="color"]::-webkit-color-swatch-wrapper { padding: 2px; }
input[type="color"]::-webkit-color-swatch { border-radius: 6px; border: none; }

/* ---------- Buttons ---------- */
.actions {
  border-top: 1px solid var(--border);
  padding: 18px 22px;
  display: flex;
  gap: 10px;
  background: rgba(0,0,0,0.2);
}

.btn {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 18px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s, transform 0.05s, border-color 0.15s;
}

.btn:active { transform: translateY(1px); }

.btn-primary {
  background: var(--accent);
  color: #001316;
}

.btn-primary:hover {
  background: var(--accent-2);
}

.btn-primary:disabled {
  background: var(--border);
  color: var(--text-mute);
  cursor: not-allowed;
}

.btn-secondary {
  background: transparent;
  color: var(--text);
  border-color: var(--border-strong);
}

.btn-secondary:hover {
  background: var(--bg-elev-2);
  border-color: var(--text-mute);
}

.ghost-btn {
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text-dim);
  padding: 9px 14px;
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
  align-self: flex-start;
}

.ghost-btn:hover {
  color: var(--text);
  border-color: var(--text-mute);
  background: rgba(255,255,255,0.02);
}

.ghost-btn.small {
  padding: 7px 10px;
  font-size: 11.5px;
}

/* ---------- Footer ---------- */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 22px 32px;
  text-align: center;
  color: var(--text-mute);
  font-size: 12px;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-elev-2);
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 13.5px;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 100;
  box-shadow: var(--shadow-lg);
  pointer-events: none;
}

.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---------- Modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal[hidden] { display: none; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: modal-fade-in 0.15s ease;
}

.modal-card {
  position: relative;
  background: var(--bg-elev-2);
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  padding: 28px 28px 22px;
  max-width: 420px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow-lg);
  animation: modal-pop-in 0.18s cubic-bezier(0.2, 0.9, 0.3, 1.1);
}

.modal-title {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin-bottom: 10px;
  color: var(--text);
}

.modal-message {
  color: var(--text-dim);
  font-size: 14px;
  margin-bottom: 22px;
  line-height: 1.55;
}

.modal-ok {
  flex: none;
  min-width: 140px;
  margin: 0 auto;
}

@keyframes modal-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes modal-pop-in {
  from { opacity: 0; transform: translateY(8px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
