/* ==========================================================
   FILE: styles.css
   WHAT IT DOES: Controls how the page looks: the calm green colors,
   the card grid (1 column on phones, more on bigger screens), the
   tag colors, the loading spinner, and dark mode.
   WHY IT'S BUILT THIS WAY: Each effect group has its own symbol and
   heading as well as a color (✚ helps, ⚠ side effect), so people who
   can't tell colors apart still know which is which.
   ========================================================== */

/* ----- Color tokens (light theme) ----- */
:root {
  --bg: #f6f5f0;
  --surface: #ffffff;
  --surface-alt: #eef3ee;
  --text: #1d2a22;
  --text-muted: #556259;
  --border: #d6ddd5;
  --accent: #2f6f4f;
  --helps-bg: #e3f1e7;
  --helps-text: #1f5a3a;
  --feel-bg: #eef0f6;
  --feel-text: #33405e;
  --side-bg: #fbeee6;
  --side-text: #8a3b12;
  --focus: #d08a00;
  --button-text: #ffffff;      /* every button has white text */
  --button-bg: #2f6f4f;        /* main buttons: deep green */
  --button-hover: #22553b;
  --button-alt-bg: #3f4d45;    /* second-choice buttons and chips: dark grey-green */
  --button-alt-border: #3f4d45;
  --button-alt-hover: #2c3832;
  --button-off-bg: #6b756f;    /* unavailable page button: grey */
  --button-shadow: rgba(16, 40, 27, 0.25);
  --tip-bg: #1d2a22;           /* tooltips: dark box, white text */
  --tip-text: #ffffff;
  --radius: 14px;
  color-scheme: light;
}

/* ----- Dark theme (follows the device setting) ----- */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111613;
    --surface: #18201b;
    --surface-alt: #1f2a23;
    --text: #e6ece7;
    --text-muted: #a6b3aa;
    --border: #2f3b33;
    --accent: #7cc49b;
    --helps-bg: #1e3b2a;
    --helps-text: #a8e2be;
    --feel-bg: #252c3d;
    --feel-text: #c4cdea;
    --side-bg: #3d2619;
    --side-text: #f3c0a0;
    --button-bg: #2e7d55;      /* deep enough for white text (5:1), still stands out on dark */
    --button-hover: #276b48;
    --button-alt-bg: #34463b;
    --button-alt-border: #8fd6ab; /* bright edge so it shows against the dark page */
    --button-alt-hover: #405749;
    --button-shadow: rgba(0, 0, 0, 0.5);
    --tip-bg: #f1f5f2;         /* tooltips: light box, dark text, so it pops off the dark page */
    --tip-text: #111613;
    color-scheme: dark;
  }
}

/* ----- Base ----- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.6;
  overflow-wrap: break-word; /* long words wrap instead of running off small screens */
}

a {
  color: var(--accent);
}

/* Visible focus ring for keyboard users */
:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: 1rem;
  top: -4rem;
  padding: 0.6rem 1rem;
  background: var(--accent);
  color: var(--surface);
  border-radius: 8px;
  z-index: 10;
}

.skip-link:focus {
  top: 1rem;
}

/* ----- Header ----- */
.site-header,
main,
.site-footer {
  max-width: 72rem;
  margin: 0 auto;
  padding: 0 1rem;
}

.site-header {
  padding-top: 2.5rem;
}

.site-header h1 {
  margin: 0;
  font-size: clamp(2rem, 5vw, 2.75rem);
  letter-spacing: -0.02em;
}

.lede {
  margin: 0.25rem 0 1.5rem;
  color: var(--text-muted);
  max-width: 40rem;
}

/* Warning box at the top: same warm colors as the full notice in the footer,
   with a thick left stripe and a warning sign so it is hard to miss */
.top-notice {
  margin: 0 0 1.5rem;
  padding: 1rem 1.25rem;
  background: var(--side-bg);
  color: var(--side-text);
  border: 2px solid var(--side-text);
  border-left-width: 8px;
  border-radius: var(--radius);
}

