/* Codologia — светлая тема, перенесённая из старого интерфейса */
:root {
    --purple: #1ea5b7;
    --green: #77C234;
    --red: #E22550;
    --yellow: #F1CC00;
    --mint: #9CE2DA;
    --text: #222;
    --muted: #777;
    --border: #e8e5ee;
    --soft: #f8f6fb;
    --shadow: 0 0 40px 10px #00000022;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    min-height: 100%;
}

body {
    min-height: 100vh;
    margin: 0;
    padding: 1px 0;
    background: url("/static/background.png"), linear-gradient(135deg, #eee8f6 0%, #dff3ef 100%);
    color: var(--text);
    font-family: "Open Sans", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select,
textarea {
    font: inherit;
}

button {
    cursor: pointer;
}

button:disabled,
input:disabled {
    cursor: not-allowed;
    opacity: .85;
}

/* Общая белая карточка страницы — визуально как старый .main */
.main {
    position: relative;
    display: flex;
    align-items: stretch;
    width: min(75vw, 1500px);
    height: 80vh;
    min-height: 520px;
    margin: 5vh auto;
    padding: 25px;
    gap: 24px;
    border-radius: 15px;
    background: #fff;
    box-shadow: var(--shadow);
}

h1,
h2,
h3,
p {
    overflow-wrap: anywhere;
}

h1,
h2,
h3 {
    line-height: 1.2;
}

/* Главная: список турниров */
.page-home .container {
    display: flex;
    flex: 1;
    flex-direction: column;
    min-width: 0;
    overflow: auto;
    padding: 12px;
}

.page-home .container > h1 {
    margin: 0 0 10px;
    color: var(--purple);
    font-size: clamp(2rem, 4vw, 3rem);
}

.page-home .container > p {
    margin-top: 0;
    color: var(--muted) !important;
}

.tournaments-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(300px, 100%), 1fr));
    gap: 18px;
    margin-top: 20px;
}

.tournament-card {
    min-width: 0;
    padding: 22px;
    border: 1px solid #eee7f6;
    border-radius: 14px;
    background: #fff;
    box-shadow: 0 4px 16px #52348812;
}

.tournament-card h2 {
    margin: 0 0 18px;
    color: var(--red);
    font-size: 1.35rem;
}

.tournament-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.login-form input,
.admin-form input,
.page-home input {
    width: 100%;
    min-width: 0;
    padding: 11px 13px;
    border: 1px solid #e5deef;
    border-radius: 8px;
    outline: none;
    background: #faf8fd;
    color: var(--text);
}

.login-form input:focus,
.admin-form input:focus,
.page-home input:focus {
    border-color: var(--purple);
    box-shadow: 0 0 0 3px #52348818;
}

.login-form button,
.dashboard-link,
.nav-btn,
.tab,
.waiting button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: 9px 15px;
    border: 0;
    border-radius: 8px;
    background: var(--purple);
    color: white;
    font-weight: 700;
    text-decoration: none;
    transition: background .15s ease, transform .15s ease;
}

.login-form button:hover,
.dashboard-link:hover,
.nav-btn:hover,
.tab:hover,
.waiting button:hover {
    background: var(--purple);
}

.login-form button:active,
.waiting button:active {
    transform: translateY(1px);
}

.dashboard-link {
    background: #f0ebf7;
    color: var(--purple);
}

.dashboard-link:hover {
    background: #e4daf2;
    color: var(--purple);
}

/* Страница решения */
.page-tournament {
    padding: 20px;
}

.tournament {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 280px;
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas:
        "timer timer"
        "task nav";
    gap: 18px 24px;
    width: 100%;
    min-width: 0;
    min-height: 0;
}

#tournament-timer,
#block-timer {
    grid-area: timer;
    align-self: start;
    color: var(--purple);
    font-size: 24px;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
}

#task-view {
    grid-area: task;
    min-width: 0;
    min-height: 0;
    overflow: auto;
    padding: 4px 10px 8px 2px;
}

