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

:root {
    --bg: #0f1117;
    --surface: #1a1d27;
    --surface2: #242836;
    --border: #2e3344;
    --text: #e1e4ed;
    --text-muted: #8b90a0;
    --primary: #6c63ff;
    --primary-hover: #5a52e0;
    --secondary: #3a3f52;
    --secondary-hover: #4a5068;
    --danger: #e05555;
    --danger-hover: #c94444;
    --success: #4caf7d;
    --warning: #e0a050;
    --accent: #63b3ed;
    --radius: 8px;
    --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
    --mono: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

.container {
    max-width: 720px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

header {
    text-align: center;
    margin-bottom: 2rem;
}

.site-title {
    font-size: 3rem;
    font-weight: 800;
    letter-spacing: 0.05em;
}

.site-title a {
    color: var(--primary);
    text-decoration: none;
}

main {
    flex: 1;
}

footer {
    text-align: center;
    margin-top: 3rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
}

.footer-text {
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* Flash messages */
.flash-messages {
    margin-bottom: 1.5rem;
}

.flash {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}

.flash-error { background: rgba(224, 85, 85, 0.15); border: 1px solid var(--danger); color: #f08080; }
.flash-success { background: rgba(76, 175, 125, 0.15); border: 1px solid var(--success); color: #6fcf97; }
.flash-info { background: rgba(99, 179, 237, 0.15); border: 1px solid var(--accent); color: var(--accent); }
.flash-warning { background: rgba(224, 160, 80, 0.15); border: 1px solid var(--warning); color: var(--warning); }

/* Buttons */
.btn {
    display: inline-block;
    padding: 0.65rem 1.5rem;
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    text-decoration: none;
    text-align: center;
    transition: background 0.2s, transform 0.1s;
}

.btn:active { transform: scale(0.97); }

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

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

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); }

.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #3d9e6d; }

.btn-lg { padding: 0.85rem 2.5rem; font-size: 1.15rem; }

.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.home-hero {
    text-align: center;
    padding: 3rem 0;
}

.home-buttons {
    display: flex;
    gap: 1.5rem;
    justify-content: center;
    flex-wrap: wrap;
}

.welcome-text {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
    color: var(--success);
}

.welcome-user {
    font-size: 1.1rem;
    margin-bottom: 1.5rem;
    color: var(--text-muted);
}

/* Step pages */
.step-header {
    margin-bottom: 1.5rem;
}

.step-header h2 {
    font-size: 1.5rem;
    margin-bottom: 0.25rem;
}

.step-header .step-number {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.step-description {
    color: var(--text-muted);
    margin-bottom: 1.5rem;
    line-height: 1.7;
}

/* Forms */
.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.35rem;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text);
}

.form-group .hint {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 0.35rem;
}

input[type="text"],
input[type="email"],
input[type="tel"],
input[type="password"],
input[type="number"],
textarea,
select {
    width: 100%;
    padding: 0.6rem 0.8rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.95rem;
    font-family: var(--font);
    transition: border-color 0.2s;
}

input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--primary);
}

textarea {
    resize: vertical;
    font-family: var(--mono);
    min-height: 100px;
}

select {
    cursor: pointer;
}

.form-row {
    display: flex;
    gap: 1rem;
}

.form-row .form-group {
    flex: 1;
}

.form-actions {
    margin-top: 2rem;
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
}

/* Checkbox */
.checkbox-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 1rem 0;
}

.checkbox-group input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
}

/* Code editor */
.code-editor {
    background: #1e1e2e;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    font-family: var(--mono);
    font-size: 0.85rem;
    line-height: 1.5;
    overflow-x: auto;
    white-space: pre;
}

textarea.code-textarea {
    font-family: var(--mono);
    font-size: 0.85rem;
    line-height: 1.5;
    min-height: 300px;
    background: #1e1e2e;
    tab-size: 4;
}

/* Grid for 15x15 */
.color-grid {
    display: grid;
    grid-template-columns: repeat(15, 1fr);
    gap: 2px;
    max-width: 500px;
    margin: 1.5rem auto;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    padding: 4px;
    background: var(--surface);
}

.color-grid .cell {
    aspect-ratio: 1;
    border-radius: 3px;
    cursor: pointer;
    border: 2px solid transparent;
    transition: border-color 0.15s, transform 0.1s;
}

