/* ==========================================================================
   Fliqlo Web — flip clock responsif
   Ukuran dasar dibuat tetap (base size), lalu diskalakan lewat JS (fit()).
   ========================================================================== */

:root {
  --cw: 160px;          /* lebar satu kartu */
  --ch: 220px;          /* tinggi satu kartu */
  --radius: 14px;
  --unit-gap: 10px;     /* jarak antar kartu dalam satu unit */
  --clock-gap: 22px;    /* jarak antar unit / pemisah */
  --board-gap: 46px;    /* jarak jam ke tanggal */

  --bg: #000;
  --card-top-a: #2f2f35;
  --card-top-b: #26262b;
  --card-bot-a: #212126;
  --card-bot-b: #1b1b1f;
  --hinge: #0b0b0c;
  --digit: #f7f7fa;
  --muted: #8a8a90;
  --surface: rgba(28, 28, 32, 0.92);
  --line: rgba(255, 255, 255, 0.09);
  --text: #e5e5ea;
}

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

[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--digit);
  font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, "Segoe UI", system-ui, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

/* ---------- panggung ---------- */

.stage {
  position: fixed;
  inset: 0;
  overflow: hidden;
  touch-action: none; /* cubit jari dipakai untuk zoom jam, bukan zoom halaman */
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/*
 * Board sengaja di-absolute, bukan item grid/flex, supaya lebarnya tidak
 * pernah dikunci oleh container. Kalau dikunci, kartu jam ikut menyusut dan
 * pengukuran offsetWidth di fit() jadi salah -> skala kacau di layar sempit.
 */
.board {
  position: absolute;
  left: 50%;
  top: 50%;
  width: max-content;
  height: max-content;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--board-gap);
  transform: translate(-50%, -50%) scale(var(--scale, 1));
  transform-origin: center center;
  will-change: transform;
}

.clock {
  display: flex;
  align-items: center;
  gap: var(--clock-gap);
  flex: none;
}

.unit {
  display: flex;
  gap: var(--unit-gap);
  flex: none;
}

/* ---------- kartu flip ---------- */

.flip {
  position: relative;
  flex: none;
  width: var(--cw);
  height: var(--ch);
  perspective: 700px;
  border-radius: var(--radius);
}

.half {
  position: absolute;
  left: 0;
  width: 100%;
  height: 50%;
  overflow: hidden;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.half span {
  position: absolute;
  left: 0;
  width: 100%;
  height: var(--ch);
  font-size: calc(var(--ch) * 0.82);
  line-height: var(--ch);
  font-weight: 600;
  letter-spacing: -0.02em;
  text-align: center;
  color: var(--digit);
  font-variant-numeric: tabular-nums;
  -webkit-user-select: none;
  user-select: none;
}

.top-half {
  top: 0;
  border-radius: var(--radius) var(--radius) 0 0;
  transform-origin: bottom center;
  background: linear-gradient(var(--card-top-a), var(--card-top-b));
}

.top-half span { top: 0; }

.top-half::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 2px;
  background: var(--hinge);
  opacity: 0.9;
}

.bottom-half {
  bottom: 0;
  border-radius: 0 0 var(--radius) var(--radius);
  transform-origin: top center;
  background: linear-gradient(var(--card-bot-a), var(--card-bot-b));
}

.bottom-half span { bottom: 0; }

.bottom-half::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 2px;
  background: var(--hinge);
  opacity: 0.9;
}

/* posisi diam saat tidak beranimasi: rebah tegak lurus layar -> tak terlihat */
.flip-top {
  transform: rotateX(-90deg);
  z-index: 3;
}

.flip-bottom {
  transform: rotateX(90deg);
  z-index: 2;
}

.flip-top.run {
  animation: flip-top 300ms cubic-bezier(0.4, 0, 1, 1) forwards;
}

.flip-bottom.run {
  animation: flip-bottom 300ms cubic-bezier(0, 0, 0.6, 1) 300ms forwards;
}

@keyframes flip-top {
  from { transform: rotateX(0deg); }
  to   { transform: rotateX(-90deg); }
}

@keyframes flip-bottom {
  from { transform: rotateX(90deg); }
  to   { transform: rotateX(0deg); }
}

/* ---------- pemisah & AM/PM ---------- */

.sep {
  display: flex;
  flex: none;
  flex-direction: column;
  align-items: center;
  gap: 26px;
}

