/* ==========================================================================
   Kenjiro design system — see CLAUDE.md "Design" before changing anything.
   Cream washi paper, indigo ink, vermilion seals. Calm, flat, lots of air.
   ========================================================================== */
:root {
  /* Palette (sampled from static/img/landscape.webp) */
  --paper: #ebdfc4;      /* main background */
  --paper-hi: #f3e9d3;   /* raised surfaces: cards */
  --dusk: #e8cda6;       /* bottom of the background gradient */
  --navy: #162633;       /* text / ink */
  --sumi: #1b1712;       /* calligraphy black: frame rules, brush kanji */
  --vermilion: #b23e28;  /* primary action, seals, kana eyebrows */
  --gold: #c9a043;       /* gold-leaf accents, sparingly */
  --muted: #6b6858;      /* secondary text, labels */
  --line: rgba(22, 38, 51, .5);   /* input underlines */
  --rule: rgba(22, 38, 51, .16);  /* card borders, dividers */

  /* Type */
  --font-serif: "Shippori Mincho", "Yu Mincho", serif;   /* headings, kana */
  --font-brush: "Yuji Boku", serif;                       /* the name only */
  --font-ui: system-ui, -apple-system, "Segoe UI", sans-serif;

  --radius: 2px;         /* near-square corners, like cut paper */
}

* { box-sizing: border-box; }
html { background: var(--paper); }
body {
  margin: 0; min-height: 100vh;
  color: var(--navy);
  font: 16px/1.55 var(--font-ui);
  /* Cream paper, warming towards the bottom like the sunset */
  background: linear-gradient(180deg, var(--paper) 0%, var(--paper) 55%, var(--dusk) 100%) fixed;
}
/* Washi grain over the whole page */
body::before {
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .2  0 0 0 0 .15  0 0 0 0 .1  .5 0 0 0 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  opacity: .22; mix-blend-mode: multiply;
}

/* ---------- Typography ---------- */
h1, h2, h3 { font-family: var(--font-serif); font-weight: 700; color: var(--navy); margin: 0; line-height: 1.15; }
h1 { font-size: 2.4rem; letter-spacing: -.01em; }
h2 { font-size: 1.25rem; }
.kana {  /* small Japanese eyebrow above a heading */
  margin: 0 0 6px; font-family: var(--font-serif); font-weight: 600;
  font-size: .95rem; letter-spacing: .3em; color: var(--vermilion);
}
.muted { color: var(--muted); margin: 0; }

/* ---------- Layout ---------- */
.container { max-width: 1040px; margin: 0 auto; padding: 40px 20px 64px; }
.page-head { margin-bottom: 32px; }
.page-head h1 + .muted { margin-top: 10px; }

.topbar {
  display: flex; justify-content: space-between; align-items: center;
  max-width: 1040px; margin: 0 auto; padding: 18px 20px;
  border-bottom: 1px solid var(--rule);
}
.topbar form { margin: 0; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--sumi); text-decoration: none; }
.brand-kanji { font-family: var(--font-brush); font-size: 1.5rem; line-height: 1; }
.brand-seal {
  display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: var(--radius);
  background: var(--vermilion); color: var(--paper-hi); font-family: var(--font-brush); font-size: .8rem;
}

/* ---------- Cards ---------- */
.card {
  background: var(--paper-hi); border: 1px solid var(--rule);
  border-radius: var(--radius); padding: 22px;
}
.grid {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
}
.tile { min-height: 150px; display: flex; flex-direction: column; gap: 6px; }
.tile .kana { margin: 0; }

/* ---------- Forms ---------- */
label {
  display: grid; gap: 6px; color: var(--muted);
  font-size: .72rem; font-weight: 600; letter-spacing: .14em; text-transform: uppercase;
}
label.check { display: flex; gap: 8px; align-items: center; text-transform: none; letter-spacing: 0; font-size: .9rem; font-weight: 400; }
input[type=checkbox] { accent-color: var(--vermilion); width: 16px; height: 16px; }
input:not([type=checkbox]), textarea, select {
  font: inherit; font-size: 1rem; color: var(--navy); background: transparent;
  border: 0; border-bottom: 1.5px solid var(--line); border-radius: 0; padding: 8px 2px;
}
input:focus, textarea:focus, select:focus { outline: none; border-bottom-color: var(--vermilion); box-shadow: 0 1.5px 0 var(--vermilion); }

