/* Global Reset and Base Styles */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    /* Color Palette - Base colors with derived shades */
    --color-primary: #2563eb;       /* Blue */
    --color-primary-hover: #1d4ed8;  /* Darker blue */
    --color-primary-light: #dbeafe;  /* Light blue */

    --color-secondary: #6b7280;     /* Gray */
    --color-secondary-light: #f3f4f6; /* Light gray */
    --color-secondary-hover: #4b5563; /* Darker gray */

    --color-success: #10b981;       /* Green */
    --color-error: #ef4444;         /* Red */
    --color-warning: #f59e0b;       /* Amber */

    --color-background: #ffffff;    /* White */
    --color-surface: #f8fafc;       /* Off-white */

    --color-text: #111827;          /* Very dark blue-gray */
    --color-text-secondary: #6b7280; /* Gray */
    --color-text-muted: #9ca3af;     /* Light gray */

    --color-border: #e5e7eb;        /* Light border */
    --color-border-hover: #d1d5db;  /* Slightly darker border */

    --color-input-bg: #ffffff;
    --color-button-primary: var(--color-primary);
    --color-button-primary-hover: var(--color-primary-hover);
    --color-button-secondary: var(--color-secondary);
    --color-button-secondary-hover: var(--color-secondary-hover);

    /* Updated result and accent colors */
    --color-result-bg: var(--color-surface);
    --color-accent: var(--color-primary-light);
    --color-highlight: #fef3c7;     /* Light yellow for highlights */

    /* Spacing Scale */
    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
    --spacing-xl: 32px;
    --spacing-xxl: 48px;

    /* Border Radius Scale */
    --border-radius-sm: 4px;
    --border-radius: 8px;
    --border-radius-lg: 12px;
    --border-radius-xl: 16px;

    /* Shadow Scale */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);

    /* Typography Scale */
    --text-xs: 0.75rem;
    --text-sm: 0.875rem;
    --text-base: 1rem;
    --text-lg: 1.125rem;
    --text-xl: 1.25rem;
    --text-2xl: 1.5rem;
    --text-3xl: 1.875rem;
    --text-4xl: 2.25rem;

    --font-weight-normal: 400;
    --font-weight-medium: 500;
    --font-weight-semibold: 600;
    --font-weight-bold: 700;

    --line-height-tight: 1.25;
    --line-height-normal: 1.5;
    --line-height-relaxed: 1.625;

    --max-width: 1200px;
    --text-max-width: 65ch; /* For comfortable reading */
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', sans-serif;
    background: var(--color-background);
    color: var(--color-text);
    line-height: var(--line-height-relaxed);
    margin: 0;
    padding: var(--spacing-lg);
}

/* Typography */
h1 {
    font-size: 2.5rem;
    font-weight: 700;
    letter-spacing: -0.5px;
    text-align: center;
    margin: var(--spacing-xl) 0 var(--spacing-sm);
}

.hero-description {
    text-align: center;
    font-size: var(--text-lg);
    color: var(--color-text-secondary);
    margin: 0 0 var(--spacing-xl);
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
}

h2 {
    font-size: 1.5rem;
    font-weight: 600;
    letter-spacing: -0.25px;
    margin-bottom: var(--spacing-md);
    width: 100%;
}

/* Layout & Grid */
.container {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--spacing-lg);
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 var(--spacing-md);
}

@media (min-width: 768px) {
    .container {
        grid-template-columns: repeat(2, 1fr);
    }
    
    /* Target the last section when it's the 5th child */
    .storage-section:nth-child(5) {
        grid-column: 1 / -1;
        max-width: 500px;
        justify-self: center;
    }
    
    /* Ensure consistent styling for centered element */
    .storage-section:nth-child(5) {
        display: flex;
        flex-direction: column;
        align-items: center;
    }
    
    .storage-section:nth-child(5) .storage-form {
        width: 100%;
    }
}

/* Storage Section Components */
.storage-section {
    background: var(--color-background);
    padding: var(--spacing-lg);
    border-radius: var(--border-radius);
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    width: 100%;
}

.storage-form {
    width: 100%;
}

/* Form Controls */
.input-group {
    display: flex;
    gap: var(--spacing-sm);
    margin-bottom: var(--spacing-md);
}

