:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --ink: #1c2733;
  --muted: #5c6b7a;
  --line: #dfe4ea;
  --accent: #0b6bcb;
  --good: #1a9850;
  --bad: #d73027;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(20, 30, 40, .08), 0 4px 14px rgba(20, 30, 40, .06);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font: 15px/1.45 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  padding-bottom: env(safe-area-inset-bottom);
}
h1 { font-size: 17px; margin: 0; }
h2 { font-size: 18px; margin: 0 0 4px; }
h3 .sub { display: inline; font-weight: 500; margin-left: 6px; }
a { color: var(--accent); }
button { font: inherit; cursor: pointer; }
.sub { color: var(--muted); font-size: 12.5px; margin: 2px 0 0; }

header {
  position: sticky; top: 0; z-index: 1200;
  background: linear-gradient(#ffffffee, #fffffffa);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line);
  padding: 10px 14px 0;
}
.brand { display: flex; flex-direction: column; }
.tabs { display: flex; gap: 6px; margin: 8px 0 0; }
.tab {
  border: 1px solid var(--line); background: #fff; color: var(--muted);
  border-radius: 999px; padding: 7px 14px; font-weight: 600; font-size: 13.5px;
}
.tab.active { background: var(--ink); color: #fff; border-color: var(--ink); }

#selector {
  position: sticky; top: 88px; z-index: 1100;
  background: var(--card); border-bottom: 1px solid var(--line);
  padding: 10px 14px 12px; box-shadow: var(--shadow);
}
.presets { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; scrollbar-width: none; }
.presets::-webkit-scrollbar { display: none; }
body.locked { overflow: hidden; }
.preset {
  flex: 0 0 auto; border: 1px solid var(--line); background: #fff;
  border-radius: 999px; padding: 5px 11px; font-size: 12.5px; font-weight: 600; color: var(--ink);
}
.preset.on { background: #e8f1fb; border-color: var(--accent); color: var(--accent); }
.weekgrid-wrap { width: 100%; }
.weekgrid {
  display: grid;
  grid-template-columns: 44px repeat(24, minmax(0, 1fr));
  gap: 2px; width: 100%;
  touch-action: pan-y;
  user-select: none;
}
.wg-corner { font-size: 10px; color: var(--muted); }
.wg-daylabel {
  font-size: 11px; font-weight: 700; color: var(--muted);
  display: flex; align-items: center; justify-content: flex-end; padding-right: 4px;
  border-radius: 6px;
}
.wg-daylabel.on { color: var(--accent); }
.wg-daylabel.bh { color: #7b4bd0; }
.wg-hourlabel { font-size: 9px; color: var(--muted); text-align: center; }
.wg-cell {
  height: 16px; border-radius: 3px; background: #edf0f4;
}
.wg-cell.on { background: var(--accent); }
.wg-cell.bhrow { background: #e6e0f5; }
.wg-cell.bhrow.on { background: #7b4bd0; }
.sel-info { font-size: 12px; color: var(--muted); margin-top: 7px; display: flex; justify-content: space-between; gap: 8px; }
.sel-info b { color: var(--ink); }

main { padding: 0 0 30px; }
.view { display: none; }
.view.active { display: block; }

#view-map { position: relative; }
.mapbar { padding: 10px 14px 6px; }
#road-jump {
  width: 100%; padding: 9px 10px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); font-size: 14px; color: var(--ink);
}
#map {
  height: calc(100dvh - 330px); min-height: 360px;
  margin: 0 10px; border-radius: var(--radius); box-shadow: var(--shadow);
  background: #e8ebee; z-index: 900;
}
.legend {
  display: flex; align-items: center; gap: 8px; justify-content: center;
  margin: 10px 14px 0; font-size: 11.5px; color: var(--muted);
}
.legend-bar { width: 130px; height: 10px; border-radius: 5px; background: linear-gradient(90deg, #1a9850, #a6d96a, #fee08b, #f46d43, #d73027); }

#view-best, #view-holidays { padding: 12px 14px; }
.scope-row { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 10px; }
.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 12px 14px; margin-bottom: 10px;
}
.card h3 { margin: 0 0 2px; font-size: 14.5px; }
.rank { display: flex; justify-content: space-between; align-items: baseline; padding: 6px 0; border-top: 1px dashed var(--line); font-variant-numeric: tabular-nums; }
.rank:first-of-type { border-top: none; }
.rank .when { font-weight: 700; }
.rank .idx { color: var(--muted); font-size: 12.5px; }
.badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; margin-left: 6px; }
.badge.good { background: #e3f4e9; color: var(--good); }
.badge.bad { background: #fdebe9; color: var(--bad); }
.sect-label { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; margin: 10px 0 2px; }

.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 1400;
  background: var(--card); border-radius: 18px 18px 0 0; box-shadow: 0 -6px 30px rgba(0,0,0,.18);
  padding: 8px 16px calc(14px + env(safe-area-inset-bottom));
  max-height: 78vh; overflow-y: auto; overscroll-behavior: contain;
  transform: translateY(100%); transition: transform .25s ease;
}
.sheet.open { transform: translateY(0); }
.sheet-grip { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 4px auto 8px; }
.sheet-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
#sheet-close { border: none; background: #eef1f5; border-radius: 999px; width: 30px; height: 30px; color: var(--muted); }
.chips { display: flex; gap: 6px; overflow-x: auto; margin: 10px 0 6px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; border: 1px solid var(--line); background: #fff; border-radius: 999px;
  padding: 4px 11px; font-size: 12.5px; font-weight: 600;
}
.chip.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.chart-box { position: relative; height: 230px; }
.chart-box canvas { width: 100% !important; }
#sheet-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 10px; }
.stat { background: #f4f6f8; border-radius: 10px; padding: 8px 10px; }
.stat .v { font-weight: 800; font-size: 15px; font-variant-numeric: tabular-nums; }
.stat .k { font-size: 11px; color: var(--muted); }

footer {
  margin: 20px 14px 0; padding: 14px 0; border-top: 1px solid var(--line);
  font-size: 11.5px; color: var(--muted);
}
@media (min-width: 720px) {
  header { display: flex; justify-content: space-between; align-items: flex-start; padding: 12px 20px 0; }
  .tabs { margin: 2px 0 0; }
  #selector { top: 64px; }
  #map { height: calc(100dvh - 340px); margin: 0 20px; }
}
