/* Collaborative Pixel Canvas - Styles */

*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --color-bg: #f5f5f5;
    --color-surface: #ffffff;
    --color-text: #1a1a1a;
    --color-text-muted: #555;
    --color-border: #ccc;
    --color-primary: #3b82f6;
    --color-primary-hover: #2563eb;
    --color-error: #dc2626;
    --color-error-bg: #fef2f2;
    --color-warning-bg: #fffbeb;
    --color-warning-border: #f59e0b;
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.15);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.2);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background-color: var(--color-bg);
    color: var(--color-text);
    line-height: 1.5;
}

/* Main app layout */
#app {
    text-align: center;
    padding: 2rem 1rem;
}

h1 {
    margin-bottom: 1.5rem;
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--color-text);
}

/* Canvas container */
#canvas-container {
    position: relative;
    display: inline-block;
}

#canvas {
    display: block;
    border: 2px solid var(--color-border);
    border-radius: var(--radius-sm);
    background-color: var(--color-surface);
    cursor: crosshair;
}

/* Tooltip */
.tooltip {
    position: absolute;
    max-width: 220px;
    padding: 0.5rem 0.75rem;
    background-color: var(--color-text);
    color: var(--color-surface);
    font-size: 0.8125rem;
    line-height: 1.4;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    pointer-events: none;
    z-index: 100;
    white-space: normal;
    word-wrap: break-word;
}

.tooltip[hidden] {
    display: none;
}

/* Canvas error display */
.error-display {
    margin-top: 1.5rem;
    padding: 1.5rem;
    background-color: var(--color-error-bg);
    border: 1px solid var(--color-error);
    border-radius: var(--radius-md);
    text-align: center;
}

.error-display[hidden] {
    display: none;
}

.error-display p {
    margin-bottom: 1rem;
    color: var(--color-error);
    font-weight: 500;
}

.error-display button {
    padding: 0.5rem 1.25rem;
    background-color: var(--color-error);
    color: var(--color-surface);
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: opacity 0.15s;
}

.error-display button:hover {
    opacity: 0.9;
}

.error-display button:focus-visible {
    outline: 2px solid var(--color-error);
    outline-offset: 2px;
}

/* Modal overlay */
.modal-overlay {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 1000;
}

.modal-overlay[hidden] {
    display: none;
}

.modal-content {
    background-color: var(--color-surface);
    padding: 2rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 90%;
    max-width: 400px;
    text-align: center;
}

.modal-content h2 {
    margin-bottom: 0.5rem;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--color-text);
}

.modal-description {
    margin-bottom: 1.5rem;
    font-size: 0.875rem;
    color: var(--color-text-muted);
}

#name-form {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

#name-input {
    padding: 0.625rem 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    line-height: 1.5;
    color: var(--color-text);
    transition: border-color 0.15s;
}

#name-input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

#name-input[aria-invalid="true"] {
    border-color: var(--color-error);
}

#name-input[aria-invalid="true"]:focus {
    box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.15);
}

.validation-error {
    font-size: 0.8125rem;
    color: var(--color-error);
    text-align: left;
}

.validation-error[hidden] {
    display: none;
}

#name-submit-btn {
    padding: 0.625rem 1.5rem;
    background-color: var(--color-primary);
    color: var(--color-surface);
    border: none;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.15s;
}

#name-submit-btn:hover {
    background-color: var(--color-primary-hover);
}

#name-submit-btn:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

#name-submit-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Toast notifications */
.toast {
    position: fixed;
    top: 1rem;
    right: 1rem;
    max-width: 360px;
    padding: 0.875rem 1rem;
    padding-right: 2.5rem;
    background-color: var(--color-warning-bg);
    border: 1px solid var(--color-warning-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    font-size: 0.875rem;
    color: var(--color-text);
    z-index: 900;
    animation: toast-slide-in 0.2s ease-out;
}

.toast[hidden] {
    display: none;
}

.toast-error {
    background-color: var(--color-error-bg);
    border-color: var(--color-error);
}

.toast-dismiss {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    width: 1.5rem;
    height: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    font-size: 1.25rem;
    color: var(--color-text-muted);
    cursor: pointer;
    border-radius: var(--radius-sm);
    line-height: 1;
}

.toast-dismiss:hover {
    color: var(--color-text);
    background-color: rgba(0, 0, 0, 0.05);
}

.toast-dismiss:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 1px;
}

@keyframes toast-slide-in {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Responsive adjustments */
@media (max-width: 560px) {
    #app {
        padding: 1rem 0.5rem;
    }

    h1 {
        font-size: 1.25rem;
    }

    #canvas {
        max-width: 100%;
        height: auto;
    }

    .toast {
        left: 1rem;
        right: 1rem;
        max-width: none;
    }
}
