:root {
  color-scheme: light;
  --bg: #eef3ed;
  --surface: #ffffff;
  --ink: #1c2820;
  --muted: #647269;
  --line: #d6e0d7;
  --accent: #b94f3f;
  --accent-dark: #8e392f;
  --accent-soft: #fff0eb;
  --accent-ink: #ffffff;
  --shadow: 0 12px 28px rgb(28 40 32 / 8%);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #17201a;
  --surface: #222d25;
  --ink: #eff5ef;
  --muted: #b2c0b4;
  --line: #3b4a3e;
  --accent: #e47865;
  --accent-dark: #ff9a87;
  --accent-soft: #3b2926;
  --accent-ink: #241512;
  --shadow: 0 16px 34px rgb(0 0 0 / 24%);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.45;
}

a { color: var(--accent-dark); }

a:focus-visible,
button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgb(185 79 63 / 30%);
  outline-offset: 2px;
}

.topbar {
  display: block;
  padding: 16px clamp(18px, 4vw, 48px) 0;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: block;
  margin-bottom: 12px;
  color: var(--ink);
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: .02em;
  text-decoration: none;
}

nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.menu-group {
  display: flex;
  align-items: center;
  gap: 16px;
}

.theme-toggle {
  width: 42px;
  min-height: 42px;
  padding: 0;
  border-radius: 50%;
  background: transparent;
}

.theme-toggle:hover { background: var(--accent-soft); }

.theme-icon {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.theme-icon-moon { display: none; }

:root[data-theme="dark"] .theme-icon-sun { display: none; }
:root[data-theme="dark"] .theme-icon-moon { display: block; }

nav a {
  color: var(--muted);
  font-weight: 650;
  text-decoration: none;
}

nav a:hover { color: var(--accent-dark); }

.shell {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 0 0 56px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.page-heading,
.detail,
.form-panel,
.auth-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.page-heading {
  display: flex;
  gap: 24px;
  align-items: center;
  justify-content: space-between;
  padding: 28px;
  border-top: 4px solid var(--accent);
}

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 12px; font-size: clamp(2rem, 4vw, 3.5rem); line-height: 1.02; }
h2 { font-size: 1rem; margin-top: 24px; }
p { color: var(--muted); line-height: 1.6; }

.button,
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-weight: 750;
  text-decoration: none;
  cursor: pointer;
  transition: background-color .16s ease, border-color .16s ease, color .16s ease, transform .16s ease;
}

.button:hover,
button:hover { border-color: #b5c5b8; transform: translateY(-1px); }

.button.primary,
button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
}

.button.primary:hover,
button.primary:hover { border-color: var(--accent-dark); background: var(--accent-dark); }

