:root {
  --primary: #6a8a1e;
  --primary-light: #abc442;
  --primary-bg: #f2f7e4;
  --accent: #ef6c00;
  --accent-bg: #fff3e0;
  --danger: #d32f2f;
  --danger-bg: #ffebee;
  --text: #1a1a1a;
  --text-secondary: #5f6368;
  --bg: #f8f9fa;
  --card: #ffffff;
  --border: #e8eaed;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.06), 0 1px 3px rgba(0,0,0,0.1);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px rgba(0,0,0,0.1), 0 4px 6px rgba(0,0,0,0.05);
  --radius: 14px;
  --radius-sm: 10px;
  --radius-full: 100px;
  --bar-h: 36px;
  --label-w: 130px;
  --bar-inactive: rgba(0,0,0,0.06);
  --primary-glow: rgba(106,138,30,0.25);
}

[data-theme="dark"] {
  --primary: #abc442;
  --primary-light: #c5d96a;
  --primary-bg: #2a2e1a;
  --accent: #ffb74d;
  --accent-bg: #3e2c10;
  --danger: #ef5350;
  --danger-bg: #3e1a1a;
  --text: #e8e8e8;
  --text-secondary: #9e9e9e;
  --bg: #1a1a1a;
  --card: #252525;
  --border: #3a3a3a;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.2), 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.25), 0 2px 4px rgba(0,0,0,0.2);
  --shadow-lg: 0 10px 15px rgba(0,0,0,0.3), 0 4px 6px rgba(0,0,0,0.2);
  --bar-inactive: rgba(255,255,255,0.07);
  --primary-glow: rgba(171,196,66,0.35);
}
[data-theme="dark"] header {
  background: linear-gradient(135deg, #2a3a0a 0%, #3d5010 100%);
}
[data-theme="dark"] .timeline {
  background: #3a3a3a;
}
[data-theme="dark"] .tag {
  background: #1a2a3e;
  color: #64b5f6;
}
[data-theme="dark"] .sheet-handle {
  background: #555;
}
[data-theme="dark"] #search::placeholder {
  color: #666;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  padding-bottom: env(safe-area-inset-bottom);
  -webkit-font-smoothing: antialiased;
}

/* Header */
header {
  background: linear-gradient(135deg, #4a6b14 0%, var(--primary) 100%);
  color: #fff;
  padding: 20px 20px 16px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-md);
}
.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.header-logo {
  max-height: 40px;
  width: auto;
  border-radius: 6px;
}
.theme-toggle {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.3);
  background: rgba(255,255,255,0.1);
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .2s;
}
.view-toggle {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.3);
  background: rgba(255,255,255,0.1);
  color: rgba(255,255,255,0.9);
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.view-toggle:active { background: rgba(255,255,255,0.25); }
.theme-toggle::after { content: "🌙"; }
[data-theme="dark"] .theme-toggle::after { content: "☀️"; }
.theme-toggle:active { background: rgba(255,255,255,0.25); }
header h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.3px;
}
.date-info {
  font-size: 13px;
  opacity: .8;
  margin-top: 3px;
  font-weight: 500;
}

/* Toolbar (search + filters) */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 12px;
  background: var(--card);
  position: sticky;
  top: 78px;
  z-index: 99;
  border-bottom: 1px solid var(--border);
  align-items: center;
}
#search {
  flex: 1;
  min-width: 0;
  padding: 8px 12px;
  font-size: 15px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  -webkit-appearance: none;
  background: var(--bg);
  color: var(--text);
  transition: border-color .2s, background .2s, box-shadow .2s;
}
#search:focus {
  border-color: var(--primary-light);
  background: var(--card);
  box-shadow: 0 0 0 3px rgba(76, 175, 80, 0.15);
}
#search::placeholder { color: #9aa0a6; }
.filter-btns {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}
.filter-btn {
  padding: 6px 14px;
  border: 2px solid var(--border);
  border-radius: var(--radius-full);
  background: var(--card);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all .2s;
  white-space: nowrap;
}
.filter-btn:hover {
  border-color: var(--primary-light);
  color: var(--primary);
}
.filter-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* Count */
.count {
  padding: 8px 20px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

/* Bird list */
.bird-list { padding: 0 12px 80px; }
.bird-card {
  background: var(--card);
  border-radius: var(--radius);
  margin-bottom: 8px;
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: transform .12s, box-shadow .12s;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.bird-card:active {
  transform: scale(0.98);
  box-shadow: var(--shadow-md);
}
.bird-name {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.2px;
  color: var(--text);
}
.bird-sub {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 3px;
  font-weight: 500;
}

/* Badges */
.badge {
  padding: 5px 12px;
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  letter-spacing: 0.2px;
  text-transform: uppercase;
}
.badge-active {
  background: var(--primary-bg);
  color: var(--primary);
}
.badge-inactive {
  background: var(--danger-bg);
  color: var(--danger);
}

/* Detail overlay */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 200;
  display: none;
  justify-content: center;
  align-items: flex-end;
}
.overlay.open { display: flex; }

.detail-sheet {
  background: var(--card);
  width: 100%;
  max-width: 500px;
  max-height: 92vh;
  border-radius: 24px 24px 0 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  animation: slideUp .3s cubic-bezier(0.16, 1, 0.3, 1);
  padding-bottom: env(safe-area-inset-bottom);
}
@keyframes slideUp {
  from { transform: translateY(100%); opacity: 0.5; }
  to { transform: translateY(0); opacity: 1; }
}

.sheet-handle {
  width: 40px;
  height: 5px;
  background: #dadce0;
  border-radius: 3px;
  margin: 12px auto 4px;
}

.sheet-header {
  padding: 12px 24px 20px;
  border-bottom: 1px solid var(--border);
}
.sheet-header h2 {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: var(--text);
}
.bird-link {
  color: var(--primary-light);
  text-decoration: none;
  font-size: 0.7em;
  vertical-align: super;
}
.bird-link:active { opacity: 0.6; }
.sheet-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  padding: 6px 16px;
  border-radius: var(--radius-full);
  font-size: 14px;
  font-weight: 700;
}

