:root {
  --bg: #0b0d12;
  --fg: #f4f6fb;
  --muted: #8b93a7;
  --accent: #4f8cff;
  --ring-track: rgba(255, 255, 255, 0.08);
  --btn: rgba(255, 255, 255, 0.06);
  --btn-hover: rgba(255, 255, 255, 0.12);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  /* Custom background hook for logged-in users gets set on body via inline style */
  background-size: cover;
  background-position: center;
}

/* Body is a flex column: timer area fills, footer sits below — never overlap. */
body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.stage {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(1.5rem, 5vh, 5rem);
  padding: calc(env(safe-area-inset-top) + 1rem) env(safe-area-inset-right)
           1rem env(safe-area-inset-left);
  transition: background 0.4s ease;
}

/* ---- Timer + progress ring ---- */
.timer {
  position: relative;
  width: min(78vw, 78vh, 560px);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
}

.ring {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.ring-track {
  fill: none;
  stroke: var(--ring-track);
  stroke-width: 3;
}

.ring-progress {
  fill: none;
  stroke: var(--accent);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-dasharray: 289.027;   /* 2 * PI * 46 */
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 0.3s linear, stroke 0.3s ease;
}

.display {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  z-index: 1;
}

.time {
  font-size: clamp(3.2rem, 17vw, 11rem);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  line-height: 1;
  font-feature-settings: "tnum";
}

.custom {
  height: 1.6rem;
}

.custom-input {
  width: 9rem;
  background: transparent;
  border: none;
  border-bottom: 1px solid transparent;
  color: var(--muted);
  text-align: center;
  font-size: 1rem;
  padding: 0.2rem 0;
  outline: none;
  transition: border-color 0.2s, color 0.2s;
}

.custom-input::placeholder { color: var(--muted); opacity: 0.6; }
.custom-input:focus {
  color: var(--fg);
  border-bottom-color: var(--accent);
}

/* ---- Controls ---- */
.controls {
  display: flex;
  align-items: center;
  gap: clamp(1rem, 4vw, 1.8rem);
}

.btn {
  display: grid;
  place-items: center;
  border: none;
  cursor: pointer;
  border-radius: 50%;
  background: var(--btn);
  color: var(--fg);
  transition: background 0.15s, transform 0.05s;
}
.btn:hover { background: var(--btn-hover); }
.btn:active { transform: scale(0.94); }
.btn svg { width: 46%; height: 46%; fill: currentColor; }

.btn-secondary { width: clamp(3rem, 12vw, 4rem); height: clamp(3rem, 12vw, 4rem); }
.btn-primary {
  width: clamp(4.2rem, 17vw, 5.5rem);
  height: clamp(4.2rem, 17vw, 5.5rem);
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: #3f7bf0; }

/* play/pause icon swap driven by body.running */
.ic-pause { display: none; }
body.running .ic-play { display: none; }
body.running .ic-pause { display: block; }

/* ---- Brand footer ---- */
.brand {
  position: relative;
  z-index: 1;
  flex: 0 0 auto;
  text-align: center;
  padding: 0.7rem 1rem max(0.7rem, env(safe-area-inset-bottom));
  color: var(--muted);
  font-size: clamp(0.72rem, 2.6vw, 0.85rem);
  letter-spacing: 0.03em;
  line-height: 1.5;
}
.brand a, .brand a:visited { color: inherit; text-decoration: none; white-space: nowrap; }
.brand a:hover { color: var(--fg); text-decoration: underline; }

/* ---- Account link (top-right) ---- */
.account-link {
  position: fixed;
  top: max(0.9rem, env(safe-area-inset-top));
  right: max(0.9rem, env(safe-area-inset-right));
  width: 2.4rem; height: 2.4rem;
  display: grid; place-items: center;
  border-radius: 50%;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.04);
  transition: color 0.15s, background 0.15s;
  z-index: 2;
}
.account-link:hover { color: var(--fg); background: rgba(255, 255, 255, 0.1); }
.account-link svg { width: 55%; height: 55%; fill: currentColor; }
body.immersive .account-link { opacity: 0; transition: opacity 0.4s; }
body.immersive.show-ui .account-link { opacity: 1; }

/* Darken custom background for legibility */
body.has-bg::before {
  content: "";
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 0;
  pointer-events: none;
}
body.has-bg .stage { position: relative; z-index: 1; }

/* ---- Finished state: flash ---- */
@keyframes flash {
  0%, 100% { background-color: var(--bg); }
  50% { background-color: #2a1416; }
}
body.finished .time { color: #ff6b6b; }
body.finished .ring-progress { stroke: #ff6b6b; }
body.finished { animation: flash 0.7s ease-in-out 4; }

/* Hide controls/brand/input in immersive fullscreen until pointer moves */
body.immersive .controls,
body.immersive .brand,
body.immersive .custom { opacity: 0; transition: opacity 0.4s; }
body.immersive.show-ui .controls,
body.immersive.show-ui .brand,
body.immersive.show-ui .custom { opacity: 1; }
