:root {
  --bg: #1b1b1b;
  --fg: #ededeb;
  --muted: #8c8c89;
  --line: #3b3b3a;
  --ease: cubic-bezier(0.22, 1, 0.36, 1); /* long, soft landing */
  --swift: cubic-bezier(0.65, 0, 0.35, 1); /* symmetrical, for things that travel */
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme='dark']) {
    --bg: #f3f2ee;
    --fg: #1b1b1a;
    --muted: #8a8984;
    --line: #d6d4ce;
    color-scheme: light;
  }
}
:root[data-theme='light'] {
  --bg: #f3f2ee;
  --fg: #1b1b1a;
  --muted: #8a8984;
  --line: #d6d4ce;
  color-scheme: light;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

html { background: var(--bg); }
body {
  min-height: 100dvh;
  background: var(--bg);
  color: var(--fg);
  font: 300 16px/1.4 'Helvetica Neue', Helvetica, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.5s var(--ease), color 0.5s var(--ease);
}

main {
  position: relative;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: calc(env(safe-area-inset-top) + clamp(24px, 5vw, 64px)) clamp(20px, 5vw, 72px)
    calc(env(safe-area-inset-bottom) + 20px);
}

.label {
  font-size: 10.5px;
  font-weight: 400;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--fg);
  font-variant-numeric: tabular-nums;
}

header {
  padding: 0 64px clamp(20px, 3vw, 36px) 0; /* room for the account circle on phones */
  margin-bottom: clamp(24px, 3vw, 40px);
  border-bottom: 1px solid var(--line);
}
/* account circle (and, on desktop, the info card beside it) */
.aside {
  position: absolute;
  z-index: 5;
  top: calc(env(safe-area-inset-top) + clamp(24px, 5vw, 64px));
  right: clamp(20px, 5vw, 72px);
}
h1 {
  font-size: clamp(30px, 7vw, 76px);
  font-weight: 200;
  letter-spacing: 0.2em;
  line-height: 1;
  text-transform: uppercase;
  margin: 0 -0.2em 14px -0.04em;
}
#clock { margin-left: 1.4em; }

/* Desktop: everything at 80%, edge to edge, with the ambient readouts shown. */
@media (min-width: 880px) {
  body { zoom: 0.8; }
  main, body { min-height: calc(100dvh / 0.8); }
  #clock { display: none; } /* local time has its own readout */
  header { padding-right: 0; }
  /* the right column starts level with the day name: card, account circle, then the week */
  .aside {
    position: relative;
    top: auto;
    right: auto;
    display: flex;
    align-items: flex-start;
    gap: 22px;
    margin-bottom: clamp(24px, 3vw, 40px);
  }
}

/* ---------- account: one cell divides into two, then opens ---------- */

#me {
  --cell: 48px;
  --bud: 40px;
  --reach: 46px; /* how far the new cell travels */
  position: relative;
  flex: none;
  width: var(--cell);
  height: var(--cell);
}
#me .goo {
  position: absolute;
  top: -40px;
  right: -40px;
  width: 330px;
  height: 330px;
  filter: url(#goo);
  pointer-events: none;
}
#me .goo > * {
  position: absolute;
  background: var(--fg);
  transition: background-color 0.5s var(--ease);
}
#me .cell { border-radius: 50%; }
#me .cell.a { top: 40px; right: 40px; width: var(--cell); height: var(--cell); }
#me .cell.b {
  top: 44px;
  right: 44px;
  width: var(--bud);
  height: var(--bud);
  transition: transform 0.7s var(--swift), background-color 0.5s var(--ease);
}
#me .sheet {
  top: 100px;
  right: 40px;
  width: 190px;
  height: 154px;
  border-radius: 26px;
  transform-origin: calc(100% - 70px) -32px; /* grows out of the new cell */
  transform: scale(0) rotate(-35deg);
  transition: transform 0.45s var(--swift), background-color 0.5s var(--ease);
}

