/* Main App Styles */

:root {
    /* Colors */
    --pt-void: #080808;
    --pt-white: #FFFFFF;
    --pt-red: #FF2A2A;
    --pt-gray-dark: #1A1A1A;
    --pt-gray-light: #CCCCCC;

    /* Typography */
    --pt-font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
    --pt-font-mono: "SFMono-Regular", Consolas, "Liberation Mono", "Menlo", monospace;
    --pt-font-size-base: 16px;
    --pt-line-height-base: 1.5;

    /* Spacing Scale */
    --pt-s-1: 0.25rem;
    /* 4px */
    --pt-s-2: 0.5rem;
    /* 8px */
    --pt-s-3: 1rem;
    /* 16px */
    --pt-s-4: 1.5rem;
    /* 24px */
    --pt-s-5: 2rem;
    /* 32px */
    --pt-s-6: 3rem;
    /* 48px */
    --pt-s-8: 4rem;
    /* 64px */

    /* Borders */
    --pt-border-width: 1px;
    --pt-border: var(--pt-border-width) solid var(--pt-white);
    --pt-border-focus: 2px solid var(--pt-red);

    /* Layout */
    --pt-max-width: 800px;
    --pt-container-padding: var(--pt-s-3);
}

/* Global Reset */
*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    background-color: var(--pt-void);
    color: var(--pt-white);
    font-family: var(--pt-font-body);
    font-size: var(--pt-font-size-base);
    line-height: var(--pt-line-height-base);
    -webkit-font-smoothing: antialiased;
}

/* Typography Defaults */
h1,
h2,
h3,
h4,
h5,
h6 {
    margin-top: 0;
    margin-bottom: var(--pt-s-3);
    font-weight: 700;
    line-height: 1.2;
}

h1 {
    font-size: 2.5rem;
}

h2 {
    font-size: 2rem;
}

h3 {
    font-size: 1.75rem;
}

p {
    margin-top: 0;
    margin-bottom: var(--pt-s-3);
}

a {
    color: var(--pt-white);
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 3px;
    transition: color 0.2s ease, text-decoration-color 0.2s ease;
}

a:hover {
    color: var(--pt-red);
    text-decoration-color: var(--pt-red);
}

/* Terminal / Monospace elements */
pre,
code,
kbd,
samp {
    font-family: var(--pt-font-mono);
    font-size: 0.9em;
}

/* Accessibility: Focus States */
:focus-visible,
.pt-shell :focus-visible {
    outline: var(--pt-border-focus);
    outline-offset: 2px;
}

/* Accessibility: Skip Link */
.skip-link {
    position: absolute;
    top: -9999px;
    left: -9999px;
    background-color: var(--pt-white);
    color: var(--pt-void);
    padding: var(--pt-s-3);
    z-index: 9999;
    text-decoration: none;
    font-weight: bold;
    border: 2px solid var(--pt-red);
}

.skip-link:focus {
    top: var(--pt-s-3);
    left: var(--pt-s-3);
    width: auto;
    height: auto;
    clip: auto;
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }

    .pt-logo--glitch::before,
    .pt-logo--glitch::after,
    .pt-btn--primary,
    .pt-counter--ticking {
        animation: none !important;
        display: none !important;
        /* For glitch pseudo-elements */
    }

    .pt-btn--primary {
        display: inline-block !important;
        /* Don't hide the button itself */
    }
}

/* Layout Utilities (TICKET-009 foundations) */
.pt-shell {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    width: 100%;
    padding: var(--pt-s-3);
}

.pt-frame {
    flex: 1;
    border: var(--pt-border);
    width: 100%;
    max-width: var(--pt-max-width);
    margin: 0 auto;
    padding: var(--pt-s-4);
    display: flex;
    flex-direction: column;
    position: relative;
}

@media (min-width: 768px) {
    .pt-frame {
        padding: var(--pt-s-5);
    }
}

.pt-content {
    width: 100%;
}

/* Header & Footer alignment within frame */
.site-header {
    margin-bottom: var(--pt-s-4);
    border-bottom: 1px dashed var(--pt-gray-light);
    /* Optional visual separator, verifiable in design */
    padding-bottom: var(--pt-s-3);
}

.site-footer {
    margin-top: auto;
    padding-top: var(--pt-s-4);
    border-top: 1px dashed var(--pt-gray-light);
    font-size: 0.875rem;
    text-align: center;
}

.footer-links a {
    margin: 0 var(--pt-s-2);
}

