/* Russ's Stats tab (build spec 6.6). Classes st-*, on the shared hard-edged base
   (shared/ui/hard-edges.css): no radius, no shadows, black 1px lines, white panels, colour only where
   the bar and the calendar need it. Fits 1366 x 657 below a 44 px top bar with no scrolling and
   stacks at phone width, bar above calendar. */

/* ---- the page background (the app owns the host; these are the layers inside it) ---- */

:where(.st-bg-host) { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }

.st-bg {
  position: absolute; inset: 0; z-index: 1;
  background-size: cover; background-position: center; background-repeat: no-repeat;
  opacity: 0;
  transition: opacity 0.6s ease; /* FADE_MS in stats.js */
}
.st-bg.is-front { z-index: 2; }
.st-bg.is-on { opacity: 1; }
.st-bg.is-instant { transition: none; }

/* The fade over the picture: about 38% black, so the white panels stand clear of it. */
.st-bg-fade { position: absolute; inset: 0; z-index: 3; background: rgba(0, 0, 0, 0.38); }

/* ---- layout ---- */

.st-root {
  --st-valley: 70%;     /* the valley's share of the bar; the three bands take 10% each */
  --st-band-h: 10%;
  --st-bar-w: 160px;
  --st-inset: 16px;     /* room above and below the bar for the level chip and the scale */
  --st-empty: 1;        /* 1 minus the fraction of the valley still full; set by stats.js */
  --st-band: -1;        /* index of the highest band reached, or -1 */
  box-sizing: border-box; position: relative; z-index: 1;
  height: 100%; min-height: 0; padding: 12px;
  display: grid; gap: 12px;
  grid-template-columns: minmax(300px, 340px) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) auto;
  color: var(--ge-black); font-size: 0.9375rem; line-height: 1.25;
}

.st-panel { box-sizing: border-box; position: relative; min-width: 0; min-height: 0; background: var(--ge-white); border: var(--ge-line); }

/* ---- the bar ---- */

.st-bar-panel { display: flex; justify-content: center; padding: 8px 12px; }
.st-bar-area { position: relative; width: 100%; max-width: 320px; height: 100%; }

.st-scale, .st-bar, .st-rail { position: absolute; top: var(--st-inset); bottom: var(--st-inset); }
.st-scale { left: 0; width: 52px; }
.st-bar {
  left: 52px; width: var(--st-bar-w); box-sizing: border-box;
  display: flex; flex-direction: column; background: var(--ge-white); border: var(--ge-line);
}
.st-rail { left: calc(52px + var(--st-bar-w)); right: 0; }

.st-tick {
  position: absolute; right: 0; padding-right: 10px;
  top: calc((100 - var(--p)) / 100 * var(--st-valley)); transform: translateY(-50%);
  font-size: 0.75rem; color: var(--ge-grey-3); white-space: nowrap;
}
.st-tick::after { content: ""; position: absolute; right: 0; top: 50%; width: 7px; border-top: var(--ge-line); }

/* The valley: the whole rainbow-to-night gradient, covered from the top by white as calls are made. */
.st-valley { position: relative; flex: 0 0 var(--st-valley); overflow: hidden; background: var(--st-bar-gradient); }
.st-cover {
  position: absolute; top: 0; left: 0; right: 0;
  height: calc(var(--st-empty) * 100%);
  background: var(--ge-white);
  transition: height 0.5s ease;
}
.st-cover::after { content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 1px; background: var(--ge-black); }

/* The three bands below 0%, grey until reached, then red, gold and black. */
.st-band {
  box-sizing: border-box; flex: 0 0 var(--st-band-h);
  display: flex; align-items: center; justify-content: space-between; padding: 0 10px;
  border-top: var(--ge-line); background: var(--ge-grey-1); color: var(--ge-grey-3);
  font-size: 0.8125rem; font-weight: 700;
}
.st-band:nth-child(2) { border-top-width: 2px; } /* the 0% line */
.st-band.is-lit { color: var(--ge-white); }
.st-band[data-band="alpha"].is-lit { background: var(--st-alpha); }
.st-band[data-band="g"].is-lit { background: var(--st-g); color: var(--ge-black); }
.st-band[data-band="top-g"].is-lit { background: var(--st-top-g); }

/* The level chip: where the valley has got to, or the band reached. */
.st-level {
  position: absolute; left: 14px; transform: translateY(-50%);
  box-sizing: border-box; min-width: 56px; min-height: 30px; padding: 4px 10px;
  display: flex; align-items: center; justify-content: center;
  background: var(--ge-black); color: var(--ge-white);
  font-size: 1rem; font-weight: 700; white-space: nowrap;
  top: calc(var(--st-empty) * var(--st-valley));
  transition: top 0.5s ease;
}
.st-level::before { content: ""; position: absolute; right: 100%; top: 50%; width: 14px; border-top: var(--ge-line); }
.st-root[data-zone="band"] .st-level {
  top: calc(var(--st-valley) + (var(--st-band) + 0.5) * var(--st-band-h));
}

