:root {
  --green: #1e7d32;
  --green-dark: #14591f;
  --green-light: #e8f5e9;
  --gold: #c98a1e;
  --purple: #7b3fb0;
  --blue: #1f6fb2;
  --ink: #1c2321;
  --muted: #6b7770;
  --bg: #f6f8f5;
  --card-bg: #ffffff;
  --border: #e1e6df;
  --danger: #b3261e;
  --radius: 12px;
  --topbar-h: 56px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }

#app {
  min-height: 100vh; /* fallback for browsers without dvh support */
  min-height: 100dvh; /* tracks the *actual* visible area as Safari's chrome shows/hides */
}

/* Top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--green);
  color: white;
  height: var(--topbar-h);
}
.topbar-inner {
  max-width: 1100px;
  margin: 0 auto;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
}
.logo { font-weight: 700; font-size: 1.1rem; }
.desktop-nav { display: none; gap: 4px; }
.desktop-nav a {
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 0.92rem;
  opacity: 0.9;
}
.desktop-nav a.active, .desktop-nav a:hover { background: rgba(255,255,255,0.15); opacity: 1; }

/* Hamburger button (mobile) */
.hamburger-btn {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 4px;
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  cursor: pointer;
  padding: 0;
}
.hamburger-btn span {
  display: block;
  width: 22px;
  height: 2px;
  background: white;
  border-radius: 2px;
  transition: transform 0.2s ease, opacity 0.2s ease;
}
.hamburger-btn[aria-expanded="true"] span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
.hamburger-btn[aria-expanded="true"] span:nth-child(2) { opacity: 0; }
.hamburger-btn[aria-expanded="true"] span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

/* Mobile menu (dropdown from top bar) */
.mobile-menu {
  display: none;
  flex-direction: column;
  background: var(--green-dark);
  padding: 6px 16px calc(10px + env(safe-area-inset-bottom));
}
.mobile-menu.open { display: flex; }
.mobile-menu a {
  color: white;
  padding: 12px 4px;
  font-size: 1rem;
  border-bottom: 1px solid rgba(255,255,255,0.12);
  display: flex;
  align-items: center;
  gap: 10px;
}
.mobile-menu a:last-child { border-bottom: none; }
.mobile-menu a.active { color: #cdeccf; font-weight: 600; }
.mobile-menu .icon { font-size: 1.1rem; }

@media (min-width: 860px) {
  .desktop-nav { display: flex; }
  .hamburger-btn { display: none; }
  .mobile-menu { display: none !important; }
}

/* View container */
.view {
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px;
}

/* Cards / stats */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}
@media (min-width: 640px) {
  .stat-grid { grid-template-columns: repeat(4, 1fr); }
}
.stat-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  text-align: center;
}
.stat-card .num { font-size: 1.7rem; font-weight: 700; color: var(--green); }
.stat-card .label { font-size: 0.78rem; color: var(--muted); margin-top: 2px; }

.section-title {
  font-size: 1.05rem;
  font-weight: 700;
  margin: 22px 0 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
}

/* Round / list item cards */
.round-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}
.round-card .main { flex: 1; min-width: 0; }
.round-card .course-name { font-weight: 600; }
.round-card .meta { font-size: 0.82rem; color: var(--muted); margin-top: 2px; }
.round-card .tags { margin-top: 6px; display: flex; gap: 6px; flex-wrap: wrap; }
.tag {
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--green-light);
  color: var(--green-dark);
}
.tag.gold { background: #fbeecb; color: #7a560f; }
.tag.private { background: #ece4fb; color: #4b2e91; }
.tag.resort { background: #fde2c8; color: #8a4a12; }
.website-link { font-size: 0.82rem; }
.round-card .actions { display: flex; gap: 6px; flex-shrink: 0; }
.round-card .source { font-size: 0.76rem; color: var(--muted); opacity: 0.8; margin-top: 2px; font-style: italic; }

.icon-btn {
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 1rem;
  padding: 4px 6px;
  border-radius: 6px;
  color: var(--muted);
}
.icon-btn:hover { background: var(--border); }

/* Toolbar / filters */
.toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.toolbar input, .toolbar select {
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  background: white;
}
.toolbar input[type="text"] { flex: 1; min-width: 140px; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 8px;
  border: none;
  background: var(--green);
  color: white;
  font-size: 0.9rem;
  cursor: pointer;
  font-weight: 600;
}
.btn:hover { background: var(--green-dark); }
.btn.secondary { background: white; color: var(--ink); border: 1px solid var(--border); }
.btn.danger { background: var(--danger); }
.btn.full { width: 100%; justify-content: center; }

.fab {
  position: fixed;
  right: 18px;
  bottom: calc(18px + env(safe-area-inset-bottom));
  width: 54px; height: 54px;
  border-radius: 50%;
  background: var(--green);
  color: white;
  font-size: 1.6rem;
  border: none;
  box-shadow: 0 4px 14px rgba(0,0,0,0.25);
  cursor: pointer;
  z-index: 40;
}

/* Map */
.map-container {
  width: 100%;
  height: calc(100dvh - var(--topbar-h) - 90px);
  min-height: 340px;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}
@media (min-width: 860px) {
  .map-container { height: calc(100dvh - var(--topbar-h) - 140px); }
}

/* Table (desktop) */
.data-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.data-table th, .data-table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.data-table th { color: var(--muted); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
}
@media (min-width: 640px) {
  .modal-overlay { align-items: center; }
}
.modal {
  background: white;
  border-radius: 16px 16px 0 0;
  width: 100%;
  max-width: 520px;
  max-height: 92vh;
  overflow-y: auto;
  padding: 20px;
}
@media (min-width: 640px) {
  .modal { border-radius: 16px; }
}
.modal h3 { margin-top: 0; }
.form-row { margin-bottom: 12px; display: flex; flex-direction: column; gap: 4px; }
.form-row label { font-size: 0.8rem; color: var(--muted); font-weight: 600; }
.form-row input, .form-row textarea, .form-row select {
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
  font-family: inherit;
}
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.form-actions { display: flex; gap: 8px; margin-top: 16px; }
.checkbox-row { flex-direction: row; align-items: center; gap: 8px; }
.checkbox-row label { font-size: 0.9rem; color: var(--ink); font-weight: 500; }

/* Toast */
#toast-root {
  position: fixed;
  bottom: calc(20px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
}
.toast {
  background: var(--ink);
  color: white;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.85rem;
  margin-bottom: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.25);
}
.toast.error { background: var(--danger); }

.empty-state { text-align: center; color: var(--muted); padding: 40px 10px; }

.progress-bar {
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
}
.progress-bar > div { height: 100%; background: var(--green); }

.ri-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--border); gap: 10px; }
.ri-row .name { font-weight: 600; font-size: 0.92rem; }
.ri-row .city { font-size: 0.78rem; color: var(--muted); }
.ri-toggle { display: flex; gap: 10px; font-size: 0.78rem; }
.ri-toggle button { border: 1px solid var(--border); background: white; border-radius: 999px; padding: 4px 10px; cursor: pointer; }
.ri-toggle button.on { background: var(--green-light); border-color: var(--green); color: var(--green-dark); font-weight: 600; }

.badge-played { background: var(--green-light); color: var(--green-dark); font-size: 0.7rem; padding: 2px 8px; border-radius: 999px; font-weight: 600; }

.course-marker { background: transparent; border: none; }
.leaflet-popup-content { font-size: 0.88rem; }
