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

:root {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-card: #0f3460;
    --accent: #e94560;
    --accent-hover: #ff6b6b;
    --text-primary: #eee;
    --text-secondary: #aaa;
    --success: #4ade80;
    --warning: #fbbf24;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

#app {
    height: 100%;
    max-width: 600px;
    margin: 0 auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
}

.screen {
    display: none;
    flex-direction: column;
    height: 100%;
    animation: fadeIn 0.2s ease;
}

.screen.active {
    display: flex;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

h1 {
    font-size: 2.5rem;
    text-align: center;
    margin-bottom: 2rem;
    color: var(--accent);
}

h2 {
    font-size: 1.5rem;
    text-align: center;
    margin-bottom: 1.5rem;
}

h3 {
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
}

.btn {
    padding: 15px 30px;
    font-size: 1.1rem;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 600;
}

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

.btn-primary:hover, .btn-primary:active {
    background: var(--accent-hover);
}

.btn-secondary {
    background: var(--bg-card);
    color: var(--text-primary);
}

.btn-secondary:hover, .btn-secondary:active {
    background: var(--bg-secondary);
}

.btn-back {
    position: absolute;
    top: 20px;
    left: 20px;
    background: transparent;
    color: var(--text-secondary);
    padding: 10px;
    font-size: 1.5rem;
    line-height: 1;
}

.screen {
    position: relative;
}

.btn-small {
    padding: 8px 15px;
    font-size: 1rem;
}

.btn-large {
    padding: 20px 40px;
    font-size: 1.3rem;
    margin-top: 1rem;
}

.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-bottom: 2rem;
}

.menu-buttons.secondary {
    flex-direction: row;
    justify-content: center;
}

.menu-buttons.secondary .btn {
    flex: 1;
}

.button-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    overflow-y: auto;
    flex: 1;
}

.subset-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 1.5rem;
}

.subset-custom {
    background: var(--bg-secondary);
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 1rem;
}

.target-selectors {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
}

.target-selectors select {
    flex: 1;
    padding: 10px;
    font-size: 1rem;
    background: var(--bg-card);
    color: var(--text-primary);
    border: none;
    border-radius: 4px;
}

.selected-cases {
    max-height: 100px;
    overflow-y: auto;
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

/* Game Screen */
.game-top, .game-bottom {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.game-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 20px;
}

.game-case {
    font-size: 4rem;
    font-weight: 700;
    color: var(--accent);
    text-align: center;
}

.game-alg {
    font-size: 1.2rem;
    color: var(--text-secondary);
    text-align: center;
    max-width: 100%;
    word-wrap: break-word;
    opacity: 0;
    transition: opacity 0.3s;
}

.game-alg.visible {
    opacity: 1;
}

.game-tap-area {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 50vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(to top, var(--bg-secondary) 0%, transparent 100%);
}

.game-tap-area.timing {
    background: linear-gradient(to top, var(--accent) 0%, transparent 100%);
}

.tap-hint {
    color: var(--text-secondary);
    font-size: 1.2rem;
}

.game-tap-area.timing .tap-hint {
    color: white;
}

/* Results Screen */
.session-summary {
    background: var(--bg-secondary);
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 1rem;
    text-align: center;
}

.session-summary .avg {
    font-size: 2rem;
    font-weight: 700;
    color: var(--accent);
}

.results-list {
    flex: 1;
    overflow-y: auto;
    margin-bottom: 1rem;
}

.result-item {
    display: flex;
    justify-content: space-between;
    padding: 10px 15px;
    background: var(--bg-secondary);
    border-radius: 4px;
    margin-bottom: 5px;
}

.result-item .case {
    font-weight: 600;
}

.result-item .time {
    color: var(--text-secondary);
}

.result-item.removable {
    cursor: pointer;
}

.result-item.removed {
    opacity: 0.3;
    text-decoration: line-through;
}

.results-actions {
    display: flex;
    gap: 10px;
}

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

/* Stats Screen */
.global-stats {
    background: var(--bg-secondary);
    padding: 20px;
    border-radius: 8px;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid var(--bg-card);
}

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

.stat-label {
    color: var(--text-secondary);
}

.stat-value {
    font-weight: 600;
}

/* Import Screen */
.import-options {
    text-align: center;
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
}

#import-status {
    color: var(--text-secondary);
}

#import-status.success {
    color: var(--success);
}

#import-status.error {
    color: var(--accent);
}

/* Responsive */
@media (max-width: 400px) {
    #app {
        padding: 15px;
    }

    h1 {
        font-size: 2rem;
    }

    .game-case {
        font-size: 3rem;
    }

    .btn {
        padding: 12px 20px;
    }
}