.sep i {
  display: block;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #5a5a63;
  animation: colon-blink 1s ease-in-out infinite;
}

/* dua titik tidak berkedip bersamaan -> terlihat seperti denyut */
.sep i:last-child { animation-delay: 0.2s; }

@keyframes colon-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.22; }
}

.meridiem {
  display: flex;
  flex: none;
  flex-direction: column;
  justify-content: center;
  gap: 20px;
  height: var(--ch);
  padding-left: 4px;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.meridiem span {
  color: #3a3a41;
  transition: color 200ms ease;
}

.meridiem span.on { color: var(--digit); }

/* ---------- tanggal (+ kalender hijri) ---------- */

.dates {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.date {
  font-size: 30px;
  font-weight: 500;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
}

.hijri {
  font-size: 22px;
  font-weight: 400;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: #5f5f66;
  white-space: nowrap;
}

/* ---------- kontrol ---------- */

.controls {
  position: fixed;
  top: calc(14px + env(safe-area-inset-top));
  right: calc(14px + env(safe-area-inset-right));
  display: flex;
  gap: 8px;
  z-index: 20;
  opacity: 0.3;
  transition: opacity 250ms ease;
}

.controls:hover,
.controls:focus-within { opacity: 1; }

.btn {
  appearance: none;
  border: 0;
  padding: 0;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
  cursor: pointer;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  transition: background 200ms ease, transform 120ms ease;
}

.btn:hover { background: rgba(255, 255, 255, 0.15); }
.btn:active { transform: scale(0.94); }
.btn:focus-visible { outline: 2px solid #0a84ff; outline-offset: 2px; }

.btn svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- panel pengaturan ---------- */

.panel {
  position: fixed;
  top: calc(66px + env(safe-area-inset-top));
  right: calc(14px + env(safe-area-inset-right));
  width: 240px;
  padding: 14px;
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.55);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  z-index: 21;
  animation: panel-in 160ms ease-out;
}

@keyframes panel-in {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.panel__title {
  margin: 0 0 2px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 14px;
  color: var(--text);
}

.switch {
  position: relative;
  flex: none;
  width: 44px;
  height: 26px;
  padding: 0;
  border: 0;
  border-radius: 99px;
  background: #3a3a41;
  cursor: pointer;
  transition: background 200ms ease;
}

.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  transition: transform 200ms ease;
}

.switch[aria-checked="true"] { background: #34c759; }
.switch[aria-checked="true"]::after { transform: translateX(18px); }
.switch:focus-visible { outline: 2px solid #0a84ff; outline-offset: 2px; }

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(28px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 13px;
  white-space: nowrap;
  z-index: 30;
  animation: toast-in 200ms ease-out;
}

@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

/* ---------- penyesuaian layar kecil ---------- */

@media (max-width: 640px) {
  .controls { gap: 6px; }
  .btn { width: 40px; height: 40px; border-radius: 11px; }
  .panel { width: min(240px, calc(100vw - 28px)); }
  .toast { font-size: 12px; max-width: calc(100vw - 32px); }
}

/*
 * Ponsel dalam posisi tegak: jam ditumpuk vertikal (jam di atas, menit di
 * bawah). Karena hanya 2 kartu yang berbaris, kartunya bisa tampil jauh
 * lebih besar daripada mode mendatar 4 kartu.
 */
@media (max-width: 640px) and (orientation: portrait) {
  .clock { flex-direction: column; }
  .sep { flex-direction: row; gap: 16px; }
  .sep i { width: 16px; height: 16px; }
  .meridiem { flex-direction: row; height: auto; gap: 16px; padding: 0; }
  /* tanggal dikecilkan agar tidak jadi penentu lebar -> kartu jam bisa besar */
  .date { font-size: 16px; letter-spacing: 0.16em; }
  .hijri { font-size: 13px; letter-spacing: 0.13em; }
}

@media (hover: none) {
  .controls { opacity: 0.55; }
}

/* ---------- aksesibilitas ---------- */

@media (prefers-reduced-motion: reduce) {
  .flip-top.run,
  .flip-bottom.run { animation-duration: 1ms; animation-delay: 0ms; }
  .sep i { animation: none; opacity: 0.75; }
  .panel, .toast { animation: none; }
  .switch::after, .switch, .btn { transition: none; }
}
