*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: Arial, Helvetica, sans-serif;
  background-color: #05060a;
  color: #f5f5f7;
  line-height: 1.5;
}

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Landing */
.landing {
  padding: 1.5rem 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 100vh;
}

.landing-inner {
  max-width: 640px;
  margin: 0 auto;
}

.branding {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 2rem;
}

.logo {
  width: 56px;
  height: 56px;
}

.app-title {
  margin: 0;
  font-size: 1.8rem;
  letter-spacing: 0.03em;
}

.app-tagline {
  margin-top: 0.5rem;
  margin-bottom: 0;
  color: #c3c4cf;
  font-size: 0.95rem;
}

.primary-btn,
.secondary-btn {
  border: none;
  border-radius: 999px;
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
  cursor: pointer;
  transition: background-color 0.18s ease, box-shadow 0.18s ease, transform 0.08s ease;
}

.primary-btn {
  background: linear-gradient(135deg, #3b82f6, #6366f1);
  color: #ffffff;
  box-shadow: 0 10px 25px rgba(59, 130, 246, 0.35);
}

.primary-btn:hover,
.primary-btn:focus-visible {
  background: linear-gradient(135deg, #2563eb, #4f46e5);
  box-shadow: 0 12px 28px rgba(59, 130, 246, 0.45);
  outline: none;
}

.secondary-btn {
  background-color: #181924;
  color: #e5e7eb;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.45);
}

.secondary-btn:hover,
.secondary-btn:focus-visible {
  background-color: #1f2030;
  outline: none;
}

.primary-btn:active,
.secondary-btn:active {
  transform: translateY(1px);
}

.footer {
  margin-top: 3rem;
  text-align: center;
  font-size: 0.85rem;
  color: #9ca3af;
}

.footer a {
  color: #9ca3af;
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.footer a:hover,
.footer a:focus-visible {
  color: #e5e7eb;
  border-color: #e5e7eb;
  outline: none;
}

/* Editor */
.editor {
  display: none;
  flex: 1;
  padding: 1.5rem 1.25rem 2rem;
}

/* Preview */
.preview-section {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.preview-frame-wrapper {
  position: relative;
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
}

.cinema-preview-btn {
  position: absolute;
  top: 0.85rem;
  right: 0.85rem;
  z-index: 12;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  border: none;
  border-radius: 999px;
  padding: 0.55rem 0.8rem;
  font-size: 0.85rem;
  color: #ffffff;
  background: rgba(0, 0, 0, 0.72);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  touch-action: manipulation;
  cursor: pointer;
  transition: background-color 0.15s ease, transform 0.08s ease;
}

.cinema-preview-btn:hover,
.cinema-preview-btn:focus-visible {
  background: rgba(17, 24, 39, 0.9);
  outline: none;
}

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

.cinema-preview-icon {
  font-size: 0.95rem;
  line-height: 1;
}

.preview-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9; /* default, can be overridden by JS */
  background-color: #0b0c12;
  border: 1px solid #222;
  border-radius: 1rem;
  overflow: hidden;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.75);
  touch-action: manipulation;
  transition: transform 260ms ease, opacity 260ms ease, border-radius 260ms ease, box-shadow 260ms ease;
}

body.cinema-preview-active {
  overflow: hidden;
  background-color: #000000;
}

body.cinema-preview-active .editor {
  display: block;
  padding: 0;
  margin: 0;
  max-width: none;
}

body.cinema-preview-active .preview-section {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  background-color: #000000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 260ms ease;
}

body.cinema-preview-active .preview-section.is-active {
  opacity: 1;
  pointer-events: auto;
}

body.cinema-preview-active .image-controls,
body.cinema-preview-active .controls-section,
body.cinema-preview-active .floating-edit-btn {
  display: none !important;
}

body.cinema-preview-active .preview-frame-wrapper {
  width: min(94vw, calc(94vh * 16 / 9));
  height: min(94vh, calc(94vw * 9 / 16));
  max-width: 100%;
  max-height: 100%;
  margin: 0;
}

@media (max-width: 767px) {
  body.cinema-preview-active .preview-frame-wrapper {
    width: min(100vw, calc(100vh * 16 / 9));
    height: min(100vh, calc(100vw * 9 / 16));
    padding: 0;
  }
}

body.cinema-preview-active .preview-frame {
  width: 100%;
  height: 100%;
  border: none;
  border-radius: 0;
  box-shadow: none;
  transform: scale(0.96);
}

body.cinema-preview-active .preview-section.is-active .preview-frame {
  transform: scale(1);
}

body.cinema-preview-active .cinema-preview-btn {
  display: none;
}

.preview-image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.subtitle-overlay {
  position: absolute;
  inset: 0;
  display: block;
  padding: 0;
  pointer-events: none;
}

.subtitle-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 2;
  background: transparent;
  opacity: 1;
  visibility: visible;
}

.subtitle-text {
  position: absolute;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  margin: 0;
  max-width: min(90%, 900px);
  text-align: center;
  word-wrap: break-word;
  display: inline-block;
  visibility: visible;
  opacity: 1;
  color: #ffffff;
  font-weight: 700;
  line-height: 1.2;
  pointer-events: none;
  text-shadow: 0 0 10px rgba(0, 0, 0, 0.85);
}

.subtitle-text.is-fallback {
  display: inline-block;
}

/* Drag & drop overlay */
.drop-overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background-color: rgba(15, 23, 42, 0.75);
  color: #e5e7eb;
  font-size: 1rem;
  text-align: center;
  pointer-events: none;
}

