/* PHOS · Live Timer — premium dark mobile timer */

:root {
  --bg: #0e100f;
  --bg-raise: #141715;
  --ink: #f2ead9;          /* warm ivory digits */
  --ink-dim: #a9a493;      /* muted ivory for secondary text */
  --ink-faint: #6f6e63;    /* quietest text */
  --hairline: rgba(242, 234, 217, 0.12);
  --green: #7fb08a;        /* restrained green accent */
  --green-deep: #233528;
  --amber: #d3ab62;        /* source-connected / stopped */
  --gray-dot: #575a52;
  --danger: #d0826a;
  --focus: #9fd0aa;
  --radius: 16px;
  --font-serif: "New York", ui-serif, Georgia, "Times New Roman", serif;
  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

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

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
  min-height: 100svh;
}

::selection {
  background: var(--green-deep);
  color: var(--ink);
}

/* ---------- Layout shell ---------- */

.shell {
  min-height: 100vh;
  min-height: 100svh;
  max-width: 640px;
  margin: 0 auto;
  padding:
    max(env(safe-area-inset-top), 14px)
    max(env(safe-area-inset-right), 22px)
    max(env(safe-area-inset-bottom), 16px)
    max(env(safe-area-inset-left), 22px);
  display: flex;
  flex-direction: column;
}

/* ---------- Masthead ---------- */

.masthead {
  display: flex;
  align-items: baseline;
  gap: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--hairline);
}

.masthead__brand {
  font-family: var(--font-sans);
  font-weight: 700;
  font-size: 0.82rem;
  letter-spacing: 0.42em;
  text-indent: 0.42em; /* optically recenter tracked caps */
  color: var(--ink);
}

.masthead__rule {
  flex: 1;
  height: 1px;
  align-self: center;
  background: var(--hairline);
}

.masthead__tag {
  font-size: 0.66rem;
  font-weight: 600;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--green);
}

/* ---------- Views ---------- */