#task-list {
    grid-area: nav;
    display: flex;
    align-content: flex-start;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 10px;
    min-width: 0;
    min-height: 0;
    align-self: stretch;
    overflow-y: auto;
    padding: 12px;
    border-radius: 15px;
    background: #F1CC0013;
}

#task-list .task-button,
#task-list button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 50px;
    width: 50px;
    height: 50px;
    padding: 0;
    border: 0;
    border-radius: 12px;
    background: #ddd;
    color: #222;
    font-size: 20px;
    font-weight: 700;
    text-align: center;
    user-select: none;
    transition: filter .15s ease, transform .15s ease;
}

#task-list .task-button:hover,
#task-list button:hover {
    background: #bbb;
}

#task-list .task-button:focus-visible,
#task-list button:focus-visible {
    outline: 3px solid #b9a7d5;
    outline-offset: 2px;
}

.task-button.task-right,
.task-right {
    background: var(--green) !important;
    color: white !important;
}

.task-button.task-wrong,
.task-wrong {
    background: var(--red) !important;
    color: white !important;
}

.task-button.task-partial,
.task-partial {
    background: var(--yellow) !important;
    color: #332900 !important;
}

#task-list .task-button.task-active,
#task-list button.task-active {
    /* Active outline keeps the answer-state background visible. */
    outline: 3px solid var(--purple);
    outline-offset: 2px;
    box-shadow: 0 0 0 1px #fff;
}

/* Загруженный HTML-фрагмент задачи */
.task {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    width: 100%;
    min-width: 0;
    min-height: 100%;
}

.task h2,
.task-title {
    margin: 0 0 16px;
    color: var(--red);
    font-size: clamp(1.35rem, 2.2vw, 1.9rem);
}

.task-content {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding-right: 8px;
}

.task-text {
    margin: 0 0 16px;
    color: var(--text);
    font-size: 18px;
    line-height: 1.55;
    white-space: pre-wrap;
}

.task-image {
    display: block;
    max-width: 100%;
    height: auto;
    margin: 12px auto;
    object-fit: contain;
}

.task-answer,
.answer-widget {
    flex: 0 0 auto;
    margin-top: 12px;
}

/* Общие элементы виджетов. Более специфичные селекторы заменяют старые inline-style. */
.task-widget {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    width: 100%;
    max-width: 100%;
}

.task-widget input,
.task-input {
    display: block;
    width: 100%;
    min-width: 0;
    height: 46px;
    margin: 0 0 6px;
    padding: 0 13px;
    overflow: hidden;
    border: 0;
    border-radius: 8px;
    outline: none;
    background: var(--mint);
    color: #222;
    font-size: 18px;
    line-height: normal;
}

.task-widget input:focus,
.task-input:focus {
    box-shadow: 0 0 0 3px #9CE2DA77;
}

.task-widget input[type="number"]::-webkit-outer-spin-button,
.task-widget input[type="number"]::-webkit-inner-spin-button {
    margin: 0;
    -webkit-appearance: none;
}

.task-widget input[type="number"] {
    -moz-appearance: textfield;
    appearance: textfield;
}

.task-widget button,
.task-send {
    display: block;
    width: 100%;
    min-height: 46px;
    margin: 0;
    padding: 10px 14px;
    border: 0;
    border-radius: 8px;
    background: var(--purple);
    color: white;
    font-size: 18px;
    font-weight: 700;
    transition: background .15s ease;
}

.task-widget button:hover:not(:disabled),
.task-send:hover:not(:disabled) {
    background: var(--purple);
}

.task-widget button#wrong,
.task-send.answer-wrong {
    background: var(--red) !important;
    color: white !important;
}

.task-widget button#partial,
.task-send.answer-partial {
    background: var(--yellow) !important;
    color: #332900 !important;
}

.task-widget button#full,
.task-send.answer-right {
    background: var(--green) !important;
    color: white !important;
}

.task-input,
.task-send {
    box-sizing: border-box;
}

/* Область ожидания */
.waiting {
    display: flex;
    flex: 1;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 18px;
    width: 100%;
    min-height: 300px;
    text-align: center;
}

.waiting h1,
.waiting h2 {
    margin: 0;
    color: var(--purple);
}

