:root {
  --ink: #e8eff6;
  --dim: rgba(232, 239, 246, .68);
  --line: rgba(232, 239, 246, .22);
  --accent: #a9c1d6;
  --glass: rgba(10, 18, 30, .5)
}

* {
  box-sizing: border-box
}

[hidden] {
  display: none !important
}

html,
body {
  height: 100%;
  margin: 0
}

body {
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: #0b1422;
  color: var(--ink);
  font-family: 'Hanken Grotesk', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-weight: 300;
  -webkit-font-smoothing: antialiased;
  text-shadow: 0 1px 18px rgba(5, 10, 20, .35)
}

body.idle {
  cursor: none
}

#sky {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  opacity: 0;
  transition: opacity 2.4s ease
}

.ready #sky {
  opacity: 1
}

.shade {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at 50% 45%, rgba(5, 10, 20, 0) 35%, rgba(5, 10, 20, .5) 100%)
}

main {
  position: relative;
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding: max(1.1rem, env(safe-area-inset-top)) clamp(1.1rem, 3.4vw, 2.8rem) max(1.1rem, env(safe-area-inset-bottom));
  opacity: 0;
  transition: opacity 1.6s ease .9s
}

.ready main {
  opacity: 1
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: opacity .7s
}

.brand {
  font-weight: 500;
  font-size: 1rem;
  letter-spacing: .01em
}

.brand span {
  font-weight: 300;
  color: var(--dim);
  margin-left: .5rem
}

.tools {
  display: flex;
  gap: .5rem
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer
}

.icon {
  width: 2.6rem;
  height: 2.6rem;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(10, 18, 30, .25);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  position: relative;
  transition: background .25s, border-color .25s
}

.icon:hover,
.icon[aria-expanded=true] {
  background: rgba(232, 239, 246, .14);
  border-color: rgba(232, 239, 246, .45)
}

.icon svg {
  width: 1.15rem;
  height: 1.15rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round
}

.icon.live::after {
  content: "";
  position: absolute;
  top: .35rem;
  right: .35rem;
  width: .45rem;
  height: .45rem;
  border-radius: 50%;
  background: var(--accent)
}

:focus-visible {
  outline: 2px solid #cfe0ee;
  outline-offset: 3px
}

#panel {
  position: absolute;
  top: 4.4rem;
  right: clamp(1.1rem, 3.4vw, 2.8rem);
  width: min(21rem, calc(100vw - 2.2rem));
  padding: 1.1rem 1.2rem 1.2rem;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--glass);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  z-index: 5;
  transition: opacity .7s
}

#panel h2 {
  margin: 0 0 .6rem;
  font-size: .85rem;
  font-weight: 500;
  color: var(--dim)
}

#panel h2:not(:first-child) {
  margin-top: 1.1rem
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem
}

.chip {
  padding: .4rem .85rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  font-size: .88rem;
  transition: background .25s, border-color .25s
}

.chip:hover {
  border-color: rgba(232, 239, 246, .5)
}

.chip[aria-pressed=true] {
  background: rgba(232, 239, 246, .2);
  border-color: rgba(232, 239, 246, .6);
  font-weight: 500
}

.vol {
  display: flex;
  align-items: center;
  gap: .8rem;
  margin-top: .9rem;
  font-size: .88rem;
  color: var(--dim)
}

.vol input {
  flex: 1;
  accent-color: #a9c1d6
}

.hint {
  margin: 1rem 0 0;
  font-size: .8rem;
  color: var(--dim)
}

.center {
  display: grid;
  place-content: center;
  justify-items: center;
  text-align: center;
  gap: .9rem;
  min-height: 0
}

#clock {
  display: flex;
  align-items: baseline;
  justify-content: center;
  font-size: clamp(4rem, min(19vw, 32vh), 15rem);
  font-weight: 200;
  line-height: 1;
  letter-spacing: -.03em;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  user-select: none;
  background: none;
  border: 0;
  padding: 0;
  text-shadow: 0 2px 40px rgba(5, 10, 20, .4)
}

#clock .colon {
  padding: 0 .04em;
  transform: translateY(-.06em);
  animation: pulse 2s ease-in-out infinite
}

#clock small {
  font-size: .2em;
  font-weight: 300;
  letter-spacing: 0;
  margin-left: .3em;
  color: var(--dim);
  min-width: 1.6em;
  text-align: left
}

