/* Fliqlo web app — clock face ported from the SwiftUI reconstruction
   (FlapView.swift / ContentView.swift), card style from Fliqlo.saver. */

@font-face {
  font-family: "Fliqlo";
  src: url("fonts/Fliqlo.otf") format("opentype");
  font-display: block;
}

:root {
  color-scheme: dark;
  --bg: #000;
  /* Card style (saver design canvas 600). */
  --fill-top: rgb(17 17 17);
  --fill-bottom: rgb(11 11 11);
  --inner-shadow: rgb(13 13 13);
  --border-top: rgb(22 22 22);
  --border-bottom: rgb(12 12 12);
  /* Settings sheet (iOS dark grouped form). */
  --sheet-bg: #1c1c1e;
  --cell-bg: #2c2c2e;
  --separator: rgb(84 84 88 / 0.6);
  --label: #fff;
  --secondary: rgb(235 235 245 / 0.6);
  --tint: #0a84ff;
  --green: #34c759;
  --red: #ff453a;
  --side: 300px;      /* card side, set by app.js */
  --dial: 40px;       /* dial diameter, set by app.js */
}
:root[data-theme="dark"] { color-scheme: dark; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --bg: #000; }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  overflow: hidden;
  overscroll-behavior: none;
}
body {
  position: fixed;
  inset: 0;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Helvetica Neue", Arial, sans-serif;
  color: var(--label);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-text-size-adjust: 100%;
}

/* ---------- Stage & clock ---------- */

#stage {
  position: absolute;
  left: 50%;
  top: 50%;
  /* width/height/transform set by app.js (orientation lock rotates it) */
  touch-action: none;
  overflow: hidden;
  background: var(--bg);
}

#clock {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: calc(var(--side) * 0.098);
  flex-direction: column;
}
#stage.landscape #clock { flex-direction: row; }

.card {
  position: relative;
  width: var(--side);
  height: var(--side);
  flex: none;
  perspective: calc(var(--side) / 0.15);  /* saver perspective 0.15 */
  contain: layout size;
}

/* Every layer is a full card; halves are clipped at the hinge (center). */
.layer {
  position: absolute;
  inset: 0;
  transform-origin: 50% 50%;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  will-change: transform, opacity;
}
.layer.top    { clip-path: inset(0 0 50% 0); }
.layer.bottom { clip-path: inset(50% 0 0 0); }
.layer.flap   { visibility: hidden; }

.face {
  position: absolute;
  inset: 0;
  border-radius: calc(var(--side) * 50 / 600);
  border: max(1px, calc(var(--side) / 600)) solid transparent;
  background:
    linear-gradient(var(--fill-top), var(--fill-bottom)) padding-box,
    linear-gradient(var(--border-top), var(--border-bottom)) border-box;
  box-shadow: inset 0 0 calc(var(--side) * 200 / 600 / 2) var(--inner-shadow);
  overflow: hidden;
}
.no-flaps .face { background: none; border-color: transparent; box-shadow: none; }

.face svg {
  position: absolute;
  inset: -1px;            /* undo the border so the 600 canvas is the full card */
  width: calc(100% + 2px);
  height: calc(100% + 2px);
  overflow: visible;
}
.digits {
  font-family: "Fliqlo";
  fill: #fff;
  fill-opacity: 0.711;
}
.badge {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", system-ui, sans-serif;
  font-weight: 700;
  font-stretch: 75%;
  fill: #fff;
  fill-opacity: 0.711;
}

/* Saver brightness(-0.05) / (+0.05) on the moving flaps, as additive light. */
.shade {
  position: absolute;
  inset: 0;
  border-radius: calc(var(--side) * 50 / 600);
  background: rgb(13 13 13);
  pointer-events: none;
  opacity: 0;
}
.shade.darken  { mix-blend-mode: difference; }
.shade.lighten { mix-blend-mode: plus-lighter; }

.split {
  position: absolute;
  left: -1px;
  right: -1px;
  top: 50%;
  height: max(2px, calc(var(--side) * 0.011));
  transform: translateY(-50%);
  background: #000;
  pointer-events: none;
  z-index: 5;
}

/* ---------- Seconds dial ---------- */

#dial {
  position: absolute;
  width: var(--dial);
  height: var(--dial);
  right: calc(var(--dial) * 0.51);
  bottom: calc(var(--dial) * 0.51);
  border-radius: 50%;
  overflow: hidden;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.4s ease-out, visibility 0s linear 0.4s;
  background:
    radial-gradient(circle at 50% 30%, rgb(255 255 255 / 0.10), rgb(255 255 255 / 0.03) 60%, rgb(255 255 255 / 0.05));
  -webkit-backdrop-filter: blur(10px) saturate(1.6);
  backdrop-filter: blur(10px) saturate(1.6);
  z-index: 10;
}
#dial::after {   /* thin light rim, brighter on top */
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  padding: max(1px, calc(var(--dial) * 0.012));
  background: linear-gradient(rgb(255 255 255 / 0.22), rgb(255 255 255 / 0.08));
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
}
#dial.visible {
  opacity: 1;
  visibility: visible;
  transition: opacity 0.2s ease-in, visibility 0s;
}
#dial .row-num {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--dial) * 0.35);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: rgb(179 179 179);
  will-change: transform, opacity;
}