/* Buttons (TICKET-010) */
.pt-btn {
    display: inline-block;
    padding: var(--pt-s-3) var(--pt-s-4);
    font-family: var(--pt-font-mono);
    font-weight: bold;
    text-transform: uppercase;
    text-decoration: none;
    background-color: transparent;
    border: var(--pt-border-width) solid var(--pt-white);
    color: var(--pt-white);
    cursor: pointer;
    min-height: 44px;
    transition: background-color 0.2s, color 0.2s;
}

.pt-btn:hover,
.pt-btn:focus-visible {
    background-color: var(--pt-white);
    color: var(--pt-void);
    text-decoration: none;
    outline: none;
    /* Focus outline replaced by border color/background change if preferred for buttons, but keeping outline is safer. */
}

/* Primary Button Variant + Pulse */
.pt-btn--primary {
    border-color: var(--pt-white);
    position: relative;
}

.pt-btn--primary:hover,
.pt-btn--primary:focus-visible {
    border-color: var(--pt-red);
    background-color: var(--pt-void);
    color: var(--pt-red);
}


@keyframes pt-pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.4);
    }

    70% {
        box-shadow: 0 0 0 10px rgba(255, 255, 255, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(255, 255, 255, 0);
    }
}

.pt-btn--primary {
    animation: pt-pulse 2s infinite;
}

/* Progress Bar (TICKET-011) */
.pt-progress-container {
    width: 100%;
    margin-bottom: var(--pt-s-3);
}

.pt-progress {
    width: 100%;
    height: 24px;
    border: var(--pt-border-width) solid var(--pt-white);
    background-color: var(--pt-void);
    position: relative;
}

.pt-progress__bar {
    height: 100%;
    background-color: var(--pt-white);
    width: 0%;
    transition: width 0.3s ease;
}

.pt-progress__label {
    display: block;
    font-family: var(--pt-font-mono);
    font-size: 0.875rem;
    margin-bottom: var(--pt-s-1);
    text-align: right;
}

/* Stall State (Ticket-057) */
.pt-progress--stall .pt-progress__bar {
    background-color: var(--pt-red) !important;
    width: 4% !important;
    /* Cap width visually for stall */
}

.pt-progress-status {
    display: none;
    color: var(--pt-red);
    font-family: var(--pt-font-mono);
    font-size: 0.875rem;
    font-weight: bold;
    text-transform: uppercase;
    margin-top: var(--pt-s-2);
    padding: var(--pt-s-2);
    border: 1px solid var(--pt-red);
    background: rgba(255, 42, 42, 0.1);
}

.pt-progress--stall+.pt-progress-status {
    display: block;
}

/* Urgent CTA Variant */
.pt-btn--urgent,
.is-urgent {
    border-color: var(--pt-red);
    background-color: var(--pt-void);
    color: var(--pt-red);
    box-shadow: 0 0 10px rgba(255, 42, 42, 0.3);
    animation: pt-pulse-urgent 1.5s infinite;
}

@keyframes pt-pulse-urgent {
    0% {
        box-shadow: 0 0 0 0 rgba(255, 42, 42, 0.4);
        transform: scale(1);
    }

    50% {
        transform: scale(1.02);
    }

    70% {
        box-shadow: 0 0 0 10px rgba(255, 42, 42, 0);
        transform: scale(1);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(255, 42, 42, 0);
        transform: scale(1);
    }
}

/* Roadblock (Ticket-059) */
.pt-roadblock {
    margin-top: var(--pt-s-3);
    margin-bottom: var(--pt-s-3);
    padding: var(--pt-s-3);
    border: 1px solid var(--pt-white);
    background-color: var(--pt-void);
    color: var(--pt-white);
    font-size: 0.95rem;
    line-height: 1.5;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.5s ease, transform 0.5s ease;
}

