@font-face {
  font-family: "Saira";
  src: url("fonts/saira.woff2") format("woff2");
  font-weight: 300 800;
  font-stretch: 50% 125%;
  font-display: swap;
}

:root {
  --red: #e31937;
  --red-glow: rgba(227, 25, 55, .35);
  --radius: 18px;
  --rail-w: 232px;
  --ease: cubic-bezier(.2, .8, .2, 1);
}

[data-theme="dark"] {
  --bg: #0d0e10;
  --bg-2: #15171a;
  --panel: #1a1c20;
  --panel-hi: #23262b;
  --line: rgba(255, 255, 255, .07);
  --line-hi: rgba(255, 255, 255, .16);
  --ink: #eceae6;
  --ink-2: #9a9da3;
  --ink-3: #5d6168;
  --plate: #f3f2ef;
  --shadow: 0 1px 0 rgba(255, 255, 255, .04) inset, 0 10px 30px -12px rgba(0, 0, 0, .7);
  --glow: radial-gradient(1200px 600px at 78% -10%, rgba(227, 25, 55, .10), transparent 60%),
          radial-gradient(900px 700px at -10% 110%, rgba(120, 140, 170, .08), transparent 60%);
  color-scheme: dark;
}

[data-theme="light"] {
  --bg: #e9e8e4;
  --bg-2: #dfdeda;
  --panel: #f6f5f2;
  --panel-hi: #ffffff;
  --line: rgba(0, 0, 0, .07);
  --line-hi: rgba(0, 0, 0, .18);
  --ink: #16171a;
  --ink-2: #5c5f66;
  --ink-3: #9a9ca1;
  --plate: #ffffff;
  --shadow: 0 1px 0 rgba(255, 255, 255, .9) inset, 0 10px 24px -14px rgba(30, 30, 40, .35);
  --glow: radial-gradient(1200px 600px at 78% -10%, rgba(227, 25, 55, .07), transparent 60%),
          radial-gradient(900px 700px at -10% 110%, rgba(255, 255, 255, .7), transparent 60%);
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Saira", "Segoe UI", sans-serif;
  font-stretch: 100%;
  background: var(--glow), var(--bg);
  background-attachment: fixed;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  overflow: hidden;
  transition: background-color .4s var(--ease), color .4s var(--ease);
}

