/* ==================================================
   1. Design tokens
   ================================================== */

:root {
    --background: #f4f2ed;
    --surface: #ffffff;
    --text: #1d1d1b;
    --muted-text: #65655f;
    --border: #d7d5ce;
    --accent: #222222;
    --accent-hover: #444444;
    --focus: #1f6feb;
}


/* ==================================================
   2. Reset and base styles
   ================================================== */

* {
    box-sizing: border-box;
}

body {
    min-height: 100vh;
    margin: 0;

    color: var(--text);
    background: var(--background);

    font-family: Inter, Arial, Helvetica, sans-serif;
}

button,
input,
select {
    font: inherit;
}

button {
    cursor: pointer;
}

h1,
h2 {
    margin-top: 0;
}

h1 {
    margin-bottom: 16px;
    font-size: clamp(2.5rem, 7vw, 4.5rem);
    line-height: 1;
}

h2 {
    margin-bottom: 12px;
    font-size: clamp(2rem, 5vw, 3rem);
}


/* ==================================================
   3. Shared layout and utilities
   ================================================== */

.app-container {
    width: min(100% - 32px, 1000px);
    margin: 0 auto;
    padding: 64px 0;
}

.screen {
    display: none;
}

.screen.active {
    display: block;
}

.hidden {
    display: none !important;
}

.app-header {
    max-width: 650px;
    margin-bottom: 40px;
}

.eyebrow {
    margin: 0 0 10px;

    color: var(--muted-text);

    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.intro,
#selection-description {
    margin: 0;

    color: var(--muted-text);

    font-size: 1.1rem;
    line-height: 1.6;
}


/* ==================================================
   4. Buttons
   ================================================== */

.primary-button {
    padding: 12px 18px;

    color: white;
    background: var(--accent);
    border: 0;
    border-radius: 10px;

    font-weight: 700;
}

.primary-button:hover:not(:disabled) {
    background: var(--accent-hover);
}

.primary-button:disabled,
.secondary-button:disabled {
    cursor: not-allowed;
    opacity: 0.4;
}

.secondary-button {
    padding: 0.75rem 1.1rem;

    color: var(--accent);
    background: transparent;
    border: 2px solid var(--accent);
    border-radius: 10px;

    font-weight: 700;

    transition:
        background-color 0.2s ease,
        color 0.2s ease,
        transform 0.2s ease;
}

.secondary-button:hover:not(:disabled) {
    color: white;
    background: var(--accent);
}

.secondary-button:active:not(:disabled) {
    transform: translateY(1px);
}

.text-button {
    margin-bottom: 40px;
    padding: 0;

    color: var(--text);
    background: transparent;
    border: 0;

    font-weight: 600;
}

.text-button:hover {
    text-decoration: underline;
}

.mode-card:focus-visible,
.text-button:focus-visible,
.primary-button:focus-visible,
.secondary-button:focus-visible,
.level-filter-button:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 4px;
}


/* ==================================================
   5. Home screen
   ================================================== */

.mode-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 20px;
}

.mode-card {
    display: flex;
    min-height: 260px;
    padding: 28px;

    flex-direction: column;
    align-items: flex-start;
    gap: 16px;

    color: var(--text);
    text-align: left;

    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 18px;

    transition:
        transform 160ms ease,
        border-color 160ms ease;
}

.mode-card:hover {
    border-color: var(--text);
    transform: translateY(-4px);
}

.mode-label {
    padding: 6px 10px;

    background: var(--background);
    border-radius: 999px;

    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.mode-title {
    margin-top: auto;

    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1.2;
}

.mode-description {
    color: var(--muted-text);
    line-height: 1.5;
}


/* ==================================================
   6. Trick selection screen
   ================================================== */

.selection-header {
    max-width: 700px;
    margin-bottom: 30px;
}

.selection-actions,
.level-filter {
    margin-bottom: 1.5rem;
}

.selection-status {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;

    margin-bottom: 20px;
    padding: 16px 20px;

    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
}

.selection-status p {
    margin: 0;
}

#selection-counter {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 20px;
}

.level-filter-label {
    margin-bottom: 0.75rem;
    font-weight: 700;
}

