/* Minimal palette · mobile-first · filter sheet · theme: system / light / dark */

:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --text: #171717;
  --text-muted: #737373;
  --border: #e5e5e5;
  --border-strong: #d4d4d4;
  --header-bg: #ffffff;
  --overlay: rgba(0, 0, 0, 0.45);
  --focus: #404040;

  --radius: 8px;
  --radius-lg: 12px;
  --font: "IBM Plex Sans", system-ui, -apple-system, sans-serif;
  --touch: 48px;
  --pad-x: max(1rem, env(safe-area-inset-left, 0px));
  --pad-x-end: max(1rem, env(safe-area-inset-right, 0px));
  --pad-top: max(0.5rem, env(safe-area-inset-top, 0px));
  --pad-bottom: max(1rem, env(safe-area-inset-bottom, 0px));
}

[data-theme="light"] {
  color-scheme: light;
  --bg: #fafafa;
  --surface: #ffffff;
  --text: #171717;
  --text-muted: #737373;
  --border: #e5e5e5;
  --border-strong: #d4d4d4;
  --header-bg: #ffffff;
  --overlay: rgba(0, 0, 0, 0.45);
  --focus: #404040;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #171717;
  --surface: #262626;
  --text: #fafafa;
  --text-muted: #a3a3a3;
  --border: #404040;
  --border-strong: #525252;
  --header-bg: #171717;
  --overlay: rgba(0, 0, 0, 0.65);
  --focus: #a3a3a3;
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="system"] {
    color-scheme: dark;
    --bg: #171717;
    --surface: #262626;
    --text: #fafafa;
    --text-muted: #a3a3a3;
    --border: #404040;
    --border-strong: #525252;
    --header-bg: #171717;
    --overlay: rgba(0, 0, 0, 0.65);
    --focus: #a3a3a3;
  }
}

@media (prefers-color-scheme: light) {
  :root[data-theme="system"] {
    color-scheme: light;
  }
}

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

html {
  font-size: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font);
  font-weight: 400;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}

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

.skip-link {
  position: absolute;
  left: -9999px;
  z-index: 300;
  padding: 0.75rem 1rem;
  background: var(--text);
  color: var(--bg);
  text-decoration: none;
  font-weight: 600;
  border-radius: var(--radius);
}

.skip-link:focus {
  left: max(1rem, env(safe-area-inset-left));
  top: max(1rem, env(safe-area-inset-top));
}

/* Header */
.store-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--header-bg);
  border-bottom: 1px solid var(--border);
}

.store-header__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: var(--pad-top) var(--pad-x) 0.75rem;
  padding-right: var(--pad-x-end);
}

.store-header__brand {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  min-width: 0;
}

