:root {
  --accent: #d9333f;          /* vermillion */
  --accent-dark: #a8232d;
  --ink: #2b2b2b;
  --paper: #faf7f2;
  --line: #e4ddd2;
  --muted: #8a8378;
  /* month colors (Jan..Dec) */
  --m1: #5b7fd4; --m2: #4aa3c7; --m3: #58b88a; --m4: #e58bb1;
  --m5: #7cb84f; --m6: #4fb8ab; --m7: #e8a23d; --m8: #e0633c;
  --m9: #c98a4b; --m10: #b06fc4; --m11: #8a6e51; --m12: #6a7fa0;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: "Hiragino Sans", "Noto Sans JP", -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--paper);
}

body { display: flex; flex-direction: column; }

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 10px 18px;
  background: #fff;
  border-bottom: 3px solid var(--accent);
}

.title h1 {
  margin: 0;
  font-size: 22px;
  color: var(--accent);
  letter-spacing: 1px;
}

.subtitle { font-size: 12px; color: var(--muted); }

.controls { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.view-toggle { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.view-toggle button {
  border: none; background: #fff; padding: 7px 14px;
  font-size: 14px; cursor: pointer; color: var(--ink);
}
.view-toggle button.active { background: var(--accent); color: #fff; }

#search, #score-filter {
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 14px;
  background: #fff;
}
#search { width: 220px; }

#month-bar[hidden] { display: none; }
#month-bar {
  display: flex;
  gap: 4px;
  padding: 8px 18px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}
#month-bar button {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}
#month-bar button.active {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}
#month-bar button .dot {
  display: inline-block; width: 8px; height: 8px;
  border-radius: 50%; margin-right: 5px; vertical-align: 1px;
}

main { flex: 1; position: relative; min-height: 0; }

#map-view, #map { height: 100%; }

/* ---------- calendar ---------- */
#calendar-view {
  height: 100%;
  overflow-y: auto;
  padding: 14px 18px 30px;
}

.cal-header {
  display: flex; align-items: center; justify-content: center; gap: 16px;
  margin-bottom: 10px;
}
.cal-header h2 { margin: 0; font-size: 20px; min-width: 200px; text-align: center; }
.cal-header button {
  border: 1px solid var(--line); background: #fff; border-radius: 8px;
  font-size: 20px; width: 36px; height: 36px; cursor: pointer;
}
.cal-header button:hover { background: var(--paper); }

#cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
}
.cal-dow {
  text-align: center; font-size: 12px; font-weight: 600;
  color: var(--muted); padding: 4px 0;
}
.cal-cell {
  min-height: 86px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 4px;
  font-size: 12px;
  background: #fffdf9;
  overflow: hidden;
}
.cal-cell.other { background: #f4f0e9; opacity: .55; }
.cal-cell.today { border: 2px solid var(--accent); }
.cal-cell .daynum { font-weight: 600; color: var(--muted); }
.cal-cell.today .daynum { color: var(--accent); }

.chip {
  display: block;
  margin-top: 3px;
  padding: 2px 6px;
  border-radius: 5px;
  color: #fff;
  font-size: 11px;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  border: none;
  width: 100%;
  text-align: left;
}
.chip:hover { filter: brightness(.9); }

#month-list { margin-top: 18px; }
#month-list h3 { margin: 0 0 8px; font-size: 15px; color: var(--muted); }
.fest-row {
  display: flex; align-items: baseline; gap: 10px;
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
  padding: 9px 12px; margin-bottom: 6px; cursor: pointer;
}
.fest-row:hover { border-color: var(--accent); }
.fest-row .dates { font-size: 12px; color: var(--muted); min-width: 110px; }
.fest-row .name { font-weight: 600; }
.fest-row .place { font-size: 12px; color: var(--muted); }

.score-badge {
  font-size: 11px; font-weight: 700;
  color: #fff; background: var(--accent);
  border-radius: 999px; padding: 2px 8px;
  margin-left: auto; white-space: nowrap;
}
.score-badge.s-mid { background: #c98a4b; }
.score-badge.s-low { background: #9aa0a6; }

/* ---------- year view ---------- */
#year-view {
  height: 100%;
  overflow-y: auto;
  padding: 14px 18px 30px;
}
#year-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
  gap: 12px;
}
.year-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.year-body {
  overflow-y: auto;
  max-height: 176px;   /* ~6 rows; the rest scrolls */
  scrollbar-width: thin;
}
.year-card h3 {
  margin: 0 0 8px;
  font-size: 15px;
  border-bottom: 3px solid;
  padding-bottom: 5px;
}
.year-card h3 .dot {
  display: inline-block; width: 10px; height: 10px;
  border-radius: 50%; margin-right: 6px;
}
.year-card h3 .count { float: right; color: var(--muted); font-weight: 400; font-size: 13px; }
.year-row {
  display: flex; align-items: baseline; gap: 8px;
  padding: 5px 4px;
  border-radius: 7px;
  font-size: 13px;
  cursor: pointer;
}
.year-row:hover { background: var(--paper); }
.year-row .dates { color: var(--muted); font-size: 11.5px; min-width: 86px; white-space: nowrap; }
.year-row .name {
  font-weight: 600; flex: 1 1 auto; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.year-row .place {
  color: var(--muted); font-size: 11.5px; white-space: nowrap;
  max-width: 9em; overflow: hidden; text-overflow: ellipsis;
}
.year-row .score-badge { margin-left: 0; }
.year-empty { color: var(--muted); font-size: 12.5px; padding: 4px; }

/* ---------- detail panel ---------- */
#detail {
  position: absolute;
  top: 110px; right: 16px;
  width: 340px; max-width: calc(100vw - 32px);
  max-height: calc(100% - 180px);
  overflow-y: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-top: 4px solid var(--accent);
  border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0,0,0,.18);
  padding: 16px;
  z-index: 1000;
}
#detail-close {
  position: absolute; top: 8px; right: 8px;
  border: none; background: none; font-size: 15px; cursor: pointer; color: var(--muted);
}
#detail .photo {
  width: calc(100% + 32px);
  margin: -16px -16px 8px;
  display: block;
  max-height: 210px;
  object-fit: cover;
  border-radius: 8px 8px 0 0;
}
#detail .photo-credit { font-size: 10px; color: var(--muted); margin: -6px 0 8px; }
#detail h2 { margin: 0 0 2px; font-size: 19px; }
#detail .ja { color: var(--muted); margin-bottom: 8px; }
#detail .meta { font-size: 13px; margin: 4px 0; }
#detail .meta b { color: var(--accent-dark); }
#detail .meta .ok { color: #2c7a3f; font-size: 12px; }
#detail p.desc { font-size: 14px; line-height: 1.55; }
#detail .note {
  font-size: 12.5px; background: #fdf3e3; border: 1px solid #f0ddb8;
  border-radius: 8px; padding: 7px 9px; margin: 8px 0;
}
#detail .tags { margin: 8px 0; }
#detail .tag {
  display: inline-block; font-size: 11px; background: var(--paper);
  border: 1px solid var(--line); border-radius: 999px;
  padding: 2px 8px; margin: 0 4px 4px 0; color: var(--muted);
}
#detail .links a {
  font-size: 13px; color: var(--accent-dark); margin-right: 12px;
}

/* leaflet popup tweaks */
.leaflet-popup-content { font-family: inherit; }
.popup-name { font-weight: 700; font-size: 14px; }
.popup-dates { font-size: 12px; color: #666; margin: 2px 0; }
.popup-more { font-size: 12.5px; color: var(--accent-dark); cursor: pointer; text-decoration: underline; }

footer {
  padding: 6px 18px;
  font-size: 11.5px;
  color: var(--muted);
  background: #fff;
  border-top: 1px solid var(--line);
}

@media (max-width: 700px) {
  header { padding: 8px 10px; gap: 8px; }
  .title h1 { font-size: 18px; }
  .subtitle { display: none; }
  .controls { width: 100%; }
  #search { flex: 1; width: auto; min-width: 0; }
  .view-toggle button { padding: 7px 10px; font-size: 13px; }
  #month-bar { padding: 6px 10px; }

  #calendar-view, #year-view { padding: 10px 8px 24px; }
  #cal-grid { gap: 2px; padding: 6px; }
  .cal-cell { min-height: 52px; padding: 2px; }
  .cal-cell .daynum { font-size: 10px; }
  /* chips collapse to tappable color bars; the ranked list below has the names */
  .chip {
    height: 8px;
    padding: 0;
    margin-top: 2px;
    font-size: 0;
    border-radius: 3px;
  }
  .fest-row { flex-wrap: wrap; gap: 4px 10px; }
  .fest-row .dates { min-width: 0; }

  #year-grid { grid-template-columns: minmax(0, 1fr); }
  .year-row .place { display: none; } /* name + score matter most; city is in the detail panel */
  .year-body { max-height: none; overflow: visible; } /* page scrolls instead */

  #detail {
    top: auto; right: 8px; left: 8px; bottom: 8px;
    width: auto; max-height: 62vh;
    border-radius: 14px;
  }

  footer { font-size: 10px; padding: 5px 10px; }
}
