/* ============================================================
   Theme Studio Editor - Styles
   Layered structure:
     1. Tokens (variables, reset)
     2. Layout (shell, sidebar, main grid)
     3. Sidebar
     4. Panels & section headers
     5. Subsections & field groups
     6. Field types (text, number, select, range, toggle, color)
     7. Color picker popover
     8. Buttons & notes
     9. Preview (pack card, phone, icon tile)
    10. Responsive
   ============================================================ */

/* ----- 1. TOKENS ------------------------------------------------ */

:root {
  --color-bg-deep: #131313;
  --color-bg-surface: rgba(255, 255, 255, 0.04);
  --color-bg-surface-2: rgba(255, 255, 255, 0.06);
  --color-bg-input: #181818;
  --color-border: rgba(255, 255, 255, 0.07);
  --color-border-strong: rgba(255, 255, 255, 0.14);
  --color-text: #e8eaed;
  --color-text-soft: rgba(232, 234, 237, 0.80);
  --color-text-muted: rgba(232, 234, 237, 0.55);
  --color-text-faint: rgba(232, 234, 237, 0.38);

  --accent: #815CD2;             /* singular purple (replaces #0057d6) */
  --accent-strong: #7A00FF;      /* vivid purple — hover / focus */
  --accent-warm: linear-gradient(135deg, #312CA2, #E69BF0);

  --section-name: #a0a8b3;
  --section-icon: #6BC5DA;
  --section-widget: #6bafd9;
  --section-wallpaper: #b285d9;

  --radius-xs: 6px;
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-xl: 28px;

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-7: 2.75rem;

  --shadow-card: 0 16px 48px rgba(0, 0, 0, 0.28);
  --shadow-popover: 0 16px 42px rgba(0, 0, 0, 0.42);

  font-family: "Avenir Next", "Inter", "Trebuchet MS", system-ui, sans-serif;
  color: var(--color-text);
  line-height: 1.45;
  font-weight: 400;
  font-feature-settings: "tnum" 1;
  background: #131313;
}

* { box-sizing: border-box; }

html {
  scrollbar-gutter: stable;
  background: #131313;
}

html::-webkit-scrollbar {
  width: 12px;
}

html::-webkit-scrollbar-track {
  background: #131313;
}

html::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  border: 3px solid #131313;
}

html::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
}

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3, h4, h5 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }

#root.loading {
  display: grid;
  place-items: center;
  min-height: 100vh;
  color: var(--color-text-muted);
  font-size: 0.95rem;
  letter-spacing: 0.04em;
}

/* ----- 2. LAYOUT ------------------------------------------------ */

.app-shell {
  display: grid;
  grid-template-columns: 320px minmax(0, 1192px);
  min-height: 100vh;
  width: 100%;
  max-width: 1512px;
  margin: 0 auto;
}

.main-content {
  padding: var(--space-5);
  min-width: 0;
}

.page-grid {
  display: grid;
  grid-template-columns: minmax(0, 560px) minmax(0, 1fr);
  gap: var(--space-5);
  align-items: start;
}

.content-column {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  min-width: 0;
}

.preview-column {
  min-width: 0;
  position: sticky;
  top: var(--space-5);
  align-self: start;
}

/* ----- 3. SIDEBAR ----------------------------------------------- */

.sidebar {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  padding: var(--space-5);
  border-right: 1px solid var(--color-border);
  background: #0e0e0e;
  backdrop-filter: blur(24px);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: hidden;
}

.sidebar-header {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.sidebar-header h1 {
  font-size: 1.4rem;
  letter-spacing: -0.015em;
}

.eyebrow {
  margin: 0;
  font-size: 0.68rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: #398bff;
  font-weight: 600;
}

.muted, .preview-label {
  margin: 0;
  color: var(--color-text-muted);
  font-size: 0.88rem;
}

.sidebar-tool-link {
  display: inline-block;
  margin-top: var(--space-2);
  padding: 6px 10px;
  font-size: 0.78rem;
  text-decoration: none;
  color: #398bff;
  border: 1px solid rgba(57, 139, 255, 0.35);
  border-radius: 6px;
  background: rgba(57, 139, 255, 0.08);
  align-self: flex-start;
}
.sidebar-tool-link:hover {
  background: rgba(57, 139, 255, 0.18);
  border-color: rgba(57, 139, 255, 0.6);
}

.list-panel {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  overflow-y: auto;
  padding-right: var(--space-1);
  margin-right: calc(-1 * var(--space-1));
}

.list-panel::-webkit-scrollbar { width: 6px; }
.list-panel::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 999px; }

/* Accordion sections — "My Themes" / "Curated Themes" at the top level,
   per-pack accordions nested inside "Curated Themes". */
.sidebar-accordion {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.sidebar-accordion .accordion-summary {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.6rem 0.7rem;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  color: var(--color-text);
  cursor: pointer;
  font-size: 0.92rem;
  font-weight: 600;
  text-align: left;
  width: 100%;
}
.sidebar-accordion .accordion-summary:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--color-border-strong);
}
.sidebar-accordion .accordion-chevron {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  color: var(--color-text-muted);
  font-size: 0.75rem;
}
.sidebar-accordion .accordion-title {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-width: 0;
}
.sidebar-accordion .accordion-count {
  font-size: 0.72rem;
  color: var(--color-text-muted);
  font-weight: 500;
  padding-left: 0.6rem;
}
.sidebar-accordion .accordion-body {
  padding: var(--space-3) 0 var(--space-2);
}
.sidebar-accordion .accordion-content {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}
.sidebar-accordion .accordion-empty {
  margin: 0;
  font-size: 0.82rem;
  padding: 0.25rem 0.1rem;
}
.sidebar-accordion .accordion-empty-sub {
  margin: 0;
  font-size: 0.72rem;
  opacity: 0.7;
}

/* Stack accordions with spacing between them */
.list-panel > .sidebar-accordion + .sidebar-accordion {
  margin-top: var(--space-3);
}

/* Nested per-pack accordions inside Curated Themes — visually demoted */
.sidebar-accordion.nested .accordion-summary {
  background: transparent;
  border-color: rgba(255, 255, 255, 0.05);
  font-size: 0.85rem;
  padding: 0.45rem 0.55rem;
}
.sidebar-accordion .accordion-content.nested {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.sidebar-accordion .accordion-content.nested > .sidebar-accordion + .sidebar-accordion {
  margin-top: 0;
}

/* Flat 2-column grid of saved themes (replaces the pack tree). */
.theme-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
}

