/* Utopia Fluid Typography and Spacing */
*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --step--2: clamp(0.78rem, 0.77rem + 0.03vw, 0.80rem);
  --step--1: clamp(0.94rem, 0.92rem + 0.11vw, 1.00rem);
  --step-0: clamp(1.13rem, 1.08rem + 0.22vw, 1.25rem);
  --step-1: clamp(1.35rem, 1.28rem + 0.37vw, 1.56rem);
  --step-2: clamp(1.62rem, 1.50rem + 0.58vw, 1.95rem);
  --step-3: clamp(1.94rem, 1.77rem + 0.87vw, 2.44rem);
  --step-4: clamp(2.33rem, 2.08rem + 1.25vw, 3.05rem);
  --step-5: clamp(2.80rem, 2.45rem + 1.77vw, 3.82rem);

  --space-3xs: clamp(0.31rem, 0.31rem + 0.00vw, 0.31rem);
  --space-2xs: clamp(0.56rem, 0.54rem + 0.11vw, 0.63rem);
  --space-xs: clamp(0.88rem, 0.85rem + 0.11vw, 0.94rem);
  --space-s: clamp(1.13rem, 1.08rem + 0.22vw, 1.25rem);
  --space-m: clamp(1.69rem, 1.62rem + 0.33vw, 1.88rem);
  --space-l: clamp(2.25rem, 2.16rem + 0.43vw, 2.50rem);
  --space-xl: clamp(3.38rem, 3.24rem + 0.65vw, 3.75rem);
  --space-2xl: clamp(4.50rem, 4.32rem + 0.87vw, 5.00rem);
  --space-3xl: clamp(6.75rem, 6.48rem + 1.30vw, 7.50rem);

  /* One-up pairs */
  --space-3xs-2xs: clamp(0.31rem, 0.20rem + 0.54vw, 0.63rem);
  --space-2xs-xs: clamp(0.56rem, 0.43rem + 0.65vw, 0.94rem);
  --space-xs-s: clamp(0.88rem, 0.74rem + 0.65vw, 1.25rem);
  --space-s-m: clamp(1.13rem, 0.86rem + 1.30vw, 1.88rem);
  --space-m-l: clamp(1.69rem, 1.40rem + 1.41vw, 2.50rem);
  --space-l-xl: clamp(2.25rem, 1.71rem + 2.72vw, 3.75rem);
  --space-xl-2xl: clamp(3.38rem, 2.80rem + 2.83vw, 5.00rem);
  --space-2xl-3xl: clamp(4.50rem, 3.43rem + 5.33vw, 7.50rem);

  /* Custom Colors */
  --color-bg: #fdfbf7;
  --color-text: #333333;
  --color-primary: #2c3e50;
  --color-accent: #e67e22;
  --color-border: #e0e0e0;
  --color-result-bg: #ffffff;
}

body {
  background-color: var(--color-bg);
  color: var(--color-text);
  font-family: 'Cormorant Garamond', serif;
  font-size: var(--step-0);
  line-height: 1.5;
  margin: 0;
  padding: 0;
}

h1,
h2,
h3,
h4,
h5,
h6 {
  font-family: 'Cormorant Garamond', serif;
  font-weight: 700;
  line-height: 1.2;
  margin-top: var(--space-l);
  margin-bottom: var(--space-s);
}

h1 {
  font-size: var(--step-5);
}

h2 {
  font-size: var(--step-4);
}

h3 {
  font-size: var(--step-3);
}

a {
  color: var(--color-primary);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 0.2s;
}

a:hover {
  border-bottom-color: var(--color-primary);
}

.container {
  max-width: 800px;
  margin: 0 auto;
  padding: var(--space-l) var(--space-s);
}

/* Search Section */
.search-section {
  text-align: center;
  margin-bottom: var(--space-xl);
}

.search-section.results-visible {
  margin-bottom: 0;
}

.search-container {
  position: relative;
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
}

.search-input {
  width: 100%;
  padding: var(--space-s);
  padding-right: 2.5rem;
  /* Space for clear button */
  font-size: var(--step-1);
  line-height: 1.5;
  font-family: 'Cormorant Garamond', serif;
  border: 2px solid var(--color-border);
  border-radius: 4px;
  background-color: #fff;
  transition: border-color 0.2s;
  display: block;
}

.clear-btn {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  font-size: 2rem;
  /* Increased size */
  color: #999;
  cursor: pointer;
  padding: 0;
  margin: 0;
  /* Ensure no default margins affect centering */
  line-height: 1;
  display: none;
  /* Hidden by default */
  z-index: 10;
  height: auto;
  width: auto;
  display: flex;
  /* Help center the glyph if it has internal spacing */
  align-items: center;
  justify-content: center;
}

