:root {
    color-scheme: light;

    /* Colors */
    --color-bg: #f6f7f3;
    --color-surface: #ffffff;
    --color-surface-soft: #f1f4ef;
    --color-border: #e2e8e1;
    --color-text: #1f2328;
    --color-text-muted: #687076;

    --color-brand: #0f5132;
    --color-brand-dark: #0b3d26;
    --color-brand-soft: #dcefe3;

    --color-warning: #f3b63f;
    --color-focus: rgba(15, 81, 50, 0.18);

    /* Layout */
    --sidebar-width: 300px;
    --content-max-width: 880px;
    --page-padding-x: 16px;
    --page-padding-y: 20px;
    --mobile-bottom-nav-height: 76px;

    /* Radius */
    --radius-sm: 12px;
    --radius-md: 16px;
    --radius-lg: 20px;

    /* Shadow */
    --shadow-sm: 0 8px 24px rgba(16, 24, 40, 0.06);

    /* Typography */
    --font-family-base: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --font-size-page-title: 2rem;
    --font-size-score: 3.25rem;
}

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

html {
    height: 100%;
    overflow-x: hidden;
    -webkit-text-size-adjust: 100%;
}

body {
    min-height: 100%;
    margin: 0;
    overflow-x: hidden;
}

body.app-shell {
    font-family: var(--font-family-base);
    color: var(--color-text);
    background: var(--color-bg);
}

h1,
h2,
h3,
h4,
h5,
h6 {
    margin: 0;
    color: var(--color-text);
}

p {
    margin: 0;
}

img,
svg,
video,
canvas {
    display: block;
    max-width: 100%;
}

.text-muted {
    color: var(--color-text-muted) !important;
}

/* =========================
   Layout
========================= */

.app-layout {
    display: flex;
    min-height: 100dvh;
}

.app-content {
    width: 100%;
    min-width: 0;
}

.content-wrapper {
    width: min(100%, var(--content-max-width));
    margin-inline: auto;
    padding:
        var(--page-padding-y)
        var(--page-padding-x)
        calc(var(--mobile-bottom-nav-height) + 24px)
        var(--page-padding-x);
}

.section-spacing {
    margin-bottom: 16px;
}

/* =========================
   Sidebar / Navigation
========================= */

.app-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 1020;
    display: flex;
    flex-direction: column;
    gap: 24px;
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    height: 100dvh;
    padding: 24px 18px;
    background: var(--color-surface);
    border-inline-end: 1px solid var(--color-border);
    overflow-y: auto;
}

.sidebar-brand {
    padding: 4px 8px 8px;
}

.sidebar-title {
    font-size: 1.5rem;
    font-weight: 800;
    line-height: 1.15;
    color: var(--color-brand);
}

.sidebar-subtitle {
    margin-top: 6px;
    font-size: 0.82rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--color-text-muted);
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    border-radius: var(--radius-md);
    color: #46505a;
    text-decoration: none;
    font-size: 1rem;
    font-weight: 600;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.sidebar-link:hover {
    background: var(--color-surface-soft);
    color: var(--color-text);
}

.sidebar-link.active {
    background: var(--color-brand-soft);
    color: var(--color-brand);
}

.sidebar-link i {
    font-size: 1.1rem;
}

/* =========================
   Mobile Bottom Navigation
========================= */

.mobile-bottom-nav {
    position: fixed;
    inset: auto 0 0 0;
    z-index: 2000;
    display: flex;
    justify-content: space-around;
    align-items: center;
    min-height: var(--mobile-bottom-nav-height);
    padding: 10px 8px calc(10px + env(safe-area-inset-bottom));
    background: rgba(255, 255, 255, 0.97);
    border-top: 1px solid var(--color-border);
}

.mobile-nav-link {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    min-width: 60px;
    color: var(--color-text-muted);
    text-decoration: none;
    font-size: 0.72rem;
    font-weight: 600;
}

