/* Только относительные единицы: rem, em, %, vw/vh/dvh. Никаких px. */

:root {
    --bg: #f4f6fa;
    --card: #ffffff;
    --text: #141a24;
    --muted: #5d6778;
    --line: #d9dee8;
    --accent: #1f4e9c;
    --accent-text: #ffffff;
    --accent-soft: #e3ebf8;
    --team-bg: #eef1f6;
    --win: #1a7f37;
    --loss: #c62828;
    --danger: #c62828;
    --shadow: 0 0.0625rem 0.25rem rgba(20, 26, 36, 0.08);
    --radius: 0.875rem;
    --tap: 2.75rem;
    color-scheme: light;
}

/* тёмная тема: по системе, если не выбрана вручную, или явно через data-theme */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme='light']) {
        --bg: #0f141c;
        --card: #1a212d;
        --text: #f2f5fa;
        --muted: #9aa5b8;
        --line: #2d3747;
        --accent: #5b8ee6;
        --accent-text: #0b1220;
        --accent-soft: #22324d;
        --team-bg: #252e3d;
        --win: #4ccb6e;
        --loss: #ff6b6b;
        --danger: #ff6b6b;
        --shadow: none;
        color-scheme: dark;
    }
}

:root[data-theme='dark'] {
    --bg: #0f141c;
    --card: #1a212d;
    --text: #f2f5fa;
    --muted: #9aa5b8;
    --line: #2d3747;
    --accent: #5b8ee6;
    --accent-text: #0b1220;
    --accent-soft: #22324d;
    --team-bg: #252e3d;
    --win: #4ccb6e;
    --loss: #ff6b6b;
    --danger: #ff6b6b;
    --shadow: none;
    color-scheme: dark;
}

* {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
    font-size: 100%;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 1.0625rem;
    line-height: 1.4;
    -webkit-tap-highlight-color: transparent;
}

#app {
    max-width: 30rem;
    margin: 0 auto;
    padding: max(0.75rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) max(1.5rem, env(safe-area-inset-bottom))
        max(1rem, env(safe-area-inset-left));
}

h2 {
    font-size: 1.15rem;
    margin: 0 0 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.5em;
}

h3 {
    font-size: 1rem;
    margin: 1rem 0 0.5rem;
}

p {
    margin: 0.5rem 0;
}

.muted {
    color: var(--muted);
    font-weight: normal;
}

.note,
.hint {
    color: var(--muted);
    font-size: 0.9rem;
}

.center {
    text-align: center;
}

.error {
    color: var(--danger);
    display: flex;
    gap: 0.5em;
    align-items: center;
}

.icon {
    width: 1.1em;
    height: 1.1em;
    flex: none;
    fill: currentColor;
}

/* ---------- шапка и вкладки ---------- */

.top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-weight: 700;
    font-size: 1.15rem;
}

.brand img {
    width: 2rem;
    height: 2rem;
    border-radius: 0.375rem;
}

.tabs {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.tab {
    min-height: var(--tap);
    border: 0.0625rem solid var(--line);
    background: var(--card);
    color: var(--text);
    border-radius: var(--radius);
    font: inherit;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5em;
    cursor: pointer;
}

.tab.on {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-text);
}

/* ---------- карточки ---------- */

main {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 1rem;
    box-shadow: var(--shadow);
    border: 0.0625rem solid var(--line);
}

.card > :last-child {
    margin-bottom: 0;
}

.row-between {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.row-between h3 {
    margin: 0.75rem 0;
}

/* ---------- кнопки ---------- */

.btn {
    min-height: var(--tap);
    min-width: var(--tap);
    padding: 0 1rem;
    border-radius: var(--radius);
    border: 0.0625rem solid var(--line);
    background: var(--card);
    color: var(--text);
    font: inherit;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5em;
    cursor: pointer;
    touch-action: manipulation;
}

.btn:disabled {
    opacity: 0.4;
    cursor: default;
}

.btn.primary {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-text);
}

.btn.danger {
    color: var(--danger);
    border-color: var(--danger);
    background: transparent;
}

.btn.accent {
    color: var(--accent);
    border-color: var(--accent);
    background: transparent;
}

.btn.ghost {
    background: transparent;
}

.btn.wide {
    width: 100%;
}

.btn.big {
    min-height: 3.25rem;
    font-size: 1.1rem;
}

.btn.round {
    padding: 0;
    width: var(--tap);
    border-radius: 50%;
}

