@font-face {
  font-family: "Instrument Sans";
  src: url("fonts/instrument-sans.woff2") format("woff2");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}

/* ---------- Tokens ---------- */
:root {
  --mist: #eef1f4;      /* page */
  --glass: #ffffff;     /* panels */
  --well: #e3e8ee;      /* behind screenshots */
  --ink: #1b2430;
  --slate: #5b6675;     /* secondary text */
  --rule: #d4dbe3;
  --signal: #0e7c7b;    /* the one accent: live state, selection, time rail marks */
  --signal-soft: #d6eeed;
  --danger: #b4322d;
  --focus: #0e7c7b;

  --radius-tile: 10px;  /* echoes a phone screen */
  --radius-panel: 14px;
  --radius-control: 8px;

  --font: "Instrument Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --mist: #12161c;
    --glass: #1a2029;
    --well: #222a35;
    --ink: #e6eaf0;
    --slate: #93a0b0;
    --rule: #2c3540;
    --signal: #4fb3b0;
    --signal-soft: #173a3a;
    --danger: #ef7d76;
    --focus: #4fb3b0;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--mist);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
h1, h2, p { margin: 0; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* ---------- Controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px; padding: 0 14px;
  border: 1px solid var(--rule); border-radius: var(--radius-control);
  background: var(--glass); color: inherit; cursor: pointer; text-decoration: none;
  font-weight: 550;
}
.btn:hover { border-color: var(--slate); }
.btn-primary { background: var(--ink); color: var(--glass); border-color: var(--ink); }
.btn-primary:hover { opacity: 0.9; }
.btn-primary:disabled { opacity: 0.55; cursor: progress; }
.btn-quiet { background: transparent; }
.btn-danger { background: transparent; color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, transparent); }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 10%, transparent); border-color: var(--danger); }

.brand { font-size: 28px; font-weight: 650; letter-spacing: -0.02em; }
.brand-small { font-size: 18px; }

/* ---------- Sign in ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: min(380px, 100%); display: grid; gap: 16px;
  padding: 32px 28px; background: var(--glass);
  border: 1px solid var(--rule); border-radius: var(--radius-panel);
}
.login-lead { color: var(--slate); margin-top: -8px; }
.field { display: grid; gap: 6px; font-weight: 550; font-size: 14px; }
.field input {
  min-height: 42px; padding: 0 12px; font-weight: 400; font-size: 15px;
  border: 1px solid var(--rule); border-radius: var(--radius-control); background: var(--mist);
}
.field input:focus-visible { outline-offset: 0; }
.form-error { color: var(--danger); font-size: 14px; }
.optional, .hint { color: var(--slate); font-weight: 400; }
.hint { font-size: 13px; }
.switch { color: var(--slate); font-size: 14px; text-align: center; }
.switch a { color: var(--ink); font-weight: 550; }

/* ---------- Shell ---------- */
.shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  grid-template-rows: 56px 1fr;
  grid-template-areas: "top top" "nav main";
}
.topbar {
  grid-area: top; display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px; border-bottom: 1px solid var(--rule); background: var(--glass);
  position: sticky; top: 0; z-index: 5;
}
.topbar-right { display: flex; align-items: center; gap: 14px; }
.user-email { color: var(--slate); font-size: 14px; }
.live { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; color: var(--signal); }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--signal); }

.devices { grid-area: nav; padding: 20px 12px; border-right: 1px solid var(--rule); }
.devices-title { font-size: 13px; font-weight: 600; color: var(--slate); padding: 0 10px 8px; }
.device-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; position: sticky; top: 76px; }
.device-btn {
  width: 100%; text-align: left; display: grid; gap: 2px;
  padding: 10px; border: 0; border-radius: var(--radius-control);
  background: transparent; cursor: pointer;
}
.device-btn:hover { background: var(--well); }
.device-btn[aria-current="true"] { background: var(--signal-soft); }
.device-btn-name { font-weight: 600; }
.device-btn-sub { font-size: 13px; color: var(--slate); }
.device-btn-sub .removed { color: var(--danger); }
.device-select-wrap { display: none; }
.device-select-wrap select {
  width: 100%; min-height: 40px; padding: 0 10px;
  border: 1px solid var(--rule); border-radius: var(--radius-control); background: var(--glass);
}

.content { grid-area: main; padding: 24px 32px 48px; min-width: 0; }
.device-head { display: flex; justify-content: space-between; align-items: end; margin-bottom: 20px; }
.device-name { font-size: 24px; font-weight: 650; letter-spacing: -0.015em; }
.device-meta { color: var(--slate); font-size: 14px; font-variant-numeric: tabular-nums; }

