:root {
    --ag-ink: #131611;
    --ag-paper: #e8eadf;
    --ag-paper-bright: #f5f6ed;
    --ag-muted: #62685d;
    --ag-line: rgba(21, 28, 18, 0.42);
    --ag-green: #8dff32;
    --ag-green-dark: #163817;
    --ag-red: #a31e24;
    --ag-shadow: 0 28px 80px rgba(0, 12, 0, 0.5);
    --ag-mono: "IBM Plex Mono", "Courier New", monospace;
    --ag-serif: Georgia, "Times New Roman", serif;
}

* { box-sizing: border-box; }

html,
body { min-height: 100%; }

body.auth-gateway-page {
    margin: 0;
    overflow-x: hidden;
    color: var(--ag-ink);
    background: #071006;
    font-family: var(--ag-mono);
}

.auth-gateway {
    position: relative;
    min-height: 100dvh;
    display: grid;
    place-items: center;
    padding: 36px 18px;
    isolation: isolate;
}

.auth-gateway-bg,
.auth-gateway-tint,
.auth-gateway-noise,
.auth-gateway-vignette {
    position: fixed;
    inset: 0;
    pointer-events: none;
}

.auth-gateway-bg {
    z-index: -5;
    background-image: var(--auth-gateway-bg);
    background-position: center;
    background-size: cover;
    background-repeat: no-repeat;
    image-rendering: auto;
}

.auth-gateway-tint {
    z-index: -4;
    background:
        linear-gradient(90deg, rgba(0, 19, 2, 0.48), rgba(216, 255, 199, 0.08) 48%, rgba(0, 18, 2, 0.4)),
        linear-gradient(180deg, rgba(1, 16, 4, 0.16), rgba(0, 12, 2, 0.52));
}

.auth-gateway-noise {
    z-index: -3;
    opacity: 0.22;
    background-image: repeating-linear-gradient(
        0deg,
        rgba(255,255,255,0.13) 0,
        rgba(255,255,255,0.13) 1px,
        transparent 1px,
        transparent 3px
    );
    mix-blend-mode: overlay;
}

.auth-gateway-vignette {
    z-index: -2;
    box-shadow: inset 0 0 180px 52px rgba(0, 13, 2, 0.62);
}

.auth-gateway-corner {
    position: fixed;
    z-index: 4;
    color: rgba(232, 255, 222, 0.72);
    font: 500 8px/1.5 var(--ag-mono);
    letter-spacing: 0.14em;
    text-transform: uppercase;
    text-shadow: 0 1px 2px #001500;
}

.auth-gateway-corner--top { top: 14px; left: 16px; }
.auth-gateway-corner--bottom { right: 16px; bottom: 12px; text-align: right; }

.auth-terminal {
    position: relative;
    width: min(360px, calc(100vw - 30px));
    background: rgba(235, 238, 224, 0.9);
    border: 1px solid rgba(238, 255, 227, 0.74);
    outline: 1px solid rgba(10, 24, 9, 0.52);
    box-shadow: var(--ag-shadow);
    backdrop-filter: blur(7px) saturate(0.74);
    -webkit-backdrop-filter: blur(7px) saturate(0.74);
}

.auth-terminal::before,
.auth-terminal::after {
    content: "";
    position: absolute;
    pointer-events: none;
}

.auth-terminal::before {
    inset: 3px;
    border: 1px solid rgba(17, 28, 15, 0.12);
}

.auth-terminal::after {
    top: -4px;
    left: 20px;
    width: 48px;
    height: 3px;
    background: var(--ag-green);
    box-shadow: 0 0 14px rgba(141, 255, 50, 0.65);
}

.auth-terminal--register { width: min(760px, calc(100vw - 30px)); }
.auth-terminal--verify { width: min(520px, calc(100vw - 30px)); }