#clock #ap {
  margin-left: .1em;
  min-width: 0
}

@keyframes pulse {
  50% {
    opacity: .3
  }
}

.msg {
  margin-bottom: clamp(.2rem, 2vh, 1.2rem)
}

.msg h1 {
  margin: 0;
  font-size: clamp(1.5rem, 3.4vw, 2.6rem);
  font-weight: 400;
  letter-spacing: -.01em;
  line-height: 1.15
}

.msg p {
  margin: .45rem 0 0;
  font-size: clamp(.95rem, 1.6vw, 1.2rem);
  color: var(--dim)
}

#date {
  font-size: clamp(1.05rem, 2.3vw, 1.6rem);
  font-weight: 300;
  letter-spacing: .01em
}

#zone {
  font-size: .95rem;
  color: var(--dim)
}

.bottom {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 1.5rem 3rem;
  flex-wrap: wrap
}

.prog {
  width: min(24rem, 100%);
  display: grid;
  gap: .75rem
}

.row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: .3rem .8rem;
  font-size: .9rem
}

.row span {
  color: var(--dim)
}

.row b {
  font-weight: 400;
  font-variant-numeric: tabular-nums
}

.track {
  grid-column: 1/-1;
  height: 2px;
  background: var(--line);
  border-radius: 2px;
  overflow: hidden
}

.track i {
  display: block;
  height: 100%;
  background: var(--accent);
  transform-origin: left;
  transform: scaleX(0)
}

#worlds {
  display: flex;
  flex-wrap: wrap;
  gap: 1.2rem clamp(1.2rem, 2.6vw, 2.4rem)
}

.city {
  min-width: 5.2rem
}

.city .n {
  display: flex;
  align-items: center;
  gap: .45rem;
  font-size: .88rem;
  color: var(--dim)
}

.city .d {
  width: .5rem;
  height: .5rem;
  border-radius: 50%;
  border: 1px solid var(--ink);
  flex: none
}

.city .d.day {
  background: var(--ink)
}

.city .t {
  font-size: 1.45rem;
  font-weight: 300;
  font-variant-numeric: tabular-nums;
  margin-top: .15rem
}

.city .o {
  font-size: .8rem;
  color: var(--dim)
}

.idle .top,
.idle #panel {
  opacity: 0;
  pointer-events: none
}

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


/* ---- clock click transitions ---- */
#clock {
  transition: transform .35s cubic-bezier(.22, 1, .36, 1)
}

#clock:active {
  transform: scale(.985)
}

#clock #hh {
  text-align: right
}

#clock #hh,
#clock #mm,
#clock #ap,
.city .t {
  will-change: opacity, transform, filter
}

#wx {
  font-size: .95rem;
  color: var(--dim);
  min-height: 1.3em;
  transition: opacity 1s
}

#wx:empty {
  opacity: 0
}

@media (max-width:640px) {
  .bottom {
    flex-direction: column;
    align-items: stretch
  }

  .city {
    min-width: 4.4rem
  }

  .brand span {
    display: none
  }
}

@media (max-height:560px) {
  .prog {
    display: none
  }
}

@media (prefers-reduced-motion:reduce) {
  #clock .colon {
    animation: none
  }

  #sky,
  main {
    transition-duration: .01s;
    transition-delay: 0s
  }
}

/* ================= Mobile & touch ================= */
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%
}

body {
  overscroll-behavior: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent
}

main {
  padding-left: max(clamp(1.1rem, 3.4vw, 2.8rem), env(safe-area-inset-left));
  padding-right: max(clamp(1.1rem, 3.4vw, 2.8rem), env(safe-area-inset-right))
}

#panel {
  max-height: calc(100dvh - 5.6rem);
  overflow-y: auto;
  overscroll-behavior: contain
}

#panel:not([hidden]) {
  animation: panelIn .35s cubic-bezier(.22, 1, .36, 1)
}

@keyframes panelIn {
  from {
    opacity: 0;
    transform: translateY(-8px) scale(.98)
  }
}

@media (pointer:coarse) {
  .icon {
    width: 2.9rem;
    height: 2.9rem
  }

  .chip {
    min-height: 2.5rem;
    padding: .45rem 1rem
  }

  .vol input {
    height: 2.2rem
  }

  .kbd {
    display: none
  }
}

