/* 1. Theme variables */
:root {
  --bg: #eaf2f8;
  --text: #0c5460;
  --accent: #0078D4;
  --accent-hover: #005a9e;
  --box-bg: #fff;
  --border: #ccc;
}
body.dark {
  --bg: #1e1e1e;
  --text: #e0e0e0;
  --accent: #66aaff;
  --accent-hover: #3399ff;
  --box-bg: #2a2a2a;
  --border: #444;
}

/* 2. Reset & hide scrollbars */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
*::-webkit-scrollbar { display: none; }

/* 3. Base layout */
html, body {
  height: 100%;
  overflow: hidden;
  font-family: 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  padding: env(safe-area-inset);
}
body {
  display: flex;
  flex-direction: column;
}
main#main {
  flex: 1;
  max-width: 1000px;
  margin: auto;
  padding: .75rem;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* 4. Title + Toggle */
.title-wrapper {
  position: relative;
  margin-bottom: 1rem;
}
#appTitle {
  font-size: 1.5rem;
  text-align: center;
}
.mode-container {
  position: absolute;
  top: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: .4rem;
}
.mode-label {
  font-size: .75rem;
  color: var(--text);
}

/* iOS-style switch */
.switch {
  position: relative;
  width: 2.5rem;
  height: 1.4rem;
}
.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.slider {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: #ccc;
  border-radius: 1rem;
  transition: .3s;
}
.slider::before {
  content: "";
  position: absolute;
  width: 1rem;
  height: 1rem;
  left: .2rem;
  bottom: .2rem;
  background: white;
  border-radius: 50%;
  transition: .3s;
}
.switch input:checked + .slider {
  background-color: var(--accent);
}
.switch input:checked + .slider::before {
  transform: translateX(1.1rem);
}

/* 5. Intro box */
.intro-box {
  font-size: .75rem;
  background: #d1ecf1;
  border: 1px solid #bee5eb;
  color: #0c5460;
  padding: .5rem;
  border-radius: .3rem;
  margin-bottom: 1rem;
  text-align: center;
  line-height: 1.4;
}

/* 6. Engine selectors */
#engineSelectors {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
  font-size: .8rem;
  margin-bottom: 1.25rem;
  justify-content: center;
}
#engineSelectors label {
  display: flex;
  align-items: center;
  cursor: pointer;
}
#engineSelectors input {
  margin-right: .25rem;
}

/* 7. Search bar */
.search-bar {
  display: flex;
  align-items: center;
  gap: .4rem;
  width: 100%;
  max-width: 600px;
  margin: 0 auto .75rem;
}
.autocomplete {
  flex: 1;
  position: relative;
}
.search-bar input {
  width: 100%;
  height: 2rem;
  padding: 0 .4rem;
  font-size: .8rem;
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: .3rem .3rem 0 0;
  background: var(--box-bg);
  color: var(--text);
}
.search-bar button {
  height: 2rem;
  padding: 0 .6rem;
  font-size: .8rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: .3rem;
  cursor: pointer;
}
.search-bar button:disabled {
  background: #99c2e6;
  cursor: default;
}
.search-bar button:hover:enabled {
  background: var(--accent-hover);
}

/* 8. Suggestions */
.suggestions {
  position: absolute;
  top: calc(100% + 2px);
  left: 0; right: 0;
  background: var(--box-bg);
  border: 1px solid var(--border);
  border-top: none;
  max-height: 6rem;
  overflow-y: auto;
  z-index: 100;
}
.suggestions li {
  padding: .3rem;
  font-size: .75rem;
  cursor: pointer;
}
.suggestions li:hover,
.suggestions li:focus-visible {
  background: #eee;
  outline: none;
}

/* 9. History */
#history {
  margin: 1rem 0 .5rem;
  font-size: .7rem;
  text-align: center;
}
#history a {
  margin: 0 .25rem;
  color: var(--accent);
  text-decoration: underline;
  cursor: pointer;
}

/* 10. Results */
#resultsTitle,
#openAllContainer,
#results {
  display: none;
}
#resultsTitle {
  font-size: .9rem;
  font-weight: 600;
  text-align: center;
  margin: .5rem 0;
}
#openAllContainer {
  text-align: center;
  margin-bottom: .5rem;
}
.open-all-link {
  font-size: .8rem;
  color: var(--accent);
  text-decoration: underline;
  cursor: pointer;
}
.open-all-link:hover {
  color: var(--accent-hover);
}

/* Columns & Boxes */
#results {
  flex: 1;
  display: flex;
  gap: .25rem;
  justify-content: center;
  overflow: hidden;
}
.column {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--box-bg);
  border-radius: .4rem;
  padding: .2rem;
  overflow: visible;
}
.column h2 {
  font-size: .85rem;
  text-align: center;
  margin-bottom: .2rem;
}
.result-box {
  margin: .2rem 0;
  padding: .2rem;
  font-size: .65rem;
  border: 1px solid var(--border);
  border-radius: .3rem;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.result-box h3 {
  font-size: .75rem;
  margin-bottom: .1rem;
}
.open-link {
  font-size: .65rem;
  color: var(--accent);
  text-decoration: underline;
  cursor: pointer;
}
.open-link:hover {
  color: var(--accent-hover);
}

@media (pointer: coarse) {
  .result-box { min-height: 1.8rem; }
}

/* 11. Mobile & Tablet — Stack Title + Toggle for widths ≤1024px */
@media (max-width: 1024px) {
  .title-wrapper {
    position: static;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
  }

  .mode-container {
    position: static;
    margin-top: .5rem;
  }
}