.theme-grid-tile {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 5px;
  background: transparent;
  border: 1.5px solid transparent;
  border-radius: calc(var(--radius-md) + 4px);
  cursor: pointer;
  text-align: left;
  color: inherit;
}
.theme-grid-tile:hover { border-color: var(--color-border-strong); }
.theme-grid-tile.is-active { border-color: var(--accent); }

.theme-grid-tile-preview {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: #2c2c2e;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  padding: 0.4rem;
}

/* Smaller widget + icons for the sidebar tile size. The pack-preview-tile
   targeted 132 px; the sidebar tile is whatever the grid cell is. Override
   the inner sizing so it looks proportional. */
.theme-grid-tile-preview .mini-widget { padding: 0.35rem; gap: 0.18rem; }
.theme-grid-tile-preview .mini-clock-time { font-size: 0.6rem; line-height: 1; font-weight: 700; }
.theme-grid-tile-preview .mini-clock-date { font-size: 0.42rem; }
.theme-grid-tile-preview .mini-clock-dot { width: 0.32rem; height: 0.32rem; border-radius: 50%; }
.theme-grid-tile-preview .mini-clock-line { height: 1.5px; }
.theme-grid-tile-preview .mini-icons { gap: 0.25rem; }
.theme-grid-tile-preview .icon-tile { border-radius: 22%; }

.theme-grid-name {
  font-size: 0.82rem;
  color: var(--color-text-soft);
  padding: 0 var(--space-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pack-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.pack-button, .theme-button {
  display: grid;
  grid-template-columns: auto 1fr 44px;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-bg-surface);
  color: inherit;
}

/* Middle column (name) — always centered regardless of right-side tag */
.pack-button > :nth-child(2),
.theme-button > :nth-child(2) {
  text-align: center;
}

/* Right column (Free pill or count) */
.pack-button > .pill,
.pack-button > .tag,
.theme-button > .pill,
.theme-button > .tag {
  justify-self: end;
  text-align: left;
  font-size: 0.72rem;
  transition: background 0.12s ease, border-color 0.12s ease;
}

.pack-button:hover, .theme-button:hover {
  background: var(--color-bg-surface-2);
  border-color: var(--color-border-strong);
}

.pack-button.active, .theme-button.active {
  border-color: rgba(0, 87, 214, 0.7);
  background: rgba(0, 87, 214, 0.13);
}

.theme-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding-left: var(--space-3);
  border-left: 1px dashed var(--color-border);
  margin-left: var(--space-3);
}

.theme-button {
  padding: 0.2rem 0.8rem;
  font-size: 0.8rem;
}


.pill, .tag {
  border-radius: 999px;
  padding: 0.1rem 0.55rem;
  background: rgba(255, 255, 255, 0.08);
  font-size: 0.72rem;
  color: var(--color-text-soft);
}

.tag {
  background: rgba(0, 87, 214, 0.18);
  color: #c4e0f7;
}

.add-pack-btn {
  width: 100%;
  padding: 0.6rem var(--space-3);
  border: 1px dashed var(--color-border-strong);
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--color-text-muted);
  font-size: 0.88rem;
  text-align: center;
  transition: border-color 0.12s ease, color 0.12s ease, background 0.12s ease;
}

.add-pack-btn:hover {
  border-color: rgba(0, 87, 214, 0.5);
  color: var(--accent);
  background: rgba(0, 87, 214, 0.05);
}

.status-bar {
  margin-top: auto;
  padding-top: var(--space-3);
  border-top: 1px solid var(--color-border);
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

.status-busy { color: #ffd07d; }

/* ----- 4. WORKSPACE PANELS ------------------------------------- */

.workspace-panel {
  border-radius: var(--radius-xl);
  background: var(--color-bg-surface);
  padding: var(--space-5);
  width: 100%;
  max-width: 560px;
  box-sizing: border-box;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}

.panel-header h2 {
  font-size: 1.6rem;
  letter-spacing: -0.02em;
}

/* the top-level form inside theme panel */
form.workspace-panel { padding: var(--space-5); }

/* ----- 5. SUBSECTIONS & FIELD GROUPS --------------------------- */

.subsection {
  margin-top: var(--space-3);
  padding: 0;
  position: relative;
}

.subsection:first-of-type {
  margin-top: var(--space-3);
}

.field-section { grid-column: 1 / -1; }

.subsection-header {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  margin-bottom: var(--space-4);
  padding-left: var(--space-3);
  border-left: 3px solid var(--section-name);
}

.subsection-header h3 {
  font-size: 1.15rem;
  letter-spacing: -0.01em;
}

.subsection-eyebrow {
  margin: 0;
  font-size: 0.68rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}

.subsection-name      .subsection-header { border-left-color: var(--section-name); }
.subsection-icon      .subsection-header { border-left-color: var(--section-icon); }
.subsection-widget    .subsection-header { border-left-color: var(--section-widget); }
.subsection-wallpaper .subsection-header { border-left-color: var(--section-wallpaper); }

.subsection-icon      .subsection-eyebrow { color: var(--section-icon); }
.subsection-widget    .subsection-eyebrow { color: var(--section-widget); }
.subsection-wallpaper .subsection-eyebrow { color: var(--section-wallpaper); }
.subsection-name      .subsection-eyebrow { color: var(--section-name); }

.subsection-body { padding: 0; }

.form-grid {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

/* Field groups - sub-cards inside subsections */
.field-group {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: rgba(0, 0, 0, 0.18);
  overflow: visible;
  position: relative;
}

.field-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.7rem var(--space-4);
  background: rgba(255, 255, 255, 0.025);
  border-bottom: 1px solid var(--color-border);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.field-group-header h4 {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--color-text-soft);
}

.field-group-header--toggle {
  width: 100%;
  background: rgba(255, 255, 255, 0.025);
  border: 0;
  cursor: pointer;
  transition: background 0.12s ease;
}

.field-group-header--toggle:hover {
  background: rgba(255, 255, 255, 0.05);
}

.field-group-header--toggle h4 {
  margin: 0;
}

.field-group--collapsible .field-group-header--toggle:not(.is-expanded) {
  border-bottom: 0;
  border-radius: var(--radius-lg);
}

.field-group-chevron {
  color: var(--color-text-muted);
  font-size: 1.1rem;
  margin-left: var(--space-2);
  line-height: 1;
}

.ghost-button {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: var(--color-text-muted);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 0.8rem;
  padding: 0.3rem 0.7rem;
  transition: border-color 0.12s ease, color 0.12s ease;
}

.ghost-button:hover {
  border-color: rgba(0, 87, 214, 0.4);
  color: var(--color-text);
}

.ghost-button--small {
  font-size: 0.7rem;
  padding: 0.2rem 0.55rem;
}

.field-group-body {
  display: flex;
  flex-direction: column;
}

/* ----- 6. FIELD TYPES ------------------------------------------ */

.field {
  display: grid;
  align-items: center;
  gap: var(--space-3);
  padding: 0.7rem var(--space-4);
  border-bottom: 1px solid var(--color-border);
  font-size: 0.92rem;
}

.field-group-body .field:last-child { border-bottom: 0; }

.field-label {
  font-size: 0.86rem;
  color: var(--color-text-soft);
  letter-spacing: 0;
  margin-right: 5px;
}

/* baseline single-row layout (text, number, select, color) */
.text-field, .number-field, .select-field, .color-field {
  grid-template-columns: minmax(120px, 0.9fr) minmax(0, 1.3fr);
}

/* Inputs */
.field input[type="text"],
.field input:not([type]),
.field input[type="number"] {
  width: 100%;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.75rem;
  background: var(--color-bg-input);
  color: inherit;
  font-size: 0.9rem;
  transition: border-color 0.12s ease, background 0.12s ease;
}

.field input:focus {
  outline: none;
  border-color: rgba(0, 87, 214, 0.6);
  background: rgba(5, 8, 12, 0.8);
}

.text-field.is-readonly input {
  color: var(--color-text-muted);
  background: rgba(255, 255, 255, 0.025);
  cursor: default;
}

/* Select */
.select-wrap {
  position: relative;
  display: block;
}

.select-wrap::after {
  content: "";
  position: absolute;
  right: 0.85rem;
  top: 50%;
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--color-text-muted);
  border-bottom: 2px solid var(--color-text-muted);
  transform: translateY(-65%) rotate(45deg);
  pointer-events: none;
}

.select-input {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 0.55rem 2.2rem 0.55rem 0.75rem;
  background: var(--color-bg-input);
  color: inherit;
  font-size: 0.9rem;
  cursor: pointer;
}

.select-input:focus {
  outline: none;
  border-color: rgba(0, 87, 214, 0.6);
}

/* Range field - label + value above, slider full-width below */
.range-field {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.range-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.field-value {
  font-variant-numeric: tabular-nums;
  font-size: 0.85rem;
  color: var(--color-text-soft);
  background: rgba(255, 255, 255, 0.06);
  border-radius: 999px;
  padding: 0.1rem 0.55rem;
  min-width: 2.4rem;
  text-align: center;
}

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

input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  background: linear-gradient(90deg, rgba(0, 87, 214, 0.55), rgba(60, 130, 240, 0.55));
  border-radius: 999px;
}

input[type="range"]::-moz-range-track {
  height: 4px;
  background: linear-gradient(90deg, rgba(0, 87, 214, 0.55), rgba(60, 130, 240, 0.55));
  border-radius: 999px;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 999px;
  background: #fff;
  border: 0;
  margin-top: -6px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.4), 0 0 0 1px rgba(0,0,0,0.1);
  cursor: grab;
}

