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

:root {
    font-size: 16px;

    /* Safe area insets */
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);

    /* Focus ring */
    --focus-ring: 0 0 0 3px rgba(91, 140, 255, 0.5);

    /* Dark theme (default) */
    --bg-primary: #14161C;
    --bg-secondary: #1E212B;
    --bg-card: #2A2E3A;
    --bg-card-hover: #363b4a;
    --accent: #5B8CFF;
    --accent-button: #5B8CFF;
    --accent-hover: #7BA3FF;
    --accent-on: #020a1f;
    --text-primary: #E8E9ED;
    --text-secondary: #a0a6b8;
    --text-heading: #fff;

    /* Category colors - dark */
    --cat-border: #9ca3af;
    --cat-szybkie-text: #4ADE80;
    --cat-szybkie-bg: #0B2A18;
    --cat-srednie-text: #a0a6b8;
    --cat-srednie-bg: #262A33;
    --cat-wolne-text: #FBBF24;
    --cat-wolne-bg: #1F1A08;
    --cat-niestabilne-text: #FB923C;
    --cat-niestabilne-bg: #241407;
    --cat-regres-text: #F87171;
    --cat-regres-bg: #2A1010;
    --cat-nowe-text: #8fb0ff;
    --cat-nowe-bg: #0E1A33;
    --cat-trudne-text: #a0a6b8;
    --cat-trudne-bg: #262A33;
    --cat-weak-text: #F87171;
    --cat-weak-bg: #2A1010;
    --cat-maintain-text: #4ADE80;
    --cat-maintain-bg: #0B2A18;

    /* Legacy mappings */
    --success: #4ADE80;
    --success-text: #14161C;
    --warning: #FBBF24;
    --link: #5B8CFF;
}

[data-theme="light"] {
    --bg-primary: #F7F8FA;
    --bg-secondary: #FFFFFF;
    --bg-card: #EDEFF3;
    --bg-card-hover: #E5E7EB;
    --accent: #5B8CFF;
    --accent-button: #2a53ad;
    --accent-hover: #2A56B8;
    --accent-on: #FFFFFF;
    --text-primary: #14161C;
    --text-secondary: #5A5F6E;
    --text-heading: #14161C;

    /* Category colors - light */
    --cat-border: #5a6270;
    --cat-szybkie-text: #27500A;
    --cat-szybkie-bg: #E8FBEF;
    --cat-srednie-text: #5A5F6E;
    --cat-srednie-bg: #EEF0F3;
    --cat-wolne-text: #633806;
    --cat-wolne-bg: #FEF6E0;
    --cat-niestabilne-text: #712B13;
    --cat-niestabilne-bg: #FEEEE0;
    --cat-regres-text: #791F1F;
    --cat-regres-bg: #FDEAEA;
    --cat-nowe-text: #0C447C;
    --cat-nowe-bg: #E9EFFC;
    --cat-trudne-text: #5A5F6E;
    --cat-trudne-bg: #EEF0F3;
    --cat-weak-text: #791F1F;
    --cat-weak-bg: #FDEAEA;
    --cat-maintain-text: #27500A;
    --cat-maintain-bg: #E8FBEF;

    /* Legacy mappings */
    --success: #22C55E;
    --success-text: #FFFFFF;
    --warning: #F59E0B;
    --link: #5B8CFF;
}

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;
    transition: background-color 0.3s, color 0.3s;
}

#app {
    height: 100%;
    max-width: 37.5rem;
    margin: 0 auto;
    padding: calc(0.75rem + var(--safe-top)) calc(0.75rem + var(--safe-right)) calc(0.75rem + var(--safe-bottom)) calc(0.75rem + var(--safe-left));
    display: flex;
    flex-direction: column;
}

#game-screen {
    padding: 0;
    margin: calc(-0.75rem - var(--safe-top)) calc(-0.75rem - var(--safe-right)) calc(-0.75rem - var(--safe-bottom)) calc(-0.75rem - var(--safe-left));
    width: calc(100% + 1.5rem + var(--safe-left) + var(--safe-right));
    height: calc(100% + 1.5rem + var(--safe-top) + var(--safe-bottom));
}

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

