:root {
    /* Default variables, can be overridden by a brand-specific stylesheet */

    /* Card variables */
    --brand-card-bg: #fff;
    --brand-card-hover-bg: #f0fdfa; /* A fallback, hover is mainly border */
    --brand-card-selected-bg: #f0fdfa;
    --brand-card-border-radius: 0.5rem; /* 8px */
    --brand-card-text-color: #374151; /* gray-700, used in templates */
    --brand-card-border-color: #e5e7eb; /* gray-200 */
    --brand-card-hover-border-color: #14b8a6; /* teal-500 */
    --brand-card-selected-border-color: #14b8a6; /* teal-500 */

    /* Image container */
    --brand-image-container-bg: #f3f4f6; /* gray-100 */

    /* Button variables */
    --brand-button-border-radius: 0.5rem; /* rounded-lg */

    /* Primary Button */
    --brand-button-primary-bg-from: #14b8a6; /* from-teal-500 */
    --brand-button-primary-bg-to: #34d399;   /* to-green-400 */
    --brand-button-primary-hover-bg-from: #0d9488; /* from-teal-600 */
    --brand-button-primary-hover-bg-to: #10b981;   /* to-green-500 */
    --brand-button-primary-text-color: #ffffff;

    /* Secondary Button */
    --brand-button-secondary-bg: #e5e7eb; /* bg-gray-200 */
    --brand-button-secondary-hover-bg: #d1d5db; /* bg-gray-300 */
    --brand-button-secondary-text-color: #1f2937; /* text-gray-800 */

    /* Category Button */
    --brand-category-btn-active-bg: #14b8a6; /* bg-teal-500 */
    --brand-category-btn-active-border-color: #14b8a6; /* border-teal-500 */
    --brand-category-btn-active-text-color: #ffffff;

    /* Active/Selected Color for tabs, etc. */
    --brand-active-color: #14b8a6; /* teal-500 */
    --brand-active-text-color: #0f766e; /* teal-700 */
    --brand-font-family: sans-serif; /* A sensible default */
    --brand-main-container-border-radius: 1.5rem; /* 24px */
    --brand-modal-border-radius: 1rem; /* 16px */
    --brand-card-image-border-radius: calc(var(--brand-card-border-radius, 0.5rem) - 0.25rem);
}

.brand-main-container {
    border-radius: var(--brand-main-container-border-radius);
}

body {
    font-family: var(--brand-font-family);
}

