:root {
  color-scheme: light dark;
  --bg: #f7f7f8;
  --surface: #ffffff;
  --text: #1a1a1a;
  --muted: #6b7280;
  --border: #e5e7eb;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app-header {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.header-top {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
}

.app-header h1 {
  grid-column: 1;
  justify-self: start;
  font-size: 1.25rem;
  margin: 0;
}

.year-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  font-size: 1.1rem;
  font-weight: 600;
}

.year-nav button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 6px;
  padding: 0;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
}

.year-nav button:hover {
  background: var(--bg);
}

.page-nav {
  grid-column: 2;
  display: flex;
  gap: 1rem;
}

.page-nav a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.25rem 0;
  border-bottom: 2px solid transparent;
}

.data-controls {
  grid-column: 3;
  justify-self: end;
  display: flex;
  gap: 0.5rem;
}

.data-controls button {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 6px;
  padding: 0.3rem 0.75rem;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.data-controls button:hover {
  background: var(--bg);
}

.page-nav a:hover {
  color: var(--text);
}

.page-nav a.active {
  color: var(--text);
  border-bottom-color: var(--text);
}

.sort-control {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
}

.sort-control-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}

.sort-control-options {
  display: flex;
  gap: 0.25rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.2rem;
}

.sort-option {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.3rem 0.85rem;
  border-radius: 999px;
  cursor: pointer;
}

.sort-option:hover {
  color: var(--text);
}

.sort-option.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem;
}

.legend {
  margin-bottom: 1.5rem;
}

.legend-list {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.5rem;
  margin: 0;
  padding: 0;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
}

.legend-swatch {
  width: 0.9rem;
  height: 0.9rem;
  border-radius: 3px;
  display: inline-block;
  flex-shrink: 0;
}

.legend-emoji {
  font-size: 1rem;
  line-height: 1;
}

.legend-empty {
  color: var(--muted);
  font-size: 0.9rem;
}

.months-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}

.month {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
}

.month-title {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
  text-align: center;
}

.month-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}

.weekday-label {
  font-size: 0.65rem;
  color: var(--muted);
  text-align: center;
  padding-bottom: 2px;
}

.day-cell {
  position: relative;
  aspect-ratio: 1;
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  border-radius: 3px;
  background: var(--bg);
}

.day-cell.empty {
  background: transparent;
}

.day-number {
  font-size: 0.6rem;
  padding: 2px 3px;
  color: var(--muted);
}

.day-cell.has-country .day-number {
  color: rgba(255, 255, 255, 0.9);
  text-shadow: 0 0 2px rgba(0, 0, 0, 0.5);
}

.calendar .day-cell:not(.empty) {
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}

.calendar .day-cell.trip-hover {
  outline: 2px solid color-mix(in srgb, var(--text) 35%, transparent);
  outline-offset: -1px;
}

.calendar .day-cell.selecting {
  outline: 2px solid var(--text);
  outline-offset: -1px;
}

.calendar .day-cell.selecting:not(.has-country) {
  background: color-mix(in srgb, var(--text) 12%, var(--bg));
}

.trip-popover {
  position: absolute;
  z-index: 9000;
  width: min(300px, calc(100vw - 32px));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  padding: 0.9rem 1rem;
  font-size: 0.9rem;
}

.trip-popover-title {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
}

.trip-form {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.trip-form .trip-popover-title {
  margin-bottom: 0.15rem;
}

.trip-field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 0;
  flex: 1;
}

.trip-field-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
}

.trip-field input {
  font: inherit;
  width: 100%;
  min-width: 0;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
}

.trip-field input:focus {
  outline: 2px solid var(--text);
  outline-offset: -1px;
}

.trip-field-row {
  display: flex;
  gap: 0.5rem;
}

.trip-form-error {
  margin: 0;
  font-size: 0.8rem;
  color: #dc2626;
}

.trip-form-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.25rem;
}

.trip-form-spacer {
  flex: 1;
}

.trip-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 6px;
  padding: 0.3rem 0.75rem;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

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

.trip-btn-primary {
  background: var(--text);
  border-color: var(--text);
  color: var(--surface);
}

.trip-btn-primary:hover {
  background: color-mix(in srgb, var(--text) 85%, var(--surface));
}

.trip-btn-danger {
  color: #dc2626;
}

.trip-link {
  align-self: flex-start;
  border: none;
  background: none;
  padding: 0;
  margin-top: 0.6rem;
  font: inherit;
  font-size: 0.8rem;
  color: var(--muted);
  cursor: pointer;
}