.screen.active {
    display: flex;
}

#subset-screen {
    overflow-y: auto;
}

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

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

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);
}

/* Theme Toggle */
.theme-toggle {
    position: absolute;
    top: 0;
    right: 0;
    background: var(--bg-secondary);
    border: none;
    color: var(--text-secondary);
    padding: 0.5rem;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.375rem;
    line-height: 1;
    width: 2.75rem;
    height: 2.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s, color 0.2s;
    z-index: 10;
}

.theme-toggle:hover {
    background: var(--bg-card);
    color: var(--text-primary);
}

.theme-toggle:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

.theme-toggle .icon-sun {
    display: block;
}

.theme-toggle .icon-moon {
    display: none;
}

[data-theme="light"] .theme-toggle .icon-sun {
    display: none;
}

[data-theme="light"] .theme-toggle .icon-moon {
    display: block;
}

.version {
    position: absolute;
    bottom: 0.5rem;
    left: 0;
    right: 0;
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-secondary);
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.version a {
    color: var(--link);
    text-decoration: none;
}

.version a:hover {
    text-decoration: underline;
}

.copyright {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.gh-icon {
    vertical-align: middle;
    opacity: 0.8;
}

.gh-icon:hover {
    opacity: 1;
}

.btn {
    padding: 0.9375rem 1.875rem;
    font-size: 1.1rem;
    border: none;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 600;
}

.btn:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

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

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

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

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


/* Logo Button (Home) */
.btn-logo {
    display: block;
    width: 100%;
    background: transparent;
    border: none;
    color: var(--text-heading);
    font-size: 1.5rem;
    font-weight: 700;
    padding: 0.5rem;
    margin-bottom: 0.5rem;
    cursor: pointer;
    text-align: center;
    transition: all 0.2s;
}

.btn-logo:hover, .btn-logo:active {
    color: var(--text-secondary);
    transform: scale(1.02);
}

.btn-logo:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

.btn-logo-small {
    font-size: 1rem;
    padding: 0.5rem 1rem;
    margin-bottom: 0;
    text-align: left;
    width: auto;
}

.btn-back {
    margin-top: 1.5rem;
    width: 100%;
}

@media (max-width: 600px) {
    .btn-back {
        display: none;
    }

    .missing-algs-list {
        grid-template-columns: repeat(5, 1fr);
    }
}


.btn-small {
    padding: 0.75rem 1rem;
    font-size: 1rem;
    min-height: 3rem;
}

#btn-pause {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 0;
    font-size: 1rem;
    min-width: 2.75rem;
    min-height: 2.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.target-selectors .btn-small {
    background: var(--accent);
    color: white;
    width: 3rem;
    height: 3rem;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-large {
    padding: 1.25rem 2.5rem;
    font-size: 1.3rem;
    margin-top: 1rem;
}

.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.9375rem;
    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: 0.625rem;
    overflow-y: auto;
    flex: 1;
}

.btn-all {
    width: 100%;
    margin-bottom: 0.75rem;
    font-size: 1.3rem;
}

.subset-modes {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.btn-mode {
    padding: 0.75rem;
    font-size: 1rem;
    font-weight: 600;
    min-height: 3rem;
    text-align: center;
    border-radius: 0.375rem;
}

.btn-danger {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--cat-border);
}

.btn-success {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--cat-border);
}

.btn-warning {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--cat-border);
}

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

.subset-buttons .btn {
    padding: 0.75rem 0.5rem;
    font-size: 1rem;
    min-height: 3rem;
}

#btn-fast,
#btn-average,
#btn-slow,
#btn-unstable,
#btn-regressing,
#btn-difficult {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--cat-border);
}

.inversion-toggle {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--bg-card);
}