.sheet-body { padding: 20px 24px 28px; }

/* Info grid */
.info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.info-item {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 14px;
}
.info-item.full { grid-column: 1 / -1; }
.info-label,
.date-bar-label,
.norm-table th {
  font-size: 11px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  font-weight: 700;
}
.info-value {
  font-size: 18px;
  font-weight: 700;
  margin-top: 4px;
  color: var(--text);
}
.info-value.small { font-size: 15px; }

/* Timeline / date bar */
.date-bar {
  margin-top: 16px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 16px;
}
.date-bar-label {
  margin-bottom: 12px;
}
.timeline {
  height: 10px;
  background: #e0e0e0;
  border-radius: 5px;
  position: relative;
  margin: 8px 0;
}
.timeline-fill {
  position: absolute;
  height: 100%;
  border-radius: 5px;
  background: linear-gradient(90deg, var(--primary-light), var(--primary));
}
.timeline-now {
  position: absolute;
  top: -5px;
  width: 4px;
  height: 20px;
  background: var(--accent);
  border-radius: 2px;
  transform: translateX(-2px);
  box-shadow: 0 0 0 2px var(--card);
}
.timeline-labels {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  font-weight: 600;
  margin-top: 8px;
  color: var(--text);
}

/* Tags */
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.tag {
  padding: 5px 12px;
  border-radius: var(--radius-full);
  font-size: 13px;
  font-weight: 600;
  background: #e3f2fd;
  color: #1565c0;
}
.tag.yes {
  background: var(--primary-bg);
  color: var(--primary);
}

/* Norm table */
.norm-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 10px;
}
.norm-table th, .norm-table td {
  padding: 10px 12px;
  text-align: center;
  font-size: 15px;
  border-bottom: 1px solid var(--border);
}
.norm-table th {}
.norm-table td {
  font-weight: 600;
}

/* Close button */
.close-btn {
  position: absolute;
  top: 14px;
  right: 18px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--bg);
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  color: var(--text-secondary);
  transition: background .15s;
}
.close-btn:hover { background: var(--border); }

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* View toggle */
#cardView { display: block; }
#timelineView { display: none; }
body.view-timeline #cardView { display: none; }
body.view-timeline #timelineView { display: flex; flex-direction: column; flex: 1; min-height: 0; }
body.view-timeline { overflow: hidden; height: 100vh; height: 100dvh; display: flex; flex-direction: column; }
body.view-timeline .gantt-scroll { min-height: 0; }

/* Timeline: month header */
.month-header {
  display: flex;
  height: 28px;
  flex-shrink: 0;
  z-index: 15;
  position: relative;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.month-label-spacer {
  width: var(--label-w);
  flex-shrink: 0;
  border-right: 1px solid var(--border);
}
.months-track {
  flex: 1;
  display: flex;
  position: relative;
  overflow: hidden;
}
.month-cell {
  flex: 1;
  text-align: center;
  font-size: 10px;
  font-weight: 700;
  color: var(--text-secondary);
  letter-spacing: 0.5px;
  line-height: 28px;
  border-right: 1px solid var(--border);
  text-transform: uppercase;
}
.month-cell.current {
  color: var(--accent);
  background: var(--accent-bg);
}

/* Timeline: scroll + rows */
.gantt-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  position: relative;
}
.bird-row {
  display: flex;
  height: var(--bar-h);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background .15s;
}
.bird-row:active { background: var(--primary-bg); }
.bird-label {
  width: var(--label-w);
  flex-shrink: 0;
  padding: 0 10px;
  display: flex;
  align-items: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  border-right: 1px solid var(--border);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.bird-label.inactive { color: var(--text-secondary); }
.bird-track {
  flex: 1;
  position: relative;
  overflow: hidden;
}
.bird-bar {
  position: absolute;
  top: 6px;
  height: calc(var(--bar-h) - 12px);
  border-radius: 6px;
  transition: opacity .2s;
}
.bird-bar.active {
  background: linear-gradient(90deg, var(--primary), var(--primary-light));
  box-shadow: 0 0 10px var(--primary-glow);
}
.bird-bar.not-active {
  background: var(--bar-inactive);
}

/* Timeline: now line */
.now-line {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--accent);
  box-shadow: 0 0 8px rgba(255,152,0,0.5);
  z-index: 10;
  pointer-events: none;
}
.now-line::before {
  content: 'NU';
  position: absolute;
  top: -22px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 9px;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: 1px;
}

@media (max-width: 420px) {
  :root { --label-w: 100px; --bar-h: 32px; }
  .bird-label { font-size: 11px; padding: 0 6px; }
  #search { flex: none; width: 100%; }
  .filter-btns { width: 100%; }
  .filter-btn { flex: 1; text-align: center; padding: 6px 8px; }
}