.trip-form .trip-link {
  margin-top: 0.15rem;
}

.trip-link:hover {
  color: var(--text);
  text-decoration: underline;
}

.trip-choice-list {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.trip-choice {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  text-align: left;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 6px;
  padding: 0.45rem 0.6rem;
  font: inherit;
  cursor: pointer;
}

.trip-choice:hover {
  background: var(--bg);
}

.trip-choice-text {
  display: flex;
  flex-direction: column;
}

.trip-choice-name {
  font-weight: 600;
}

.trip-choice-dates {
  font-size: 0.8rem;
  color: var(--muted);
}

.trip-toast {
  position: fixed;
  z-index: 9500;
  left: 50%;
  bottom: 1.25rem;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 1rem;
  max-width: calc(100vw - 32px);
  background: var(--text);
  color: var(--surface);
  font-size: 0.85rem;
  padding: 0.6rem 0.9rem;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}

.trip-toast[hidden] {
  display: none;
}

.trip-toast-undo {
  flex-shrink: 0;
  border: none;
  background: none;
  color: inherit;
  font: inherit;
  font-weight: 700;
  text-decoration: underline;
  cursor: pointer;
  padding: 0;
}

.overview-summary {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  padding: 0.5rem 0 0.25rem;
}

.overview-summary-count {
  font-size: 2.25rem;
  font-weight: 700;
  line-height: 1;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.overview-summary-label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.overview-progress {
  width: 100%;
  max-width: 360px;
  height: 8px;
  margin-top: 0.5rem;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}

.overview-progress-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #fb923c, #f97316);
  transition: width 0.4s ease;
}

.feed {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  max-width: 640px;
  margin: 0 auto;
}

.feed-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem 1.5rem;
}

.feed-card h2 {
  font-size: 1rem;
  margin: 0 0 0.75rem;
}

.feed-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.feed-card-header h2 {
  margin: 0;
}

.see-more-button {
  display: inline-block;
  margin-top: 0.75rem;
  color: var(--text);
  font-size: 0.9rem;
  text-decoration: none;
}

.see-more-button:hover {
  text-decoration: underline;
}

.top-list-items {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
}

.top-list-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border);
}

.top-list-item:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.top-list-item:first-child {
  padding-top: 0;
}

.top-list-rank {
  font-weight: 700;
  color: var(--muted);
  width: 1.25rem;
  flex-shrink: 0;
  text-align: center;
}

.top-list-emoji {
  font-size: 1.5rem;
  line-height: 1;
  flex-shrink: 0;
}

.top-list-link {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
  color: inherit;
  text-decoration: none;
}

.top-list-link:hover .top-list-title {
  text-decoration: underline;
}

.top-list-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.top-list-title {
  font-weight: 600;
}

.top-list-sub {
  font-size: 0.85rem;
  color: var(--muted);
}

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

.grouping-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.35rem;
}

.grouping-name {
  font-weight: 600;
}

.grouping-count {
  font-size: 0.85rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

.grouping-bar {
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}

.grouping-bar-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #fb923c, #f97316);
  transition: width 0.4s ease;
}

.busiest-day-date {
  font-weight: 600;
  font-size: 1.1rem;
}

.busiest-day-count {
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 0.15rem;
}

.busiest-day-flags {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-top: 0.75rem;
}

.busiest-day-flag {
  font-size: 2.5rem;
  line-height: 1;
  display: inline-block;
  text-decoration: none;
}

.fun-fact-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  color: inherit;
  text-decoration: none;
}

.fun-fact-header:hover .fun-fact-name {
  text-decoration: underline;
}

.fun-fact-emoji {
  font-size: 3rem;
  line-height: 1;
}

.fun-fact-header-spaced {
  margin-top: 1rem;
}

.fun-fact-main {
  display: flex;
  flex-direction: column;
}

.fun-fact-name {
  font-weight: 600;
  font-size: 1.1rem;
}

.recently-discovered-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
}

.recently-discovered-emoji {
  font-size: 2.5rem;
  line-height: 1;
  display: inline-block;
  text-decoration: none;
}

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

.years-row {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 1rem;
}

.years-year {
  font-size: 1.4rem;
  font-weight: 600;
  width: 4rem;
  flex-shrink: 0;
}

.years-flags {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  font-size: 1.8rem;
  line-height: 1;
}

