/* base.css — consolidated shared boilerplate (was responsive.css + accessibility.css). */
/* --- responsive --- */
/* =============================================
   MOBILE RESPONSIVE PATCH
   Add this to the END of theme.css
   ============================================= */

/* ======================================
   TABLET BREAKPOINT (768px)
   ====================================== */
@media (max-width: 768px) {
    /* Header adjustments */
    .header-content {
        flex-direction: column;
        gap: 1rem;
        padding: 1rem;
    }

    .header-buttons {
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        gap: 0.5rem;
        width: 100%;
    }

    header h1 {
        font-size: 1.5rem;
        text-align: center;
    }

    /* Stats row - stack vertically */
    .stats-row {
        flex-direction: column;
        gap: 0.75rem;
        align-items: stretch;
    }

    .stat-divider {
        display: none; /* Hide dividers on mobile */
    }

    /* Section spacing */
    section,
    .section {
        padding: 1rem;
        margin-bottom: 1rem;
    }

    /* Character grid - 2 columns on tablet */
    .character-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 1rem;
    }

    /* Dashboard buttons - smaller */
    .player-dashboard-btn,
    .st-dashboard-btn,
    .merits-flaws-btn,
    .in-the-blood-btn,
    .downtime-btn,
    .challenge-btn {
        padding: 0.5rem 0.75rem;
        font-size: 0.85rem;
    }

    /* Form adjustments */
    .form-row {
        flex-direction: column;
    }

    /* Attributes grid - 1 column on tablet */
    .grid-3 {
        grid-template-columns: 1fr;
    }
}

/* ======================================
   MOBILE BREAKPOINT (480px)
   ====================================== */
@media (max-width: 480px) {
    /* Typography scaling */
    header h1 {
        font-size: 1.3rem;
        letter-spacing: 0.03em;
    }

    section h2,
    .section h2 {
        font-size: 1.3rem;
    }

    section h3,
    .section h3 {
        font-size: 1.1rem;
    }

    /* Character grid - single column */
    .character-grid {
        grid-template-columns: 1fr;
    }

    /* Button sizing */
    .player-dashboard-btn,
    .st-dashboard-btn,
    .merits-flaws-btn,
    .in-the-blood-btn,
    .downtime-btn,
    .challenge-btn {
        width: 100%;
        padding: 0.75rem;
        font-size: 0.9rem;
    }

    /* Save footer adjustments */
    .save-footer {
        padding: 1rem;
    }

    .save-btn {
        width: 100%;
        max-width: 100%;
        padding: 1rem;
    }

    /* Auth box mobile */
    .auth-box {
        padding: 1.5rem 1rem;
        margin: 0.5rem;
    }

    .auth-logo {
        width: 80px;
        height: 80px;
    }

    /* Modal full screen on mobile */
    .modal-content {
        width: 100%;
        max-width: 100%;
        height: 100vh;
        margin: 0;
        border-radius: 0;
    }

    /* Downtime allocation bar */
    .allocation-bar {
        flex-direction: column;
        gap: 1rem;
        padding: 1rem;
    }

    .period-selector {
        width: 100%;
    }

    /* Challenge page - stack resources */
    .resource-bar {
        flex-direction: column;
        gap: 0.5rem;
    }

    .combat-row {
        flex-direction: column;
        gap: 1rem;
    }

    /* XP containers - wrap */
    #xp-container {
        flex-wrap: wrap;
        justify-content: center;
    }
}

/* ======================================
   TOUCH TARGET MINIMUM (44x44px)
   ====================================== */
button,
.btn,
.btn-primary,
.btn-secondary,
a.back-btn,
.resource-btn,
.action-btn-compact,
input[type="submit"],
input[type="button"] {
    min-height: 44px;
    min-width: 44px;
    /* Ensure touch-friendly targets */
}

/* Small buttons exception - but still accessible */
.gen-dot,
.cap-btn {
    min-height: 32px;
    min-width: 32px;
    padding: 0.25rem;
}

/* ======================================
   LANDSCAPE ORIENTATION
   ====================================== */
