/* ==============================================
   CrossGrid CSS - Sleek Apple Dark/Black Theme
   Pure #000000 and #ffffff contrast.
   ============================================== */

:root {
    --bg-color: #000000;
    --text-primary: #ffffff;
    --text-dim: rgba(255, 255, 255, 0.6);
    --border-color: rgba(255, 255, 255, 0.15);
    --border-hover: rgba(255, 255, 255, 0.4);
    --panel-bg: rgba(255, 255, 255, 0.03);
    --input-bg: rgba(255, 255, 255, 0.05);
    --btn-bg: #ffffff;
    --btn-text: #000000;
    --focus-ring: rgba(255, 255, 255, 0.5);
    --error: #ff453a;

    --radius-lg: 16px;
    --radius-md: 10px;
    --radius-sm: 6px;

    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-smooth: 300ms cubic-bezier(0.4, 0, 0.2, 1);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    font-family:
        "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        Helvetica, Arial, sans-serif;
    line-height: 1.5;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 2rem 1rem;
    -webkit-font-smoothing: antialiased;
}

.container {
    width: 100%;
    max-width: 900px;
    margin: 0 auto;
}

/* Header */
header {
    text-align: center;
    margin-bottom: 3rem;
    animation: fade-in 0.6s ease-out;
}

header h1 {
    font-size: 2.5rem;
    font-weight: 500;
    letter-spacing: -0.02em;
    margin-bottom: 0.5rem;
}

header p {
    color: var(--text-dim);
    font-weight: 300;
    font-size: 1.125rem;
}

/* Dashboard Form */
#crossword-form {
    display: grid;
    grid-template-columns: 1fr 1.5fr;
    gap: 2rem;
    animation: fade-in-up 0.8s ease-out;
}

@media (max-width: 768px) {
    #crossword-form {
        grid-template-columns: 1fr;
    }
}

.analytics-panel {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
    margin-bottom: 2rem;
    animation: fade-in-up 0.6s ease-out;
}

@media (max-width: 768px) {
    .analytics-panel {
        grid-template-columns: 1fr;
    }
}

.stat-card {
    background-color: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.5);
    transition: transform var(--transition-smooth), box-shadow var(--transition-smooth);
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.7);
    border-color: var(--border-hover);
}

.stat-card h3 {
    font-size: 0.875rem;
    color: var(--text-dim);
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.stat-card p.stat-value {
    font-size: 2.5rem;
    font-weight: 600;
    color: var(--text-primary);
}

.stat-card canvas {
    width: 100% !important;
    height: 80px !important;
}

.dashboard-panel, .upload-panel {
    background-color: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 2rem;
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.5);
    transition: box-shadow var(--transition-smooth), border-color var(--transition-smooth);
}

.dashboard-panel:hover, .upload-panel:hover {
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.7);
    border-color: rgba(255, 255, 255, 0.25);
}

h2 {
    font-size: 1.25rem;
    font-weight: 500;
    margin-bottom: 1.5rem;
    letter-spacing: -0.01em;
}

/* Form Controls */
.form-group {
    margin-bottom: 1.25rem;
}

label {
    display: block;
    font-size: 0.875rem;
    color: var(--text-dim);
    margin-bottom: 0.5rem;
}

input[type="text"],
input[type="number"],
select {
    width: 100%;
    background-color: var(--input-bg);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-radius: var(--radius-md);
    padding: 0.75rem 1rem;
    font-size: 1rem;
    font-family: inherit;
    transition: all var(--transition-fast);
    min-height: 44px; /* Touch target size */
}

input:hover, select:hover {
    border-color: var(--border-hover);
}

input:focus, select:focus {
    outline: none;
    border-color: var(--text-primary);
    box-shadow: 0 0 0 2px var(--focus-ring);
}

/* Custom Select Dropdown Arrow */
.select-wrapper {
    position: relative;
}

.select-wrapper::after {
    content: "";
    position: absolute;
    right: 1.25rem;
    top: 50%;
    transform: translateY(-50%);
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 5px solid var(--text-primary);
    pointer-events: none;
}

select {
    appearance: none;
    -webkit-appearance: none;
    padding-right: 2.5rem;
}

/* Reset option styling for standard select */
option {
    background-color: #1c1c1e;
    color: #ffffff;
}

/* Drag and Drop Zone */
.drop-zone {
    border: 1px dashed var(--border-color);
    border-radius: var(--radius-lg);
    background-color: var(--input-bg);
    padding: 3rem 2rem;
    text-align: center;
    cursor: pointer;
    transition: all var(--transition-smooth);
    margin-bottom: 1.5rem;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 200px;
}