button { font: inherit; cursor: pointer; }
button.primary {
  padding: 14px 20px; border: 0; border-radius: var(--radius);
  background: var(--vermilion); color: var(--paper-hi);
  font-weight: 600; letter-spacing: .12em; text-transform: uppercase; font-size: .85rem;
  transition: filter .15s, transform .15s;
}
button.primary:hover { filter: brightness(1.08); }
button.primary:active { transform: translateY(1px); }
button.link { background: none; border: 0; padding: 0; color: var(--muted); font-size: .85rem; letter-spacing: .08em; text-transform: uppercase; }
button.link:hover { color: var(--vermilion); }

/* Segmented toggle (e.g. All / Ride / Run) */
.segmented { display: inline-flex; border: 1px solid var(--navy); border-radius: var(--radius); overflow: hidden; }
.segmented button {
  border: 0; background: transparent; color: var(--navy); padding: 9px 16px;
  font-size: .78rem; font-weight: 600; letter-spacing: .12em; text-transform: uppercase;
}
.segmented button + button { border-left: 1px solid var(--navy); }
.segmented button small { font-weight: 400; color: var(--muted); letter-spacing: 0; margin-left: 4px; }
.segmented button[aria-selected=true] { background: var(--navy); color: var(--paper-hi); }
.segmented button[aria-selected=true] small { color: var(--paper); }

a.link-card { color: inherit; text-decoration: none; transition: border-color .15s, transform .15s; }
a.link-card:hover { border-color: var(--vermilion); transform: translateY(-1px); }

.empty-state { max-width: 560px; display: grid; gap: 12px; justify-items: start; padding: 32px; }
.empty-state .kana { margin: 0; }

/* ---------- Icons ---------- */
.icon { width: 1.25em; height: 1.25em; flex: none; vertical-align: -.25em; }