.input-wrapper {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xs);
    flex: 1;
}

.input-wrapper label {
    font-size: var(--text-sm);
    font-weight: var(--font-weight-medium);
    color: var(--color-text);
    margin-bottom: var(--spacing-xs);
}

.input-row,
.button-row {
    display: flex;
    gap: var(--spacing-sm);
    margin-bottom: var(--spacing-md);
}

.input-row {
    flex-direction: column;
    align-items: stretch;
}

.button-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
}

@media (min-width: 480px) {
    .input-row {
        flex-direction: row;
        align-items: center;
    }

    .button-row button {
        flex: 0 0 auto;
    }
}

/* Enhanced form labels */
.form-group {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xs);
    margin-bottom: var(--spacing-md);
    width: 100%;
}

.form-label {
    font-size: var(--text-sm);
    font-weight: var(--font-weight-medium);
    color: var(--color-text);
    margin-bottom: var(--spacing-xs);
}

.form-help {
    font-size: var(--text-xs);
    color: var(--color-text-secondary);
    line-height: var(--line-height-tight);
    margin-top: var(--spacing-xs);
}

input[type="text"] {
    padding: var(--spacing-sm) var(--spacing-md);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    background: var(--color-input-bg);
    font-size: var(--text-base);
    flex: 1;
    min-width: 0; /* Prevents flex items from overflowing */
    height: 44px; /* Consistent height with buttons */
}

/* Button Hierarchy */
.btn-primary {
    background: var(--color-button-primary);
    color: white;
    font-weight: var(--font-weight-medium);
}

.btn-primary:hover {
    background: var(--color-button-primary-hover);
}

.btn-secondary {
    background: var(--color-button-secondary);
    color: white;
    font-weight: var(--font-weight-medium);
}

.btn-secondary:hover {
    background: var(--color-button-secondary-hover);
}

.btn-success {
    background: var(--color-success);
    color: white;
    font-weight: var(--font-weight-medium);
}

.btn-success:hover {
    background: #059669;
}

.btn-danger {
    background: var(--color-error);
    color: white;
    font-weight: var(--font-weight-medium);
}

.btn-danger:hover {
    background: #dc2626;
}

button {
    padding: var(--spacing-sm) var(--spacing-md);
    color: white;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-size: var(--text-sm);
    font-weight: var(--font-weight-normal);
    font-family: inherit;
    height: 44px; /* Minimum 44px for accessibility */
    transition: all 0.15s ease;
    min-width: 80px;
    line-height: var(--line-height-tight);
}

button:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-lg);
}

button:active {
    transform: translateY(0);
}

button:focus {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

/* Animation for better user feedback */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.result-display {
    animation: fadeIn 0.2s ease-out;
}

input:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-light);
    outline: none;
}

button:active {
    transform: translateY(1px);
}

/* Results Display - Enhanced Data Presentation */
.result-display {
    background: var(--color-result-bg);
    border-radius: var(--border-radius);
    padding: var(--spacing-md);
    margin-top: var(--spacing-md);
    min-height: 60px;
    font-size: var(--text-sm);
    line-height: var(--line-height-relaxed);
    word-break: break-word;
    border: 1px solid var(--color-border);
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
}

.result-display:empty::before {
    content: "No results yet";
    color: var(--color-text-muted);
    font-style: italic;
}

#cookie-result,
#local-result,
#session-result,
#idb-result,
#cache-result {
    background: var(--color-result-bg);
    border-radius: var(--border-radius);
    padding: var(--spacing-md);
    margin-top: var(--spacing-md);
    min-height: 60px;
    font-size: var(--text-sm);
    line-height: var(--line-height-relaxed);
    word-break: break-word;
    border: 1px solid var(--color-border);
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
}

#cookie-result:empty::before,
#local-result:empty::before,
#session-result:empty::before,
#idb-result:empty::before,
#cache-result:empty::before {
    content: "Ready to store data. Enter a key and value above, then click 'Set' to get started.";
    color: var(--color-text-muted);
    font-style: italic;
}

/* Comparison Overview Section */
.comparison-overview {
    max-width: var(--max-width);
    margin: 0 auto var(--spacing-xxl);
    padding: 0 var(--spacing-md);
}

