/* ───────────────────────────────────────────────────────────────────────────
   SmartSuli — login stage
   The shared sign-in surface for BOTH doors: the teacher door (/Login, on
   _Layout + site.css) and the family door (/Portal/Login, on _PortalLayout +
   family.css). One look, two token sets.

   The two stylesheets name the same Indigo Pulse palette differently, so every
   colour here is read through a fallback chain: --ss-* first (admin), then the
   family.css name, then a literal. Both source sheets are already dark-aware,
   so this file needs no dark block of its own.

   The backdrop is a squared exercise-book page that writes itself: objects are
   drawn stroke by stroke, formulas and margin notes are written character by
   character, both fade, both start again. Coral is the teacher's ink, blue is
   the student's — the same two hands as on a marked exam paper.
   Chosen from dev-planning/assets/designs/login-stage-prototype.html (variant B).
   prefers-reduced-motion freezes the page into a finished, static sheet.
   ─────────────────────────────────────────────────────────────────────────── */

/* family.css has no global border-box reset (site.css gets one from Bootstrap),
   so the card's own padding was pushing it past the viewport on the portal. */
.ss-login-page,
.ss-login-page *,
.ss-login-page *::before,
.ss-login-page *::after { box-sizing: border-box; }

.ss-login-page {
    --ls-ink:      var(--ss-ink,          var(--ink,       #191b2e));
    --ls-soft:     var(--ss-muted,        var(--ink-soft,  #4e5170));
    --ls-surface:  var(--ss-surface,      var(--card,      #ffffff));
    --ls-line:     var(--ss-border,       var(--line,      rgba(25, 27, 46, .12)));
    --ls-primary:  var(--ss-primary,      var(--pine,      #4038a8));
    --ls-primary-2:var(--ss-accent-lavender, var(--pine-soft, #5a51c8));
    --ls-accent:   var(--ss-accent-cyan,  var(--gold,      #14b8a6));
    --ls-danger:   var(--ss-danger,       var(--danger,    #e5484d));
    /* Flips to near-black in dark, where the primary itself is a light lavender —
       white on that sits near 2.3:1. */
    --ls-on-primary: var(--ss-on-primary, var(--on-pine,   #ffffff));
    --ls-serif:    var(--ss-serif,        var(--serif,     Georgia, "Times New Roman", serif));
    --ls-bg:       var(--ss-bg,           var(--paper,     #f7f8fc));
    /* The two hands. family.css already flips --coral/--sky with the theme;
       site.css has neither, so the literals carry the light values here and the
       dark ones in the data-bs-theme block below. */
    --ls-ink-teacher: var(--coral, #e5604f);
    --ls-ink-student: var(--sky,   #3d87d8);

    position: relative;
    z-index: 1;
    /* Flex, not grid: with `place-items: center` the card's percentage width
       resolves against a max-content column, so long copy pushed it wider than
       the viewport on phones. */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: calc(100dvh - 5rem);
    padding: 1.5rem 1rem 3rem;
}

html[data-bs-theme="dark"] .ss-login-page {
    --ls-ink-teacher: var(--coral, #f08a7a);
    --ls-ink-student: var(--sky,   #6faee8);
}

/* Both shells put a wordmark above the page — the admin's plain header and the
   portal's topbar — and the card already carries the mark. The portal also paints
   its own grid-and-aurora background (.ss-bg) and lifts each child of .ss-main on
   entry; on the sign-in surface the stage replaces the first and the card does the
   second, so all of it stands down here. */
body:has(.ss-login-page) .ss-plain-top,
body:has(.ss-login-page) .ss-topbar,
body:has(.ss-login-page) .ss-bg { display: none; }
body:has(.ss-login-page) { margin-bottom: 0; }
body:has(.ss-login-page) .ss-main > * { animation: none; }

/* ── Backdrop ───────────────────────────────────────────────────────────────
   z-index -1 keeps it above the canvas background but below every in-flow
   element, so it never needs the page chrome to opt out of its stacking. */
.ss-login-stage {
    position: fixed;
    inset: 0;
    z-index: -1;
    overflow: hidden;
    pointer-events: none;
}

/* ── The paper ──────────────────────────────────────────────────────────────
   Squared exercise-book ruling, edge to edge, in student-ink blue. This is the
   surface the whole product already lives on: the exam paper, the whiteboard,
   the teacher's margin notes. */
.ss-login-paper {
    position: absolute;
    inset: -2px;
    background-image:
        linear-gradient(to right, currentColor 1px, transparent 1px),
        linear-gradient(to bottom, currentColor 1px, transparent 1px);
    background-size: 30px 30px;
    color: var(--ls-ink-student);
    opacity: .16;
}

/* A breath of paper colour under the card so the card edge never fights the
   ruling for attention. */
.ss-login-stage::after {
    content: "";
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse 34% 40% at 50% 50%,
        color-mix(in srgb, var(--ls-bg) 85%, transparent), transparent 70%);
}

/* ── Hand ───────────────────────────────────────────────────────────────────
   Objects are not faded in — they are DRAWN, stroke by stroke, then held, then
   let go. Two inks, exactly as on a marked-up exam paper: coral is the teacher,
   blue is the student.

   Per-item custom properties, set inline in _LoginStage.cshtml:
   --x/--y position, --sz size, --t cycle length, --d delay (negative so the
   page opens mid-cycle), --rot tilt, --n character count for written text. */
.ss-login-ink {
    position: absolute;
    left: var(--x);
    top: var(--y);
    color: var(--ls-ink-teacher);
    transform: rotate(var(--rot, 0deg));
}
.ss-login-ink--student { color: var(--ls-ink-student); }

.ss-login-ink svg {
    display: block;
    width: var(--sz, 54px);
    height: var(--sz, 54px);
    fill: none;
    stroke: currentColor;
    stroke-width: 1.5;
    stroke-linecap: round;
    stroke-linejoin: round;
    overflow: visible;
}

/* Every drawable carries pathLength="1", so one keyframe set draws any shape
   regardless of its real length. */
.ss-login-ink svg [pathLength] {
    stroke-dasharray: 1;
    stroke-dashoffset: 1;
    animation: ssLoginDraw var(--t, 34s) linear var(--d, 0s) infinite;
}

@keyframes ssLoginDraw {
    0%, 2%    { stroke-dashoffset: 1; opacity: .9; }
    16%       { stroke-dashoffset: 0; opacity: .9; }
    54%       { stroke-dashoffset: 0; opacity: .9; }
    66%, 100% { stroke-dashoffset: 0; opacity: 0; }
}

/* ── Written text ───────────────────────────────────────────────────────────
   The line is written, not switched on: a soft-edged mask travels left to right
   across it, so the ink appears continuously under a moving nib. This started
   as a per-character steps() reveal and that was wrong — stepping makes the
   words flash into place in chunks instead of flowing.

   The mask is twice the line's width, black for its first half and fading out
   over the next 7%; sliding it from right to left uncovers the line with a
   ~15%-wide soft edge. mask-position animates on the compositor, so this is
   cheap however many lines are on the sheet.

   A line takes five seconds to write. That is slower than a hand really moves,
   deliberately: at writing speed the eye is pulled to it, and this sits behind a
   sign-in form that people came here to use. */
.ss-login-write {
    position: absolute;
    left: var(--x);
    top: var(--y);
    color: var(--ls-ink-teacher);
    font-family: var(--ls-serif);
    font-style: italic;
    font-size: var(--sz, 1.2rem);
    white-space: nowrap;
    transform: rotate(var(--rot, 0deg));

    -webkit-mask-image: linear-gradient(90deg, #000 0 55%, transparent 62%);
            mask-image: linear-gradient(90deg, #000 0 55%, transparent 62%);
    -webkit-mask-size: 220% 100%;
            mask-size: 220% 100%;
    -webkit-mask-repeat: no-repeat;
            mask-repeat: no-repeat;
    -webkit-mask-position: 100% 0;
            mask-position: 100% 0;

    /* Reveal and fade run on separate clocks: the reveal eases the way a hand
       does, the fade stays linear. */
    animation:
        ssLoginWrite   var(--t, 34s) cubic-bezier(.5, 0, .5, 1) var(--d, 0s) infinite,
        ssLoginInkFade var(--t, 34s) linear                     var(--d, 0s) infinite;
}
.ss-login-write--student { color: var(--ls-ink-student); }

/* The teacher's own margin notes are in a hand, not in the textbook serif. */
.ss-login-write--hand {
    font-family: "Bradley Hand", "Noteworthy", "Segoe Script", "Comic Sans MS", cursive;
    font-style: normal;
    font-weight: 600;
}

@keyframes ssLoginWrite {
    0%        { -webkit-mask-position: 100% 0; mask-position: 100% 0; }
    15%, 100% { -webkit-mask-position: 0 0;    mask-position: 0 0; }
}

/* Written, held, then let go — and a long blank tail, so at any moment only
   about half the sheet is inked and the page never feels crowded. */
@keyframes ssLoginInkFade {
    0%, 54%   { opacity: .88; }
    66%, 100% { opacity: 0; }
}

/* The nib: a short ink stroke that rides the writing edge and lifts the moment
   the line is finished. */
.ss-login-write::after {
    content: "";
    position: absolute;
    top: 8%;
    left: 0;
    width: 1.5px;
    height: 84%;
    background: currentColor;
    opacity: 0;
    animation: ssLoginNib var(--t, 34s) cubic-bezier(.5, 0, .5, 1) var(--d, 0s) infinite;
}

@keyframes ssLoginNib {
    0%          { left: 0;    opacity: .45; }
    12.9%       { left: 100%; opacity: .45; }
    13.5%, 100% { left: 100%; opacity: 0; }
}

/* The only printed thing on the sheet: the mark, watermarked under the hand-work.
   Masked PNG, so the bare shape carries the brand gradient with no icon tile. */
.ss-login-mote {
    position: absolute;
    left: var(--x);
    top: var(--y);
    transform: rotate(var(--rot, 0deg));
    opacity: 0;
    animation: ssLoginMote var(--t, 44s) ease-in-out var(--d, 0s) infinite;
}
.ss-login-mote i {
    display: block;
    width: var(--sz, 120px);
    height: var(--sz, 120px);
    background: linear-gradient(140deg, var(--ls-primary), var(--ls-accent));
    -webkit-mask: url("../img/brand/smartsuli-mark.png") center / contain no-repeat;
            mask: url("../img/brand/smartsuli-mark.png") center / contain no-repeat;
}
@keyframes ssLoginMote {
    0%, 100% { opacity: 0; }
    22%, 72% { opacity: .11; }
}

/* Narrow windows: the card is a fixed 408px, so the clear corridor around it
   widens as the viewport shrinks. The items nearest the card's flanks step off
   the sheet first. */
@media (max-width: 1100px) {
    .ss-login-ink--md-hide,
    .ss-login-write--md-hide { display: none; }
}

/* Phones: the card takes the middle, so the inner half of the sheet is dropped
   and the ruling tightens to phone density. */
@media (max-width: 640px) {
    .ss-login-ink--sm-hide,
    .ss-login-write--sm-hide,
    .ss-login-mote--sm-hide { display: none; }
    .ss-login-paper { background-size: 22px 22px; }
}

@media (prefers-reduced-motion: reduce) {
    .ss-login-ink svg [pathLength] { animation: none; stroke-dashoffset: 0; opacity: .8; }
    .ss-login-write { animation: none; opacity: .8;
        -webkit-mask-image: none; mask-image: none; }
    .ss-login-write::after { animation: none; opacity: 0; }
    .ss-login-mote { animation: none; opacity: .09; }
}

/* ── Card ───────────────────────────────────────────────────────────────── */
.ss-login-card {
    position: relative;
    width: 100%;
    max-width: 25.5rem;
    padding: 2.25rem 1.9rem 1.9rem;
    border: 1px solid var(--ls-line);
    border-radius: 1.35rem;
    background: color-mix(in srgb, var(--ls-surface) 82%, transparent);
    -webkit-backdrop-filter: blur(20px) saturate(1.3);
    backdrop-filter: blur(20px) saturate(1.3);
    box-shadow:
        0 1px 0 color-mix(in srgb, var(--ls-surface) 70%, transparent) inset,
        0 30px 70px -32px color-mix(in srgb, var(--ls-primary) 55%, transparent);
    text-align: center;
    animation: ssLoginCardIn .65s cubic-bezier(.2, .8, .2, 1) both;
}

@keyframes ssLoginCardIn {
    from { opacity: 0; transform: translateY(12px) scale(.98); }
    to   { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
    .ss-login-card { animation: none; }
}

/* Brand mark with a breathing halo — the one deliberate motion inside the card.
   The mark is the transparent brand PNG used as a mask, so it carries the brand
   gradient on the bare shape: no rounded-square app-icon tile behind it. The
   wordmark right below carries the name, so the shape itself is decorative. */
.ss-login-mark {
    position: relative;
    display: grid;
    place-items: center;
    width: 62px;
    height: 62px;
    margin: 0 auto .9rem;
}
.ss-login-mark i {
    position: relative;
    display: block;
    width: 62px;
    height: 62px;
    background: linear-gradient(140deg, var(--ls-primary), var(--ls-accent));
    -webkit-mask: url("../img/brand/smartsuli-mark.png") center / contain no-repeat;
            mask: url("../img/brand/smartsuli-mark.png") center / contain no-repeat;
}
.ss-login-mark::after {
    content: "";
    position: absolute;
    width: 62px;
    height: 62px;
    border-radius: 50%;
    box-shadow: 0 0 0 0 color-mix(in srgb, var(--ls-accent) 45%, transparent);
    animation: ssLoginHalo 7s ease-out infinite;
}
@keyframes ssLoginHalo {
    0%       { box-shadow: 0 0 0 0 color-mix(in srgb, var(--ls-accent) 45%, transparent); }
    70%,100% { box-shadow: 0 0 0 22px color-mix(in srgb, var(--ls-accent) 0%, transparent); }
}
@media (prefers-reduced-motion: reduce) {
    .ss-login-mark::after { animation: none; }
}

.ss-login-brand {
    font-family: var(--ls-serif);
    font-size: 1.7rem;
    font-weight: 700;
    letter-spacing: -.02em;
    line-height: 1.1;
    color: var(--ls-ink);
    margin: 0;
}
.ss-login-brand em { font-style: normal; color: var(--ls-primary); }

.ss-login-chip {
    display: inline-block;
    margin-top: .55rem;
    padding: .2rem .65rem;
    border-radius: 999px;
    background: color-mix(in srgb, var(--ls-primary) 12%, transparent);
    color: var(--ls-primary);
    font-size: .7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .09em;
}

/* Headline for the follow-up screens of the same flow (link sent, link expired),
   which carry a sentence instead of the wordmark's brand moment. */
.ss-login-title {
    font-family: var(--ls-serif);
    font-size: 1.3rem;
    font-weight: 600;
    letter-spacing: -.01em;
    color: var(--ls-ink);
    margin: .2rem 0 .7rem;
}
.ss-login-body {
    margin: 0 0 .7rem;
    color: var(--ls-soft);
    font-size: .9rem;
    line-height: 1.55;
}

.ss-login-lede {
    margin: .9rem 0 1.4rem;
    color: var(--ls-soft);
    font-size: .9rem;
    line-height: 1.5;
}

/* ── Controls ───────────────────────────────────────────────────────────── */
.ss-login-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .6rem;
    width: 100%;
    padding: .8rem 1rem;
    border: 1px solid var(--ls-line);
    border-radius: .8rem;
    background: var(--ls-surface);
    color: var(--ls-ink);
    font: inherit;
    font-size: .95rem;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    box-sizing: border-box;
    transition: transform .15s ease, box-shadow .15s ease, background-color .15s ease;
}
/* The lift is a primary-tinted glow, never an --ls-ink one: in dark mode ink is
   near-white, which halos the button instead of seating it. */
.ss-login-btn:hover {
    color: var(--ls-ink);
    background: color-mix(in srgb, var(--ls-primary) 9%, var(--ls-surface));
    transform: translateY(-1px);
    box-shadow: 0 12px 24px -16px color-mix(in srgb, var(--ls-primary) 75%, transparent);
}
.ss-login-btn:active { transform: none; }
.ss-login-btn svg { width: 18px; height: 18px; flex: none; }

.ss-login-btn--primary {
    border-color: transparent;
    background: linear-gradient(135deg, var(--ls-primary), var(--ls-primary-2));
    color: var(--ls-on-primary);
}
.ss-login-btn--primary:hover {
    background: linear-gradient(135deg, var(--ls-primary-2), var(--ls-primary));
    color: var(--ls-on-primary);
}

.ss-login-btn--ghost {
    background: transparent;
    color: var(--ls-soft);
    font-size: .85rem;
    font-weight: 500;
    padding: .55rem .8rem;
}
.ss-login-btn--ghost:hover { color: var(--ls-ink); }

.ss-login-btn:focus-visible,
.ss-login-field input:focus-visible {
    outline: 2px solid var(--ls-primary);
    outline-offset: 2px;
}

.ss-login-field { text-align: left; margin-bottom: .7rem; }
.ss-login-field label {
    display: block;
    margin-bottom: .3rem;
    font-size: .8rem;
    font-weight: 600;
    color: var(--ls-soft);
}
.ss-login-field input {
    display: block;
    width: 100%;
    padding: .75rem .85rem;
    border: 1px solid var(--ls-line);
    border-radius: .8rem;
    background: color-mix(in srgb, var(--ls-surface) 70%, transparent);
    color: var(--ls-ink);
    font: inherit;
    font-size: 1rem;
    box-sizing: border-box;
}
.ss-login-field input::placeholder { color: color-mix(in srgb, var(--ls-soft) 70%, transparent); }
.ss-login-error { display: block; margin-top: .25rem; font-size: .8rem; color: var(--ls-danger); }

.ss-login-or {
    display: flex;
    align-items: center;
    gap: .8rem;
    margin: 1.1rem 0;
    color: var(--ls-soft);
    font-size: .78rem;
}
.ss-login-or::before,
.ss-login-or::after { content: ""; flex: 1; height: 1px; background: var(--ls-line); }

.ss-login-hint {
    margin: .8rem 0 0;
    color: var(--ls-soft);
    font-size: .78rem;
    line-height: 1.45;
}

.ss-login-foot {
    margin-top: 1.2rem;
    padding-top: 1rem;
    border-top: 1px dashed var(--ls-line);
}
