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

:root {
    --md-sys-color-primary: #6750A4;
    --md-sys-color-on-primary: #FFFFFF;
    --md-sys-color-primary-container: #EADDFF;
    --md-sys-color-on-primary-container: #21005D;
    --md-sys-color-secondary: #625B71;
    --md-sys-color-secondary-container: #E8DEF8;
    --md-sys-color-tertiary: #7D5260;
    --md-sys-color-tertiary-container: #FFD8E4;
    --md-sys-color-background: #FFFBFE;
    --md-sys-color-on-background: #1C1B1F;
    --md-sys-color-surface: #FFFBFE;
    --md-sys-color-on-surface: #1C1B1F;
    --md-sys-color-outline: #79747E;
    --md-sys-color-error: #B3261E;
    --md-sys-color-warning: #994500;
    --md-sys-color-warning-container: #FFDCC4;
}

body {
    font-family: 'Google Sans', 'Roboto', 'Segoe UI', sans-serif;
    background-color: var(--md-sys-color-background);
    color: var(--md-sys-color-on-background);
    min-height: 100vh;
    padding: 24px;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

h1 {
    text-align: center;
    color: var(--md-sys-color-primary);
    margin-bottom: 24px;
    font-size: 2.25em;
    font-weight: 400;
    letter-spacing: -0.5px;
}

.password-modal {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background-color: var(--md-sys-color-background);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    transition: opacity 0.3s ease;
}

.password-container {
    background: white;
    padding: 40px;
    border-radius: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    text-align: center;
    max-width: 400px;
    width: 90%;
}

.password-container h2 {
    color: var(--md-sys-color-primary);
    margin-bottom: 30px;
    font-size: 1.8em;
}

.password-container input {
    width: 100%;
    padding: 16px 20px;
    border: 2px solid var(--md-sys-color-outline);
    border-radius: 12px;
    font-size: 16px;
    margin-bottom: 20px;
    outline: none;
    transition: border-color 0.3s;
}

.password-container input:focus {
    border-color: var(--md-sys-color-primary);
}

.password-container .btn-primary {
    width: 100%;
    margin-bottom: 15px;
}

.password-error {
    color: var(--md-sys-color-error);
    font-size: 0.9em;
    min-height: 20px;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-10px); }
    75% { transform: translateX(10px); }
}

.shake { animation: shake 0.3s ease-in-out; }

.timer-container {
    text-align: center;
    margin-bottom: 24px;
}

.timer {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    padding: 12px 24px;
    background: var(--md-sys-color-primary-container);
    color: var(--md-sys-color-on-primary-container);
    border-radius: 100px;
    font-size: 1.5em;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    box-shadow: 0 2px 6px 2px rgba(0, 0, 0, 0.15);
    transition: all 0.2s ease;
    cursor: pointer;
}

.timer:hover {
    transform: scale(1.02);
    box-shadow: 0 4px 8px 3px rgba(0, 0, 0, 0.2);
}

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

.timer.paused {
    background: var(--md-sys-color-secondary-container);
    opacity: 0.8;
}

.timer.expired {
    background: var(--md-sys-color-error);
    color: white;
    cursor: default;
}