.comparison-overview h2 {
    text-align: center;
    font-size: var(--text-2xl);
    font-weight: var(--font-weight-bold);
    margin-bottom: var(--spacing-xl);
    color: var(--color-text);
}

.comparison-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--spacing-md);
    background: var(--color-background);
    border-radius: var(--border-radius-lg);
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.comparison-header {
    display: grid;
    grid-template-columns: 150px 1fr 100px 120px 120px 1fr;
    gap: var(--spacing-md);
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    padding: var(--spacing-md);
    font-weight: var(--font-weight-semibold);
    font-size: var(--text-sm);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--color-text-secondary);
}

.comparison-row {
    display: grid;
    grid-template-columns: 150px 1fr 100px 120px 120px 1fr;
    gap: var(--spacing-md);
    padding: var(--spacing-md);
    border-bottom: 1px solid var(--color-border);
    align-items: start;
    transition: background-color 0.15s ease;
}

.comparison-row:hover {
    background: var(--color-surface);
}

.comparison-row:last-child {
    border-bottom: none;
}

.comparison-cell {
    font-size: var(--text-sm);
    line-height: var(--line-height-normal);
    color: var(--color-text);
    word-wrap: break-word;
}

.storage-name {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xs);
}

.storage-category {
    font-size: var(--text-xs);
    font-weight: var(--font-weight-medium);
    background: var(--color-primary-light);
    color: var(--color-primary);
    padding: 2px var(--spacing-xs);
    border-radius: var(--border-radius-sm);
    align-self: flex-start;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.comparison-row[data-storage-type="cookies"] .storage-category {
    background: var(--color-accent);
    color: var(--color-secondary);
}

.comparison-row[data-storage-type="localstorage"] .storage-category,
.comparison-row[data-storage-type="sessionstorage"] .storage-category {
    background: var(--color-success);
    color: white;
}

.comparison-row[data-storage-type="indexeddb"] .storage-category {
    background: var(--color-warning);
    color: white;
}

.comparison-row[data-storage-type="cache"] .storage-category {
    background: var(--color-error);
    color: white;
}

/* Responsive design for comparison grid */
@media (max-width: 1024px) {
    .comparison-header,
    .comparison-row {
        grid-template-columns: 1fr 1fr;
        gap: var(--spacing-sm);
    }

    .comparison-header {
        display: none; /* Hide header on mobile, use implied labels */
    }

    .comparison-cell:nth-child(1)::before { content: "Type: "; font-weight: bold; }
    .comparison-cell:nth-child(2)::before { content: "Purpose: "; font-weight: bold; }
    .comparison-cell:nth-child(3)::before { content: "Size: "; font-weight: bold; }
    .comparison-cell:nth-child(4)::before { content: "Duration: "; font-weight: bold; }
    .comparison-cell:nth-child(5)::before { content: "Scope: "; font-weight: bold; }
    .comparison-cell:nth-child(6)::before { content: "Use: "; font-weight: bold; }

    .comparison-cell {
        margin-bottom: var(--spacing-sm);
        padding-bottom: var(--spacing-sm);
        border-bottom: 1px solid var(--color-border);
    }

    .comparison-cell:last-child {
        border-bottom: none;
        margin-bottom: 0;
        padding-bottom: 0;
    }
}

/* Educational Content Styles */
.educational-content {
    margin-bottom: var(--spacing-xl);
    padding: var(--spacing-lg);
    background: var(--color-surface);
    border-radius: var(--border-radius);
    border: 1px solid var(--color-border);
}

.educational-content > div {
    margin-bottom: var(--spacing-lg);
}

.educational-content > div:last-child {
    margin-bottom: 0;
}

.content-description {
    margin-bottom: var(--spacing-lg);
}

.content-description p {
    margin-bottom: var(--spacing-sm);
    line-height: var(--line-height-normal);
}

.key-characteristics {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--spacing-md);
    margin-bottom: var(--spacing-lg);
}

.characteristic {
    background: var(--color-background);
    padding: var(--spacing-sm) var(--spacing-md);
    border-radius: var(--border-radius-sm);
    border: 1px solid var(--color-border);
    font-size: var(--text-sm);
}

.use-case-examples strong,
.best-practices strong {
    display: block;
    margin-bottom: var(--spacing-sm);
    font-size: var(--text-base);
    color: var(--color-text);
}

