/* -- MODAL OVERLAY -- */
dialog.modal {
  /* Reset browser dialog defaults */
  border: none;
  padding: 1.5rem;
  background: transparent;
  max-width: 100%;
  max-height: 100%;
  overflow: visible;
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 500;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.28s ease;
}

/* Only show as flex layout when the dialog is open (showModal sets [open]) */
dialog.modal[open] { display: flex; }

/* Use our own animated backdrop div; suppress the native one */
dialog.modal::backdrop { display: none; }

dialog.modal.open {
  opacity: 1;
  pointer-events: auto;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(31, 35, 41, 0.75);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

/* -- PANEL -- */
.modal-panel {
  position: relative;
  z-index: 1;
  background: #fff;
  border-radius: 24px;
  width: min(900px, 94vw);
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transform: scale(0.9) translateY(16px);
  transition: transform 0.42s cubic-bezier(0.16,1,0.3,1);
  box-shadow: 0 36px 90px rgba(31, 35, 41, 0.3), 0 0 0 1px rgba(255,255,255,0.06);
}

.modal.open .modal-panel {
  transform: scale(1) translateY(0);
}

/* -- HEADER -- */
.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 2rem 2rem 1.6rem;
  flex-shrink: 0;
}

.modal-header-left {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.modal-icon {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.modal-icon svg {
  width: 26px;
  height: 26px;
}

.modal-header-text { display: flex; flex-direction: column; gap: 0.2rem; }

.modal-title {
  font-family: 'Processity', serif;
  font-size: 1.55rem;
  font-weight: 900;
  letter-spacing: -0.035em;
  color: var(--gray-900);
  line-height: 1.1;
}

.modal-tagline {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--gray-600);
  letter-spacing: 0.03em;
}

.modal-close {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--gray-200);
  color: var(--gray-700);
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.18s, color 0.18s;
  line-height: 1;
}
.modal-close:hover { background: var(--gray-300); color: var(--gray-900); }

/* -- DIVIDER -- */
.modal-divider {
  height: 1px;
  background: rgba(31, 35, 41, 0.07);
  flex-shrink: 0;
}

/* -- BODY -- */
.modal-body {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 0;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  scrollbar-width: thin;
  scrollbar-color: rgba(31, 35, 41, 0.12) transparent;
}

.modal-body::-webkit-scrollbar { width: 6px; }
.modal-body::-webkit-scrollbar-track { background: transparent; }
.modal-body::-webkit-scrollbar-thumb { background: rgba(31, 35, 41, 0.12); border-radius: 3px; }

/* -- LEFT: description + components -- */
.modal-info {
  padding: 1.8rem 2rem 2rem;
  border-right: 1px solid rgba(31, 35, 41, 0.06);
}

.modal-description {
  font-size: 0.975rem;
  line-height: 1.76;
  color: var(--gray-700);
  font-weight: 300;
  margin-bottom: 1.8rem;
}

.modal-section-label {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--gray-600);
  margin-bottom: 0.9rem;
}

.modal-components {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.comp-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 500;
  border: 1.5px solid transparent;
  transition: transform 0.15s;
}
.comp-chip:hover { transform: translateY(-1px); }

.comp-chip::before {
  content: '';
  width: 5px;
  height: 5px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* -- RIGHT: illustration + screenshot -- */
.modal-visual {
  padding: 1.8rem 1.8rem 2rem;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: flex-start;
  gap: 1.25rem;
  width: 100%;
}

.modal-illustration {
  width: 100%;
  max-width: 300px;
  border-radius: 18px;
  overflow: hidden;
  align-self: center;
}

.modal-illustration svg {
  width: 100%;
  height: auto;
  display: block;
}

/* -- SCREENSHOT PLACEHOLDER -- */
.modal-screenshot {
  width: 100%;
  border-radius: 14px;
  overflow: hidden;
  position: relative;
}

.modal-screenshot img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 14px;
}

.modal-screenshot:not(.missing) img {
  cursor: zoom-in;
  transition: opacity 0.15s ease;
}

.modal-screenshot:not(.missing):hover img {
  opacity: 0.9;
}

.modal-screenshot-expand {
  position: absolute;
  bottom: 0.5rem;
  right: 0.5rem;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
  backdrop-filter: blur(4px);
}

.modal-screenshot:not(.missing):hover .modal-screenshot-expand {
  opacity: 1;
}

.modal-screenshot-placeholder {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  aspect-ratio: 16 / 10;
  border: 1.5px dashed rgba(31, 35, 41, 0.15);
  border-radius: 14px;
  color: var(--ink-soft);
  background: var(--gray-50);
}

.modal-screenshot-placeholder span {
  font-size: 0.78rem;
  font-weight: 500;
}

.modal-screenshot.missing img {
  display: none;
}
.modal-screenshot.missing .modal-screenshot-placeholder {
  display: flex;
}

/* -- RESPONSIVE -- */
@media (max-width: 680px) {
  dialog.modal {
    padding: 0.75rem;
  }
  .modal-panel {
    max-height: calc(100vh - 1.5rem);
    border-radius: 18px;
    display: block;
    overflow-y: auto;
  }
  .modal-body {
    grid-template-columns: 1fr;
    display: block;
    overflow: visible;
    flex: none;
    min-height: 0;
  }
  .modal-visual {
    padding: 0 1.5rem 1.5rem;
    order: -1;
  }
  .modal-info { border-right: none; }
  .modal-header {
    padding: 1.5rem 1.5rem 1.2rem;
    position: sticky;
    top: 0;
    z-index: 2;
  }
  .modal-title { font-size: 1.3rem; }
  .modal-illustration { max-width: 100%; }
}

/* -- LIGHTBOX -- */
dialog.lightbox {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  border: none;
  padding: 2rem;
  background: transparent;
  overflow: hidden;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  z-index: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

dialog.lightbox[open] { display: flex; }

dialog.lightbox::backdrop {
  background: rgba(0, 0, 0, 0.88);
  backdrop-filter: blur(6px);
  opacity: 0;
  transition: opacity 0.2s ease;
}

dialog.lightbox.open {
  opacity: 1;
  pointer-events: auto;
}

dialog.lightbox.open::backdrop {
  opacity: 1;
}

.lightbox-img {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  border-radius: 10px;
  box-shadow: 0 32px 96px rgba(0, 0, 0, 0.6);
  transform: scale(0.96);
  transition: transform 0.2s ease;
  display: block;
}

dialog.lightbox.open .lightbox-img {
  transform: scale(1);
}

.lightbox-close {
  position: fixed;
  top: 1rem;
  right: 1rem;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1.5px solid rgba(255, 255, 255, 0.2);
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  backdrop-filter: blur(4px);
  z-index: 1;
}

.lightbox-close:hover {
  background: rgba(255, 255, 255, 0.25);
}

@media (prefers-reduced-motion: reduce) {
  .modal, .modal-panel { transition: none; }
  dialog.lightbox, dialog.lightbox::backdrop, .lightbox-img { transition: none; }
}
