* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  max-width: 100vw;
  overflow-x: hidden;
  font-family: 'Poppins', sans-serif;
  background: radial-gradient(circle at top left, #0f172a, #0a0f1c);
  color: #e2e8f0;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
}

canvas {
  position: absolute;
  top: 0;
  left: 0;
  display: block;
  width: 100%;
  height: 100%;
  z-index: 0;
}

header, .container, footer {
  position: relative;
  z-index: 1;
}

@keyframes spawnDown {
  from { opacity: 0; transform: translateY(-20px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes spawnUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

header h1 {
  font-size: 2.8rem;
  color: #cbd5e1;
  text-shadow: 0 0 12px #1e293baa;
  margin: 0;
}

.container {
  max-width: 600px;
  width: 90vw;
  margin: 1rem auto 2rem;
  background-color: rgba(15, 23, 42, 0.85);
  border-radius: 20px;
  padding: 2rem;
  box-shadow: 0 0 25px rgba(30, 41, 59, 0.3);
  position: relative;
  z-index: 1;
  backdrop-filter: blur(10px);
  border: 1px solid rgba(51, 65, 85, 0.2);
  animation: spawnUp 0.5s ease-out forwards;
  opacity: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.input-group {
  position: relative;
  display: flex;
  width: 100%;
  align-items: center;
  margin-bottom: 1rem;
}

.input-group input[type="text"] {
  flex: 1;
  padding: 1rem;
  border-radius: 14px;
  border: 2px solid #334155;
  background: rgba(15, 23, 42, 0.9);
  color: #f1f5f9;
  font-size: 1rem;
  outline: none;
  transition: box-shadow 0.3s ease;
  max-width: 100%;
  word-break: break-word;
  overflow-wrap: break-word;
  white-space: normal;
}

.input-group button {
  position: absolute;
  top: 50%;
  right: 0.8rem;
  transform: translateY(-50%);
  background: rgba(255, 255, 255, 0.05);
  backdrop-filter: blur(6px);
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 8px;
  cursor: pointer;
  z-index: 2;
  transition: background-color 0.3s ease, border-color 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.input-group button:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.2);
}

.input-group button img {
  width: 20px;
  height: 20px;
  filter: brightness(0) saturate(100%) invert(65%) sepia(8%) saturate(445%) hue-rotate(185deg) brightness(90%) contrast(85%);
  opacity: 0.8;
  transition: opacity 0.2s;
}

.input-group button:hover img {
  opacity: 1;
}

#downloadBtn {
  width: 100%;
  background: linear-gradient(135deg, #1e293b, #0f172a);
  border: none;
  padding: 0.9rem;
  color: #f8fafc;
  font-size: 1rem;
  border-radius: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 0 10px #1e293b;
  transition: 0.3s ease;
}

#downloadBtn:hover {
  background: linear-gradient(135deg, #334155, #1e293b);
  transform: scale(1.02);
}

#downloadBtn img {
  width: 18px;
  height: 18px;
}

.loader {
  border: 4px solid rgba(255, 255, 255, 0.1);
  border-top: 4px solid #64748b;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  animation: spin 1s linear infinite;
  margin-left: 8px;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.result {
  margin-top: 2rem;
  background: rgba(30, 41, 59, 0.75);
  padding: 1.5rem;
  border-radius: 18px;
  box-shadow: 0 0 20px rgba(51, 65, 85, 0.3);
  width: 100%;
  max-width: 600px;
  display: none;
  text-align: center;
}

.result-title {
  font-size: 1.2rem;
  font-weight: 600;
  color: #e2e8f0;
  margin-bottom: 1rem;
  border-left: 4px solid #334155;
  padding-left: 0.8rem;
  text-align: left;
  word-break: break-word;
  overflow-wrap: break-word;
}

video {
  width: 100%;
  max-width: 100%;
  border-radius: 14px;
  margin-top: 1rem;
  border: 2px solid #334155;
  box-shadow: 0 0 12px rgba(30, 41, 59, 0.4);
}

.download-buttons {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-top: 1rem;
}

.download-buttons a {
  text-decoration: none;
  width: 100%;
}

.download-buttons button {
  width: 100%;
  background: linear-gradient(135deg, #1e293b, #0f172a);
  border: none;
  padding: 0.8rem;
  color: white;
  font-size: 1rem;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
}

footer {
  text-align: center;
  margin-top: 2rem;
  padding: 2rem 1rem;
  font-size: 0.9rem;
  color: #94a3b8;
  width: 100%;
  max-width: 600px;
  position: relative;
  z-index: 1;
}

@media (max-width: 600px) {
  header h1 {
    font-size: 2rem;
  }

  .container {
    margin: 1rem;
    padding: 1.5rem;
    width: 90vw;
  }
}

#toast-container {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 90%;
}

.toast {
  display: flex;
  align-items: center;
  background: #1e293b;
  border-radius: 10px;
  padding: 14px 18px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.2);
  min-width: 320px;
  max-width: 480px;
  position: relative;
  animation: slideIn 0.4s ease;
  border-left: 5px solid;
  opacity: 1;
  transition: opacity 0.5s ease;
  color: #f1f5f9;
}

.toast.fade-out {
  opacity: 0;
  transition: opacity 0.5s ease;
}

.toast .icon {
  width: 30px;
  height: 30px;
  margin-right: 12px;
  flex-shrink: 0;
}

.toast .content {
  flex-grow: 1;
}

.toast .title {
  font-weight: 600;
  margin-bottom: 4px;
  color: #e2e8f0;
}

.toast .message {
  font-size: 14px;
  color: #cbd5e1;
}

.toast .close-btn {
  background: none;
  border: none;
  font-size: 18px;
  color: #94a3b8;
  cursor: pointer;
  position: absolute;
  top: 10px;
  right: 14px;
}

.toast.success { border-color: #22c55e; }
.toast.info { border-color: #64748b; }
.toast.warning { border-color: #facc15; }
.toast.error { border-color: #ef4444; }

@keyframes slideIn {
  from { opacity: 0; transform: translateY(-20px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeOut {
  from { opacity: 1; transform: translateY(0); }
  to { opacity: 0; transform: translateY(-20px); }
}
