/* StayLit styles. Colours are tokens; themes and accents only swap tokens. */

:root {
  --bg: #0e1014;
  --fg: #eef0f3;
  --muted: #8b929c;
  --surface: #171a20;
  --surface-2: #20242c;
  --line: #2b303a;
  --on: #3ddc84;
  --on-bg: rgba(61, 220, 132, .14);
  --accent: #ffb84d;
  --shadow: 0 20px 60px rgba(0, 0, 0, .5);
  --font-clock: "SF Pro Display", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --gutter: max(16px, env(safe-area-inset-left), env(safe-area-inset-right));
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #f6f4ef;
  --fg: #16181c;
  --muted: #5f6670;
  --surface: #ffffff;
  --surface-2: #eeebe4;
  --line: #d9d5cc;
  --on: #12924b;
  --on-bg: rgba(18, 146, 75, .12);
  --shadow: 0 20px 60px rgba(30, 25, 10, .18);
  color-scheme: light;
}
@media (prefers-color-scheme: light) {
  :root[data-theme="auto"] {
    --bg: #f6f4ef;
    --fg: #16181c;
    --muted: #5f6670;
    --surface: #ffffff;
    --surface-2: #eeebe4;
    --line: #d9d5cc;
    --on: #12924b;
    --on-bg: rgba(18, 146, 75, .12);
    --shadow: 0 20px 60px rgba(30, 25, 10, .18);
    color-scheme: light;
  }
}

