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

:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --secondary: #64748b;
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --bg: #0f172a;
    --bg-light: #1e293b;
    --text: #f1f5f9;
    --text-dim: #94a3b8;
}

html {
    width: 100%;
    height: 100%;
    overflow: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;
    position: fixed;
}

.screen {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
}

.screen.active {
    display: flex;
    flex-direction: column;
}

.container {
    display: flex;
    flex-direction: column;
    padding: max(1rem, env(safe-area-inset-top)) 1.5rem max(2rem, env(safe-area-inset-bottom)) 1.5rem;
    max-width: 600px;
    margin: 0 auto;
    width: 100%;
    min-height: 100%;
    box-sizing: border-box;
}

/* Home Screen */
.logo {
    font-size: 3rem;
    font-weight: 800;
    text-align: center;
    margin: 2rem 0 1.5rem 0;
    background: linear-gradient(135deg, #6366f1, #ec4899);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.menu {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* Buttons */
.btn {
    padding: 0.875rem 1.5rem;
    border: none;
    border-radius: 0.75rem;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
}

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

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

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

.btn-secondary {
    background: var(--bg-light);
    color: var(--text);
    border: 2px solid var(--secondary);
}

.btn-large {
    padding: 1.25rem 2rem;
    font-size: 1.25rem;
}

.btn-back {
    background: transparent;
    color: var(--text-dim);
    margin-top: auto;
}

/* Deck Selection */
h2 {
    font-size: 1.75rem;
    margin-bottom: 1rem;
    text-align: center;
}

.deck-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.deck-item {
    background: var(--bg-light);
    padding: 1rem;
    border-radius: 0.75rem;
    border: 2px solid transparent;
    cursor: pointer;
    transition: all 0.2s;
}

.deck-item:hover {
    border-color: var(--primary);
}

.deck-name {
    font-weight: 600;
    font-size: 1.125rem;
    margin-bottom: 0.25rem;
}

.deck-count {
    color: var(--text-dim);
    font-size: 0.875rem;
}

/* Ready Screen */
.instructions {
    background: var(--bg-light);
    padding: 2rem;
    border-radius: 1rem;
    margin: 2rem 0;
}

.instructions p {
    font-size: 1.25rem;
    margin: 1rem 0;
    text-align: center;
}

/* Gameplay Screen */
.game-container {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    background: var(--bg);
}

.timer-bar {
    height: 4rem;
    background: var(--bg-light);
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.timer-fill {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    background: var(--primary);
    transition: width 1s linear, background-color 0.3s;
    width: 100%;
}

.timer-fill.warning {
    background: var(--warning);
}

.timer-text {
    position: relative;
    z-index: 1;
    font-size: 2rem;
    font-weight: 700;
}

.card-display {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.card-text {
    font-size: 3rem;
    font-weight: 700;
    text-align: center;
    line-height: 1.2;
    max-width: 90%;
}

.score-display {
    height: 4rem;
    display: flex;
    justify-content: space-around;
    align-items: center;
    background: var(--bg-light);
    font-size: 1.5rem;
    font-weight: 600;
}

.score-correct {
    color: var(--success);
}

.score-skip {
    color: var(--text-dim);
}

/* Desktop Controls */
.desktop-controls {
    display: none;
    position: fixed;
    bottom: 5rem;
    left: 0;
    right: 0;
    justify-content: center;
    gap: 2rem;
    padding: 1rem;
    z-index: 10;
}

.btn-control {
    padding: 1.5rem 3rem;
    font-size: 1.5rem;
    font-weight: 700;
    border: none;
    border-radius: 1rem;
    cursor: pointer;
    transition: all 0.2s;
    min-width: 150px;
}

.btn-control:active {
    transform: scale(0.95);
}

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

.btn-skip:hover {
    background: var(--text-dim);
}

.btn-correct {
    background: var(--success);
    color: white;
}

.btn-correct:hover {
    background: #16a34a;
}

/* Show desktop controls on non-mobile devices */
@media (hover: hover) and (pointer: fine) {
    .desktop-controls {
        display: flex;
    }
}

/* Summary Screen */
.summary-stats {
    display: flex;
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat {
    flex: 1;
    background: var(--bg-light);
    padding: 1.5rem;
    border-radius: 1rem;
    text-align: center;
}

.stat-label {
    display: block;
    color: var(--text-dim);
    font-size: 0.875rem;
    margin-bottom: 0.5rem;
}

.stat-value {
    display: block;
    font-size: 2.5rem;
    font-weight: 700;
}

.card-results {
    background: var(--bg-light);
    border-radius: 1rem;
    padding: 1rem;
    max-height: 300px;
    overflow-y: auto;
    margin-bottom: 2rem;
}

.result-item {
    display: flex;
    align-items: center;
    padding: 0.75rem;
    border-bottom: 1px solid var(--bg);
}

.result-item:last-child {
    border-bottom: none;
}

.result-icon {
    margin-right: 0.75rem;
    font-size: 1.25rem;
}

.result-card {
    flex: 1;
}

.summary-actions {
    display: flex;
    gap: 1rem;
}

.summary-actions .btn {
    flex: 1;
}

/* Create Deck */
.input, .textarea, .select {
    width: 100%;
    padding: 1rem;
    background: var(--bg-light);
    border: 2px solid var(--secondary);
    border-radius: 0.75rem;
    color: var(--text);
    font-size: 1rem;
    margin-bottom: 1rem;
}

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

.textarea {
    min-height: 300px;
    resize: vertical;
    font-family: inherit;
}

.form-actions {
    display: flex;
    gap: 1rem;
    margin-top: auto;
}

.form-actions .btn {
    flex: 1;
}

/* Manage Decks */
.custom-deck-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 2rem;
}

.custom-deck-item {
    background: var(--bg-light);
    padding: 1rem;
    border-radius: 0.75rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.deck-info {
    flex: 1;
}

.deck-actions {
    display: flex;
    gap: 0.5rem;
}

.btn-small {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

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

/* Settings */
.settings-list {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background: var(--bg-light);
    border-radius: 0.75rem;
}

.setting-item label {
    font-weight: 600;
    font-size: 1.125rem;
}

.toggle {
    width: 3rem;
    height: 1.75rem;
    appearance: none;
    background: var(--secondary);
    border-radius: 1rem;
    position: relative;
    cursor: pointer;
    transition: background 0.2s;
}

.toggle:checked {
    background: var(--success);
}

.toggle::before {
    content: '';
    position: absolute;
    width: 1.25rem;
    height: 1.25rem;
    border-radius: 50%;
    background: white;
    top: 0.25rem;
    left: 0.25rem;
    transition: transform 0.2s;
}

.toggle:checked::before {
    transform: translateX(1.25rem);
}

.select {
    min-width: 150px;
}

/* Sync Section */
.sync-section {
    margin-top: 2rem;
    padding-top: 2rem;
    border-top: 1px solid var(--secondary);
}

.sync-section h3 {
    font-size: 1.25rem;
    margin-bottom: 0.75rem;
}

.sync-description {
    color: var(--text-dim);
    font-size: 0.875rem;
    margin-bottom: 1rem;
}

.sync-link-container {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.sync-link-input {
    flex: 1;
    font-size: 0.875rem;
    font-family: monospace;
    margin-bottom: 0;
}

.sync-hint {
    color: var(--text-dim);
    font-size: 0.75rem;
    font-style: italic;
}

/* Landscape Mode for Gameplay */
@media (orientation: landscape) {
    .card-text {
        font-size: 4rem;
    }
}

/* Mobile Optimizations */
@media (max-width: 640px) {
    .logo {
        font-size: 2.5rem;
    }

    .card-text {
        font-size: 2.5rem;
    }
}