.grain {
  position: fixed; inset: 0; pointer-events: none; z-index: 0; opacity: .06;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .5 0 0 0 0 .5 0 0 0 0 .5 0 0 0 1 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

button { font: inherit; color: inherit; cursor: pointer; }
svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Top bar ---------- */
.bar {
  position: relative; z-index: 2;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  height: 92px; padding: 0 28px;
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark {
  width: 6px; height: 34px; border-radius: 3px; background: var(--red);
  box-shadow: 0 0 18px var(--red-glow);
}
.brand-text {
  font-stretch: 62%; font-weight: 700; font-size: 26px; letter-spacing: .14em;
}
.brand-text em { font-style: normal; font-weight: 400; color: var(--ink-3); letter-spacing: .04em; margin-left: 4px; }
.fs-badge {
  font-stretch: 70%; font-size: 12px; font-weight: 700; letter-spacing: .2em;
  padding: 4px 9px; border-radius: 6px; color: var(--red); border: 1px solid var(--red);
}

.clock { display: flex; align-items: center; gap: 12px; }
.clock-time {
  font-stretch: 58%; font-weight: 300; font-size: 64px; line-height: 1;
  letter-spacing: .02em; font-variant-numeric: tabular-nums;
}
.clock-meta { display: flex; flex-direction: column; gap: 2px; }
#clockAmpm { font-stretch: 70%; font-weight: 700; font-size: 15px; letter-spacing: .16em; color: var(--red); }
#clockDate { font-stretch: 75%; font-size: 15px; letter-spacing: .08em; color: var(--ink-2); text-transform: uppercase; }

.actions { display: flex; justify-content: flex-end; align-items: center; gap: 12px; }
.icon-btn {
  width: 58px; height: 58px; border-radius: 16px;
  display: grid; place-items: center;
  background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow);
  transition: transform .15s var(--ease), background .2s;
}
.icon-btn svg { width: 26px; height: 26px; }
.icon-btn:active { transform: scale(.94); }
[data-theme="dark"] .i-sun, [data-theme="light"] .i-moon { display: none; }

.fs-btn {
  height: 58px; padding: 0 22px 0 18px; border-radius: 16px; border: 0;
  display: flex; align-items: center; gap: 10px;
  background: var(--red); color: #fff;
  font-stretch: 72%; font-weight: 700; font-size: 19px; letter-spacing: .12em; text-transform: uppercase;
  box-shadow: 0 10px 28px -10px var(--red-glow), 0 1px 0 rgba(255, 255, 255, .25) inset;
  transition: transform .15s var(--ease), filter .2s;
}
.fs-btn svg { width: 24px; height: 24px; stroke-width: 2.2; }
.fs-btn:active { transform: scale(.96); filter: brightness(.9); }

/* ---------- Layout ---------- */
.layout {
  position: relative; z-index: 1;
  display: grid; grid-template-columns: var(--rail-w) 1fr;
  height: calc(100% - 92px);
}

.rail {
  display: flex; flex-direction: column; gap: 6px;
  padding: 22px 14px 22px 20px;
  border-right: 1px solid var(--line);
  overflow-y: auto;
}
.rail-btn {
  position: relative;
  display: flex; align-items: center; justify-content: space-between;
  min-height: 62px; padding: 0 16px 0 22px; border-radius: 14px;
  background: transparent; border: 1px solid transparent; text-align: left;
  font-stretch: 78%; font-weight: 600; font-size: 20px; letter-spacing: .06em; text-transform: uppercase;
  color: var(--ink-2);
  transition: background .2s, color .2s, border-color .2s;
}
.rail-btn::before {
  content: ""; position: absolute; left: 8px; top: 50%; width: 4px; height: 0; border-radius: 2px;
  background: var(--red); transform: translateY(-50%); transition: height .25s var(--ease);
}
.rail-btn .n { font-stretch: 60%; font-weight: 400; font-size: 16px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.rail-btn[aria-current="true"] { color: var(--ink); background: var(--panel); border-color: var(--line); box-shadow: var(--shadow); }
.rail-btn[aria-current="true"]::before { height: 26px; box-shadow: 0 0 12px var(--red-glow); }
.rail-sep { height: 1px; margin: 10px 8px; background: var(--line); }

.stage { overflow-y: auto; padding: 26px 32px 48px; scroll-behavior: smooth; }
.stage-head { display: flex; align-items: baseline; gap: 16px; margin: 4px 4px 22px; }
.stage-head h1 {
  margin: 0; font-stretch: 55%; font-weight: 600; font-size: 46px; letter-spacing: .04em; text-transform: uppercase; line-height: 1;
}
.count { font-stretch: 60%; font-size: 18px; color: var(--ink-3); letter-spacing: .1em; }
.stage-head .ghost-btn:first-of-type { margin-left: auto; }

/* ---------- Tiles ---------- */
.grid {
  display: grid; gap: 18px;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
}
.tile {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  aspect-ratio: 1 / .92; padding: 16px 12px 14px; border-radius: var(--radius);
  background: linear-gradient(180deg, var(--panel-hi), var(--panel));
  border: 1px solid var(--line); box-shadow: var(--shadow);
  color: var(--ink); text-decoration: none;
  opacity: 0; transform: translateY(10px);
  animation: rise .5s var(--ease) forwards; animation-delay: calc(var(--i) * 28ms);
  transition: transform .16s var(--ease), border-color .2s;
}
.tile:active { transform: scale(.95); border-color: var(--line-hi); }
@keyframes rise { to { opacity: 1; transform: none; } }

.plate {
  width: 84px; height: 84px; border-radius: 22px; flex: none;
  display: grid; place-items: center; overflow: hidden;
  background: var(--plate);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .06) inset, 0 8px 18px -10px rgba(0, 0, 0, .55);
}
.plate img { width: 62px; height: 62px; object-fit: contain; border-radius: 12px; }
.plate.mono {
  background: linear-gradient(145deg, hsl(var(--h) 62% 46%), hsl(calc(var(--h) + 28) 70% 30%));
  color: #fff; font-stretch: 60%; font-weight: 700; font-size: 36px; letter-spacing: .02em;
  text-shadow: 0 2px 8px rgba(0, 0, 0, .25);
}
.label {
  max-width: 100%; text-align: center;
  font-stretch: 80%; font-weight: 600; font-size: 17px; letter-spacing: .03em; line-height: 1.15;
  overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}

.tile .del {
  position: absolute; top: -10px; right: -10px; width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center; background: var(--red); color: #fff; border: 3px solid var(--bg);
  font-size: 22px; line-height: 1;
}
.editing .tile { animation: rise .5s var(--ease) forwards, wiggle .32s ease-in-out infinite alternate; }
@keyframes wiggle { from { rotate: -.8deg; } to { rotate: .8deg; } }

.empty { margin: 40px 4px; font-size: 20px; color: var(--ink-2); }

/* ---------- Buttons ---------- */
.ghost-btn, .solid-btn {
  min-height: 52px; padding: 0 22px; border-radius: 14px;
  font-stretch: 75%; font-weight: 600; font-size: 18px; letter-spacing: .08em; text-transform: uppercase;
  transition: transform .15s var(--ease);
}
.ghost-btn { background: transparent; border: 1px solid var(--line-hi); }
.solid-btn { background: var(--ink); color: var(--bg); border: 0; }
.ghost-btn:active, .solid-btn:active { transform: scale(.96); }
.ghost-btn[aria-pressed="true"] { background: var(--red); border-color: var(--red); color: #fff; }

/* ---------- Overlays ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 10;
  display: grid; place-items: center;
  background: rgba(5, 6, 8, .62); backdrop-filter: blur(6px);
  animation: fade .2s ease;
}
@keyframes fade { from { opacity: 0; } }
.sheet {
  width: min(520px, calc(100% - 40px)); padding: 30px 32px 26px; border-radius: 24px;
  background: var(--panel); border: 1px solid var(--line-hi);
  box-shadow: 0 30px 80px -20px rgba(0, 0, 0, .7);
  animation: pop .28s var(--ease);
  user-select: text;
}
.sheet-wide { width: min(640px, calc(100% - 40px)); max-height: calc(100% - 40px); overflow-y: auto; }
@keyframes pop { from { transform: translateY(14px) scale(.98); opacity: 0; } }
.sheet h2 { margin: 0 0 20px; font-stretch: 62%; font-weight: 600; font-size: 34px; letter-spacing: .04em; text-transform: uppercase; }
.sheet label { display: block; margin-bottom: 16px; font-stretch: 80%; font-size: 15px; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-2); }
.sheet input {
  display: block; width: 100%; margin-top: 8px; height: 58px; padding: 0 16px; border-radius: 12px;
  background: var(--bg); border: 1px solid var(--line-hi); color: var(--ink);
  font: inherit; font-stretch: 100%; font-size: 21px; letter-spacing: 0; text-transform: none;
}
.sheet input:focus { outline: 2px solid var(--red); outline-offset: 1px; }
.form-err { margin: -4px 0 12px; color: var(--red); font-size: 17px; }
.sheet-actions { display: flex; justify-content: flex-end; gap: 12px; margin-top: 22px; }

.sheet-fs { text-align: center; }
.sheet-fs .sheet-actions { justify-content: center; }
.ring { position: relative; width: 120px; height: 120px; margin: 0 auto 18px; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { stroke-width: 6; fill: none; }
.ring-bg { stroke: var(--line-hi); }
.ring-fg { stroke: var(--red); stroke-dasharray: 327; stroke-dashoffset: 0; transition: stroke-dashoffset 1s linear; }
.ring span { position: absolute; inset: 0; display: grid; place-items: center; font-stretch: 55%; font-weight: 300; font-size: 56px; }
.steps { margin: 0 auto; padding: 0; max-width: 380px; list-style: none; counter-reset: s; text-align: left; }
.steps li { counter-increment: s; position: relative; padding: 8px 0 8px 44px; font-size: 18px; color: var(--ink-2); }
.steps li::before {
  content: counter(s); position: absolute; left: 0; top: 6px; width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center; border: 1px solid var(--line-hi); color: var(--ink);
  font-stretch: 60%; font-weight: 700; font-size: 16px;
}
.steps b, .faq b { color: var(--ink); }

.opt { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 0; border-top: 1px solid var(--line); }
.opt > span { font-stretch: 80%; font-size: 18px; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-2); }
.seg { display: flex; padding: 4px; gap: 4px; border-radius: 14px; background: var(--bg); border: 1px solid var(--line); }
.seg button {
  min-height: 48px; padding: 0 18px; border-radius: 10px; border: 0; background: transparent; color: var(--ink-2);
  font-stretch: 78%; font-weight: 600; font-size: 17px; letter-spacing: .04em;
}
.seg button[aria-pressed="true"] { background: var(--panel-hi); color: var(--ink); box-shadow: var(--shadow); }

.custom-links { padding: 14px 0 8px; border-top: 1px solid var(--line); }
.custom-links h3 { margin: 0 0 12px; font-stretch: 80%; font-size: 18px; font-weight: 400; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-2); }
.inline-add { display: grid; grid-template-columns: 1fr 1.6fr auto; gap: 10px; }
.inline-add input {
  height: 54px; padding: 0 14px; border-radius: 12px; min-width: 0;
  background: var(--bg); border: 1px solid var(--line-hi); color: var(--ink);
  font: inherit; font-size: 19px;
}
.inline-add input:focus { outline: 2px solid var(--red); outline-offset: 1px; }
.inline-add .solid-btn { min-height: 54px; }
.custom-links .form-err { margin: 10px 0 0; }
.link-list { list-style: none; margin: 12px 0 0; padding: 0; }
.link-list li { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.link-list li > span { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.link-list b { font-size: 19px; font-weight: 600; }
.link-list small { font-size: 15px; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-list .ghost-btn { min-height: 46px; font-size: 15px; padding: 0 16px; }

.faq { margin-top: 10px; padding: 14px 0 0; border-top: 1px solid var(--line); }
.faq summary { font-stretch: 80%; font-size: 18px; font-weight: 600; letter-spacing: .04em; cursor: pointer; padding: 6px 0; }
.faq p { font-size: 17px; line-height: 1.5; color: var(--ink-2); }
.fine { margin: 16px 0 0; font-size: 15px; color: var(--ink-3); }

/* Narrower browser window (e.g. split screen) */
@media (max-width: 900px) {
  :root { --rail-w: 176px; }
  .clock-time { font-size: 48px; }
  .brand-text em, .fs-btn span { display: none; }
  .fs-btn { padding: 0 17px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before { animation: none !important; transition: none !important; }
  .tile { opacity: 1; transform: none; }
}
