/* ChronoVault demo - hand-written, no frameworks. */

:root {
  --bg: #0a0e13;
  --panel: #111822;
  --panel-2: #0d141d;
  --line: #1e2a38;
  --text: #e6edf3;
  --muted: #8496ab;
  --accent: #38bdf8;
  --accent-dim: #0ea5e9;
  --seal: #2dd4bf;
  --warn: #fbbf24;
  --danger: #f87171;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html { background: var(--bg); }

body {
  margin: 0;
  background: radial-gradient(1200px 600px at 50% -10%, #16202c 0%, var(--bg) 60%);
  color: var(--text);
  font: 15px/1.55 var(--sans);
  min-height: 100vh;
}

a { color: var(--accent); }

.wrap { max-width: 900px; margin: 0 auto; padding: 32px 20px 64px; }
.wrap.narrow { max-width: 460px; padding-top: 12vh; }

/* --- header --- */

header.top {
  display: flex; align-items: center; gap: 14px;
  /* Wraps rather than overflowing: on a narrow screen the session line and
     Lock button drop to a second row under the brand. */
  flex-wrap: wrap; row-gap: 10px;
  padding-bottom: 18px; margin-bottom: 28px;
  border-bottom: 1px solid var(--line);
}
header.top .spacer { flex: 1; }

.brand { display: flex; align-items: center; gap: 14px; }
.brand .mark {
  width: 48px; height: 48px; flex: none;
  border-radius: 13px;
  background: linear-gradient(150deg, var(--seal), var(--accent-dim));
  display: grid; place-items: center;
  color: #04222b; font-weight: 700; font-size: 21px;
  box-shadow: 0 0 0 1px rgba(56, 189, 248, .25), 0 8px 26px -8px var(--accent);
}
.brand .mark { text-decoration: none; }
.brand-name {
  display: block; color: var(--text); text-decoration: none;
  font-size: 25px; font-weight: 700; letter-spacing: -.015em; line-height: 1.15;
}
/* Same look whether it is the b4igo.com credit or a plain page descriptor. */
.brand-sub {
  display: block; color: var(--muted); font-size: 12px;
  letter-spacing: .12em; text-transform: uppercase; margin-top: 1px;
}
a.brand-sub { text-decoration: none; }
a.brand-sub:hover, a.brand-sub:focus-visible { color: var(--seal); text-decoration: underline; }

.who { color: var(--muted); font-size: 13px; }
.who b { color: var(--text); font-weight: 600; }

/* --- panels --- */

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 20px;
}
.card > h2 {
  margin: 0 0 4px; font-size: 15px; letter-spacing: .02em;
  display: flex; align-items: center; gap: 8px;
}
.card > h2 + p.hint { margin-top: 0; }

p.hint { color: var(--muted); font-size: 13px; margin: 0 0 18px; }

.card.locked { border-color: #4a1f1f; background: linear-gradient(180deg, rgba(248, 113, 113, .07), transparent 60%), var(--panel); }
.card.locked > h2 { color: var(--danger); }

.note {
  border-left: 2px solid var(--seal);
  background: var(--panel-2);
  padding: 11px 14px;
  border-radius: 0 8px 8px 0;
  color: var(--muted);
  font-size: 13px;
  margin: 0 0 20px;
}
.note b { color: var(--seal); font-weight: 600; }
.note.warn { border-left-color: var(--warn); }
.note.warn b { color: var(--warn); }

/* --- forms --- */

.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; }
.grid .full { grid-column: 1 / -1; }
@media (max-width: 620px) { .grid { grid-template-columns: 1fr; } }

label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; letter-spacing: .03em; }

input[type=text], input[type=password], input[type=date], select, textarea {
  width: 100%;
  padding: 9px 11px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font: inherit;
}
textarea { resize: vertical; min-height: 76px; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent-dim);
  box-shadow: 0 0 0 3px rgba(14, 165, 233, .15);
}

.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }

button {
  font: inherit; font-weight: 600;
  padding: 9px 16px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
}
button:hover { border-color: #2b3b4e; }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary { background: var(--accent-dim); border-color: var(--accent); color: #04222b; }
button.primary:hover { background: var(--accent); }
button.seal { background: var(--seal); border-color: var(--seal); color: #04222b; }
button.ghost { background: transparent; }
button.link { background: none; border: none; color: var(--muted); padding: 4px 6px; text-decoration: underline; font-weight: 400; }
button.link:hover { color: var(--danger); }

/* --- status --- */

.status { font-size: 13px; color: var(--muted); min-height: 20px; }
.status.ok { color: var(--seal); }
.status.err { color: var(--danger); }

/* --- breakglass output --- */

.bg-out { display: none; gap: 20px; margin-top: 20px; align-items: flex-start; }
.bg-out.on { display: flex; }
@media (max-width: 620px) { .bg-out { flex-direction: column; } }

.qr {
  background: #fff; padding: 12px; border-radius: 8px; flex: none;
  line-height: 0;
}
.qr svg { width: 190px; height: 190px; display: block; }

.bg-meta { flex: 1; min-width: 0; }
.uri {
  font-family: var(--mono); font-size: 12px;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 8px; padding: 10px 12px;
  word-break: break-all; margin: 8px 0 12px;
}
.uri .key { color: var(--warn); }

/* --- link list --- */

table.links { width: 100%; border-collapse: collapse; font-size: 13px; }
table.links th {
  text-align: left; color: var(--muted); font-weight: 500; font-size: 11px;
  letter-spacing: .07em; text-transform: uppercase;
  padding: 0 10px 8px 0; border-bottom: 1px solid var(--line);
}
table.links td { padding: 10px 10px 10px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
table.links tr:last-child td { border-bottom: none; }
table.links code { font-family: var(--mono); font-size: 12px; color: var(--accent); }
.empty { color: var(--muted); font-size: 13px; padding: 8px 0; }

.pill {
  display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 999px;
  border: 1px solid var(--line); color: var(--muted);
}
.pill.hot { color: var(--warn); border-color: #4a3a12; background: #241c07; }

/* --- breakglass reader page --- */

.reader { max-width: 720px; }
.seal-bar {
  display: flex; align-items: center; gap: 10px;
  background: linear-gradient(90deg, rgba(45,212,191,.12), transparent);
  border: 1px solid #16413c; border-radius: var(--radius);
  padding: 12px 16px; margin-bottom: 20px; font-size: 13px; color: var(--seal);
}
.seal-bar.bad { background: linear-gradient(90deg, rgba(248,113,113,.12), transparent); border-color: #4a1f1f; color: var(--danger); }

.record h3 {
  margin: 26px 0 10px; font-size: 12px; letter-spacing: .09em;
  text-transform: uppercase; color: var(--muted);
  border-bottom: 1px solid var(--line); padding-bottom: 8px;
}
.record .kv { display: grid; grid-template-columns: 190px 1fr; gap: 8px 16px; font-size: 14px; }
@media (max-width: 620px) { .record .kv { grid-template-columns: 1fr; gap: 2px 0; } }
.record .kv dt { color: var(--muted); font-size: 13px; }
.record .kv dd { margin: 0; white-space: pre-wrap; }
.record .kv dd:empty::after { content: "-"; color: var(--muted); }

footer.foot {
  margin-top: 40px; padding-top: 18px; border-top: 1px solid var(--line);
  color: var(--muted); font-size: 12px;
}
footer.foot code { font-family: var(--mono); color: #6f8299; }

/* --- phone lock screen simulation ---
   Every dimension on the screen is derived from real iOS points via --pt, so
   the widget carrying the QR occupies exactly the fraction of the display that
   accessoryRectangular does on a 430x932pt iPhone: 172x76pt, of which the
   square available to a QR code is 76x76pt (228x228px at @3x). */

body.stage {
  /* One iOS point. The phone itself is always true size for a 430x932pt
     iPhone; only the widget is blown up (see below). */
  --pt: 0.72px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  padding: 36px 20px 56px;
  background: radial-gradient(900px 500px at 50% 0%, #1a2734 0%, var(--bg) 65%);
}

/* The widget is drawn at 2x by default: deliberately out of proportion with
   the phone around it, but large enough that a phone camera can read the code
   straight off a desktop screen. Everything inside the widget derives from
   --pt, so overriding it here scales the widget as one piece and keeps its own
   172x76pt proportions exact. */
.phone .widget { --pt: 1.44px; }
.phone.true-scale .widget { --pt: 0.72px; }

.phone {
  --bezel: calc(15 * var(--pt));
  width: calc(430 * var(--pt) + 2 * var(--bezel));
  flex: none;
  border-radius: calc(58 * var(--pt) + var(--bezel));
  padding: var(--bezel);
  background: linear-gradient(160deg, #3a4553, #10161d 40%, #2b3541);
  box-shadow: 0 40px 80px -30px #000, 0 0 0 1px #05080b inset;
}

.screen {
  width: calc(430 * var(--pt));
  height: calc(932 * var(--pt));
  border-radius: calc(58 * var(--pt));
  overflow: hidden;
  background:
    radial-gradient(120% 60% at 50% 0%, #1d3a4d 0%, transparent 60%),
    linear-gradient(200deg, #14212c 0%, #0a1017 55%, #131c26 100%);
  color: #f3f7fb;
  display: flex;
  flex-direction: column;
  padding: calc(16 * var(--pt)) calc(24 * var(--pt)) calc(14 * var(--pt));
  font-family: var(--sans);
}

.statusbar {
  display: flex; align-items: center; justify-content: space-between;
  height: calc(38 * var(--pt)); flex: none;
  font-size: calc(15 * var(--pt)); color: #dbe6f0;
}
.statusbar .island {
  width: calc(125 * var(--pt)); height: calc(37 * var(--pt));
  border-radius: 999px; background: #05080b;
}
.statusbar .meters { font-size: calc(12 * var(--pt)); letter-spacing: .12em; }

/* On iOS 16 and later the date sits above the time, not below it. */
.glance { text-align: center; padding-top: calc(22 * var(--pt)); flex: none; }
.padlock { width: calc(22 * var(--pt)); height: calc(22 * var(--pt)); color: #cddcea; opacity: .85; }
.date { font-size: calc(21 * var(--pt)); color: #d6e2ee; margin-top: calc(6 * var(--pt)); }
.clock {
  font-size: calc(96 * var(--pt)); font-weight: 300; line-height: 1;
  white-space: nowrap;
  letter-spacing: -.02em; font-variant-numeric: tabular-nums;
  margin-top: calc(2 * var(--pt));
  text-shadow: 0 2px 20px rgba(0, 0, 0, .5);
}

/* The widget row, where a Lock Screen widget actually lives. */
.widget-row { display: flex; justify-content: center; margin-top: calc(26 * var(--pt)); flex: none; }

.widget {
  /* WidgetKit insets accessory content, and the real widget puts the QR in an
     HStack beside a label. 4pt all round is an estimate, not a published
     figure - it leaves a 68x68pt square rather than the full 76. */
  --inset: 4;
  width: calc(172 * var(--pt));
  height: calc(76 * var(--pt));
  padding: calc(var(--inset) * var(--pt));
  border-radius: calc(18 * var(--pt));
  background: rgba(235, 242, 249, .28);
  backdrop-filter: blur(6px);
  display: flex; align-items: center; overflow: hidden;
}
.widget-qr {
  width: calc((76 - 2 * var(--inset)) * var(--pt));
  height: calc((76 - 2 * var(--inset)) * var(--pt));
  flex: none; line-height: 0;
  border-radius: calc(4 * var(--pt));
  overflow: hidden;
}

/* Opaque: full black-on-white contrast. On iOS this is only reachable through
   a Live Activity - a Lock Screen widget cannot render this way. */
.widget.opaque .widget-qr { background: #fff; }

/* Vibrant: what iOS actually does. Per WWDC22, accessory content is
   desaturated and mapped into an adaptive material - light source colours stay
   bright and mostly opaque, dark ones become a blurred, slightly brightened
   view of whatever is behind the widget. So a white-on-black QR keeps its
   bright modules and loses its black field to the wallpaper. */
.widget.vibrant .widget-qr {
  background: none;
  backdrop-filter: blur(9px) brightness(1.25) saturate(0);
}
.widget-qr svg { width: 100%; height: 100%; display: block; }
.widget-text {
  padding: 0 calc(8 * var(--pt)); min-width: 0;
  font-size: calc(13 * var(--pt)); line-height: 1.25;
}
.widget-text b { display: block; font-size: calc(15 * var(--pt)); }
.widget-text small {
  display: block; color: #cfdae6; font-size: calc(12 * var(--pt));
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.widget.dead .widget-qr { display: none; }
.widget.dead { background: rgba(190, 60, 60, .3); }
.widget.dead .widget-text { padding: 0 calc(14 * var(--pt)); }

.tray {
  margin-top: auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 calc(34 * var(--pt));
  flex: none;
}
.tray-button {
  width: calc(50 * var(--pt)); height: calc(50 * var(--pt)); border-radius: 50%;
  background: rgba(255, 255, 255, .16);
  display: grid; place-items: center; font-size: calc(20 * var(--pt));
}
.grabber {
  width: calc(140 * var(--pt)); height: calc(5 * var(--pt));
  border-radius: 3px; background: rgba(255, 255, 255, .55);
  margin: calc(20 * var(--pt)) auto 0;
  flex: none;
}

/* Side by side at true widget size: what iOS gives you, and what it would look
   like if the material rendering were not in the way. */
.compare { display: flex; gap: 16px; flex-wrap: wrap; justify-content: center; max-width: 560px; }
.compare figure { margin: 0; flex: 1 1 250px; }
.compare .wallpaper {
  --pt: 1.44px; /* fixed at 2x so the contrast comparison stays legible */
  border-radius: var(--radius);
  padding: 18px 12px;
  display: flex; justify-content: center;
  background:
    radial-gradient(120% 90% at 30% 0%, #24455c 0%, transparent 60%),
    linear-gradient(200deg, #16242f 0%, #0a1017 60%, #16202b 100%);
  border: 1px solid var(--line);
}
.compare figcaption { font-size: 12px; color: var(--muted); line-height: 1.55; margin-top: 10px; }
.compare figcaption b { color: var(--text); font-weight: 600; display: block; }

/* Shown full size below the phone, because a true-to-scale widget QR is far
   too small to scan off a laptop screen - which is itself the point. */
.scan-aside {
  display: flex; align-items: center; gap: 18px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px; max-width: 460px;
}
.scan-aside .qr { padding: 8px; }
.scan-aside .qr svg { width: 132px; height: 132px; display: block; }
.scan-aside p { margin: 0; font-size: 12.5px; color: var(--muted); line-height: 1.6; }
.scan-aside b { color: var(--text); font-weight: 600; }

.controls { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.scale-toggle { display: flex; gap: 8px; }
.scale-toggle button {
  font-size: 12.5px; padding: 7px 14px; font-weight: 500;
  border-radius: 999px; border: 1px solid var(--line);
  background: var(--panel); color: var(--muted); cursor: pointer;
}
.scale-toggle button:hover { color: var(--text); border-color: #2b3b4e; }
.scale-toggle button[aria-pressed="true"] {
  background: var(--accent-dim); border-color: var(--accent);
  color: #04222b; font-weight: 600;
}

.stage-caption {
  max-width: 460px; margin: 0; text-align: center;
  color: var(--muted); font-size: 12.5px; line-height: 1.6;
}
.stage-caption code { font-family: var(--mono); color: #7f93a9; }