/* Accents: a brighter tone for dark backgrounds, a deeper one for light. */
:root[data-accent="amber"]  { --accent: #ffb84d; --accent-l: #b86e00; }
:root[data-accent="mint"]   { --accent: #5ee0a0; --accent-l: #0f8a52; }
:root[data-accent="sky"]    { --accent: #6cb8ff; --accent-l: #1867c0; }
:root[data-accent="rose"]   { --accent: #ff7a90; --accent-l: #c22d4a; }
:root[data-accent="violet"] { --accent: #b49bff; --accent-l: #6a45d6; }
:root[data-accent="mono"]   { --accent: #eef0f3; --accent-l: #16181c; }
:root[data-theme="light"] { --accent: var(--accent-l); }
@media (prefers-color-scheme: light) {
  :root[data-theme="auto"] { --accent: var(--accent-l); }
}

:root[data-font="mono"]  { --font-clock: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace; }
:root[data-font="serif"] { --font-clock: ui-serif, "New York", Georgia, "Times New Roman", serif; }

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.5 var(--font-ui);
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 100dvh;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  transition: background-color .3s, color .3s;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip { position: absolute; left: -999px; top: 8px; z-index: 10; background: var(--surface); color: var(--fg); padding: 8px 12px; border-radius: 8px; }
.skip:focus { left: 16px; }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }

/* ---- Top and bottom bars ---- */
.chrome {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px var(--gutter);
  transition: opacity .5s ease;
}
.top { justify-content: space-between; align-items: flex-start; padding-top: max(16px, env(safe-area-inset-top)); }
.bottom { justify-content: center; flex-wrap: wrap; padding-bottom: max(20px, env(safe-area-inset-bottom)); }
body.idle .chrome:not(:focus-within) { opacity: 0; }
body.idle { cursor: none; }

.brand { font-weight: 700; letter-spacing: .02em; color: var(--muted); font-size: 14px; padding-top: 5px; }

.status { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.pill {
  display: inline-flex; align-items: center; gap: 8px; align-self: flex-start;
  padding: 5px 12px 5px 10px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted);
  font-size: 13px; font-weight: 600; white-space: nowrap;
  transition: background-color .3s, color .3s;
}
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.pill[data-state="on"] { background: var(--on-bg); color: var(--on); }
.pill[data-state="on"] .dot { box-shadow: 0 0 0 0 currentColor; animation: pulse 2.4s ease-out infinite; }
.pill[data-state="pending"] { color: var(--fg); }
.pill[data-state="unsupported"] { text-decoration: none; opacity: .8; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, currentColor 60%, transparent); }
  70%, 100% { box-shadow: 0 0 0 7px transparent; }
}
.note { margin: 0; font-size: 12.5px; color: var(--muted); }

.link {
  background: none; border: 0; padding: 0; font: inherit; color: var(--fg);
  text-decoration: underline; text-underline-offset: 2px; cursor: pointer; border-radius: 3px;
}

/* ---- Clock ---- */
.clock {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 0; padding: 0 var(--gutter);
}
.time {
  font-family: var(--font-clock);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
  font-weight: 600;
  line-height: .9;
  letter-spacing: -.03em;
  display: flex; align-items: flex-start;
  white-space: nowrap;
  font-size: var(--clock-size, min(26vw, 55vh));
  color: var(--fg);
}
:root[data-font="mono"] .time { letter-spacing: -.06em; font-weight: 500; }
:root[data-font="serif"] .time { font-weight: 500; letter-spacing: -.02em; }
.time .side {
  display: flex; flex-direction: column; justify-content: space-between;
  font-size: .3em; line-height: 1; margin-left: .25em; padding: .18em 0;
  align-self: stretch; letter-spacing: 0;
}
.sec { color: var(--accent); }
.ampm { color: var(--muted); font-size: .62em; font-weight: 600; letter-spacing: .04em; }
body:not(.show-seconds) .sec { display: none; }
body:not(.show-seconds) .time .side { justify-content: flex-end; }
body.h24 .ampm { display: none; }
body.h24:not(.show-seconds) .time .side { display: none; }

.date {
  font-size: calc(var(--clock-size, 20vw) * .12);
  color: var(--muted);
  margin-top: .6em;
  font-weight: 500;
  text-align: center;
}
body:not(.show-date) .date { display: none; }

/* ---- Buttons ---- */
.btn {
  font: inherit; color: var(--fg); background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 999px;
  min-height: 44px; padding: 0 18px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  cursor: pointer; transition: background-color .2s, border-color .2s, color .2s, transform .1s;
}
.btn:hover { border-color: var(--muted); }
.btn:active { transform: scale(.97); }
.btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.btn.icon { width: 44px; padding: 0; }
.btn.primary { font-weight: 650; padding: 0 22px; }
.btn.primary[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--bg); }
.btn[hidden] { display: none; }

/* ---- Dialogs ---- */
dialog {
  border: 1px solid var(--line); border-radius: 18px; padding: 0;
  background: var(--surface); color: var(--fg);
  width: min(440px, calc(100vw - 32px)); max-height: calc(100dvh - 32px);
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(0, 0, 0, .55); backdrop-filter: blur(3px); }
.panel { padding: 20px 22px 22px; }
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.panel h2 { font-size: 18px; margin: 8px 0 0; line-height: 1.3; }
.panel p, .panel li { color: var(--fg); }
.panel ul { padding-left: 20px; }
.panel code { background: var(--surface-2); padding: 1px 6px; border-radius: 6px; font-size: .92em; }
.muted { color: var(--muted) !important; font-size: 13.5px; }
.close { flex: none; }

fieldset { border: 0; padding: 0; margin: 16px 0 0; }
legend { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: 8px; padding: 0; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; border-bottom: 1px solid var(--line); cursor: pointer; }
.row:last-child { border-bottom: 0; }
kbd {
  font: 600 11px/1 var(--font-ui); padding: 3px 6px; border-radius: 5px;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--muted);
  vertical-align: 1px; margin-left: 4px;
}
legend kbd { text-transform: none; }

input[type="checkbox"][role="switch"] {
  appearance: none; -webkit-appearance: none; margin: 0; flex: none;
  width: 44px; height: 26px; border-radius: 999px; background: var(--line);
  position: relative; cursor: pointer; transition: background-color .2s;
}
input[type="checkbox"][role="switch"]::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%;
  background: #fff; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.3);
}
input[type="checkbox"][role="switch"]:checked { background: var(--accent); }
input[type="checkbox"][role="switch"]:checked::after { transform: translateX(18px); }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 12px; }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg span { display: block; text-align: center; padding: 9px 4px; border-radius: 9px; font-weight: 600; color: var(--muted); }
.seg input:checked + span { background: var(--surface); color: var(--fg); box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.seg input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 1px; }
.f-sans { font-family: system-ui, sans-serif; }
.f-mono { font-family: ui-monospace, Menlo, monospace; }
.f-serif { font-family: ui-serif, Georgia, serif; }

.swatches { display: flex; gap: 10px; flex-wrap: wrap; }
.swatch { position: relative; width: 36px; height: 36px; border-radius: 50%; background: var(--sw); cursor: pointer; border: 2px solid var(--line); }
.swatch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.swatch:has(input:checked) { box-shadow: 0 0 0 3px var(--surface), 0 0 0 5px var(--fg); }
.swatch:has(input:focus-visible) { outline: 3px solid var(--accent); outline-offset: 5px; }

.keys { margin: 20px 0 0; font-size: 13px; color: var(--muted); }
.keys kbd { margin: 0 2px; }

/* The fallback video sits off to the side, tiny and invisible. */
.nosleep { position: fixed; width: 1px; height: 1px; opacity: 0; pointer-events: none; left: 0; bottom: 0; }

/* Phones */
@media (max-width: 520px) {
  .brand { display: none; }
  .btn.primary { flex: 1 1 100%; max-width: 360px; order: -1; }
  .bottom { gap: 10px; }
}
@media (max-height: 420px) {
  .note { display: none; }
  .chrome { padding-top: 10px; padding-bottom: 10px; }
}

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