.inversion-toggle label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.inversion-toggle input[type="checkbox"] {
    width: 1.5rem;
    height: 1.5rem;
    accent-color: var(--accent);
}

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

.subset-custom h3 {
    margin-bottom: 0.75rem;
}

.target-selectors {
    display: flex;
    gap: 1.5rem;
    margin-bottom: 0.625rem;
    justify-content: center;
}

.target-selectors select {
    width: 5.5rem;
    padding: 0.75rem 1.5rem 0.75rem 0.5rem;
    font-size: 1rem;
    background: var(--bg-card);
    color: var(--text-primary);
    border: none;
    border-radius: 0.25rem;
    min-height: 3rem;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23888' d='M2 4l4 4 4-4'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.5rem center;
    cursor: pointer;
    text-align: center;
    text-indent: -0.5rem;
}

.target-selectors select:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

.selected-cases-row {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
}

.selected-cases {
    flex: 1;
    max-height: 8rem;
    overflow-y: auto;
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.6;
    text-align: center;
}

.btn-reset {
    flex-shrink: 0;
    height: 3rem;
    padding: 0 1rem;
    font-size: 0.9rem;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 0.5rem;
    font-weight: 600;
    cursor: pointer;
}

.selected-preview {
    font-size: 0.8rem;
    margin-top: 0.25rem;
    word-break: break-word;
}

/* Pause Setting */
.pause-setting {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.pause-setting select {
    padding: 0.5rem 2rem 0.5rem 0.75rem;
    font-size: 0.9rem;
    background: var(--bg-card);
    color: var(--text-primary);
    border: none;
    border-radius: 0.25rem;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23888' d='M2 4l4 4 4-4'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.5rem center;
    cursor: pointer;
}

.pause-setting select:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

/* Game Screen */
.game-top {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 1rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
    position: relative;
    z-index: 10;
}

.game-timer {
    font-size: 3rem;
    font-weight: 700;
    color: var(--text-heading);
    text-align: center;
    text-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

[data-theme="light"] .game-timer {
    text-shadow: none;
}

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

.game-case {
    font-size: 4rem;
    font-weight: 700;
    color: var(--text-heading);
    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-next-preview {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--text-secondary);
    text-align: center;
    opacity: 0;
    transition: opacity 0.3s;
    margin-top: 1rem;
}

.game-next-preview.visible {
    opacity: 1;
}

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

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

#game-screen.timing {
    background: var(--bg-secondary);
}

#game-screen.timing .game-case {
    color: var(--text-primary);
}

.pause-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-primary);
    z-index: 100;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3rem;
}

.pause-overlay.active {
    display: flex;
    animation: fadeIn 0.2s ease;
}

.pause-menu {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3rem;
    width: 100%;
    max-width: 20rem;
    padding: 2rem;
}

.pause-icon {
    color: var(--accent);
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.pause-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    width: 100%;
}

.pause-buttons .btn {
    width: 100%;
}

.pause-buttons .btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

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

.results-header {
    display: flex;
    justify-content: space-between;
    padding: 0.625rem 0.9375rem;
    background: var(--bg-card);
    border-radius: 0.25rem;
    margin-bottom: 0.3125rem;
}

.sort-btn {
    cursor: pointer;
    color: var(--text-secondary);
    user-select: none;
    transition: color 0.2s;
}

.sort-btn:hover {
    color: var(--text-primary);
}

.sort-btn:focus-visible {
    outline: none;
    text-decoration: underline;
}

.sort-btn.active {
    color: var(--accent);
    font-weight: 600;
}

.sort-arrow {
    display: inline-block;
    width: 1em;
}

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

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

.result-item {
    display: flex;
    justify-content: space-between;
    padding: 0.625rem 0.9375rem;
    background: var(--bg-secondary);
    border-radius: 0.25rem;
    margin-bottom: 0.3125rem;
}

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

.result-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.result-item .time {
    color: var(--text-secondary);
    min-width: 3.5rem;
    text-align: right;
}

