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

/* ── PAGE ── */
body {
  font-family: 'NewsGothicBold', Helvetica, Arial, sans-serif;
  min-height: 100vh;
  background: #2a1a22;
  background-image:
    radial-gradient(ellipse at 20% 10%, rgba(200,96,144,0.18) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 90%, rgba(140,60,100,0.15) 0%, transparent 50%);
  padding: 0 0 32px;
  -webkit-tap-highlight-color: transparent;
}

/* Tap-friendly defaults across the configurator */
.style-btn, .color-item, .icon-btn, .copy-btn, .field-row input {
  touch-action: manipulation;
  -webkit-user-select: none; user-select: none;
}
.field-row input { -webkit-user-select: text; user-select: text; }

.page-wrap {
  max-width: 980px;
  margin: 0 auto;
  padding: 0 16px;
}

/* ── HEADER ── */
.header {
  text-align: center;
  padding: 14px 0 12px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  margin-bottom: 16px;
}
.header img.logo {
  max-height: 52px;
  object-fit: contain;
}
.header .subtitle {
  font-family: 'NewsGothicBold', Helvetica, sans-serif;
  font-size: 0.62rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.45);
  margin-top: 4px;
}

/* ── STYLE SWITCHER ── */
.style-bar {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.style-btn {
  background: rgba(255,255,255,0.08);
  border: 1.5px solid rgba(255,255,255,0.18);
  border-radius: 20px;
  color: rgba(255,255,255,0.7);
  cursor: pointer;
  font-family: 'NewsGothicBold', Helvetica, sans-serif;
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 8px 20px;
  transition: all 0.15s;
}
.style-btn:hover {
  background: rgba(200,96,144,0.25);
  border-color: rgba(200,96,144,0.6);
  color: white;
}
.style-btn.active {
  background: #c86090;
  border-color: #c86090;
  color: white;
}

/* ── MAIN GRID ── */
.main-grid {
  display: grid;
  grid-template-columns: 220px 1fr 220px;
  grid-template-areas:
    "left preview right"
    "left text    right";
  gap: 14px;
  align-items: start;
}
.col-left  { grid-area: left; }
.col-right { grid-area: right; }
#kc-wrap   { grid-area: preview; justify-self: center; align-self: start; }
.col-text  {
  grid-area: text;
  justify-self: center;
  width: 100%;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 14px;
}

@media (max-width: 740px) {
  .main-grid {
    grid-template-columns: 1fr;
    grid-template-areas:
      "preview"
      "text"
      "left"
      "right";
    gap: 14px;
  }
  #kc-wrap {
    /* Bar sticky a tope del viewport. El bg opaco evita que el contenido se vea por debajo. */
    position: sticky;
    top: 0;
    z-index: 50;
    margin: 0 -14px;  /* full-bleed dentro del page-wrap (padding 14px) */
    padding: 6px 0 12px;
    background: linear-gradient(180deg, rgba(42,26,34,0.96) 78%, rgba(42,26,34,0.88) 100%);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    box-shadow: 0 6px 18px rgba(0,0,0,0.45);
    justify-self: stretch;
  }
}

/* ── PANELS ── */
.panel {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 12px;
}
.panel-label {
  font-family: 'NewsGothicBold', Helvetica, sans-serif;
  font-size: 0.64rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.5);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 7px;
}
.panel-label .num {
  background: #c86090;
  color: white;
  width: 17px; height: 17px;
  border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 0.6rem;
  flex-shrink: 0;
}

/* ── COLOR LIST ── */
.color-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-height: 400px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: rgba(200,96,144,0.4) transparent;
}
.color-item {
  cursor: pointer;
  border-radius: 6px;
  border: 1.5px solid transparent;
  transition: border-color 0.12s, background 0.1s;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px 6px 6px;
  flex-shrink: 0;
  min-height: 36px;
}
.color-item:hover { background: rgba(255,255,255,0.07); border-color: rgba(200,96,144,0.4); }
.color-item.active { border-color: #c86090; background: rgba(200,96,144,0.12); }
.color-swatch {
  width: 24px; height: 24px;
  border-radius: 4px;
  flex-shrink: 0;
  border: 1px solid rgba(255,255,255,0.15);
}
.color-name {
  font-family: 'NewsGothicBold', Helvetica, sans-serif;
  font-size: 0.64rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.78);
}

/* ── ICON GRID ── */
.icon-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
  gap: 6px;
}
.icon-btn {
  aspect-ratio: 1;
  border-radius: 8px;
  border: 1.5px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.05);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  padding: 6px;
  transition: all 0.12s;
  position: relative;
  min-height: 44px;
}
.icon-btn img, .icon-btn svg {
  width: 100%; height: 100%;
  object-fit: contain;
  filter: brightness(0) invert(0.7);
}
.icon-btn:hover {
  background: rgba(200,96,144,0.2);
  border-color: rgba(200,96,144,0.6);
  transform: scale(1.08);
  z-index: 2;
}
.icon-btn:hover img, .icon-btn:hover svg { filter: brightness(0) invert(1); }
.icon-btn.active {
  background: #c86090;
  border-color: #a04070;
}
.icon-btn.active img, .icon-btn.active svg { filter: brightness(0) invert(1); }
/* tooltip */
.icon-btn::after {
  content: attr(data-label);
  position: absolute;
  bottom: calc(100% + 5px);
  left: 50%; transform: translateX(-50%);
  background: #222; color: white;
  font-size: 0.52rem; font-family: Helvetica, sans-serif;
  letter-spacing: 0.04em; white-space: nowrap;
  padding: 2px 6px; border-radius: 3px;
  pointer-events: none; opacity: 0; transition: opacity 0.1s; z-index: 20;
}
.icon-btn:hover::after { opacity: 1; }
.icon-msg {
  font-size: 0.68rem;
  color: rgba(255,255,255,0.4);
  text-align: center;
  padding: 10px 4px;
  letter-spacing: 0.06em;
  grid-column: 1 / -1;
}