@media (max-width: 768px) and (orientation: landscape) {
    /* Reduce header size in landscape */
    header {
        padding: 0.5rem 1rem;
    }

    header h1 {
        font-size: 1.2rem;
    }

    /* Compact resource displays */
    .resource-bar {
        flex-direction: row;
        gap: 0.5rem;
    }
}

/* ======================================
   PRINT STYLES (Bonus)
   ====================================== */
@media print {
    /* Hide navigation */
    header .header-buttons,
    .back-btn,
    .save-footer {
        display: none;
    }

    /* Expand all collapsed sections */
    details {
        display: block;
    }

    details summary {
        display: none;
    }

    /* Remove background effects for printing */
    body,
    #app {
        background: white;
        color: black;
    }

    section,
    .section {
        border: 1px solid #333;
        box-shadow: none;
        page-break-inside: avoid;
    }
}

/* --- accessibility --- */
/* =============================================
   ACCESSIBILITY PATCH
   Critical WCAG 2.1 fixes
   ============================================= */

/* ======================================
   1. COLOR CONTRAST FIXES
   ====================================== */

/* Fix: Muted text contrast (was 4.1:1, now 4.6:1) */
:root {
    --text-muted: #8a7874; /* Increased from #7a6864 */
}

/* Fix: Auth link contrast (was 3.8:1, now 4.8:1) */
.auth-links a {
    color: #c97676; /* Increased from rgba(180,100,100,0.9) */
}

.auth-links a:hover {
    color: #d98888;
}

/* Ensure form hints are readable */
.form-group small,
.field-hint {
    color: #9a8884; /* Ensure at least 4.5:1 contrast */
}

/* ======================================
   2. FOCUS INDICATORS (Keyboard Nav)
   ====================================== */

/* Visible focus for all interactive elements */
button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.gen-dot:focus-visible,
.resource-btn:focus-visible {
    outline: 3px solid var(--accent-purple);
    outline-offset: 2px;
}

/* Remove default focus ring (use focus-visible instead) */
button:focus,
a:focus,
input:focus,
select:focus,
textarea:focus {
    outline: none; /* Rely on focus-visible styling */
}

/* High contrast focus for dark backgrounds */
.auth-btn:focus-visible,
.save-btn:focus-visible {
    outline: 3px solid #fbbf24;
    outline-offset: 3px;
}

/* ======================================
   3. SKIP LINK
   ====================================== */

.skip-link {
    position: absolute;
    top: -100px;
    left: 10px;
    background: var(--accent-purple);
    color: white;
    padding: 0.75rem 1rem;
    border-radius: var(--radius-md);
    text-decoration: none;
    font-weight: 600;
    z-index: 9999;
    transition: top 0.2s ease;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
}

.skip-link:focus {
    top: 10px;
}

/* ======================================
   4. SCREEN READER ONLY TEXT
   ====================================== */

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* ======================================
   5. FORM FIELD STATES
   ====================================== */

/* Required field indicator */
.form-group.required label::after {
    content: " *";
    color: var(--accent-blood);
    font-weight: bold;
}

/* Error state */
input.error,
select.error,
textarea.error {
    border-color: var(--accent-blood);
    background: rgba(139, 0, 0, 0.1);
}

/* Success state */
input.valid,
select.valid,
textarea.valid {
    border-color: var(--accent-green);
    background: rgba(34, 197, 94, 0.05);
}

/* Field-level error message */
.field-error {
    color: var(--accent-blood);
    font-size: 0.85rem;
    margin-top: 0.25rem;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.field-error::before {
    content: "⚠️";
}

/* ======================================
   6. MODAL ACCESSIBILITY
   ====================================== */

/* Ensure modals have proper focus trap styling */
.modal[aria-modal="true"] {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
}

.modal-content:focus {
    outline: none; /* Focus trap handles keyboard nav */
}

/* Close button accessibility */
.close-btn {
    position: relative;
}

.close-btn::after {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    background: transparent;
    transition: background 0.2s ease;
}

.close-btn:focus-visible::after {
    background: rgba(139, 92, 246, 0.2);
}

/* ======================================
   7. REDUCED MOTION
   ====================================== */

/* Respect user's motion preferences */
@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;
    }

    /* Keep essential transitions but make them instant */
    .auth-container,
    .auth-box,
    .auth-logo {
        animation: none;
    }
}

