/* 07 Night shift (js/night.js): the pixel night behind the section, and the log of one night on Lantern over it.
   The log is vertical by default and lays out along a time axis from 1100px. */

#night-demo { position: absolute; inset: 0; z-index: 0; overflow: hidden; pointer-events: none; }
.ns-layer { position: absolute; left: 0; image-rendering: pixelated; image-rendering: crisp-edges; image-rendering: pixelated; will-change: transform; }

#night-log { position: relative; margin: 0 0 200px; --nl-card: var(--night-2); }

/* Head: what this is, the span of the night, and a replay. */
.nl-head { display: flex; align-items: center; gap: 14px; min-height: 30px; margin-bottom: 16px; }
.nl-title { display: inline-flex; align-items: center; gap: 10px; font-size: 13.5px; color: var(--muted); }
.nl-title b { color: var(--paper); font-weight: 650; }
.nl-moon { width: 14px; height: 14px; color: var(--paper); }
.nl-range { font: 500 11.5px/1 var(--font-mono); color: var(--dim); letter-spacing: 0.02em; }
.nl-replay {
  margin-left: auto; display: inline-flex; align-items: center; gap: 7px; min-height: 30px; padding: 0 11px; cursor: pointer;
  border: 1px solid var(--line-2); border-radius: 7px; background: color-mix(in srgb, var(--night-3) 80%, transparent);
  font: 500 11.5px/1 var(--font-mono); color: var(--muted); transition: color 0.15s, border-color 0.15s, opacity 0.3s;
}
.nl-replay:hover { color: var(--paper); border-color: var(--dim); }
.nl-replay-i { width: 6px; height: 6px; color: currentColor; }
#night-log.playing .nl-replay { opacity: 0.45; }

/* The playhead's clock. */
.nl-clock {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 7px; border-radius: 5px; white-space: nowrap;
  background: var(--paper); color: var(--night); font: 650 11px/1 var(--font-mono); letter-spacing: 0.02em;
  box-shadow: 3px 3px 0 var(--accent);
}
.nl-clock-i { width: 10px; height: 12px; color: var(--night); }
.nl-hclock { display: none; }

/* Cards: one per event, lit in the colour of who acted. */
.nl-list { list-style: none; margin: 0; padding: 0 0 0 30px; position: relative; display: grid; gap: 8px; }
.nl-ev { position: relative; min-width: 0; }
.nl-card {
  display: flex; flex-direction: column; justify-content: flex-start; width: 100%; text-align: left; cursor: pointer; padding: 11px 12px 12px;
  background: var(--nl-card); border: 1px solid var(--line); border-radius: 10px; color: var(--text);
  transition: border-color 0.2s, background-color 0.2s;
}
.nl-card > * { transition: opacity 0.6s ease; }
.nl-card:hover { border-color: var(--line-2); }
.nl-card:focus-visible { outline-offset: 2px; }
.nl-you { background: color-mix(in srgb, var(--accent) 7%, var(--nl-card)); }
.nl-meta { display: flex; align-items: center; gap: 7px; font: 500 11px/1 var(--font-mono); color: var(--dim); }
.nl-meta time { color: var(--muted); }
.nl-who { display: block; margin-top: 8px; font: 600 11px/1 var(--font-mono); color: var(--c); }
.nl-led { display: inline-block; flex: none; width: 7px; height: 7px; background: var(--line-2); transition: background 0.3s, box-shadow 0.3s; }
.lit .nl-led, .nl-sub.lit .nl-led { background: var(--c); box-shadow: 0 0 8px var(--c); }
.nl-chat { margin-left: auto; display: inline-flex; color: var(--paper); opacity: 0.75; }
.nl-bubble { width: 12px; height: 10px; color: currentColor; }
.nl-text { display: block; margin-top: 6px; font-size: 12.5px; line-height: 1.5; color: var(--text); }
.nl-text q { color: var(--paper); quotes: "\201C" "\201D"; }
.nl-you .nl-text q { font-weight: 550; }
.nl-name { color: var(--c); font-family: var(--font-mono); font-size: 11.5px; }
.nl-chip {
  display: inline-block; font: 600 10.5px/1 var(--font-mono); padding: 3px 5px; border-radius: 4px; margin: 0 2px 0 0;
  background: var(--night-4); color: var(--muted); vertical-align: 1px; white-space: nowrap;
}
.nl-chip.bad { background: color-mix(in srgb, var(--bad) 16%, transparent); color: var(--bad); }
.nl-chip.ok { background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok); }
.nl-sub {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 7px; margin-top: 9px; padding-top: 9px; border-top: 1px dashed var(--line);
  font: 500 11px/1.2 var(--font-mono); color: var(--muted); transition: opacity 0.6s;
}
.nl-sub .nl-name { font-size: 11px; font-weight: 600; }