.level-filter-options {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.level-filter-button {
    padding: 8px 12px;

    background: var(--surface);
    border: 1px solid #cfcfcf;
    border-radius: 999px;

    font-weight: 600;
}

.level-filter-button:hover {
    border-color: #777;
}

.level-filter-button.active {
    color: white;
    background: var(--accent);
    border-color: var(--accent);
}


/* ==================================================
   7. Trick table
   ================================================== */

.table-container {
    overflow-x: auto;

    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
}

.trick-table {
    width: 100%;
    border-collapse: collapse;
}

.trick-table th,
.trick-table td {
    padding: 14px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.trick-table th {
    color: var(--muted-text);
    background: #f8f7f3;

    font-size: 0.75rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.trick-table tbody tr:last-child td {
    border-bottom: 0;
}

.trick-table th:first-child,
.trick-table td:first-child {
    width: 80px;
    text-align: center;
}

.trick-table th:nth-child(2),
.trick-table td:nth-child(2),
.trick-table th:nth-child(3),
.trick-table td:nth-child(3),
.trick-table th:last-child,
.trick-table td:last-child {
    width: 90px;
    text-align: center;
}

.trick-row {
    cursor: pointer;
    user-select: none;
    transition: background-color 0.15s ease;
}

.trick-row:hover {
    background: #f5f8fc;
}

.trick-row.selected {
    background: #eef4ff;
}

.trick-row:has(.trick-checkbox:disabled) {
    cursor: not-allowed;
    opacity: 0.6;
}

.trick-checkbox {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.table-message {
    margin-top: 16px;
    color: var(--muted-text);
}


/* ==================================================
   8. Practice screen
   ================================================== */

.practice-heading {
    margin-bottom: 1rem;
    text-align: center;
}

.practice-heading h2 {
    margin: 0;
}

.practice-mode-label {
    margin: 0 0 0.35rem;

    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.practice-timer {
    margin: 1.5rem 0 0.75rem;

    text-align: center;
    font-size: clamp(4rem, 14vw, 7rem);
    font-weight: 800;
    line-height: 1;
    font-variant-numeric: tabular-nums;
}

.practice-timer.countdown {
    font-size: clamp(6rem, 20vw, 10rem);
}

.practice-timer.finished {
    font-size: clamp(2.5rem, 10vw, 5rem);
}

.practice-message {
    min-height: 1.5em;
    margin: 0 auto 1.5rem;

    text-align: center;
    font-weight: 600;
}

.practice-trick-list {
    display: grid;
    gap: 0.75rem;

    margin: 0;
    padding-left: 0;

    list-style: none;
    counter-reset: practice-tricks;
}

.practice-trick-item {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 0.85rem;

    padding: 1rem;

    background: var(--surface);
    border: 1px solid #d8d8d8;
    border-radius: 12px;

    counter-increment: practice-tricks;
}

.practice-trick-item::before {
    display: grid;
    place-items: center;

    width: 2rem;
    height: 2rem;

    color: white;
    background: var(--accent);
    border-radius: 50%;

    font-weight: 700;

    content: counter(practice-tricks);
}

.practice-trick-name {
    font-weight: 700;
}

.practice-trick-level {
    white-space: nowrap;
    font-size: 0.9rem;
    font-weight: 600;
}

.practice-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.75rem;

    margin-top: 1.5rem;
}


/* ==================================================
   9. Results screen
   ================================================== */

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

#results-content {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;

    margin-bottom: 2rem;
}

.result-section {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.result-section h3 {
    margin-bottom: 0.5rem;
}

.result-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;

    padding: 0.75rem 1rem;

    border: 1px solid #ddd;
    border-radius: 10px;
}

.result-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.result-info {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.result-level,
.result-name {
    display: block;
}

.result-name {
    font-weight: 500;
}

.result-points {
    color: var(--accent);
    font-weight: 700;
}

.score-breakdown {
    margin: 2rem 0;
}

.score-breakdown h3 {
    margin-bottom: 1rem;
}

.score-line,
.score-total {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.score-line {
    padding: 0.4rem 0;
}

.bonus-line {
    color: var(--accent);
    font-weight: 700;
}

.score-total {
    margin-top: 1rem;
    padding-top: 1rem;

    border-top: 2px solid #ddd;

    font-size: 1.3rem;
    font-weight: 700;
}

#results-total-score {
    font-size: 2rem;
}

.results-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 1rem;
}


/* ==================================================
   10. Responsive styles
   ================================================== */

@media (max-width: 700px) {
    .app-container {
        padding: 36px 0;
    }

    .mode-grid {
        grid-template-columns: 1fr;
    }

    .mode-card {
        min-height: 220px;
    }

    .selection-status {
        align-items: stretch;
        flex-direction: column;
    }

    .primary-button {
        width: 100%;
    }
}

@media (max-width: 600px) {
    .practice-trick-item {
        grid-template-columns: auto 1fr;
    }

    .practice-trick-level {
        grid-column: 2;
    }

    .practice-actions {
        flex-direction: column;
    }

    .practice-actions button {
        width: 100%;
    }
}