/* Sky at the exact time: the time at screen scale over the sky. The sky is a WebGL canvas, the stars a 2D canvas. */

@font-face {
  font-family: 'Roboto Flex';
  src: url('../font/RobotoFlex-100-1000.woff2') format('woff2');
  font-weight: 100 1000;
  font-display: block;
}

/* The site's Roboto Flex: 169 Latin characters. Two extra subsets, downloaded only if the page uses those characters
   (unicode-range): Latin Extended (© « » Turkish, Romanian…) and Cyrillic. OFL license, next to the files. */
@font-face {
  font-family: 'Roboto Flex'; src: url('../font/RobotoFlex-latin-ext.woff2') format('woff2'); font-weight: 100 1000; font-display: swap;
  unicode-range: U+00A9, U+00AB, U+00BB, U+0101, U+0103, U+011F, U+0130-0131, U+0153, U+015E-015F, U+0219, U+02BB, U+03BF, U+03C0, U+03C7, U+1ED3, U+2212;
}
@font-face {
  font-family: 'Roboto Flex'; src: url('../font/RobotoFlex-cyrillic.woff2') format('woff2'); font-weight: 100 1000; font-display: swap;
  unicode-range: U+0400-04FF;
}

/* Text weight, color and shadow follow the light of the sky behind the time (light.js): here the night values */
:root {
  --time-weight: 200;
  --text-weight: 300;
  --text: #f2f5ff;
  --text-shadow: 0 2px 28px rgba(12, 16, 24, 0.24), 0 0 2px rgba(12, 16, 24, 0.13);
  --time-spacing: -0.05em;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --font-text: 'Roboto Flex', system-ui, sans-serif;
}
/* Japanese, Korean, Chinese and Arabic: the system font after Roboto Flex (0 KB extra); weight follows the light in steps
   instead of continuously. The big time is digits only: it stays in Roboto Flex, continuous (option A from the SEO chat). */
:root:lang(ja) { --font-text: 'Roboto Flex', 'Hiragino Sans', 'Noto Sans JP', 'Yu Gothic', sans-serif; }
:root:lang(ko) { --font-text: 'Roboto Flex', 'Apple SD Gothic Neo', 'Noto Sans KR', 'Malgun Gothic', sans-serif; }
:root:lang(zh-hant) { --font-text: 'Roboto Flex', 'PingFang TC', 'Noto Sans TC', 'Microsoft JhengHei', sans-serif; }
:root:lang(zh-hans) { --font-text: 'Roboto Flex', 'PingFang SC', 'Noto Sans SC', 'Microsoft YaHei', sans-serif; }
:root:lang(ar) { --font-text: 'Roboto Flex', 'Geeza Pro', 'Noto Sans Arabic', 'Segoe UI', sans-serif; }

*, *::before, *::after { box-sizing: border-box; }

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

body {
  background: #0a0a0a;
  color: var(--text);
  font-family: var(--font-text);
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  cursor: grab;
}
body.dragging { cursor: grabbing; }

canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  opacity: 0;
}
#sky { z-index: 0; }
#stars { z-index: 1; }
#weather { z-index: 1; }     /* clouds, fog, rain: above the stars (comes later in the DOM), below the text */
body.ready canvas { opacity: 1; transition: opacity 1.4s ease-out; }

#scene {
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  /* anti-image-retention (screens on for hours): main.js moves all text by one pixel every 150 s along a 3 px circle */
  translate: var(--drift-x, 0px) var(--drift-y, 0px);
  transition: translate 2s ease-in-out;
}

/* --- the time --- */
.time-block {
  position: absolute;
  left: 0; right: 0;
  top: 40%;
  transform: translateY(-50%);
  text-align: center;
  padding: 0 16px;
  text-shadow: var(--text-shadow);
}
.date {
  margin: 0 0 0.9em;
  font-size: clamp(0.72rem, 0.55rem + 0.55vw, 1rem);
  font-weight: var(--text-weight);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  opacity: var(--text-opacity, 0.9);
}
#time {
  display: block;
  font-family: 'Roboto Flex', system-ui, sans-serif;
  direction: ltr; unicode-bidi: isolate;            /* the time stays in Latin digits, left to right, even in Arabic */
  font-size: clamp(4.6rem, 17vw, 19rem);
  font-weight: var(--time-weight);
  letter-spacing: var(--time-spacing);
  line-height: 0.9;
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'tnum' 1;
  white-space: nowrap;
}
#ss {
  position: relative;
  font-size: 0.34em;
  letter-spacing: -0.02em;
  margin-left: 0.14em;
  opacity: 0.82;
}
/* temperature above the seconds (?temp=clock, 14/11/2026): same light as the time, outside the layout so the time does not move */
#ss[data-temp]::before {
  content: attr(data-temp);
  position: absolute; left: 0.04em; bottom: 100%;
  font-size: 0.52em; line-height: 1; letter-spacing: 0; white-space: nowrap;
}
/* 12-hour clock (15/11/2026): «AM»/«PM» in the same place, above the seconds */
#ss[data-period]::after {
  content: attr(data-period);
  position: absolute; left: 0.04em; bottom: 100%;
  font-size: 0.52em; line-height: 1; letter-spacing: 0.02em; white-space: nowrap;
}
/* the temperature after the date switches °C and °F (ui.js) */
.date .temp {
  margin: 0; padding: 0; font: inherit; color: inherit; letter-spacing: inherit; text-transform: inherit; text-shadow: inherit;
  background: none; border: 0; cursor: pointer; pointer-events: auto; -webkit-tap-highlight-color: transparent;
}
.date .temp:hover { text-decoration: underline dotted; text-underline-offset: 3px; }
.date .temp:focus-visible { outline: 1px solid currentColor; outline-offset: 2px; }