/* Before the sweep reaches them: faint. */
#night-log.armed .nl-ev:not(.lit) .nl-card > * { opacity: 0.24; }
#night-log.armed .nl-ev:not(.lit) .nl-card { border-color: color-mix(in srgb, var(--line) 60%, transparent); }
#night-log.armed .nl-sub:not(.lit) { opacity: 0.25; }
.nl-ev.lit .nl-card { animation: nl-in 0.5s steps(4) 1; }
@keyframes nl-in { 0% { border-color: var(--c); } 100% { border-color: var(--line); } }

/* Highlighted, by hover, focus or a tap. */
#night-log.hl-on .nl-ev:not(.hl) .nl-card > * { opacity: 0.5; }
.nl-ev.hl .nl-card { border-color: var(--c); background: color-mix(in srgb, var(--c) 9%, var(--night-2)); }

/* The quiet hours: hollow marks that never reach the chat. */
.nl-qg { display: inline-flex; gap: 3px; }
.nl-qg i { width: 6px; height: 6px; border: 1px solid var(--line-2); transition: border-color 0.4s; }
.nl-qg.lit i, .lit .nl-qg i { border-color: var(--dim); }
.nl-qg.lit i, .lit > .nl-qg i { animation: nl-check 0.7s steps(3) 1 backwards; }
.nl-qg i:nth-child(2) { animation-delay: 0.08s !important; }
.nl-qg i:nth-child(3) { animation-delay: 0.16s !important; }
@keyframes nl-check { 0% { border-color: var(--line-2); } 40% { border-color: var(--muted); } 100% { border-color: var(--dim); } }

/* Summary. */
.nl-sum { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; margin-top: 18px; font: 500 12px/1.2 var(--font-mono); color: var(--muted); }
.nl-sum-g { display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; }
.nl-sum b { color: var(--paper); font-weight: 650; min-width: 1.2ch; text-align: right; font-variant-numeric: tabular-nums; }
.nl-sum-i { display: inline-flex; }
.nl-sum-chat { color: var(--paper); opacity: 0.8; }
.nl-sum-quiet i { width: 8px; height: 8px; border: 1px solid var(--dim); }
.nl-dot { color: var(--dim); margin: 0 4px; }