#me .glyph {
  position: absolute;
  top: 4px;
  right: 4px;
  width: var(--bud);
  height: var(--bud);
  display: grid;
  place-items: center;
  color: var(--bg);
  opacity: 0;
  transform: rotate(180deg) scale(0.4);
  transition: transform 0.6s var(--swift), opacity 0.25s;
  pointer-events: none;
}

#avatar {
  all: unset;
  box-sizing: border-box;
  position: absolute;
  inset: 4px;
  border-radius: 50%;
  overflow: hidden;
  cursor: pointer;
  display: grid;
  place-items: center;
  background: var(--bg) center / cover no-repeat;
  color: var(--fg);
  font-size: 15px;
  font-weight: 400;
  text-transform: uppercase;
  transition: transform 0.5s var(--ease), background-color 0.5s var(--ease);
}
#avatar:focus-visible { outline: 1px solid var(--bg); outline-offset: -4px; }
#avatar:empty::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--muted); }
#avatar.has-photo::before { display: none; }

#menu {
  position: absolute;
  top: 60px;
  right: 0;
  width: 190px;
  padding: 8px;
  display: grid;
  gap: 2px;
  visibility: hidden;
  transition: visibility 0s 0.3s;
}
#menu button {
  all: unset;
  box-sizing: border-box;
  height: 44px;
  padding: 0 16px;
  border-radius: 18px;
  display: flex;
  align-items: center;
  cursor: pointer;
  color: var(--bg);
  font-size: 15px;
  font-weight: 400;
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.2s, transform 0.3s var(--ease), background-color 0.3s var(--ease), padding 0.4s var(--ease);
}
#menu button:hover,
#menu button:focus-visible {
  background: color-mix(in srgb, var(--bg) 12%, transparent);
  padding-left: 20px;
}

/* open: 1) the cell divides  2) the arrow turns and the sheet unrolls  3) the options settle in */
#me.open .cell.b { transform: translateX(calc(var(--reach) * -1)); }
#me.open .glyph {
  opacity: 1;
  transform: translateX(calc(var(--reach) * -1)) rotate(90deg);
  transition: transform 0.7s var(--swift), opacity 0.4s 0.3s;
}
#me.open .sheet {
  transform: none;
  transition: transform 0.75s var(--ease) 0.45s, background-color 0.5s var(--ease);
}
#me.open #avatar { transform: scale(0.94); }
#me.open #menu { visibility: visible; transition-delay: 0s; }
#me.open #menu button {
  opacity: 1;
  transform: none;
  transition: opacity 0.5s, transform 0.7s var(--ease), background-color 0.3s var(--ease), padding 0.4s var(--ease);
  transition-delay: 0.75s, 0.75s, 0s, 0s;
}
#me.open #menu button:nth-child(2) { transition-delay: 0.82s, 0.82s, 0s, 0s; }
#me.open #menu button:nth-child(3) { transition-delay: 0.89s, 0.89s, 0s, 0s; }

/* ---------- lists ---------- */

.cols {
  flex: 1;
  display: grid;
  gap: clamp(36px, 4vw, 56px) clamp(36px, 6vw, 96px);
  align-content: start;
  padding: 0 0 40px;
}
@media (min-width: 880px) {
  .cols { grid-template-columns: 1fr 1fr; }
}

h2.label { margin-bottom: 14px; }
h2 span { color: var(--fg); margin-left: 0.6em; }
#week-h span { margin-left: 1.2em; }

.tasks { list-style: none; }

/* A finished task leaves in two unhurried beats: its text drifts away and fades,
   then the row closes up so the list settles into the space. */
.tasks li {
  display: grid;
  grid-template-rows: 1fr;
  transition: grid-template-rows 0.7s var(--swift);
}
.tasks li.entering { grid-template-rows: 0fr; }
.tasks li.leaving { grid-template-rows: 0fr; transition-delay: 0.35s; }
.tasks li.entering button,
.tasks li.leaving button { opacity: 0; transform: translateX(14px); border-bottom-color: transparent; }
.tasks li.entering button { transform: translateY(8px); }
.tasks .row { min-height: 0; overflow: hidden; }