/* --- footer --- */
/* smaller than before (EM, 11/11/2026: «i numeretti in basso sono ancora troppo grandi»): about 9 px on a phone, 11 px on a computer,
   and never heavier than 600 even in full daylight */
.footer {
  position: absolute;
  left: 24px; right: 24px; bottom: 20px;
  font-size: clamp(0.56rem, 0.5rem + 0.18vw, 0.68rem);
  font-weight: min(var(--text-weight), 600);
  line-height: 1.35;
  letter-spacing: 0.06em;
  opacity: var(--text-opacity, 0.9);
  text-shadow: var(--text-shadow);
}
.footer p { margin: 0; }
/* one row: place left, sunrise and sunset right, on the same baseline */
.footer-row { display: flex; justify-content: space-between; align-items: baseline; gap: 24px; }
.footer-row > * { white-space: nowrap; }
.footer .seg { display: inline; }
/* not enough room (ui.js measures it): each side on two lines, side by side and aligned row by row;
   the coordinates step aside when the place has a name (they stay in the tooltip) */
.footer.compact .footer-row { align-items: flex-start; gap: 16px; }
.footer.compact .seg { display: block; }
.footer.compact .sep, .footer.compact .seg.optional { display: none; }
/* the place name is a button that shares this sky (navigator.share, otherwise copies the link) */
.footer .place {
  margin: 0; font: inherit; color: inherit; letter-spacing: inherit; text-shadow: inherit; text-align: start;
  background: none; border: 0; cursor: pointer; pointer-events: auto; -webkit-tap-highlight-color: transparent;
}
.footer .place:hover { text-decoration: underline dotted; text-underline-offset: 3px; }
.footer .place:focus-visible { outline: 1px solid currentColor; outline-offset: 2px; }
.footer .right { text-align: end; }
/* credits (terrain, stars, weather, places): required by the licenses but secondary; on their own line, smaller (EM, 10/11/2026) */
.footer .credits { font-size: 0.8em; line-height: 1.35; text-align: end; width: fit-content; max-width: calc(100% + 16px); }

/* the light changes gently: a one-second transition on weight, spacing, color and shadow */
#time, .date, .footer, .footer p, .footer .place { transition: font-weight 1s linear, letter-spacing 1s linear, color 1s ease, text-shadow 1s ease, background-color 1s ease; }
/* date and footer: color decided block by block from the sky behind (ui.js); the veil appears only if the color is not enough */
.date, .footer p, .footer .place { border-radius: 6px; padding: 2px 8px; margin-left: -8px; margin-right: -8px; }
.footer .right { margin-inline-start: 0; margin-inline-end: -8px; }
.footer p.credits { margin-block: 3px 0; margin-inline: auto -8px; }
#credits { opacity: 0.8; }
.date { display: inline-block; margin-left: 0; margin-right: 0; }


/* --- «enter» button (phase 2): position, compass and gyroscope; color and veil are decided by ui.js as for the footer --- */
.enter-button {
  position: absolute; left: 50%; bottom: max(16vh, 92px); transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 9px 22px 8px; border-radius: 999px; border: 1px solid currentColor; background: none;
  color: var(--text); font: inherit; font-size: clamp(0.78rem, 0.7rem + 0.3vw, 0.95rem); font-weight: var(--text-weight);
  letter-spacing: 0.16em; text-transform: uppercase; text-shadow: var(--text-shadow);
  cursor: pointer; pointer-events: auto; -webkit-tap-highlight-color: transparent;
  opacity: 0; transition: color 1s ease, text-shadow 1s ease, background-color 1s ease, opacity 0.4s ease;
}
.enter-button small { font-size: 0.72em; letter-spacing: 0.05em; text-transform: none; opacity: 0.85; }
.enter-button[hidden] { display: none; }
.enter-button:focus-visible { outline: 1px solid currentColor; outline-offset: 3px; }
@keyframes compare { from { opacity: 0; translate: 0 10px; } to { opacity: var(--text-opacity, 0.9); translate: 0 0; } }
body.ready .enter-button { animation: compare 0.9s var(--ease) 1.1s both; }
body.ready .enter-button.gone { animation: none; opacity: 0; pointer-events: none; }

/* --- capsule, top right (11/11/2026): «app · screensaver» and the menu. Color and veil from the sky behind it (ui.js, like the footer).
   Visible for 4 s after a move, a tap or a key (body.controls-on), then it fades; never while the menu is open. Calm motion:
   in at once (0.2 s), out slowly (0.6 s). The menu itself is css/menu.css, loaded with it. --- */