/* Image controls */
.image-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  justify-content: space-between;
  max-width: 960px;
  margin: 0.25rem auto 0;
}

.image-upload-label {
  display: inline-flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.9rem;
  color: #d1d5db;
}

.image-upload-label input[type="file"] {
  font-size: 0.85rem;
  color: #e5e7eb;
}

/* Controls */
.controls-section {
  margin-top: 1.75rem;
  max-width: 960px;
  margin-left: auto;
  margin-right: auto;
  background-color: #0b0c12;
  border-radius: 1rem;
  padding: 1.25rem 1.25rem 1.5rem;
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.7);
}

.controls-title {
  margin: 0 0 1rem;
  font-size: 1.1rem;
  color: #e5e7eb;
}

.controls-form {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.form-group label {
  font-size: 0.9rem;
  color: #d1d5db;
}

textarea,
input[type="number"],
input[type="color"],
select {
  border-radius: 0.75rem;
  border: 1px solid #1f2937;
  background-color: #05060a;
  color: #f9fafb;
  padding: 0.6rem 0.7rem;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

textarea {
  resize: vertical;
  min-height: 3rem;
}

input[type="color"] {
  padding: 0;
  height: 2.4rem;
  width: 4rem;
  cursor: pointer;
}

textarea:focus-visible,
input[type="number"]:focus-visible,
input[type="color"]:focus-visible,
select:focus-visible {
  border-color: #3b82f6;
  box-shadow: 0 0 0 1px rgba(59, 130, 246, 0.7);
}

/* Share */
.share-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
}

.share-status {
  font-size: 0.85rem;
  color: #9ca3af;
}

/* Floating edit button */
.floating-edit-btn {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: 20;
  display: none;
  border: none;
  border-radius: 999px;
  padding: 0.7rem 1.2rem;
  font-size: 0.95rem;
  cursor: pointer;
  background-color: #111827;
  color: #e5e7eb;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.7);
  transition: background-color 0.15s ease, box-shadow 0.15s ease, transform 0.08s ease;
}

.floating-edit-btn:hover,
.floating-edit-btn:focus-visible {
  background-color: #1f2937;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.8);
  outline: none;
}

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

/* Responsive */
@media (max-width: 767px) {
  .preview-section {
    gap: 0.75rem;
  }

  .cinema-preview-btn {
    top: auto;
    right: 0.75rem;
    top: calc(0.75rem + env(safe-area-inset-bottom));
    padding: 0.7rem 0.95rem;
    font-size: 0.95rem;
    border-radius: 999px;
  }

  .image-controls {
    flex-direction: column;
    align-items: stretch;
  }

  .image-upload-label {
    width: 100%;
  }

  .preview-frame {
    border-radius: 0.8rem;
  }
}

@media (min-width: 768px) {
  .landing {
    padding-top: 2.5rem;
  }

  .app-title {
    font-size: 2.1rem;
  }

  .editor {
    padding-top: 2rem;
  }

  .controls-form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .form-group:nth-child(1) {
    grid-column: 1 / -1;
  }

  .share-group {
    grid-column: 1 / -1;
  }
}

@media (min-width: 1024px) {
  .editor {
    max-width: 1120px;
    margin: 0 auto;
  }

  .preview-section {
    margin-bottom: 1.5rem;
  }
}

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

.colors {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
}
.colors label {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.85rem;
}
.colors input[type="color"] {
  cursor: pointer;
  border: none;
}

.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  cursor: pointer;
  font-size: 0.95rem;
}

.checkbox-label input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
  accent-color: #3b82f6;
}