body {
  font-family: "Helvetica Neue", Arial, sans-serif;
  background-color: #f4f7f6;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  margin: 0;
  color: #333;
}

#app {
  background: white;
  padding: 2.5rem;
  border-radius: 12px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.05);
  text-align: center;
  width: 90%;
  max-width: 500px;
}

h1 {
  margin-top: 0;
  margin-bottom: 30px;
  color: #2c3e50;
  font-size: 24px;
  font-weight: 600;
  span {
    font-size: 0.6em;
  }
}

#controls {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.control-group {
  width: 100%;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

button {
  width: 100%;
  padding: 12px 15px;
  font-size: 15px;
  cursor: pointer;
  border: none;
  border-radius: 6px;
  font-weight: 500;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

/* Viewer Page Styles */
.navbar {
  width: 100%;
  background-color: #fff;
  padding: 15px 30px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
  display: flex;
  align-items: center;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 100;
}

.nav-brand {
  font-size: 20px;
  font-weight: bold;
  color: #2c3e50;
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
}

.viewer-body {
  padding-top: 80px;
  /* Space for fixed navbar */
  flex-direction: column;
  justify-content: flex-start;
}

.viewer-card {
  background: white;
  padding: 20px;
  border-radius: 12px;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
  text-align: center;
  /* Max width 90% of viewport, but shrink if content (image) is smaller */
  width: auto;
  max-width: 90vw;
  margin-top: 20px;
  margin-bottom: 40px;
  /* Space for scrolling */
  display: inline-block;
  /* Shrink to fit content */
}

.viewer-card img {
  /* Image scales down if larger than container (90vw), but stays original size if smaller */
  max-width: 100%;
  height: auto;
  /* Maintain aspect ratio */
  /* Removed max-height to allow vertical scrolling */
  border-radius: 8px;
  border: 1px solid #eee;
}

/* Button Variants */
.primary-btn {
  background-color: #3498db;
  color: white;
  font-size: 16px;
  padding: 15px;
  box-shadow: 0 4px 6px rgba(52, 152, 219, 0.2);
}

.primary-btn:hover {
  background-color: #2980b9;
  transform: translateY(-1px);
}

.secondary-btn {
  background-color: #95a5a6;
  color: white;
}

.secondary-btn:hover {
  background-color: #7f8c8d;
}

.tertiary-btn {
  background-color: #ecf0f1;
  color: #7f8c8d;
  border: 1px solid #bdc3c7;
}

.tertiary-btn:hover {
  background-color: #e0e5e6;
  color: #34495e;
}

.accent-btn {
  background-color: #2ecc71;
  color: white;
}

.accent-btn:hover {
  background-color: #27ae60;
}

/* URL Input Group */
.url-group {
  display: flex;
  flex-direction: row;
  /* Revert to horizontal */
  gap: 10px;
  margin-top: 10px;
  padding-top: 20px;
  border-top: 1px solid #eee;
}

.url-group button {
  width: auto;
  /* Allow button to shrink to content */
  white-space: nowrap;
  min-width: 120px;
  /* Ensure strictly enough clickable area */
}

input[type="text"] {
  flex: 1;
  padding: 10px 12px;
  font-size: 15px;
  border: 1px solid #ddd;
  border-radius: 6px;
  outline: none;
  transition: border-color 0.2s;
}

input[type="text"]:focus {
  border-color: #3498db;
}

/* Modals & Overlays */
#selection-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.3);
  cursor: crosshair;
  z-index: 9999;
}

#selection-box {
  border: 2px solid #3498db;
  background: rgba(52, 152, 219, 0.1);
  position: absolute;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
}

#loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(255, 255, 255, 0.8);
  /* Light clean overlay */
  backdrop-filter: blur(2px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 10000;
  color: #333;
}

.spinner {
  border: 4px solid #f3f3f3;
  border-top: 4px solid #3498db;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  animation: spin 1s linear infinite;
  margin-bottom: 15px;
}

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

  100% {
    transform: rotate(360deg);
  }
}

#loading-text {
  font-weight: 600;
  font-size: 1.1rem;
  color: #555;
}

/* Result Modal */
#result-area {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(2px);
  z-index: 9998;
  justify-content: center;
  align-items: center;
  padding: 20px;
  box-sizing: border-box;
}

#result-card {
  background: white;
  padding: 40px 30px 30px;
  /* Increased top padding for breathing room */
  border-radius: 16px;
  /* softer corners */
  max-width: 90%;
  max-height: 90vh;
  width: 600px;
  /* specific width for better desktop look */
  overflow-y: auto;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
  text-align: center;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  animation: popIn 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28);
}

@keyframes popIn {
  from {
    transform: scale(0.9);
    opacity: 0;
  }

  to {
    transform: scale(1);
    opacity: 1;
  }
}

#result-card h3 {
  margin-top: 5px;
  margin-bottom: 5px;
  color: #27ae60;
  font-size: 24px;
}

#result-link {
  display: block;
  margin: 15px 0 25px;
  color: #3498db;
  text-decoration: none;
  word-break: break-all;
  font-size: 14px;
  background: #f8f9fa;
  padding: 10px;
  border-radius: 6px;
  width: 100%;
  box-sizing: border-box;
}

#btn-copy {
  background-color: #34495e;
  color: white;
  width: auto;
  min-width: 200px;
  /* Make it substantial */
  padding: 12px 24px;
  font-size: 16px;
  box-shadow: 0 4px 6px rgba(44, 62, 80, 0.2);
  margin-bottom: 10px;
}

#btn-copy:hover {
  background-color: #2c3e50;
  transform: translateY(-1px);
}

#result-image {
  max-width: 100%;
  height: auto;
  margin-top: 20px;
  border: 1px solid #eee;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
  display: block;
}

.close-btn {
  position: absolute;
  top: 15px;
  right: 20px;
  font-size: 32px;
  color: #bdc3c7;
  cursor: pointer;
  background: none;
  border: none;
  padding: 5px;
  line-height: 1;
  transition: color 0.2s;
  z-index: 10;
  /* Ensure it's on top */
}

.close-btn:hover {
  color: #e74c3c;
}

/* Error Modal */
#error-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(2px);
  z-index: 10001;
  /* Highest z-index */
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
  box-sizing: border-box;
}

#error-card {
  background: white;
  padding: 30px;
  border-radius: 12px;
  max-width: 400px;
  width: 100%;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  text-align: center;
  position: relative;
  animation: shake 0.4s ease-in-out;
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }

  25% {
    transform: translateX(-5px);
  }

  75% {
    transform: translateX(5px);
  }
}

.error-icon {
  font-size: 48px;
  margin-bottom: 15px;
}

#error-card h3 {
  margin: 0 0 10px;
  color: #e74c3c;
}

#error-card p {
  color: #555;
  margin-bottom: 25px;
  line-height: 1.5;
}

#btn-error-ok {
  width: 100%;
  background-color: #e74c3c;
  border: none;
  color: white;
  font-size: 16px;
  padding: 12px;
}

#btn-error-ok:hover {
  background-color: #c0392b;
}

/* Floating Download Button */
.fab-bottom-right {
  position: fixed;
  bottom: 30px;
  right: 30px;
  z-index: 1000;
  padding: 15px 25px;
  border-radius: 50px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-weight: bold;
  font-size: 16px;
  text-decoration: none !important;
  color: white !important;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.fab-bottom-right:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
  text-decoration: none;
}

.logo-text {
  span {
    font-size: 0.6em;
  }
}
