/* Site-specific tweaks on top of Pico. Mobile first: the owner uses the site
   mostly on a phone, so small screens are the default and wider ones adapt. */

:root {
  --tabbar-height: 4rem;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --row-min: 3.5rem;
  --brand: #17635b;
  /* Resolved here, at the root: Pico redefines its colour variables on buttons. */
  --chip-bg: var(--pico-background-color);
  --chip-text: var(--pico-color);
}

nav a[aria-current="page"] {
  font-weight: bold;
  text-decoration: underline;
}

/* Pico's [type=submit] spacing outranks its nav button sizing; restore the latter. */
nav li [type="submit"] {
  margin-bottom: 0;
  padding: calc(var(--pico-nav-link-spacing-vertical) - var(--pico-border-width) * 2)
    var(--pico-nav-link-spacing-horizontal);
}

/* ---- Compact header on phones ------------------------------------------ */

@media (max-width: 767px) {
  :root {
    --pico-font-size: 100%;
  }
  .container {
    padding-inline: 1rem;
  }
  .site-header nav {
    min-height: 0;
  }
  .site-header nav ul {
    margin-block: 0;
  }
  .site-header nav a {
    padding-block: 0.6rem;
    font-size: 0.95rem;
  }
  .site-header [type="submit"] {
    padding: 0.35rem 0.75rem;
    font-size: 0.85rem;
  }
  h1 {
    font-size: 1.6rem;
  }
  h2 {
    font-size: 1.2rem;
  }
}

/* ---- Toast messages ------------------------------------------------------ */

.toasts {
  position: fixed;
  z-index: 50;
  top: max(0.75rem, env(safe-area-inset-top, 0px));
  left: 50%;
  width: min(32rem, calc(100% - 2rem));
  transform: translateX(-50%);
  display: grid;
  gap: 0.5rem;
}
.toast {
  margin: 0;
  padding: 0.85rem 1rem;
  border-radius: var(--pico-border-radius);
  background: var(--pico-card-background-color);
  box-shadow: 0 0.5rem 2rem rgb(0 0 0 / 0.2);
  border-left: 4px solid var(--pico-primary);
  cursor: pointer;
  animation: toast-in 0.2s ease-out;
}
.toast.hiding {
  opacity: 0;
  transform: translateY(-0.5rem);
  transition: opacity 0.25s, transform 0.25s;
}
.flash-error {
  border-left-color: var(--pico-del-color);
}
@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(-0.5rem);
  }
}

.error {
  color: var(--pico-del-color);
}
.ok {
  color: var(--pico-ins-color);
}
.muted {
  color: var(--pico-muted-color);
}

/* ---- Page heading -------------------------------------------------------- */

.page-head {
  margin-bottom: 1rem;
}
.page-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}
.page-title h1 {
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
}
.page-title [role="button"] {
  flex: none;
  padding: 0.5rem 0.9rem;
  white-space: nowrap;
}
.page-head .subtitle {
  margin: 0.15rem 0 0;
  color: var(--pico-muted-color);
}
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.15rem;
  min-height: 2.75rem;
  margin-left: -0.35rem;
  text-decoration: none;
  font-size: 0.95rem;
}

.icon {
  flex: none;
  width: 1.4em;
  height: 1.4em;
  vertical-align: -0.3em;
}

/* ---- Bottom tab bar -------------------------------------------------------- */

body.shisha main,
body.gaming main {
  padding-bottom: calc(var(--tabbar-height) + var(--safe-bottom) + 2rem);
}
.tabbar {
  position: fixed;
  z-index: 40;
  inset: auto 0 0 0;
  padding-bottom: var(--safe-bottom);
  background: var(--pico-background-color);
  border-top: 1px solid var(--pico-muted-border-color);
}
.tabbar ul {
  display: flex;
  margin: 0 auto;
  padding: 0;
  max-width: 36rem;
  height: var(--tabbar-height);
}
.tabbar li {
  flex: 1;
  list-style: none;
  margin: 0;
  padding: 0;
}
.tabbar a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  height: 100%;
  color: var(--pico-muted-color);
  font-size: 0.7rem;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