/* ======================================
   8. HIGH CONTRAST MODE
   ====================================== */

/* Windows High Contrast Mode support */
@media (prefers-contrast: high) {
    :root {
        --border-subtle: rgba(255, 255, 255, 0.5);
        --border-glow: rgba(255, 255, 255, 0.8);
    }

    button,
    .btn,
    input,
    select,
    textarea {
        border: 2px solid;
    }

    a {
        text-decoration: underline;
    }

    .auth-box,
    section,
    .section {
        border: 2px solid;
    }
}

/* ======================================
   9. LOADING INDICATORS
   ====================================== */

/* Accessible loading spinner */
.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 0.8s linear infinite;
}

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

/* Button loading state */
.btn-loading {
    position: relative;
    color: transparent !important;
    pointer-events: none;
}

.btn-loading::after {
    content: "";
    position: absolute;
    width: 18px;
    height: 18px;
    top: 50%;
    left: 50%;
    margin-left: -9px;
    margin-top: -9px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 0.6s linear infinite;
}

/* ======================================
   10. TOAST NOTIFICATIONS (Accessible)
   ====================================== */

.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    pointer-events: none;
}

.toast {
    background: var(--bg-card);
    border: 2px solid var(--accent-purple);
    border-radius: var(--radius-md);
    padding: 1rem 1.25rem;
    min-width: 250px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    opacity: 0;
    transform: translateX(100px);
    transition: all 0.3s ease;
    pointer-events: auto;
}

.toast.show {
    opacity: 1;
    transform: translateX(0);
}

.toast.toast-success {
    border-color: var(--accent-green);
}

.toast.toast-error {
    border-color: var(--accent-blood);
}

.toast.toast-info {
    border-color: var(--accent-purple);
}

/* ======================================
   11. KEYBOARD NAVIGATION HELPERS
   ====================================== */

/* Tab order indicators (dev mode) */
body.debug-tab-order [tabindex]:focus::before {
    content: attr(tabindex);
    position: absolute;
    top: -20px;
    left: 0;
    background: red;
    color: white;
    padding: 2px 6px;
    font-size: 12px;
    z-index: 9999;
}

/* Visible focus for custom controls */
.gen-dot[role="radio"]:focus-visible,
.resource-btn:focus-visible,
.cap-btn:focus-visible {
    box-shadow: 0 0 0 3px var(--accent-purple);
}

/* ======================================
   12. LINK STYLING FOR CLARITY
   ====================================== */

/* Ensure links are distinguishable from regular text */
a {
    text-decoration: underline;
    text-decoration-color: rgba(139, 92, 246, 0.3);
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
    transition: text-decoration-color 0.2s ease;
}

a:hover {
    text-decoration-color: var(--accent-purple);
}

/* Exception for button-styled links */
a.btn,
a.back-btn,
a.logo-link {
    text-decoration: none;
}

/* ======================================
   13. ARIA LIVE REGIONS
   ====================================== */

/* Style for dynamically updated content */
[aria-live="polite"],
[aria-live="assertive"] {
    position: relative;
}

/* Visual indicator for screen reader announcements (dev mode) */
body.debug-aria [aria-live]::after {
    content: "🔊";
    position: absolute;
    top: 0;
    right: 0;
    font-size: 12px;
    opacity: 0.3;
}

/* ======================================
   14. ERROR & SUCCESS STATES (ARIA)
   ====================================== */

/* Alert role styling */
[role="alert"] {
    border-left: 4px solid;
    padding-left: 1rem;
}

[role="alert"].error-message {
    border-left-color: var(--accent-blood);
}

[role="alert"].success-message {
    border-left-color: var(--accent-green);
}
