:root {
  --bg:     #ffffff;
  --fg:     #1a1a1a;
  --fg-sub: #6b7280;
  --line:   #d4d8dd;
  --accent: #1f4e7a;

  --font:       system-ui, "Hiragino Kaku Gothic ProN", "Yu Gothic", "Noto Sans JP", sans-serif;
  --font-serif: "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif JP", serif;

  --dial:  clamp(220px, min(80vw, 64vh), 560px);
  --digit: clamp(48px, 15vw, 160px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg:     #121417;
    --fg:     #e8eaed;
    --fg-sub: #9aa3ad;
    --line:   #333a43;
    --accent: #7fb0dd;
  }
}

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

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

body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  display: flex;
  flex-direction: column;
}

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
}

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

/* ---------- switcher ---------- */
.switcher {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  overflow-x: auto;
  overflow-y: hidden;
  flex-wrap: nowrap;
  flex: none;
  -webkit-overflow-scrolling: touch;
}

.switch-btn {
  flex: none;
  min-width: 44px;
  min-height: 44px;
  padding: 0 16px;
  font-family: var(--font);
  font-size: 14px;
  color: var(--fg-sub);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}

.switch-btn[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg);
}

.switch-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- clock area ---------- */
.clock-area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: 8px;
}

.clock {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  opacity: 1;
  transition: opacity 0.15s ease;
}

.clock[hidden] {
  display: none;
}

@media (prefers-reduced-motion: reduce) {
  .clock {
    transition: none;
  }
}

/* ---------- analog ---------- */
.analog-face {
  width: var(--dial);
  height: var(--dial);
}

.dial-bg {
  fill: var(--bg);
  stroke: var(--line);
  stroke-width: 1.5;
}

.tick {
  stroke: var(--fg-sub);
}
.tick-major {
  stroke-width: 2.5;
  stroke: var(--fg);
}
.tick-minor {
  stroke-width: 1;
}

.num {
  font-family: var(--font);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  fill: var(--fg);
  text-anchor: middle;
  dominant-baseline: middle;
}

.hand {
  stroke-linecap: round;
}
.hand-hour {
  stroke: var(--fg);
  stroke-width: 5;
}
.hand-minute {
  stroke: var(--fg);
  stroke-width: 3.5;
}
.hand-second {
  stroke: var(--accent);
  stroke-width: 2;
}
.pivot {
  fill: var(--accent);
}

/* ---------- digital ---------- */
.digital-time {
  font-family: var(--font);
  font-size: var(--digit);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--fg);
  line-height: 1.1;
}
.digital-date {
  margin-top: 8px;
  font-family: var(--font);
  font-size: clamp(13px, 3vw, 18px);
  font-variant-numeric: tabular-nums;
  color: var(--fg-sub);
}

/* ---------- japanese text ---------- */
.text-date {
  font-family: var(--font-serif);
  font-size: clamp(16px, 4vw, 28px);
  color: var(--fg-sub);
  font-variant-numeric: tabular-nums;
}
.text-time {
  margin-top: 6px;
  font-family: var(--font-serif);
  font-size: clamp(32px, 10vw, 96px);
  color: var(--fg);
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

/* ---------- binary ---------- */
.binary-grid {
  display: flex;
  gap: clamp(8px, 2.5vw, 22px);
}
.binary-col {
  display: flex;
  flex-direction: column;
  gap: clamp(6px, 1.8vw, 14px);
}
.binary-dot {
  width: clamp(14px, 4.5vw, 32px);
  height: clamp(14px, 4.5vw, 32px);
  border-radius: 50%;
  background: var(--line);
}
.binary-dot.on {
  background: var(--accent);
}
.binary-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 14px;
  padding: 0 clamp(6px, 1.8vw, 14px);
  width: 100%;
}
.binary-labels span {
  flex: 1;
  text-align: center;
  font-family: var(--font);
  font-size: clamp(12px, 2.5vw, 16px);
  color: var(--fg-sub);
}

/* ---------- flip ---------- */
.flip-row {
  display: flex;
  align-items: center;
  gap: clamp(6px, 2vw, 16px);
}
.flip-unit {
  perspective: 400px;
}
.flip-face {
  width: clamp(70px, 20vw, 200px);
  height: clamp(90px, 25vw, 240px);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font);
  font-size: clamp(40px, 14vw, 140px);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  transform-style: preserve-3d;
  backface-visibility: hidden;
}
.flip-face.flip-anim {
  animation: flipCard 0.3s ease;
}
@keyframes flipCard {
  0%   { transform: rotateX(0deg); }
  50%  { transform: rotateX(-90deg); }
  100% { transform: rotateX(0deg); }
}
.flip-sep {
  font-family: var(--font);
  font-size: clamp(28px, 8vw, 80px);
  font-weight: 600;
  color: var(--fg-sub);
}

@media (prefers-reduced-motion: reduce) {
  .flip-face.flip-anim {
    animation: none;
  }
}

/* ---------- status ---------- */
.status {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 16px 14px;
  text-align: center;
  font-family: var(--font);
  font-size: 12.5px;
  color: var(--fg-sub);
  font-variant-numeric: tabular-nums;
}

.status-dot {
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--fg-sub);
}
.status-dot.synced {
  background: var(--accent);
}