.auth-terminal-bar {
    position: relative;
    z-index: 1;
    min-height: 28px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 5px 9px;
    color: #3d4939;
    background: linear-gradient(#f4f5ef, #c7cbbf);
    border-bottom: 1px solid var(--ag-line);
    font: 500 8px/1 var(--ag-mono);
    letter-spacing: 0.09em;
}

.auth-terminal-bar strong { color: #14220f; font-weight: 600; }
.auth-terminal-led { display: inline-flex; align-items: center; gap: 6px; text-transform: uppercase; }
.auth-terminal-led::before {
    content: "";
    width: 5px;
    height: 5px;
    background: #3a8f31;
    box-shadow: 0 0 6px rgba(56, 190, 47, 0.8);
}

.auth-terminal-body {
    position: relative;
    z-index: 1;
    padding: 25px 22px 22px;
}

.auth-brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.auth-brand-kicker {
    margin-bottom: 5px;
    color: #33412f;
    font: 500 8px/1.4 var(--ag-mono);
    letter-spacing: 0.18em;
    text-transform: uppercase;
}

.auth-brand-title {
    margin: 0;
    color: #10200f;
    font: 400 28px/0.95 var(--ag-serif);
    letter-spacing: -0.045em;
    text-transform: uppercase;
}

.auth-brand-subtitle {
    margin: 7px 0 0;
    color: #455240;
    font: 500 8px/1.45 var(--ag-mono);
    letter-spacing: 0.13em;
    text-transform: uppercase;
}

.auth-sigil {
    position: relative;
    width: 118px;
    height: 118px;
    margin: 18px auto 16px;
    filter: drop-shadow(0 9px 15px rgba(14, 46, 8, 0.3));
    animation: ag-float 5s ease-in-out infinite, ag-signal 9s steps(1, end) infinite;
}

.auth-sigil svg { display: block; width: 100%; height: 100%; overflow: visible; }
.auth-sigil-petals { transform-origin: 50% 50%; animation: ag-spin 22s linear infinite; }
.auth-sigil-core { transform-origin: 50% 50%; animation: ag-spin-reverse 31s linear infinite; }

.auth-gateway-copy {
    max-width: 54ch;
    margin: 0 auto 18px;
    color: #4e584a;
    font: 400 10px/1.6 var(--ag-mono);
    text-align: center;
}

.auth-action-menu {
    display: grid;
    gap: 5px;
}

.auth-command,
.auth-submit,
.auth-back,
.auth-inline-button {
    min-height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #687263;
    border-radius: 0;
    color: #172113;
    background: linear-gradient(#f6f7f1, #c9cec2);
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.8);
    font: 500 11px/1 var(--ag-mono);
    letter-spacing: 0.13em;
    text-transform: uppercase;
    cursor: pointer;
}

.auth-command--primary,
.auth-submit {
    color: #f2ffe9;
    background: #142f18;
    border-color: #82a178;
    box-shadow: inset 0 0 0 1px rgba(0,0,0,0.45), 0 0 0 1px rgba(255,255,255,0.55);
}

.auth-command:hover,
.auth-submit:hover,
.auth-back:hover,
.auth-inline-button:hover {
    color: #0e220d;
    background: var(--ag-green);
    border-color: #163817;
}

.auth-panel[hidden] { display: none !important; }

.auth-panel-title-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 16px;
    margin: 2px 0 16px;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(25, 35, 22, 0.28);
}

.auth-panel-title-row h2 {
    margin: 0;
    color: #142211;
    font: 400 20px/1 var(--ag-serif);
    text-transform: uppercase;
}

.auth-panel-title-row span {
    color: var(--ag-muted);
    font: 500 7px/1.4 var(--ag-mono);
    letter-spacing: 0.11em;
    text-transform: uppercase;
}

.auth-form { display: grid; gap: 11px; }
.auth-form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.auth-field { display: grid; gap: 5px; }
.auth-field--wide { grid-column: 1 / -1; }

.auth-field > span,
.auth-fieldset legend {
    color: #4c5747;
    font: 500 8px/1.4 var(--ag-mono);
    letter-spacing: 0.09em;
    text-transform: uppercase;
}

.auth-field input,
.auth-field select {
    width: 100%;
    min-height: 36px;
    padding: 8px 9px;
    color: #10200f;
    background: rgba(250, 251, 245, 0.86);
    border: 1px solid rgba(45, 56, 40, 0.48);
    border-radius: 0;
    box-shadow: inset 1px 1px 0 rgba(0,0,0,0.08);
    font: 500 11px/1.3 var(--ag-mono);
}

.auth-field input:focus,
.auth-field select:focus {
    outline: 1px solid #2b6d24;
    outline-offset: 2px;
    border-color: #2b6d24;
}

.auth-field input::placeholder { color: #8a9184; }

.auth-fieldset { margin: 0; padding: 0; border: 0; }
.auth-radio-row { display: flex; gap: 16px; min-height: 36px; align-items: center; }
.auth-radio-row label { display: inline-flex; align-items: center; gap: 6px; color: #384333; font-size: 9px; text-transform: uppercase; }

.auth-captcha {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 6px;
}

.auth-captcha-code {
    min-height: 36px;
    display: grid;
    place-items: center;
    color: #172712;
    background: repeating-linear-gradient(-45deg, #eef0e7 0, #eef0e7 4px, #d9ddcf 4px, #d9ddcf 5px);
    border: 1px solid rgba(45, 56, 40, 0.48);
    font: 600 14px/1 var(--ag-mono);
    letter-spacing: 0.22em;
}

.auth-inline-button { min-height: 36px; padding: 0 10px; font-size: 8px; }

.auth-form-actions {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 6px;
    margin-top: 4px;
}

.auth-back { min-width: 92px; font-size: 8px; }

.auth-status {
    min-height: 18px;
    margin-top: 10px;
    color: #33452d;
    font: 500 9px/1.45 var(--ag-mono);
    text-align: center;
}

.auth-status.is-error { color: var(--ag-red); }
.auth-status.is-success { color: #21611d; }

.auth-password-note,
.auth-notice {
    color: #5e6758;
    font: 400 8px/1.55 var(--ag-mono);
}

.auth-notice {
    margin: 0 0 14px;
    padding: 9px 10px;
    background: rgba(245, 247, 237, 0.55);
    border: 1px solid rgba(45, 56, 40, 0.28);
    border-left: 3px solid #4b7541;
}

.auth-notice.is-error { border-left-color: var(--ag-red); color: #76151a; }
.auth-notice.is-success { border-left-color: #34732d; color: #24551f; }
.auth-secondary-form { margin-top: 10px; }
.auth-secondary-form .auth-back { width: 100%; }
.auth-return-link { margin: 16px 0 0; text-align: center; font-size: 8px; text-transform: uppercase; }
.auth-return-link a { color: #294f25; text-underline-offset: 3px; }

.auth-terminal-footer {
    position: relative;
    z-index: 1;
    display: flex;
    justify-content: space-between;
    gap: 10px;
    padding: 5px 8px;
    color: #576151;
    background: linear-gradient(#d2d6ca, #bfc4b7);
    border-top: 1px solid var(--ag-line);
    font: 500 7px/1.2 var(--ag-mono);
    letter-spacing: 0.07em;
    text-transform: uppercase;
}

@keyframes ag-float {
    0%, 100% { transform: translateY(0) rotate(-1deg); }
    50% { transform: translateY(-7px) rotate(1deg); }
}

@keyframes ag-spin { to { transform: rotate(360deg); } }
@keyframes ag-spin-reverse { to { transform: rotate(-360deg); } }

@keyframes ag-signal {
    0%, 91%, 94%, 100% { opacity: 1; filter: drop-shadow(0 9px 15px rgba(14, 46, 8, 0.3)); }
    92% { opacity: 0.72; transform: translate(2px, -4px); filter: hue-rotate(30deg) contrast(1.5); }
    93% { opacity: 0.9; transform: translate(-2px, -5px); }
}

@media (max-width: 620px) {
    .auth-gateway { padding: 20px 10px; align-items: start; }
    .auth-terminal { margin-top: 28px; }
    .auth-terminal-body { padding: 21px 15px 17px; }
    .auth-form-grid { grid-template-columns: 1fr; }
    .auth-field--wide { grid-column: auto; }
    .auth-terminal--register .auth-sigil { width: 84px; height: 84px; margin: 12px auto; }
    .auth-gateway-corner--bottom { display: none; }
}

@media (prefers-reduced-motion: reduce) {
    .auth-sigil,
    .auth-sigil-petals,
    .auth-sigil-core { animation: none !important; }
}