.tabbar a[aria-current] {
  color: var(--pico-primary);
  font-weight: 600;
}
.tabbar .tab-log a {
  color: var(--pico-primary-inverse);
}
.tabbar .tab-log a .icon {
  box-sizing: content-box;
  width: 1.6rem;
  height: 1.6rem;
  padding: 0.55rem;
  margin-top: -1.4rem;
  border-radius: 50%;
  background: var(--pico-primary-background);
  box-shadow: 0 0.35rem 1rem rgb(0 0 0 / 0.25);
}
.tabbar .tab-log span {
  color: var(--pico-primary);
  font-weight: 600;
}
@media (min-width: 768px) {
  /* A floating dock on wide screens. */
  .tabbar {
    left: 50%;
    right: auto;
    bottom: 1rem;
    width: 34rem;
    transform: translateX(-50%);
    border: 1px solid var(--pico-muted-border-color);
    border-radius: 1.25rem;
    box-shadow: 0 0.5rem 2rem rgb(0 0 0 / 0.12);
  }
}

/* ---- List rows (instead of tables on phones) -------------------------------- */

.rows {
  margin: 0 0 1rem;
  padding: 0;
  border-radius: var(--pico-border-radius);
  background: var(--pico-card-background-color);
  box-shadow: var(--pico-card-box-shadow);
}
.rows > li {
  list-style: none;
  margin: 0;
  border-bottom: 1px solid var(--pico-muted-border-color);
}
.rows > li:last-child {
  border-bottom: 0;
}
.row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-height: var(--row-min);
  padding: 0.6rem 0.9rem;
  color: inherit;
  text-decoration: none;
}
a.row:hover,
a.row:active {
  background: var(--pico-secondary-focus);
}
.row-main {
  flex: 1;
  min-width: 0;
}
.row-title {
  display: block;
  font-weight: 600;
  overflow-wrap: anywhere;
}
.row-sub {
  display: block;
  color: var(--pico-muted-color);
  font-size: 0.85rem;
}
.row-meta {
  flex: none;
  text-align: right;
  font-size: 0.9rem;
}
.row-meta small {
  display: block;
  color: var(--pico-muted-color);
}
.row > .icon:last-child {
  color: var(--pico-muted-color);
}
.row-action {
  flex: none;
  margin: 0;
}
.row-action button {
  margin: 0;
  padding: 0.5rem;
  border: 0;
  background: none;
  color: var(--pico-muted-color);
  min-width: 2.75rem;
  min-height: 2.75rem;
}

/* ---- Chips: filters and tap-to-pick choices ------------------------------------ */

.chips {
  display: flex;
  gap: 0.5rem;
  margin: 0 -1rem 1rem;
  padding: 0.1rem 1rem;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.chips::-webkit-scrollbar {
  display: none;
}
.chip,
.choice span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  min-height: 2.5rem;
  padding: 0.3rem 0.9rem;
  border: 1px solid var(--pico-muted-border-color);
  border-radius: 999px;
  background: var(--chip-bg);
  color: var(--chip-text);
  font-size: 0.9rem;
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.chip[aria-current],
.choice input:checked + span {
  border-color: var(--pico-primary-background);
  background: var(--pico-primary-background);
  color: var(--pico-primary-inverse);
}
.choice input:focus-visible + span {
  outline: 2px solid var(--pico-primary-focus);
  outline-offset: 2px;
}
/* Radio/checkbox choices drawn as chips; the input stays for forms and screen readers. */
.choice {
  display: inline-flex;
  margin: 0;
  position: relative;
}
.choice input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  margin: 0;
}
.choices {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: var(--pico-spacing);
}
.choices.scroll {
  flex-wrap: nowrap;
  overflow-x: auto;
  margin-inline: -1rem;
  padding-inline: 1rem;
  scrollbar-width: none;
}
.choices.scroll::-webkit-scrollbar {
  display: none;
}
/* Ratings 1-10: two rows of five on phones, one row when there's room. */
.rating-picker {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.4rem;
  margin-bottom: var(--pico-spacing);
}
.rating-picker .choice span {
  width: 100%;
  padding-inline: 0;
  border-radius: var(--pico-border-radius);
}
.rating-picker .rating-later {
  grid-column: 1 / -1;
}
@media (min-width: 576px) {
  .rating-picker {
    grid-template-columns: repeat(10, 1fr);
  }
}
fieldset > legend {
  margin-bottom: 0.4rem;
}