input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 999px;
  background: #fff;
  border: 0;
  box-shadow: 0 2px 6px rgba(0,0,0,0.4);
  cursor: grab;
}

input[type="range"]:active::-webkit-slider-thumb { cursor: grabbing; }

/* Toggle / switch */
.toggle-field {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.7rem var(--space-4);
  border-bottom: 1px solid var(--color-border);
  font-size: 0.92rem;
}

.field-group-body .toggle-field:last-child { border-bottom: 0; }

.switch {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
  flex: 0 0 auto;
}

.switch input {
  position: absolute;
  inset: 0;
  opacity: 0;
  margin: 0;
  cursor: pointer;
}

.switch-track {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  transition: background 0.16s ease;
}

.switch-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 2px 4px rgba(0,0,0,0.3);
  transition: transform 0.16s ease;
}

.switch input:checked ~ .switch-track { background: var(--accent-warm); }
.switch input:checked ~ .switch-track .switch-thumb { transform: translateX(18px); }

/* Color field */
.color-input {
  position: relative;
  display: grid;
  grid-template-columns: 36px 1fr;
  gap: var(--space-3);
  align-items: center;
}

.color-swatch-button {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--color-border-strong);
  background: #000;
  box-shadow: inset 0 0 0 2px rgba(0,0,0,0.25), 0 1px 2px rgba(0,0,0,0.4);
  padding: 0;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.color-swatch-button:hover { transform: scale(1.05); }
.color-swatch-button.active {
  box-shadow: inset 0 0 0 2px rgba(0,0,0,0.25), 0 0 0 2px rgba(0, 87, 214, 0.65);
}

.color-input input {
  font-family: "JetBrains Mono", "SF Mono", ui-monospace, monospace;
  font-size: 0.84rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ----- 7. COLOR POPOVER ---------------------------------------- */

.color-popover {
  position: absolute;
  top: calc(100% + 0.5rem);
  left: 0;
  z-index: 30;
  width: 240px;
  padding: var(--space-3);
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border-strong);
  background: rgba(10, 14, 20, 0.97);
  box-shadow: var(--shadow-popover);
  backdrop-filter: blur(20px);
}

.color-popover.hidden { display: none; }

.color-surface {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  cursor: crosshair;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.color-surface-thumb {
  position: absolute;
  width: 16px;
  height: 16px;
  border-radius: 999px;
  border: 2px solid white;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.5);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.color-hue { margin-top: var(--space-3); }

.color-hue input {
  width: 100%;
  padding: 0;
  border: 0;
  background: linear-gradient(90deg, #f00, #ff0, #0f0, #0ff, #00f, #f0f, #f00);
  appearance: none;
  -webkit-appearance: none;
  height: 12px;
  border-radius: 999px;
}

.color-hue input::-webkit-slider-runnable-track {
  background: transparent;
  height: 12px;
}

.color-hue input::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 999px;
  background: #fff;
  border: 0;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.5);
  margin-top: 0;
}

/* ----- 8. BUTTONS & NOTES -------------------------------------- */

.form-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  margin-top: var(--space-1);
  padding-top: var(--space-4);
  gap: var(--space-2);
}
.form-action-leading { margin-right: auto; }

.primary-button, .secondary-button, .danger-button {
  border: 0;
  border-radius: 999px;
  padding: 0.65rem 1.1rem;
  font-weight: 600;
  font-size: 0.88rem;
  letter-spacing: 0.01em;
  transition: transform 0.1s ease, filter 0.1s ease, box-shadow 0.1s ease;
}