.color-grid .cell:hover { transform: scale(1.1); z-index: 1; }
.color-grid .cell.selected { border-color: #fff; box-shadow: 0 0 8px rgba(255,255,255,0.5); transform: scale(1.15); }

/* Rhythm */
.rhythm-container {
    text-align: center;
    padding: 2rem;
}

.rhythm-timer {
    font-size: 4rem;
    font-weight: 800;
    color: var(--primary);
    margin: 1rem 0;
    font-variant-numeric: tabular-nums;
}

.rhythm-bar {
    width: 100%;
    height: 24px;
    background: var(--surface);
    border-radius: 12px;
    overflow: hidden;
    margin: 1rem 0;
}

.rhythm-bar-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 12px;
    transition: width 0.1s linear;
}

.rhythm-status {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
}

.rhythm-attempt {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    margin: 0 4px;
    background: var(--border);
}

.rhythm-attempt.done { background: var(--success); }
.rhythm-attempt.active { background: var(--primary); box-shadow: 0 0 8px var(--primary); }
.rhythm-attempt.fail { background: var(--danger); }

.spacebar-indicator {
    font-size: 1.2rem;
    padding: 1rem;
    margin: 1rem auto;
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    max-width: 300px;
    transition: background 0.1s, border-color 0.1s;
}

.spacebar-indicator.pressed {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

/* Preferences columns */
.preferences-table {
    width: 100%;
    border-collapse: collapse;
}

.preferences-table tr {
    border-bottom: 1px solid var(--border);
}

.preferences-table td {
    padding: 0.6rem 0.5rem;
    text-align: center;
}

.preferences-table .pref-item {
    padding: 0.5rem 1rem;
    cursor: pointer;
    border-radius: var(--radius);
    border: 2px solid transparent;
    transition: background 0.15s, border-color 0.15s;
    user-select: none;
}

.preferences-table .pref-item:hover {
    background: var(--surface2);
}

.preferences-table .pref-item.chosen {
    border-color: var(--primary);
    background: rgba(108, 99, 255, 0.15);
}

.preferences-table .vs-cell {
    color: var(--text-muted);
    font-size: 0.8rem;
    font-weight: 600;
}

/* Camera */
.camera-wrapper {
    text-align: center;
    margin: 1.5rem 0;
}

.camera-wrapper video {
    max-width: 100%;
    border-radius: var(--radius);
    border: 2px solid var(--border);
}

.camera-wrapper canvas {
    display: none;
}

.captured-preview {
    max-width: 300px;
    border-radius: var(--radius);
    border: 2px solid var(--success);
    margin: 0.5rem auto;
}

/* Emoji display */
.emoji-codes-list {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    max-height: 400px;
    overflow-y: auto;
    font-size: 1.3rem;
    line-height: 2;
}

.emoji-codes-list .emoji-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.emoji-codes-list .emoji-index {
    color: var(--text-muted);
    font-size: 0.8rem;
    min-width: 2rem;
    text-align: right;
}

/* QR display */
.qr-display {
    text-align: center;
    margin: 1.5rem 0;
}

.qr-display img {
    max-width: 250px;
    border-radius: var(--radius);
    border: 2px solid var(--border);
}

/* Emoji input */
.emoji-input-wrapper {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
}

.emoji-input-wrapper input {
    font-size: 1.5rem;
    text-align: center;
    width: 3.5rem;
    padding: 0.5rem;
}

/* Progress bar for steps */
.progress-bar {
    display: flex;
    gap: 4px;
    margin-bottom: 2rem;
}

.progress-bar .step-dot {
    flex: 1;
    height: 4px;
    border-radius: 2px;
    background: var(--border);
}

.progress-bar .step-dot.completed { background: var(--success); }
.progress-bar .step-dot.current { background: var(--primary); }

/* Section separator */
.section-sep {
    border: none;
    border-top: 1px solid var(--border);
    margin: 2rem 0;
}

/* Upload area */
.upload-area {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 2rem;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s;
    margin: 1rem 0;
}

.upload-area:hover {
    border-color: var(--primary);
}

.upload-area input[type="file"] {
    display: none;
}

/* Responsive */
@media (max-width: 600px) {
    .container { padding: 1rem; }
    .site-title { font-size: 2.2rem; }
    .form-row { flex-direction: column; gap: 0; }
    .color-grid { max-width: 100%; }
}