.top-notice h2 {
  margin: 0 0 0.35rem;
  font-size: 1.2rem;
}

/* The sign is decoration; the heading already says "Important" ("" = nothing read aloud) */
.top-notice h2::before {
  content: "⚠ " / "";
}

.top-notice p {
  margin: 0;
  color: var(--text);
}

.top-notice p + p {
  margin-top: 0.6rem;
}

.top-notice a {
  color: var(--side-text);
  font-weight: 700;
  text-underline-offset: 3px;
}

.top-notice a::after {
  content: " ↓" / "";
}

.status {
  padding: 0.6rem 0.8rem;
  border-left: 4px solid var(--accent);
  background: var(--surface-alt);
  border-radius: 4px;
}

/* ----- Loading message with a spinning ring ----- */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  min-height: 12rem;
  margin: 1rem 0;
  color: var(--text-muted);
  font-weight: 600;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

/* [hidden] must win over display: flex above */
.loading[hidden] {
  display: none;
}

.loading::before {
  content: "";
  width: 1.5rem;
  height: 1.5rem;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* People who turn on "reduce motion" see a still ring instead of a spinning one */
@media (prefers-reduced-motion: reduce) {
  .loading::before {
    animation: none;
  }
}

/* ----- Card grid: 1 column on phones, more as the screen widens ----- */
.strain-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 17rem), 1fr));
  gap: 1rem;
  list-style: none;
  margin: 1rem 0 2rem;
  padding: 0;
}