.primary-button {
  background: var(--accent-warm);
  color: #ffffff;
}
.secondary-button { background: rgba(255, 255, 255, 0.85); color: #14181f; }
.danger-button {
  background: linear-gradient(135deg, #d95470, #e11010);
  color: #fff;
}

.primary-button:hover, .secondary-button:hover, .danger-button:hover { filter: brightness(1.05); }
.primary-button:active, .secondary-button:active, .danger-button:active { transform: translateY(1px); }
.primary-button:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }

/* Notes */
.notes-panel { margin-top: var(--space-3); }
.notes-form { display: flex; flex-direction: column; gap: var(--space-3); }

.notes-textarea {
  width: 100%;
  min-height: 200px;
  resize: vertical;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  background: var(--color-bg-input);
  color: inherit;
  font-family: "JetBrains Mono", "SF Mono", ui-monospace, monospace;
  font-size: 0.85rem;
  line-height: 1.55;
}

.notes-textarea:focus {
  outline: none;
  border-color: rgba(0, 87, 214, 0.5);
}

/* ----- 9. PREVIEW ---------------------------------------------- */

.preview-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  padding: var(--space-5);
  max-width: 560px;
  background: #1c1c1c;
  transition: background 0.18s ease;
}
.preview-panel.is-light-bg { background: #d8dde6; color: #18202c; }
.preview-panel.is-light-bg .eyebrow,
.preview-panel.is-light-bg .pack-preview-meta,
.preview-panel.is-light-bg .pack-preview-hint { color: #4a5468; }

.preview-bg-toggle {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--color-border);
  border-radius: 50%;
  background: var(--color-bg-surface);
  color: inherit;
  cursor: pointer;
  padding: 0;
  z-index: 2;
  transition: background 0.12s, border-color 0.12s;
}
.preview-bg-toggle:hover { background: var(--color-bg-surface-2); }
.preview-bg-toggle svg { width: 16px; height: 16px; display: block; }
.preview-panel.is-light-bg .preview-bg-toggle { background: rgba(0,0,0,0.06); border-color: rgba(0,0,0,0.18); }
.preview-panel.is-light-bg .preview-bg-toggle:hover { background: rgba(0,0,0,0.10); }

.pack-preview-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-3);
}

/* Square pack-preview tile on the left, layout-template switcher
   immediately to its right. Both shrink-wrap their content — the
   tile keeps its fixed 132×132, the switcher hugs its trigger. */
.pack-preview-row {
  display: flex;
  align-items: start;
  gap: var(--space-3);
}

.pack-preview-tile-wrap,
.pack-preview-layout-wrap {
  flex: 0 0 auto;
  min-width: 0;
}

.pack-preview-tile {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 0.55rem;
  width: 132px;
  height: 132px;
  border-radius: var(--radius-md);
}

.pack-preview-meta {
  margin: 0;
  font-size: 0.82rem;
  color: var(--color-text-muted);
}

.mini-widget, .phone-widget {
  display: flex;
  flex-direction: column;
  gap: 0.28rem;
  border-radius: var(--radius-sm);
  padding: 0.55rem;
}

.mini-widget { min-height: 27px; }

.widget-line { height: 5px; border-radius: 999px; }
.widget-line.strong { height: 7px; }
.widget-accent { margin-top: auto; height: 4px; border-radius: 999px; }

.mini-icons, .phone-icons {
  display: grid;
  gap: 0.4rem;
}

.mini-icons { grid-template-columns: repeat(2, 1fr); }

.phone-preview-panel {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  justify-content: flex-start;
  gap: var(--space-3);
  padding: 0;
  background: transparent;
  border: 0;
  flex-wrap: wrap;
}

.preview-col {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  align-items: stretch;
  flex: 1 1 0;
  min-width: 0;
}
.preview-col:has(.phone-frame)     { flex: 3 1 0; }
.preview-col:has(.large-icon-wrap) { flex: 2 1 0; }

.phone-frame {
  width: 100%;
  aspect-ratio: 9 / 19.5;
  /* Asymmetric % keeps the corners circular at any size:
     16% × width = 7.4% × height when aspect-ratio is 9/19.5 (W×19.5/9 = H,
     so 16%·W = 16% × W and 7.4%·H = 7.4% × W × 19.5/9 ≈ 16%·W).
     Visually ≈40px at a 250px-wide preview, scales down with the window. */
  border-radius: 16% / 7.4%;
  padding: 5% 6%;
  border: 1px solid var(--color-border-strong);
  display: flex;
  flex-direction: column;
  gap: 2%;
  overflow: hidden;
}

.status-notch {
  align-self: center;
  width: 32%;
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.25);
}

.phone-widget { min-height: 74px; }

.phone-icons {
  margin-top: auto;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.phone-icons .icon-tile:last-child { grid-column: 1 / 2; }

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

.preview-section-label {
  margin: 0;
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--color-text-faint);
}

.large-icon-wrap {
  width: 100%;
  aspect-ratio: 1 / 1;
  flex-shrink: 0;
}

.large-icon-wrap .icon-tile {
  width: 100%;
  height: 100%;
  border-radius: 26%;
}

/* Icon tile internals */
.icon-tile {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1 / 1;
  border-radius: 30%;
  overflow: hidden;
}

.icon-layer {
  position: relative;
  width: 75%;
  height: 75%;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-glyph, .icon-source {
  width: 100%;
  height: 100%;
  display: block;
}

.icon-source { object-fit: contain; }

.icon-overlay-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.blur-base {
  position: absolute;
  inset: 0;
}

.blur-layer {
  position: absolute;
  inset: 0;
  background-repeat: no-repeat;
  background-position: center;
  background-size: 62% 62%;
  pointer-events: none;
}

.empty-panel {
  min-height: 320px;
  display: grid;
  place-items: center;
  text-align: center;
  gap: var(--space-2);
}

/* ----- 10. RESPONSIVE ----------------------------------------- */

@media (max-width: 1180px) {
  .app-shell { grid-template-columns: 1fr; }
  .page-grid { grid-template-columns: 1fr; }

  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--color-border);
  }

  .preview-column { position: static; }
}

@media (max-width: 760px) {
  .main-content, .sidebar { padding: var(--space-4); }

  .text-field, .number-field, .select-field, .color-field {
    grid-template-columns: 1fr;
    gap: var(--space-2);
  }

  .panel-header {
    flex-direction: column;
    align-items: flex-start;
  }
}

/* ----- 11. THEME NAME ROW --------------------------------------- */

.theme-name-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}