.years-flag {
  display: inline-block;
  text-decoration: none;
}

.years-count {
  flex-shrink: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.countries-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 1rem;
}

.country-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 0.75rem;
  color: inherit;
  text-decoration: none;
}

.country-card:hover {
  border-color: var(--muted);
}

.country-card.has-color {
  background: color-mix(in srgb, var(--country-color) 35%, white);
}

.country-card.not-visited {
  background: none;
}

.country-card-flag {
  font-size: 2.75rem;
  line-height: 1;
}

.country-card-name {
  font-weight: 600;
  font-size: 1.1rem;
}

.country-card-days {
  font-size: 1rem;
  color: var(--text);
}

.country-card-trips {
  font-size: 0.9rem;
  color: var(--muted);
}

.country-card-first-visit {
  font-size: 0.85rem;
  color: var(--muted);
}

.back-link {
  display: inline-block;
  margin-bottom: 1.25rem;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 600;
}

.back-link:hover {
  color: var(--text);
}

.country-detail-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.35rem;
  margin-bottom: 1.5rem;
}

.country-detail-flag {
  font-size: 4rem;
  line-height: 1;
}

.country-detail-name {
  margin: 0;
  font-size: 1.5rem;
}

.country-stat-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.country-stat-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 0.75rem;
}

.country-stat-card-value {
  font-size: 1.75rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.country-stat-card-label {
  font-size: 0.85rem;
  color: var(--muted);
}

.country-trips-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
}

.country-trip-row {
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
}

.country-trip-button {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: calc(100% + 1rem);
  margin: -0.3rem -0.5rem;
  padding: 0.3rem 0.5rem;
  border: none;
  border-radius: 6px;
  background: none;
  color: inherit;
  font: inherit;
  font-variant-numeric: tabular-nums;
  text-align: left;
  cursor: pointer;
}

.country-trip-button::after {
  content: "Edit";
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  opacity: 0;
}

.country-trip-button:hover,
.country-trip-button:focus-visible {
  background: var(--bg);
}

.country-trip-button:hover::after,
.country-trip-button:focus-visible::after {
  opacity: 1;
}

.country-trip-row:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.country-trip-row:first-child {
  padding-top: 0;
}

.country-groupings-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.country-grouping-tag {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.3rem 0.75rem;
  font-size: 0.85rem;
}

.world-map {
  height: 70vh;
  min-height: 420px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #fefefe;
  color: var(--muted);
  font-size: 0.9rem;
}

.world-map.scheme-dark {
  background: #eef1f6;
}

.day-tooltip {
  position: fixed;
  z-index: 10000;
  pointer-events: none;
  background: var(--text);
  color: var(--surface);
  font-size: 0.8rem;
  line-height: 1.2;
  padding: 0.35rem 0.6rem;
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  white-space: nowrap;
}

/* Touch devices have no hover, so keep the "Edit" hint visible. */
@media (hover: none) {
  .country-trip-button::after {
    opacity: 1;
  }
}

@media (max-width: 720px) {
  .app-header {
    padding: 0.75rem 1rem;
  }

  /* Title and data controls share the first row; the page nav gets its own. */
  .header-top {
    grid-template-columns: 1fr auto;
    row-gap: 0.75rem;
  }

  .app-header h1 {
    font-size: 1.1rem;
  }

  .data-controls {
    grid-column: 2;
    grid-row: 1;
  }

  .page-nav {
    grid-column: 1 / -1;
    grid-row: 2;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .page-nav::-webkit-scrollbar {
    display: none;
  }

  .page-nav a {
    flex-shrink: 0;
  }

  .year-nav button {
    width: 2.5rem;
    height: 2.5rem;
  }

  .sort-control {
    flex-wrap: wrap;
  }

  main {
    padding: 1rem;
  }

  .feed-card {
    padding: 1rem;
  }

  .countries-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 0.75rem;
  }

  .country-stat-cards {
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 0.75rem;
  }

  .years-row {
    flex-wrap: wrap;
    gap: 0.5rem 1rem;
  }

  .years-year {
    width: auto;
  }

  .years-flags {
    order: 1;
    flex-basis: 100%;
  }

  .years-count {
    margin-left: auto;
  }

  .world-map {
    height: 60vh;
    min-height: 320px;
  }

  /* 16px inputs stop iOS Safari from zooming in on focus. */
  .trip-field input {
    font-size: 16px;
  }
}