/* ---------- The time rail ---------- */
.day { margin-bottom: 28px; }
.day-title {
  font-size: 15px; font-weight: 650; margin: 0 0 8px 0;
  position: sticky; top: 56px; z-index: 2; padding: 8px 0;
  background: var(--mist);
}
.hour {
  display: grid; grid-template-columns: 96px minmax(0, 1fr);
  position: relative;
}
/* the rail: a line down the left edge, a mark at each hour, the hour beside it */
.hour::before {
  content: ""; position: absolute; left: 4px; top: 0; bottom: 0;
  width: 1px; background: var(--rule);
}
.hour-label {
  position: relative; padding: 1px 0 0 20px;
  font-size: 13px; font-weight: 600; color: var(--slate);
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.hour-label::after {
  content: ""; position: absolute; left: 0; top: 7px;
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--mist); border: 1.5px solid var(--signal);
}
.tiles {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(116px, 1fr));
  gap: 12px; padding-bottom: 20px;
}
.tile {
  display: grid; gap: 6px; padding: 0; border: 0; background: none;
  cursor: zoom-in; text-align: left; border-radius: var(--radius-tile);
}
.tile-img {
  display: block; width: 100%; aspect-ratio: 9 / 19;
  object-fit: contain; background: var(--well);
  border-radius: var(--radius-tile); border: 1px solid var(--rule);
}
.tile:hover .tile-img { border-color: var(--slate); }
.tile-time { font-size: 12px; color: var(--slate); font-variant-numeric: tabular-nums; padding-left: 2px; }
.tile.is-new .tile-img { border-color: var(--signal); box-shadow: 0 0 0 2px var(--signal-soft); }
.tile.is-new .tile-time { color: var(--signal); font-weight: 600; }

.more { display: grid; justify-items: start; padding-left: 96px; }
.loading { color: var(--slate); font-size: 14px; }

.empty {
  max-width: 460px; padding: 28px; background: var(--glass);
  border: 1px solid var(--rule); border-radius: var(--radius-panel);
}
.empty h2 { font-size: 17px; font-weight: 650; margin-bottom: 6px; }
.empty p { color: var(--slate); }

/* ---------- Viewer ---------- */
.viewer {
  width: min(1100px, 96vw); height: min(92vh, 960px); max-width: none; max-height: none;
  padding: 0; border: 1px solid var(--rule); border-radius: var(--radius-panel);
  background: var(--glass); color: var(--ink);
}
.viewer::backdrop { background: rgb(10 14 20 / 0.72); }
.viewer-body {
  height: 100%; display: grid;
  grid-template-columns: 48px minmax(0, 1fr) 48px 260px;
  align-items: stretch;
}
.viewer-figure {
  margin: 0; height: 100%; min-height: 0; overflow: hidden; padding: 16px;
  display: flex; align-items: center; justify-content: center; background: var(--well);
}
.viewer-figure img {
  display: block; max-width: 100%; max-height: 100%; width: auto; height: auto;
  object-fit: contain; border-radius: var(--radius-tile);
}
.viewer-nav {
  border: 0; background: var(--well); cursor: pointer;
  font-size: 32px; line-height: 1; color: var(--slate);
}
.viewer-nav:hover:not(:disabled) { color: var(--ink); }
.viewer-nav:disabled { opacity: 0.3; cursor: default; }
.viewer-info {
  display: flex; flex-direction: column; gap: 14px;
  padding: 20px; border-left: 1px solid var(--rule);
}
.viewer-close { align-self: flex-end; }
.viewer-time { font-size: 32px; font-weight: 650; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.viewer-facts { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; font-size: 14px; }
.viewer-facts dt { color: var(--slate); }
.viewer-facts dd { margin: 0; font-variant-numeric: tabular-nums; }
#viewer-delete { margin-top: auto; }

.confirm {
  width: min(420px, 92vw); padding: 24px; border: 1px solid var(--rule);
  border-radius: var(--radius-panel); background: var(--glass); color: var(--ink);
}
.confirm::backdrop { background: rgb(10 14 20 / 0.6); }
.confirm h2 { font-size: 18px; font-weight: 650; margin-bottom: 8px; }
.confirm p { color: var(--slate); }
.confirm-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  padding: 10px 16px; border-radius: var(--radius-control);
  background: var(--ink); color: var(--glass); font-size: 14px; font-weight: 550;
  z-index: 20;
}

/* ---------- Small screens ---------- */
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; grid-template-areas: "top" "nav" "main"; grid-template-rows: 56px auto 1fr; }
  .topbar { padding: 0 16px; }
  .user-email { display: none; }
  .devices { border-right: 0; padding: 12px 16px 0; }
  .devices-title, .device-list { display: none; }
  .device-select-wrap { display: block; }
  .content { padding: 16px 16px 40px; }
  .hour { grid-template-columns: 1fr; }
  .hour-label { padding-bottom: 8px; }
  .tiles { grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; padding-left: 20px; }
  .more { padding-left: 20px; }
  .viewer { width: 100vw; height: 100vh; border-radius: 0; }
  .viewer-body { grid-template-columns: 36px minmax(0, 1fr) 36px; grid-template-rows: minmax(0, 1fr) auto; }
  .viewer-info { grid-column: 1 / -1; border-left: 0; border-top: 1px solid var(--rule); }
  .viewer-time { font-size: 24px; }
}

@media (prefers-reduced-motion: no-preference) {
  .tile.is-new .tile-img { transition: border-color 1.2s ease, box-shadow 1.2s ease; }
}