.capsule {
  position: absolute; top: max(14px, env(safe-area-inset-top)); inset-inline-end: max(14px, env(safe-area-inset-right));
  display: flex; align-items: center; height: 32px; padding: 0 3px; border-radius: 999px;
  border: 1px solid color-mix(in srgb, currentColor 30%, transparent);
  color: var(--text); font-size: 12px; font-weight: min(var(--text-weight), 600); letter-spacing: 0.04em; text-shadow: var(--text-shadow);
  opacity: 0; pointer-events: none;
  transition: opacity 600ms cubic-bezier(0.65, 0, 0.35, 1), color 1s var(--ease), text-shadow 1s var(--ease), background-color 1s var(--ease);
}
.capsule[hidden] { display: none; }
body.ready.controls-on .capsule { opacity: var(--text-opacity, 0.9); pointer-events: auto;
  transition: opacity 200ms cubic-bezier(0.22, 1, 0.36, 1), color 1s var(--ease), text-shadow 1s var(--ease), background-color 1s var(--ease); }
body.menu-open .capsule, body.snapshot .capsule { opacity: 0; pointer-events: none; }
.capsule button {
  appearance: none; border: 0; background: none; color: inherit; font: inherit; letter-spacing: inherit; cursor: pointer;
  display: flex; align-items: center; height: 26px; padding: 0 11px; border-radius: 999px; white-space: nowrap;
  -webkit-tap-highlight-color: transparent; transition: background-color 160ms cubic-bezier(0.22, 1, 0.36, 1), transform 160ms cubic-bezier(0.22, 1, 0.36, 1);
}
.capsule #capsule-menu { padding: 0 10px; }
.capsule-sep { width: 1px; height: 14px; background: currentColor; opacity: 0.3; }
@media (hover: hover) and (pointer: fine) { .capsule button:hover { background: color-mix(in srgb, currentColor 14%, transparent); } }
.capsule button:active { transform: scale(0.97); }
.capsule button:focus-visible { outline: 1px solid currentColor; outline-offset: 1px; }
@media (max-width: 640px) { .capsule { height: 30px; font-size: 11.5px; } }
@media (prefers-reduced-motion: reduce) { .capsule button:active { transform: none; } }

/* place change (GPS): the sky fades out and comes back with the new place */
body.ready.place-change canvas { opacity: 0; transition: opacity 0.45s ease-in; }

/* --- entrance: background, then time, date and footer in cascade --- */
.time-block > *, .footer > * { opacity: 0; }
@keyframes entra {
  from { opacity: 0; transform: translateY(22px); filter: blur(10px); }
  to   { opacity: 1; transform: translateY(0);    filter: blur(0); }
}
body.ready #time  { animation: entra 0.9s var(--ease) 0.15s both; }
body.ready .date { animation: entra 0.9s var(--ease) 0.30s both; }
body.ready .footer > * { animation: entra 0.9s var(--ease) 0.45s both; }

@media (prefers-reduced-motion: reduce) {
  body.ready canvas { transition: none; }
  body.ready #time, body.ready .date, body.ready .footer > *, body.ready .enter-button { animation: none; opacity: 1; }
}

/* --- phone --- */
@media (max-width: 600px) {
  .time-block { top: 36%; }
  .footer { left: 16px; right: 16px; bottom: max(14px, env(safe-area-inset-bottom)); }
  .enter-button { bottom: 132px; }
}
@media (max-height: 420px) {
  .time-block { top: 42%; }
  #time { font-size: clamp(3.4rem, 22vh, 9rem); }
}

/* --- snapshot (?snapshot): no fades, for automated screenshots --- */
body.snapshot canvas, body.snapshot .time-block > *, body.snapshot .footer > * {
  animation: none !important; transition: none !important; opacity: 1 !important;
}
body.snapshot .footer, body.snapshot #time, body.snapshot .date { transition: none !important; }
body.snapshot .date, body.snapshot .footer > * { opacity: var(--text-opacity, 0.9) !important; }

/* --- debug (?debug) --- */
#debug {
  direction: ltr; text-align: left;
  position: fixed;
  right: 12px; top: 12px;
  z-index: 4;
  margin: 0;
  padding: 8px 10px;
  font: 11px/1.45 ui-monospace, Menlo, monospace;
  color: #fff;
  background: rgba(0, 0, 0, 0.55);
  border-radius: 6px;
  white-space: pre;
  pointer-events: none;
}
/* on the phone the long lines went off screen: wrapped, full width, scrollable */
@media (max-width: 600px) {
  #debug {
    left: 8px; right: 8px; top: max(8px, env(safe-area-inset-top));
    font-size: 9px; white-space: pre-wrap; overflow-wrap: anywhere;
    max-height: 70vh; overflow: auto; pointer-events: auto; touch-action: pan-y;
  }
}

/* --- no WebGL: any gradient, just so it does not stay black --- */
body.no-webgl { background: linear-gradient(#1b2a4a, #6b86b3 60%, #2a2a2a 60.2%); }
