:root {
  --ink: #19352b;
  --muted: #60746b;
  --paper: #f7f8f3;
  --card: #ffffff;
  --line: #dce5dd;
  --forest: #236347;
  --leaf: #8ca84b;
  --shadow: 0 12px 32px rgba(25, 53, 43, 0.08);
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 16px/1.55 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
a { color: inherit; }
.site-header { min-height: calc(64px + env(safe-area-inset-top)); padding: env(safe-area-inset-top) 5vw 0; display: flex; align-items: center; justify-content: space-between; background: #fff; border-bottom: 1px solid var(--line); }
.brand { color: var(--forest); font-size: 1.1rem; font-weight: 800; text-decoration: none; letter-spacing: -0.02em; }
.read-only, .back-link, .header-action { color: var(--muted); font-size: 0.9rem; }
.back-link, .header-action { text-decoration: none; font-weight: 700; }
.header-action { min-height: 44px; display: inline-flex; align-items: center; }
.page-shell { width: min(1160px, 100% - 32px); margin: 0 auto; padding: 36px 0 64px; }
.hero { max-width: 720px; padding: 18px 0 24px; }
.eyebrow { margin: 0 0 8px; color: var(--forest); font-size: 0.82rem; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 8px; font-size: clamp(2rem, 7vw, 3.8rem); line-height: 1; letter-spacing: -0.055em; }
h2 { margin-bottom: 12px; font-size: 1.35rem; letter-spacing: -0.025em; }
.hero p:not(.eyebrow) { color: var(--muted); max-width: 570px; }
.stats-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 26px; }
.stat-card, .control-panel, .species-card, .detail-card, .observation-card, .empty-state { background: var(--card); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); }
.stat-card { min-height: 105px; padding: 18px; display: flex; flex-direction: column; justify-content: space-between; }
.stat-card span { color: var(--muted); font-size: 0.85rem; font-weight: 700; }
.stat-card strong { color: var(--forest); font-size: 2rem; line-height: 1; }
.control-panel { padding: 18px; margin-bottom: 32px; }
label { display: block; color: var(--ink); font-size: 0.84rem; font-weight: 800; }
input, select, textarea, button { min-height: 46px; border-radius: 10px; font: inherit; }
input, select, textarea { width: 100%; margin-top: 6px; padding: 9px 12px; color: var(--ink); border: 1px solid #becfc1; background: #fff; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 3px solid rgba(140, 168, 75, 0.35); border-color: var(--leaf); }
.search-group label { font-size: 1rem; }
.search-group input { min-height: 54px; font-size: 1rem; }
.filter-grid { display: grid; grid-template-columns: 1fr; gap: 14px; margin-top: 16px; }
.control-actions { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-top: 18px; }
button { padding: 0 16px; color: var(--forest); border: 1px solid var(--forest); background: #fff; font-weight: 800; cursor: pointer; }
button:hover { background: #edf5ef; }
button:disabled { cursor: wait; opacity: 0.72; }
#result-summary { margin: 0; color: var(--muted); font-size: 0.9rem; }
.section-heading { display: flex; justify-content: space-between; align-items: baseline; }
.species-grid { display: grid; grid-template-columns: 1fr; gap: 18px; }
.species-card { overflow: hidden; transition: transform 160ms ease, box-shadow 160ms ease; }
.species-card:hover { transform: translateY(-2px); box-shadow: 0 16px 36px rgba(25, 53, 43, 0.13); }
.species-card a { display: block; height: 100%; text-decoration: none; }
.card-photo, .photo-placeholder { display: block; width: 100%; height: 190px; object-fit: cover; background: linear-gradient(135deg, #dbe8d7, #f2f4e8); }
.photo-placeholder { display: grid; place-items: center; color: var(--forest); font-size: 2rem; }
.card-content { padding: 18px; }
.card-content h3 { margin: 0 0 4px; font-size: 1.25rem; }
.scientific { color: var(--forest); font-style: italic; }
.english, .meta { color: var(--muted); }
.card-footer { margin-top: 14px; display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.confidence { display: inline-flex; align-items: center; min-height: 28px; padding: 3px 9px; border-radius: 99px; font-size: 0.8rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.04em; }
.confidence-high { background: #dff3e5; color: #17663a; }
.confidence-medium { background: #fff0c9; color: #765300; }
.confidence-low { background: #f8dfe1; color: #8a2630; }
.observation-count { color: var(--muted); font-size: 0.86rem; font-weight: 700; }
.empty-state { padding: 34px 22px; text-align: center; color: var(--muted); }
.detail-shell { max-width: 960px; }
.detail-heading { padding: 18px 0 24px; }
.detail-heading h1 { margin-bottom: 10px; }
.detail-grid { display: grid; gap: 18px; }
.detail-card { padding: 20px; }
.data-list { display: grid; grid-template-columns: 1fr; gap: 13px; margin: 0; }
.data-list div { padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.data-list div:last-child { border-bottom: 0; padding-bottom: 0; }
.data-list dt { color: var(--muted); font-size: 0.8rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.06em; }
.data-list dd { margin: 3px 0 0; overflow-wrap: anywhere; }
.characteristics { display: grid; grid-template-columns: 1fr; gap: 13px; }
.characteristic { padding: 13px; background: #f6f8f2; border-radius: 12px; }
.characteristic h3 { margin-bottom: 5px; font-size: 0.95rem; }
.characteristic p { margin: 0; color: #42584c; }
.observation-grid { display: grid; grid-template-columns: 1fr; gap: 16px; }
.observation-card { overflow: hidden; }
.observation-body { padding: 16px; }
.observation-body h3 { margin-bottom: 7px; color: var(--forest); }
.observation-body p { margin-bottom: 6px; }
.observation-body p:last-child { margin-bottom: 0; }
.error-state { padding: 32px 0; }
.primary-action, .secondary-action { display: inline-flex; align-items: center; justify-content: center; min-height: 46px; padding: 10px 16px; border-radius: 10px; font-weight: 800; text-decoration: none; cursor: pointer; }
.primary-action { color: #fff; border: 1px solid var(--forest); background: var(--forest); }
.primary-action:hover { background: #174c36; }
.secondary-action { color: var(--forest); border: 1px solid var(--forest); background: #fff; }
.dashboard-action { margin-top: 8px; }
.form-shell { max-width: 820px; }
.intro, .field-hint { color: var(--muted); }
.entry-form { display: grid; gap: 18px; }
.form-section, .review-card { padding: 20px; background: var(--card); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); }
.form-section h2, .review-card h2 { margin-bottom: 12px; }
.form-grid { display: grid; grid-template-columns: 1fr; gap: 14px; margin-bottom: 14px; }
.optional { color: var(--muted); font-weight: 600; }
.full-width { width: 100%; }
.button-row { display: flex; flex-direction: column-reverse; gap: 12px; margin-top: 20px; }
.button-row > * { width: 100%; }
.review-layout { display: grid; grid-template-columns: 1fr; gap: 18px; margin: 20px 0; }
.preview-image { display: block; width: 100%; max-height: 460px; object-fit: contain; border: 1px solid var(--line); border-radius: 18px; background: #e8eee6; }
.status { padding: 14px 16px; border-radius: 12px; }
.status.existing { background: #fff0c9; color: #765300; }
.status.new { background: #dff3e5; color: #17663a; }
.local-photo-preview { margin-top: 14px; }
.connection-status, .install-hint { position: fixed; left: 16px; right: 16px; z-index: 10; padding: 12px 14px; border-radius: 12px; box-shadow: var(--shadow); font-weight: 700; }
.connection-status { top: calc(12px + env(safe-area-inset-top)); background: #f8dfe1; color: #8a2630; }
.install-hint { top: calc(12px + env(safe-area-inset-top)); display: flex; gap: 10px; align-items: center; justify-content: space-between; background: #fff0c9; color: #765300; }
.install-hint button { min-height: 36px; padding: 4px 9px; color: #765300; border-color: #765300; background: transparent; font-size: 0.8rem; }
.mobile-nav { display: none; }

@media (min-width: 640px) {
  .page-shell { width: min(1160px, 100% - 48px); padding-top: 48px; }
  .stats-grid { grid-template-columns: repeat(4, 1fr); }
  .filter-grid { grid-template-columns: repeat(2, 1fr); }
  .form-grid { grid-template-columns: repeat(2, 1fr); }
  .button-row { flex-direction: row; justify-content: flex-end; }
  .button-row > * { width: auto; }
  .species-grid { grid-template-columns: repeat(2, 1fr); }
  .data-list { grid-template-columns: repeat(2, 1fr); column-gap: 28px; }
  .characteristics { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 639px) {
  body.has-mobile-nav { padding-bottom: calc(72px + env(safe-area-inset-bottom)); }
  .mobile-nav { position: fixed; right: 0; bottom: 0; left: 0; z-index: 8; display: grid; grid-template-columns: repeat(2, 1fr); min-height: calc(64px + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); background: rgba(255, 255, 255, 0.96); border-top: 1px solid var(--line); box-shadow: 0 -6px 20px rgba(25, 53, 43, 0.08); backdrop-filter: blur(10px); }
  .mobile-nav a { display: flex; min-height: 60px; align-items: center; justify-content: center; gap: 7px; color: var(--muted); font-size: 1.05rem; font-weight: 800; text-decoration: none; }
  .mobile-nav a span { font-size: 0.82rem; }
  .mobile-nav a.active { color: var(--forest); background: #edf5ef; }
}

@media (min-width: 960px) {
  .species-grid { grid-template-columns: repeat(3, 1fr); }
  .observation-grid { grid-template-columns: repeat(2, 1fr); }
  .review-layout { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; }
}
