:root {
  --white: #ffffff;
  --black: #0a0a0a;
  --bg-primary: #0a0a0a;
  --surface-primary: #1a1a1a;
  --surface-secondary: #2c2c2c;
  --text-primary: #ffffff;
  --text-secondary: #c0c0c0;
  --accent: #ffffff;
  --hover: #e0e0e0;
  --active: #c0c0c0;

  --radius: 4px;
  --shadow: 4px 4px 0 var(--text-primary);
  --shadow-dark: 4px 4px 0 var(--black);

  --t-fast: 0.3s ease-in-out;
  --t-layout: 0.6s cubic-bezier(0.4, 0, 0.2, 1);

  --spacing: 1rem;
  --footer-height: 4rem;
  --search-bar-height: 8rem;
}

/* Tema claro */
@media (prefers-color-scheme: light) {
  :root {
    --white: #0a0a0a;
    --black: #ffffff;
    --bg-primary: #f5f5f5;
    --surface-primary: #ffffff;
    --surface-secondary: #e0e0e0;
    --text-primary: #0a0a0a;
    --text-secondary: #505050;
    --accent: #0a0a0a;
    --hover: #c0c0c0;
    --active: #a0a0a0;
    --shadow: 4px 4px 0 var(--text-primary);
    --shadow-dark: 4px 4px 0 var(--black);
  }
}

/* Reset */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
body {
  font-family: 'Inter', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background var(--t-fast), color var(--t-fast);
}

/* Layout principal */
#app-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  justify-content: flex-start;
  align-items: center;
  padding-bottom: var(--footer-height);
  transition: all var(--t-layout);
}

#search-bar-frame {
  width: 100%;
  max-width: 600px;
  padding: 1.5rem;
  background: var(--surface-secondary);
  border-radius: var(--radius);
  border: 2px solid var(--text-primary);
  box-shadow: 8px 8px 0 var(--text-primary);
  transition: all var(--t-layout);
  margin: var(--spacing) auto;
}

#app-title {
  font-size: 1.875rem;
  font-weight: 700;
  margin-bottom: 1.5rem;
  text-align: center;
}

/* Formulário */
#search-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
@media (min-width: 768px) {
  #search-form {
    flex-direction: row;
    align-items: flex-end;
  }
}
.form-group {
  flex: 1;
  display: flex;
  flex-direction: column;
}
label {
  font-size: 0.875rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

/* Inputs e Select */
input, select {
  width: 100%;
  padding: 1rem 1.25rem;
  border-radius: var(--radius);
  border: 2px solid var(--text-primary);
  background: var(--surface-primary);
  color: var(--text-primary);
  font-size: 1.125rem;
  box-shadow: var(--shadow);
  transition: all var(--t-fast);
}
input:focus, select:focus {
  outline: none;
  border-color: var(--text-secondary);
  box-shadow: 4px 4px 0 var(--text-secondary), 0 0 0 2px var(--text-secondary);
}
select {
  appearance: none;
  background: var(--surface-primary) url('data:image/svg+xml;utf8,<svg fill="%23ffffff" viewBox="0 0 24 24"><path d="M7 10l5 5 5-5z"/></svg>') no-repeat right 0.75rem center/1.25rem;
}

/* Botões (mantendo estilo antigo) */
button, .footer-button {
  font-weight: 700;
  border-radius: var(--radius);
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 1px;
  transition: all var(--t-fast);
  padding: 1.25rem 1.75rem;
  border: 2px solid var(--black);
  background: var(--accent);
  color: var(--black);
  box-shadow: var(--shadow-dark);
}
button:hover, .footer-button:hover {
  background: var(--hover);
  transform: translate(-2px, -2px);
  box-shadow: 6px 6px 0 var(--black);
}
button:active, .footer-button:active {
  transform: none;
  box-shadow: var(--shadow-dark);
}
button:disabled {
  background: var(--surface-secondary);
  color: var(--text-secondary);
  border-color: var(--text-secondary);
  cursor: not-allowed;
  box-shadow: none;
}

/* Resultados */
#results-browser {
  flex: 1;
  width: 100%;
  max-width: 600px;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  overflow-y: auto;
  transition: all var(--t-layout);
  margin: var(--spacing) auto;
}
.result-item {
  background: var(--surface-primary);
  border: 1px solid var(--surface-secondary);
  border-radius: var(--radius);
  padding: 1rem;
  transition: all var(--t-fast);
}
.result-item:hover {
  border-left: 4px solid var(--text-primary);
  background: var(--surface-secondary);
}
.result-item .result-link-button {
  font-weight: 600;
  border-radius: var(--radius);
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  transition: all var(--t-fast);
  padding: 0.75rem 1rem; /* Slightly larger padding for better click area */
  border: 2px solid var(--black);
  background: var(--accent);
  color: var(--black);
  box-shadow: var(--shadow-dark);
  font-size: 0.875rem;
  margin-top: 0.75rem; /* Increased margin-top */
  width: calc(100% - 1rem); /* Take almost full width with 0.5rem margin on each side */
  display: block; /* Make it a block element to take full width */
  margin-left: auto; /* Center the button if it doesn't take full width */
  margin-right: auto; /* Center the button if it doesn't take full width */
}