.btn-difficult-toggle,
.btn-remove-result {
    background: var(--bg-card);
    border: none;
    color: var(--text-secondary);
    width: 1.75rem;
    height: 1.75rem;
    border-radius: 0.25rem;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.btn-difficult-toggle:hover {
    background: var(--warning);
    color: white;
}

.btn-difficult-toggle.active {
    background: var(--warning);
    color: white;
}

.btn-remove-result:hover {
    background: var(--accent);
    color: white;
}

.result-item.removed {
    opacity: 0.3;
}

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

.results-actions {
    display: flex;
    gap: 0.625rem;
}

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

/* Stats Screen */
.stats-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.stats-tabs {
    display: flex;
    gap: 0.25rem;
    margin-bottom: 1rem;
    background: var(--bg-secondary);
    padding: 0.25rem;
    border-radius: 0.5rem;
}

.stats-tab {
    flex: 1;
    padding: 0.625rem;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    border-radius: 0.375rem;
    transition: all 0.2s;
}

.stats-tab:hover {
    color: var(--text-primary);
}

.stats-tab.active {
    background: var(--accent);
    color: white;
}

.stats-panel {
    flex: 1;
    overflow-y: auto;
}

.stats-section {
    background: var(--bg-secondary);
    padding: 1rem;
    border-radius: 0.5rem;
    margin-bottom: 0.75rem;
}

.stats-section h3 {
    font-size: 1rem;
    color: var(--text-heading);
    margin-bottom: 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--bg-card);
}

.global-stats {
    background: var(--bg-secondary);
    padding: 1.25rem;
    border-radius: 0.5rem;
}

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

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

.daily-stats {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--bg-card);
}

.daily-table {
    width: 100%;
    margin-top: 0.5rem;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.daily-table th,
.daily-table td {
    padding: 0.4rem 0.5rem;
    text-align: left;
}

.daily-table th {
    color: var(--text-secondary);
    font-weight: 500;
}

.daily-table tr:not(:last-child) {
    border-bottom: 1px solid var(--bg-card);
}

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

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

.stat-cases {
    font-size: 0.85rem;
    color: var(--text-secondary);
    padding: 0.5rem 0;
    line-height: 1.5;
}

.stat-categories,
.stat-trends {
    padding: 0.5rem 0;
}

.cat-badges {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.375rem;
    margin-top: 0.25rem;
}

.trend-badges {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.375rem;
    margin-top: 0.25rem;
}

.cat-badge,
.trend-badge {
    font-size: 0.85rem;
    padding: 0.5rem 0.75rem;
    border-radius: 0.25rem;
    background: var(--bg-card);
    color: var(--text-primary);
    min-height: 2.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.cat-badge.cat-weak,
.cat-badge.cat-maintain,
.cat-badge.cat-new,
.cat-badge.cat-fast,
.cat-badge.cat-average,
.cat-badge.cat-slow,
.cat-badge.cat-unstable,
.cat-badge.cat-regressing,
.cat-badge.cat-difficult {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--cat-border);
}

.cat-badge[data-filter-cat] {
    transition: transform 0.1s, box-shadow 0.1s;
}

.cat-badge[data-filter-cat]:hover {
    transform: scale(1.05);
}

.cat-badge[data-filter-cat].active {
    box-shadow: 0 0 0 2px white, 0 0 0 4px var(--accent);
}

.trend-badge[data-filter-trend] {
    transition: transform 0.1s, box-shadow 0.1s;
}

.trend-badge[data-filter-trend]:hover {
    transform: scale(1.05);
}

.trend-badge[data-filter-trend].active {
    box-shadow: 0 0 0 2px white, 0 0 0 4px var(--accent);
}

.trend-improving,
.trend-stable,
.trend-declining {
    color: inherit;
}

.cases-details {
    margin-top: 0.75rem;
    border-top: 1px solid var(--bg-card);
    padding-top: 0.75rem;
}

.cases-header {
    color: var(--text-heading);
    font-weight: 600;
    padding: 0.5rem 0;
}

.cases-table-wrapper {
    overflow-x: auto;
    margin-top: 0.5rem;
}

.cases-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
}