.btn.round.big {
    width: 3.25rem;
    min-height: 3.25rem;
}

.btn.small {
    font-size: 0.9rem;
    padding: 0 0.75rem;
}

.btn + .btn {
    margin-top: 0.5rem;
}

.actions {
    display: grid;
    gap: 0.5rem;
}

.actions .btn + .btn {
    margin-top: 0;
}

.segmented {
    display: flex;
    background: var(--bg);
    border-radius: var(--radius);
    padding: 0.25rem;
    gap: 0.25rem;
}

.seg {
    flex: 1;
    min-height: var(--tap);
    border: 0;
    border-radius: calc(var(--radius) - 0.25rem);
    background: transparent;
    color: var(--text);
    font: inherit;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
}

.seg.on {
    background: var(--accent);
    color: var(--accent-text);
}

.seg:disabled {
    opacity: 0.35;
}

.stepper {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.stepper-value {
    min-width: 3em;
    text-align: center;
    font-weight: 700;
    font-size: 1.15rem;
}

.chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin: 0.5rem 0;
}

.chip {
    min-height: var(--tap);
    min-width: var(--tap);
    padding: 0 0.9rem;
    border-radius: 999rem;
    border: 0.0625rem solid var(--line);
    background: var(--card);
    color: var(--text);
    font: inherit;
    cursor: pointer;
}

.chip.on {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-text);
}

/* ---------- ввод ников ---------- */

.add-row {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

input[type='text'],
input[type='number'] {
    font: inherit;
    color: var(--text);
    background: var(--bg);
    border: 0.0625rem solid var(--line);
    border-radius: var(--radius);
    min-height: var(--tap);
    padding: 0 0.75rem;
    min-width: 0;
    flex: 1;
}

input:focus-visible,
.btn:focus-visible,
.seg:focus-visible,
.chip:focus-visible {
    outline: 0.15rem solid var(--accent);
    outline-offset: 0.1rem;
}

.name-list {
    list-style: none;
    margin: 0.5rem 0 0;
    padding: 0;
}

.name-list li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.25rem 0;
    border-bottom: 0.0625rem solid var(--line);
}

.name-list li:last-child {
    border-bottom: 0;
}

.name-list li.inactive > span {
    color: var(--muted);
    text-decoration: line-through;
}

/* ---------- матч ---------- */

.round-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.round-head h2 {
    margin: 0;
    font-size: 1.4rem;
}

.court-label {
    font-size: 0.85rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--accent);
    margin-bottom: 0.5rem;
}

.teams {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: stretch;
    gap: 0.5rem;
    text-align: center;
    margin-bottom: 0.75rem;
}

.team {
    font-weight: 700;
    font-size: 1.1rem;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 0.1rem;
    border: 0.0625rem solid var(--line);
    border-radius: 0.75rem;
    padding: 0.5rem 0.25rem;
    min-height: 100%;
    background: var(--team-bg);
}

.team .plus {
    font-size: 1.4rem;
    font-weight: 700;
    line-height: 1;
}

.teams .vs {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--text);
}

.name-btn {
    min-height: var(--tap);
    padding: 0 0.4rem;
    border: 0;
    border-bottom: 0.125rem dotted var(--muted);
    background: transparent;
    color: var(--text);
    font: inherit;
    cursor: pointer;
}

.plus,
.vs {
    color: var(--muted);
    font-weight: normal;
}

.teams > .vs {
    align-self: center;
}

.score-display {
    text-align: center;
    font-size: 2.75rem;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    margin: 0.25rem 0 0.75rem;
}

.score-free {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.score-side {
    display: flex;
    flex-direction: column-reverse;
    align-items: center;
    gap: 0.4rem;
}

.score-input {
    width: 4.5rem;
    flex: none !important;
    text-align: center;
    font-size: 2.25rem !important;
    font-weight: 800;
    min-height: 3.5rem !important;
    padding: 0 !important;
    -moz-appearance: textfield;
}

.score-input::-webkit-outer-spin-button,
.score-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.score-colon {
    font-size: 2.25rem;
    font-weight: 800;
    color: var(--muted);
}

.target-grid {
    display: grid;
    gap: 0.4rem;
    margin-bottom: 0.75rem;
}

.cell {
    min-height: var(--tap);
    min-width: 0;
    padding: 0;
    aspect-ratio: 5 / 4;
    font-size: 1.2rem;
    border-radius: 0.6rem;
    border: 0.0625rem solid var(--line);
    background: var(--bg);
    color: var(--text);
    font: inherit;
    font-weight: 700;
    cursor: pointer;
    touch-action: manipulation;
}

.cell.on {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-text);
}