.use-case-examples ul,
.best-practices ul {
    margin: 0;
    padding-left: var(--spacing-lg);
}

.use-case-examples li,
.best-practices li {
    margin-bottom: var(--spacing-xs);
    line-height: var(--line-height-normal);
    color: var(--color-text-secondary);
}

.demo-section {
    border-top: 2px solid var(--color-border);
    padding-top: var(--spacing-lg);
}

.demo-section h3 {
    font-size: var(--text-lg);
    font-weight: var(--font-weight-semibold);
    margin-bottom: var(--spacing-md);
    color: var(--color-text);
}

/* Decision Tree Section */
.decision-tree-section {
    max-width: var(--max-width);
    margin: 0 auto var(--spacing-xxl);
    padding: 0 var(--spacing-md);
}

.decision-tree-section h2 {
    text-align: center;
    font-size: var(--text-2xl);
    font-weight: var(--font-weight-bold);
    margin-bottom: var(--spacing-xl);
    color: var(--color-text);
}

.decision-tree {
    background: var(--color-surface);
    border-radius: var(--border-radius-lg);
    border: 1px solid var(--color-border);
    padding: var(--spacing-xl);
    box-shadow: var(--shadow);
}

.decision-node h3 {
    font-size: var(--text-xl);
    font-weight: var(--font-weight-semibold);
    margin-bottom: var(--spacing-lg);
    color: var(--color-text);
    text-align: center;
}

.decision-options {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: var(--spacing-md);
    margin-bottom: var(--spacing-xl);
}

.decision-btn {
    background: var(--color-primary);
    color: white;
    border: none;
    padding: var(--spacing-md) var(--spacing-lg);
    border-radius: var(--border-radius);
    font-size: var(--text-base);
    font-weight: var(--font-weight-medium);
    cursor: pointer;
    transition: all 0.15s ease;
    text-align: center;
    min-height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: var(--line-height-normal);
}

.decision-btn:hover {
    background: var(--color-primary-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.decision-result {
    background: var(--color-background);
    border-radius: var(--border-radius-lg);
    padding: var(--spacing-lg);
    border: 2px solid var(--color-success);
    box-shadow: var(--shadow);
}

.recommended-storage h4 {
    font-size: var(--text-lg);
    font-weight: var(--font-weight-semibold);
    margin-bottom: var(--spacing-md);
    color: var(--color-text);
    text-align: center;
}

.recommended-type {
    background: var(--color-success);
    color: white;
    padding: var(--spacing-sm) var(--spacing-md);
    border-radius: var(--border-radius);
    font-size: var(--text-lg);
    font-weight: var(--font-weight-bold);
    text-align: center;
    margin-bottom: var(--spacing-md);
    display: inline-block;
}

.decision-explanation {
    background: var(--color-surface);
    padding: var(--spacing-md);
    border-radius: var(--border-radius);
    border: 1px solid var(--color-border);
    font-size: var(--text-base);
    line-height: var(--line-height-normal);
    color: var(--color-text-secondary);
    text-align: center;
}

/* Responsive adjustments for decision tree */
@media (max-width: 768px) {
    .decision-options {
        grid-template-columns: 1fr;
    }

    .decision-btn {
        min-height: auto;
        padding: var(--spacing-md);
    }
}

/* Typography - proper text constraints */
.result-display p,
.result-display div {
    max-width: 65ch;
    line-height: 1.5;
}

/* Enhanced accessibility and focus states */
button:not(:disabled):focus-visible,
input:focus-visible {
    outline: 3px solid var(--color-primary);
    outline-offset: 2px;
}

/* GitHub Corner */
.github-corner svg {
    fill: var(--color-text);
    color: var(--color-background);
    position: absolute;
    top: 0;
    right: 0;
    border: 0;
    z-index: 100;
}

.github-corner:hover .octo-arm {
    animation: octocat-wave 560ms ease-in-out;
}

@keyframes octocat-wave {
    0%, 100% { transform: rotate(0); }
    20%, 60% { transform: rotate(-25deg); }
    40%, 80% { transform: rotate(10deg); }
}

@media (max-width: 500px) {
    .github-corner:hover .octo-arm {
        animation: none;
    }
    .github-corner .octo-arm {
        animation: octocat-wave 560ms ease-in-out;
    }
}
