html {
  overflow-x: hidden;
  width: 100%;
}

body {
  margin: 0;
  padding: 0;
  overflow-x: hidden;
  width: 100%;
  position: relative;
}

body {
  min-height: 100dvh;
  font-family: 'Outfit', 'Inter', sans-serif;
  background: linear-gradient(135deg, #1e0533, #0d1b2a, #310a31);
  background-size: 300% 300%;
  animation: gradientBG 15s ease infinite;
  color: #fff;
  display: flex;
  flex-direction: column;
}

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

@keyframes gradientBG {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

:root {
  --glass-bg: rgba(255, 255, 255, 0.05);
  --glass-border: rgba(255, 255, 255, 0.1);
  --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
  --primary: #9b51e0;
  --primary-hover: #b472f2;
  --secondary: #00d2ff;
  --success: #00d084;
  --danger: #eb5757;
  --text-main: #ffffff;
  --text-muted: #a0a0b0;
  --radius: 1.25rem;
  --transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

/* Glass Container Base */
.glass-panel {
  background: var(--glass-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  box-shadow: var(--glass-shadow);
  padding: 3rem;
  width: 90%;
  max-width: 600px;
  margin: 0 auto;
}

/* Typography */
h1, h2, h3, h4 {
  margin-top: 0;
  font-weight: 700;
  letter-spacing: -0.02em;
}

h1.logo-text {
  text-align: center;
  font-size: 3.5rem;
  margin-bottom: 0.5rem;
  background: linear-gradient(135deg, var(--secondary), var(--primary));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: glow 3s ease-in-out infinite alternate;
}

@keyframes glow {
  from { filter: drop-shadow(0 0 10px rgba(155, 81, 224, 0.3)); }
  to { filter: drop-shadow(0 0 20px rgba(0, 210, 255, 0.5)); }
}

p.subtitle {
  text-align: center;
  color: var(--text-muted);
  font-size: 1.1rem;
  margin-bottom: 2.5rem;
}

/* Forms & Inputs */
.form-group {
  position: relative;
  margin-bottom: 1.5rem;
}

.input-label {
  display: block;
  margin-bottom: 0.5rem;
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text-muted);
}

.glass-input {
  width: 100%;
  padding: 1.2rem 1.25rem;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--glass-border);
  border-radius: 0.75rem;
  color: var(--text-main);
  font-size: 1rem;
  font-family: inherit;
  transition: var(--transition);
  outline: none;
}

.glass-input::placeholder {
  color: rgba(255, 255, 255, 0.3);
}

.glass-input:focus {
  border-color: var(--primary);
  background: rgba(0, 0, 0, 0.4);
  box-shadow: 0 0 0 4px rgba(155, 81, 224, 0.15);
}

/* To correctly position the icon inside the input wrapper, let's wrap the input */
.input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
}

.input-wrapper .input-icon {
  position: absolute;
  left: 1.2rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

.input-wrapper .glass-input {
  padding-left: 3.5rem;
}

.icon {
  width: 1.25rem;
  height: 1.25rem;
  fill: currentColor;
  flex-shrink: 0;
}

.icon-stroke {
  width: 1.25rem;
  height: 1.25rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 1.2rem 2rem;
  font-size: 1.05rem;
  font-weight: 600;
  border-radius: 0.75rem;
  cursor: pointer;
  transition: var(--transition);
  width: 100%;
  position: relative;
  overflow: hidden;
  text-decoration: none;
}

.btn::before {
  content: '';
  position: absolute;
  top: 0; left: -100%; width: 100%; height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
  transition: all 0.5s;
}

.btn:hover {
  background: var(--primary-hover);
  transform: translateY(-2px);
  box-shadow: 0 10px 20px rgba(155, 81, 224, 0.4);
}

.btn:hover::before {
  left: 100%;
}

.btn:active {
  transform: translateY(0);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--glass-border);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.15);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

.btn-icon-only {
  padding: 0.8rem;
  width: auto;
  border-radius: 50%; /* Make them circular for better aesthetics */
}

/* Result Card */
.result-card {
  margin-top: 2rem;
  padding: 2rem;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 0.75rem;
  border: 1px solid var(--success);
  display: none;
  width: 100%;
  box-sizing: border-box;
  animation: slideUp 0.4s ease-out forwards;
}

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

.result-card.show {
  display: block;
}

.short-url-display {
  display: block;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--success);
  word-break: break-all;
  margin: 1.5rem 0;
  text-align: center;
  text-decoration: none;
  padding: 1rem;
  background: rgba(0, 208, 132, 0.1);
  border-radius: 0.5rem;
  border: 1px dashed rgba(0, 208, 132, 0.3);
}

.action-row {
  display: flex;
  flex-wrap: wrap; /* Allows wrapping on very small screens */
  gap: 1rem;
  justify-content: center;
  margin-top: 1.5rem;
}

.action-btn-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.action-btn-group span {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* History Section */
.history-section {
  margin-top: 4rem;
  max-width: 800px;
  width: 90%;
  margin-left: auto;
  margin-right: auto;
}

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
}

/* Special styling for Clear History button to fit nicely without breaking */
#clear-history-btn {
  padding: 0.6rem 1rem;
  font-size: 0.9rem;
  border-radius: 0.5rem;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
}