.mobile-nav-link i {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 32px;
    font-size: 1.25rem;
    border-radius: 16px;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.mobile-nav-link.active {
    color: var(--color-brand);
    font-weight: 700;
}

.mobile-nav-link.active i {
    background-color: var(--color-brand-soft);
    color: var(--color-brand-dark);
}

/* =========================
   Generic Cards / Sections
========================= */

.app-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

.app-card-body {
    padding: 18px;
}

.page-header {
    margin-bottom: 20px;
    text-align: center;
}

.page-header h1 {
    margin-bottom: 8px;
    font-size: var(--font-size-page-title);
    font-weight: 800;
    line-height: 1.1;
}

.page-header p {
    color: var(--color-text-muted);
    font-size: 1rem;
}

.section-header {
    margin-bottom: 16px;
}

.section-header h2 {
    margin-bottom: 4px;
    font-size: 1.2rem;
    font-weight: 700;
}

.section-header p {
    color: var(--color-text-muted);
    font-size: 0.95rem;
}

.stack-lg {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.action-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* =========================
   Forms
========================= */

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

.form-label {
    margin-bottom: 0;
    font-weight: 600;
    color: var(--color-text);
}

.form-control,
.form-select {
    min-height: 52px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    box-shadow: none;
    background: var(--color-surface);
}

.form-control:focus,
.form-select:focus {
    border-color: var(--color-brand);
    box-shadow: 0 0 0 0.2rem var(--color-focus);
}

.input-action-row {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* =========================
   Buttons
========================= */

.btn {
    min-height: 48px;
    border-radius: var(--radius-sm);
    font-weight: 700;
}

.btn-dark {
    background: var(--color-brand);
}

.btn-dark:hover,
.btn-dark:focus {
    background: var(--color-brand-dark);
}

.btn-outline-dark,
.score-btn {
    border: 2px solid var(--color-brand);
    background: transparent;
    color: var(--color-brand);
    transition: background-color 0.2s ease, color 0.2s ease;
    width: 100%;
}

.btn-outline-dark:hover,
.btn-outline-dark:focus,
.score-btn:hover,
.score-btn:active {
    background: var(--color-brand);
    border-color: var(--color-brand);
    color: #fff;
}

.btn-secondary,
.btn-warning {
    border: none;
}

.btn:disabled,
.btn.disabled {
    opacity: 0.65;
    cursor: not-allowed;
}

.btn,
.snake-hotspot-area,
.btn-toggle {
    touch-action: manipulation;
}

.btn-toggle {
    border: 1px solid var(--color-brand);
    background: var(--color-surface);
    color: var(--color-brand);
    border-radius: 999px;
    padding: 0.5rem 1rem;
    font-weight: 600;
}

.btn-toggle.active {
    background: var(--color-brand);
    color: #fff;
}

/* =========================
   Toast Notifications
========================= */

.toast-container {
    position: fixed;
    top: 15px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    pointer-events: none;
}

.app-toast {
    min-width: 280px;
    padding: 14px 20px;
    border: 2px solid var(--color-brand);
    border-radius: var(--radius-md);
    background-color: var(--color-surface);
    color: var(--color-text);
    box-shadow: var(--shadow-sm);
    font-weight: 600;
    font-size: 0.95rem;
    pointer-events: auto;
    opacity: 0;
    transform: translateY(-15px);
    animation: slideIn 0.3s forwards ease-out;
}

.app-toast.success {
    border-color: #d1e7dd;
}

.app-toast.error {
    border-color: #dc3545;
}

.app-toast.fade-out {
    animation: slideOut 0.3s forwards ease-in;
}

@keyframes slideIn {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideOut {
    to {
        opacity: 0;
        transform: translateY(-15px);
    }
}

/* =========================
   Player Selection / Preview
========================= */

.selection-mode-toggle,
.score-mode-toggle {
    display: flex;
    justify-content: center;
}

.score-mode-toggle {
    gap: 0.75rem;
    margin: 1rem 0 1.25rem;
}

.team-setup {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 14px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface-soft);
}

.team-title {
    font-size: 1.05rem;
    font-weight: 700;
}

.match-preview {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    text-align: center;
}

.match-preview-team {
    display: flex;
    flex-direction: column;
    gap: 6px;
    width: 100%;
    min-height: 120px;
    padding: 14px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface-soft);
}

.match-preview-label {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.match-preview-name {
    font-size: 1.2rem;
    font-weight: 800;
    color: var(--color-brand);
}

.match-preview-players {
    font-size: 0.95rem;
    font-weight: 600;
}

.match-preview-vs {
    font-size: 1.1rem;
    font-weight: 800;
    color: var(--color-text-muted);
    text-transform: uppercase;
}

.match-preview.ready .match-preview-team {
    border-color: var(--color-brand);
    background: #eef7f1;
    box-shadow: 0 6px 18px rgba(15, 81, 50, 0.08);
}

.match-preview.ready .match-preview-name {
    color: var(--color-brand-dark);
}

.match-preview.ready .match-preview-vs {
    color: var(--color-brand);
}

/* =========================
   Match Page
========================= */

.score-section {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-bottom: 16px;
}

.score-team-card {
    overflow: hidden;
}

.score-teams-wrapper {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 15px;
    align-items: start;
}

.team-column {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    min-width: 0;
}

.team-divider {
    align-self: stretch;
    width: 2px;
    background-color: var(--color-border);
    border-radius: 2px;
    opacity: 0.5;
}

.score-team-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    margin-bottom: 18px;
    text-align: center;
    width: 100%;
    min-width: 0;
}

.score-team-header h2 {
    width: 100%;
    min-width: 0;
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1.15;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.score-team-header-top {
    gap: 6px;
}

.score-team-players {
    width: 100%;
    min-width: 0;
    line-height: 1.35;
    letter-spacing: 0.2px;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.score-value {
    font-size: var(--font-size-score);
    line-height: 1;
    font-weight: 800;
    color: var(--color-brand);
}

.score-button-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    width: 100%;
}

.manual-score-input {
    width: 100%;
    margin-top: 15px;
}

.card-action-row {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
    margin-top: 25px;
}

.match-summary-grid {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 12px;
    margin-bottom: 20px;
}

.match-summary-actions {
    display: flex;
    justify-content: center;
    margin-top: 8px;
}

.match-summary-actions .btn {
    width: auto;
    min-width: 150px;
}

.summary-item {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    padding: 14px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface-soft);
    text-align: center;

}

.summary-label {
    font-size: 0.9rem;
    color: var(--color-text-muted);
}

.summary-value {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--color-brand);
}

/* =========================
   Snake Board
========================= */

.snake-board {
    position: relative;
    width: 100%;
    max-width: 500px;
    margin: 1.5rem auto;
    aspect-ratio: 1 / 1;
}

.snake-shape {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

.snake-s-path,
.snake-center-line {
    fill: none;
    stroke: #111;
    stroke-width: 6;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.snake-hotspot-area {
    fill: transparent;
    cursor: pointer;
    transition: fill 0.2s ease;
}

.snake-tallies-layer {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.snake-tally-group {
    position: absolute;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    width: 44%;
    transform: translateY(-50%);
}

.snake-tally-group.left {
    right: 53%;
    left: auto;
    flex-direction: row-reverse;
    justify-content: flex-start;
}

.snake-tally-group.right {
    left: 53%;
    right: auto;
    flex-direction: row;
    justify-content: flex-start;
}

.snake-tally {
    width: 8px;
    height: 48px;
    background: #111;
    border-radius: 4px;
    transform: rotate(10deg);
}

.snake-rest {
    position: absolute;
    bottom: 0;
    font-size: 3rem;
    font-weight: 800;
    color: #111;
}

.snake-rest.left {
    left: 25%;
    transform: translateX(-50%);
}

.snake-rest.right {
    right: 25%;
    transform: translateX(50%);
}

.snake-target-row {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.35rem;
    margin: 1.25rem 0 0.5rem;
}

.snake-target-label {
    font-size: 0.95rem;
    font-weight: 600;
    color: #495057;
}

.snake-target-value {
    min-width: 88px;
    padding: 0.55rem 1rem;
    border: 1px solid #ced4da;
    border-radius: 0.75rem;
    background: #fff;
    font-weight: 700;
    text-align: center;
}

/* =========================
   Status / Utility Blocks
========================= */

.status-stack {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 18px;
}

.status-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    padding: 12px 0;
    border-bottom: 1px solid var(--color-border);
}

.status-row:last-child {
    border-bottom: 0;
}

.status-label {
    font-weight: 600;
    color: var(--color-text-muted);
}

.status-value {
    font-weight: 700;
    color: var(--color-brand);
    text-align: right;
}

/* =========================
   Podium
========================= */

.podium-container {
    display: flex;
    align-items: flex-end;
    justify-content: center;
    gap: 12px;
    min-height: 220px;
    padding-top: 20px;
}

.podium-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 30%;
    max-width: 140px;
    transition: transform 0.3s ease;
}

.podium-col:hover {
    transform: translateY(-5px);
}

.podium-step {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    width: 100%;
    padding-top: 12px;
    border-top-left-radius: 12px;
    border-top-right-radius: 12px;
    font-size: 2rem;
    font-weight: 800;
    color: rgba(255, 255, 255, 0.7);
    box-shadow: inset 0 -10px 20px rgba(0, 0, 0, 0.15), 0 4px 8px rgba(0, 0, 0, 0.1);
}

.podium-gold .podium-step {
    height: 130px;
    background: linear-gradient(135deg, #f9d423 0%, #ff4e50 100%);
}

.podium-silver .podium-step {
    height: 95px;
    background: linear-gradient(135deg, #e0eafc 0%, #cfdef3 100%);
    color: rgba(0, 0, 0, 0.3);
}

.podium-bronze .podium-step {
    height: 70px;
    background: linear-gradient(135deg, #d4a373 0%, #a98467 100%);
}

.podium-avatar {
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 50px;
    height: 50px;
    margin-bottom: 8px;
    border: 3px solid #fff;
    border-radius: 50%;
    background-color: var(--color-brand-dark);
    color: #fff;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    font-weight: 800;
    font-size: 1.2rem;
}

.podium-gold .podium-avatar {
    width: 64px;
    height: 64px;
    border: 4px solid #f9d423;
    background-color: var(--color-brand);
    font-size: 1.5rem;
}

.podium-name {
    margin-bottom: 2px;
    font-weight: 700;
    text-align: center;
}

.podium-stat {
    margin-bottom: 10px;
    font-size: 0.9rem;
    color: #6c757d;
    text-align: center;
    font-weight: 600;
}

.podium-gold .podium-stat {
    color: var(--color-brand-dark);
    font-size: 1rem;
}

/* =========================
   Modal
========================= */

.modal-header {
    position: relative;
    justify-content: center;
    padding-top: 16px;
    text-align: center;
    border-bottom: 0;
}

.modal-title {
    width: 100%;
    text-align: center;
}

.btn-close {
    position: absolute;
    top: 16px;
    right: 16px;
    margin: 0;
}

.modal-footer {
    justify-content: center;
    gap: 12px;
}

.modal-footer .btn {
    min-width: 140px;
}

/* =========================
   Desktop
========================= */

@media (min-width: 768px) {
    :root {
        --font-size-page-title: 2.5rem;
        --font-size-score: 4.5rem;
    }

    .app-content {
        margin-left: var(--sidebar-width);
    }

    .content-wrapper {
        padding: 28px 24px;
    }

    .section-spacing {
        margin-bottom: 20px;
    }

    .app-card-body {
        padding: 24px;
    }

    .stack-lg {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 20px;
    }

    .input-action-row {
        flex-direction: row;
        align-items: stretch;
    }

    .input-action-row .form-control {
        flex: 1;
    }

    .match-preview {
        flex-direction: row;
        justify-content: center;
        align-items: stretch;
    }

    .match-preview-team {
        max-width: 280px;
    }

    .match-preview-vs {
        display: flex;
        align-items: center;
        padding-inline: 8px;
    }

    .match-summary-grid {
        flex-direction: row;
        flex-wrap: wrap;
    }

    .match-summary-grid .summary-item {
        min-width: 250px;
    }

    .toast-container {
        left: calc(50% + (var(--sidebar-width) / 2));
    }

    .modal {
        padding-left: var(--sidebar-width) !important;
    }
}

/* =========================
   Mobile Adjustments
========================= */

@media (max-width: 768px) {
    .score-team-header h2 {
        font-size: 1.0rem;
    }

    .score-team-players {
        font-size: 0.82rem;
    }

    .snake-board {
        max-width: 420px;
    }

    .snake-tally {
        width: 6px;
        height: 38px;
    }

    .snake-rest {
        font-size: 2.2rem;
    }

    body:has(input:focus) .mobile-bottom-nav {
        display: none;
    }
}

/* =========================
   Reduced Motion
========================= */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        transition: none !important;
        animation: none !important;
    }
}