:root {
    --ink: #17201f;
    --ink-soft: #42504d;
    --paper: #e8e3d8;
    --paper-light: #f6f3ea;
    --signal: #e6a11a;
    --signal-dark: #a96100;
    --ready: #1f7a55;
    --danger: #b8412f;
    --line: rgba(23, 32, 31, 0.16);
    --shadow: 0 28px 80px rgba(23, 32, 31, 0.18);
    --paper-bright: var(--paper-light);
    --safety: var(--signal);
    --success: var(--ready);
    --display: Rockwell, Georgia, serif;
    --body: "Bahnschrift", "DIN Alternate", "Aptos", sans-serif;
}

* {
    box-sizing: border-box;
}

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

body {
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
    color: var(--ink);
    background: var(--paper);
    font-family: "Bahnschrift", "DIN Alternate", "Aptos", sans-serif;
}

button,
input {
    font: inherit;
}

.factory-grid {
    position: fixed;
    inset: 0;
    pointer-events: none;
    background-image:
        linear-gradient(var(--line) 1px, transparent 1px),
        linear-gradient(90deg, var(--line) 1px, transparent 1px);
    background-size: 64px 64px;
    mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.45), transparent 78%);
}

.topbar,
.terminal-footer {
    position: relative;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: max(20px, env(safe-area-inset-top)) clamp(24px, 5vw, 72px) 18px;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    color: inherit;
    text-decoration: none;
    text-transform: uppercase;
    letter-spacing: 0.09em;
}

.brand-mark {
    display: grid;
    width: 46px;
    height: 46px;
    place-items: center;
    color: var(--paper-light);
    background: var(--ink);
    font-size: 0.82rem;
    font-weight: 800;
    letter-spacing: -0.04em;
}

.brand strong,
.brand small {
    display: block;
}

.brand strong {
    font-size: 0.92rem;
}

.brand small {
    margin-top: 2px;
    color: var(--ink-soft);
    font-size: 0.67rem;
}

.network-state {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    font-size: 0.76rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.network-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--ready);
    box-shadow: 0 0 0 5px rgba(31, 122, 85, 0.13);
}

.network-state.offline .network-dot {
    background: var(--danger);
    box-shadow: 0 0 0 5px rgba(184, 65, 47, 0.13);
}

.terminal-shell {
    position: relative;
    z-index: 1;
    display: grid;
    grid-template-columns: 54px minmax(0, 900px);
    justify-content: center;
    min-height: calc(100dvh - 158px);
    padding: clamp(20px, 3vw, 44px) clamp(18px, 5vw, 72px);
}

.context-rail {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 22px 0;
    writing-mode: vertical-rl;
    transform: rotate(180deg);
    font-family: ui-monospace, "Cascadia Code", monospace;
    font-size: 0.63rem;
    letter-spacing: 0.16em;
}

.rail-line {
    width: 1px;
    flex: 1;
    background: var(--ink);
    opacity: 0.45;
}

.rail-caption {
    color: var(--ink-soft);
}

.terminal-panel {
    position: relative;
    min-height: 560px;
    border: 1px solid var(--ink);
    background: rgba(246, 243, 234, 0.94);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.terminal-panel::before {
    position: absolute;
    top: 0;
    right: 0;
    width: 34%;
    height: 11px;
    content: "";
    background: var(--signal);
}

.loading-view,
.activation-view,
.linked-view,
.blocked-view {
    min-height: 560px;
}

.loading-view {
    display: grid;
    place-content: center;
    justify-items: center;
    color: var(--ink-soft);
}

.spinner {
    width: 42px;
    height: 42px;
    border: 2px solid var(--line);
    border-top-color: var(--ink);
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
}

.loading-view p {
    margin-top: 18px;
    font-size: 0.78rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.activation-view {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(320px, 0.82fr);
}

.panel-heading,
.activation-form,
.linked-view,
.blocked-view {
    padding: clamp(36px, 6vw, 76px);
}

.panel-heading {
    display: flex;
    flex-direction: column;
    justify-content: center;
    border-right: 1px solid var(--ink);
}

.eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: var(--signal-dark);
    font-family: ui-monospace, "Cascadia Code", monospace;
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0.16em;
}

.eyebrow::before {
    width: 28px;
    height: 2px;
    content: "";
    background: currentColor;
}

h1 {
    margin: 22px 0;
    font-family: "Rockwell", "Roboto Slab", Georgia, serif;
    font-size: clamp(2.5rem, 5vw, 5.4rem);
    font-weight: 600;
    line-height: 0.94;
    letter-spacing: -0.055em;
}

.panel-heading p,
.next-step,
.blocked-view p {
    max-width: 36rem;
    color: var(--ink-soft);
    font-size: clamp(0.96rem, 1.5vw, 1.1rem);
    line-height: 1.62;
}

.activation-form {
    align-self: center;
}

.activation-form label {
    display: flex;
    justify-content: space-between;
    margin: 0 0 9px;
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.activation-form label:not(:first-child) {
    margin-top: 28px;
}

.activation-form label span,
.activation-form small {
    color: var(--ink-soft);
    font-weight: 500;
}

.activation-form input {
    width: 100%;
    border: 0;
    border-bottom: 2px solid var(--ink);
    border-radius: 0;
    outline: none;
    color: var(--ink);
    background: transparent;
}

#pairing-code {
    padding: 12px 0 9px;
    font-family: ui-monospace, "Cascadia Code", monospace;
    font-size: clamp(1.7rem, 4vw, 2.8rem);
    font-weight: 800;
    letter-spacing: 0.09em;
    text-transform: uppercase;
}

#device-name {
    padding: 12px 0;
    font-size: 1rem;
}