.result-item .result-link-button:hover {
  background: var(--hover);
  transform: translate(-1px, -1px); /* Smaller hover effect */
  box-shadow: 3px 3px 0 var(--black);
}

.result-item .result-link-button:active {
  transform: none;
  box-shadow: var(--shadow-dark);
}

/* Status bar */
#status-bar {
  background: var(--accent);
  color: var(--black);
  font-weight: 700;
  text-align: center;
  font-size: 0.875rem;
  padding: 0.75rem 1.5rem;
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  transform: translateY(100%);
  opacity: 0;
  transition: all var(--t-fast);
}
#status-bar.show {
  transform: translateY(0);
  opacity: 1;
}

/* Footer */
#app-footer {
  display: flex;
  justify-content: center;
  gap: 1rem;
  padding: 1rem;
  background: var(--bg-primary);
  width: 100%;
  position: fixed;
  bottom: 0;
  z-index: 20;
}

/* Como Usar (pop-up) */
#how-to-use-overlay {
  background-color: rgba(0,0,0,0.7);
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  z-index: 50;
}
#how-to-use-overlay:not(.hidden) {
  opacity: 1;
  visibility: visible;
}

#how-to-use-overlay:not(.hidden) #how-to-use {
  opacity: 1;
  transform: translateY(0);
  animation: fadeIn 0.6s ease-out forwards; /* Re-apply fade-in for consistency */
}

#how-to-use {
  background: var(--surface-primary);
  color: var(--text-primary);
  border: 2px solid var(--text-primary);
  border-radius: var(--radius);
  padding: 2rem;
  max-width: 450px;
  width: 90%;
  position: relative;
  box-shadow: 8px 8px 0 var(--text-primary);
  /* Ensure it starts hidden for its own animation */
  opacity: 0;
  transform: translateY(20px);
}
#how-to-use h2 {
  color: var(--accent);
  margin-bottom: 1rem;
  font-size: 1.75rem;
}
#how-to-use p {
  margin-bottom: 0.75rem;
  line-height: 1.5;
}
#close-how-to-use {
  position: absolute;
  top: 0.75rem; /* Adjusted top position */
  right: 0.75rem; /* Adjusted right position */
  background: var(--accent);
  border: 2px solid var(--black);
  border-radius: var(--radius);
  color: var(--black);
  font-size: 1.5rem; /* Further decreased font size */
  width: 2rem; /* Further decreased width */
  height: 2rem; /* Further decreased height */
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--t-fast); /* Keep transition */
  box-shadow: var(--shadow-dark); /* Use dark shadow for consistency */
}
  #close-how-to-use:hover {
    background: var(--hover); /* Hover effect */
    color: var(--black); /* Text color on hover */
    box-shadow: 6px 6px 0 var(--black); /* Larger shadow on hover */
    transform: translate(-2px, -2px); /* Slight movement on hover */
  }
  #close-how-to-use:active {
    transform: none; /* Reset transform on active */
    box-shadow: var(--shadow-dark); /* Reset shadow on active */
  }

/* Loading Spinner */
#loading-spinner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin: 2rem auto;
  color: var(--text-secondary);
  font-size: 1.125rem;
  transition: opacity var(--t-fast);
}

#loading-spinner.hidden {
  display: none;
}

.spinner {
  border: 4px solid var(--surface-secondary);
  border-top: 4px solid var(--accent);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  animation: spin 1s linear infinite;
}

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

/* General Animations */
.fade-in {
  animation: fadeIn 0.6s ease-out forwards;
}

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

/* Apply fade-in to main sections */
#search-bar-frame,
#results-browser,
#status-bar,
#app-footer,
#how-to-use {
  opacity: 0; /* Start hidden for fade-in */
}

#app-container.loaded #search-bar-frame,
#app-container.loaded #results-browser,
#app-container.loaded #status-bar,
#app-container.loaded #app-footer,
#app-container.loaded #how-to-use {
  opacity: 1;
  animation: fadeIn 0.6s ease-out forwards;
}

/* Delay animations for a staggered effect */
#app-container.loaded #search-bar-frame { animation-delay: 0.1s; }
#app-container.loaded #results-browser { animation-delay: 0.2s; }
#app-container.loaded #status-bar { animation-delay: 0.3s; }
#app-container.loaded #app-footer { animation-delay: 0.4s; }
#app-container.loaded #how-to-use { animation-delay: 0.5s; }

/* Responsividade (continuação) */
@media (max-width: 768px) {
  #search-bar-frame,
  #results-browser {
    max-width: 95%;
    padding: 1rem;
    margin: var(--spacing) auto;
  }
  #search-form {
    flex-direction: column;
    align-items: stretch;
  }
  button, .footer-button {
    width: 100%;
  }
  #app-footer {
    flex-direction: column;
    gap: 0.5rem;
  }
}