.match.saved {
    opacity: 0.85;
}

ul.plain,
ol.plain {
    margin: 0;
    padding-left: 1.25rem;
}

ul.plain li,
ol.plain li {
    margin: 0.25rem 0;
}

/* ---------- переключатели темы и языка (как на pdmulenko.github.io) ---------- */

.switches {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem;
    border-radius: var(--radius);
    background: #1c4689;
    color: #ffffff;
    font-weight: 500;
}

.switch-container {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.switch {
    position: relative;
    display: inline-block;
    width: 3.125rem;
    height: 1.625rem;
    flex: none;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    inset: 0;
    cursor: pointer;
    background-color: #cccccc;
    transition: 0.4s;
    border-radius: 1.25rem;
}

.slider::before {
    position: absolute;
    content: '';
    height: 1.125rem;
    width: 1.125rem;
    left: 0.25rem;
    bottom: 0.25rem;
    background-color: #ffffff;
    transition: 0.4s;
    border-radius: 50%;
}

.switch input:checked + .slider {
    background-color: #2196f3;
}

.switch input:checked + .slider::before {
    transform: translateX(1.5rem);
}

.switch input:focus-visible + .slider {
    outline: 0.15rem solid #ffffff;
    outline-offset: 0.1rem;
}

.flag {
    width: 1.75rem;
    height: 1.3rem;
    object-fit: cover;
}

/* ---------- баннер «турнир завершён» ---------- */

.banner {
    text-align: center;
    border-color: var(--accent);
    background: var(--accent-soft);
}

.banner h2 {
    justify-content: center;
    font-size: 1.4rem;
    margin-bottom: 0.25rem;
}

.banner p {
    font-size: 1.15rem;
    font-weight: 600;
}

.banner-icon .icon {
    width: 2.5rem;
    height: 2.5rem;
    color: #e0a800;
}

/* ---------- таблица ---------- */

.table-wrap {
    overflow-x: auto;
    margin: 0 -0.25rem;
}

.standings {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95rem;
    font-variant-numeric: tabular-nums;
}

.standings th,
.standings td {
    padding: 0.45rem 0.3rem;
    text-align: center;
    border-bottom: 0.0625rem solid var(--line);
    white-space: nowrap;
}

.standings th {
    font-size: 0.8rem;
    color: var(--muted);
    font-weight: 600;
}

.standings .name {
    text-align: left;
    white-space: normal;
    width: 100%;
}

.standings td.key {
    font-weight: 800;
    font-size: 1.05rem;
}

.standings th.key {
    color: var(--text);
}

.standings tr.inactive td {
    color: var(--muted);
}

.wdl .w {
    color: var(--win);
    font-weight: 700;
}

.wdl .d {
    color: var(--text);
}

.wdl .l {
    color: var(--loss);
    font-weight: 700;
}

.wdl .zero {
    color: var(--muted);
}

/* ---------- история ---------- */

.history {
    list-style: none;
    margin: 0;
    padding: 0;
}

.history > li {
    padding: 0.5rem 0;
    border-bottom: 0.0625rem solid var(--line);
}

.history > li:last-child {
    border-bottom: 0;
}

.history-round {
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--muted);
}

.history-match {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.history-score {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    font-weight: 800;
    white-space: nowrap;
}

/* ---------- диалог и уведомления ---------- */

dialog {
    width: min(28rem, calc(100vw - 2rem));
    max-height: calc(100dvh - 2rem);
    border: 0;
    border-radius: var(--radius);
    padding: 1.25rem;
    background: var(--card);
    color: var(--text);
    position: fixed;
}

dialog::backdrop {
    background: rgba(0, 0, 0, 0.45);
}

.dialog-close {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
}

dialog h2 {
    padding-right: 3rem;
}

.dialog-teams {
    text-align: center;
    font-weight: 600;
}

.list-buttons {
    display: grid;
    gap: 0.5rem;
}

.list-buttons .btn + .btn {
    margin-top: 0;
}

.toast {
    position: fixed;
    left: 50%;
    bottom: max(1.5rem, env(safe-area-inset-bottom));
    transform: translateX(-50%);
    background: var(--text);
    color: var(--bg);
    padding: 0.75rem 1.25rem;
    border-radius: 999rem;
    font-weight: 600;
    max-width: calc(100vw - 2rem);
}
