@font-face {
  font-family: 'TK Figtree';
  src: url('../resources/fonts/figtree.woff') format('woff');
  font-weight: 300 900;
  font-display: block;
}

:root {
  --u: 1vmin;
  --ink: #f4f6f5;
  --glow: #3ddc97;
  --paper: #101315;
  --paper-opacity: 1;
  --behind: #ff6b6b;
  --pr5: #ff5d5d;
  --pr3: #ffb23e;
  --pr1: #5c9dff;

  --pad: calc(var(--u) * 5);
  --gap: calc(var(--u) * 5);
  --hero: calc(var(--u) * 20);
  --title: calc(var(--u) * 4.2);
  --facts: calc(var(--u) * 3);
  --small: calc(var(--u) * 3.4);
  --tick: calc(var(--u) * 5.4);
  --glance-w: 30%;
}

/* the two short slots (840 x 344 and 696 x 416) keep readable text and drop the extras instead */
@media (max-height: 450px) {
  :root { --u: 5px; --pad: 22px; --gap: 22px; --hero: 96px; }
  .tk-next, .tk-day, .tk-sync { display: none !important; }
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { width: 100%; height: 100%; overflow: hidden; background: transparent; }
body { font-family: 'TK Figtree', 'Segoe UI', sans-serif; color: var(--ink); -webkit-font-smoothing: antialiased; }

.tk {
  position: fixed; inset: 0; padding: var(--pad);
  display: grid; gap: 0 var(--gap);
  grid-template-columns: var(--glance-w) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) auto;
  grid-template-areas: "glance plan" "glance sync";
}
.tk-back { position: absolute; inset: 0; background: var(--paper); opacity: var(--paper-opacity); z-index: 0; }
.tk > section, .tk-sync, .tk-card { position: relative; z-index: 1; }