.store-header__logo {
  flex-shrink: 0;
  width: 2.5rem;
  height: 2.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.store-header__title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.store-header__subtitle {
  margin: 0;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.store-header__actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.view-toggle {
  display: flex;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}

.view-toggle__btn {
  min-height: var(--touch);
  padding: 0 0.75rem;
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 500;
  border: none;
  background: var(--bg);
  color: var(--text-muted);
  cursor: pointer;
}

.view-toggle__btn.is-active {
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  box-shadow: 0 0 0 1px var(--border);
}

.view-toggle__btn:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.btn-icon {
  min-height: var(--touch);
  padding: 0 0.875rem;
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 500;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

.btn-icon:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.theme-btn {
  min-width: 3.25rem;
  font-variant-numeric: tabular-nums;
}

.theme-btn__text {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

/* Toolbar */
.store-toolbar {
  padding: 0.5rem var(--pad-x) 0.75rem;
  padding-right: var(--pad-x-end);
  padding-bottom: max(0.75rem, var(--pad-bottom));
}

.toolbar-search-row {
  display: flex;
  align-items: stretch;
  gap: 0.5rem;
}

.search-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
}

.search-wrap__icon {
  position: absolute;
  left: 0.875rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1.125rem;
  color: var(--text-muted);
  pointer-events: none;
}

.search-wrap__input {
  width: 100%;
  min-height: var(--touch);
  padding: 0.625rem 0.875rem 0.625rem 2.75rem;
  font-size: 1rem;
  font-family: inherit;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}

.search-wrap__input::placeholder {
  color: var(--text-muted);
}

.search-wrap__input:focus {
  outline: none;
  border-color: var(--text-muted);
  box-shadow: 0 0 0 2px rgba(115, 115, 115, 0.2);
}

/* Filter trigger (line-style icon) */
.filter-menu-btn {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: var(--touch);
  padding: 0 0.75rem;
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  position: relative;
  -webkit-tap-highlight-color: transparent;
}

.filter-menu-btn:hover {
  background: var(--bg);
}

.filter-menu-btn:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.filter-menu-btn__icon {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 18px;
}

.filter-menu-btn__icon span {
  display: block;
  height: 2px;
  background: currentColor;
  border-radius: 1px;
}

.filter-menu-btn__icon span:nth-child(1) {
  width: 100%;
}
.filter-menu-btn__icon span:nth-child(2) {
  width: 70%;
}
.filter-menu-btn__icon span:nth-child(3) {
  width: 100%;
}

.filter-menu-btn__label {
  display: none;
}

@media (min-width: 380px) {
  .filter-menu-btn__label {
    display: inline;
  }
}

.filter-menu-btn__badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 1.125rem;
  height: 1.125rem;
  padding: 0 4px;
  font-size: 0.625rem;
  font-weight: 700;
  line-height: 1.125rem;
  text-align: center;
  background: var(--text);
  color: var(--bg);
  border-radius: 999px;
}

.filter-menu-btn__badge[hidden] {
  display: none;
}

/* Quick chips */
.quick-filters {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 2px;
}

.quick-filters__label {
  display: none;
}

.chip {
  flex-shrink: 0;
  min-height: 40px;
  padding: 0.35rem 0.85rem;
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 500;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

.chip.is-active {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}

.chip:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* Filter overlay + sheet */
.filter-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.filter-overlay[hidden] {
  display: none;
}

.filter-overlay__backdrop {
  position: absolute;
  inset: 0;
  border: none;
  padding: 0;
  margin: 0;
  background: var(--overlay);
  cursor: pointer;
}

.filter-sheet {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 32rem;
  max-height: min(85dvh, 100%);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.12);
  padding-bottom: env(safe-area-inset-bottom, 0);
}

@media (min-width: 640px) {
  .filter-overlay {
    align-items: center;
    padding: 1rem;
  }

  .filter-sheet {
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    max-height: min(90dvh, 100%);
  }
}

.filter-sheet__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.filter-sheet__title {
  margin: 0;
  font-size: 1.0625rem;
  font-weight: 600;
}

.filter-sheet__actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.filter-sheet__clear {
  min-height: 40px;
  padding: 0 0.875rem;
  font-family: inherit;
  font-size: 0.9375rem;
  font-weight: 600;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}

.filter-sheet__clear:hover {
  border-color: var(--border-strong);
  color: var(--text);
  background: var(--bg);
}

.filter-sheet__clear:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.filter-sheet__done {
  min-height: 40px;
  padding: 0 1rem;
  font-family: inherit;
  font-size: 0.9375rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  background: var(--text);
  color: var(--bg);
  cursor: pointer;
}

.filter-sheet__done:hover {
  opacity: 0.92;
}

.filter-sheet__body {
  padding: 1rem 1.25rem 1.5rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.filter-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.filter-field__label {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.filter-field__select {
  min-height: var(--touch);
  width: 100%;
  padding: 0.5rem 0.75rem;
  font-size: 1rem;
  font-family: inherit;
  font-weight: 500;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
}

.filter-field__select:focus {
  outline: none;
  border-color: var(--text-muted);
  box-shadow: 0 0 0 2px rgba(115, 115, 115, 0.2);
}

/* Main */
.main {
  padding: 0.75rem var(--pad-x) max(1.5rem, var(--pad-bottom));
  padding-right: var(--pad-x-end);
}

.result-bar {
  margin: 0 0 0.75rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 2rem 1rem;
  color: var(--text-muted);
}

.loading[hidden] {
  display: none;
}

.loading-spinner {
  width: 1.25rem;
  height: 1.25rem;
  border: 2px solid var(--border);
  border-top-color: var(--text-muted);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

.error-msg {
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.875rem;
}

.error-msg[hidden] {
  display: none;
}

/* Grid — 2 columns on mobile for card mode */
.plant-grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem;
}

@media (min-width: 640px) {
  .plant-grid {
    gap: 0.75rem;
  }
}

@media (min-width: 1024px) {
  .plant-grid {
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  }
}

.plant-grid[hidden] {
  display: none !important;
}

/* Card grid — image + minimal caption; opens detail on click */
button.plant-card--media {
  width: 100%;
  margin: 0;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  text-align: left;
  cursor: pointer;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  font: inherit;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
}

button.plant-card--media:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.plant-card__figure {
  aspect-ratio: 4 / 3;
  background: var(--bg);
  position: relative;
}

.plant-card__figure--pending .plant-card__ph {
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    -45deg,
    var(--bg),
    var(--bg) 8px,
    var(--border) 8px,
    var(--border) 9px
  );
  opacity: 0.55;
}

.plant-card__img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.plant-card__caption {
  padding: 0.45rem 0.6rem 0.55rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}

.plant-card--media .plant-card__title {
  font-size: 0.8125rem;
  font-weight: 600;
  line-height: 1.25;
  display: block;
}

.plant-card--media .plant-card__where {
  font-size: 0.625rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  line-height: 1.2;
}

.plant-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.plant-list[hidden] {
  display: none !important;
}

button.plant-row--interactive {
  width: 100%;
  margin: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  display: grid;
  grid-template-columns: 48px 1fr auto;
  align-items: center;
  gap: 0.65rem;
  padding: 0.45rem 0.65rem;
  text-align: left;
  cursor: pointer;
  font: inherit;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
}

button.plant-row--interactive:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.plant-row__thumb {
  width: 48px;
  height: 48px;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg);
  flex-shrink: 0;
}

.plant-row__thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.plant-row__thumb--empty {
  background: repeating-linear-gradient(
    -45deg,
    var(--bg),
    var(--bg) 6px,
    var(--border) 6px,
    var(--border) 7px
  );
  opacity: 0.7;
}

.plant-row--interactive .plant-row__title {
  margin: 0;
  font-size: 0.9375rem;
  font-weight: 600;
  line-height: 1.25;
}

.plant-row__sub {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.1rem;
}

.plant-row__chev {
  color: var(--text-muted);
  font-size: 1.35rem;
  font-weight: 300;
  line-height: 1;
}

/* Detail modal */
.detail-overlay {
  position: fixed;
  inset: 0;
  z-index: 150;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.detail-overlay[hidden] {
  display: none;
}

.detail-overlay__backdrop {
  position: absolute;
  inset: 0;
  border: none;
  padding: 0;
  margin: 0;
  background: var(--overlay);
  cursor: pointer;
}

.detail-sheet {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 28rem;
  max-height: min(92dvh, 100%);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.12);
  padding-bottom: env(safe-area-inset-bottom, 0);
}

@media (min-width: 640px) {
  .detail-overlay {
    align-items: center;
    padding: 1rem;
  }

  .detail-sheet {
    border-radius: var(--radius-lg);
    max-height: min(90dvh, 100%);
  }
}

.detail-sheet__toolbar {
  flex-shrink: 0;
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
}

.detail-sheet__close {
  min-height: 40px;
  padding: 0 1rem;
  font-family: inherit;
  font-size: 0.9375rem;
  font-weight: 600;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
}

.detail-sheet__body {
  overflow-y: auto;
  padding: 0 1rem 1.5rem;
  -webkit-overflow-scrolling: touch;
}

.detail-hero {
  margin: 0 -1rem 1rem;
  max-height: 42vh;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
}

.detail-hero__img {
  width: 100%;
  max-height: 42vh;
  object-fit: contain;
  display: block;
}

.detail-title {
  margin: 0 0 1rem;
  font-size: 1.25rem;
  font-weight: 600;
  line-height: 1.25;
}

.detail-meta {
  margin-bottom: 0.75rem;
}

.detail-meta__row {
  display: flex;
  gap: 0.75rem;
  padding: 0.25rem 0;
  font-size: 0.875rem;
  border-bottom: 1px solid var(--border);
}

.detail-meta__row:last-child {
  border-bottom: none;
}

.detail-meta__k {
  color: var(--text-muted);
  width: 5.5rem;
  flex-shrink: 0;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.detail-meta__v {
  font-weight: 500;
  min-width: 0;
}

.detail-notes {
  margin: 0 0 1rem;
  font-size: 0.9375rem;
  line-height: 1.5;
  color: var(--text);
}

.detail-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 1rem;
}

.detail-tag {
  font-size: 0.75rem;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-muted);
}

.detail-wiki {
  display: inline-block;
  font-size: 0.875rem;
  font-weight: 600;
  color: inherit;
  text-decoration: underline;
}

.empty-state {
  text-align: center;
  padding: 2rem 1rem;
  font-size: 0.9375rem;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
}

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

.store-footer {
  padding: 1rem var(--pad-x) max(1.5rem, var(--pad-bottom));
  padding-right: var(--pad-x-end);
  font-size: 0.75rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1.25rem;
}

.store-footer a {
  color: inherit;
  font-weight: 600;
}

.store-footer code {
  font-size: 0.7rem;
  background: var(--bg);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  border: 1px solid var(--border);
}

@media (min-width: 1200px) {
  .store-header__bar,
  .store-toolbar,
  .main,
  .store-footer {
    max-width: 1280px;
    margin-left: auto;
    margin-right: auto;
  }
}