.tasks button {
  all: unset;
  box-sizing: border-box;
  display: flex;
  align-items: baseline;
  gap: 14px;
  width: 100%;
  padding: 15px 0;
  border-bottom: 1px solid var(--line);
  font-size: clamp(19px, 2.1vw, 24px);
  letter-spacing: -0.01em;
  cursor: pointer;
  transition: border-color 0.5s var(--ease), opacity 0.6s var(--swift), transform 0.75s var(--swift);
}
.tasks button::before {
  content: '';
  flex: none;
  width: 0.62em;
  height: 0.62em;
  border: 1px solid var(--muted);
  border-radius: 50%;
  transform: translateY(-0.04em);
  box-shadow: inset 0 0 0 0.31em var(--bg); /* a filled dot hidden behind a full inset ring */
  background: var(--fg);
  transition: box-shadow 0.45s var(--ease), border-color 0.3s var(--ease), transform 0.45s var(--ease);
}
.tasks .title {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
  transition: transform 0.5s var(--ease), color 0.5s var(--ease);
}
/* the strike is drawn across rather than switched on */
.tasks .title span {
  background: linear-gradient(currentColor, currentColor) no-repeat 0 58% / 0% 1px;
  transition: background-size 0.5s var(--ease);
}
/* description: smaller than the title, same full-strength colour */
.tasks .note {
  display: block;
  max-width: 62ch;
  margin-top: 5px;
  font-size: 14px;
  font-weight: 400;
  line-height: 1.45;
  letter-spacing: 0;
  white-space: pre-line;
  color: var(--fg);
  transition: color 0.5s var(--ease);
}
.tasks li.done .note { color: inherit; }
.tasks .meta { flex: none; transition: opacity 0.4s var(--ease); }
.tasks .meta.day { color: var(--fg); }

@media (hover: hover) {
  .tasks button:hover { border-bottom-color: var(--muted); }
  .tasks button:hover::before { border-color: var(--fg); box-shadow: inset 0 0 0 0.17em var(--bg); }
  .tasks button:hover .title { transform: translateX(3px); }
}
.tasks button:focus-visible { outline: 1px solid var(--muted); outline-offset: -1px; }
.tasks button:active::before { transform: translateY(-0.04em) scale(0.85); }

.tasks li.done button::before { border-color: var(--fg); box-shadow: inset 0 0 0 0 var(--bg); }
.tasks li.done .title { color: var(--muted); transform: none; }
.tasks li.done .title span { background-size: 100% 1px; }
.tasks li.done .meta { opacity: 0.3; }

.quiet { color: var(--fg); font-size: clamp(19px, 2.1vw, 24px); padding: 15px 0; animation: fade 0.8s var(--ease) both; }
@keyframes fade { from { opacity: 0; } }

/* ---------- readouts: label over value ---------- */

.readouts { display: grid; gap: 24px; }
.readouts dt { margin-bottom: 6px; }
.readouts dd { font-size: clamp(22px, 2.4vw, 30px); font-weight: 200; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; white-space: nowrap; }
.readouts dd small { font-size: 0.5em; font-weight: 400; letter-spacing: 0.08em; color: var(--fg); margin-left: 0.6em; }
.readouts dd.sub { font-size: 10.5px; font-weight: 400; letter-spacing: 0.16em; margin-top: 8px; }
.readouts dd .link { font-size: 0.6em; }

#stats {
  grid-template-columns: 1fr 1fr;
  padding: 24px 0 28px;
  border-top: 1px solid var(--line);
}
@media (min-width: 640px) {
  #stats { grid-template-columns: repeat(4, 1fr); }
}