/* Re-hide by default since I added display:flex above which overrides display:none */
.clear-btn[style*="display: block"] {
  display: flex !important;
}

.clear-btn {
  display: none;
}

.clear-btn:hover {
  color: var(--color-primary);
}

.search-input.has-results {
  border-bottom: none;
  border-radius: 4px 4px 0 0;
}

.search-input:focus {
  outline: none;
  border-color: var(--color-primary);
}

/* Results Section */
.results-section {
  max-width: 600px;
  margin: 0 auto;
  background: #fff;
  border: 2px solid var(--color-primary);
  border-top: none;
  border-radius: 0 0 4px 4px;
  display: none;
  /* Hidden by default */
  margin-top: -2px;
}

.result-item {
  cursor: pointer;
  padding: var(--space-s);
  margin-bottom: 0;
}

.result-item:last-child {
  border-bottom: none;
}

.result-item:hover {
  background-color: #f9f9f9;
  text-decoration: none;
}

.result-title {
  font-size: var(--step-1);
  margin: 0;
  color: var(--color-text);
  font-weight: 400;
}

.result-tags {
  font-size: var(--step--1);
  color: #666;
}

.tag {
  display: inline-block;
  background: #eee;
  padding: 2px 8px;
  border-radius: 12px;
  margin-right: 8px;
}

/* Article Section */
.article-section {
  display: none;
  /* Hidden by default */
  background: var(--color-result-bg);
  padding: var(--space-xl);
  border-radius: 4px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
}

.back-button {
  display: inline-block;
  margin-bottom: var(--space-m);
  font-size: var(--step-0);
  cursor: pointer;
  color: var(--color-accent);
}

.article-content {
  font-size: var(--step-0);
}

.article-content h1 {
  margin-top: 0;
}

/* PureCSS overrides if needed */
.pure-button-primary {
  background-color: var(--color-primary);
}

/* Modal Styles */
.modal {
  display: none;
  position: fixed;
  z-index: 2000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: auto;
  background-color: rgba(0, 0, 0, 0.4);
}

.modal-content {
  background-color: #fefefe;
  margin: 10% auto;
  padding: var(--space-l);
  border: 1px solid #888;
  width: 90%;
  max-width: 600px;
  border-radius: 4px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.close {
  color: #aaa;
  float: right;
  font-size: 28px;
  font-weight: bold;
  cursor: pointer;
}

.close:hover,
.close:focus {
  color: black;
  text-decoration: none;
  cursor: pointer;
}

/* Back Arrow */
.back-arrow {
  display: none;
  /* Hidden by default */
  cursor: pointer;
  color: var(--color-primary);
  padding: var(--space-2xs);
  margin-right: var(--space-s);
  /* Flex item behavior */
  flex-shrink: 0;
  position: relative;
  /* Required for z-index to work */
  z-index: 102;
  /* Ensure it is above just in case */
}

.back-arrow:hover {
  color: var(--color-accent);
}

/* Search Active State (Article View) */
body.search-active .search-section {
  position: sticky;
  top: 0;
  background-color: var(--color-bg);
  z-index: 100;
  padding-bottom: var(--space-s);
  margin-bottom: var(--space-m);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  flex-direction: row;
  /* Change to row to align back arrow and input */
  align-items: center;
  justify-content: center;
  padding-top: var(--space-s);
  max-width: 800px;
  /* Match content width */
  margin-left: auto;
  margin-right: auto;
  padding-left: var(--space-s);
  padding-right: var(--space-s);
}

/* Search Active State (Article View) - Global Layout */
body.search-active .search-section {
  position: sticky;
  top: 0;
  background-color: var(--color-bg);
  z-index: 100;
  padding-bottom: var(--space-s);
  margin-bottom: var(--space-m);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding-top: var(--space-s);
}

body.search-active .search-section h1 {
  display: none;
  /* Default for mobile/no-animation: just hide it */
}

body.search-active .back-arrow {
  display: flex;
  /* Helps center the SVG */
  align-items: center;
  justify-content: center;
}

body.search-active .search-container {
  margin: 0;
  flex-grow: 1;
  /* Take remaining space */
  max-width: none;
  /* Reset max-width restriction */
  /* padding-left removed */
}

body.search-active .search-input {
  margin: 0;
  padding: var(--space-2xs);
  padding-right: 3rem;
  /* More space for the button */
  font-size: var(--step-0);
}

body.search-active .clear-btn {
  font-size: 1.5rem;
  /* Increased for active state too */
  right: 15px;
  /* Moved away from the edge */
}

body.search-active .container {
  padding-top: 0;
}

body.search-active .article-section {
  max-width: 800px;
  margin: 0 auto;
}

/* Animations and Overlay - Global */
body.search-active .search-section {
  transition: all 0.3s ease-in-out;
}

body.search-active .search-input {
  transition: all 0.3s ease-in-out;
}

body.search-active .article-section {
  transition: filter 0.3s ease-in-out, opacity 0.3s ease-in-out;
}

/* Search Overlay State */
body.search-overlay .search-section {
  transform: translateY(20vh);
  background-color: transparent;
  border-bottom: none;
  z-index: 200;
}

body.search-overlay .search-input {
  padding: var(--space-s);
  font-size: var(--step-1);
  box-shadow: 0 4px 20px -5px rgba(0, 0, 0, 0.1);
}

body.search-overlay .article-section {
  filter: blur(5px);
  opacity: 0.8;
  pointer-events: none;
}

body.search-overlay .results-section {
  position: absolute;
  left: 0;
  right: 0;
  z-index: 201;
  /* Match search section transform */
  transform: translateY(20vh);

  top: 0;
  margin-top: calc(var(--step-1) * 1.5 + var(--space-s) * 3 - 4px);

  pointer-events: auto;
  background: var(--color-result-bg);
  border-radius: 0 0 4px 4px;
  box-shadow: 0 10px 20px -5px rgba(0, 0, 0, 0.1);
  border-top: none;
}

/* Animations and Overlay - Desktop Only Specifics */
@media (min-width: 769px) {


  /* Override display:none with animation for desktop */
  body.search-active .search-section h1 {
    display: block;
    max-height: 0;
    opacity: 0;
    margin: 0;
    overflow: hidden;
    pointer-events: none;
  }


  /* Search Overlay State moved to global */

}

/* Ensure container is relative for absolute positioning of results */
.container {
  position: relative;
}

/* Floating Submit Button */
#floatingSubmitBtnContainer {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 1001;
  /* Above modal if needed, but modal is 1000 so this is fine, actually modal should be higher */
}

