/* ==========================================================================
   Kellian's Dressing Room - CSS Design System v2.0.0
   Mobile-first, professional restyle
   ========================================================================== */

:root {
  --bg-1: #0b1020;
  --bg-2: #131a30;
  --accent: #7c5cff;
  --accent-2: #a855f7;
  --accent-grad: linear-gradient(135deg, #6366f1 0%, #a855f7 100%);
  --success-grad: linear-gradient(135deg, #10b981 0%, #059669 100%);
  --danger-grad: linear-gradient(135deg, #f43f5e 0%, #e11d48 100%);

  --panel: rgba(22, 30, 52, 0.72);
  --panel-solid: #161e34;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.14);
  --text: #f4f6fb;
  --text-dim: #9aa6be;
  --card: rgba(26, 34, 56, 0.9);

  --shadow: 0 8px 24px -8px rgba(0, 0, 0, 0.5);
  --shadow-sm: 0 2px 8px -2px rgba(0, 0, 0, 0.4);

  --r-lg: 20px;
  --r-md: 14px;
  --r-sm: 10px;

  --gap: 14px;
}

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

html, body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

body {
  font-family: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  min-height: 100dvh;
  background:
    radial-gradient(1000px 600px at 80% -10%, rgba(124, 92, 255, 0.18), transparent 60%),
    radial-gradient(800px 500px at -10% 10%, rgba(168, 85, 247, 0.12), transparent 55%),
    linear-gradient(180deg, var(--bg-1) 0%, var(--bg-2) 100%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}

/* ------------------------------------------------------------------ Layout */
.app-container {
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 12px 12px calc(12px + env(safe-area-inset-bottom));
  gap: 12px;
}

/* ------------------------------------------------------------------ Header */
.app-header {
  position: sticky;
  top: 8px;
  z-index: 40;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px;
  background: var(--panel);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow);
}

.header-logo { display: flex; align-items: center; gap: 10px; min-width: 0; }

.logo-emoji { font-size: 1.5rem; animation: float 4s ease-in-out infinite; }

.app-header h1 {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  background: var(--accent-grad);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-button {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 1.15rem;
  border-radius: 12px;
  cursor: pointer;
  transition: transform 0.2s ease, background 0.2s ease;
}
.icon-button:hover { background: rgba(255, 255, 255, 0.12); }
.icon-button:active { transform: scale(0.92); }

/* -------------------------------------------------------------- Main grid */
.app-main {
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1;
  min-height: 0;
}

/* --------------------------------------------------------- Character card */
.character-section { display: flex; }

.character-card {
  width: 100%;
  background: var(--panel);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow);
}

.magic-frame {
  position: relative;
  width: 100%;
  max-width: 230px;
  aspect-ratio: 9 / 16;   /* portrait, to show Kellian head-to-toe */
  border-radius: var(--r-md);
  overflow: hidden;
  border: 1px solid var(--border-strong);
  background: #fff;
}

#kellianImg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;    /* never crops -- always the full photo */
  transition: opacity 0.4s ease;
  display: block;
}

/* Loading overlay */
.loading-overlay {
  position: absolute; inset: 0;
  background: rgba(11, 16, 32, 0.86);
  backdrop-filter: blur(6px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 18px;
  z-index: 10;
}
.sparkles-container { display: flex; gap: 12px; font-size: 2rem; }
.sparkle { animation: bounce 1.4s infinite alternate; }
.sparkle.s1 { animation-delay: 0.1s; }
.sparkle.s2 { animation-delay: 0.3s; }
.sparkle.s3 { animation-delay: 0.5s; }
.sparkle.s4 { animation-delay: 0.7s; }
.loading-text {
  font-size: 1.15rem; font-weight: 800; color: #fff;
  text-shadow: 0 0 12px rgba(168, 85, 247, 0.7);
  animation: pulse 1.4s infinite alternate;
}
.loading-bar {
  width: 72%; height: 8px;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 99px; overflow: hidden;
}
.loading-progress {
  width: 100%; height: 100%;
  background: var(--accent-grad); border-radius: 99px;
  animation: progressLoad 3.5s infinite linear;
}

/* Action buttons */
.character-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  width: 100%;
}
.action-button {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 10px;
  font-family: inherit; font-size: 0.98rem; font-weight: 700;
  color: #fff; border: none; border-radius: var(--r-md);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.2s ease, opacity 0.2s ease;
}
.action-button:active { transform: scale(0.96); }
.action-button.reset { background: var(--danger-grad); }
.action-button.download { background: var(--success-grad); }
.action-button.reset:hover { box-shadow: 0 6px 18px -4px rgba(244, 63, 94, 0.5); }
.action-button.download:hover { box-shadow: 0 6px 18px -4px rgba(16, 185, 129, 0.5); }
.btn-icon { font-size: 1.05rem; }

/* --------------------------------------------------------- Catalog panel */
.catalog-section {
  background: var(--panel);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: var(--shadow);
  flex: 1;
  min-height: 0;
}

.shelf-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.shelf-header h2 { font-size: 1.1rem; font-weight: 800; letter-spacing: -0.01em; }

/* Category chips */
.category-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  margin: 0 -2px;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.category-tabs::-webkit-scrollbar { display: none; }

.tab-button {
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 9px 14px;
  border-radius: 99px;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}
.tab-button:hover { background: rgba(255, 255, 255, 0.1); color: var(--text); }
.tab-button.active {
  background: var(--accent-grad);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 4px 14px -4px rgba(124, 92, 255, 0.6);
}

/* Search bar */
.search-bar-container { display: flex; gap: 8px; }
.search-bar-container.hidden { display: none !important; }
.web-search-input {
  flex: 1; min-width: 0;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 11px 14px;
  border-radius: var(--r-md);
  font-family: inherit; font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s ease, background 0.2s ease;
}
.web-search-input::placeholder { color: var(--text-dim); }
.web-search-input:focus { border-color: var(--accent-2); background: rgba(255, 255, 255, 0.09); }
.web-search-btn {
  flex-shrink: 0;
  background: var(--accent-grad);
  color: #fff; border: none;
  padding: 0 18px;
  border-radius: var(--r-md);
  font-family: inherit; font-size: 0.95rem; font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.2s ease;
}
.web-search-btn:hover { box-shadow: 0 6px 16px -4px rgba(124, 92, 255, 0.6); }
.web-search-btn:active { transform: scale(0.96); }

/* Scrollable grid */
.catalog-container {
  flex: 1;
  overflow-y: auto;
  min-height: 220px;
  margin: 0 -4px;
  padding: 0 4px 4px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.14) transparent;
}
.catalog-container::-webkit-scrollbar { width: 6px; }
.catalog-container::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.14); border-radius: 99px; }