/* Preview-layout picker — SVG thumbnails of each layout, with the
   current one shown as the trigger and a popover showing all 11 options
   (Auto + 0..9). Lives inside the Icon Pack field group. */
.layout-picker {
  position: relative;
  display: flex;
  justify-content: flex-start;
}

/* Informational note shown inside a field group (e.g. the Baked-In tab
   body) — explains a feature without taking the visual weight of an
   editable field. */
.field-note {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-3);
  background: var(--color-bg-input);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
}
.field-note p { margin: 0; line-height: 1.4; font-size: 0.85rem; }
.field-note p.small { font-size: 0.78rem; }

.layout-picker-trigger {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px 4px 4px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  cursor: pointer;
  color: var(--color-text-soft);
  transition: border-color 0.12s ease, background 0.12s ease, color 0.12s ease;
}
.layout-picker-trigger:hover {
  background: rgba(255, 255, 255, 0.07);
  border-color: var(--color-border-strong);
  color: var(--color-text);
}

.layout-picker-thumb {
  display: inline-block;
  width: 28px;
  height: 42px;
  border-radius: 4px;
  overflow: hidden;
  flex-shrink: 0;
}
.layout-picker-thumb svg {
  display: block;
  width: 100%;
  height: 100%;
}

.layout-picker-caret {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.layout-picker-popover {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(6, auto);
  gap: 6px;
  padding: 8px;
  background: var(--color-bg-elevated, #1c1c1c);
  border: 1px solid var(--color-border-strong, rgba(255,255,255,0.18));
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
}
.layout-picker-popover.hidden { display: none; }

.layout-picker-option {
  padding: 3px;
  background: transparent;
  border: 1.5px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  transition: border-color 0.1s ease, background 0.1s ease;
}
.layout-picker-option:hover {
  background: rgba(255, 255, 255, 0.06);
}
.layout-picker-option.is-active {
  border-color: var(--accent);
  background: rgba(255, 255, 255, 0.04);
}
.layout-picker-option .layout-picker-thumb {
  width: 36px;
  height: 54px;
}

.theme-name-row input {
  flex: 1;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.75rem;
  background: var(--color-bg-input);
  color: inherit;
  font-size: 0.9rem;
  transition: border-color 0.12s ease;
}

.theme-name-row input:focus {
  outline: none;
  border-color: rgba(0, 87, 214, 0.6);
}

.theme-name-row .toggle-field {
  flex-shrink: 0;
  border-bottom: 0;
  padding: 0;
  gap: var(--space-2);
  font-size: 0.78rem;
  color: var(--color-text-soft);
}
.theme-name-row .switch {
  width: 30px;
  height: 17px;
}
.theme-name-row .switch-thumb {
  top: 2px;
  left: 2px;
  width: 13px;
  height: 13px;
}
.theme-name-row .switch input:checked ~ .switch-track .switch-thumb {
  transform: translateX(13px);
}

/* ----- 12. TABS (renumbered) ------------------------------------ */

.tab-bar {
  display: flex;
  gap: 0;
  padding: 0;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: rgba(255, 255, 255, 0.02);
}

.tab-btn {
  flex: 1;
  border: 0;
  border-radius: 0;
  padding: 0.5rem 0.5rem;
  font-size: 0.85rem;
  font-weight: 500;
  background: transparent;
  color: var(--color-text-muted);
  transition: background 0.12s ease, color 0.12s ease;
  border-right: 1px solid var(--color-border);
}

.tab-btn:last-child { border-right: 0; }

.tab-btn:hover {
  background: var(--color-bg-surface-2);
  color: var(--color-text-soft);
}

.tab-btn.active {
  background: var(--accent);
  color: #ffffff;
}

/* Container spacing for the Icon/Widget/Wallpaper switcher (top-level tabs)
   vs the bg-type tabs that sit inside a field-group body. */
.tab-bar:not(.bg-type-tabs) {
  margin: var(--space-6) 0 var(--space-2);
}

.tab-bar.bg-type-tabs {
  margin: var(--space-3) var(--space-4);
}

/* ----- 12. PANEL HEADER ACTIONS --------------------------------- */

.panel-header-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: none;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--color-text-soft);
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease, transform 0.08s ease;
}

.icon-button svg {
  width: 18px;
  height: 18px;
  display: block;
}

.icon-button:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--color-border-strong);
  color: var(--color-text);
}

.icon-button:active {
  transform: translateY(1px);
}

.icon-button:disabled,
.icon-button[disabled] {
  opacity: 0.35;
  cursor: not-allowed;
  background: rgba(255, 255, 255, 0.02);
}
.icon-button:disabled:hover,
.icon-button[disabled]:hover {
  background: rgba(255, 255, 255, 0.02);
  border-color: var(--color-border);
  color: var(--color-text-soft);
}

.icon-button--danger {
  color: #f29b9b;
  border: 1px solid rgba(225, 16, 16, 0.35);
  background: rgba(225, 16, 16, 0.07);
}

.icon-button--danger:hover {
  color: #fff;
  background: linear-gradient(135deg, #d95470, #e11010);
  border-color: transparent;
}

/* Save button — bright primary blue, white diskette icon. Always emphasized
   so users can hit Save without scrolling to the bottom of the form. */
.icon-button--save {
  color: #fff;
  background: var(--accent-warm);
  border-color: transparent;
}
.icon-button--save:hover {
  color: #fff;
  filter: brightness(1.08);
  background: var(--accent-warm);
  border-color: transparent;
}
.icon-button--save:active { filter: brightness(0.95); }

/* ----- 13. COLOR CHIPS ------------------------------------------ */

.color-chips-editor {
  display: flex;
  flex-direction: column;
}

.color-chips-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: var(--space-3) var(--space-4) var(--space-2);
  align-items: center;
}

.color-chips-add-row {
  padding: 0 var(--space-4) var(--space-3);
}

.color-chip-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.color-chip-field {
  display: block;
  padding: 0;
  border: none;
}

.color-chip-field .color-swatch-button {
  width: 36px;
  height: 36px;
}

.chip-remove-btn {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  border: 1px solid var(--color-border-strong);
  color: var(--color-text-muted);
  font-size: 0.7rem;
  line-height: 1;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.12s ease;
}

.color-chip-wrap:hover .chip-remove-btn { opacity: 1; }

.chip-add-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1.5px dashed rgba(255, 255, 255, 0.25);
  background: transparent;
  color: var(--color-text-muted);
  font-size: 1.1rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.12s ease, color 0.12s ease;
}