/* ---- phones, portrait ---- */
@media (max-width:640px) {
  main {
    padding-top: max(.8rem, env(safe-area-inset-top));
    padding-bottom: max(.9rem, env(safe-area-inset-bottom))
  }

  #clock {
    font-size: clamp(3.4rem, min(22vw, 22dvh), 9rem)
  }

  .center {
    gap: .6rem
  }

  .msg {
    margin-bottom: .3rem
  }

  .msg h1 {
    font-size: clamp(1.4rem, 7vw, 1.9rem)
  }

  .msg p {
    font-size: .95rem
  }

  #date {
    font-size: 1.05rem
  }

  #zone,
  #wx {
    font-size: .85rem
  }

  .bottom {
    gap: .9rem
  }

  .prog {
    width: 100%;
    gap: .55rem
  }

  .row {
    font-size: .82rem
  }

  /* world clocks become a swipeable strip */
  #worlds {
    flex-wrap: nowrap;
    gap: 1.4rem;
    overflow-x: auto;
    scroll-snap-type: x proximity;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    padding-right: 2rem;
    -webkit-mask-image: linear-gradient(90deg, #000 85%, transparent);
    mask-image: linear-gradient(90deg, #000 85%, transparent)
  }

  #worlds::-webkit-scrollbar {
    display: none
  }

  .city {
    flex: none;
    min-width: 0;
    scroll-snap-align: start
  }

  .city .n {
    font-size: .8rem
  }

  .city .t {
    font-size: 1.2rem
  }

  .city .o {
    font-size: .74rem
  }

  /* settings become a bottom sheet */
  #panel {
    position: fixed;
    top: auto;
    left: .75rem;
    right: .75rem;
    bottom: max(.75rem, env(safe-area-inset-bottom));
    width: auto;
    max-height: min(74dvh, 34rem);
    border-radius: 20px;
    background: rgba(10, 18, 30, .78);
    padding: 1.1rem 1.1rem 1.2rem
  }

  #panel:not([hidden]) {
    animation-name: sheetIn
  }

  .hint {
    font-size: .78rem
  }
}

@keyframes sheetIn {
  from {
    opacity: 0;
    transform: translateY(24px)
  }
}

/* ---- short phones ---- */
@media (max-width:640px) and (max-height:640px) {
  #zone {
    display: none
  }

  .msg p {
    display: none
  }

  #clock {
    font-size: clamp(3rem, min(20vw, 18dvh), 9rem)
  }
}

@media (max-width:360px) {
  #clock {
    font-size: clamp(3rem, 20vw, 9rem)
  }

  .brand {
    display: none
  }
}

/* ---- phones, landscape ---- */
@media (max-height:480px) and (orientation:landscape) {
  main {
    padding-top: max(.6rem, env(safe-area-inset-top));
    padding-bottom: max(.6rem, env(safe-area-inset-bottom))
  }

  .top {
    position: absolute;
    top: max(.6rem, env(safe-area-inset-top));
    left: max(1rem, env(safe-area-inset-left));
    z-index: 6
  }

  .icon {
    width: 2.4rem;
    height: 2.4rem
  }

  .center {
    gap: .35rem;
    grid-row: 1/3
  }

  .msg p,
  #zone {
    display: none
  }

  .msg {
    margin-bottom: 0
  }

  .msg h1 {
    font-size: 1.3rem
  }

  #clock {
    font-size: clamp(3rem, min(15vw, 30dvh), 9rem)
  }

  #date {
    font-size: 1rem
  }

  .bottom {
    grid-row: 3;
    flex-wrap: nowrap
  }

  #worlds {
    gap: 1.2rem
  }

  .city .t {
    font-size: 1.1rem
  }

  .city .o {
    display: none
  }

  #panel {
    position: fixed;
    top: .6rem;
    right: max(.75rem, env(safe-area-inset-right));
    left: auto;
    bottom: .6rem;
    width: min(22rem, 60vw);
    max-height: none
  }

  #panel:not([hidden]) {
    animation-name: panelIn
  }
}

/* keep the grid from growing wider than the screen */
main {
  grid-template-columns: minmax(0, 1fr)
}

.bottom,
.center,
.top {
  min-width: 0
}

@media (max-width:640px) {
  #worlds {
    max-width: 100%
  }
}
