:root {
    --color-bg: #f5f5f5;
    --color-surface: #ffffff;
    --color-surface-muted: #f2f2f2;
    --color-text: #222222;
    --color-text-muted: #666666;
    --color-border: #dddddd;
    --color-danger: #7a1f1f;

    --heatmap-0: #ebedf0;
    --heatmap-1: #c6e48b;
    --heatmap-2: #7bc96f;
    --heatmap-3: #239a3b;
    --heatmap-4: #196127;

    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: system-ui, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
}

a {
    color: var(--color-text);
}

/* Layout */

.container {
    max-width: 800px;
    margin: 48px auto;
    padding: 0 16px;
}

.wide-container {
    max-width: 1280px;
}

.card {
    background: var(--color-surface);
    padding: 32px;
    border-radius: var(--radius-xl);
}

/* Common UI */

.button {
    display: inline-block;
    padding: 10px 16px;
    background: var(--color-text);
    color: var(--color-surface);
    border: 0;
    border-radius: var(--radius-md);
    font: inherit;
    text-decoration: none;
    cursor: pointer;
}

.secondary-button {
    background: #555555;
}

.danger-button {
    background: var(--color-danger);
}

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 16px;
}

.meta {
    color: var(--color-text-muted);
    font-size: 14px;
}

/* Forms */

.form-row {
    margin-bottom: 16px;
}

.form-row label {
    display: block;
    margin-bottom: 8px;
    font-weight: 700;
}

input[type="text"],
input[type="email"],
input[type="password"],
select {
    width: 100%;
    max-width: 420px;
    padding: 10px;
    border: 1px solid #cccccc;
    border-radius: var(--radius-md);
    font: inherit;
}

input[type="file"] {
    display: block;
    padding: 8px 0;
}

/* Tables */

table {
    width: 100%;
    margin-top: 24px;
    border-collapse: collapse;
}

th,
td {
    padding: 12px;
    border-bottom: 1px solid var(--color-border);
    text-align: left;
}

th {
    background: var(--color-surface-muted);
}

/* Code blocks */

pre {
    overflow-x: auto;
    background: var(--color-surface-muted);
    padding: 16px;
    border-radius: var(--radius-md);
}

/* Study */

.prompt {
    font-size: 24px;
    line-height: 1.8;
}

.target {
    display: inline-block;
    padding: 8px 12px;
    background: var(--color-surface-muted);
    border-radius: var(--radius-md);
    font-size: 24px;
    font-weight: 700;
}

.review-badge {
    display: inline-block;
    margin-left: 8px;
    padding: 4px 8px;
    background: var(--color-danger);
    color: var(--color-surface);
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
}

#handwriting-canvas {
    display: block;
    width: 100%;
    max-width: 640px;
    height: 360px;
    background: var(--color-surface);
    border: 2px solid var(--color-text);
    border-radius: var(--radius-md);
    touch-action: none;
}

.handwriting-preview {
    width: 220px;
    max-height: 160px;
    object-fit: contain;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
}

/* Dashboard */

.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 24px;
    margin-bottom: 32px;
}

.dashboard-header h1 {
    margin-bottom: 8px;
}

.dashboard-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 32px;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 16px;
    margin: 24px 0 40px;
}

.stat-card {
    background: var(--color-surface-muted);
    padding: 20px;
    border-radius: var(--radius-lg);
}

.stat-label {
    color: var(--color-text-muted);
    font-size: 14px;
    margin-bottom: 8px;
}

.stat-value {
    font-size: 32px;
    font-weight: 700;
}

.dashboard-section {
    margin-top: 40px;
}

.dashboard-section h2 {
    margin-bottom: 16px;
}

.logout-form {
    margin-top: 24px;
}

/* Heatmap */

.heatmap {
    display: grid;
    grid-template-rows: repeat(7, 12px);
    grid-auto-flow: column;
    grid-auto-columns: 12px;
    gap: 4px;
    width: max-content;
    max-width: 100%;
    overflow-x: auto;
    padding-bottom: 8px;
    margin: 16px 0 8px;
}

.heatmap-cell {
    width: 12px;
    height: 12px;
    border-radius: 3px;
    background: var(--heatmap-0);
}

.heatmap-cell.level-0 {
    background: var(--heatmap-0);
}

.heatmap-cell.level-1 {
    background: var(--heatmap-1);
}

.heatmap-cell.level-2 {
    background: var(--heatmap-2);
}

.heatmap-cell.level-3 {
    background: var(--heatmap-3);
}

.heatmap-cell.level-4 {
    background: var(--heatmap-4);
}

/* Responsive */

@media (max-width: 640px) {
    .dashboard-header {
        display: block;
    }

    .dashboard-header form {
        margin-top: 16px;
    }

    .dashboard-actions {
        display: grid;
        grid-template-columns: 1fr;
    }

    .button {
        text-align: center;
    }
}