/* ---- glance: the number you read in two seconds ---- */
.tk-glance { grid-area: glance; display: flex; flex-direction: column; justify-content: center; gap: calc(var(--u) * 1.4); min-width: 0; }
.tk-day { font-size: var(--small); font-weight: 600; opacity: 0.6; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tk-hero { display: flex; flex-direction: column; }
.tk-hero b { font-size: var(--hero); font-weight: 800; line-height: 0.92; letter-spacing: -0.04em; font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--glow); }
.tk-hero span { font-size: var(--small); font-weight: 600; opacity: 0.85; white-space: nowrap; }
.tk-late { font-size: var(--small); font-weight: 700; opacity: 0.7; white-space: nowrap; }
.tk-late.is-behind { color: var(--behind); opacity: 1; }
.tk-next { font-size: var(--facts); line-height: 1.3; opacity: 0.75; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

/* ---- the plan ---- */
.tk-plan { grid-area: plan; min-height: 0; overflow: hidden; }
.tk-rows { list-style: none; display: flex; flex-direction: column; }
.tk-band { font-size: calc(var(--u) * 2.6); font-weight: 800; letter-spacing: 0.14em; text-transform: uppercase; opacity: 0.5; padding: calc(var(--u) * 1.6) 0 calc(var(--u) * 0.6); }
.tk-band:first-child { padding-top: 0; }
.tk-band-overdue { color: var(--behind); opacity: 0.85; }
.tk-row {
  display: grid; grid-template-columns: var(--tick) minmax(0, 1fr); align-items: center; gap: calc(var(--u) * 2.4);
  padding: calc(var(--u) * 1.3) 0; border-bottom: 1px solid color-mix(in srgb, var(--ink) 9%, transparent);
  --pc: color-mix(in srgb, var(--ink) 45%, transparent);
}
.tk-row.pr5 { --pc: var(--pr5); }
.tk-row.pr3 { --pc: var(--pr3); }
.tk-row.pr1 { --pc: var(--pr1); }
.tk-tick {
  position: relative; width: var(--tick); height: var(--tick); border-radius: 50%;
  border: calc(var(--u) * 0.55) solid var(--pc); background: color-mix(in srgb, var(--pc) 12%, transparent);
  cursor: pointer; color: inherit; font: inherit;
}
.tk-tick::before { content: ''; position: absolute; inset: calc(var(--u) * -2.2); }  /* finger-sized target */
.tk-tick:disabled { cursor: default; }
.tk-row.is-ticked .tk-tick { background: var(--glow); border-color: var(--glow); }
.tk-row.is-ticked .tk-tick::after {
  content: ''; position: absolute; left: 30%; top: 14%; width: 26%; height: 48%;
  border: solid var(--paper); border-width: 0 calc(var(--u) * 0.6) calc(var(--u) * 0.6) 0; transform: rotate(45deg);
}
.tk-words { min-width: 0; display: flex; flex-direction: column; gap: calc(var(--u) * 0.4); }
.tk-title { font-size: var(--title); font-weight: 600; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tk-row.is-ticked .tk-title { text-decoration: line-through; opacity: 0.5; }
.tk-facts { display: flex; gap: calc(var(--u) * 2); font-size: var(--facts); line-height: 1.25; white-space: nowrap; overflow: hidden; }
.tk-facts > span { opacity: 0.62; flex: none; }
.tk-facts > .tk-list, .tk-facts > .tk-tag { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.tk-when { font-weight: 700; opacity: 0.85 !important; font-variant-numeric: tabular-nums; }
.tk-when.is-behind { color: var(--behind); opacity: 1 !important; }
.tk-row.is-late:not(.is-ticked) .tk-title { color: color-mix(in srgb, var(--behind) 35%, var(--ink)); }
.tk-undo { color: var(--glow); opacity: 1 !important; font-weight: 700; }
.tk-steps { font-variant-numeric: tabular-nums; }
.tk-more, .tk-clear { font-size: var(--facts); font-weight: 600; opacity: 0.55; padding-top: calc(var(--u) * 1.4); }
.tk-clear { font-size: var(--title); opacity: 0.7; }
.is-off { display: none !important; }

.tk-sync { grid-area: sync; font-size: calc(var(--u) * 2.4); opacity: 0.4; text-align: right; padding-top: calc(var(--u) * 1); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tk-sync.is-stale { color: var(--pr3); opacity: 0.95; }

/* ---- setup / loading / error ---- */
.tk-card {
  grid-area: 1 / 1 / -1 / -1; align-self: center; justify-self: center;
  display: flex; flex-direction: column; gap: calc(var(--u) * 2); max-width: 46em; text-align: center; align-items: center;
}
.tk-card[hidden] { display: none; }
.tk-card b { font-size: calc(var(--u) * 6); font-weight: 800; color: var(--glow); }
.tk-card span { font-size: var(--small); line-height: 1.4; opacity: 0.78; }
.tk[data-state="setup"] .tk-glance, .tk[data-state="setup"] .tk-plan, .tk[data-state="setup"] .tk-sync,
.tk[data-state="error"] .tk-glance, .tk[data-state="error"] .tk-plan, .tk[data-state="error"] .tk-sync,
.tk[data-state="loading"] .tk-glance, .tk[data-state="loading"] .tk-plan, .tk[data-state="loading"] .tk-sync { display: none; }

/* ---- wide slots: tasks flow down into two or three columns ---- */
@media (min-aspect-ratio: 11/5) and (min-height: 451px) {
  :root { --glance-w: 25%; }
  .tk-rows { display: block; height: 100%; column-count: 2; column-fill: auto; column-gap: calc(var(--u) * 6); }
  .tk-rows > li { break-inside: avoid; }
  .tk-band { break-after: avoid; }
  .tk-band:first-child, .tk-row + .tk-band { padding-top: calc(var(--u) * 1.6); }
  .tk-rows > li:first-child { padding-top: 0; }
}
@media (min-aspect-ratio: 3/1) and (min-height: 451px) {
  :root { --glance-w: 20%; }
  .tk-rows { column-count: 3; }
}

/* ---- tall slots: the glance sits on top ---- */
@media (max-aspect-ratio: 11/10) {
  .tk { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr) auto; grid-template-areas: "glance" "plan" "sync"; gap: var(--gap) 0; }
  .tk-glance { justify-content: flex-start; }
  .tk-hero { flex-direction: row; align-items: baseline; gap: calc(var(--u) * 3); }
  .tk-hero span { font-size: calc(var(--u) * 4.6); }
}

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