.cases-table th,
.cases-table td {
    padding: 0.4rem 0.3rem;
    text-align: center;
    border-bottom: 1px solid var(--bg-card);
}

.cases-table th {
    background: var(--bg-card);
    color: var(--text-secondary);
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}

.cases-table th:hover {
    color: var(--accent);
}

.cases-table th.sort-asc::after {
    content: ' ↑';
    font-size: 0.7rem;
}

.cases-table th.sort-desc::after {
    content: ' ↓';
    font-size: 0.7rem;
}

.cases-table td.case-name {
    text-align: left;
    font-weight: 600;
}

.cases-table td.case-avg {
    font-weight: 600;
}

.case-row.cat-fast { background: var(--cat-szybkie-bg); color: var(--cat-szybkie-text); }
.case-row.cat-slow { background: var(--cat-wolne-bg); color: var(--cat-wolne-text); }
.case-row.cat-unstable { background: var(--cat-niestabilne-bg); color: var(--cat-niestabilne-text); }
.case-row.cat-new { background: var(--cat-nowe-bg); color: var(--cat-nowe-text); }
.case-row.cat-regressing { background: var(--cat-regres-bg); color: var(--cat-regres-text); }

.text-muted {
    color: var(--text-secondary);
    font-style: italic;
}

/* Missing algorithms */
.missing-algs {
    margin-top: 1rem;
    border-top: 1px solid var(--bg-card);
    padding-top: 0.75rem;
}

.missing-algs-list {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 0.4rem;
    margin-top: 0.5rem;
}

.missing-alg-item {
    background: var(--bg-card);
    padding: 0.3rem 0.6rem;
    border-radius: 0.25rem;
    font-size: 0.85rem;
    cursor: pointer;
    color: var(--text-secondary);
    border: 1px solid var(--text-secondary);
    transition: all 0.15s;
    text-align: center;
}

.missing-alg-item:hover {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 100;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--bg-secondary);
    border-radius: 0.5rem;
    padding: 1.25rem;
    width: 100%;
    max-width: 24rem;
    max-height: 80vh;
    overflow-y: auto;
    margin-bottom: 7rem;
}

@media (max-width: 600px) {
    .modal-content {
        margin-bottom: 10rem;
    }
}

.modal-content h3 {
    color: var(--text-heading);
    margin-bottom: 1rem;
    text-align: center;
}

.modal-case {
    font-size: 1.5rem;
    font-weight: 700;
    text-align: center;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.modal-content textarea {
    width: 100%;
    padding: 0.75rem;
    font-size: 1rem;
    font-family: monospace;
    background: var(--bg-card);
    color: var(--text-primary);
    border: 2px solid transparent;
    border-radius: 0.375rem;
    resize: vertical;
    min-height: 4rem;
}

.modal-content textarea:focus {
    outline: none;
    border-color: var(--accent);
}

.checkbox-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.75rem;
    cursor: pointer;
    color: var(--text-primary);
}

.checkbox-row input[type="checkbox"] {
    width: 1.5rem;
    height: 1.5rem;
    accent-color: var(--accent);
    cursor: pointer;
}

.modal-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
}