.activation-form input:focus {
    border-bottom-color: var(--signal-dark);
    box-shadow: 0 3px 0 rgba(230, 161, 26, 0.18);
}

.activation-form small {
    display: block;
    margin-top: 9px;
    font-size: 0.68rem;
}

.primary-action,
.secondary-action {
    border: 0;
    cursor: pointer;
    font-weight: 800;
    letter-spacing: 0.04em;
    transition: transform 160ms ease, background-color 160ms ease;
}

.primary-action {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    min-height: 64px;
    margin-top: 38px;
    padding: 0 20px 0 24px;
    color: var(--paper-light);
    background: var(--ink);
}

.primary-action:hover,
.primary-action:focus-visible {
    background: #283533;
    transform: translateY(-2px);
}

.primary-action:disabled {
    cursor: wait;
    opacity: 0.62;
    transform: none;
}

.button-arrow {
    font-size: 1.45rem;
    color: var(--signal);
}

.form-message {
    min-height: 24px;
    margin: 16px 0 0;
    color: var(--danger);
    font-size: 0.82rem;
    line-height: 1.4;
}

.linked-view {
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.linked-status {
    display: flex;
    align-items: center;
    gap: 10px;
    font-family: ui-monospace, "Cascadia Code", monospace;
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.14em;
}

.status-pulse {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--ready);
    box-shadow: 0 0 0 7px rgba(31, 122, 85, 0.13);
    animation: breathe 2.4s ease-in-out infinite;
}

.machine-identity {
    margin: clamp(34px, 7vh, 70px) 0;
}

.machine-code {
    color: var(--signal-dark);
    font-family: ui-monospace, "Cascadia Code", monospace;
    font-size: clamp(1rem, 2vw, 1.35rem);
    font-weight: 800;
    letter-spacing: 0.15em;
}

.machine-identity h1 {
    max-width: 800px;
    margin: 12px 0 0;
    font-size: clamp(3.5rem, 9vw, 8rem);
}

.linked-meta {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    max-width: 620px;
    border-top: 1px solid var(--ink);
    border-bottom: 1px solid var(--ink);
}

.linked-meta > div {
    padding: 18px 22px 18px 0;
}

.linked-meta > div + div {
    padding-left: 22px;
    border-left: 1px solid var(--ink);
}

.linked-meta small,
.linked-meta strong {
    display: block;
}

.linked-meta small {
    margin-bottom: 7px;
    color: var(--ink-soft);
    font-size: 0.66rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.ready-label {
    color: var(--ready);
}

.next-step {
    margin: 28px 0 0;
    font-size: 0.9rem;
}

.blocked-view {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
}

.blocked-symbol {
    display: grid;
    width: 64px;
    height: 64px;
    margin-bottom: 34px;
    place-items: center;
    border: 2px solid var(--danger);
    color: var(--danger);
    font-family: ui-monospace, monospace;
    font-size: 2rem;
}

.blocked-view h1 {
    font-size: clamp(3rem, 7vw, 6rem);
}

.secondary-action {
    min-height: 52px;
    margin-top: 26px;
    padding: 0 24px;
    border: 1px solid var(--ink);
    background: transparent;
}

.secondary-action:hover,
.secondary-action:focus-visible {
    color: var(--paper-light);
    background: var(--ink);
}

.terminal-footer {
    padding-top: 12px;
    padding-bottom: max(20px, env(safe-area-inset-bottom));
    font-family: ui-monospace, "Cascadia Code", monospace;
    font-size: 0.63rem;
    font-weight: 700;
    letter-spacing: 0.13em;
}

[hidden] {
    display: none !important;
}

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

@keyframes breathe {
    50% { box-shadow: 0 0 0 12px rgba(31, 122, 85, 0.04); }
}

@media (max-width: 760px) {
    .terminal-shell {
        grid-template-columns: 1fr;
        padding-inline: 16px;
    }

    .context-rail {
        display: none;
    }

    .activation-view {
        grid-template-columns: 1fr;
    }

    .panel-heading {
        border-right: 0;
        border-bottom: 1px solid var(--ink);
    }

    .panel-heading,
    .activation-form,
    .linked-view,
    .blocked-view {
        padding: 34px 26px;
    }

    .loading-view,
    .activation-view,
    .linked-view,
    .blocked-view {
        min-height: 0;
    }

    .terminal-panel {
        min-height: 520px;
    }

    .linked-meta {
        grid-template-columns: 1fr;
        width: 100%;
    }

    .linked-meta > div + div {
        padding-left: 0;
        border-top: 1px solid var(--ink);
        border-left: 0;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
