:root {
    --primary-color: #2c3e50;
    --secondary-color: #3498db;
    --accent-color: #e74c3c;
    --light-color: #ecf0f1;
    --dark-color: #2c3e50;
    --success-color: #2ecc71;
    --warning-color: #f39c12;
    --error-color: #e74c3c;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

body {
    background-color: #f5f5f5;
    color: var(--dark-color);
    line-height: 1.6;
}

header {
    background-color: var(--primary-color);
    color: white;
    padding: 1.5rem;
    text-align: center;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.logo-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

h1 {
    font-size: 2.5rem;
    margin-bottom: 0.3rem;
}

.subtitle {
    font-size: 1rem;
    opacity: 0.8;
}

.main-nav {
    background-color: white;
    padding: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: nowrap;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    position: sticky;
    top: 0;
    z-index: 100;
    max-width: 1200px;
    margin: 0 auto;
}

.categories {
    display: flex;
    flex-wrap: nowrap;
    gap: 0.5rem;
    overflow-x: auto;
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE and Edge */
    padding-bottom: 5px;
    white-space: nowrap;
    scroll-behavior: smooth; /* Add smooth scrolling behavior */
    scroll-snap-type: x mandatory; /* Add snap points */
    -webkit-overflow-scrolling: touch; /* Better scrolling on iOS */
    width: auto;
    max-width: 70%;
    margin-bottom: 0;
}

.category-btn {
    background-color: var(--light-color);
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.3s;
    font-weight: 500;
    scroll-snap-align: start; /* Make buttons snap points */
    flex-shrink: 0; /* Prevent buttons from shrinking */
}

.category-btn:hover {
    background-color: var(--secondary-color);
    color: white;
}

.category-btn.active {
    background-color: var(--secondary-color);
    color: white;
}

.search-container {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: auto;
}

#search {
    padding: 0.5rem 1rem;
    border: 1px solid #ddd;
    border-radius: 20px;
    width: 250px;
    outline: none;
}

#search-btn {
    background-color: var(--secondary-color);
    color: white;
    border: none;
    width: 35px;
    height: 35px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

main {
    padding: 2rem;
    max-width: 1200px;
    margin: 0 auto;
}

.procedures-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 1.5rem;
}

.procedure-card {
    background-color: white;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s, box-shadow 0.3s;
    cursor: pointer;
}

.procedure-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

.procedure-img {
    width: 100%;
    height: 130px;
    object-fit: cover;
    border-bottom: 1px solid #eee;
}

.procedure-info {
    padding: 1rem;
}

