/* Ändra färger och mått här. Inga externa beroenden behövs. */
:root {
  --background: #101214;
  --text: #f3f3ee;
  --muted: #a1a6ab;
  --year: #b8d888;
  --month: #d9d57d;
  --day: #e79c9c;
  --week: #edb878;
  --decade: #7cd5c9;
  --century: #9abaef;
  --millennium: #b5a3e6;
  --outline: #c2c6c8;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--background);
  font-synthesis: none;
}
* { box-sizing: border-box; }
html { height: 100%; }
body { margin: 0; height: 100vh; height: 100dvh; display: grid; align-items: center; padding: clamp(8px, 2dvh, 24px) clamp(12px, 3vw, 24px); }
/* En enda kolumn: staplarna och infotexten delar samma cell i stället för att
   auto-placeras i egna kolumner, så bredden aldrig beror på vad som visas. */
main { width: min(100%, 760px); margin-inline: auto; height: 100%; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr) auto; gap: clamp(6px, 2dvh, 20px); }
h1 { margin: 0; font: inherit; }
.controls { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 8px; margin: 0; }
.toggle { position: relative; display: flex; min-width: 0; cursor: pointer; }
.toggle input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.toggle span, button { display: grid; place-items: center; width: 100%; min-width: 0; min-height: 44px; padding: 9px 4px; border: 1px solid #45494d; border-radius: 7px; font: inherit; font-size: 12px; text-align: center; }
.toggle span { color: var(--muted); transition: background .15s, color .15s; }
.toggle input:checked + span { background: #292e30; border-color: #757c81; color: var(--text); }
.toggle input:focus-visible + span, button:focus-visible { outline: 2px solid var(--text); outline-offset: 4px; }
.toggle:hover span, button:hover { border-color: #a1a6ab; }
button { background: transparent; color: var(--text); cursor: pointer; }
/* Staplar krymper genom båda komprimeringslägena (70 och 46 px).
   Först vid 32 px rullar ytan, så även många egna staplar förblir läsbara. */
.bars { grid-area: 2 / 1; min-height: 0; display: grid; grid-auto-rows: minmax(32px, 110px); align-content: safe center; gap: clamp(4px, 1.5dvh, 16px); overflow-y: auto; padding: 8px 4px 4px; }
.period { position: relative; min-height: 0; container-type: size; display: grid; grid-template-rows: minmax(0, 26px) minmax(0, 1fr) minmax(0, 12px); gap: 4px; }
.period[data-period="year"] { --accent: var(--year); }
.period[data-period="month"] { --accent: var(--month); }
.period[data-period="day"] { --accent: var(--day); }
.period[data-period="week"] { --accent: var(--week); }
.period[data-period="decade"] { --accent: var(--decade); }
.period[data-period="century"] { --accent: var(--century); }
.period[data-period="millennium"] { --accent: var(--millennium); }
.period-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; min-width: 0; }
h2 { margin: 0; min-width: 0; font-size: 15px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.period-name { color: var(--muted); font-size: 13px; font-weight: 400; margin-left: 9px; }
.value { white-space: nowrap; font-size: 22px; font-weight: 500; font-variant-numeric: tabular-nums; letter-spacing: -.035em; }
.value small { color: var(--muted); font-size: 12px; font-weight: 400; letter-spacing: 0; margin-left: 5px; }
.battery { --battery-inset: min(5px, 5cqh); --pin-rise: 5px; --pin-size: 5px; --pin-ring: 1.5px; height: 100%; min-height: 0; padding: var(--battery-inset); border: 1px solid var(--outline); border-radius: 9px; background: #22272a; }
/* Vänsterkanten är rak så att nålen ser ut att klippa exakt; höger sida följer spåret. */
.battery-fill { position: relative; height: 100%; width: 100%; margin-left: auto; margin-right: 0; border-radius: 0 4px 4px 0; background: var(--accent); transition: width .6s ease; }
/* Snittet mellan förflutet och återstående: en knappnål. Nålen är lika tjock och
   lika ljus som stapelns kontur, går ned till underkanten och en bit upp ovanför
   överkanten, där knoppen sitter centrerad på linjen. */
.battery-fill::before, .battery-fill::after { content: ''; position: absolute; right: 100%; pointer-events: none; }
.battery-fill::before {
  width: 1px;
  top: calc(-1 * (var(--battery-inset) + var(--pin-rise)));
  bottom: calc(-1 * var(--battery-inset));
  background: var(--cut, var(--outline));
  z-index: 3; /* över knoppens ring, annars kapas stiftet strax under knoppen */
}
.battery-fill::after {
  width: var(--pin-size); height: var(--pin-size); border-radius: 50%;
  margin-right: calc(0.5px - var(--pin-size) / 2);
  top: calc(-1 * (var(--battery-inset) + var(--pin-rise) + var(--pin-size) / 2));
  background: var(--pin, var(--text));
  /* Ringen är bakgrundsfärgad: osynlig mot bakgrunden, men håller knoppen läsbar
     när den passerar under procenttalet. */
  box-shadow: 0 0 0 var(--pin-ring) var(--background);
  z-index: 2;
}
.scale { display: flex; justify-content: space-between; margin: 0; color: var(--muted); font-size: 10px; font-variant-numeric: tabular-nums; }
.empty { grid-area: 2 / 1; align-self: center; margin: 0; border: 1px dashed #45494d; border-radius: 9px; padding: 35px 20px; color: var(--muted); text-align: center; line-height: 1.6; }
footer { grid-area: 3 / 1; display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: clamp(4px, 1vw, 12px); color: var(--muted); font-size: clamp(7px, 1.4vw, 11px); line-height: 1.4; white-space: nowrap; }
footer time { text-align: right; }
noscript { grid-area: 2 / 1; }
time { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }
@media (max-width: 799px) {
  .controls { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (max-width: 599px) {
  .toggle span, button { font-size: 11px; }
  .period-name { font-size: 11px; margin-left: 5px; }
}
@media (max-width: 359px) {
  .toggle span, button { font-size: 10px; padding-inline: 1px; }
}
@media (max-height: 499px) {
  .toggle span, button { min-height: 30px; padding-block: 4px; }
}
/* Komprimera varje stapel efter utrymmet den faktiskt får. */
@container (max-height: 70px) {
  .scale { display: none; }
  .battery { grid-row: 2 / 4; }
  .value { font-size: 18px; }
}
@container (max-height: 46px) {
  .battery { grid-row: 1 / 4; opacity: .45; }
  .period-heading { position: absolute; inset: 0 8px; align-items: center; z-index: 1; }
  h2 { font-size: 12px; }
  .value { font-size: 16px; }
  .value small { font-size: 10px; }
}
@media (prefers-reduced-motion: reduce) { .battery-fill, .toggle span { transition: none; } }

#show-all { grid-column: 2; justify-self: center; width: auto; min-height: 28px; padding: 4px 16px; font-size: 11px; color: var(--muted); }
#custom-open.active { background: #292e30; border-color: #757c81; }
.period[data-period="custom"] { --accent: #8edac0; }
dialog { width: min(680px, calc(100% - 24px)); max-height: calc(100dvh - 24px); padding: 24px; overflow: hidden; border: 1px solid #45494d; border-radius: 14px; background: var(--background); color: var(--text); }
dialog::backdrop { background: #0009; }
dialog h2 { font-size: 21px; }
#custom-form { position: relative; display: flex; flex-direction: column; max-height: calc(100dvh - 74px); overflow-y: auto; }
#custom-close { position: absolute; top: 0; right: 0; width: 36px; min-height: 36px; padding: 0; border: 0; color: var(--muted); }
#custom-title { padding-right: 44px; }
#custom-close:hover { color: var(--text); }
#custom-close:focus-visible { outline: 2px solid var(--outline); outline-offset: -2px; }
dialog p { color: var(--muted); font-size: 13px; line-height: 1.6; }
dialog fieldset { margin: 20px 0; padding: 0; border: 0; }
dialog legend { margin-bottom: 10px; }
.date-fields { display: grid; grid-template-columns: 1.4fr 1fr 1fr 1.5fr; gap: 10px; }
.date-fields label { display: grid; gap: 6px; font-size: 12px; color: var(--muted); }
.date-fields input { width: 100%; min-width: 0; min-height: 44px; padding: 8px; border: 1px solid #45494d; border-radius: 7px; background: #22272a; color: var(--text); font: inherit; font-size: 14px; }
.date-fields input:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }
.dialog-actions { position: sticky; bottom: 0; z-index: 1; display: flex; gap: 8px; margin-top: 12px; padding-top: 12px; background: var(--background); }
.dialog-actions .primary { background: #29483e; border-color: #8edac0; }
#custom-error { color: #ffb4b4; }
@media (max-width: 420px) { dialog { padding: 18px; } .date-fields, #custom-editor:not(.uses-time) .date-fields { grid-template-columns: 1fr 1fr; } }

.form-field { display: grid; gap: 6px; margin-top: 16px; color: var(--muted); font-size: 13px; }
.form-field input, .form-field select { width: 100%; min-height: 44px; padding: 8px; border: 1px solid #45494d; border-radius: 7px; background: #22272a; color: var(--text); font: inherit; }
.custom-edit { display: inline; width: auto; min-height: 0; padding: 0; border: 0; border-radius: 2px; font: inherit; text-align: left; text-decoration: underline; text-decoration-color: #757c81; text-underline-offset: 3px; }
.dialog-actions { flex-wrap: wrap; }
.dialog-actions button { flex: 1 1 90px; }

.custom-list-heading { margin: 18px 6px 4px; color: var(--muted); font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; }
#custom-list, #custom-completed-list { list-style: none; margin: 0 0 12px; padding: 6px; scroll-padding: 6px; display: grid; gap: 6px; max-height: 220px; overflow-y: auto; }
#custom-list li, #custom-completed-list li { display: grid; grid-template-columns: minmax(0, 1fr) 44px 44px; gap: 6px; align-items: center; }
#custom-list .custom-list-title, #custom-completed-list .custom-list-title { display: flex; align-items: baseline; justify-content: flex-start; gap: 9px; text-align: left; padding-inline: 12px; overflow: hidden; white-space: nowrap; }
.custom-list-name { flex: 0 1 auto; overflow: hidden; font-weight: 500; text-overflow: ellipsis; }
.custom-list-range { flex: 1 1 auto; overflow: hidden; color: var(--muted); font-size: 11px; font-weight: 400; text-overflow: ellipsis; }
.custom-list-title[aria-pressed="true"] { background: #292e30; border-color: #8edac0; }
.is-hidden .custom-list-title { color: var(--muted); }
.custom-list-icon { height: 44px; padding: 8px; }
.custom-list-icon svg { width: 22px; height: 22px; }
.custom-list-remove, #custom-close { position: relative; font-size: 0; }
#custom-close { position: absolute; }
.custom-list-remove::before, .custom-list-remove::after,
#custom-close::before, #custom-close::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: 18px;
  height: 2px;
  border-radius: 1px;
  background: currentColor;
  transform: translate(-50%, -50%) rotate(45deg);
}
.custom-list-remove::after, #custom-close::after { transform: translate(-50%, -50%) rotate(-45deg); }
.custom-list-remove:hover { color: #ffb4b4; border-color: #ffb4b4; }
#custom-new { border-style: dashed; }
#custom-editor-title { margin: 24px 0 0; font-size: 15px; font-weight: 500; }

#custom-save:disabled { opacity: .4; cursor: default; }
#custom-save:disabled:hover { border-color: #8edac0; }

#custom-editor { min-width: 0; margin: 0; }

#custom-undo { margin-top: 14px; padding-inline: 12px; overflow-wrap: anywhere; }
#custom-undo:disabled { opacity: .4; cursor: default; }
#custom-history-status:empty { display: none; }

#custom-color { width: 54px; height: 36px; padding: 3px; cursor: pointer; }
.custom-options { display: flex; align-items: center; flex-wrap: wrap; gap: 12px 20px; margin-top: 16px; }
.custom-color-field, .custom-time-toggle { display: flex; align-items: center; gap: 9px; color: var(--muted); font-size: 13px; }
.custom-time-toggle input { width: 20px; height: 20px; margin: 0; accent-color: #8edac0; }
.custom-time-toggle:has(input:disabled) { opacity: .45; }
.custom-date-info { margin-top: 12px; }
.custom-date-info summary { display: grid; place-items: center; width: 24px; height: 24px; border: 1px solid #45494d; border-radius: 50%; color: var(--muted); font-size: 13px; font-weight: 600; cursor: pointer; list-style: none; }
.custom-date-info summary::-webkit-details-marker { display: none; }
.custom-date-info summary:hover { border-color: #a1a6ab; color: var(--text); }
.custom-date-info summary:focus-visible { outline: 2px solid var(--text); outline-offset: 3px; }
.custom-date-info p { margin: 8px 0 0; }
#custom-editor:not(.uses-time) .custom-time-field { display: none; }
#custom-editor:not(.uses-time) .date-fields { grid-template-columns: 1.4fr 1fr 1fr; }
#custom-list .custom-list-title, #custom-completed-list .custom-list-title { border-left: 5px solid var(--custom-color, #8edac0); }
.custom-completed-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 10px; }
.custom-completed-heading .custom-list-heading { margin-top: 4px; }
#custom-clear-completed { width: auto; min-height: 34px; padding: 5px 10px; color: var(--muted); }
.period.is-completed .value { color: var(--muted); font-size: 15px; letter-spacing: 0; }
.period.is-completed .battery-fill::before, .period.is-completed .battery-fill::after { display: none; }