/* === Unified Card System (Универсальная карточка: Товар, Аватар, Образ) === */
.u-card {
    position: relative;
    display: flex;
    flex-direction: column;
    background-color: var(--brand-card-bg, #fff);
    border-radius: var(--brand-card-border-radius, 0.5rem);
    border: 2px solid var(--brand-card-border-color, #e5e7eb);
    transition: all 0.2s ease-in-out;
    cursor: pointer;
    padding: 0.5rem; /* p-2 */
}
.u-card:hover {
    border-color: var(--brand-card-hover-border-color, #14b8a6);
}
.u-card.selected {
    border-color: var(--brand-card-selected-border-color, #14b8a6);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand-card-selected-border-color, #14b8a6) 30%, transparent);
    background-color: var(--brand-card-selected-bg, #f0fdfa);
}

.u-card__img-wrapper {
    position: relative;
    width: 100%;
    padding-top: 125%; /* 4:5 aspect ratio */
    background-color: var(--brand-image-container-bg, #f3f4f6);
    /* Calculate inner radius based on parent's radius */
    border-radius: var(--brand-card-image-border-radius);
    overflow: hidden;
}
.u-card__img {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background-size: contain;
    background-position: center;
    background-repeat: no-repeat;
    transition: transform 0.3s ease;
}
.u-card:hover .u-card__img {
    transform: scale(1.05);
}

.u-card__body {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    text-align: center;
    padding: 0.5rem 0.25rem 0; /* pt-2 px-1 */
    min-height: 40px;
}

/* Modifier for horizontal cards (e.g., in modals) */
.u-card--horizontal {
    flex-direction: row;
    align-items: center;
    gap: 1rem; /* 16px */
    padding: 1rem; /* 16px */
}
.u-card--horizontal .u-card__img-wrapper {
    width: 5rem; /* 80px */
    height: 6rem; /* 96px */
    padding-top: 0; /* Override aspect ratio */
    flex-shrink: 0;
}
.u-card--horizontal .u-card__body {
    text-align: left;
    padding: 0;
    min-height: 0;
}
.u-card--horizontal:hover .u-card__img {
    transform: none; /* Disable image zoom for this variant */
}

/* Modifier for instruction cards */
.u-card--instruction {
    padding: 0;
    border-radius: 0.75rem; /* 12px */
    border-width: 2px;
    border-style: solid;
    cursor: default;
}
.u-card--instruction:hover {
    border-color: inherit; /* Override hover */
}
.u-card--instruction .u-card__img-wrapper {
    border-radius: 0;
    border-top-left-radius: 0.65rem;
    border-top-right-radius: 0.65rem;
}
.u-card--instruction .u-card__img {
    transition: none;
}
.u-card--instruction:hover .u-card__img {
    transform: none;
}
.u-card--instruction .u-card__body {
    padding: 1rem; /* p-4 */
    text-align: left;
}
.u-card--instruction.correct {
    background-color: #f0fdfa; /* teal-50 */
    border-color: #14b8a6; /* teal-500 */
}
.u-card--instruction.incorrect {
    background-color: #fee2e2; /* red-100 */
    border-color: #ef4444; /* red-500 */
}
.loader { width: 50px; height: 50px; border: 5px solid #f3f3f3; border-top: 5px solid #14b8a6; border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* === Unified Modal System === */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000; /* A high but consistent z-index */
    background-color: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem; /* 16px */
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.modal-overlay.is-visible {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background-color: #fff;
    border-radius: var(--brand-modal-border-radius, 1rem);
    box-shadow: 0 10px 25px rgba(0,0,0,0.15);
    width: 100%;
    max-height: 95vh; /* Fallback for older browsers */
    max-height: 95dvh; /* Use dynamic viewport height for mobile */
    display: flex;
    flex-direction: column;
    position: relative;
    transform: scale(0.95);
    transition: transform 0.3s ease;
    /* Scrolling is now handled by the modal-body */
}

.modal-overlay.is-visible .modal-content {
    transform: scale(1);
}

.modal-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid #e5e7eb; /* gray-200 */
    flex-shrink: 0;
    background-color: #fff; /* Ensure it's not transparent when scrolling */
    border-top-left-radius: var(--brand-modal-border-radius, 1rem); /* Match parent's rounding */
    border-top-right-radius: var(--brand-modal-border-radius, 1rem); /* Match parent's rounding */
}

.modal-title {
    font-size: 1.5rem; /* text-2xl */
    font-weight: 700; /* bold */
    color: #1f2937; /* gray-800 */
    text-align: center;
}

.modal-body {
    padding: 1.5rem;
    overflow-y: auto; /* The body is now the scrollable container */
    flex-grow: 1;
}

.modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid #e5e7eb; /* gray-200 */
    flex-shrink: 0;
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    background-color: #f9fafb; /* gray-50 */
    border-bottom-left-radius: var(--brand-modal-border-radius, 1rem);
    border-bottom-right-radius: var(--brand-modal-border-radius, 1rem);
}

.modal-close-btn {
    position: absolute;
    top: 0.75rem; /* 12px */
    right: 0.75rem; /* 12px */
    color: #9ca3af; /* gray-400 */
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0.25rem;
    z-index: 10;
}
.modal-close-btn:hover {
    color: #374151; /* gray-700 */
}
.modal-close-btn svg {
    width: 2rem; /* 32px */
    height: 2rem; /* 32px */
}

/* Correct/Incorrect Icon Colors */
.u-card--instruction.correct .icon {
   color: #10b981; /* green-500 */
}
.u-card--instruction.incorrect .icon {
   color: #ef4444; /* red-500 */
}

/* === Unified Button System === */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 600; /* semibold */
    padding: 0.5rem 1rem; /* py-2 px-4 */
    border-radius: var(--brand-button-border-radius, 0.5rem);
    transition: all 0.2s ease-in-out;
    cursor: pointer;
    border: none;
    text-decoration: none; /* for <a> tags */
}
.btn-lg {
    padding-top: 0.75rem; /* py-3 */
    padding-bottom: 0.75rem;
    padding-left: 1.5rem; /* px-6 */
    padding-right: 1.5rem;
}
.btn-primary {
    background-image: linear-gradient(to right, var(--tw-gradient-stops));
    --tw-gradient-from: var(--brand-button-primary-bg-from, #14b8a6);
    --tw-gradient-to: var(--brand-button-primary-bg-to, #34d399);
    --tw-gradient-stops: var(--tw-gradient-from), var(--tw-gradient-to);
    color: var(--brand-button-primary-text-color, white);
    padding-left: 1.5rem; /* px-6 */
    padding-right: 1.5rem;
}
.btn-primary:hover {
    --tw-gradient-from: var(--brand-button-primary-hover-bg-from, #0d9488);
    --tw-gradient-to: var(--brand-button-primary-hover-bg-to, #10b981);
}
.btn-secondary {
    background-color: var(--brand-button-secondary-bg, #e5e7eb);
    color: var(--brand-button-secondary-text-color, #1f2937);
}
.btn-secondary:hover {
    background-color: var(--brand-button-secondary-hover-bg, #d1d5db);
}
.btn-link {
    color: #4b5563; /* text-gray-600 */
    font-weight: 600; /* semibold */
    border-radius: var(--brand-button-border-radius, 0.5rem);
    transition: background-color 0.2s ease-in-out;
}
.btn-link:hover {
    background-color: #f3f4f6; /* hover:bg-gray-100 */
}
/* Tab specific styles */
#tabs a.active {
    border-color: var(--brand-active-color, #14b8a6);
    color: var(--brand-active-text-color, #0f766e);
}
.category-btn {
   display: inline-flex;
   align-items: center;
   justify-content: center;
   font-weight: 500; /* medium */
   padding: 0.375rem 0.875rem; /* py-1.5 px-3.5 */
   border-radius: 9999px; /* rounded-full */
   transition: all 0.2s ease-in-out;
   cursor: pointer;
   border: 1px solid #d1d5db; /* border-gray-300 */
   background-color: #ffffff; /* bg-white */
   color: #374151; /* text-gray-700 */
   font-size: 0.875rem; /* text-sm */
}
.category-btn:hover {
   background-color: #f3f4f6; /* hover:bg-gray-100 */
   border-color: #9ca3af; /* hover:border-gray-400 */
}
.category-btn.active {
   background-color: var(--brand-category-btn-active-bg, #14b8a6);
   color: var(--brand-category-btn-active-text-color, #ffffff);
   border-color: var(--brand-category-btn-active-border-color, #14b8a6);
   font-weight: 600; /* semibold */
}