.timer.warning {
    background: var(--md-sys-color-warning-container);
    color: var(--md-sys-color-warning);
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.timer-icon { font-size: 1.2em; }

.controls {
    background: var(--md-sys-color-surface);
    padding: 24px;
    border-radius: 24px;
    box-shadow: 0 4px 8px 3px rgba(0, 0, 0, 0.15),
                0 1px 3px rgba(0, 0, 0, 0.3);
    display: flex;
    gap: 24px;
    flex-wrap: wrap;
    justify-content: center;
    align-items: flex-end;
    margin-bottom: 30px;
    max-width: 800px;
    margin-left: auto;
    margin-right: auto;
    border: 1px solid rgba(0, 0, 0, 0.05);
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

label {
    font-size: 0.875em;
    font-weight: 500;
    color: #49454F;
    margin-left: 4px;
}

input {
    padding: 16px 20px;
    border: 1px solid var(--md-sys-color-outline);
    border-radius: 12px;
    font-size: 16px;
    background: var(--md-sys-color-surface);
    color: var(--md-sys-color-on-surface);
    width: 220px;
    outline: none;
    transition: all 0.2s ease;
}

input:focus {
    border-color: var(--md-sys-color-primary);
    border-width: 2px;
    padding: 15px 19px;
}

input:hover { border-color: #49454F; }

.btn-primary {
    padding: 16px 32px;
    background: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
    border: none;
    border-radius: 100px;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    box-shadow: 0 4px 8px 3px rgba(0, 0, 0, 0.15);
    transition: all 0.2s ease;
    outline: none;
    letter-spacing: 0.5px;
}

.btn-primary:hover {
    box-shadow: 0 6px 12px 4px rgba(0, 0, 0, 0.15);
    transform: translateY(-1px);
}

.btn-primary:active {
    box-shadow: 0 2px 4px 2px rgba(0, 0, 0, 0.15);
    transform: translateY(1px);
}

.btn-primary:disabled {
    background: #B1AFC7;
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}

.error {
    color: var(--md-sys-color-error);
    text-align: center;
    margin-bottom: 30px;
    font-weight: 500;
    font-size: 1em;
    padding: 16px 24px;
    background: #F8D7DA;
    border-radius: 12px;
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
    display: none;
}

.info {
    text-align: center;
    margin-bottom: 20px;
    color: #49454F;
    font-size: 0.9em;
}

/* --- Стили для выбора категорий --- */

.category-selector {
    max-width: 800px;
    margin: 0 auto 30px;
    background: var(--md-sys-color-surface);
    border-radius: 24px;
    box-shadow: 0 4px 8px 3px rgba(0, 0, 0, 0.15),
                0 1px 3px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(0, 0, 0, 0.05);
    overflow: hidden;
}

.selector-toggle {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    background: var(--md-sys-color-primary-container);
    cursor: pointer;
    user-select: none;
    transition: background 0.2s;
    font-weight: 500;
    color: var(--md-sys-color-on-primary-container);
}

.selector-toggle:hover {
    background: #D0BCFF; /* Немного темнее primary-container */
}

.toggle-title {
    font-size: 1.1em;
}

.toggle-icon {
    font-size: 0.8em;
    transition: transform 0.3s ease;
}

.selector-content {
    padding: 20px 24px;
    transition: max-height 0.3s ease, opacity 0.3s ease;
    max-height: 800px; /* Достаточно большое значение для контента */
    opacity: 1;
    overflow: hidden;
}

.selector-content.collapsed {
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
    opacity: 0;
}

.selector-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    font-weight: 500;
    color: var(--md-sys-color-on-surface);
    flex-wrap: wrap;
    gap: 12px;
}

.selector-actions {
    display: flex;
    gap: 8px;
}

.btn-text {
    background: none;
    border: none;
    color: var(--md-sys-color-primary);
    cursor: pointer;
    font-size: 0.9em;
    padding: 8px 12px;
    border-radius: 8px;
    transition: background 0.2s;
    font-weight: 500;
}

.btn-text:hover {
    background: var(--md-sys-color-primary-container);
}

.category-list {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 16px;
    justify-content: center;
}

.category-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    background: var(--md-sys-color-secondary-container);
    border-radius: 8px;
    cursor: pointer;
    user-select: none;
    transition: all 0.2s ease;
    border: 2px solid transparent;
}

.category-chip:hover {
    background: var(--md-sys-color-primary-container);
}

.category-chip.selected {
    border-color: var(--md-sys-color-primary);
    background: var(--md-sys-color-primary-container);
}

.category-chip input {
    cursor: pointer;
    accent-color: var(--md-sys-color-primary);
    width: 16px;
    height: 16px;
}

.category-chip span {
    font-size: 0.95em;
    color: var(--md-sys-color-on-surface);
}

.category-chip.selected span {
    color: var(--md-sys-color-on-primary-container);
    font-weight: 500;
}

/* --- Билеты --- */

.tickets-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 24px;
    max-width: 1400px;
    margin: 0 auto;
}

.ticket {
    background: var(--md-sys-color-surface);
    border-radius: 16px;
    padding: 24px;
    box-shadow: 0 2px 6px 2px rgba(0, 0, 0, 0.15),
                0 1px 2px rgba(0, 0, 0, 0.3);
    transition: all 0.2s ease;
    border: 1px solid rgba(0, 0, 0, 0.05);
    position: relative;
    overflow: hidden;
    cursor: pointer;
}

.ticket::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 4px;
    background: linear-gradient(90deg, 
        var(--md-sys-color-primary),
        var(--md-sys-color-secondary),
        var(--md-sys-color-tertiary));
}

.ticket:hover {
    box-shadow: 0 8px 16px 4px rgba(0, 0, 0, 0.15),
                0 4px 8px rgba(0, 0, 0, 0.3);
    transform: translateY(-2px);
}

.ticket h3 {
    margin-top: 0;
    margin-bottom: 20px;
    color: var(--md-sys-color-primary);
    font-size: 1.25em;
    font-weight: 500;
    padding-bottom: 12px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}

.ticket ol { padding-left: 24px; }

.ticket li {
    margin-bottom: 12px;
    color: var(--md-sys-color-on-surface);
    font-size: 1em;
    line-height: 1.6;
    padding: 12px 16px;
    background: var(--md-sys-color-secondary-container);
    border-radius: 8px;
    color: #1D192B;
}

.ticket li:hover {
    background: var(--md-sys-color-primary-container);
    color: var(--md-sys-color-on-primary-container);
    cursor: default;
}

.badge {
    display: inline-block;
    padding: 4px 12px;
    background: var(--md-sys-color-primary-container);
    color: var(--md-sys-color-on-primary-container);
    border-radius: 100px;
    font-size: 0.75em;
    font-weight: 600;
    margin-bottom: 16px;
}

.loading {
    text-align: center;
    padding: 40px;
    color: #49454F;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.ticket { animation: fadeIn 0.3s ease forwards; }
.ticket:nth-child(1) { animation-delay: 0.05s; }
.ticket:nth-child(2) { animation-delay: 0.1s; }
.ticket:nth-child(3) { animation-delay: 0.15s; }
.ticket:nth-child(4) { animation-delay: 0.2s; }
.ticket:nth-child(5) { animation-delay: 0.25s; }

.ticket.refreshing {
    animation: cardRefresh 0.5s ease;
}

@keyframes cardRefresh {
    0% { transform: scale(1); opacity: 1; }
    50% { transform: scale(0.95); opacity: 0.7; }
    100% { transform: scale(1); opacity: 1; }
}

@media (max-width: 768px) {
    h1 { font-size: 1.75em; }
    .timer { font-size: 1.2em; padding: 10px 20px; }
    .controls { padding: 20px; }
    input { width: 100%; }
    .btn-primary { width: 100%; }
    .category-selector { margin-left: 10px; margin-right: 10px; }
    .selector-content { padding: 15px; }
    .category-list { gap: 6px; }
    .category-chip { padding: 8px 12px; font-size: 0.9em; }
}