.catalog-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.loading-spinner {
  grid-column: 1 / -1;
  text-align: center;
  font-size: 1rem;
  color: var(--text-dim);
  padding: 40px 12px;
  line-height: 1.5;
}

/* Clothing card */
.clothing-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  cursor: pointer;
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}
.clothing-card:active { transform: scale(0.97); }
.clothing-card:hover { border-color: var(--accent-2); box-shadow: 0 8px 20px -8px rgba(168, 85, 247, 0.5); }

.card-img-container {
  width: 100%;
  aspect-ratio: 1 / 1;
  background: #fff;
  padding: 8px;
  display: grid;
  place-items: center;
  position: relative;
}
.card-img-container img {
  max-width: 100%; max-height: 100%;
  object-fit: contain;
}
.card-img-container.img-error { background: rgba(255, 255, 255, 0.04); }
.card-img-container.img-error::after {
  content: "🧦";
  position: absolute; inset: 0;
  display: grid; place-items: center;
  font-size: 1.8rem; opacity: 0.5;
}

.try-on-overlay {
  position: absolute; inset: 0;
  background: rgba(124, 92, 255, 0.72);
  display: grid; place-items: center;
  font-size: 1.9rem;
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
}
.clothing-card:hover .try-on-overlay { opacity: 1; }

.card-info {
  padding: 9px 10px 11px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  flex: 1;
}
.card-title {
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1.25;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-tag {
  align-self: flex-start;
  margin-top: auto;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  background: rgba(168, 85, 247, 0.14);
  color: #c9b0ff;
  padding: 3px 8px;
  border-radius: 99px;
}

/* --------------------------------------------------------- Custom upload */
.custom-upload-panel { display: flex; flex-direction: column; gap: 14px; padding: 4px 0; }
.upload-box {
  border: 2px dashed var(--border-strong);
  border-radius: var(--r-md);
  padding: 26px 16px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease;
  background: rgba(255, 255, 255, 0.02);
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.upload-box:hover { border-color: var(--accent-2); background: rgba(168, 85, 247, 0.05); }
.upload-icon { font-size: 2.2rem; }
.upload-box p { font-size: 0.95rem; color: var(--text-dim); line-height: 1.4; }
.select-file-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border);
  color: #fff;
  padding: 10px 18px;
  border-radius: var(--r-md);
  font-family: inherit; font-size: 0.95rem; font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease;
}
.select-file-btn:hover { background: rgba(255, 255, 255, 0.18); }
.hidden-input { display: none; }