.waiting p,
#waiting-status {
    color: var(--muted);
    font-size: 1.1rem;
}

/* Dashboard — та же светлая палитра и цветовые состояния старой таблицы */
.page-dashboard {
    overflow: hidden;
}

.dashboard {
    display: flex;
    flex: 1;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    width: 100%;
    padding: 8px;
}

.dashboard-header h1 {
    margin: 0 0 8px;
    color: var(--red);
    font-size: clamp(1.5rem, 3vw, 2.2rem);
}

.dashboard-meta {
    margin: 0 0 20px;
    color: var(--muted);
}

.dashboard-tabs,
.dash-nav {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 18px;
}

.dashboard-tabs .tab,
.dash-nav .nav-btn {
    min-height: 38px;
    padding: 8px 13px;
    border: 1px solid #e6e0ee;
    border-radius: 8px;
    background: #f2eef8;
    color: var(--purple);
    font-size: 14px;
    font-weight: 600;
}

.dashboard-tabs .tab:hover,
.dash-nav .nav-btn:hover {
    background: #e8e0f2;
}

.dashboard-tabs .tab.active,
.dash-nav .nav-btn.nav-active {
    border-color: var(--purple);
    background: var(--purple);
    color: #fff;
}

#dashboard-table {
    flex: 1;
    min-height: 0;
    overflow: auto;
    border-radius: 10px;
}

.dashboard-status {
    padding: 20px;
    color: var(--muted);
    text-align: center;
}

.dashboard-status.error {
    color: var(--red);
}

.scoreboard,
.standings {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    background: white;
    color: var(--text);
    font-size: 15px;
}

.scoreboard th,
.scoreboard td,
.standings th,
.standings td {
    padding: 10px 12px;
    border-right: 1px solid #eeeaf3;
    border-bottom: 1px solid #eeeaf3;
    text-align: center;
    vertical-align: middle;
}

.scoreboard th,
.standings thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: #faf8fc;
    color: var(--purple);
    font-weight: 800;
}

.scoreboard tr:first-child th,
.standings tr:first-child th {
    border-top: 1px solid #eeeaf3;
}

.scoreboard th:first-child,
.scoreboard td:first-child,
.standings th:first-child,
.standings td:first-child {
    border-left: 1px solid #eeeaf3;
}

.scoreboard tbody tr:hover td,
.standings tbody tr:hover td {
    background-color: #faf8fc;
}

.scoreboard .col-team,
.standings .team {
    min-width: 160px;
    text-align: left;
    white-space: nowrap;
}

.scoreboard .col-place,
.scoreboard .col-total,
.standings .rank,
.standings .total {
    font-weight: 800;
}

.scoreboard .solve-none,
.standings .cell.no-answer {
    background: #fff;
    color: #999;
}

.scoreboard .solve-full,
.standings .cell.correct {
    background: linear-gradient(180deg, #e6f9ec, #dff3e3);
    color: #0b4f18;
    font-weight: 700;
}

.scoreboard .solve-wrong,
.standings .cell.wrong {
    background: linear-gradient(180deg, #ffecec, #ffdede);
    color: #7b131e;
    font-weight: 700;
}

.scoreboard .solve-partial,
.standings .cell.partial {
    background: linear-gradient(180deg, #fff8d9, #fff4c2);
    color: #8b6914;
    font-weight: 700;
}

/* Старые имена классов dashboard, если они ещё встречаются в шаблонах */
.dashboard-root {
    display: flex;
    flex: 1;
    flex-direction: column;
    min-width: 0;
    padding: 12px;
}

.dash-section {
    margin: 18px 0;
    padding: 8px 0;
}

.table-wrap {
    max-width: 100%;
    max-height: calc(80vh - 220px);
    overflow: auto;
    margin-top: 8px;
}

/* Сообщения */
#message {
    position: relative;
    z-index: 1000;
    max-width: min(600px, 90%);
    margin: 12px auto;
    padding: 12px 24px;
    border-radius: 8px;
    color: #fff;
    font-size: 16px;
    font-weight: 600;
    text-align: center;
    pointer-events: none;
    box-shadow: 0 4px 12px #0002;
    transition: opacity .3s ease, transform .3s ease;
}

#message.hidden,
.hidden,
[hidden] {
    display: none !important;
}

#message.success { background: var(--green); }
#message.error { background: var(--red); }
#message.info { background: var(--purple); }

/* Примеры для виджетов, где есть набор тестовых значений */
.examples-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 12px;
}

.example-row {
    display: flex;
    align-items: center;
    gap: 10px;
    line-height: 1.2;
}

.example-text {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.example-input {
    width: 72px;
    height: 32px;
    padding: 4px 6px;
    border: 0;
    border-radius: 8px;
    background: var(--mint);
    font-size: .95rem;
}

footer {
    margin: 0;
    padding: 20px;
}

/* Отдельная страница входа */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - 2px);
    padding: 24px;
}

