/* Shared responsive layer. Keep feature-specific mobile rules in their feature stylesheet. */

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

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

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

input,
select,
textarea,
button {
    max-width: 100%;
    font-family: inherit;
}

.navbar {
    justify-content: flex-start;
    gap: 24px;
    padding-right: 24px;
    padding-left: 24px;
}

.navbar__home {
    flex: 0 0 auto;
}

.navbar__menu {
    display: flex;
    min-width: 0;
    flex: 1 1 auto;
    align-items: center;
    justify-content: space-around;
    gap: 20px;
}

.navbar__toggle {
    display: none;
}

.tooltip:focus .tooltiptext,
.tooltip:focus-within .tooltiptext {
    visibility: visible;
    opacity: 1;
}

.fm-table-wrap,
.log-summary__table-wrap,
.leaderboard__table-wrapper {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

@media (max-width: 900px) {
    body {
        background-attachment: scroll;
    }

    .navbar {
        padding: calc(6px + env(safe-area-inset-top)) 10px 6px;
        justify-content: space-between;
        gap: 10px;
    }

    .navbar img {
        width: 44px;
        height: 44px;
    }

    .navbar a {
        margin: 0;
        padding: 10px 12px;
        font-size: 1rem;
    }

    .navbar__home {
        display: inline-flex;
        align-items: center;
        padding: 0 !important;
    }

    .navbar__toggle {
        display: inline-flex;
        width: 48px;
        min-width: 48px;
        height: 44px;
        margin: 0;
        padding: 9px 10px;
        flex-direction: column;
        align-items: stretch;
        justify-content: center;
        gap: 5px;
        border: 1px solid rgba(73, 38, 0, 0.38);
        border-radius: 8px;
        background: rgba(255, 255, 255, 0.35);
        cursor: pointer;
    }

    .navbar__toggle-line {
        display: block;
        width: 100%;
        height: 2px;
        border-radius: 999px;
        background: var(--color-forest);
        transition: transform 180ms ease, opacity 180ms ease;
    }

    .navbar.is-open .navbar__toggle-line:nth-child(1) {
        transform: translateY(7px) rotate(45deg);
    }

    .navbar.is-open .navbar__toggle-line:nth-child(2) {
        opacity: 0;
    }

    .navbar.is-open .navbar__toggle-line:nth-child(3) {
        transform: translateY(-7px) rotate(-45deg);
    }

    .navbar__menu {
        position: absolute;
        top: 100%;
        right: 0;
        left: 0;
        display: none;
        max-height: calc(100dvh - 60px - env(safe-area-inset-top));
        overflow-y: auto;
        overscroll-behavior: contain;
        flex-direction: column;
        align-items: stretch;
        justify-content: flex-start;
        gap: 0;
        padding: 4px 10px calc(12px + env(safe-area-inset-bottom));
        border-top: 1px solid rgba(73, 38, 0, 0.2);
        background: linear-gradient(to bottom, rgba(238, 219, 190, 0.98), rgba(250, 242, 229, 0.98));
        box-shadow: 0 12px 24px rgba(0, 0, 0, 0.18);
    }

    .navbar.is-open .navbar__menu {
        display: flex;
    }

    .navbar__menu > .navbar__link,
    .dropdown,
    .dropdown__toggle {
        width: 100%;
    }

    .navbar__menu > .navbar__link,
    .dropdown__toggle {
        min-height: 44px;
        text-align: center;
    }

    .dropdown__indicator {
        display: inline-block;
        margin-left: 0.35rem;
        transition: transform 180ms ease;
    }

    .dropdown.is-open .dropdown__indicator {
        transform: rotate(180deg);
    }

    .dropdown {
        position: static;
        display: flex;
        flex-direction: column;
    }

    .dropdown-content {
        position: static;
        display: none;
        width: 100%;
        min-width: 0;
        margin: 0;
        overflow: visible;
        flex-direction: column;
        border-radius: 8px;
        background: rgba(160, 100, 55, 0.16);
        box-shadow: none;
        opacity: 0;
        transform: none;
        visibility: hidden;
        pointer-events: none;
    }

    .dropdown.is-open .dropdown-content {
        display: flex;
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
    }

    .dropdown-content a {
        min-height: 42px;
        padding: 10px 14px;
        border-bottom-color: rgba(73, 38, 0, 0.18);
        color: var(--color-bark);
        text-align: center;
        font-size: 0.94rem;
    }

    .page-body.nav-open {
        overflow: hidden;
    }

    .page-section {
        width: 100%;
        padding: calc(82px + env(safe-area-inset-top)) 12px 36px;
    }

    .MainHeader {
        padding: 16px 0 24px;
        font-size: clamp(2rem, 10vw, 3rem);
        line-height: 1.08;
    }

    .header {
        padding: 16px 0 20px;
        font-size: clamp(1.75rem, 8vw, 2.45rem);
        line-height: 1.12;
    }

    .subheader {
        padding: 14px 0;
        font-size: clamp(1.35rem, 6.5vw, 2rem);
        line-height: 1.2;
    }

    .text {
        padding: 0;
        font-size: clamp(1rem, 4.5vw, 1.25rem);
        line-height: 1.55;
        overflow-wrap: anywhere;
    }

    .list {
        padding-left: 1.25rem;
        font-size: 1.05rem;
        text-align: left;
    }

    .white-card,
    .white-card.white-card-header,
    .white-card--fit {
        display: block;
        width: 100%;
        max-width: 100%;
        padding: 12px;
    }

    .white-card.white-card-header {
        margin-bottom: 10px;
    }

    .page-heading {
        display: flex;
        margin: 0 0 18px;
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }

    .page-heading__back {
        position: static;
        width: auto;
        min-width: 48px;
        min-height: 44px;
        align-self: flex-start;
        margin: 0;
        padding: 8px 16px;
        font-size: 1.2rem;
    }

    .page-heading .header {
        width: 100%;
        line-height: 1.12;
    }

    .page-heading > .white-card {
        align-self: stretch;
    }

    .media-stack,
    .media-stack--narrow,
    .media-stack--gallery {
        max-width: 100%;
        gap: 12px;
        padding: 12px 0;
    }

    .media-stack__image {
        width: auto;
        max-width: 100%;
        max-height: 70dvh;
    }

    .content-row {
        flex-direction: column;
        gap: 12px;
    }

    .link-stack,
    .link-stack.card-stack:not(.link-stack--grid),
    .link-stack--grid,
    .log-links--grid {
        width: 100%;
        max-width: 100%;
    }

    .link-stack {
        gap: 12px;
        margin-top: 12px;
    }

    .link-stack.card-stack:not(.link-stack--grid),
    .link-stack--grid,
    .log-links--grid {
        grid-template-columns: minmax(0, 1fr);
    }

    .link-stack--grid {
        gap: 12px;
    }

    .log-links--grid {
        gap: 10px;
        padding: 0;
    }

    .task-link {
        width: 100%;
        min-height: 52px;
        padding: 10px 14px;
        font-size: clamp(1.2rem, 6vw, 1.6rem);
        line-height: 1.2;
    }

    .form,
    .form-fields,
    .form-row {
        width: 100%;
        max-width: 100%;
    }

    .form {
        gap: 16px;
    }

    .form-row {
        flex-direction: column;
        align-items: stretch;
        gap: 6px;
    }

    .form-row__label,
    .form-row__input,
    .form-row__message {
        width: 100%;
        max-width: 100%;
        text-align: center;
    }

    .form-row__label {
        font-weight: 600;
    }

    .form-row__input {
        flex-wrap: wrap;
        gap: 8px;
    }

    .form-input,
    .form-input--narrow,
    .form-input--medium,
    .form-input--wide,
    .form-input--password,
    .teacher-settings-grid input,
    .teacher-settings-grid select,
    .flashcards__select,
    .flashcards-deck__select,
    .leaderboard select {
        width: min(100%, 420px);
        min-height: 44px;
        font-size: 16px;
    }

    textarea {
        width: 100%;
        font-size: 16px;
    }

    .form-label,
    .form-checkbox-group legend {
        font-size: 1.05rem;
    }

    .form-actions {
        width: 100%;
        gap: 10px;
        align-items: stretch;
    }

    .form-actions .button,
    .form--log .form-actions--log-row .button {
        width: min(100%, 440px);
        min-width: 0;
        min-height: 44px;
        flex: 1 1 auto;
        margin-right: auto;
        margin-left: auto;
    }

    .button {
        min-height: 44px;
        padding: 10px 16px;
        line-height: 1.2;
    }

    .teacher-settings-grid {
        grid-template-columns: minmax(0, 1fr);
        max-width: 100%;
    }

    .form-checkbox {
        min-height: 36px;
        font-size: 1rem;
    }

    .tooltip .tooltiptext {
        position: fixed;
        right: 12px;
        bottom: calc(16px + env(safe-area-inset-bottom));
        left: 12px;
        width: auto;
        max-width: none;
        margin: 0;
        padding: 10px 12px;
        transform: none;
        font-size: 0.92rem;
        line-height: 1.4;
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.24);
    }

    .upload-wrapper,
    .upload-form,
    .upload-dropzone {
        width: 100%;
    }

    .upload-dropzone {
        padding: 14px;
        border-radius: 14px;
    }

    .upload-dropzone__button {
        width: 100%;
        min-width: 0;
        min-height: 44px;
    }

    .upload-dropzone__meta {
        width: 100%;
    }

    .upload-dropzone__format,
    .upload-dropzone__filename {
        max-width: 100%;
        overflow-wrap: anywhere;
    }

    .generator-guide {
        gap: 12px;
    }

    .generator-guide__figure {
        width: 100%;
    }

    .form--stat-project {
        width: 100%;
        padding: 0;
    }

    .stat-project__assignment {
        align-items: stretch;
    }

    .stat-project__controls {
        align-items: stretch;
        flex-direction: column;
    }

    .stat-project__table,
    .stat-project__table tbody,
    .stat-project__table tr,
    .stat-project__table th,
    .stat-project__table td {
        display: block;
        width: 100%;
    }

    .stat-project__table {
        background: transparent;
        border-radius: 0;
        overflow: visible;
    }

    .stat-project__table thead {
        display: none;
    }

    .stat-project__table tr {
        margin-bottom: 12px;
        padding: 12px;
        border: 1px solid var(--color-line);
        border-radius: 10px;
        background: rgba(255, 255, 255, 0.82);
    }

    .stat-project__table th,
    .stat-project__table td,
    .stat-project__table td:last-child {
        width: 100%;
        padding: 6px 0;
        border: 0;
        text-align: left;
    }

    .stat-project__table th[scope="row"] {
        margin-bottom: 6px;
        color: var(--color-forest);
        font-size: 1.05rem;
    }

    .stat-project__table td::before {
        content: attr(data-label);
        display: block;
        margin-bottom: 5px;
        color: var(--color-muted);
        font-size: 0.84rem;
        font-weight: 700;
    }

    .log-summary,
    .log-preview,
    .edit-list,
    .flashcards-log,
    .flashcards-deck,
    .flashcards-log__card {
        width: 100%;
        max-width: 100%;
    }

    .log-summary__table,
    .log-summary__table[style] {
        min-width: 620px;
    }

    .log-preview__body,
    .log-summary__entry-raw,
    .fm-pre {
        font-size: 0.82rem;
        overflow-wrap: anywhere;
    }

    .edit-list {
        overflow-x: auto;
    }

    .edit-list__table {
        min-width: 560px;
    }

    .flashcards-log__card {
        padding: 0;
    }

    .flashcards-log__row,
    .flashcards-log__header {
        grid-template-columns: 32px minmax(90px, 1fr) minmax(110px, 1.3fr) 58px;
        gap: 5px;
        font-size: 0.82rem;
    }

    .flashcards-log__row span,
    .flashcards-log__header span {
        min-width: 0;
        overflow-wrap: anywhere;
    }

    .flashcards-deck__field {
        gap: 6px;
    }

    .flashcards-deck__thumbs {
        width: 44px;
        flex-basis: 44px;
    }

    .flashcards-deck__thumbnail {
        width: 40px;
        height: 40px;
    }

    .file-manager {
        width: 100%;
        padding: 10px;
    }

    .fm-breadcrumbs {
        overflow-wrap: anywhere;
        line-height: 1.6;
    }

    .fm-toolbar,
    .fm-upload {
        width: 100%;
        align-items: stretch;
        flex-direction: column;
    }

    .fm-upload input[type="file"] {
        width: 100%;
        font-size: 16px;
    }

    .fm-toolbar .button,
    .fm-upload .button {
        width: 100%;
        min-height: 44px;
        margin: 0;
    }

    .fm-table thead {
        display: none;
    }

    .fm-table,
    .fm-table tbody,
    .fm-table tr,
    .fm-table td {
        display: block;
        width: 100%;
    }

    .fm-table tbody tr {
        margin-bottom: 10px;
        padding: 10px;
        border: 1px solid rgba(0, 0, 0, 0.12);
        border-radius: 8px;
        background: rgba(255, 255, 255, 0.78);
    }

    .fm-table tbody td {
        padding: 5px 0;
        border: 0;
    }

    .fm-table .fm-name {
        align-items: flex-start;
    }

    .fm-table .fm-name a {
        white-space: normal;
        overflow: visible;
        text-overflow: clip;
        overflow-wrap: anywhere;
    }

    .fm-size::before {
        content: "Velikost: ";
        font-weight: 700;
    }

    .fm-mtime::before {
        content: "Upraveno: ";
        font-weight: 700;
    }

    .fm-table .fm-actions {
        padding-top: 8px;
        border-top: 1px solid rgba(0, 0, 0, 0.08);
    }

    .fm-pre,
    .fm-textarea {
        width: 100%;
        max-width: 100%;
    }

    .leaderboard {
        width: 100%;
        margin: 0 auto 30px;
        padding: 16px 12px 20px;
        border-radius: 12px;
    }

    .leaderboard__title {
        font-size: clamp(1.8rem, 8vw, 2.4rem);
    }

    .leaderboard__controls,
    .leaderboard__tabs,
    .leaderboard__filter {
        width: 100%;
    }

    .leaderboard__tabs {
        display: grid;
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .leaderboard__pill {
        min-height: 44px;
        text-align: center;
    }

    .leaderboard__filter {
        align-items: stretch;
        flex-direction: column;
    }

    .leaderboard__table thead {
        display: none;
    }

    .leaderboard__table,
    .leaderboard__table tbody,
    .leaderboard__table tr,
    .leaderboard__table td {
        display: block;
        width: 100%;
    }

    .leaderboard__table {
        background: transparent;
    }

    .leaderboard__table tr {
        margin-bottom: 10px;
        overflow: hidden;
        border: 1px solid var(--color-line);
        border-radius: 10px;
        background: rgba(255, 255, 255, 0.94);
    }

    .leaderboard__table td {
        display: flex;
        min-height: 38px;
        padding: 8px 10px;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        text-align: right;
    }

    .leaderboard__table td::before {
        flex: 0 0 auto;
        color: var(--color-muted);
        font-weight: 700;
    }

    .leaderboard__table td:nth-child(1)::before { content: "#"; }
    .leaderboard__table td:nth-child(2)::before { content: "Player"; }
    .leaderboard__table td:nth-child(3)::before { content: "Score"; }
    .leaderboard__table td:nth-child(4)::before { content: "Difficulty"; }
    .leaderboard__table td:nth-child(5)::before { content: "Map"; }
    .leaderboard__table td:nth-child(6)::before { content: "Date"; }

    .leaderboard__table .leaderboard__empty {
        display: block;
        padding: 16px;
        text-align: center;
    }

    .leaderboard__table .leaderboard__empty::before {
        content: none;
    }

    .flashcards {
        padding: 14px 12px calc(150px + env(safe-area-inset-bottom));
    }

    .flashcards__text {
        min-height: 0 !important;
        flex: 1 1 42%;
        overflow-y: auto;
        overscroll-behavior: contain;
        scrollbar-gutter: stable;
        font-size: 1.3rem;
    }

    .flashcards__answer {
        display: flex;
        min-height: 0 !important;
        flex: 1 1 58%;
        flex-direction: column;
        align-items: stretch;
        justify-content: flex-start;
        overflow-y: auto;
        overscroll-behavior: contain;
        scrollbar-gutter: stable;
        font-size: 1.1rem;
    }

    .flashcards__answer-content {
        margin: 0;
        padding: 0;
        flex: 0 0 auto;
    }

    .flashcards__card {
        height: clamp(300px, 52vh, 520px);
        height: clamp(300px, 52svh, 520px);
        min-height: 0;
        overflow: hidden;
        contain: layout paint;
    }

    .flashcards__image {
        max-height: min(22svh, 180px);
    }

    body.flashcards-study-active {
        overflow: hidden;
    }

    body.flashcards-study-active .page-section {
        height: 100svh;
        padding: 0;
        overflow: hidden;
    }

    body.flashcards-study-active .white-card-header,
    body.flashcards-study-active .flashcards__code-panel {
        display: none;
    }

    body.flashcards-study-active .flashcards {
        position: fixed;
        z-index: 900;
        top: calc(56px + env(safe-area-inset-top));
        right: 0;
        bottom: 0;
        left: 0;
        display: flex;
        width: 100%;
        max-width: none;
        height: auto;
        margin: 0;
        padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
        flex-direction: column;
        border-radius: 0;
    }

    body.flashcards-study-active .flashcards__toolbar {
        flex: 0 0 auto;
        gap: 0;
        margin-bottom: 6px;
    }

    body.flashcards-study-active .flashcards__toolbar label,
    body.flashcards-study-active .flashcards__progress {
        display: none;
    }

    body.flashcards-study-active .flashcards__select {
        width: 100%;
        min-height: 42px;
    }

    body.flashcards-study-active .flashcards__meta {
        min-height: 1.2em;
        margin-bottom: 4px;
        gap: 0;
        flex: 0 0 auto;
    }

    body.flashcards-study-active .flashcards__card {
        width: 100%;
        height: auto;
        min-height: 0;
        flex: 1 1 auto;
    }

    body.flashcards-study-active .flashcards__actions {
        position: static;
        z-index: auto;
        left: auto;
        bottom: auto;
        width: 100%;
        margin: 0;
        padding: 8px 0 0;
        flex: 0 0 auto;
        transform: none;
        border: 0;
        border-radius: 0;
        background: transparent;
        box-shadow: none;
    }

    .flashcards__select {
        min-width: 0;
    }

    .cookie-banner__button {
        min-height: 44px;
    }

    .simple-page {
        min-height: 100dvh;
        padding: calc(16px + env(safe-area-inset-top)) 12px calc(16px + env(safe-area-inset-bottom));
    }
}

@media (max-width: 700px) {
    .flashcards {
        padding-bottom: calc(150px + env(safe-area-inset-bottom));
    }
}

@media (max-width: 420px) {
    .page-section {
        padding-right: 9px;
        padding-left: 9px;
    }

    .white-card {
        padding: 10px;
        border-radius: 10px;
    }

    .flashcards__rates {
        gap: 5px;
    }

    .flashcards__rates .button {
        padding: 8px 5px;
        font-size: 0.82rem;
    }

    .flashcards__code-panel {
        padding: 10px;
    }

    .cookie-banner {
        padding-right: 9px;
        padding-left: 9px;
    }
}

@media (max-width: 900px) and (max-height: 500px) {
    .navbar img {
        width: 36px;
        height: 36px;
    }

    .navbar__toggle {
        height: 38px;
    }

    .page-section {
        padding-top: calc(70px + env(safe-area-inset-top));
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
    }
}