.pt-roadblock.is-active {
    opacity: 1;
    transform: translateY(0);
    animation: pt-bounce-in 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.pt-roadblock__t {
    display: block;
    font-family: var(--pt-font-mono);
    color: var(--pt-red);
    font-weight: bold;
    margin-bottom: var(--pt-s-1);
    text-transform: uppercase;
}

@keyframes pt-bounce-in {
    0% {
        opacity: 0;
        transform: scale(0.9) translateY(10px);
    }

    100% {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* Purity Counter (TICKET-012) */
.pt-counter {
    position: fixed;
    top: var(--pt-s-3);
    right: var(--pt-s-3);
    background-color: var(--pt-void);
    color: var(--pt-white);
    border: var(--pt-border);
    padding: var(--pt-s-2) var(--pt-s-3);
    font-family: var(--pt-font-mono);
    font-size: 1.25rem;
    font-weight: bold;
    z-index: 1000;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
}

@media (max-width: 767px) {
    .pt-counter {
        top: var(--pt-s-2);
        right: var(--pt-s-2);
        font-size: 1rem;
        padding: var(--pt-s-1) var(--pt-s-2);
        /* Ensure it respects safe area on notches */
        top: max(var(--pt-s-2), env(safe-area-inset-top));
        right: max(var(--pt-s-2), env(safe-area-inset-right));
    }
}

/* Analyze Log UI (TICKET-013) */
.pt-log {
    font-family: var(--pt-font-mono);
    color: var(--pt-white);
    background-color: var(--pt-gray-dark);
    border: var(--pt-border);
    padding: var(--pt-s-3);
    width: 100%;
    margin-bottom: var(--pt-s-4);
    overflow-x: hidden;
    /* Prevent horizontal scroll */
}

.pt-log__line {
    display: block;
    margin-bottom: var(--pt-s-1);
    line-height: 1.4;
    word-break: break-all;
    /* Break long hashes */
    overflow-wrap: anywhere;
    /* Ensure wrapping works everywhere */
}

.pt-log__prompt {
    color: var(--pt-gray-light);
    margin-right: var(--pt-s-1);
    user-select: none;
}

.pt-log__status--error {
    color: var(--pt-red);
}

.pt-log__status--success {
    color: var(--pt-white);
    /* Or green if we had one, but white fits theme */
}

/* Glitch Logo (TICKET-014) */
.pt-logo {
    display: inline-block;
    position: relative;
    font-family: var(--pt-font-mono);
    font-weight: 700;
    font-size: 1.5rem;
    text-transform: uppercase;
    text-decoration: none;
    color: var(--pt-white);
    z-index: 1;
}

.pt-logo:hover {
    text-decoration: none;
    color: var(--pt-white);
}

.pt-logo--glitch::before,
.pt-logo--glitch::after {
    content: attr(data-text);
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--pt-void);
}

.pt-logo--glitch::before {
    left: 2px;
    text-shadow: -1px 0 #ff00c1;
    clip: rect(44px, 450px, 56px, 0);
    animation: pt-glitch-anim 5s infinite linear alternate-reverse;
}

.pt-logo--glitch::after {
    left: -2px;
    text-shadow: -1px 0 #00fff9;
    clip: rect(44px, 450px, 56px, 0);
    animation: pt-glitch-anim2 5s infinite linear alternate-reverse;
}

@keyframes pt-glitch-anim {
    0% {
        clip: rect(38px, 9999px, 81px, 0);
    }

    5% {
        clip: rect(96px, 9999px, 3px, 0);
    }

    10% {
        clip: rect(2px, 9999px, 7px, 0);
    }

    15% {
        clip: rect(80px, 9999px, 86px, 0);
    }

    20% {
        clip: rect(28px, 9999px, 44px, 0);
    }

    25% {
        clip: rect(80px, 9999px, 9px, 0);
    }

    30% {
        clip: rect(57px, 9999px, 60px, 0);
    }

    35% {
        clip: rect(3px, 9999px, 1px, 0);
    }

    40% {
        clip: rect(81px, 9999px, 47px, 0);
    }

    45% {
        clip: rect(93px, 9999px, 20px, 0);
    }

    50% {
        clip: rect(11px, 9999px, 78px, 0);
    }

    55% {
        clip: rect(82px, 9999px, 59px, 0);
    }

    60% {
        clip: rect(19px, 9999px, 72px, 0);
    }

    65% {
        clip: rect(31px, 9999px, 23px, 0);
    }

    70% {
        clip: rect(61px, 9999px, 5px, 0);
    }

    75% {
        clip: rect(3px, 9999px, 19px, 0);
    }

    80% {
        clip: rect(6px, 9999px, 65px, 0);
    }

    85% {
        clip: rect(78px, 9999px, 16px, 0);
    }

    90% {
        clip: rect(66px, 9999px, 3px, 0);
    }

    95% {
        clip: rect(3px, 9999px, 10px, 0);
    }

    100% {
        clip: rect(10px, 9999px, 42px, 0);
    }
}

@keyframes pt-glitch-anim2 {
    0% {
        clip: rect(33px, 9999px, 89px, 0);
    }

    5% {
        clip: rect(2px, 9999px, 19px, 0);
    }

    10% {
        clip: rect(91px, 9999px, 35px, 0);
    }

    15% {
        clip: rect(78px, 9999px, 86px, 0);
    }

    20% {
        clip: rect(10px, 9999px, 30px, 0);
    }

    25% {
        clip: rect(20px, 9999px, 60px, 0);
    }

    30% {
        clip: rect(59px, 9999px, 30px, 0);
    }

    35% {
        clip: rect(14px, 9999px, 53px, 0);
    }

    40% {
        clip: rect(63px, 9999px, 89px, 0);
    }

    45% {
        clip: rect(4px, 9999px, 35px, 0);
    }

    50% {
        clip: rect(82px, 9999px, 3px, 0);
    }

    55% {
        clip: rect(38px, 9999px, 7px, 0);
    }

    60% {
        clip: rect(48px, 9999px, 63px, 0);
    }

    65% {
        clip: rect(53px, 9999px, 90px, 0);
    }

    70% {
        clip: rect(42px, 9999px, 5px, 0);
    }

    75% {
        clip: rect(72px, 9999px, 73px, 0);
    }

    80% {
        clip: rect(55px, 9999px, 81px, 0);
    }

    85% {
        clip: rect(31px, 9999px, 70px, 0);
    }

    90% {
        clip: rect(3px, 9999px, 67px, 0);
    }

    95% {
        clip: rect(13px, 9999px, 8px, 0);
    }

    100% {
        clip: rect(37px, 9999px, 1px, 0);
    }
}

/* Responsive UI Pass (TICKET-015) */

/* Hero Adjustments */
.hero h1 {
    word-break: break-word;
    /* Prevent overflow on small screens */
    font-size: clamp(2rem, 5vw, 3rem);
    /* Fluid typography */
}

/* Micro-test Questions */
.question-item {
    border: var(--pt-border);
    padding: var(--pt-s-3);
    margin-bottom: var(--pt-s-3);
    background-color: rgba(255, 255, 255, 0.05);
}

.question-item p {
    font-size: 1.1rem;
    margin-bottom: var(--pt-s-3);
    font-weight: 500;
}

.question-item .actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--pt-s-3);
}