/* ---- Search ------------------------------------------------------------------- */

.searchbar {
  position: sticky;
  z-index: 5;
  top: 0;
  margin: 0 -1rem 0.6rem;
  padding: 0.5rem 1rem;
  background: var(--pico-background-color);
}
.searchbar input[type="search"] {
  margin: 0;
}
.filter-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}
.filter-row select {
  width: auto;
  margin: 0;
  padding-block: 0.4rem;
  font-size: 0.9rem;
}

/* ---- Buttons and actions ------------------------------------------------------ */

.btn-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(7.5rem, 1fr));
  gap: 0.5rem;
  margin-bottom: var(--pico-spacing);
}
.btn-row > *,
.btn-row form button {
  width: 100%;
  margin: 0;
}
.btn-row [role="button"],
.btn-row button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 3rem;
}
.btn-row form {
  margin: 0;
}
.btn-block {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  width: 100%;
  min-height: 3.25rem;
  font-size: 1.05rem;
}
/* Keeps the main button of a long form in thumb reach above the tab bar. */
.action-bar {
  position: sticky;
  z-index: 10;
  bottom: calc(var(--tabbar-height) + var(--safe-bottom) + 0.5rem);
  margin: 1rem -1rem 0;
  padding: 0.5rem 1rem;
  background: linear-gradient(transparent, var(--pico-background-color) 30%);
}
.action-bar button,
.action-bar [role="button"] {
  margin: 0;
}
@media (min-width: 768px) {
  .action-bar {
    bottom: 6rem;
  }
}
.danger-zone {
  margin-top: 2.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--pico-muted-border-color);
}
.danger-zone button {
  width: 100%;
  border-color: var(--pico-del-color);
  color: var(--pico-del-color);
}

form.inline {
  display: inline;
  margin: 0;
}
form.inline fieldset,
form.inline button,
form.inline input,
form.inline select {
  margin-bottom: 0;
}

/* ---- Cards and stats ------------------------------------------------------------ */

.card {
  margin-bottom: 1rem;
  padding: 1rem;
}
.stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.6rem;
  margin-bottom: 1.25rem;
}
.stat {
  margin: 0;
  padding: 0.75rem;
  border-radius: var(--pico-border-radius);
  background: var(--pico-card-background-color);
  box-shadow: var(--pico-card-box-shadow);
}
.stat strong {
  display: block;
  font-size: 1.5rem;
  line-height: 1.2;
}
.stat small {
  color: var(--pico-muted-color);
}
@media (min-width: 768px) {
  .stats {
    grid-template-columns: repeat(4, 1fr);
  }
}
.tiles {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.6rem;
  margin-bottom: 1.25rem;
}
.tile {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-height: 5rem;
  padding: 0.8rem;
  border-radius: var(--pico-border-radius);
  background: var(--pico-card-background-color);
  box-shadow: var(--pico-card-box-shadow);
  color: inherit;
  text-decoration: none;
}
.tile .icon {
  color: var(--pico-primary);
}
.tile strong {
  font-size: 0.95rem;
}
.tile small {
  color: var(--pico-muted-color);
}
.tile.primary {
  background: var(--pico-primary-background);
  color: var(--pico-primary-inverse);
}
.tile.primary .icon,
.tile.primary small {
  color: inherit;
}
.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin: 1.5rem 0 0.5rem;
}
.section-head h2 {
  margin: 0;
}
.section-head a {
  font-size: 0.9rem;
}