/* Vertical-swipe dimming (two stops, as DimOverlayView) */
#dim {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 20;
}

/* ---------- Settings sheet ---------- */

#sheetBackdrop {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 0.45);
  opacity: 0;
  transition: opacity 0.3s ease;
  z-index: 40;
}
#sheetBackdrop.open { opacity: 1; }

#sheet {
  position: fixed;
  left: 50%;
  bottom: 0;
  width: min(100%, 560px);
  height: calc(100% - max(env(safe-area-inset-top), 12px) - 10px);
  max-height: 900px;
  transform: translate(-50%, 100%);
  transition: transform 0.38s cubic-bezier(0.32, 0.72, 0, 1);
  background: var(--sheet-bg);
  border-radius: 12px 12px 0 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  font-size: 17px;
  -webkit-user-select: none;
  user-select: none;
}
#sheet.open { transform: translate(-50%, 0); }
@media (orientation: landscape) and (max-height: 500px) {
  #sheet { height: calc(100% - 8px); }
}

.nav {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  min-height: 56px;
  padding: 0 16px;
  flex: none;
}
.nav h1 { margin: 0; font-size: 17px; font-weight: 600; }
.nav-done {
  justify-self: end;
  border: 0;
  background: none;
  color: var(--tint);
  font: inherit;
  font-weight: 600;
  padding: 8px 0 8px 12px;
  cursor: pointer;
}

.form {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 0 16px calc(env(safe-area-inset-bottom) + 24px);
}
.section-title {
  margin: 22px 16px 7px;
  font-size: 13px;
  font-weight: 400;
  text-transform: uppercase;
  color: var(--secondary);
}
.group {
  background: var(--cell-bg);
  border-radius: 10px;
  overflow: hidden;
}
.row {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 44px;
  padding: 6px 16px;
  width: 100%;
  border: 0;
  background: none;
  color: var(--label);
  font: inherit;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}
.row + .row::before {
  content: "";
  position: absolute;
  top: 0;
  left: 16px;
  right: 0;
  height: 0.5px;
  background: var(--separator);
}
.row:active:not(:has(.switch)) { background: rgb(255 255 255 / 0.06); }
.row.sub { color: var(--secondary); font-size: 15px; cursor: default; }
.row.action { color: var(--tint); }
.row.destructive { color: var(--red); }
.value { color: var(--secondary); display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.value.plain { color: var(--secondary); }
.chev {
  width: 8px;
  height: 13px;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 13'%3E%3Cpath d='M1 4.5 4 1.5l3 3M1 8.5l3 3 3-3' fill='none' stroke='%23000' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 13'%3E%3Cpath d='M1 4.5 4 1.5l3 3M1 8.5l3 3 3-3' fill='none' stroke='%23000' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;
}
.picker select {
  position: absolute;
  inset: 0;
  width: 100%;
  opacity: 0;
  font-size: 17px;
  cursor: pointer;
}
.footnote {
  margin: 8px 16px 0;
  font-size: 13px;
  line-height: 1.35;
  color: var(--secondary);
}
.footnote.center { text-align: center; margin-top: 28px; }

/* iOS-style switch */
.switch {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  flex: none;
  width: 51px;
  height: 31px;
  margin: 0;
  border-radius: 16px;
  background: rgb(120 120 128 / 0.32);
  transition: background 0.25s ease;
  cursor: pointer;
}
.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 27px;
  height: 27px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 3px 8px rgb(0 0 0 / 0.15), 0 3px 1px rgb(0 0 0 / 0.06);
  transition: transform 0.25s cubic-bezier(0.3, 0.7, 0.3, 1);
}
.switch:checked { background: var(--green); }
.switch:checked::after { transform: translateX(20px); }
.switch:focus-visible, .row:focus-visible, .nav-done:focus-visible { outline: 2px solid var(--tint); outline-offset: -2px; }

/* ---------- Alert ---------- */

#alert {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgb(0 0 0 / 0.4);
  z-index: 60;
}
#alert[hidden] { display: none; }
.alert-box {
  width: min(270px, calc(100% - 32px));
  background: rgb(44 44 46 / 0.96);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  border-radius: 14px;
  text-align: center;
  overflow: hidden;
  animation: pop 0.2s ease-out;
}
@keyframes pop { from { transform: scale(1.15); opacity: 0; } }
.alert-box h3 { margin: 19px 16px 2px; font-size: 17px; font-weight: 600; }
.alert-box p { margin: 0 16px 19px; font-size: 13px; line-height: 1.35; }
.alert-buttons { display: grid; grid-template-columns: 1fr 1fr; border-top: 0.5px solid var(--separator); }
.alert-buttons button {
  min-height: 44px;
  border: 0;
  background: none;
  color: var(--tint);
  font: inherit;
  font-size: 17px;
  cursor: pointer;
}
.alert-buttons button + button { border-left: 0.5px solid var(--separator); }
.alert-buttons .destructive { color: var(--red); font-weight: 600; }

#hapticLabel { position: fixed; left: -100px; top: -100px; width: 1px; height: 1px; overflow: hidden; opacity: 0; pointer-events: none; }

@media (prefers-reduced-motion: reduce) {
  #sheet, #sheetBackdrop { transition-duration: 0.01s; }
}