.custom-details {
  display: flex; gap: 14px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  padding: 14px;
  border-radius: var(--r-md);
  align-items: center;
}
.preview-thumbnail-container {
  width: 90px; height: 90px;
  border-radius: var(--r-sm);
  overflow: hidden;
  background: #fff;
  padding: 6px;
  display: grid; place-items: center;
  flex-shrink: 0;
}
.preview-thumbnail-container img { max-width: 100%; max-height: 100%; object-fit: contain; }
.custom-inputs { display: flex; flex-direction: column; gap: 8px; flex: 1; min-width: 0; }
.custom-inputs label { font-size: 0.9rem; font-weight: 600; color: var(--text-dim); }
.custom-inputs input {
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border);
  color: #fff;
  padding: 10px;
  border-radius: var(--r-sm);
  font-family: inherit; font-size: 0.95rem;
  width: 100%;
}
.action-button.try-custom { background: var(--accent-grad); margin-top: 4px; }
.action-button.try-custom:hover { box-shadow: 0 6px 18px -4px rgba(124, 92, 255, 0.6); }

/* --------------------------------------------------------------- Modal */
.modal {
  position: fixed; inset: 0;
  background: rgba(11, 16, 32, 0.72);
  backdrop-filter: blur(6px);
  display: flex; justify-content: center; align-items: center;
  z-index: 100;
  padding: 16px;
}
.modal-content {
  background: var(--panel-solid);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  width: 100%; max-width: 440px;
  box-shadow: var(--shadow);
  overflow: hidden;
  animation: modalOpen 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 1.05rem; font-weight: 800; }
.close-button { background: none; border: none; color: var(--text-dim); font-size: 1.6rem; line-height: 1; cursor: pointer; }
.close-button:hover { color: #fff; }
.modal-body { padding: 18px; display: flex; flex-direction: column; gap: 16px; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-size: 0.95rem; font-weight: 600; }
.form-group input, .form-group select {
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border);
  color: #fff;
  padding: 11px;
  border-radius: var(--r-sm);
  font-family: inherit; font-size: 0.95rem;
}
.form-group small { font-size: 0.8rem; color: var(--text-dim); line-height: 1.4; }
.store-select option, select option { background-color: var(--panel-solid); color: var(--text); }
.save-settings-btn {
  background: var(--accent-grad);
  color: #fff; border: none;
  font-family: inherit; font-size: 1rem; font-weight: 700;
  padding: 12px;
  border-radius: var(--r-md);
  cursor: pointer;
  transition: box-shadow 0.2s ease;
  width: 100%;
}
.save-settings-btn:hover { box-shadow: 0 6px 18px -4px rgba(124, 92, 255, 0.6); }

/* ------------------------------------------------------------ Utilities */
.hidden { display: none !important; }

/* --------------------------------------------------------- Animations */
@keyframes float {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-6px) rotate(6deg); }
}
@keyframes bounce { from { transform: translateY(0) scale(1); } to { transform: translateY(-9px) scale(1.05); } }
@keyframes pulse { from { opacity: 0.55; } to { opacity: 1; } }
@keyframes progressLoad { 0% { width: 0%; } 50% { width: 70%; } 100% { width: 100%; } }
@keyframes modalOpen { from { transform: translateY(12px) scale(0.98); opacity: 0; } to { transform: none; opacity: 1; } }

/* =========================================================================
   Larger screens: two-column layout
   ========================================================================= */
@media (min-width: 860px) {
  .app-container {
    max-width: 1080px;
    padding: 20px 20px calc(20px + env(safe-area-inset-bottom));
    gap: 16px;
  }
  .app-header { padding: 14px 20px; }
  .app-header h1 { font-size: 1.4rem; }
  .logo-emoji { font-size: 1.8rem; }

  .app-main {
    display: grid;
    grid-template-columns: minmax(300px, 380px) 1fr;
    align-items: start;
    gap: 16px;
  }
  .character-section { position: sticky; top: 84px; }
  .magic-frame { max-width: 270px; }
  .catalog-section { max-height: calc(100dvh - 130px); }
  .catalog-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .card-title { font-size: 0.88rem; }
}

@media (min-width: 1100px) {
  .app-main { grid-template-columns: 400px 1fr; }
}

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