.drop-zone:hover, .drop-zone.drag-over {
    border-color: var(--text-primary);
    background-color: rgba(255, 255, 255, 0.08);
}

.drop-zone.drag-over {
    transform: scale(1.02);
}

.upload-icon {
    margin-bottom: 1rem;
    color: var(--text-dim);
    transition: color var(--transition-fast);
}

.drop-zone:hover .upload-icon {
    color: var(--text-primary);
}

.drop-text {
    font-size: 1.125rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
}

.sub-text {
    font-size: 0.875rem;
    color: var(--text-dim);
}

.browse-text {
    color: var(--text-primary);
    text-decoration: underline;
    text-decoration-color: var(--border-hover);
    text-underline-offset: 4px;
}

/* Selected File Indicator */
.file-indicator {
    display: flex;
    align-items: center;
    background-color: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 0.75rem 1rem;
    margin-bottom: 1.5rem;
    animation: fade-in 0.3s ease-out;
}

.file-indicator svg {
    color: var(--text-dim);
    margin-right: 0.75rem;
    flex-shrink: 0;
}

#file-name {
    flex-grow: 1;
    font-size: 0.875rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.remove-btn {
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    padding: 4px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

.remove-btn:hover {
    color: var(--text-primary);
    background-color: rgba(255, 255, 255, 0.1);
}

/* Primary Button */
.primary-btn {
    width: 100%;
    background-color: var(--btn-bg);
    color: var(--btn-text);
    border: none;
    border-radius: var(--radius-md);
    padding: 1rem;
    font-size: 1rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition-fast);
    box-shadow: 0 4px 14px rgba(255, 255, 255, 0.1);
    min-height: 44px; /* Touch target */
    display: flex;
    justify-content: center;
    align-items: center;
}

.primary-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(255, 255, 255, 0.15);
}

.primary-btn:active {
    transform: translateY(1px);
    box-shadow: 0 2px 8px rgba(255, 255, 255, 0.1);
}

.primary-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* States */
.hidden {
    display: none !important;
}

.loading-state, .error-state {
    text-align: center;
    margin-top: 2rem;
    padding: 1.5rem;
    background-color: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    animation: fade-in 0.3s ease-out;
}

.error-state {
    border-color: rgba(255, 69, 58, 0.3);
    color: var(--error);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
}

.spinner {
    width: 24px;
    height: 24px;
    border: 2px solid var(--border-color);
    border-top-color: var(--text-primary);
    border-radius: 50%;
    margin: 0 auto 1rem auto;
    animation: spin 1s linear infinite;
}

/* Animations */
@keyframes fade-in {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes fade-in-up {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Accessibility: focus visible only for keyboard */
:focus:not(:focus-visible) {
    outline: none;
    box-shadow: none;
}

/* ══════════════════════════════════════════
   PWA: Install Toast (ui-ux-pro-max §micro-interactions)
   ══════════════════════════════════════════ */
#pwa-install-toast {
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%) translateY(120%);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 999px;
    padding: 0.75rem 1.25rem;
    color: #fff;
    font-size: 0.9rem;
    white-space: nowrap;
    z-index: 9999;
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

#pwa-install-toast.visible {
    transform: translateX(-50%) translateY(0);
}

#pwa-install-btn {
    background: #fff;
    color: #000;
    font-weight: 600;
    font-size: 0.85rem;
    border: none;
    border-radius: 999px;
    padding: 0.35rem 1rem;
    cursor: pointer;
    transition: transform 0.15s ease;
}

#pwa-install-btn:hover { transform: scale(1.04); }
#pwa-install-btn:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

#pwa-dismiss-btn {
    background: none;
    color: rgba(255, 255, 255, 0.6);
    border: none;
    cursor: pointer;
    font-size: 1rem;
    padding: 0.25rem;
    line-height: 1;
    transition: color 0.15s ease;
}
#pwa-dismiss-btn:hover { color: #fff; }
#pwa-dismiss-btn:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

/* ══════════════════════════════════════════
   PWA: Offline Banner (accessibility-compliance: role=alert, high contrast)
   ══════════════════════════════════════════ */
#offline-banner {
    position: sticky;
    top: 0;
    z-index: 1000;
    width: 100%;
    background: rgba(255, 69, 58, 0.1);
    border-bottom: 1px solid rgba(255, 69, 58, 0.3);
    color: #ff6b6b;
    text-align: center;
    padding: 0.6rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from { transform: translateY(-100%); opacity: 0; }
    to   { transform: translateY(0);     opacity: 1; }
}