/* weather, sun, time and city clocks: desktop only, one outlined card */
#ambient { display: none; }
@media (min-width: 880px) {
  #ambient {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 24px 34px;
    border: 1px solid var(--line);
    border-radius: 22px;
    padding: 22px 26px 24px;
    animation: fade 0.8s var(--ease) both;
  }
  #ambient .wide { flex: 1 1 210px; } /* weather on the left; the rest sits to its right */
  #ambient dd { font-size: 26px; }
  #ambient dd.sub { font-size: 10.5px; white-space: normal; line-height: 1.7; }

  /* city clocks share their own row along the bottom of the card */
  #clocks {
    flex: 0 0 100%;
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr)); /* six always fit on one row; dials shrink if they must */
    gap: 16px;
    padding-top: 22px;
    border-top: 1px solid var(--line);
  }

  /* a city clock: a dial with the time written inside it, the city underneath */
  #ambient .city { display: flex; flex-direction: column-reverse; justify-content: flex-end; align-items: center; gap: 9px; } /* dials stay level whatever the label height */
  #ambient .city dt { margin: 0; text-align: center; }
  #ambient .city dt small { display: block; margin: 4px 0 0; font-size: 1em; letter-spacing: inherit; }
  .dial { display: block; width: 100%; max-width: 92px; height: auto; aspect-ratio: 1; margin: 0 auto; overflow: visible; }
  .dial circle, .dial line { fill: none; stroke: var(--fg); stroke-linecap: round; vector-effect: non-scaling-stroke; }
  .dial circle { stroke-width: 1; }
  .dial .tick { stroke-width: 1; }
  .dial .hour { stroke-width: 2.25; }
  .dial .minute { stroke-width: 1.25; }
  .dial text {
    fill: var(--fg);
    font-size: 15px;
    font-weight: 400;
    letter-spacing: 0.04em;
    text-anchor: middle;
    font-variant-numeric: tabular-nums;
    paint-order: stroke; /* a halo in the page colour keeps the digits clear of a passing hand */
    stroke: var(--bg);
    stroke-width: 5px;
    stroke-linejoin: round;
  }
}

footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 46px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}
/* theme switch: a solid half-filled circle that flips over on hover */
#theme {
  all: unset;
  cursor: pointer;
  width: 14px;
  height: 14px;
  border: 1px solid var(--fg);
  border-radius: 50%;
  background: linear-gradient(90deg, var(--fg) 50%, transparent 50%);
  transition: transform 0.8s var(--ease), border-color 0.5s var(--ease);
}
#theme:hover, #theme:focus-visible { transform: rotate(180deg); }
#theme:focus-visible { outline: 1px solid var(--muted); outline-offset: 4px; }
:root[data-theme='light'] #theme { transform: rotate(180deg); }
:root[data-theme='light'] #theme:hover, :root[data-theme='light'] #theme:focus-visible { transform: rotate(360deg); }

/* ---------- panels ---------- */

dialog {
  margin: auto;
  max-height: calc(100dvh - 48px);
  overflow-y: auto;
  width: min(360px, calc(100vw - 32px));
  padding: 28px;
  border: 0;
  border-radius: 28px;
  background: var(--fg);
  color: var(--bg);
  opacity: 0;
  transform: translateY(12px) scale(0.97);
  transition: opacity 0.4s var(--ease), transform 0.5s var(--ease), overlay 0.5s allow-discrete, display 0.5s allow-discrete;
}
dialog[open] { opacity: 1; transform: none; }
@starting-style { dialog[open] { opacity: 0; transform: translateY(12px) scale(0.97); } }
dialog::backdrop {
  background: color-mix(in srgb, var(--bg) 70%, transparent);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  opacity: 0;
  transition: opacity 0.5s var(--ease), overlay 0.5s allow-discrete, display 0.5s allow-discrete;
}
dialog[open]::backdrop { opacity: 1; }
@starting-style { dialog[open]::backdrop { opacity: 0; } }