/* ── TEXT INPUTS ── */
.text-fields { display: flex; flex-direction: column; gap: 9px; }
.field-row label {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 0.6rem; letter-spacing: 0.1em; text-transform: uppercase;
  color: rgba(255,255,255,0.4); margin-bottom: 4px;
}
.field-row label .maxlen { color: rgba(200,96,144,0.6); }
.field-row input[type="text"] {
  width: 100%;
  background: rgba(255,255,255,0.06);
  border: 1.5px solid rgba(255,255,255,0.12);
  border-radius: 7px;
  padding: 8px 11px;
  font-family: 'NewsGothicBold', Helvetica, sans-serif;
  font-size: 0.88rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: white;
  outline: none;
  transition: border-color 0.12s;
}
.field-row input[type="text"]::placeholder { color: rgba(255,255,255,0.2); }
.field-row input[type="text"]:focus { border-color: #c86090; }

/* ── PANEL TOP: ocultar en modo 1 color ── */
.panel-top { transition: opacity 0.2s; }
.panel-top.disabled { opacity: 0.3; pointer-events: none; }

/* ── PREVIEW COLUMN ── */
.col-preview {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

/* Text panel lives BELOW the keychain preview — wider than the keychain so inputs breathe */
.text-panel {
  width: 100%;
}

/* ── KEYCHAIN PREVIEW ── */
#kc-wrap {
  display: flex;
  justify-content: center;
  align-items: flex-start;
}
.kc-inner {
  position: relative;
  width: 220px;
  filter: drop-shadow(0 12px 28px rgba(0,0,0,0.6));
}
#kc-canvas {
  display: block;
  width: 220px;
  height: 367px; /* maintain aspect ratio of 240:400 = 0.6 */
}
#kc-svg {
  position: absolute;
  top: 0; left: 0;
  width: 220px; height: 367px;
  pointer-events: none;
  overflow: visible;
}

/* ── SUMMARY ── */
.summary {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 0.7rem;
  line-height: 2;
  color: rgba(255,255,255,0.7);
  width: 220px;
}
.summary strong { color: #c86090; }

/* ── COPY BUTTON ── */
.copy-btn {
  width: 100%;
  max-width: 320px;
  background: #c86090;
  color: white;
  border: none;
  border-radius: 8px;
  padding: 14px 0;
  font-family: 'NewsGothicBold', Helvetica, sans-serif;
  font-size: 0.82rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.15s;
  min-height: 48px;
}
.copy-btn:hover { background: #a04070; }
.copy-btn.ok { background: #2a8a4a; }

/* ── MOBILE-SPECIFIC TWEAKS ── */
@media (max-width: 740px) {
  .page-wrap { padding: 0 14px; }
  .header img.logo { max-height: 44px; }
  .style-btn {
    font-size: 0.78rem;
    padding: 11px 22px;
    min-height: 44px;
  }
  .panel { padding: 14px; }
  .panel-label { font-size: 0.7rem; margin-bottom: 12px; }
  .panel-label .num { width: 19px; height: 19px; font-size: 0.66rem; }
  .color-list {
    /* Slightly shorter on mobile so the page never feels trapped in a scroll well */
    max-height: 320px;
  }
  .color-item {
    padding: 9px 12px 9px 8px;
    min-height: 44px;
  }
  .color-swatch { width: 28px; height: 28px; }
  .color-name { font-size: 0.72rem; }
  .icon-grid {
    grid-template-columns: repeat(auto-fill, minmax(56px, 1fr));
    gap: 8px;
  }
  .icon-btn { min-height: 56px; padding: 9px; }
  .field-row input[type="text"] {
    padding: 12px 14px;
    font-size: 0.95rem;
    min-height: 46px;
  }
  .field-row label { font-size: 0.68rem; }
  .summary { width: 100%; max-width: 100%; }
  .text-panel { max-width: 100%; }
  .copy-btn { max-width: 100%; }
  /* Compact llavero on mobile so panels below remain tappable */
  .kc-inner { width: 140px; filter: drop-shadow(0 6px 14px rgba(0,0,0,0.55)); }
  #kc-canvas, #kc-svg { width: 140px !important; height: 234px !important; }
  /* Tooltips on icon hover get sticky on touch — hide them */
  .icon-btn::after { display: none; }
}

/* Touch devices: kill hover transforms that otherwise stick after a tap */
@media (hover: none) {
  .icon-btn:hover {
    transform: none;
    background: rgba(255,255,255,0.05);
    border-color: rgba(255,255,255,0.12);
    z-index: auto;
  }
  .icon-btn:hover img, .icon-btn:hover svg { filter: brightness(0) invert(0.7); }
  .icon-btn:hover::after { opacity: 0; }
  .icon-btn.active { background: #c86090; border-color: #a04070; }
  .icon-btn.active img, .icon-btn.active svg { filter: brightness(0) invert(1); }
  .color-item:hover { background: transparent; border-color: transparent; }
  .color-item.active { border-color: #c86090; background: rgba(200,96,144,0.12); }
  .style-btn:hover {
    background: rgba(255,255,255,0.08);
    border-color: rgba(255,255,255,0.18);
    color: rgba(255,255,255,0.7);
  }
  .style-btn.active { background: #c86090; border-color: #c86090; color: white; }
}