.view {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.view--loading {
  align-items: center;
  justify-content: center;
}

.loading {
  color: var(--ink-faint);
  font-size: 0.85rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  margin: 0;
}

/* ---------- Eyebrow / shared bits ---------- */

.eyebrow {
  margin: 0;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

.btn {
  font-family: var(--font-sans);
  font-size: 1rem;
  font-weight: 600;
  border-radius: 999px;
  min-height: 48px;
  padding: 0 26px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background-color 160ms ease, border-color 160ms ease, color 160ms ease;
}

.btn:disabled {
  opacity: 0.55;
  cursor: default;
}

.btn--solid {
  background: var(--ink);
  color: #141511;
  width: 100%;
}

.btn--solid:hover:not(:disabled) {
  background: #fffdf4;
}

.btn--ghost {
  background: transparent;
  color: var(--green);
  border-color: rgba(127, 176, 138, 0.4);
}

.btn--ghost:hover {
  background: var(--green-deep);
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
  border-radius: 4px;
}

/* ---------- Login view ---------- */

.view--login {
  justify-content: center;
  padding: 28px 0 12px;
}

.login {
  width: 100%;
  max-width: 400px;
  margin: 0 auto;
}

.login__title {
  font-family: var(--font-serif);
  font-weight: 500;
  font-size: clamp(2.4rem, 10vw, 3.2rem);
  line-height: 1.08;
  letter-spacing: -0.01em;
  margin: 18px 0 10px;
  color: var(--ink);
}

.login__sub {
  margin: 0 0 28px;
  color: var(--ink-dim);
  font-size: 1.02rem;
  line-height: 1.5;
  max-width: 34ch;
}

.login__form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.field__label {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

.password {
  position: relative;
  display: flex;
  align-items: center;
}

.field__input {
  width: 100%;
  min-height: 54px;
  font-size: 1.1rem;
  color: var(--ink);
  background: var(--bg-raise);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 0 64px 0 18px;
  caret-color: var(--green);
}

.field__input::placeholder {
  color: var(--ink-faint);
}

.field__input:focus {
  border-color: rgba(127, 176, 138, 0.55);
}

.password__toggle {
  position: absolute;
  right: 6px;
  min-width: 52px;
  min-height: 44px;
  background: transparent;
  border: 0;
  border-radius: 12px;
  color: var(--green);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}

.password__toggle:hover {
  background: var(--green-deep);
}

.form__error {
  margin: 2px 0 0;
  color: var(--danger);
  font-size: 0.92rem;
  line-height: 1.4;
}

.login__form .btn--solid {
  margin-top: 8px;
}

.fineprint {
  margin: 26px 0 0;
  text-align: center;
  color: var(--ink-faint);
  font-size: 0.8rem;
  letter-spacing: 0.04em;
}

/* ---------- Timer view ---------- */

.view--timer {
  justify-content: space-between;
}

.timer {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 18px;
  padding: 24px 0 8px;
}

.timer__head {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}

.timer__name {
  margin: 0;
  font-size: 0.9rem;
  color: var(--ink-dim);
  letter-spacing: 0.02em;
  max-width: 32ch;
  overflow-wrap: anywhere;
}

/* Status row: dot + text */

.status {
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 28px;
  padding: 5px 16px 5px 12px;
  border: 1px solid var(--hairline);
  border-radius: 999px;
  background: rgba(242, 234, 217, 0.03);
}

.status__text {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: none;
}

.dot--live {
  background: var(--green);
  box-shadow: 0 0 10px rgba(127, 176, 138, 0.45);
}

.dot--stopped {
  background: var(--amber);
  box-shadow: 0 0 10px rgba(211, 171, 98, 0.4);
}

.dot--offline,
.dot--missing {
  background: var(--gray-dot);
}

.dot--reconnecting {
  background: transparent;
  border: 2px solid var(--ink-faint);
  width: 8px;
  height: 8px;
}

.status--live .status__text { color: var(--green); }
.status--stopped .status__text { color: var(--amber); }

/* ---------- The digits ---------- */

.digits {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums lining-nums;
  font-feature-settings: "tnum" 1, "lnum" 1;
  font-weight: 600;
  color: var(--ink);
  line-height: 1;
  letter-spacing: -0.02em;
  white-space: nowrap;
  max-width: 100%;
  text-shadow: 0 0 42px rgba(242, 234, 217, 0.08);
  user-select: none;
}

/* Predefined length buckets — fits 320px wide screens, scales up */
.d-5  { font-size: clamp(4rem, 26vw, 9.5rem); }
.d-8  { font-size: clamp(2.55rem, 17.4vw, 8.5rem); }   /* 00:25:00 ≈ 4.8em wide */
.d-10 { font-size: clamp(1.9rem, 13vw, 6.25rem); }
.d-12 { font-size: clamp(1.45rem, 10.4vw, 5rem); }

.source {
  margin: 0;
  color: var(--ink-faint);
  font-size: 0.9rem;
  line-height: 1.5;
  max-width: 38ch;
  min-height: 1.5em;
  overflow-wrap: anywhere;
}

.retry {
  margin-top: 2px;
}

/* ---------- Footer: keep awake + sign out ---------- */

.foot {
  border-top: 1px solid var(--hairline);
  padding-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.foot__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.chip {
  min-height: 44px;
  padding: 0 18px;
  border-radius: 999px;
  border: 1px solid var(--hairline);
  background: transparent;
  color: var(--ink-dim);
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  cursor: pointer;
  transition: background-color 160ms ease, color 160ms ease, border-color 160ms ease;
}

.chip:hover {
  border-color: rgba(127, 176, 138, 0.45);
  color: var(--ink);
}

.chip[aria-pressed="true"] {
  background: var(--green-deep);
  border-color: rgba(127, 176, 138, 0.55);
  color: var(--green);
}

.signout {
  min-height: 44px;
  padding: 0 10px;
  background: transparent;
  border: 0;
  color: var(--ink-faint);
  font-family: var(--font-sans);
  font-size: 0.9rem;
  font-weight: 500;
  text-decoration: underline;
  text-underline-offset: 4px;
  text-decoration-color: var(--hairline);
  cursor: pointer;
}

.signout:hover {
  color: var(--ink-dim);
  text-decoration-color: var(--ink-faint);
}

.awake-note {
  margin: 0;
  min-height: 1.1em;
  font-size: 0.75rem;
  color: var(--ink-faint);
}

/* ---------- Landscape phones: collapse vertical rhythm ---------- */

@media (orientation: landscape) and (max-height: 540px) {
  .shell {
    padding-top: max(env(safe-area-inset-top), 8px);
    padding-bottom: max(env(safe-area-inset-bottom), 8px);
  }

  .masthead {
    padding-bottom: 8px;
  }

  .timer {
    gap: 8px;
    padding: 6px 0 0;
  }

  .d-5  { font-size: clamp(2.6rem, 30vh, 5.5rem); }
  .d-8  { font-size: clamp(2rem, 24vh, 4.6rem); }
  .d-10 { font-size: clamp(1.5rem, 18vh, 3.6rem); }
  .d-12 { font-size: clamp(1.2rem, 14vh, 2.8rem); }

  .foot {
    padding-top: 8px;
  }

  .view--login {
    padding: 8px 0 0;
  }

  .login__title {
    font-size: 2rem;
    margin: 10px 0 6px;
  }

  .login__sub {
    margin-bottom: 14px;
  }
}

/* Larger screens: keep digits on a leash */
@media (min-width: 720px) {
  .shell {
    max-width: 720px;
  }
}

/* ---------- Reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}

/* Long hours/fractions stay within the viewport; use the smallest type bucket. */
.digits.d-12 { font-size: min(10.2vw, 10.2vh, 5.5rem); }
#signOutBtn { margin-left: auto; }
