File size: 10,873 Bytes
f59178c
4f5b6ff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width,initial-scale=1" />
  <title>Responsive Analog Clock</title>
  <style>
    :root {
      --bg: #ffffff;
      --ink: #0f172a;            /* primary text/face color */
      --muted: #64748b;          /* minute tick color */
      --accent: #ef4444;         /* second hand */
      --accent-weak: #fca5a5;
      --ring: #0f172a;
      --shadow: 0 20px 40px rgba(2, 6, 23, 0.12);
      --ring-width: clamp(6px, 0.8vmin, 10px);
      --center-cap: clamp(8px, 1vmin, 14px);
      --major-tick: clamp(4px, 0.6vmin, 6px);
      --minor-tick: clamp(1px, 0.25vmin, 2px);
      --num-size: clamp(14px, 3.4vmin, 28px);
      --brand-size: clamp(11px, 2.6vmin, 16px);
    }

    * { box-sizing: border-box; }
    html, body {
      height: 100%;
      margin: 0;
      background: var(--bg);
      color: var(--ink);
      -webkit-font-smoothing: antialiased;
      -moz-osx-font-smoothing: grayscale;
      font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
    }

    .wrap {
      min-height: 100%;
      display: grid;
      grid-template-rows: auto 1fr auto;
      align-items: center;
      justify-items: center;
      gap: 1rem;
      padding: 2rem 1rem 1.5rem;
    }

    header {
      display: flex;
      align-items: baseline;
      gap: 1rem;
      justify-content: center;
      width: 100%;
      max-width: 1100px;
    }
    .title {
      font-weight: 700;
      letter-spacing: 0.02em;
      font-size: clamp(18px, 2.6vmin, 28px);
    }
    .subtitle {
      color: var(--muted);
      font-size: clamp(12px, 2.2vmin, 16px);
    }
    a.brand {
      margin-left: auto;
      text-decoration: none;
      color: var(--ink);
      font-size: var(--brand-size);
      opacity: 0.8;
      border-bottom: 1px solid color-mix(in oklab, var(--ink), transparent 80%);
      transition: opacity .2s ease, transform .2s ease;
    }
    a.brand:hover { opacity: 1; transform: translateY(-1px); }

    .digital {
      font-variant-numeric: tabular-nums;
      letter-spacing: 0.06em;
      font-weight: 600;
      font-size: clamp(16px, 3.2vmin, 24px);
      padding: 0.35rem 0.75rem;
      border-radius: 999px;
      border: 1px solid color-mix(in oklab, var(--ink), transparent 88%);
      background: #fff;
      box-shadow: var(--shadow);
      user-select: none;
    }

    .clock {
      position: relative;
      width: min(86vmin, 540px);
      aspect-ratio: 1;
      border-radius: 50%;
      border: var(--ring-width) solid var(--ring);
      background:
        radial-gradient(circle at 50% 50%, #fff 0 68%, #f8fafc 69% 100%); /* subtle inner ring */
      box-shadow: var(--shadow);
      overflow: hidden;
      isolation: isolate;
    }

    /* Minute ring (60 ticks) */
    .clock::before {
      content: "";
      position: absolute;
      inset: clamp(10px, 2.2vmin, 18px);
      border-radius: 50%;
      background:
        /* minor ticks (59) */
        repeating-conic-gradient(
          from -90deg,
          color-mix(in oklab, var(--muted), transparent 40%) 0deg,
          color-mix(in oklab, var(--muted), transparent 40%) 1deg,
          transparent 1deg 6deg
        ),
        /* major ticks (12) */
        repeating-conic-gradient(
          from -90deg,
          var(--muted) 0deg,
          var(--muted) 2.2deg,
          transparent 2.2deg 30deg
        );
      -webkit-mask: radial-gradient(circle, #0000 calc(100% - clamp(12px, 1.6vmin, 16px)), #000 calc(100% - clamp(12px, 1.6vmin, 16px)));
              mask: radial-gradient(circle, #0000 calc(100% - clamp(12px, 1.6vmin, 16px)), #000 calc(100% - clamp(12px, 1.6vmin, 16px)));
      pointer-events: none;
    }

    /* Numbers */
    .numbers {
      position: absolute;
      inset: 0;
      border-radius: 50%;
    }
    .num {
      position: absolute;
      left: 50%;
      top: 50%;
      transform-origin: center center;
      font-weight: 700;
      font-size: var(--num-size);
      user-select: none;
      pointer-events: none;
      color: var(--ink);
      filter: drop-shadow(0 1px 0 rgba(2,6,23,0.06));
      transition: transform 0.2s ease;
    }
    .num small {
      font-size: 0.72em;
      font-weight: 600;
      opacity: 0.85;
    }

    /* Hands */
    .hands { position: absolute; inset: 0; }
    .hand {
      position: absolute;
      left: 50%;
      bottom: 50%;
      transform: translateX(-50%) rotate(0deg);
      transform-origin: 50% 100%;
      border-radius: 999px;
      will-change: transform;
    }

    .hand.hour {
      width: clamp(7px, 1vmin, 10px);
      height: 24%;
      background: linear-gradient(#111, #1f2937);
      box-shadow: 0 6px 10px rgba(2,6,23,0.15);
    }

    .hand.minute {
      width: clamp(5px, 0.8vmin, 8px);
      height: 34%;
      background: linear-gradient(#111, #1f2937);
      box-shadow: 0 6px 10px rgba(2,6,23,0.15);
    }

    /* Second hand (animated with CSS) */
    .hand.second {
      width: clamp(2.5px, 0.55vmin, 4px);
      height: 40%;
      background: var(--accent);
      box-shadow: 0 6px 10px rgba(239, 68, 68, 0.3);
      --spin-duration: 60s;
      animation: spin linear infinite;
      animation-duration: var(--spin-duration);
    }
    /* Smooth continuous animation, not tied to wall-clock seconds */
    @keyframes spin {
      from { transform: translateX(-50%) rotate(0deg); }
      to   { transform: translateX(-50%) rotate(360deg); }
    }
    /* Optional: pause if user prefers reduced motion */
    @media (prefers-reduced-motion: reduce) {
      .hand.second { animation: none; }
    }

    /* Center cap */
    .pivot {
      position: absolute;
      left: 50%;
      top: 50%;
      width: clamp(16px, 2.4vmin, 22px);
      height: clamp(16px, 2.4vmin, 22px);
      transform: translate(-50%, -50%);
      background: #fff;
      border: clamp(3px, 0.5vmin, 4px) solid var(--ink);
      border-radius: 50%;
      box-shadow: inset 0 1px 1px rgba(2,6,23,0.15), 0 2px 4px rgba(2,6,23,0.12);
      z-index: 2;
    }
    .pivot::after {
      content: "";
      position: absolute;
      left: 50%;
      top: 50%;
      width: var(--center-cap);
      height: var(--center-cap);
      transform: translate(-50%, -50%);
      background: var(--accent);
      border-radius: 50%;
      box-shadow: 0 0 0 2px color-mix(in oklab, #fff, transparent 25%);
    }

    /* Helper: tiny brand at bottom inside the clock */
    .brand-inside {
      position: absolute;
      bottom: clamp(10px, 2.4vmin, 18px);
      left: 50%;
      transform: translateX(-50%);
      font-size: clamp(10px, 2.2vmin, 12px);
      color: color-mix(in oklab, var(--ink), transparent 50%);
      user-select: none;
      pointer-events: none;
    }

    /* Accessibility: focus outline on digital readout for keyboard users */
    .digital:focus-visible {
      outline: 2px solid color-mix(in oklab, var(--ink), transparent 60%);
      outline-offset: 4px;
    }
  </style>
</head>
<body>
  <div class="wrap">
    <header>
      <div class="title">Responsive Analog Clock</div>
      <div class="subtitle">White background • CSS-animated second hand</div>
      <a class="brand" href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank" rel="noreferrer noopener">Built with anycoder</a>
    </header>

    <div class="digital" id="digital" aria-live="polite" title="Current time">
      <!-- JS fills HH:MM:SS -->
    </div>

    <div class="clock" id="clock" aria-label="Analog clock">
      <div class="numbers" id="numbers" aria-hidden="true"></div>

      <div class="hands" aria-hidden="true">
        <div class="hand hour"   id="hourHand"></div>
        <div class="hand minute" id="minuteHand"></div>
        <div class="hand second" id="secondHand"></div>
      </div>

      <div class="pivot" aria-hidden="true"></div>
      <div class="brand-inside">anycoder</div>
    </div>
  </div>

  <script>
    (function () {
      const els = {
        digital: document.getElementById('digital'),
        clock: document.getElementById('clock'),
        numbers: document.getElementById('numbers'),
        hour: document.getElementById('hourHand'),
        minute: document.getElementById('minuteHand'),
        second: document.getElementById('secondHand')
      };

      // Create numbers (12 → Roman numerals), 24 → Arabic numerals
      function makeNumbers(use24 = false) {
        els.numbers.innerHTML = '';
        const fragment = document.createDocumentFragment();
        for (let i = 1; i <= 12; i++) {
          const n = document.createElement('div');
          n.className = 'num';
          const label = use24 ? (i + 12) : toRoman(i);
          n.textContent = label;
          n.dataset.h = i; // store hour
          fragment.appendChild(n);
        }
        els.numbers.appendChild(fragment);
        layoutNumbers();
      }

      function toRoman(num) {
        const map = [
          [1000,'M'], [900,'CM'], [500,'D'], [400,'CD'],
          [100,'C'], [90,'XC'], [50,'L'], [40,'XL'],
          [10,'X'], [9,'IX'], [5,'V'], [4,'IV'], [1,'I']
        ];
        let out = '';
        for (const [v, s] of map) {
          while (num >= v) { out += s; num -= v; }
        }
        return out;
      }

      function layoutNumbers() {
        const radiusPct = 42; // percentage of radius for text baseline
        const nums = els.numbers.querySelectorAll('.num');
        nums.forEach(n => {
          const h = parseInt(n.dataset.h, 10);
          const deg = h * 30; // 360/12
          n.style.transform = `translate(-50%, -50%) rotate(${deg}deg) translateY(-${radiusPct}%) rotate(${-deg}deg)`;
        });
      }

      // Update hands every frame (hour/minute) to catch time changes smoothly
      let lastSec = -1;
      function update() {
        const now = new Date();
        const ms = now.getMilliseconds();
        const s = now.getSeconds() + ms / 1000;   // smooth fraction
        const m = now.getMinutes() + s / 60;
        const h = (now.getHours() % 12) + m / 60;

        // Hour hand
        els.hour.style.transform = `translateX(-50%) rotate(${h * 30}deg)`;
        // Minute hand
        els.minute.style.transform = `translateX(-50%) rotate(${m * 6}deg)`;

        // Digital readout (update only when seconds change to reduce reflow)
        const secInt = now.getSeconds();
        if (secInt !== lastSec) {
          els.digital.textContent = now.toLocaleTimeString([], { hour12: false });
          lastSec = secInt;
        }

        requestAnimationFrame(update);
      }

      // Responsive: re-layout numbers when size changes
      const ro = new ResizeObserver(() => layoutNumbers());
      ro.observe(els.clock);

      // Initialize
      makeNumbers(false);
      update();
    })();
  </script>
</body>
</html>