/* Toggle Switch */
.switch {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 20px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  -webkit-transition: .4s;
  transition: .4s;
}

.slider:before {
  position: absolute;
  content: "";
  height: 16px;
  width: 16px;
  left: 2px;
  bottom: 2px;
  background-color: white;
  -webkit-transition: .4s;
  transition: .4s;
}

input:checked+.slider {
  background-color: var(--color-primary);
}

input:focus+.slider {
  box-shadow: 0 0 1px var(--color-primary);
}

input:checked+.slider:before {
  -webkit-transform: translateX(20px);
  -ms-transform: translateX(20px);
  transform: translateX(20px);
}

/* Rounded sliders */
.slider.round {
  border-radius: 34px;
}

.slider.round:before {
  border-radius: 50%;
}

/* Mobile Optimizations */
@media (max-width: 768px) {
  :root {
    --space-l: var(--space-m);
    --space-xl: var(--space-l);
    --space-2xl: var(--space-xl);
  }

  /* Floating Button - Bottom Right on Mobile */
  #floatingSubmitBtnContainer {
    top: auto;
    bottom: 20px;
    right: 20px;
  }

  /* Search Section */
  .search-section {
    padding: 0 var(--space-s);
  }

  .search-input {
    font-size: var(--step-0);
    padding: var(--space-s);
    margin: 0 auto;
    /* Ensure centering on mobile */
  }

  /* Sticky Header on Mobile */
  body.search-active .search-section {
    padding: var(--space-xs) var(--space-s);
  }

  body.search-active .search-input {
    font-size: var(--step--1);
    padding: var(--space-xs) var(--space-s);
  }

  /* Article View */
  .article-section {
    padding: var(--space-m);
  }

  /* Modals */
  .modal-content {
    width: 95%;
    margin: 20% auto;
    padding: var(--space-m);
  }

  h1 {
    font-size: var(--step-3);
  }

  .results-section {
    width: calc(100% - 2 * var(--space-s));
  }

  body.search-overlay .results-section {
    width: auto;
    left: calc(2 * var(--space-s));
    right: calc(2 * var(--space-s));
    margin-top: calc(1.5 * var(--step--1) + 3 * var(--space-xs) + 2px);
    /* Adjusted for mobile input height */
  }
}