.chip-add-btn:hover {
  border-color: rgba(0, 87, 214, 0.5);
  color: var(--accent);
}

/* ----- 14. ICON PACK CHOOSER ----------------------------------- */

.icon-pack-chooser {
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  gap: 6px;
  padding: var(--space-3) var(--space-4) var(--space-3);
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

.pack-chooser-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 4px 2px;
  border-radius: 8px;
  border: 1.5px solid transparent;
  background: transparent;
  cursor: pointer;
  transition: border-color 0.12s ease, background 0.12s ease;
  width: 100%;
  min-width: 0;
}

.pack-chooser-tile:hover {
  background: rgba(255, 255, 255, 0.05);
}

.pack-chooser-tile--active {
  border-color: var(--accent);
  background: transparent;
}

.pack-chooser-img {
  width: 100%;
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  overflow: visible;
}

.pack-chooser-img img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.pack-chooser-label {
  font-size: 0.62rem;
  color: var(--color-text-muted);
  text-transform: lowercase;
  text-align: center;
  word-break: break-word;
  line-height: 1.1;
}

.pack-chooser-tile--active .pack-chooser-label {
  color: var(--color-text);
}

/* ----- 15. GRADIENT EDITOR ------------------------------------- */

.gradient-editor {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.gradient-entry {
  display: flex;
  flex-direction: column;
  border-bottom: 1px solid var(--color-border);
}

.gradient-entry:last-of-type {
  border-bottom: 0;
}

.gradient-remove-btn {
  margin: var(--space-2) var(--space-4) var(--space-3);
  align-self: flex-start;
  border: 1px solid rgba(242, 107, 107, 0.3);
  border-radius: 999px;
  padding: 0.2rem 0.7rem;
  font-size: 0.78rem;
  background: transparent;
  color: #f29b9b;
  transition: background 0.12s ease;
}

.gradient-remove-btn:hover { background: rgba(242, 107, 107, 0.1); }

.gradient-add-btn {
  margin: var(--space-3) var(--space-4);
  align-self: flex-start;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1.5px dashed rgba(255, 255, 255, 0.25);
  background: transparent;
  color: var(--color-text-muted);
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.12s ease, color 0.12s ease;
}

.gradient-add-btn:hover {
  border-color: rgba(0, 87, 214, 0.5);
  color: var(--accent);
}

/* ----- 15. PHONE PREVIEW LAYOUT --------------------------------- */

.ph-status-bar {
  flex-shrink: 0;
  line-height: 0;
}

/* Unified 4-col × 4-row grid (visible portion of the spec's 4×6 grid;
   trailing 2 rows are cropped off-screen by spec, so we don't render
   them). Cells are equal squares so widgets and icons share the same
   sizing — switching layouts never shifts the icons. */
.ph-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(6, 1fr);
  gap: 4%;
  width: 100%;
  /* 4 cols × 6 rows of square cells. Aspect-ratio = 4 / 6 = 2 / 3 fixes
     row height to column width regardless of how much vertical space the
     parent allocates, which is the only reliable way to keep the cells
     truly square in a CSS grid. The dock lives BELOW this grid as a
     separate row in the phone-frame flex column. */
  aspect-ratio: 4 / 6;
}

/* Widgets occupy 2×2 (small) or 4×2 (medium) cells. Container fills its
   grid area; corner radius ≈ 18% of cell height per spec — using a
   reasonable fixed fallback that matches the existing icon tile look. */
.ph-widget {
  position: relative;
  border-radius: 18px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding: 8% 10%;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", system-ui, sans-serif;
}

.ph-widget .ph-w-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.ph-widget .ph-w-spacer { flex: 1; }