.export-options {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.export-options .btn {
    width: 100%;
}

.export-desc {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin: 0 0 1rem 0;
    text-align: center;
}

.modal-actions .btn {
    flex: 1;
    font-size: 0.875rem;
    padding: 0.75rem 1rem;
    min-height: 3rem;
}

/* Clickable case row */
.case-row {
    cursor: pointer;
    transition: background 0.2s;
}

.case-row:hover {
    background: var(--bg-card);
}

/* Edit button in results */
.btn-edit-alg {
    background: var(--bg-card);
    border: none;
    color: var(--text-secondary);
    width: 1.75rem;
    height: 1.75rem;
    border-radius: 0.25rem;
    cursor: pointer;
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.btn-edit-alg:hover {
    background: var(--accent);
    color: white;
}

/* Help button */
.btn-help {
    position: absolute;
    bottom: 2.5rem;
    right: 0;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    width: 2.75rem;
    height: 2.75rem;
    padding: 0;
    font-size: 1.25rem;
    font-weight: 700;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-help:hover {
    background: var(--bg-card);
    color: var(--accent);
}

/* Help modal */
.modal-help {
    max-height: 85vh;
    position: relative;
}

.modal-help .btn {
    margin-top: 1rem;
}

.modal-close-x {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    line-height: 1;
    width: 2.75rem;
    height: 2.75rem;
    padding: 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 0.25rem;
    transition: color 0.2s, background 0.2s;
}

.modal-close-x:hover {
    color: var(--text-primary);
    background: var(--bg-card);
}

.modal-close-x:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

.help-content {
    max-height: 60vh;
    overflow-y: auto;
    text-align: left;
    font-size: 0.9rem;
    line-height: 1.5;
}

.help-content:focus {
    outline: none;
}

.help-content:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 0.25rem;
}

.help-content section {
    margin-bottom: 1.25rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--bg-card);
}

.help-content section:last-child {
    border-bottom: none;
    margin-bottom: 0;
}

.help-content h4 {
    color: var(--accent);
    margin-bottom: 0.5rem;
    font-size: 1rem;
}

.help-content p {
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.help-content ul,
.help-content ol {
    margin: 0.5rem 0;
    padding-left: 1.25rem;
}

.help-content li {
    margin-bottom: 0.25rem;
}

.help-content code {
    background: var(--bg-card);
    padding: 0.1rem 0.3rem;
    border-radius: 0.2rem;
    font-size: 0.85rem;
}

.help-content pre {
    background: var(--bg-card);
    padding: 0.5rem;
    border-radius: 0.25rem;
    font-size: 0.8rem;
    overflow-x: auto;
    margin: 0.5rem 0;
}

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

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

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

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

/* Responsive */
@media (max-width: 25rem) {
    #app {
        padding: 0.9375rem;
    }

    h1 {
        font-size: 2rem;
    }

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

    .btn {
        padding: 0.75rem 1.25rem;
    }
}

/* Flashcard Screen */
.start-buttons {
    display: flex;
    gap: 0.75rem;
    margin-top: 1rem;
}

.start-buttons .btn {
    flex: 1;
}

.flashcard-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 1rem;
    padding: 0 0.5rem;
}

.flashcard-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2rem;
}

.flashcard-case {
    font-size: 5rem;
    font-weight: 700;
    color: var(--text-heading);
    text-align: center;
}

.flashcard-alg {
    font-size: 1.5rem;
    font-family: monospace;
    color: var(--text-primary);
    text-align: center;
    padding: 1rem;
    min-height: 3rem;
    opacity: 0;
    transition: opacity 0.3s;
}

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

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

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

.flashcard-tap-area.hidden {
    display: none;
}

.flashcard-buttons {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 30rem;
    display: flex;
    gap: 0.75rem;
    padding: 1.5rem;
    padding-bottom: calc(1.5rem + var(--safe-bottom));
    background: var(--bg-secondary);
}

.flashcard-buttons.hidden {
    display: none;
}

.flashcard-buttons .btn {
    flex: 1;
    padding: 1.25rem;
    font-size: 1.1rem;
}

.flashcard-actions {
    display: flex;
    gap: 1rem;
    margin-top: 0.5rem;
}

.btn-flashcard-edit {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1.25rem;
    cursor: pointer;
    padding: 0;
    min-width: 2.75rem;
    min-height: 2.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-flashcard-edit:hover {
    color: var(--accent);
}

@media (max-width: 25rem) {
    .flashcard-case {
        font-size: 3.5rem;
    }

    .flashcard-alg {
        font-size: 1.2rem;
    }
}