.question-item button {
    /* Assuming standard buttons or pt-btn inside placeholder */
    background: transparent;
    border: var(--pt-border);
    color: var(--pt-white);
    padding: var(--pt-s-2);
    font-family: var(--pt-font-mono);
    text-transform: uppercase;
    cursor: pointer;
    min-height: 44px;
    /* Accessible tap target */
    font-weight: bold;
    transition: background 0.2s;
}

.question-item button:hover,
.question-item button:focus {
    background: var(--pt-white);
    color: var(--pt-void);
}

.question-item .btn-yes:hover {
    border-color: var(--pt-red);
    /* Optional accent */
}

@media (max-width: 480px) {
    .question-item .actions {
        gap: var(--pt-s-2);
    }

    .question-item {
        padding: var(--pt-s-3) var(--pt-s-2);
    }
}

/* Counter Avoidance */
@media (max-width: 767px) {
    .site-branding {
        padding-right: 60px;
        /* Reserve space for counter if header is sticky or overlapping */
    }

    /* Ensure hero content pushes down if needed, though safe area inset helps */
    .hero {
        padding-top: var(--pt-s-2);
    }
}

/* Ticking Effect (TICKET-020) */
@keyframes pt-border-pulse {
    0% {
        border-color: var(--pt-white);
    }

    50% {
        border-color: var(--pt-red);
    }

    100% {
        border-color: var(--pt-white);
    }
}

.pt-counter--ticking {
    animation: pt-border-pulse 0.2s infinite;
}

/* Legacy Pivot Banner (Ticket-058) */
.pt-pivot {
    margin: var(--pt-s-5) 0;
    border: 2px solid var(--pt-red);
    background-color: var(--pt-void);
    color: var(--pt-white);
    padding: var(--pt-s-4);
    text-align: center;
}

.pt-pivot__msg {
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: var(--pt-s-3);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.pt-pivot__cta {
    display: inline-block;
    padding: var(--pt-s-3) var(--pt-s-4);
    background: transparent;
    border: 1px solid var(--pt-white);
    color: var(--pt-white);
    text-decoration: none;
    font-family: var(--pt-font-mono);
    font-weight: bold;
    text-transform: uppercase;
    transition: all 0.2s ease;
}

.pt-pivot__cta:hover,
.pt-pivot__cta:focus-visible {
    background: var(--pt-white);
    color: var(--pt-void);
    border-color: var(--pt-white);
    outline: 2px solid var(--pt-red);
    outline-offset: 4px;
}

/* Legacy Context Links */
.legacy-context-links {
    margin-bottom: var(--pt-s-4);
    border-bottom: 1px dashed var(--pt-gray-light);
    padding-bottom: var(--pt-s-3);
}

.context-nav a {
    color: var(--pt-gray-light);
    font-family: var(--pt-font-mono);
    font-size: 0.875rem;
    text-decoration: none;
    border-bottom: 1px solid transparent;
}

.context-nav a:hover,
.context-nav a:focus {
    color: var(--pt-white);
    border-bottom-color: var(--pt-red);
}