/*
 * 時計の画面の配置。色はテーマのCSS変数 (--bg、--bg2、--ink、--ink-dim、--accent-1) だけで塗る。
 * 根拠は docs/design.md の2節から4節にある。
 */

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

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

body {
  background: var(--bg);
  color: var(--ui-text);
  font-family: var(--ui-font);
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* 時計の画面。中央を --bg、端を --bg2 にする。数字の下地と同じ --bg が数字の後ろに来る */
#stage {
  position: fixed;
  inset: 0;
  overflow: hidden;
  display: grid;
  place-items: center;
  background: radial-gradient(120% 100% at 50% 45%, var(--bg) 30%, var(--bg2) 100%);
  color: var(--ink);
}

body.is-idle #stage {
  cursor: none;
}

#fx-back,
#fx-front {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
}

#fx-back {
  z-index: var(--z-fx-back);
}

#fx-front {
  z-index: var(--z-fx-front);
}

/* 時計の領域。焼き付きの対策で、--shift-x と --shift-y だけ位置をずらす */
#clock-region {
  position: relative;
  z-index: var(--z-clock);
  isolation: isolate;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: calc(var(--slot-font, 20px) * 0.6);
  max-width: 100%;
  padding: var(--space-4);
  translate: var(--shift-x, 0px) var(--shift-y, 0px);
}

/*
 * 数字の下地。後ろの層に粒子が描かれても、数字の背後が --bg のまま保たれるようにする (design.md C1)。
 * 動かない放射状のグラデーションで、中央は不透明、外側に向けて透明にする。
 */
#clock-region::before {
  content: "";
  position: absolute;
  inset: -22% -16%;
  z-index: -1;
  pointer-events: none;
  background: radial-gradient(
    closest-side,
    var(--bg) 0%,
    var(--bg) 64%,
    color-mix(in oklab, var(--bg) 55%, transparent) 84%,
    transparent 100%
  );
}

/* 時計の上下の枠 */
#slot-top,
#slot-bottom {
  color: var(--ink-dim);
  font-size: var(--slot-font, 20px);
  line-height: var(--lh-tight);
  font-variant-numeric: tabular-nums;
  text-align: center;
  max-width: 100%;
}

#visit-caption:empty {
  display: none;
}

/* ------------------------------------------------------------------------- */
/* 時刻                                                                      */
/* ------------------------------------------------------------------------- */

#clock {
  position: relative;
  color: var(--ink);
  line-height: 1;
  font-family: var(--clock-family);
  font-weight: var(--clock-weight, 400);
  font-variant-numeric: tabular-nums lining-nums;
  font-feature-settings: "tnum" 1, "lnum" 1;
  letter-spacing: 0;
  max-width: 100%;
}

/* 書体。外部のフォントは読み込まず、端末に入っている書体の組み合わせで作る */
#clock[data-font="standard"] {
  /* 字形の開いたサンセリフ (design.md D2) */
  --clock-family: "Segoe UI Variable Display", "Segoe UI", -apple-system, BlinkMacSystemFont, "SF Pro Display", "Noto Sans", "Roboto", "Ubuntu", "DejaVu Sans", "Hiragino Sans", "Yu Gothic UI", sans-serif;
}

#clock[data-font="mono"] {
  --clock-family: ui-monospace, "Cascadia Mono", "SF Mono", "JetBrains Mono", Menlo, Consolas, "Noto Sans Mono", "DejaVu Sans Mono", monospace;
}

#clock[data-font="din"] {
  --clock-family: "Bahnschrift", "D-DIN", "DIN Alternate", "DIN Next", "Barlow", "Roboto Condensed", "Arial Narrow", "DejaVu Sans Condensed", sans-serif;
}

#clock[data-font="serif"] {
  --clock-family: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Charter, "Noto Serif", "DejaVu Serif", Georgia, serif;
}

.clock-time {
  display: flex;
  align-items: baseline;
  justify-content: center;
  white-space: nowrap;
  font-size: var(--clock-font, 160px);
}

/* 幅を測るための写し。見えず、配置にも影響しない */
.clock-probe {
  position: absolute;
  top: 0;
  left: 0;
  visibility: hidden;
  pointer-events: none;
  font-size: 100px;
}

.clock-period {
  font-family: var(--ui-font);
  font-size: 0.22em;
  font-weight: 500;
  margin-right: 0.35em;
}

.clock-digits,
.clock-seconds {
  display: inline-flex;
  align-items: baseline;
}

.d {
  display: inline-block;
}

/* 多くの書体で低く見えるコロンを、数字の中央に寄せる */
.d.colon {
  padding: 0 0.04em;
  translate: 0 -0.06em;
}

.d.colon.is-dim {
  opacity: 0.25;
}

.clock-seconds {
  font-size: 0.4em;
  margin-left: 0.2em;
}

/* アナログ */
.analog {
  display: block;
  width: var(--clock-dial, 320px);
  height: var(--clock-dial, 320px);
  overflow: visible;
}

.analog-face {
  fill: none;
  stroke: var(--ink-dim);
  stroke-width: calc(1.25px * var(--hand-scale, 1));
}

.tick {
  stroke: var(--ink-dim);
  stroke-width: calc(1.2px * var(--hand-scale, 1));
  stroke-linecap: round;
}

.tick-major {
  stroke: var(--ink);
  stroke-width: calc(2.6px * var(--hand-scale, 1));
}

.hand line {
  stroke: var(--ink);
  stroke-linecap: round;
}

.hand-hour line {
  stroke-width: calc(6px * var(--hand-scale, 1));
}

.hand-minute line {
  stroke-width: calc(4px * var(--hand-scale, 1));
}

.hand-second line {
  stroke: var(--accent-1);
  stroke-width: calc(1.5px * var(--hand-scale, 1));
}

.analog-hub {
  fill: var(--accent-1);
}

/* 夜の間に表示を暗くする。動かない半透明の層を、時計の画面の上に重ねる */
#stage.is-night-dim::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: var(--z-caption);
  pointer-events: none;
  background: oklch(0 0 0 / 0.4);
}
