/* Reset and base */
body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: #f5f7fa;
  color: #222;
  margin: 0;
  padding: 20px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.dark {
  background: #222;
  color: #eee;
}

/* Header styling */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

#mainTitle {
  font-size: 2.2rem;
  font-weight: 700;
  margin: 0;
  color: #4a90e2;
}

/* Top controls container */
.top-controls {
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
}

/* Language container */
.language-container {
  display: flex;
  align-items: center;
  gap: 8px;
}

.language-label {
  font-weight: 600;
  font-size: 1rem;
  user-select: none;
  color: #333;
}

/* Language select dropdown */
#languageSelect {
  padding: 8px 12px;
  font-size: 1rem;
  border-radius: 8px;
  border: 2px solid #4a90e2;
  background-color: white;
  color: #222;
  min-width: 140px;
  cursor: pointer;
  transition: border-color 0.3s ease;
  position: relative;
  z-index: 10;
  appearance: none;
  background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%234a90e2'%3E%3Cpath d='M4 6l4 4 4-4z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 12px;
}

#languageSelect:focus {
  border-color: #357abd;
  outline: none;
}

/* Theme toggle button */
#themeToggle {
  cursor: pointer;
  background: transparent;
  border: 2px solid #4a90e2;
  padding: 8px 14px;
  border-radius: 8px;
  color: #4a90e2;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.25s ease, color 0.25s ease;
  font-size: 0.8rem;
  width: 48px;
  height: 48px;
}

#themeToggle:hover,
#themeToggle:focus {
  background-color: #4a90e2;
  color: white;
  outline: none;
}

/* Container and sections */
.container {
  max-width: 600px;
  margin: 0 auto;
  background: white;
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 5px 20px rgb(74 144 226 / 0.15);
  overflow: visible; /* Allow dropdowns to show outside container */
  box-sizing: border-box;
}

.dark .container {
  background: #333;
  box-shadow: 0 5px 20px rgb(74 144 226 / 0.5);
  color: #eee;
}

/* Form groups */
.form-group {
  margin-bottom: 18px;
}

label {
  font-weight: 600;
  display: block;
  margin-bottom: 6px;
  font-size: 1.1rem;
}

input[type="number"],
select {
  width: 100%;
  padding: 10px 14px;
  font-size: 1.1rem;
  border-radius: 8px;
  border: 1.8px solid #4a90e2;
  transition: border-color 0.3s ease;
  box-sizing: border-box;
  min-width: 0; /* Fix flex overflow */
  position: relative;
  z-index: 10; /* dropdown priority */
  appearance: none;
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 12px;
}

select {
  background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%234a90e2'%3E%3Cpath d='M4 6l4 4 4-4z'/%3E%3C/svg%3E");
}

input[type="number"]:focus,
select:focus {
  border-color: #357abd;
  outline: none;
}

/* Units row layout */
.units-row {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  margin-bottom: 20px;
  flex-wrap: wrap;
  box-sizing: border-box;
}

.unit-select {
  flex: 1 1 40%;
  min-width: 140px;
}

/* Swap button */
#swapBtn {
  background: #4a90e2;
  color: white;
  border: none;
  font-size: 1.3rem;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  align-self: center;
  flex-shrink: 0;
  transition: background-color 0.3s ease;
  min-height: 48px;
  user-select: none;
}

#swapBtn:hover,
#swapBtn:focus {
  background-color: #357abd;
  outline: none;
}

/* Convert button */
#convertBtn {
  width: 100%;
  padding: 12px;
  background-color: #4a90e2;
  color: white;
  font-weight: 700;
  font-size: 1.15rem;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: background-color 0.3s ease;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  user-select: none;
}

#convertBtn:hover,
#convertBtn:focus {
  background-color: #357abd;
  outline: none;
}

/* Result box */
.result-box {
  margin-top: 20px;
  font-weight: 700;
  font-size: 1.3rem;
  color: #222;
  min-height: 2em; /* reserve space */
}

.dark .result-box {
  color: #ddd;
}

/* History */
.history-section {
  margin-top: 40px;
}

.history-list {
  list-style: none;
  padding-left: 0;
  max-height: 180px;
  overflow-y: auto;
  border: 1px solid #4a90e2;
  border-radius: 8px;
  background-color: #f9fafe;
}

.dark .history-list {
  background-color: #444;
  border-color: #357abd;
}

.history-list li {
  padding: 8px 12px;
  border-bottom: 1px solid #4a90e2;
  font-weight: 600;
  font-size: 1rem;
  color: #333;
}

.dark .history-list li {
  border-color: #357abd;
  color: #eee;
}

.history-list li:last-child {
  border-bottom: none;
}

/* Responsive adjustments */
@media (max-width: 480px) {
  .units-row {
    flex-direction: column;
  }
  .unit-select {
    flex: 1 1 100%;
    min-width: auto;
  }
  #swapBtn {
    align-self: flex-start;
    width: 100%;
  }
  .top-controls {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }
}