/* The push notification, on the phone (wide) or under the ask (narrow). */
.nl-push { border-radius: 12px; background: #191d33; border: 1px solid #262b4a; padding: 9px 10px 10px; color: var(--text); text-align: left; }
.nl-push-head { display: flex; align-items: center; gap: 6px; font: 500 10px/1 var(--font-mono); color: var(--dim); }
.nl-push-head b { color: var(--paper); font-weight: 650; }
.nl-push-head time { margin-left: auto; }
.nl-app { display: inline-grid; place-items: center; width: 16px; height: 16px; border-radius: 4px; background: #050b26; }
.nl-app-4 { width: 6.5px; height: 8px; color: var(--paper); }
.nl-app-4 .px-off { fill: var(--accent); }
.nl-push-body { margin-top: 7px; font-size: 11.5px; line-height: 1.4; color: var(--paper); }
.nl-push-body b { display: block; font: 600 10.5px/1.3 var(--font-mono); color: var(--ember); margin-bottom: 1px; }
.nl-push-acts { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 9px; }
.nl-push-acts span {
  display: grid; place-items: center; height: 24px; border-radius: 6px; background: #262b4a; font: 600 10.5px/1 var(--font-mono); color: var(--text);
  transition: background 0.3s, color 0.3s, opacity 0.3s;
}
#night-log.picked .nl-push-acts span:first-child { opacity: 0.45; }
#night-log.picked .nl-pick { background: var(--accent); color: var(--night); }

.nl-push-inline { max-width: 360px; margin: 8px 0 0; transition: opacity 0.5s, transform 0.5s cubic-bezier(0.2, 0.8, 0.2, 1); }
#night-log.armed:not(.asked) .nl-push-inline { opacity: 0; transform: translateY(-6px); }

.nl-phone { display: none; }

/* Narrow: a vertical axis down the left, the playhead a light running down it, the clock in the head. */
@media (max-width: 1099.98px) {
  .nl-track { display: none; }
  .nl-list::before { content: ""; position: absolute; left: 8px; top: 14px; bottom: 14px; width: 1px; background: var(--line-2); }
  .nl-ev::before {
    content: ""; position: absolute; left: -26px; top: 12px; width: 9px; height: 9px; box-sizing: border-box;
    border: 1px solid var(--line-2); background: var(--night); transition: background 0.3s, border-color 0.3s, box-shadow 0.3s;
  }
  .nl-ev.lit::before { background: var(--c); border-color: var(--c); box-shadow: 0 0 9px var(--c); }
  .nl-ev.hl::before { transform: scale(1.3); }
  .nl-quiet-row { position: relative; display: flex; align-items: center; gap: 10px; height: 22px; padding-left: 12px; font: 500 11px/1 var(--font-mono); color: var(--dim); }
  .nl-quiet-row .nl-qg { position: absolute; left: -16px; top: 8px; gap: 2px; }
  .nl-quiet-row .nl-qg i { width: 6px; height: 6px; }
  .nl-quiet-row time { color: var(--dim); }
  .nl-quiet-row .nl-qtext { color: var(--dim); opacity: 0.8; }
  #night-log.armed .nl-quiet-row:not(.lit) { opacity: 0.4; }
  .nl-play-v {
    position: absolute; left: 6px; top: 0; width: 5px; height: 34px; margin-top: -17px; pointer-events: none; opacity: 0;
    background: linear-gradient(to bottom, transparent, var(--paper) 45%, var(--paper) 55%, transparent); transition: opacity 0.4s;
  }
  .nl-play-v .nl-clock { display: none; }
  #night-log.playing .nl-play-v { opacity: 0.9; }
  #night-log.playing .nl-head .nl-hclock { display: inline-flex; }
  #night-log.playing .nl-head .nl-range { display: none; }
}

/* Wide: a time axis with the night's hours, leaders down to a row of cards, and your phone up in the sky. */
@media (min-width: 1100px) {
  #night-log { margin-bottom: 220px; }
  .nl-play-v { display: none; }
  .nl-track { position: relative; height: 86px; }
  .nl-hours { position: absolute; left: 0; right: 0; top: 32px; }
  .nl-hour { position: absolute; transform: translateX(-50%); font: 500 10.5px/1 var(--font-mono); color: var(--muted); }
  .nl-hour::after { content: ""; position: absolute; left: 50%; top: 42px; width: 1px; height: 5px; background: var(--line-2); }
  .nl-axis { position: absolute; left: -10px; right: -10px; top: 80px; height: 1px; background: linear-gradient(90deg, transparent, var(--line-2) 2%, var(--line-2) 98%, transparent); }
  .nl-marks { position: absolute; left: 0; right: 0; top: 80px; height: 0; }
  .nl-mark {
    position: absolute; top: 0; width: 9px; height: 9px; margin: -4px 0 0 -4px; box-sizing: border-box; cursor: default;
    border: 1px solid var(--line-2); background: var(--night); transition: background 0.3s, border-color 0.3s, box-shadow 0.3s, transform 0.2s;
  }
  .nl-mark-sub { width: 7px; height: 7px; margin: -3px 0 0 -3px; }
  .nl-mark.lit { background: var(--c); border-color: var(--c); box-shadow: 0 0 9px var(--c); animation: nl-pop 0.45s steps(3) 1; }
  .nl-mark.hl { transform: scale(1.45); }
  @keyframes nl-pop { 0% { transform: scale(1.9); } 100% { transform: scale(1); } }
  .nl-quiet { position: absolute; left: 0; right: 0; top: 49px; }
  .nl-qg { position: absolute; top: 0; transform: translateX(-50%); flex-direction: column; align-items: center; gap: 2px; padding: 0 4px; }
  .nl-qg i { width: 6px; height: 6px; }
  .nl-qg::after { content: ""; width: 1px; height: 6px; margin-top: 1px; background: repeating-linear-gradient(to bottom, var(--line-2) 0 1px, transparent 1px 2px); }
  .nl-qtip {
    position: absolute; bottom: calc(100% + 22px); left: 50%; transform: translateX(-50%); padding: 4px 6px; border-radius: 4px;
    background: var(--night-3); border: 1px solid var(--line-2); font: 500 10.5px/1 var(--font-mono); color: var(--muted); white-space: nowrap;
    opacity: 0; pointer-events: none; transition: opacity 0.2s;
  }
  .nl-qg:hover .nl-qtip { opacity: 1; }
  .nl-leaders { position: absolute; left: 0; width: 100%; overflow: visible; pointer-events: none; }
  .nl-leaders path { fill: none; stroke: var(--line-2); stroke-width: 1; transition: stroke 0.4s, opacity 0.4s; }
  .nl-leaders path.lit { stroke: color-mix(in srgb, var(--c) 45%, var(--line-2)); }
  .nl-leaders path.hl { stroke: var(--c); stroke-width: 1.5; }
  .nl-track .nl-play { position: absolute; left: 0; top: 0; height: 92px; width: 0; opacity: 0; transition: opacity 0.5s; pointer-events: none; will-change: transform; }
  .nl-track .nl-play::before { content: ""; position: absolute; left: 0; top: 18px; bottom: 0; width: 1px; background: linear-gradient(to bottom, var(--paper), color-mix(in srgb, var(--paper) 20%, transparent)); }
  .nl-track .nl-play .nl-clock { position: absolute; top: 0; left: 0; transform: translateX(-50%); }
  #night-log.playing .nl-track .nl-play { opacity: 1; }
  .nl-list { grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 10px; padding: 0; margin-top: 46px; }
  .nl-card { height: 100%; }
  .nl-quiet-row { display: none; }
  .nl-push-inline { display: none; }

  .nl-phone {
    display: block; position: absolute; right: 6px; bottom: calc(100% + 30px); width: 164px; height: 250px; padding: 12px 9px;
    border-radius: 28px; background: #04050b; border: 1px solid var(--line-2);
    box-shadow: inset 0 0 0 3px #0b0d1a, 0 30px 60px -28px rgba(0, 0, 0, 0.9); transition: background-color 0.6s, box-shadow 0.6s;
  }
  .nl-notch { position: absolute; left: 50%; top: 11px; width: 44px; height: 11px; margin-left: -22px; border-radius: 6px; background: #000; }
  .nl-lock { display: block; margin-top: 30px; text-align: center; font: 300 38px/1 var(--font-sans); letter-spacing: -0.02em; color: var(--paper); opacity: 0.22; transition: opacity 0.6s; font-variant-numeric: tabular-nums; }
  .nl-push-phone { position: absolute; left: 9px; right: 9px; top: 94px; transition: opacity 0.5s, transform 0.5s cubic-bezier(0.2, 0.8, 0.2, 1); }
  #night-log:not(.asked) .nl-push-phone { opacity: 0; transform: translateY(-10px); }
  #night-log.asked .nl-phone { background: #0a0d1c; box-shadow: inset 0 0 0 3px #0b0d1a, 0 0 46px -16px color-mix(in srgb, var(--accent) 55%, transparent), 0 30px 60px -28px rgba(0, 0, 0, 0.9); }
  #night-log.asked .nl-lock { opacity: 0.85; }
  #night-log.playing.asked .nl-phone { animation: nl-buzz 0.42s steps(2) 2; }
  @keyframes nl-buzz { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-2px) rotate(-1deg); } 75% { transform: translateX(2px) rotate(1deg); } }
}

@media (max-width: 760px) {
  #night-log { margin-bottom: 190px; }
  .nl-range { display: none; }
}
@media (max-width: 480px) {
  .nl-sum { flex-direction: column; align-items: flex-start; }
  .nl-sum .nl-dot { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .nl-card, .nl-card > *, .nl-mark, .nl-qg i, .nl-push-inline, .nl-push-phone, .nl-phone { animation: none !important; transition: none !important; }
}