.stock-low {
  color: #b7791f;
}
.stock-out {
  color: var(--pico-del-color);
}
.notes {
  white-space: pre-line;
}
dl.facts {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.35rem 1rem;
  margin-bottom: 0.75rem;
}
dl.facts dt {
  color: var(--pico-muted-color);
}
dl.facts dd {
  margin: 0;
}
.badge {
  display: inline-block;
  min-width: 2.6rem;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  background: #fde9c0;
  color: #5a3d00;
  font-size: 0.85rem;
  font-weight: 600;
  text-align: center;
}
.badge.unrated {
  background: var(--pico-muted-border-color);
  color: var(--pico-muted-color);
  font-weight: normal;
}
.tag {
  display: inline-block;
  margin: 0 0.25rem 0.25rem 0;
  padding: 0.05rem 0.45rem;
  border: 1px solid var(--pico-muted-border-color);
  border-radius: 999px;
  font-size: 0.75rem;
  color: var(--pico-muted-color);
  text-decoration: none;
}
.profile {
  color: var(--pico-muted-color);
  font-size: 0.85rem;
}

/* ---- Mix recipe bar: one coloured segment per tobacco, width = its share --------- */

.mix-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(18rem, 1fr));
  gap: 0.75rem;
}
.mix-card {
  display: block;
  margin: 0;
  padding: 0.9rem 1rem;
  color: inherit;
  text-decoration: none;
}
.mix-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}
.mix-card-head strong {
  overflow-wrap: anywhere;
}
.mix-card footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin: 0.5rem -1rem -0.9rem;
  padding: 0.4rem 0.6rem 0.4rem 1rem;
  font-size: 0.85rem;
  color: var(--pico-muted-color);
}
.mix-card footer [role="button"] {
  padding: 0.35rem 0.9rem;
  font-size: 0.85rem;
}
.mix-bar {
  display: flex;
  height: 0.6rem;
  overflow: hidden;
  border-radius: 999px;
  margin-bottom: 0.5rem;
}
.recipe {
  margin: 0 0 0.25rem;
  padding: 0;
  font-size: 0.95rem;
}
.recipe li {
  list-style: none;
  margin: 0 0 0.15rem;
}
.swatch {
  display: inline-block;
  width: 0.7rem;
  height: 0.7rem;
  margin-right: 0.4rem;
  border-radius: 2px;
}
.mix-bar-0 { background: #2a9d8f; }
.mix-bar-1 { background: #e9c46a; }
.mix-bar-2 { background: #e76f51; }
.mix-bar-3 { background: #8e7dbe; }
.mix-bar-4 { background: #4d9de0; }
.mix-bar-5 { background: #b5838d; }

/* ---- Mix composer ------------------------------------------------------------- */

fieldset.composer {
  min-width: 0;
}
.composer-row {
  margin-bottom: 0.75rem;
  padding: 0.6rem;
  border: 1px solid var(--pico-muted-border-color);
  border-radius: var(--pico-border-radius);
}
.composer-row select {
  margin-bottom: 0.5rem;
}
.composer-line {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}
.stepper {
  display: flex;
  flex: 1;
  align-items: stretch;
}
.stepper input {
  margin: 0;
  text-align: center;
  border-radius: 0;
}
.stepper button {
  flex: none;
  width: 3rem;
  margin: 0;
  padding: 0;
  font-size: 1.25rem;
}
.stepper button:first-child {
  border-radius: var(--pico-border-radius) 0 0 var(--pico-border-radius);
}
.stepper button:last-child {
  border-radius: 0 var(--pico-border-radius) var(--pico-border-radius) 0;
}
.composer-line .remove {
  flex: none;
  width: 3rem;
  margin: 0;
  padding: 0;
}
.mix-total {
  margin-bottom: 0.75rem;
  font-weight: 600;
}

/* ---- Weekly chart ------------------------------------------------------------- */

.week-chart {
  margin-bottom: 1rem;
}
.week-chart svg {
  width: 100%;
  height: auto;
}
.week-chart .bar {
  fill: var(--pico-primary);
}
.week-chart .bar-empty {
  fill: var(--pico-muted-border-color);
}
.week-chart text {
  fill: var(--pico-muted-color);
  font-size: 11px;
}

.bowl-plan ul {
  padding-left: 1.1rem;
  font-size: 0.95rem;
}
.tag-choices {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: var(--pico-spacing);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* Bigger tap targets for form controls on touch screens. */
@media (pointer: coarse) {
  input:not([type="checkbox"], [type="radio"]),
  select,
  textarea,
  button,
  [role="button"] {
    min-height: 2.9rem;
  }
}

/* A card whose title link covers the whole card; buttons marked .above stay clickable. */
.mix-card {
  position: relative;
}
.mix-card .stretched {
  color: inherit;
  text-decoration: none;
}
.mix-card .stretched::after {
  content: "";
  position: absolute;
  inset: 0;
}
.mix-card .above {
  position: relative;
  z-index: 1;
}

/* Tap-to-pick list rows (e.g. which mix you're smoking). */
.pick-list label.row {
  margin: 0;
  cursor: pointer;
}
.pick-list input[type="radio"] {
  flex: none;
  margin: 0;
}
.pick-list label.row:has(input:checked) {
  background: var(--pico-primary-focus);
  box-shadow: inset 4px 0 0 var(--pico-primary-background);
}

/* The submit button of an auto-submitting form is only for when JS is off. */
.js [data-autosubmit] .fallback {
  display: none;
}

details > summary {
  min-height: 2.75rem;
  display: flex;
  align-items: center;
}

/* ---- Overrides of Pico's nav and button defaults ---------------------------------- */

nav.tabbar ul,
nav.tabbar ul:first-of-type,
nav.tabbar ul:last-of-type {
  width: 100%;
  margin: 0 auto;
  padding: 0;
}
nav.tabbar li {
  padding: 0;
}
nav.tabbar a {
  margin: 0;
  padding: 0;
  border-radius: 0;
}
button.chip,
.chips button.chip {
  margin: 0;
  width: auto;
  background: var(--chip-bg);
  border: 1px solid var(--pico-muted-border-color);
  color: var(--chip-text);
  box-shadow: none;
  font-weight: normal;
}
button.chip:hover,
button.chip:active {
  border-color: var(--pico-primary-border);
}
.chip .icon {
  width: 1.1em;
  height: 1.1em;
}
.pick-list label.row {
  width: 100%;
}
body > main.container {
  padding-top: 0.5rem;
}
@media (max-width: 767px) {
  .site-header nav {
    padding-top: env(safe-area-inset-top, 0px);
  }
}
.rating-picker .choice {
  display: flex;
}
.rating-picker .choice span {
  flex: 1;
  min-height: 2.75rem;
  font-weight: 600;
}
[role="button"] {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
}
.action-bar .mix-total {
  margin: 0 0 0.4rem;
  text-align: center;
  font-size: 0.95rem;
}
/* Pico sizes labels holding a radio/checkbox to fit-content; chips choose their own width. */
label.choice:has([type="checkbox"], [type="radio"]) {
  width: auto;
}
.rating-picker label.choice:has([type="radio"]) {
  width: 100%;
}
.action-bar {
  background: var(--pico-background-color);
  box-shadow: 0 -0.75rem 1rem -0.75rem rgb(0 0 0 / 0.15);
}
a.row-main {
  color: inherit;
  text-decoration: none;
}
a.row-main .row-title {
  color: var(--pico-primary);
}
.toast {
  background: var(--chip-bg);
  border: 1px solid var(--pico-muted-border-color);
  border-left: 4px solid var(--pico-primary);
}
.toast.flash-error {
  border-left-color: var(--pico-del-color);
}

/* Two-way switches drawn as one segmented control (e.g. % / g). */
.choices.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 0;
}
.choices.segmented .choice {
  display: flex;
  width: 100%;
}
.choices.segmented label.choice:has([type="radio"]) {
  width: 100%;
}
.choices.segmented .choice span {
  flex: 1;
  border-radius: 0;
  white-space: normal;
  text-align: center;
  line-height: 1.2;
}
.choices.segmented .choice:first-child span {
  border-radius: var(--pico-border-radius) 0 0 var(--pico-border-radius);
}
.choices.segmented .choice:last-child span {
  border-radius: 0 var(--pico-border-radius) var(--pico-border-radius) 0;
}
/* A session is a mix or one tobacco: only that kind's list (and, for a mix,
   the bowl switch) shows. Per-tobacco grams replace the bowl total of a mix. */
form:has([name="kind"][value="mix"]:checked) .kind-tobacco,
form:has([name="kind"][value="tobacco"]:checked) .kind-mix,
form:has([name="kind"][value="mix"]:checked):has([name="split"][value="each"]:checked) .bowl-total {
  display: none;
}
.amounts {
  margin-bottom: 0.5rem;
}
.amount-row {
  margin-bottom: 0.75rem;
}
.amount-row label {
  display: flex;
  flex-wrap: wrap;
  gap: 0 0.5rem;
  align-items: baseline;
  margin-bottom: 0.3rem;
}
.amount-row .row-sub {
  display: inline;
}
.center {
  text-align: center;
}
.unit-switch {
  margin-bottom: 0.6rem;
}
.unit-switch button.chip {
  width: 100%;
  border-radius: 0;
}
.unit-switch button.chip:first-child {
  border-radius: var(--pico-border-radius) 0 0 var(--pico-border-radius);
}
.unit-switch button.chip:last-child {
  border-radius: 0 var(--pico-border-radius) var(--pico-border-radius) 0;
}
.unit-switch button.chip[aria-pressed="true"] {
  border-color: var(--pico-primary-background);
  background: var(--pico-primary-background);
  color: var(--pico-primary-inverse);
}
.stepper {
  position: relative;
}
.unit-suffix {
  position: absolute;
  right: 3.6rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--pico-muted-color);
  pointer-events: none;
}
.log-now {
  margin-top: 0.5rem;
}

/* ---- Charts ---------------------------------------------------------------------
   Categorical slots validated (scripts/validate_palette.js) on Pico's light and dark
   card surfaces; text never takes a series colour. */

:root {
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-other: #a3a29a;
  --grid: rgb(0 0 0 / 0.08);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-other: #5c5f66;
    --grid: rgb(255 255 255 / 0.1);
  }
}
[data-theme="dark"] {
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-other: #5c5f66;
  --grid: rgb(255 255 255 / 0.1);
}
.chart {
  margin: 0 0 1rem;
  padding: 0.75rem 0.75rem 0.5rem;
  border-radius: var(--pico-border-radius);
  background: var(--pico-card-background-color);
  box-shadow: var(--pico-card-box-shadow);
}
.chart svg {
  display: block;
  width: 100%;
  max-width: 40rem;
  height: auto;
  margin: 0 auto;
  overflow: visible;
}
.chart-readout {
  min-height: 1.5em;
  margin: 0 0 0.4rem;
  font-size: 0.9rem;
}
/* Chart.js sizes its canvas to this box. */
.chart-canvas {
  position: relative;
  max-width: 40rem;
  margin: 0 auto;
}
/* Without scripts the canvas shows its fallback table at full width. */
.chart-canvas canvas {
  display: block;
}
.chart-canvas table {
  margin: 0;
}
.chart-note {
  margin: 0.4rem 0 0;
  color: var(--pico-muted-color);
  font-size: 0.85rem;
}
.chart .grid {
  stroke: var(--grid);
  stroke-width: 1;
}
.chart .axis {
  stroke: var(--pico-muted-border-color);
  stroke-width: 1;
}
.chart .tick {
  fill: var(--pico-muted-color);
  font-size: 10px;
}
.chart .hit {
  fill: transparent;
  cursor: pointer;
}
.chart-mark:focus {
  outline: none;
}
.chart-mark:focus-visible .hit {
  stroke: var(--pico-primary-focus);
  stroke-width: 2;
}
.seg {
  transition: opacity 0.15s;
}
.seg-total,
.seg-s1 {
  fill: var(--series-1);
}
.seg-s2 { fill: var(--series-2); }
.seg-s3 { fill: var(--series-3); }
.seg-s4 { fill: var(--series-4); }
.seg-s5 { fill: var(--series-5); }
.seg-other { fill: var(--series-other); }
/* The tapped column stays solid; the rest step back. */
svg.has-active .chart-mark:not(.is-active) .seg {
  opacity: 0.4;
}
.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 0.9rem;
  margin: 0.6rem 0 0;
  padding: 0;
  font-size: 0.85rem;
}
.chart-legend li {
  list-style: none;
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}
.chart-legend .swatch {
  margin: 0;
}
.chart-legend small {
  color: var(--pico-muted-color);
}
.sw-s1 { background: var(--series-1); }
.sw-s2 { background: var(--series-2); }
.sw-s3 { background: var(--series-3); }
.sw-s4 { background: var(--series-4); }
.sw-s5 { background: var(--series-5); }
.sw-other { background: var(--series-other); }

/* One chart at a time, picked with a segmented switch (works without JS). */
.chart-switch [data-metric] {
  display: none;
}
.chart-switch:has([value="grams"]:checked) [data-metric="grams"],
.chart-switch:has([value="sessions"]:checked) [data-metric="sessions"] {
  display: block;
}

/* Ranked horizontal bars. */
.bar-list {
  margin: 0 0 1rem;
  padding: 0.4rem 0;
  border-radius: var(--pico-border-radius);
  background: var(--pico-card-background-color);
  box-shadow: var(--pico-card-box-shadow);
}
.bar-list li {
  list-style: none;
  margin: 0;
}
.bar-list a {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: "label value" "track track";
  gap: 0.2rem 0.75rem;
  padding: 0.5rem 0.9rem;
  color: inherit;
  text-decoration: none;
}
.bar-label {
  grid-area: label;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.bar-label .row-title,
.bar-label .row-sub {
  display: inline;
}
.bar-value {
  grid-area: value;
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}
.bar-track {
  grid-area: track;
  height: 0.55rem;
  border-radius: 999px;
  background: var(--grid);
  overflow: hidden;
}
.bar-fill {
  display: block;
  height: 100%;
  min-width: 2px;
  border-radius: 999px;
  background: var(--series-1);
}

nav.chips {
  justify-content: flex-start;
}

/* Donut: ring beside its legend when there's room, stacked on narrow phones. */
.donut-body {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.75rem 1.5rem;
}
.donut svg {
  width: min(11rem, 55vw);
  flex: none;
  margin: 0;
}
.slice {
  stroke: var(--pico-card-background-color);
  stroke-width: 2;
  stroke-linejoin: round;
  cursor: pointer;
}
.slice:focus {
  outline: none;
}
.slice:focus-visible {
  stroke: var(--pico-primary-focus);
}
svg.has-active .slice:not(.is-active) {
  opacity: 0.4;
}
.donut-total {
  fill: var(--pico-color);
  font-size: 20px;
  font-weight: 700;
}
.donut-caption {
  fill: var(--pico-muted-color);
  font-size: 11px;
}
.donut-legend {
  flex: 1 1 12rem;
  margin: 0;
  padding: 0;
}
.donut-legend li {
  list-style: none;
  margin: 0;
}
.donut-legend a,
.donut-legend li > span {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  min-height: 2.25rem;
  color: inherit;
  text-decoration: none;
  font-size: 0.9rem;
}
.donut-legend .swatch {
  flex: none;
  margin: 0;
}
.legend-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.legend-value {
  color: var(--pico-muted-color);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ---- Gaming ------------------------------------------------------------------ */

.profiles {
  display: flex;
  gap: 0.6rem;
  margin: 0 -1rem 1rem;
  padding: 0.1rem 1rem;
  overflow-x: auto;
  scrollbar-width: none;
}
.profiles::-webkit-scrollbar {
  display: none;
}
.profile-chip {
  display: flex;
  flex: none;
  align-items: center;
  gap: 0.55rem;
  min-height: var(--row-min);
  padding: 0.4rem 0.9rem 0.4rem 0.4rem;
  border-radius: 999px;
  background: var(--pico-card-background-color);
  box-shadow: var(--pico-card-box-shadow);
  color: inherit;
  text-decoration: none;
}
.profile-chip img,
.avatar {
  flex: none;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  object-fit: cover;
  background: var(--grid);
}
.profile-chip strong,
.profile-chip small {
  display: block;
  line-height: 1.25;
}
.profile-chip small {
  color: var(--pico-muted-color);
  font-size: 0.75rem;
}

.profile-card {
  display: flex;
  align-items: flex-start;
  gap: 0.9rem;
}
.profile-card .avatar {
  width: 4rem;
  height: 4rem;
}
.profile-text {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 0;
}
.profile-name {
  font-size: 1.15rem;
  overflow-wrap: anywhere;
}
.profile-text small {
  color: var(--pico-muted-color);
}
.profile-text .muted {
  white-space: pre-line;
}
.profile-text a {
  font-size: 0.9rem;
}
.tag.plus {
  margin: 0 0 0 0.25rem;
  border-color: #f3b700;
  color: #7a5a00;
  font-weight: 600;
  vertical-align: 0.15em;
}

/* Top three: a row of covers with a rank badge. */
.top-games {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.6rem;
  margin: 0 0 1rem;
  padding: 0;
}
.top-games li {
  list-style: none;
  margin: 0;
  min-width: 0;
}
.top-games a {
  display: block;
  color: inherit;
  text-decoration: none;
}
.top-cover {
  position: relative;
  display: block;
  aspect-ratio: 460 / 215;
  overflow: hidden;
  border-radius: var(--pico-border-radius);
  background: var(--grid);
}
.top-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.rank {
  position: absolute;
  top: 0.3rem;
  left: 0.3rem;
  min-width: 1.5rem;
  padding: 0.05rem 0.4rem;
  border-radius: 999px;
  background: rgb(0 0 0 / 0.65);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  text-align: center;
}
.top-text {
  display: block;
  margin-top: 0.35rem;
}
.top-text strong,
.top-text small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.top-text strong {
  font-size: 0.9rem;
}
.top-text small {
  color: var(--pico-muted-color);
  font-size: 0.75rem;
}

/* Game rows: a cover thumbnail in front. Steam headers are wide, PSN icons square. */
.game-row .thumb {
  flex: none;
  width: 4.6rem;
  height: 2.15rem;
  overflow: hidden;
  border-radius: 0.3rem;
  background: var(--grid);
}
.game-row .thumb.square {
  width: 2.6rem;
  height: 2.6rem;
}
/* Steam and PSN rows in one list: square icons centred in a wide slot. */
.rows.mixed .thumb.square {
  margin: 0 1rem;
}
.stat small.split {
  display: block;
  font-size: 0.75rem;
}
.game-row .thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.locked-row {
  opacity: 0.6;
}
details.locked {
  margin-bottom: 1rem;
}
details.locked summary {
  min-height: 2.75rem;
  line-height: 2.75rem;
}

.game-card .game-cover {
  display: block;
  width: calc(100% + 2rem);
  max-width: none;
  margin: -1rem -1rem 1rem;
  aspect-ratio: 460 / 215;
  object-fit: cover;
  border-radius: var(--pico-border-radius) var(--pico-border-radius) 0 0;
}
.game-card .game-cover.square {
  width: 8rem;
  margin: 0 0 1rem;
  aspect-ratio: 1;
  border-radius: var(--pico-border-radius);
}

.meter {
  height: 0.45rem;
  margin: 0.3rem 0 0.5rem;
  border-radius: 999px;
  background: var(--grid);
  overflow: hidden;
}
.meter span {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--series-1);
}

/* Trophy counts: a coloured dot per grade, then the number. */
.trophy-counts {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 0.3rem 0.75rem;
  font-variant-numeric: tabular-nums;
}
.trophy::before,
.trophy-dot {
  content: "";
  display: inline-block;
  width: 0.7rem;
  height: 0.7rem;
  margin-right: 0.3rem;
  border-radius: 50%;
  vertical-align: -0.05em;
  background: var(--trophy);
}
.trophy-platinum { --trophy: #8fa8c8; }
.trophy-gold { --trophy: #e0a500; }
.trophy-silver { --trophy: #a7aab0; }
.trophy-bronze { --trophy: #b8743a; }
.trophy-line {
  margin-bottom: 0.25rem;
}