.strain-card {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.strain-card img {
  width: 100%;
  height: 11rem;
  object-fit: cover;
  background: var(--surface-alt);
}

.card-header {
  display: flex;
  flex-wrap: wrap; /* THC/CBD drops below a long name when text is enlarged */
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 1rem 1rem 0.25rem;
}

.card-header h3 {
  margin: 0;
  font-size: 1.2rem;
  line-height: 1.3;
}

/* THC / CBD shown side by side */
.potency {
  display: grid;
  grid-template-columns: auto auto;
  gap: 0 0.4rem;
  margin: 0;
  font-size: 0.8rem;
  text-align: right;
  white-space: nowrap;
}

.potency dt {
  color: var(--text-muted);
  font-weight: 600;
}

.potency dd {
  margin: 0;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* ----- Effect tags ----- */
.tag-group {
  padding: 0.5rem 1rem 0;
}

.tag-group:last-of-type {
  padding-bottom: 1rem;
}

.tag-group h3,
.tag-group h4 {
  margin: 0 0 0.3rem;
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  list-style: none;
  margin: 0;
  padding: 0;
}

.tags li {
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 600;
}

/* Each group has its own color AND its own heading, so color is never the only clue */
.tags-helps li {
  background: var(--helps-bg);
  color: var(--helps-text);
}

.tags-helps li::before {
  content: "✚ ";
}

.tags-feelings li {
  background: var(--feel-bg);
  color: var(--feel-text);
}

.tags-side li {
  background: var(--side-bg);
  color: var(--side-text);
}

.tags-side li::before {
  content: "⚠ ";
}

.no-effects {
  margin: 0.5rem 1rem 1rem;
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* ----- Footer: Florida disclaimer ----- */
.site-footer {
  padding-bottom: 3rem;
}

.disclaimer {
  padding: 1.25rem 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 5px solid var(--side-text);
  border-radius: var(--radius);
}

/* When reached from the top link: a little space above, and a brief highlight */
.disclaimer {
  scroll-margin-top: 1rem;
}

.disclaimer:target {
  outline: 4px solid var(--focus);
  outline-offset: 4px;
}

.disclaimer h2 {
  margin: 0 0 0.5rem;
  font-size: 1.1rem;
}

.disclaimer ul {
  margin: 0;
  padding-left: 1.2rem;
  font-size: 0.9rem;
}

.disclaimer li + li {
  margin-top: 0.4rem;
}

.source-note {
  color: var(--text-muted);
  font-size: 0.8rem;
}

/* ==========================================================
   SEARCH PANEL
   ========================================================== */
.search-panel {
  padding: 1.25rem;
  margin-bottom: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin: 0 0 0.75rem;
}

label {
  font-weight: 600;
}

.field-symptom label {
  font-size: 1.1rem;
}

input[type="search"],
select {
  font: inherit;
  font-size: 1rem; /* 16px stops iPhones zooming in */
  color: var(--text);
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 0.6rem 0.8rem;
  min-height: 2.75rem; /* 44px touch target */
  width: 100%;
}

input[type="search"] {
  font-size: 1.1rem;
  min-height: 3.25rem;
}

input:focus-visible,
select:focus-visible {
  border-color: var(--accent);
}

/* Invalid fields get a colored border AND a written message */
[aria-invalid="true"] {
  border-color: var(--side-text) !important;
}

.hint {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.error {
  color: var(--side-text);
  font-weight: 600;
  font-size: 0.9rem;
}

.error:empty {
  display: none;
}

.error::before {
  content: "⚠ ";
}

.search-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin: 0 0 1rem;
}

button {
  font: inherit;
  cursor: pointer;
}

/* Two button styles, both with white text:
   - green: the main action (Find strains, Details, Next, Close)
   - dark grey-green: the second choice (Clear, Save, Refresh data, symptom chips)
   Both have a 2px border, bold text and a small shadow so they look pressable. */
.button-primary,
.button-secondary,
.details-button,
.favorite-button {
  min-height: 3rem;
  padding: 0.55rem 1.25rem;
  border-radius: 10px;
  border: 2px solid var(--button-bg);
  font-size: 1.05rem;
  font-weight: 700;
  box-shadow: 0 2px 4px var(--button-shadow);
}

.button-primary,
.details-button {
  background: var(--button-bg);
  color: var(--button-text);
}

.button-secondary,
.favorite-button {
  background: var(--button-alt-bg);
  border-color: var(--button-alt-border);
  color: var(--button-text);
}

.button-primary:hover,
.details-button:hover {
  background: var(--button-hover);
  border-color: var(--button-hover);
}

.button-secondary:hover,
.favorite-button:hover {
  background: var(--button-alt-hover);
}

/* Pressed: the button sinks a little */
.button-primary:active,
.button-secondary:active,
.details-button:active,
.favorite-button:active {
  transform: translateY(1px);
  box-shadow: none;
}

/* THC, CBD and Sort by sit side by side on wide screens and stack on phones.
   align-items: end lines up the bottoms of the dropdowns, and
   "Favorites only" gets its own row underneath, lined up on the left. */
.filters {
  min-width: 0; /* fieldsets don't shrink by default; this lets it fit small screens */
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 14rem), 1fr));
  gap: 0 1rem;
  align-items: end;
  margin: 0;
  padding: 0.75rem 1rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.filters legend {
  padding: 0 0.3rem;
  font-weight: 700;
  font-size: 0.9rem;
}

.filters .field-check {
  grid-column: 1 / -1;
}

.field-check {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 0.25rem 0.5rem;
  min-height: 2.75rem;
}

.field-check input {
  width: 1.3rem;
  height: 1.3rem;
  margin: 0;
  accent-color: var(--accent);
}

.field-check .error {
  grid-column: 1 / -1;
}

/* ----- Quick-pick symptom buttons ----- */
.quick-picks {
  margin-top: 1rem;
}

.quick-picks h2 {
  margin: 0 0 0.4rem;
  font-size: 0.8rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.quick-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  list-style: none;
  margin: 0;
  padding: 0;
}

.chip {
  min-height: 2.75rem;
  padding: 0.35rem 1rem;
  border: 2px solid var(--button-alt-border);
  border-radius: 999px;
  background: var(--button-alt-bg);
  color: var(--button-text);
  font-size: 1rem;
  font-weight: 700;
  box-shadow: 0 1px 3px var(--button-shadow);
}

.chip:hover {
  background: var(--button-alt-hover);
}

.chip small {
  margin-left: 0.3rem;
  color: var(--button-text);
  font-weight: 500;
}

/* "Turn off Favorites only" stands out as the main way forward */
.chip-reset {
  background: var(--button-bg);
  border-color: var(--button-bg);
}

.chip-reset:hover {
  background: var(--button-hover);
}

/* ==========================================================
   RESULTS
   ========================================================== */
.results-heading {
  margin: 1.5rem 0 0.25rem;
  font-size: 1.35rem;
  line-height: 1.3;
}

.results-heading:focus {
  outline: none;
}

.results-heading:focus-visible {
  outline: 3px solid var(--focus);
}

.results-note {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.results-note:empty {
  display: none;
}

.empty-state {
  padding: 1.5rem;
  margin: 1rem 0;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.empty-state[hidden] {
  display: none;
}

.empty-state h3 {
  margin: 0 0 0.25rem;
}

/* Effect tags that match the search stand out with an outline and bold text */
.tags li.is-match {
  outline: 2px solid currentColor;
  outline-offset: 1px;
  font-weight: 800;
}

/* ----- Card buttons ----- */
.card-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: auto; /* pushes buttons to the bottom of every card */
  padding: 0.75rem 1rem 1rem;
}

.card-actions .details-button {
  flex: 1;
  padding: 0.55rem 0.75rem;
}

/* Saved favorites: filled heart plus a green background */
.favorite-button[aria-pressed="true"] {
  background: var(--button-bg);
  border-color: var(--button-bg);
}

/* The last tag group no longer needs extra space; buttons sit below it */
.tag-group:last-of-type {
  padding-bottom: 0;
}

/* ==========================================================
   DETAIL VIEW
   ========================================================== */
.strain-dialog {
  width: min(42rem, calc(100% - 2rem));
  max-height: 90vh;
  padding: 0;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.strain-dialog::backdrop {
  background: rgba(0, 0, 0, 0.8);
}

/* Scrolling stays inside the detail view:
   - overscroll-behavior stops the scroll passing to the page when the
     detail view reaches its top or bottom
   - while the detail view is open, the page behind it can't scroll at all
     (scrollbar-gutter keeps the page from shifting sideways when its scrollbar goes) */
.strain-dialog {
  overflow-y: auto;
  overscroll-behavior: contain;
}

html {
  scrollbar-gutter: stable;
}

html:has(.strain-dialog[open]) {
  overflow: hidden;
}

.detail-image {
  width: 100%;
  height: 14rem;
  object-fit: cover;
}

.detail-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  padding: 1rem 1.25rem 0;
}

.detail-header h2 {
  margin: 0;
  font-size: 1.6rem;
}

.detail-actions {
  display: flex;
  margin: 0.5rem 1.25rem 0;
}

.detail-actions .favorite-button {
  flex: 0 1 auto;
  padding: 0 1.25rem;
}

.detail-description {
  margin: 0.75rem 1.25rem 0;
}

.strain-dialog .tag-group {
  padding: 0.75rem 1.25rem 0;
}

.terpene-list {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.35rem 1rem;
  align-items: center;
  margin: 0;
}

.terpene-list dt {
  font-weight: 600;
}

.terpene-list dd {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin: 0;
}

.terpene-list meter {
  flex: 1;
  height: 0.7rem;
}

.terpene-list data {
  min-width: 3.5rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-size: 0.85rem;
}

.tags-aromas li {
  background: var(--surface-alt);
  color: var(--text);
}

.detail-note {
  margin: 1rem 1.25rem 0;
  padding: 0.6rem 0.8rem;
  background: var(--side-bg);
  color: var(--side-text);
  border-radius: 8px;
  font-size: 0.85rem;
}

.dialog-close {
  display: flex;
  justify-content: flex-end;
  padding: 1rem 1.25rem 1.25rem;
}

/* Refresh button: centered just above the page number */
.refresh-row {
  display: flex;
  justify-content: center;
  margin: 0 0 1rem;
}

.refresh-row[hidden] {
  display: none;
}

#data-note:empty {
  display: none;
}

/* ==========================================================
   PAGES OF RESULTS (10 strains at a time)
   ========================================================== */
.pagination {
  display: flex;
  flex-wrap: wrap; /* stays inside the screen when text is enlarged */
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin: 0 0 2.5rem;
}

.pagination[hidden] {
  display: none;
}

/* Big, easy-to-tap buttons */
.page-button {
  min-width: min(8.5rem, 100%);
  min-height: 3rem;
  font-size: 1.05rem;
}

/* Unavailable (first or last page): grey and dashed, no shadow */
.page-button:disabled,
.page-button:disabled:hover {
  background: var(--button-off-bg);
  border: 2px dashed var(--text-muted);
  color: var(--button-text);
  box-shadow: none;
  transform: none;
  cursor: not-allowed;
}

.page-info {
  margin: 0;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* On narrow phones: page number on its own line, buttons side by side below */
@media (max-width: 26rem) {
  .pagination {
    flex-wrap: wrap;
  }

  .page-info {
    order: -1;
    flex-basis: 100%;
    text-align: center;
  }

  .page-button {
    flex: 1;
    min-width: 0;
  }
}

/* ----- Large text on small phones -----
   Form controls and grid/flex items normally refuse to get narrower
   than their content. These rules let them shrink and wrap instead,
   so nothing runs off the screen when someone enlarges their text. */
.field,
.filters > *,
select,
.search-actions > button {
  min-width: 0;
  max-width: 100%;
}

.search-actions > button {
  white-space: normal;
}

/* ==========================================================
   TOOLTIPS ("What is THC?" / "What is CBD?")
   ========================================================== */

/* Label and its "What is…?" button on one line, the dropdown underneath */
.field-with-tip {
  position: relative; /* the tip is placed against this field */
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  column-gap: 0.6rem;
}

.field-with-tip select {
  grid-column: 1 / -1;
}

/* The button: a small, clearly visible pill with white text and a "?" badge */
.tip-button {
  justify-self: start;
  min-height: 2.25rem;
  padding: 0.2rem 0.8rem 0.2rem 0.35rem;
  border: 2px solid var(--button-alt-border);
  border-radius: 999px;
  background: var(--button-alt-bg);
  color: var(--button-text);
  font-size: 0.9rem;
  font-weight: 700;
  box-shadow: 0 1px 3px var(--button-shadow);
}

.tip-button::before {
  content: "?" / "";
  display: inline-grid;
  place-items: center;
  width: 1.4rem;
  height: 1.4rem;
  margin-right: 0.4rem;
  border-radius: 50%;
  background: var(--button-text);
  color: var(--button-alt-bg);
  font-weight: 800;
}

.tip-button:hover,
.tip-button[aria-expanded="true"] {
  background: var(--button-alt-hover);
}

/* The tip: floats just under the label row, over the dropdown, with a small arrow */
.tip {
  position: absolute;
  top: calc(100% + 0.4rem);
  left: 0;
  right: 0; /* as wide as its field, so it never runs off a phone screen */
  z-index: 5;
  padding: 0.85rem 1rem;
  background: var(--tip-bg);
  color: var(--tip-text);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  font-size: 1rem;
  line-height: 1.5;
}

.tip[hidden] {
  display: none;
}

.tip::before {
  content: "";
  position: absolute;
  top: -0.5rem;
  left: 1.25rem;
  border: 0.5rem solid transparent;
  border-top: 0;
  border-bottom-color: var(--tip-bg);
}

/* On big screens there is room for a wider, shorter tip */
@media (min-width: 60rem) {
  .tip {
    right: auto;
    width: 24rem;
  }
}