/* ---- the calendar ---- */

.st-cal-panel {
  display: grid; grid-template-rows: auto auto minmax(0, 1fr); gap: 8px; padding: 12px;
  justify-self: end; width: 100%; max-width: 760px; /* the picture shows between the two panels */
}

.st-cal-nav { display: grid; grid-template-columns: var(--ge-target) minmax(0, 1fr) var(--ge-target); align-items: center; gap: 8px; }
.st-month { text-align: center; font-size: 1.0625rem; font-weight: 700; }
.st-nav { font-size: 1.75rem; font-weight: 700; line-height: 1; padding: 0 0 4px; }

.st-cal-head, .st-cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.st-dow { font-size: 0.75rem; text-align: center; color: var(--ge-grey-3); }
.st-cal-grid { grid-template-rows: repeat(var(--st-rows, 6), minmax(var(--ge-target), 1fr)); min-height: 0; }

.st-day {
  position: relative; box-sizing: border-box; display: block; min-width: 0; min-height: var(--ge-target);
  margin: 0; padding: 0; font: inherit; color: var(--ge-black); background: var(--ge-white);
  border: var(--ge-line); cursor: pointer; text-align: left;
}
.st-num {
  position: absolute; top: 3px; left: 3px; box-sizing: border-box;
  min-width: 22px; height: 20px; padding: 0 4px;
  background: var(--ge-white); border: var(--ge-line);
  font-size: 0.75rem; font-weight: 700; line-height: 18px; text-align: center;
}
.st-day[data-colour="rainbow"] { background: var(--st-rainbow); }
/* Today: a thick black border with a white ring just inside it, so it shows on black too. */
.st-day.is-today { border-width: 3px; outline: 2px solid var(--ge-white); outline-offset: -5px; }
.st-day.is-today .st-num { top: 1px; left: 1px; background: var(--ge-black); color: var(--ge-white); }

.st-day:hover:not(:disabled) { outline: 2px solid var(--ge-black); outline-offset: 1px; z-index: 1; }
.st-day:active:not(:disabled) { outline-width: 4px; }
.st-day:focus-visible { outline: 3px solid var(--ge-action); outline-offset: 2px; z-index: 2; }

.st-day:disabled { cursor: default; }
.st-day--future { background: transparent; border-color: var(--ge-grey-2); }
.st-day--future .st-num { background: transparent; border-color: transparent; color: var(--ge-grey-3); font-weight: 400; }
.st-day--pad { visibility: hidden; }
.st-day--spare { display: none; }

.st-tip {
  position: absolute; z-index: 5; width: max-content; max-width: 220px; box-sizing: border-box;
  display: flex; flex-direction: column; gap: 2px; padding: 6px 10px;
  background: var(--ge-white); border: var(--ge-line);
  font-size: 0.875rem; pointer-events: none;
}
.st-tip[hidden] { display: none; }

/* ---- so far ---- */

.st-sofar {
  grid-column: 1 / -1; display: grid; grid-template-columns: auto repeat(3, minmax(0, 1fr));
  background: var(--ge-white); border: var(--ge-line);
}
.st-sofar > * { box-sizing: border-box; min-height: 52px; padding: 6px 14px; }
.st-sofar > * + * { border-left: var(--ge-line); }
.st-sofar-label { display: flex; align-items: center; background: var(--ge-black); color: var(--ge-white); font-weight: 700; }
.st-stat { display: flex; flex-direction: column; justify-content: center; min-width: 0; }
.st-stat-value { font-size: 1.25rem; line-height: 1.1; }
.st-stat-caption { font-size: 0.75rem; color: var(--ge-grey-3); }

/* ---- the phone: bar above the calendar, one column, the page may scroll ---- */

@media (max-width: 720px) {
  .st-root { height: auto; grid-template-columns: minmax(0, 1fr); grid-template-rows: none; }
  .st-bar-panel { height: 268px; }
  .st-cal-panel { max-width: none; }
  .st-cal-grid { grid-template-rows: none; grid-auto-rows: 48px; }
  .st-sofar > * { padding: 6px 10px; }
}

/* ---- reduced motion: frames, bar and chip switch with no fade ---- */

@media (prefers-reduced-motion: reduce) {
  .st-bg, .st-cover, .st-level { transition: none !important; }
}