/* ---- Clock medium (layout 0) ---- */
.ph-w-clock-medium .ph-w-time {
  font-size: 2.4rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1;
  font-feature-settings: "tnum";
}
.ph-w-clock-medium .ph-w-badge {
  width: 22px;
  height: 22px;
  border-radius: 50%;
}
.ph-w-clock-medium .ph-w-date {
  margin-top: 2%;
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.ph-w-clock-medium .ph-w-rule {
  height: 4px;
  border-radius: 999px;
  width: 100%;
}

/* ---- Clock small (layouts 1, 2, 8) ---- */
.ph-w-clock-small .ph-w-time-sm {
  font-size: 1.7rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1;
  font-feature-settings: "tnum";
}
.ph-w-clock-small .ph-w-dot {
  /* Top-right accent: circle at the existing width. */
  width: 18px;
  height: 18px;
  border-radius: 50%;
}
.ph-w-clock-small .ph-w-day {
  margin-top: 4%;
  font-size: 0.62rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
/* Lower accent rule — same height as the top dot, full width across
   the bottom of the widget. */
.ph-w-clock-small .ph-w-rule-sm {
  height: 10px;
  width: 100%;
  border-radius: 999px;
}

/* ---- Battery (layouts 3, 4, 8) ---- */
.ph-w-battery .ph-w-battery-inner {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4%;
}
.ph-w-battery .ph-w-battery-ring-wrap {
  position: relative;
  width: 58%;
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.ph-w-battery .ph-w-battery-glyph {
  position: absolute;
  width: 22%;
  height: auto;
  /* Greys to match the stock iOS Batteries widget glyph. Uses its own
     color (not the theme's foreground) so it stays neutral. */
}
.ph-w-battery .ph-w-battery-pct {
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1;
  font-feature-settings: "tnum";
}
.ph-w-battery .ph-w-battery-pct-sym {
  font-size: 0.78em;
  margin-left: 1px;
  opacity: 0.85;
}

/* ---- Calendar (layouts 5, 6, 9) ---- */
.ph-w-calendar { padding: 9% 10% 7%; }
.ph-w-calendar .ph-w-cal-weekday {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.ph-w-calendar .ph-w-cal-day {
  font-size: 2.2rem;
  font-weight: 700;
  letter-spacing: -0.04em;
  line-height: 1;
  margin-top: 2%;
  font-feature-settings: "tnum";
}
.ph-w-calendar .ph-w-cal-events {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 4%;
}
.ph-w-calendar .ph-w-cal-event {
  display: flex;
  align-items: center;
  gap: 6px;
}
.ph-w-calendar .ph-w-cal-bar {
  flex-shrink: 0;
  width: 3px;
  height: 0.7rem;
  border-radius: 1.5px;
}
.ph-w-calendar .ph-w-cal-event-text {
  font-size: 0.55rem;
  font-weight: 500;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---- Photo (layouts 7, 9) ---- */
.ph-w-photo {
  padding: 0;
}

.ph-search-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 25%;
  align-self: center;
  background: rgba(255, 255, 255, 0.13);
  border-radius: 999px;
  padding: 2.5% 0;
  flex-shrink: 0;
  /* Push the search pill (and the dock that follows it) to the bottom of
     the phone-frame. The space between the home-screen grid and this pill
     auto-fills with the flex column's free space. */
  margin-top: auto;
}

.ph-search-text {
  font-size: 0.45rem;
  letter-spacing: 0.03em;
}

.ph-dock-wrap {
  margin: 0 -2%;
  border-radius: 25px;
  padding: 3% 3.5%;
  flex-shrink: 0;
  background: rgba(128, 128, 128, 0.28);
  backdrop-filter: blur(1px) saturate(180%);
  -webkit-backdrop-filter: blur(1px) saturate(180%);
  border: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.2),
    inset 0 -1px 0 rgba(0, 0, 0, 0.1);
}

.ph-dock {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4%;
}

/* ----- 16. MINI CLOCK (PACK PREVIEW CARD) ----------------------- */

.mini-widget {
  gap: 3px;
}

.mini-clock-top {
  display: flex;
  align-items: center;
  gap: 3px;
}

.mini-clock-dot {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  flex-shrink: 0;
}

.mini-clock-time {
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.03em;
}

.mini-clock-date {
  font-size: 0.38rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  display: block;
}

.mini-clock-line {
  height: 2px;
  border-radius: 999px;
  width: 52%;
  margin-top: 2px;
}


/* ----- 17. ASSET UPLOAD + CROP MODAL ---------------------------- */

.asset-upload-field {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
}

.asset-thumb {
  border-radius: 12px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--color-border);
}

.asset-thumb-wallpaper {
  width: 100px;
  aspect-ratio: 1290 / 2796;
}

.asset-thumb-iconBg {
  width: 100px;
  aspect-ratio: 1 / 1;
}

.asset-thumb-widgetBg {
  width: 140px;
  aspect-ratio: 1 / 1;
}

.asset-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.asset-upload-buttons {
  display: flex;
  gap: var(--space-2);
  align-items: center;
}

.icon-bg-slot-wrap {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
}

.icon-bg-slot-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.icon-bg-library-row {
  display: flex;
  justify-content: flex-start;
}

.icon-bg-slot {
  position: relative;
  width: 72px;
  height: 72px;
  border-radius: 14px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.04);
  padding: 0;
  border: 1px solid var(--color-border);
  cursor: pointer;
  transition: border-color 0.12s ease, background 0.12s ease;
}

.icon-bg-slot--filled img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.icon-bg-slot--filled:hover {
  border-color: var(--color-border-strong);
}

.icon-bg-slot--empty {
  border: 1.5px dashed rgba(255, 255, 255, 0.22);
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 6px;
}

.icon-bg-slot--empty:hover {
  border-color: rgba(0, 87, 214, 0.55);
  background: rgba(0, 87, 214, 0.04);
}

.icon-bg-slot-plus {
  font-size: 1.6rem;
  font-weight: 300;
  line-height: 1;
  color: var(--color-text-muted);
}

.icon-bg-slot-label {
  font-size: 0.62rem;
  text-align: center;
  color: var(--color-text-muted);
  line-height: 1.1;
}

.icon-bg-slot--empty:hover .icon-bg-slot-plus,
.icon-bg-slot--empty:hover .icon-bg-slot-label {
  color: var(--accent);
}

.icon-bg-slot-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.4);
  font-size: 0.85rem;
  line-height: 1;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.12s ease;
}

.icon-bg-slot--filled:hover .icon-bg-slot-remove {
  opacity: 1;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal {
  background: #131922;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  max-width: 90vw;
  max-height: 90vh;
  overflow: auto;
}

.modal-header {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.modal-header h3 {
  font-size: 1.1rem;
}

.modal-sub {
  margin: 0;
  font-size: 0.78rem;
  color: var(--color-text-muted);
}

.modal-warning {
  margin: 0;
  font-size: 0.8rem;
  color: #f29b68;
  background: rgba(0, 87, 214, 0.1);
  border: 1px solid rgba(0, 87, 214, 0.3);
  border-radius: var(--radius-md);
  padding: 0.5rem 0.75rem;
}

.crop-stage {
  display: flex;
  justify-content: center;
  background: #000;
  border-radius: var(--radius-lg);
  padding: var(--space-3);
}

.crop-stage canvas {
  cursor: grab;
  border-radius: 6px;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.4) inset;
}

.crop-stage canvas:active {
  cursor: grabbing;
}

.crop-zoom-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.crop-zoom-row label {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  min-width: 50px;
}

.crop-zoom-row input[type="range"] {
  flex: 1;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
}


/* ----- 18. WALLPAPER LIBRARY PICKER ----------------------------- */

.wallpaper-library-modal {
  width: 720px;
  max-width: 90vw;
  max-height: 85vh;
}

.library-collection-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

.library-collection-chip {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--color-border);
  color: var(--color-text-soft);
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  font-size: 0.78rem;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

.library-collection-chip:hover {
  background: rgba(255, 255, 255, 0.08);
}

.library-collection-chip.is-active {
  background: rgba(0, 87, 214, 0.15);
  border-color: rgba(0, 87, 214, 0.5);
  color: var(--accent);
}

.library-thumb-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 10px;
  padding: var(--space-2) 0;
}

.library-thumb-grid--portrait { grid-auto-rows: 196px; }
.library-thumb-grid--square   { grid-auto-rows: 110px; }

.library-thumb {
  display: block;
  background: rgba(0, 0, 0, 0.3);
  border: 1.5px solid transparent;
  border-radius: 10px;
  overflow: hidden;
  padding: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
  transition: border-color 0.12s ease, transform 0.12s ease;
}

.library-thumb:hover {
  border-color: rgba(0, 87, 214, 0.6);
  transform: scale(1.03);
}

.library-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.pack-summary {
  margin: var(--space-3) 0;
  font-size: 0.9rem;
  color: var(--color-text-muted);
  font-style: italic;
}

.drag-handle {
  display: inline-block;
  cursor: grab;
  color: var(--color-text-faint);
  font-size: 0.85rem;
  letter-spacing: -2px;
  margin-right: 6px;
  user-select: none;
}

.pack-button:active .drag-handle,
.theme-button:active .drag-handle {
  cursor: grabbing;
}

.pack-button.is-dragging,
.theme-button.is-dragging {
  opacity: 0.4;
}

.pack-button.drop-target-above,
.theme-button.drop-target-above {
  box-shadow: inset 0 2px 0 0 var(--accent);
}