.procedure-title {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.procedure-category {
    font-size: 0.8rem;
    color: #777;
    display: inline-block;
    background-color: #f5f5f5;
    padding: 0.2rem 0.5rem;
    border-radius: 12px;
}

.loading, .no-results {
    grid-column: 1 / -1;
    text-align: center;
    padding: 2rem;
    font-size: 1.1rem;
    color: var(--dark-color);
    background-color: rgba(255, 255, 255, 0.7);
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.loading::after {
    content: '';
    display: inline-block;
    width: 1em;
    height: 1em;
    border: 2px solid var(--secondary-color);
    border-radius: 50%;
    border-top-color: transparent;
    animation: spinner 0.8s linear infinite;
    margin-left: 0.5rem;
    vertical-align: middle;
}

@keyframes spinner {
    to { transform: rotate(360deg); }
}

footer {
    background-color: var(--primary-color);
    color: white;
    text-align: center;
    padding: 1.5rem;
    margin-top: 2rem;
}

.training-container {
    max-width: 900px;
    margin: 0 auto;
    padding: 2rem;
}

.training-header {
    margin-bottom: 2rem;
    text-align: center;
    margin-top: 2.7rem; 
}

.timer-container {
    margin: 0.8rem 0 2rem; 
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    gap: 10px;
}

.timer-container.training-active {
    justify-content: space-between;
}

.timer {
    font-size: 2rem;
    background-color: var(--primary-color);
    color: white;
    padding: 0.5rem 1.5rem;
    border-radius: 5px;
    display: inline-block;
}

.steps-container {
    margin-bottom: 2rem;
    position: relative;
}

.step {
    background-color: white;
    padding: 1.5rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: flex-start;
    gap: 1.5rem;
    transition: transform 0.5s;
}

.step-image-container {
    flex: 0 0 200px;
    position: relative;
}

.step-image {
    width: 100%;
    border-radius: 5px;
    display: none; 
}

.toggle-image-btn {
    position: absolute;
    top: 5px;
    right: 5px;
    background-color: rgba(255, 255, 255, 0.7);
    border: none;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.step-content {
    flex: 1;
}

.step-number {
    font-weight: 700;
    color: var(--secondary-color);
    margin-bottom: 0.5rem;
}

.step-description {
    margin-bottom: 1rem;
}

.step-hidden {
    background-color: #f5f5f5;
}

.step-hidden .step-description {
    filter: blur(5px);
    user-select: none;
}

.step-completed {
    background-color: rgba(46, 204, 113, 0.1);
    border-left: 3px solid var(--success-color);
}

.step-failed {
    background-color: rgba(231, 76, 60, 0.1);
    border-left: 3px solid var(--error-color);
}

.step-revealed {
    background-color: rgba(243, 156, 18, 0.1);
    border-left: 3px solid var(--warning-color);
}

.speech-input {
    margin-top: 1rem;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.input-methods {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
}

.mic-btn {
    background-color: var(--secondary-color);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 20px;
    cursor: pointer;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    white-space: nowrap;
}

.mic-btn:hover {
    background-color: #2980b9;
}

.mic-btn.listening {
    animation: pulse 1.5s infinite;
    background-color: var(--accent-color);
}

.text-input-container {
    display: flex;
    width: 100%;
    max-width: 600px;
    gap: 8px;
    align-items: center;
}

#text-input {
    flex: 1;
    padding: 0.5rem 1rem;
    border: 1px solid #ddd;
    border-radius: 20px;
    outline: none;
}

#submit-text {
    background-color: var(--secondary-color);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 20px;
    cursor: pointer;
    font-weight: 500;
    white-space: nowrap;
}

.speech-feedback {
    margin-top: 0.5rem;
    padding: 8px 12px;
    background-color: #f5f5f5;
    border: 1px solid #ddd;
    border-radius: 4px;
    min-height: 40px;
    max-height: 80px;
    overflow-y: auto;
    font-size: 0.9rem;
    width: 100%;
}

.navigation-btns {
    display: flex;
    justify-content: center;
    margin-top: 2rem;
    gap: 1rem;
    flex-wrap: wrap;
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
}

.nav-btn {
    background-color: var(--light-color);
    border: none;
    padding: 0.7rem 1.5rem;
    border-radius: 5px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-width: 120px;
}

.nav-btn:hover {
    background-color: #ddd;
}

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

.nav-btn.primary:hover {
    background-color: #2980b9;
}

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

.hint-popup {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: white;
    padding: 2rem;
    border-radius: 8px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.2);
    z-index: 1000;
    max-width: 80%;
    display: none;
}

.hint-content {
    margin-bottom: 1.5rem;
}

.hint-close {
    background-color: var(--secondary-color);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 5px;
    cursor: pointer;
    display: block;
    margin: 0 auto;
}

.overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 999;
    display: none;
}

.success-message {
    background-color: rgba(46, 204, 113, 0.2);
    border-left: 4px solid var(--success-color);
    padding: 12px;
    margin: 10px 0;
    border-radius: 5px;
}

.motivational-message {
    background-color: rgba(243, 156, 18, 0.2);
    border-left: 4px solid var(--warning-color);
    padding: 12px;
    margin: 10px 0;
    border-radius: 5px;
}

.score-display {
    font-size: 1.1rem;
    font-weight: bold;
    text-align: center;
    margin: 10px 0;
    padding: 8px;
    background-color: var(--primary-color);
    color: white;
    border-radius: 5px;
}

.completed-message {
    text-align: center;
    background-color: white;
    color: var(--dark-color);
    padding: 1.5rem;
    border-radius: 8px;
    margin-bottom: 1.5rem;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    display: none;
}

.completed-message h3 {
    color: var(--success-color);
    margin-bottom: 0.5rem;
}

.steps-summary-list {
    list-style: none;
    padding: 0;
    margin: 15px 0;
}

