:root {
  --bg-color: #f4f4f4;
  --container-bg-color: #fff;
  --text-color: #000;
  --primary-color: #007bff;
  --primary-color-hover: #0056b3;
  --border-color: #ddd;
  --shadow-color: rgba(0, 0, 0, 0.1);
  --avatar-height: 150px;
  --avatar-width-scale: 1;
}

[data-theme="dark"] {
  --bg-color: #121212;
  --container-bg-color: #1e1e1e;
  --text-color: #fff;
  --primary-color: #007bff;
  --primary-color-hover: #0056b3;
  --border-color: #444;
  --shadow-color: rgba(255, 255, 255, 0.1);
}

body {
  font-family: sans-serif;
  margin: 0;
  padding: 1em;
  background-color: var(--bg-color); /* This should be applied */
  color: var(--text-color);
  transition: background-color 0.3s, color 0.3s;
  line-height: 1.6; /* Added for better readability */
  /* TEMPORARY DEBUGGING: Add a very obvious background color */
  background-color: blue !important; 
}

.container {
  max-width: 800px;
  margin: 0 auto;
  padding: 2em;
  background-color: var(--container-bg-color);
  border-radius: 8px;
  box-shadow: 0 0 10px var(--shadow-color);
  position: relative;
}

#theme-toggle {
  position: absolute;
  top: 1em;
  right: 1em;
  padding: 0.5em 1em; /* Adjusted padding */
  font-size: 0.8em;
  background-color: var(--primary-color); /* Added theme color */
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  z-index: 10; /* Ensure it stays on top */
}

#theme-toggle:hover {
  background-color: var(--primary-color-hover);
}

h1 {
  text-align: center;
  margin-top: 2em; /* Added margin to push it down from the toggle */
  margin-bottom: 1em;
}

form div {
  margin-bottom: 1.5em; /* Increased spacing between form elements */
}

label {
  display: block;
  margin-bottom: 0.5em;
  font-weight: bold; /* Make labels stand out */
}

input[type="text"],
input[type="number"],
input[type="file"] {
  width: 100%;
  padding: 0.8em; /* Increased padding */
  box-sizing: border-box;
  background-color: var(--container-bg-color);
  color: var(--text-color);
  border: 1px solid var(--border-color);
  border-radius: 4px;
}

.upload-area {
  margin-top: 1.5em; /* Increased margin */
  text-align: center;
}

.upload-area input[type="file"] {
  width: auto;
  display: inline-block;
  padding: 0.5em; /* Smaller padding for file input */
}

form button[type="submit"] { /* Specific selector for submit button */
  width: 100%;
  padding: 0.75em 1.5em;
  background-color: var(--primary-color);
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 1em;
  margin-top: 1em; /* Added margin-top for spacing */
}

form button[type="submit"]:hover {
  background-color: var(--primary-color-hover);
}

hr {
  margin: 2em 0;
  border: none; /* Removed default border */
  border-top: 1px solid var(--border-color); /* Added themed border */
}

a {
  display: block;
  text-align: center;
  text-decoration: none;
  color: var(--primary-color);
  margin-top: 1em; /* Added margin-top for spacing */
}

a:hover {
  text-decoration: underline;
}

img {
  max-width: 100%;
  height: auto;
  display: block;
}

.profile-display {
  display: flex;
  flex-wrap: wrap; /* Allow wrapping on smaller screens */
  justify-content: space-around;
  align-items: flex-start; /* Changed to flex-start for better alignment */
  margin: 2em 0;
  gap: 1em; /* Added gap for spacing between flex items */
}

[id$="-preview-container"], #avatar-container {
  flex-basis: 45%;
  min-width: 280px; /* Ensure minimum width for each column */
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 1em; /* Added padding */
  border: 1px solid var(--border-color); /* Added border */
  border-radius: 8px;
}

[id$="-preview"] {
  max-width: 180px; /* Slightly smaller for better fit */
  max-height: 180px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
}

#avatar {
  height: var(--avatar-height);
  transform: scaleX(var(--avatar-width-scale));
  transition: height 0.3s, transform 0.3s;
  display: flex; /* Added flex to position head/body */
  flex-direction: column;
  justify-content: flex-end;
}

.avatar-head {
  height: 30%;
  aspect-ratio: 1 / 1;
  background-color: var(--text-color);
  border-radius: 50%;
  margin: 0 auto 5%; /* Adjusted margin */
}

.avatar-body {
  height: 70%;
  width: 50%;
  background-color: var(--text-color);
  border-radius: 20px 20px 0 0;
  margin: 0 auto;
}

@media (max-width: 600px) { /* Adjustments for smaller screens */
  .profile-display {
    flex-direction: column; /* Stack vertically */
    align-items: stretch;
  }

  [id$="-preview-container"], #avatar-container {
    flex-basis: 100%;
    min-width: unset; /* Remove min-width */
    margin-bottom: 1em;
  }

  h1 {
    margin-top: 1em;
  }

  #theme-toggle {
    position: static; /* Make it flow with content */
    width: 100%;
    margin-bottom: 1em;
  }
}