.pack-button.drop-target-below,
.theme-button.drop-target-below {
  box-shadow: inset 0 -2px 0 0 var(--accent);
}

/* Foreign-pack drop target: glowing blue border when a theme is being
   dragged from a different pack and hovering over this pack button. */
.pack-button.drop-target-foreign-pack {
  border-color: #398bff;
  background: rgba(57, 139, 255, 0.18);
  box-shadow:
    0 0 0 1px #398bff,
    0 0 14px 2px rgba(57, 139, 255, 0.55),
    inset 0 0 14px rgba(57, 139, 255, 0.18);
  animation: foreignPackPulse 1.4s ease-in-out infinite;
}

@keyframes foreignPackPulse {
  0%, 100% { box-shadow: 0 0 0 1px #398bff, 0 0 10px 2px rgba(57, 139, 255, 0.45), inset 0 0 12px rgba(57, 139, 255, 0.16); }
  50%      { box-shadow: 0 0 0 1px #398bff, 0 0 18px 4px rgba(57, 139, 255, 0.70), inset 0 0 18px rgba(57, 139, 255, 0.28); }
}

/* ----- 19. COLOR PICKER: EYEDROPPER + HISTORY ------------------- */

.color-dropper-row {
  display: flex;
  padding: 0px 8px 8px 0px;
}

.color-dropper-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.03);
  color: var(--color-text-soft);
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
}

.color-dropper-btn:hover {
  background: rgba(255, 255, 255, 0.07);
  border-color: var(--color-border-strong);
}

.color-dropper-btn .dropper-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 0;
  color: #398bff;
}

.color-dropper-btn .dropper-icon svg {
  display: block;
}

.color-history-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px 12px 12px;
  border-top: 1px solid var(--color-border);
  margin-top: 6px;
}

.color-history-empty {
  font-size: 0.75rem;
  color: var(--color-text-faint);
}

.color-history-swatch {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  padding: 0;
  cursor: pointer;
  transition: transform 0.1s ease, border-color 0.1s ease;
}

.color-history-swatch:hover {
  transform: scale(1.1);
  border-color: var(--accent);
}


.wallpaper-gen-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
}

.count-stepper {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  user-select: none;
  line-height: 1;
}
.count-stepper-value {
  font: inherit;
  font-weight: 600;
  min-width: 18px;
  text-align: center;
  color: inherit;
  padding: 0 2px;
}
.count-stepper-btn {
  appearance: none;
  background: transparent;
  border: 0;
  padding: 1px 4px;
  margin: 0;
  cursor: pointer;
  color: inherit;
  opacity: 0.65;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 3px;
}
.count-stepper-btn:hover:not(:disabled) {
  opacity: 1;
  background: rgba(127, 127, 127, 0.15);
}
.count-stepper-btn:disabled {
  opacity: 0.25;
  cursor: not-allowed;
}
.count-stepper-btn svg {
  display: block;
}

/* Subtle horizontal divider between groups inside the field-group body */
.field-divider {
  margin: var(--space-3) var(--space-4);
  border: 0;
  border-top: 1px solid var(--color-border);
  height: 0;
}

/* Pan-stage thumbnail (used by wallpaper, widget-bg, icon-bg) -------- */
.wallpaper-pan-stage {
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  position: relative;
}
.asset-thumb-wallpaper.wallpaper-pan-stage { width: 120px; }

.wallpaper-pan-stage.is-panning { cursor: grabbing; }

.wallpaper-pan-inner {
  position: absolute;
  inset: 0;
  background-repeat: no-repeat;
}

.wallpaper-pan-icon {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 28px;
  height: 28px;
  margin: -14px 0 0 -14px;
  pointer-events: none;
  color: rgba(255, 255, 255, 0.85);
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.7));
  opacity: 0.55;
  transition: opacity 0.15s ease;
}

.wallpaper-pan-stage:hover .wallpaper-pan-icon { opacity: 0.9; }
.wallpaper-pan-stage.is-panning .wallpaper-pan-icon { opacity: 0.25; }

.iconbg-panzoom-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0 var(--space-4);
}
.iconbg-panzoom-row .wallpaper-zoom-row { flex: 1; padding: 0; }

.wallpaper-pan-icon svg {
  width: 100%;
  height: 100%;
  display: block;
}

.wallpaper-zoom-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0 var(--space-4);
}

.wallpaper-zoom-row input[type="range"] {
  flex: 1;
}

.wallpaper-zoom-readout {
  font-size: 0.78rem;
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
  min-width: 36px;
  text-align: right;
}

.wallpaper-gen-label {
  font-size: 0.85rem;
  color: var(--color-text-soft);
  margin-right: var(--space-2);
}

.gen-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.wallpaper-gen-fg-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--color-text-soft);
  cursor: pointer;
  user-select: none;
  margin-right: var(--space-2);
}
.wallpaper-gen-fg-toggle input[type="checkbox"] {
  margin: 0;
  cursor: pointer;
}

.gen-btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 0;
  color: currentColor;
}

.gen-btn-icon svg {
  width: 14px;
  height: 14px;
  display: block;
}

@keyframes gen-spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

.gen-btn:hover .gen-btn-icon {
  animation: gen-spin 2s linear infinite;
}

/* ----- 20. IMAGE-BG WRAPPER LAYERS ------------------------------- */
/* Tiles/frames with .has-image-bg get two absolutely-positioned layers
   inserted at the top of their child list: a .bg-image-layer (image,
   sized cover, optionally scaled) and an optional .bg-overlay-layer
   (tint color × opacity). Existing children render above these. */

.has-image-bg {
  position: relative;
  overflow: hidden;
  isolation: isolate;
}

.bg-image-layer {
  position: absolute;
  /* width/height/top/left are set inline by applyImageBgLayers so the
     pan/zoom math works on both axes regardless of source aspect. */
  background-repeat: no-repeat;
  background-size: cover;
  z-index: 0;
}

.bg-overlay-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
}

.icon-tile.has-image-bg .icon-layer,
.icon-tile.has-image-bg > .blur-base,
.icon-tile.has-image-bg > .blur-layer { position: relative; z-index: 2; }

.mini-widget.has-image-bg > *:not(.bg-image-layer):not(.bg-overlay-layer),
.ph-widget.has-image-bg > *:not(.bg-image-layer):not(.bg-overlay-layer),
.phone-frame.has-image-bg > *:not(.bg-image-layer):not(.bg-overlay-layer) {
  position: relative;
  z-index: 2;
}