/* Sport colours (see CLAUDE.md): one colour + icon per group, everywhere */
.g-ride { --g: var(--vermilion); }
.g-run { --g: var(--navy); }
.g-swim { --g: #3f6878; }       /* agave blue */
.g-hike { --g: #5b7347; }       /* field green */
.g-walk { --g: #7f8a4c; }       /* olive */
.g-padel { --g: #c47f22; }      /* marigold */
.g-strength { --g: #6e4f33; }   /* wood */
.g-other { --g: #8a8576; }

/* Round sport badge with a paper-coloured icon inside */
.chip {
  display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%;
  background: var(--g); color: var(--paper-hi); flex: none;
}
.chip .icon { width: 14px; height: 14px; }

.topnav { display: flex; align-items: center; gap: 18px; }
.icon-btn {
  display: grid; place-items: center; width: 38px; height: 38px; border-radius: var(--radius);
  color: var(--navy); border: 1px solid var(--rule); transition: border-color .15s, color .15s;
}
.icon-btn:hover { border-color: var(--vermilion); color: var(--vermilion); }
.icon-btn .icon { width: 20px; height: 20px; }

/* ---------- Week bulletin ---------- */
.week { margin-bottom: 20px; padding: 26px 28px; }
.dash-row { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 20px; }
.week-body { display: grid; place-items: center; position: relative; padding: 18px; color: inherit; text-decoration: none; }
.week-body:hover { border-color: var(--vermilion); }
.body-empty { position: absolute; bottom: 4px; font-size: .78rem; }
.d-short { display: none; }

/* Body map: unworked = muted paper, 1 exercise = orange, 2+ = red */
.body-map { width: 100%; max-width: 290px; height: auto; }
.body-map .sil { fill: #e3d5b3; }
.body-map .sil .limb { fill: none; stroke: #e3d5b3; stroke-linecap: round; stroke-linejoin: round; }
.body-map .mu { fill: #d3c199; stroke: var(--paper-hi); stroke-width: 1; transition: fill .2s; }
.body-map .mu.l1 { fill: #e58c3a; }
.body-map .mu.l2 { fill: var(--vermilion); }
.week-head { display: flex; justify-content: space-between; align-items: flex-start; }
.week-head .kana { margin-bottom: 4px; }
.week-nav { display: flex; gap: 4px; }
.week-nav a, .week-nav span {
  display: grid; place-items: center; width: 34px; height: 34px; border: 1px solid var(--rule);
  border-radius: var(--radius); color: var(--navy); text-decoration: none; font-size: 1.2rem;
}
.week-nav a:hover { border-color: var(--vermilion); color: var(--vermilion); }
.week-nav span { opacity: .3; }

.week-days { list-style: none; margin: 22px 0 0; padding: 0; display: grid; grid-template-columns: repeat(7, 1fr); }
.week-days li { display: grid; justify-items: center; gap: 2px; padding: 8px 0; border-radius: var(--radius); }
.week-days li.today { background: rgba(178, 62, 40, .06); }
.week-days .wd { font-family: var(--font-serif); font-weight: 600; color: var(--muted); font-size: .92rem; }
.week-days li.today .wd { color: var(--vermilion); }
.week-days .dn { font-size: .8rem; color: var(--muted); }
.week-days .dot-wrap { height: 52px; display: flex; align-items: center; justify-content: center; gap: 4px; }
.week-days .dot-wrap .dot:not(.empty) { width: 36px; height: 36px; }
.week-days .dt { display: grid; justify-items: center; font-size: .78rem; line-height: 1.35; color: var(--navy); min-height: 2.7em; }
.dot { display: inline-grid; place-items: center; border-radius: 50%; background: var(--g); color: var(--paper-hi); text-decoration: none; transition: transform .15s; }
a.dot:hover { transform: scale(1.08); }
.dot .icon { width: 55%; height: 55%; }
.dot.empty { width: 6px; height: 6px; background: var(--rule); }

.week-totals {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px;
  margin: 18px 0 0; padding-top: 18px; border-top: 1px solid var(--rule);
}
.week-totals dt { color: var(--muted); font-size: .7rem; font-weight: 600; letter-spacing: .14em; text-transform: uppercase; }
.week-totals dd { margin: 2px 0 0; font-family: var(--font-serif); font-weight: 700; font-size: 1.5rem; color: var(--navy); }
.week-totals small { font-family: var(--font-ui); font-weight: 400; font-size: .8rem; color: var(--muted); }
.legend { margin: 16px 0 0; font-size: .75rem; color: var(--muted); display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.legend .chip { width: 18px; height: 18px; margin-left: 10px; }
.legend .chip:first-child { margin-left: 0; }
.legend .chip .icon { width: 12px; height: 12px; }

/* ---------- Dashboard: mini map (all routes, click for the full heatmap) ---------- */
.mini-map { position: relative; display: block; padding: 0; overflow: hidden; min-height: 320px; }
.mini-empty {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 500;
  color: var(--paper); font-size: .85rem; letter-spacing: .06em; background: rgba(20, 20, 20, .6); padding: 8px 14px; border-radius: var(--radius);
}
.mini-map #minimap { position: absolute; inset: 0; pointer-events: none; background: #1d1d1d; }
.mini-map #minimap .heat-canvas { filter: drop-shadow(0 0 2px rgba(255, 120, 40, .85)) drop-shadow(0 0 6px rgba(255, 90, 30, .45)); }
.mini-map::after {   /* soft vignette so the edges melt into the card */
  content: ""; position: absolute; inset: 0; pointer-events: none; z-index: 450;
  box-shadow: inset 0 0 60px rgba(0, 0, 0, .55);
}
.mini-map .mini-label {
  position: absolute; right: 14px; bottom: 14px; z-index: 500;
  background: var(--paper-hi); color: var(--navy); padding: 9px 14px; border-radius: var(--radius);
  font-size: .78rem; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; transition: color .15s;
}
.mini-map:hover .mini-label { color: var(--vermilion); }
.week-title { display: flex; align-items: center; gap: 12px; }
.week-head { gap: 16px; }
.sync-form { margin: 0 0 0 auto; align-self: center; }
.sync-form .link { font-size: .72rem; }

/* ---------- Back link + previous/next of the same type ---------- */
.back-link {
  display: inline-block; margin-bottom: 14px; color: var(--muted); text-decoration: none;
  font-size: .78rem; font-weight: 600; letter-spacing: .1em; text-transform: uppercase;
}
.back-link:hover { color: var(--vermilion); }
.same-type { display: flex; justify-content: space-between; gap: 12px; margin: -14px 0 20px; }
.same-type a {
  display: grid; gap: 2px; padding: 9px 14px; border: 1px solid var(--rule); border-radius: var(--radius);
  color: var(--navy); text-decoration: none; font-size: .78rem; font-weight: 600; letter-spacing: .08em; text-transform: uppercase;
}
.same-type a.next { text-align: right; }
.same-type a small { color: var(--muted); font-weight: 400; letter-spacing: 0; text-transform: none; font-size: .78rem; }
.same-type a:hover { border-color: var(--vermilion); color: var(--vermilion); }

/* ---------- Activity detail ---------- */
.act-head { display: flex; gap: 16px; align-items: center; }
.chip.big { width: 52px; height: 52px; }
.chip.big .icon { width: 28px; height: 28px; }
.act-head h1 { font-size: 2rem; }
.stat-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0;
  background: var(--paper-hi); border: 1px solid var(--rule); border-radius: var(--radius); margin: 0 0 20px; overflow: hidden;
}
.stat-grid > div { padding: 14px 16px; box-shadow: 1px 0 0 var(--rule), 0 1px 0 var(--rule); }
.stat-grid dt { color: var(--muted); font-size: .68rem; font-weight: 600; letter-spacing: .14em; text-transform: uppercase; }
.stat-grid dd { margin: 4px 0 0; font-family: var(--font-serif); font-weight: 700; font-size: 1.45rem; color: var(--navy); }
.stat-grid small { font-family: var(--font-ui); font-weight: 400; font-size: .78rem; color: var(--muted); }
.act-map { padding: 0; overflow: hidden; margin-bottom: 20px; }
.act-map #map { height: 420px; }
.charts { padding: 18px 22px 14px; display: grid; gap: 14px; touch-action: none; }
.chart-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 2px; }
.chart-title { font-size: .7rem; font-weight: 600; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.chart-val { font-family: var(--font-serif); font-weight: 700; color: var(--navy); }
.chart-val small { font-family: var(--font-ui); font-weight: 400; font-size: .75rem; color: var(--muted); }
.chart-svg { display: block; overflow: visible; cursor: crosshair; }
.chart-svg .grid { stroke: var(--rule); stroke-width: 1; }
.chart-svg .tick { fill: var(--muted); font-size: 10px; font-family: var(--font-ui); }
.chart-svg .line { fill: none; stroke: var(--vermilion); stroke-width: 2; stroke-linejoin: round; }
.chart-svg .muted-line { stroke: #8a7f66; }
.chart-svg .area { fill: rgba(138, 127, 102, .18); }
.chart-svg .cross { stroke: var(--navy); stroke-width: 1; stroke-dasharray: 3 3; }
.chart-svg .cross-dot { fill: var(--paper-hi); stroke: var(--navy); stroke-width: 2; }
.x-axis { display: flex; justify-content: space-between; font-size: 10px; color: var(--muted); margin-top: 4px; }

/* ---------- Workout detail ---------- */
.workout-top { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 20px; align-items: start; margin-bottom: 20px; }
.workout-top .stat-grid { margin: 0; grid-template-columns: repeat(2, 1fr); }
.workout-body { display: grid; place-items: center; padding: 18px; }
.exercise-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.exercise-head .muted { font-size: .8rem; }
.set-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.set-table th { text-align: left; color: var(--muted); font-size: .68rem; font-weight: 600; letter-spacing: .14em; text-transform: uppercase; padding: 6px 0; }
.set-table td { padding: 7px 0; border-top: 1px solid var(--rule); font-variant-numeric: tabular-nums; }
.set-table td:first-child, .set-table th:first-child { width: 60px; }
.set-table tr.warmup td { color: var(--muted); }
.workout-head h2 a { color: inherit; text-decoration: none; }
.workout-head h2 a:hover { color: var(--vermilion); }

/* ---------- Workout history ---------- */
.workout-list { display: grid; gap: 14px; }
.workout-head { display: flex; gap: 12px; align-items: center; margin-bottom: 12px; }
.workout-head .chip { width: 34px; height: 34px; }
.workout-head .chip .icon { width: 20px; height: 20px; }
.workout-head h2 { margin-bottom: 2px; }
.sets { width: 100%; border-collapse: collapse; font-size: .9rem; }
.sets td { padding: 7px 0; border-top: 1px solid var(--rule); vertical-align: top; }
.sets .ex .muted { font-size: .78rem; }
.sets .n { color: var(--muted); white-space: nowrap; padding: 7px 16px; width: 90px; }
.sets .best { text-align: right; white-space: nowrap; font-family: var(--font-serif); font-weight: 600; }
.pager { display: flex; justify-content: space-between; margin-top: 20px; }
.pager a { color: var(--vermilion); text-decoration: none; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; font-size: .8rem; }

/* ---------- Heatmap ---------- */
.heat-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.map-card { padding: 0; overflow: hidden; position: relative; }
#map { height: min(72vh, 760px); background: var(--paper); }
/* Normal map: real colours, just slightly warmed to sit on the paper */
#map[data-style=map] .leaflet-tile-pane { filter: sepia(.18) saturate(.95); }
/* Satellite: dimmed so the heat is the brightest thing on screen */
#map[data-style=satellite] .leaflet-tile-pane { filter: brightness(.55) saturate(.6) contrast(1.1); }
#map[data-style=night] { background: #1d1d1d; }
/* Glow: routes read as light, not as marker pen */
#map[data-style=night] .heat-canvas,
#map[data-style=satellite] .heat-canvas { filter: drop-shadow(0 0 2px rgba(255, 120, 40, .85)) drop-shadow(0 0 6px rgba(255, 90, 30, .45)); }
#map[data-style=map] .heat-canvas { filter: drop-shadow(0 0 1px rgba(255, 255, 255, .95)) drop-shadow(0 0 3px rgba(255, 255, 255, .6)); }
.map-style { position: absolute; top: 12px; right: 12px; z-index: 500; background: var(--paper-hi); box-shadow: 0 2px 8px rgba(22, 38, 51, .18); }
#map .leaflet-control-attribution { background: rgba(243, 233, 211, .8); }
/* Place picker, floating top-left next to the zoom buttons */
.place-pick { position: absolute; top: 12px; left: 56px; z-index: 500; }
.place-pick select {
  appearance: none; font: inherit; font-size: .78rem; font-weight: 600; letter-spacing: .08em; text-transform: uppercase;
  color: var(--navy); border: 1px solid var(--navy); border-radius: var(--radius); padding: 9px 30px 9px 12px; cursor: pointer;
  background: var(--paper-hi) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%23162633' stroke-width='1.5'/%3E%3C/svg%3E") no-repeat right 10px center;
  box-shadow: 0 2px 8px rgba(22, 38, 51, .18);
}
.place-pick select:focus { outline: 2px solid var(--vermilion); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Calendar ---------- */
.cal-head { display: flex; justify-content: space-between; align-items: flex-end; }
.muted-year { color: var(--muted); font-weight: 600; }
.cal { padding: 10px; }
.cal-row { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.cal-weekdays span {
  text-align: center; padding: 8px 0 10px; font-family: var(--font-serif); font-weight: 600; color: var(--muted);
}
.cal-day {
  min-height: 92px; padding: 8px; display: flex; flex-direction: column; gap: 8px;
  border-top: 1px solid var(--rule); color: var(--navy); border-radius: var(--radius);
}
.cal-num { color: inherit; text-decoration: none; align-self: flex-start; }
.cal-num:hover { color: var(--vermilion); }
.cal-acts a.chip:hover { transform: scale(1.1); }
.cal-day.out { opacity: .35; }
.cal-num { font-size: .85rem; color: var(--muted); }
.cal-day.today .cal-num {
  display: inline-grid; place-items: center; width: 24px; height: 24px; margin: -3px 0 0 -4px;
  border-radius: 50%; background: var(--vermilion); color: var(--paper-hi); font-weight: 600;
}
.cal-acts { display: flex; flex-wrap: wrap; gap: 4px; }
.cal-acts .chip { width: 26px; height: 26px; }
.cal-acts .chip .icon { width: 16px; height: 16px; }
.cal-acts .more { font-size: .75rem; color: var(--muted); align-self: center; }
.cal-totals { display: flex; flex-wrap: wrap; gap: 28px; margin: 22px 4px 0; }
.cal-totals dt {
  display: flex; align-items: center; gap: 6px; color: var(--muted);
  font-size: .7rem; font-weight: 600; letter-spacing: .14em; text-transform: uppercase;
}
.cal-totals dd { margin: 4px 0 0; font-family: var(--font-serif); font-weight: 700; font-size: 1.5rem; }

@media (max-width: 900px) {
  .dash-row { grid-template-columns: 1fr; }
  .workout-top { grid-template-columns: 1fr; }
  .d-long { display: none; }
  .d-short { display: inline; }
}

@media (max-width: 640px) {
  .cal-day { min-height: 64px; padding: 5px 3px; gap: 4px; }
  .cal-acts .chip { width: 18px; height: 18px; }
  .cal-acts .chip .icon { width: 11px; height: 11px; }
  .week { padding: 20px 14px; }
}

.flash {
  border: 1px solid var(--vermilion); border-radius: var(--radius);
  padding: 10px 12px; margin-bottom: 16px; color: var(--navy);
}