.steps-summary-list li {
    display: flex;
    align-items: flex-start;
    padding: 8px;
    margin-bottom: 6px;
    background-color: rgba(255, 255, 255, 0.9);
    border-radius: 6px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.status-icon {
    font-size: 1.1rem;
    margin-right: 8px;
    flex-shrink: 0;
}

.summary-step-number {
    font-weight: bold;
    margin-right: 8px;
    flex-shrink: 0;
    color: var(--dark-color);
}

.summary-step-description {
    flex: 1;
    color: var(--dark-color);
}

.timer-active {
    background-color: var(--primary-color) !important;
    cursor: default !important;
    width: auto;
    min-width: 160px;
}

.timer-in-button {
    font-size: 1.5rem;
    color: white;
    font-weight: 500;
}

.feedback-indicator {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 90px;
    z-index: 1000;
    pointer-events: none;
    animation: feedback-bounce 0.6s 3;
}

.feedback-correct {
    text-shadow: 0 0 10px rgba(46, 204, 113, 0.3);
}

.feedback-incorrect {
    background-color: rgba(231, 76, 60, 0.8);
    color: white;
    border-radius: 8px;
    width: 120px;
    height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.feedback-hide {
    animation: feedback-fade-out 0.3s forwards;
}

@keyframes feedback-bounce {
    0%, 100% {
        transform: translate(-50%, -50%) scale(1);
    }
    50% {
        transform: translate(-50%, -50%) scale(1.3);
    }
}

@keyframes feedback-fade-out {
    from {
        opacity: 1;
    }
    to {
        opacity: 0;
    }
}

@media (max-width: 768px) {
    .main-nav {
        flex-direction: column;
        align-items: stretch;
        padding: 0.5rem;
        position: sticky;
        top: 0;
        z-index: 100;
        max-width: 100%;
    }
    
    .categories {
        margin-bottom: 0.5rem;
        justify-content: flex-start;
        overflow-x: auto;
        padding-bottom: 5px;
        white-space: nowrap;
        padding-left: 0.5rem;
        padding-right: 0.5rem;
        width: 100%;
        max-width: 100%;
    }
    
    .search-container {
        width: 100%;
        justify-content: center;
        margin-top: 0.5rem;
    }
    
    .procedures-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 1rem;
    }
    
    .procedure-card {
        margin-bottom: 0.5rem;
    }
    
    .procedure-img {
        height: 100px;
    }
    
    .procedure-info {
        padding: 0.7rem;
    }
    
    .procedure-title {
        font-size: 0.9rem;
        margin-bottom: 0.3rem;
    }
    
    .procedure-category {
        font-size: 0.7rem;
        padding: 0.1rem 0.4rem;
    }
    
    footer {
        display: none;
    }
    
    header {
        padding: 0.4rem; 
    }
    
    .logo-container {
        transform: scale(0.75); 
        margin: -0.5rem 0;
    }
    
    .training-header {
        margin-bottom: 0.2rem;
        margin-top: 1.2rem; 
    }
    
    .timer-container {
        margin-top: 0.2rem; 
        margin-bottom: 0.4rem;
    }
    
    .step {
        flex-direction: column;
    }
    
    .step-image-container {
        flex: 0 0 auto;
        width: 100%;
        margin-bottom: 1rem;
    }
    
    .step-image {
        width: 100%;
        height: 206px; 
        object-fit: cover;
        object-position: center;
    }
    
    .training-container {
        padding: 1rem;
        width: 100%;
        box-sizing: border-box;
        max-width: 100%;
    }
    
    .timer-container {
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        gap: 10px;
        width: 100%;
    }
    
    #start-btn, #toggle-all-images {
        padding: 0.7rem;
        font-size: 0.9rem;
        flex: 1;
        max-width: 45%;
        min-width: 0;
    }
    
    #start-btn .btn-text, 
    #toggle-all-images .btn-text {
        display: none;
    }
    
    .timer-active {
        justify-content: center;
    }
    
    .training-header {
        text-align: center;
        padding: 0 1rem;
        width: 100%;
        box-sizing: border-box;
    }
    
    .back-link {
        text-decoration: none;
        position: absolute;
        left: 15px;
        font-size: 1.2rem; 
    }
    
    .navigation-btns {
        flex-wrap: wrap;
        gap: 5px;
        width: 100%;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: white;
        padding: 10px;
        border-top: 1px solid #ddd;
        z-index: 100;
    }
    
    .nav-btn {
        flex: 1;
        padding: 0.7rem 0.5rem;
        min-width: 0;
        max-width: 23%;
    }
    
    .nav-btn .btn-text {
        display: none;
    }
    
    .timer-in-button {
        font-size: 1.2rem;
    }
    
    .text-input-container {
        width: 100%;
        display: flex;
        flex-direction: row;
    }
    
    #text-input {
        flex: 1;
    }
    
    #submit-text {
        width: 40px;
        padding: 0.5rem;
    }
    
    #submit-text span {
        display: none;
    }
    
    .mic-btn {
        width: 40px;
        height: 40px; 
        padding: 0;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        overflow: hidden;
    }
    
    .mic-btn span {
        display: none;
    }
    
    .mic-btn i {
        margin: 0 auto;
        font-size: 1.2rem;
    }
    
    .completed-message {
        margin-bottom: 70px;
    }
    
    main {
        padding: 1rem;
    }
}

@media (min-width: 769px) {
    .back-link {
        margin-right: 10px;
    }
}

@media (max-width: 480px) {
    main {
        padding: 1rem;
        width: 100%;
        box-sizing: border-box;
    }
    
    .btn-text {
        display: none;
    }
    
    #start-btn, #toggle-all-images {
        width: auto;
        justify-content: center;
    }
}

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

#procedure-title {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

#procedure-title-text {
    max-width: 80%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.back-link {
    text-decoration: none;
    color: inherit;
    display: inline-block;
}