.history-item {
  background: var(--glass-bg);
  backdrop-filter: blur(8px);
  border: 1px solid var(--glass-border);
  border-radius: 1rem;
  padding: 1.2rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: var(--transition);
  animation: fadeIn 0.3s ease-out;
  gap: 1rem; /* Spacing between text and buttons */
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.history-item:hover {
  background: rgba(255, 255, 255, 0.1);
  transform: translateX(5px);
  border-color: rgba(255, 255, 255, 0.2);
}

.history-details {
  flex: 1;
  min-width: 0; /* Crucial for text truncation in flexbox */
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.history-short {
  display: block;
  font-weight: 600;
  color: var(--secondary);
  font-size: 1.15rem;
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-original {
  display: block;
  font-size: 0.9rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-actions {
  display: flex;
  gap: 0.75rem;
  flex-shrink: 0; /* Prevent buttons from shrinking */
}

.history-actions .btn-icon-only {
  padding: 0.6rem;
  border-radius: 0.5rem; /* slightly rounded square looks better here */
}

/* Toast System */
#toast-container {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  z-index: 1000;
  pointer-events: none;
}

.toast {
  background: rgba(20, 20, 30, 0.95);
  backdrop-filter: blur(10px);
  border: 1px solid var(--glass-border);
  color: #fff;
  padding: 1rem 1.5rem;
  border-radius: 0.75rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
  animation: toastEnter 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
  pointer-events: auto;
  min-width: 300px;
}

.toast.toast-hiding {
  animation: toastExit 0.3s ease-in forwards;
}

.toast-success { border-left: 4px solid var(--success); }
.toast-error { border-left: 4px solid var(--danger); }
.toast-info { border-left: 4px solid var(--secondary); }

.toast-icon { display: flex; align-items: center; justify-content: center; }
.toast-success .icon-stroke { stroke: var(--success); }
.toast-error .icon-stroke { stroke: var(--danger); }
.toast-info .icon-stroke { stroke: var(--secondary); }

@keyframes toastEnter {
  from { opacity: 0; transform: translateX(100%) scale(0.9); }
  to { opacity: 1; transform: translateX(0) scale(1); }
}

@keyframes toastExit {
  from { opacity: 1; transform: translateX(0) scale(1); }
  to { opacity: 0; transform: translateX(100%) scale(0.9); }
}

/* Loader */
.spinner {
  width: 20px;
  height: 20px;
  border: 3px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  display: none;
}

.btn.loading .spinner { display: inline-block; }
.btn.loading .btn-text { display: none; }
.btn.loading svg { display: none; } /* Hide icons when loading */

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Layout wrappers */
main {
  flex: 1;
  padding: 3rem 0; /* Reduced padding on mobile, controlled by width % */
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  z-index: 1;
  width: 100%;
}

/* Footer structure */
footer {
  padding: 2.5rem;
  text-align: center;
  border-top: 1px solid var(--glass-border);
  background: rgba(0,0,0,0.2);
  backdrop-filter: blur(5px);
  margin-top: auto;
}

.footer-links {
  display: flex;
  justify-content: center;
  flex-wrap: wrap; /* Allows wrapping */
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

.footer-links a {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.95rem;
  transition: var(--transition);
}

.footer-links a:hover {
  color: var(--primary);
}

/* Modal / QR */
.qr-container {
  background: #fff;
  padding: 1rem;
  border-radius: 0.75rem;
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 1.5rem auto;
  width: max-content;
  max-width: 100%;
  box-sizing: border-box;
}

/* Responsive Alignments */
@media (max-width: 768px) {
  h1.logo-text { font-size: 2.8rem; }
  .glass-panel { padding: 2rem 1.5rem; width: 92%; }
  
  .history-item { 
    flex-direction: column; /* Stack on mobile */
    align-items: flex-start; 
    gap: 1.2rem; 
  }
  
  .history-details { width: 100%; }
  
  .history-actions { 
    width: 100%; 
    justify-content: space-between; /* Spread buttons evenly */
  }
  
  .history-actions .btn-icon-only {
    flex: 1; /* Stretch buttons on mobile */
    display: flex;
    justify-content: center;
  }
  
  #toast-container { bottom: 1rem; left: 1rem; right: 1rem; top: auto; }
  .toast { width: 100%; min-width: 0; box-sizing: border-box; }
  
  .action-row { gap: 0.75rem; }
  .btn-icon-only { padding: 0.75rem; }
}

@media (max-width: 480px) {
  h1.logo-text { font-size: 2.2rem; }
  .subtitle { font-size: 1rem; }
  .glass-input { padding: 1rem; font-size: 0.95rem; }
  .input-wrapper .glass-input { padding-left: 3rem; }
  .input-wrapper .input-icon { left: 1rem; }
  
  .action-row { 
    display: flex; 
    flex-wrap: wrap; 
    gap: 1.5rem; 
    justify-content: center; 
  }
}

/* Blob Background Elements */
.bg-blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  z-index: 0;
  opacity: 0.5;
  animation: float 20s infinite alternate;
  pointer-events: none;
}

.blob-1 {
  top: 5%; left: 5%;
  width: 300px; height: 300px;
  background: var(--primary);
}

.blob-2 {
  bottom: 10%; right: 5%;
  width: 400px; height: 400px;
  background: var(--secondary);
  animation: floatReverse 20s infinite alternate;
}

/* Make sure blobs don't cause overflow on mobile */
@media (max-width: 768px) {
  .blob-1, .blob-2 { filter: blur(60px); opacity: 0.4; }
  .blob-1 { width: 250px; height: 250px; }
  .blob-2 { width: 300px; height: 300px; }
}

@keyframes float {
  from { transform: translate(0, 0); }
  to { transform: translate(60px, 30px); }
}

@keyframes floatReverse {
  from { transform: translate(0, 0); }
  to { transform: translate(-60px, -30px); }
}