.danger-zone {
  display: flex;
  justify-content: flex-end;
  margin-top: 28px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.button.danger,
button.danger { border-color: #c65b52; color: #a23e37; background: transparent; }
.button.danger:hover,
button.danger:hover { border-color: #a23e37; background: #fff0ee; }

.search {
  display: flex;
  gap: 10px;
  max-width: 680px;
  margin: 24px 0 28px;
}

.search.plant-search {
  width: min(420px, 100%);
  margin: 0 0 4px;
}

input,
textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
}

input::placeholder,
textarea::placeholder { color: #8a978d; }

input:focus,
textarea:focus { border-color: var(--accent); }

.search input { flex: 1; }

.plant-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.plant-card {
  position: relative;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  transition: border-color .16s ease, box-shadow .16s ease, transform .16s ease;
}

.plant-card:hover {
  border-color: #b7c8b9;
  box-shadow: 0 16px 32px rgb(28 40 32 / 12%);
  transform: translateY(-3px);
}

.plant-card a { text-decoration: none; }

.plant-card > a {
  display: grid;
  grid-template-columns: 132px 1fr;
  height: 100%;
}

.plant-card a:hover .plant-card-body h2 { color: var(--accent-dark); }

.winter-card-icon {
  position: absolute;
  right: 10px;
  bottom: 10px;
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border: 1px solid currentColor;
  border-radius: 50%;
  background: var(--surface);
  pointer-events: none;
}

.winter-card-icon svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.winter-card-icon.warning { color: #a23e37; background: #fff0ee; }
.winter-card-icon.ready { color: #287144; background: #eef8ef; }
.winter-card-icon.attention { color: #8a6814; background: #fff9df; }

:root[data-theme="dark"] .winter-card-icon.warning { color: #ffc0b3; background: #4a2926; }
:root[data-theme="dark"] .winter-card-icon.ready { color: #b8e8c2; background: #263f2d; }
:root[data-theme="dark"] .winter-card-icon.attention { color: #f3dc95; background: #453b1f; }

.plant-card img,
.photo-placeholder {
  width: 100%;
  height: 132px;
  object-fit: cover;
  background: #dfe8d8;
}

:root[data-theme="dark"] .photo-placeholder { background: #334238; }

.photo-placeholder {
  display: grid;
  place-items: center;
  color: var(--muted);
  font-weight: 750;
}

.plant-card-body { padding: 16px; }
.plant-card-body h2 { margin: 0 0 4px; font-size: 1.1rem; }
.plant-card-body p { margin-bottom: 10px; }
.plant-card-body span { color: var(--accent); font-weight: 750; }

.detail {
  display: grid;
  grid-template-columns: minmax(260px, 420px) 1fr;
  gap: 28px;
  padding: 24px;
}

.detail-main { min-width: 0; }

.winter-plan {
  margin: 24px 0;
  padding: 18px;
  border: 1px solid var(--line);
  border-left: 4px solid #6aa978;
  border-radius: 8px;
  background: #edf7ef;
}

.winter-plan.warning { border-left-color: #c65b52; background: #fff0ed; }
.winter-plan.attention { border-left-color: #c59d32; background: #fff9e5; }

.winter-plan h2 { margin: 0 0 4px; }
.winter-plan p { margin-bottom: 10px; }
.winter-plan p:last-child { margin-bottom: 0; }

.winter-plan-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.winter-plan-heading p { margin: 0; font-size: .9rem; }

.winter-status {
  display: inline-flex;
  flex: 0 0 auto;
  padding: 6px 9px;
  border-radius: 999px;
  font-size: .78rem;
  line-height: 1.2;
  text-align: right;
}

.winter-status.warning { background: #f8d7cf; color: #743027; }
.winter-status.ready { background: #d7eddc; color: #245b37; }
.winter-status.attention { background: #f4e8bc; color: #674f12; }

:root[data-theme="dark"] .winter-status.warning { background: #5a302b; color: #ffc0b3; }
:root[data-theme="dark"] .winter-status.ready { background: #2b5036; color: #c6f1cf; }
:root[data-theme="dark"] .winter-status.attention { background: #514622; color: #f3dc95; }
:root[data-theme="dark"] .winter-plan { border-left-color: #79bd88; background: #24352a; }
:root[data-theme="dark"] .winter-plan.warning { border-left-color: #e47865; background: #3b2926; }
:root[data-theme="dark"] .winter-plan.attention { border-left-color: #d6b44f; background: #3d3722; }

.detail-photo img {
  width: 100%;
  border-radius: 8px;
  object-fit: cover;
  box-shadow: 0 8px 20px rgb(28 40 32 / 10%);
}

.photo-credit {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: .82rem;
}

.detail-header {
  display: flex;
  justify-content: space-between;
  gap: 20px;
}

.detail-actions {
  display: flex;
  flex-wrap: nowrap;
  gap: 10px;
  align-items: center;
  justify-content: flex-start;
  margin-top: 16px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: thin;
}

.detail-actions .button,
.detail-actions form,
.detail-actions button { flex: 0 0 auto; }

.detail-actions form { margin: 0; }

.facts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin: 20px 0;
}

.facts div {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
}

.gallery figure {
  margin: 0;
}

.gallery img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--line);
}

.gallery figcaption {
  margin-top: 6px;
  color: var(--muted);
  font-size: .85rem;
}

dt {
  color: var(--muted);
  font-size: .8rem;
  font-weight: 800;
  text-transform: uppercase;
}

dd { margin: 4px 0 0; }

.form-panel,
.auth-panel { padding: 28px; }

.form-panel { max-width: 760px; margin: 0 auto; }

.auth-panel { max-width: 520px; margin: 10vh auto 0; }

.auth-panel .button { width: 100%; }

.form-panel p { color: var(--ink); }

.form-panel form p { margin-bottom: 18px; }

.form-panel label {
  display: block;
  margin-bottom: 6px;
  color: var(--ink);
  font-size: .9rem;
  font-weight: 750;
}

.form-panel .helptext {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: .85rem;
}

input[type="file"] { padding: 8px; }

.actions {
  display: flex;
  gap: 12px;
  margin-top: 18px;
}

.messages p {
  padding: 12px 14px;
  border-radius: 8px;
  background: #e2f3e8;
  color: #1b4332;
}

:root[data-theme="dark"] .messages p {
  background: #294236;
  color: #d6f0dc;
}

.setup-warning {
  margin-top: 18px;
  padding: 14px;
  border: 1px solid #e0b45c;
  border-radius: 8px;
  background: #fff5db;
  color: #5f4100;
}

:root[data-theme="dark"] .setup-warning {
  border-color: #8d7540;
  background: #3b3425;
  color: #f1dca0;
}

.setup-warning a { color: #6f2f26; font-weight: 750; }

.setup-warning p {
  margin: 6px 0 0;
  color: #6f5315;
}

.source,
.empty,
.version {
  color: var(--muted);
}

.eyebrow,
.candidate-source {
  margin-bottom: 6px;
  color: var(--accent-dark);
  font-size: .78rem;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.lookup-confirmation {
  padding: 12px 14px;
  border-left: 4px solid var(--accent);
  background: var(--accent-soft);
}

.candidate-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.candidate-card {
  display: grid;
  grid-template-columns: 128px 1fr;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.candidate-card img {
  width: 100%;
  height: 128px;
  object-fit: cover;
  background: #dfe8d8;
}

.candidate-media { height: 128px; }
.candidate-placeholder { display: grid; place-items: center; color: var(--muted); font-size: .82rem; font-weight: 750; background: #dfe8d8; }
:root[data-theme="dark"] .candidate-placeholder { background: #334238; }
.candidate-body { padding: 18px; }
.candidate-body h2 { margin: 0 0 6px; font-size: 1.2rem; }
.candidate-body p { margin-bottom: 8px; }
.candidate-body .actions { margin-top: 16px; }

.photo-search-link { margin: -8px 0 20px; }
.photo-upload { display: grid; gap: 10px; max-width: 520px; margin: 20px 0 28px; }
.photo-upload input { padding: 10px; font-size: 1rem; }
.photo-upload-hint { color: var(--muted); font-size: .9rem; }
.photo-results-heading { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin: 24px 0 16px; }
.photo-results-heading h2 { margin: 0 0 4px; }
.photo-results-heading p { margin: 0; }
.photo-search-workspace { display: grid; grid-template-columns: minmax(140px, 190px) minmax(0, 1fr); gap: 24px; align-items: start; }
.photo-search-original { width: 192px; max-width: 192px; aspect-ratio: 4 / 5; object-fit: cover; justify-self: start; border-radius: 8px; border: 1px solid var(--line); }
.photo-candidate-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.photo-candidate { position: relative; padding: 18px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.photo-candidate img { width: 100%; height: 120px; object-fit: cover; margin: -2px 0 12px; border-radius: 6px; }
.photo-candidate h3 { margin: 28px 0 6px; font-size: 1.18rem; line-height: 1.2; }
.photo-candidate img + h3 { margin-top: 0; }
.photo-candidate p { margin-bottom: 10px; font-size: .98rem; line-height: 1.45; }
.photo-candidate .source { font-weight: 700; color: var(--accent); }
.photo-candidate .photo-credit { margin: -6px 0 10px; color: var(--muted); font-size: .72rem; line-height: 1.3; }
.compare-toggle { position: absolute; top: 12px; right: 12px; display: flex; gap: 6px; align-items: center; font-size: .78rem; color: var(--muted); }
.compare-toggle input { width: auto; min-height: 0; }
.photo-result-actions { display: flex; gap: 10px; margin-top: 16px; }
.compare-note { margin-top: 10px; }
.compare-panel { grid-column: 1 / -1; margin-top: 4px; padding: 16px; border-top: 1px solid var(--line); }
.compare-panel h3 { margin: 0 0 12px; }
.compare-panel > div { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.compare-item { padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.compare-item p { margin: 6px 0 0; }

.identity-preview {
  display: block;
  width: min(240px, 100%);
  aspect-ratio: 4 / 3;
  object-fit: cover;
  margin: 20px 0;
  border-radius: 8px;
}

.version {
  padding: 18px;
  text-align: center;
  font-size: .85rem;
}

@media (max-width: 760px) {
  .topbar,
  .detail-header,
  .search {
    align-items: stretch;
  }

  .search.plant-search { width: 100%; }

  .shell { width: min(100% - 24px, 680px); padding-top: 0; }
  .page-heading,
  .detail,
  .form-panel,
  .auth-panel { padding: 20px; }
  .detail { grid-template-columns: 1fr; }
  .photo-search-workspace { grid-template-columns: 1fr; }
  .photo-search-original { width: 144px; max-width: 144px; }
  .photo-results-heading { align-items: stretch; flex-direction: column; }
  .photo-candidate-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .compare-panel > div { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .plant-grid,
  .candidate-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .plant-card > a,
  .candidate-card { display: block; }
  .plant-card img,
  .plant-card .photo-placeholder,
  .candidate-card img,
  .candidate-media { height: 112px; }
  .plant-card-body,
  .candidate-body { padding: 12px; }
  .plant-card-body h2,
  .candidate-body h2 { font-size: 1rem; }
  .candidate-body .actions { gap: 8px; }
  .candidate-body .button { width: 100%; padding: 0 8px; font-size: .78rem; }
  .winter-plan-heading { flex-direction: column; }
  .winter-status { text-align: left; }
  .actions { flex-direction: column; }
  .actions .button,
  .actions button { width: 100%; }
}