dialog .label { color: var(--bg); margin: 22px 0 10px; }
dialog h2.label { margin-top: 0; }
dialog input[type='text'] {
  all: unset;
  box-sizing: border-box;
  width: 100%;
  font-size: 20px;
  padding: 6px 0;
  border-bottom: 1px solid color-mix(in srgb, var(--bg) 35%, transparent);
  transition: border-color 0.3s;
}
dialog input[type='text']:focus { border-color: var(--bg); }
dialog input::placeholder { color: color-mix(in srgb, var(--bg) 40%, transparent); }
#d-settings input[type='text'] { font-size: 15px; margin-bottom: 8px; }
#place-now { font-size: 20px; margin-bottom: 6px; }
.results { display: grid; }
.results button, #cities button {
  all: unset;
  box-sizing: border-box;
  cursor: pointer;
  padding: 8px 12px;
  margin: 0 -12px;
  border-radius: 12px;
  font-size: 15px;
  transition: background-color 0.3s var(--ease);
}
.results button:hover, .results button:focus-visible, #cities button:hover { background: color-mix(in srgb, var(--bg) 10%, transparent); }
.results small, #cities small { margin-left: 0.5em; }
#cities { list-style: none; display: grid; margin-bottom: 4px; }
#cities button { display: flex; justify-content: space-between; width: calc(100% + 24px); }
dialog form { margin-top: 26px; text-align: right; }
.stack { display: grid; gap: 8px; justify-items: start; }
.link {
  all: unset;
  cursor: pointer;
  font-size: 15px;
  background: linear-gradient(currentColor, currentColor) no-repeat 0 100% / 100% 1px;
  transition: background-size 0.4s var(--ease), opacity 0.3s;
}
.link:hover { background-size: 0% 1px; background-position: 100% 100%; }
.link:focus-visible { outline: 1px solid currentColor; outline-offset: 4px; }
.quiet-link { background-size: 0 1px; }
.quiet-link:hover { background-size: 100% 1px; background-position: 0 100%; }

.photo-row { display: flex; align-items: center; gap: 20px; }
.photo {
  flex: none;
  width: 84px;
  height: 84px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--bg) 14%, transparent) center / cover no-repeat;
  transition: background-color 0.3s;
}

.seg { display: flex; gap: 4px; padding: 4px; border-radius: 999px; background: color-mix(in srgb, var(--bg) 10%, transparent); }
.seg button {
  all: unset;
  flex: 1;
  text-align: center;
  padding: 8px 0;
  border-radius: 999px;
  font-size: 14px;
  cursor: pointer;
  transition: background-color 0.4s var(--ease), color 0.4s var(--ease);
}
.seg button:hover { background: color-mix(in srgb, var(--bg) 10%, transparent); }
.seg button[aria-pressed='true'] { background: var(--bg); color: var(--fg); }
.copy {
  all: unset;
  cursor: pointer;
  font: 13px/1.4 ui-monospace, 'SF Mono', Menlo, monospace;
  overflow-wrap: anywhere;
  opacity: 0.8;
  transition: opacity 0.3s;
}
.copy:hover { opacity: 1; }

/* ---------- key gate ---------- */

#gate {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 16px;
  width: 100%;
  max-width: 520px;
  box-sizing: border-box;
  margin: 0 auto;
  padding: 24px;
}
#gate input {
  all: unset;
  font-size: 20px;
  padding: 8px 0;
  border-bottom: 1px solid var(--muted);
  transition: border-color 0.3s;
}
#gate input:focus { border-color: var(--fg); }
#gate input { margin-bottom: 22px; }
.wordmark {
  font-size: 30px;
  font-weight: 200;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  text-decoration: none;
  color: var(--fg);
  margin-bottom: 44px;
}
.gate-actions { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 14px 28px; margin-top: 14px; }
.gate-actions button { white-space: nowrap; }
#gate-msg:empty { display: none; }
#me-email { font-size: 15px; margin-bottom: 8px; overflow-wrap: anywhere; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; transition-delay: 0s !important; animation: none !important; }
}

.gate-fine { margin-top: 26px; font-size: 12px; line-height: 1.5; color: var(--fg); }
.gate-fine a { color: var(--fg); text-underline-offset: 3px; }