.login-card {
    width: min(760px, 100%);
    padding: clamp(22px, 4vw, 36px);
    border: 1px solid #eee7f6;
    border-radius: 15px;
    background: #fff;
    box-shadow: var(--shadow);
}

.login-card h1,
.login-card h2 {
    margin: 0 0 12px;
    color: var(--purple);
}

.login-card > p {
    margin: 0 0 20px;
    color: var(--muted);
}

.login-card label {
    display: block;
    margin: 12px 0 6px;
    font-weight: 700;
}

.login-card .login-form {
    gap: 6px;
}

.login-card .login-form input {
    min-height: 46px;
    padding: 10px 13px;
    background: #faf8fd;
}

.login-card .login-form button {
    width: 100%;
    min-height: 46px;
    margin-top: 10px;
}

.login-error {
    margin-top: 14px;
    color: var(--red);
    font-weight: 600;
}

.login-back {
    display: inline-block;
    margin-top: 18px;
    color: var(--purple);
    text-decoration: none;
}

.login-back:hover {
    text-decoration: underline;
}

/* Ожидание внутри той же белой карточки, что и остальные страницы */
.main.page-waiting {
    align-items: center;
    justify-content: center;
}

.page-waiting .waiting {
    flex: 1;
    width: 100%;
    min-width: 0;
    min-height: 100%;
    padding: 28px;
}

.waiting button[hidden],
.waiting [hidden] {
    display: none !important;
}

#continue-button {
    min-width: 190px;
    min-height: 46px;
    padding: 10px 22px;
    border: 0;
    border-radius: 8px;
    background: var(--purple);
    color: white;
    font-weight: 700;
}

#continue-button:hover:not(:disabled) {
    background: var(--purple);
}

#continue-button:disabled {
    opacity: .65;
}

@media (max-width: 1100px) {
    .main {
        width: 90vw;
        padding: 18px;
        gap: 18px;
    }

    .tournament {
        grid-template-columns: minmax(0, 1fr) 220px;
    }
}

@media (max-width: 700px) {
    .login-page {
        min-height: calc(100vh - 2px);
        padding: 12px;
    }

    .login-card {
        padding: 22px 18px;
        border-radius: 12px;
    }

    .page-waiting .waiting {
        padding: 12px;
    }

    .main {
        width: calc(100% - 20px);
        height: auto;
        min-height: calc(100vh - 20px);
        margin: 10px auto;
        padding: 14px;
        border-radius: 12px;
    }

    .page-tournament {
        padding: 12px;
    }

    .tournament {
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: auto auto minmax(300px, 1fr);
        grid-template-areas:
            "timer"
            "nav"
            "task";
        gap: 14px;
    }

    #task-list {
        max-height: 150px;
        overflow-y: auto;
    }

    #task-view {
        min-height: 300px;
        padding: 2px;
    }

    .dashboard {
        padding: 0;
    }

    .dashboard-tabs {
        margin-bottom: 12px;
    }

    .scoreboard th,
    .scoreboard td,
    .standings th,
    .standings td {
        padding: 8px;
        font-size: 13px;
    }

    .scoreboard .col-team,
    .standings .team {
        min-width: 120px;
    }
}
