/*
 * ZIEL mobile layer
 * Loaded after styles.css so mobile behaviour is predictable despite the
 * historical desktop styles. Desktop layout is intentionally untouched.
 */

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

body {
  min-width: 0;
  overscroll-behavior-y: none;
}

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

button,
input,
select,
textarea {
  touch-action: manipulation;
}

@media (hover: none), (pointer: coarse) {
  button,
  [role="button"],
  input,
  select,
  textarea,
  a {
    -webkit-tap-highlight-color: rgba(37, 111, 159, 0.16);
  }

  button:not(.word-blank),
  [role="button"],
  select,
  input:not([type="radio"]):not([type="checkbox"]) {
    min-height: 44px;
  }

  button:hover,
  .dashboard-card:hover,
  .landing-section-card:hover {
    transform: none;
  }
}

@media (max-width: 768px) {
  :root {
    --mobile-gutter: 12px;
    --mobile-radius: 12px;
  }

  html,
  body,
  #app,
  .landing-shell,
  .app-shell,
  .b1-shell,
  .approved-dashboard-shell {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    overflow-x: clip;
  }

  body {
    font-size: 14px;
  }

  /* Landing: compact header, centred copy, no horizontal clipping in RTL. */
  .landing-header {
    position: sticky;
    top: 0;
    z-index: 50;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    width: 100%;
    min-height: 60px;
    padding: 8px var(--mobile-gutter);
    gap: 8px;
  }

  .landing-header::after {
    display: none;
  }

  .landing-brand,
  .landing-actions,
  .landing-actions > * {
    min-width: 0;
  }

  .landing-wordmark {
    font-size: clamp(23px, 7vw, 30px);
    white-space: nowrap;
  }

  .landing-actions {
    display: flex;
    justify-content: flex-end;
    gap: 5px;
  }

  .landing-actions .landing-login-button {
    display: none;
  }

  .landing-actions .language-switch,
  .landing-actions .level-switch {
    min-height: 40px;
    padding: 3px;
  }

  .landing-actions .language-switch button,
  .landing-actions .level-switch button {
    min-width: 40px;
    min-height: 36px;
    padding: 5px 8px;
  }

  .landing-page {
    display: block;
    width: 100%;
    min-height: calc(100dvh - 60px);
    padding: 26px var(--mobile-gutter) calc(28px + env(safe-area-inset-bottom));
    margin: 0;
  }

  .landing-hero,
  .landing-hero-copy {
    display: block;
    width: 100%;
    min-width: 0;
    max-width: 100%;
    padding: 0;
    margin: 0;
    overflow: visible;
  }

  .landing-hero::before,
  .landing-hero::after {
    display: none;
  }

  .landing-hero-copy,
  html[dir="rtl"] .landing-hero-copy {
    text-align: center;
  }

  .landing-hero h1 {
    width: 100%;
    max-width: 100%;
    margin: 0;
    font-size: clamp(29px, 9vw, 42px);
    line-height: 1.16;
    overflow-wrap: anywhere;
  }

  .landing-hero p {
    width: 100%;
    max-width: 36rem;
    margin: 10px auto 0;
    font-size: 15px;
    line-height: 1.55;
    overflow-wrap: anywhere;
  }

  .landing-cta {
    display: grid;
    grid-template-columns: 1fr;
    width: min(100%, 360px);
    margin: 18px auto 0;
    gap: 10px;
  }

  .landing-cta .primary,
  .landing-cta .secondary,
  .landing-cta .landing-outline-button {
    width: 100%;
    min-width: 0;
    min-height: 48px;
    margin: 0;
    padding: 10px 14px;
    font-size: 15px;
  }

  .landing-section-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
    max-width: 560px;
    margin: 22px auto 0;
    gap: 10px;
  }

  .landing-section-card {
    width: 100%;
    min-width: 0;
    min-height: 112px;
    padding: 12px 8px;
    border-radius: var(--mobile-radius);
  }

  .landing-section-card:last-child:nth-child(odd) {
    grid-column: 1 / -1;
  }

  .landing-section-icon,
  .landing-section-icon svg {
    width: 38px;
    height: 38px;
  }

  .landing-section-card strong {
    font-size: 14px;
    overflow-wrap: anywhere;
  }

  .landing-section-card small {
    font-size: 11px;
  }

  .landing-simple-note {
    justify-content: center;
    width: 100%;
    margin: 18px auto 0;
    font-size: 12px;
    line-height: 1.45;
    text-align: center;
  }

  /* Shared B2 header becomes a real stacked mobile toolbar. */
  .app-shell,
  .app-shell.exam-mode-shell,
  .training-focus-shell,
  .training-focus-shell.menu-open {
    padding-top: 0;
  }

  .exam-header {
    position: sticky;
    inset: auto;
    top: 0;
    z-index: 60;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    width: 100%;
    min-height: 0;
    padding: 8px var(--mobile-gutter);
    gap: 7px;
  }

  .header-left,
  .brand,
  .main-nav-wrap,
  .header-actions {
    min-width: 0;
    max-width: 100%;
  }

  .brand {
    width: 100%;
    gap: 8px;
    padding: 0;
  }

  .brand-mark {
    width: 38px;
    height: 38px;
    flex: 0 0 38px;
  }

  .brand strong {
    max-width: calc(100vw - 190px);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .brand small {
    display: none;
  }

  .header-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: nowrap;
    width: auto;
    gap: 5px;
  }

  .header-actions .ghost {
    display: none;
  }

  .header-actions .icon-button,
  .timer {
    flex: 0 0 auto;
    min-height: 40px;
  }

  .timer {
    min-width: 64px;
    padding: 7px;
  }

  .main-nav-wrap {
    grid-column: 1 / -1;
    width: 100%;
  }

  .main-nav-toggle-label {
    min-height: 44px;
  }

  .main-nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
    max-height: min(60dvh, 430px);
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .main-nav-tab {
    min-height: 44px;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .section-subnav,
  .model-subnav,
  .answer-sheet-strip,
  .b1-category-tabs {
    display: flex;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .section-subnav::-webkit-scrollbar,
  .model-subnav::-webkit-scrollbar,
  .answer-sheet-strip::-webkit-scrollbar,
  .b1-category-tabs::-webkit-scrollbar {
    display: none;
  }

  .section-subtab,
  .model-subtab,
  .answer-sheet-pill {
    flex: 0 0 auto;
    min-height: 44px;
  }

  /* Dashboard and overview pages. */
  .dashboard-page,
  .approved-dashboard-page,
  .student-dashboard-page,
  .overview,
  .start-screen,
  .results-page,
  .b1-overview,
  .b1-page,
  .b1-reader-page {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    padding-inline: var(--mobile-gutter);
    margin-inline: 0;
  }

  .dashboard-page {
    padding-block: 14px calc(28px + env(safe-area-inset-bottom));
    border-radius: 0;
  }

  .dashboard-cockpit,
  .dashboard-action-strip,
  .dashboard-grid,
  .model-grid,
  .breakdown-grid,
  .welcome-stats,
  .start-grid,
  .briefing-grid,
  .result-score,
  .formal-grid {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  .dashboard-page .welcome-panel,
  .dashboard-card,
  .start-panel,
  .results-panel {
    width: 100%;
    min-width: 0;
    border-radius: var(--mobile-radius);
  }

  .dashboard-page .welcome-panel {
    padding: 14px;
  }

  .dashboard-page .welcome-stats {
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
  }

  .dashboard-card {
    padding: 0;
  }

  .dashboard-cover {
    max-height: none;
    aspect-ratio: 16 / 8;
  }

  .cockpit-actions,
  .start-actions,
  .result-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    width: 100%;
  }

  .cockpit-actions button,
  .start-actions button,
  .result-actions button {
    width: 100%;
    min-width: 0;
    min-height: 48px;
  }

  /* Exercise layouts: reading and answers become one vertical document. */
  .exam-main,
  .training-focus-shell .exam-main,
  .training-focus-shell.menu-open .exam-main,
  .b1-reader-shell .exam-main {
    width: 100%;
    min-width: 0;
    height: auto;
    min-height: calc(100dvh - 60px);
    overflow: visible;
  }

  .exam-workspace,
  .lesen-teil2-workspace,
  .lesen-teil3-workspace,
  .sprachb2-workspace,
  .writing-layout,
  .muendlich-workspace,
  .b1-exam-workspace,
  .b1-exercise-layout.has-passage {
    display: grid;
    grid-template-columns: minmax(0, 1fr) !important;
    width: 100%;
    min-width: 0;
    height: auto;
    overflow: visible;
  }

  .text-pane,
  .answer-pane,
  .lesen-article-pane,
  .teil2-answer-pane,
  .lesen-teil3-text-pane,
  .lesen-teil3-answer-pane,
  .sprachb2-workspace > *,
  .writing-layout > *,
  .muendlich-workspace > *,
  .b1-passage-pane,
  .b1-questions-pane {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    height: auto;
    max-height: none;
    overflow: visible;
  }

  .text-pane,
  .answer-pane,
  .lesen-article-pane,
  .teil2-answer-pane,
  .lesen-teil3-text-pane,
  .lesen-teil3-answer-pane {
    padding: 14px var(--mobile-gutter) 22px;
  }

  .task-copy,
  .article-copy,
  .passage-card,
  .question-card,
  .teil2-question-card,
  .teil3-info-card,
  .teil3-situation-card,
  .sprachb2-text,
  .prompt-box,
  .writing-source,
  .muendlich-card,
  .b1-question-card,
  .b1-passage-copy {
    min-width: 0;
    max-width: 100%;
    overflow-wrap: anywhere;
    word-break: normal;
  }

  .article-copy,
  .task-copy,
  .b1-passage-copy {
    font-size: 15px;
    line-height: 1.72;
  }

  .choice-grid,
  .rf-choice-list,
  .word-bank,
  .b1-answer-options {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  .answer-choice,
  .rf-choice,
  .teil2-choice,
  .heading-option,
  .word-option,
  .word-bank-option,
  .b1-answer-option {
    width: 100%;
    min-width: 0;
    min-height: 44px;
    overflow-wrap: anywhere;
    text-align: start;
  }

  textarea,
  input[type="text"],
  input[type="search"],
  select {
    width: 100%;
    max-width: 100%;
    font-size: 16px; /* prevents iOS input zoom */
  }

  textarea {
    min-height: 220px;
    resize: vertical;
  }

  /* Hören and native audio controls remain fully usable offline. */
  .hoeren-layout,
  .hoeren-panel,
  .hoeren-answer-block,
  .audio-card,
  .hoeren-question,
  .prompt-box {
    width: 100%;
    min-width: 0;
    max-width: 100%;
  }

  .hoeren-layout {
    padding: 12px var(--mobile-gutter) 24px;
    overflow: visible;
  }

  .hoeren-panel {
    margin: 0;
  }

  audio,
  .audio-card audio {
    display: block;
    width: 100%;
    min-width: 0;
  }

  .hoeren-question .rf-choice {
    min-height: 48px;
  }

  /* Model test: status stays readable and parts swipe horizontally. */
  .model-exam-status {
    width: calc(100% - (2 * var(--mobile-gutter)));
    min-width: 0;
    margin: 12px var(--mobile-gutter);
    padding: 12px;
  }

  .model-status-main,
  .model-status-metrics {
    min-width: 0;
  }

  .model-status-metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .answer-sheet-pill {
    min-width: 128px;
  }

  /* Fixed/sticky controls must not cover the final answer. */
  .exam-footer,
  .b1-shell .b1-exercise-actions {
    position: sticky;
    bottom: 0;
    z-index: 45;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    width: 100%;
    padding: 10px var(--mobile-gutter) calc(10px + env(safe-area-inset-bottom));
    gap: 8px;
    background: color-mix(in srgb, var(--surface) 94%, transparent);
    backdrop-filter: blur(16px);
  }

  .footer-left,
  .footer-right {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    width: 100%;
    gap: 8px;
  }

  .exam-footer button,
  .b1-shell .b1-exercise-actions button {
    width: 100%;
    min-width: 0;
    min-height: 46px;
  }

  /* B1 shell and topics. */
  .b1-shell .b1-header {
    position: sticky;
    top: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    width: 100%;
    min-height: 0;
    padding: 8px var(--mobile-gutter);
    gap: 8px;
  }

  .b1-shell .b1-header-actions {
    grid-column: auto;
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    min-width: 0;
    gap: 5px;
  }

  .b1-shell .main-nav-wrap {
    grid-column: 1 / -1;
  }

  .b1-shell .b1-topic-grid {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  .b1-topic-card {
    grid-template-columns: 44px minmax(0, 1fr);
  }

  .b1-topic-card .primary {
    grid-column: 1 / -1;
    width: 100%;
  }

  .b1-reader-toolbar {
    grid-template-columns: auto minmax(0, 1fr);
    width: 100%;
    min-width: 0;
  }

  /* Vocabulary and dialogs. */
  .private-vocab-grid,
  .private-vocab-quiz-grid {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  .private-image-modal,
  .modal,
  [role="dialog"] {
    width: calc(100% - (2 * var(--mobile-gutter)));
    max-width: 100%;
    max-height: calc(100dvh - (2 * var(--mobile-gutter)));
    overflow: auto;
  }

  /* The landing header keeps the Telegram shortcut; the floating copy would
     otherwise cover answer and submit controls on narrow screens. */
  .telegram-floating-link {
    display: none !important;
  }
}

@media (max-width: 420px) {
  :root {
    --mobile-gutter: 9px;
  }

  .landing-wordmark {
    font-size: 22px;
  }

  .landing-actions .language-switch button,
  .landing-actions .level-switch button {
    min-width: 36px;
    padding-inline: 6px;
  }

  .landing-hero h1 {
    font-size: clamp(28px, 9.2vw, 36px);
  }

  .landing-section-grid {
    gap: 8px;
  }

  .landing-section-card {
    min-height: 105px;
  }

  .dashboard-page .welcome-stats {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  .model-status-metrics {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 340px) {
  .landing-header {
    grid-template-columns: minmax(0, 1fr);
  }

  .landing-actions {
    justify-content: stretch;
  }

  .landing-actions .language-switch,
  .landing-actions .level-switch {
    flex: 1 1 auto;
  }

  .landing-actions .language-switch button,
  .landing-actions .level-switch button {
    flex: 1 1 auto;
  }

  .landing-section-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .landing-section-card:last-child:nth-child(odd) {
    grid-column: auto;
  }
}

@media (orientation: landscape) and (max-height: 520px) and (pointer: coarse) {
  .landing-page {
    padding-top: 16px;
  }

  .landing-section-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .exam-header,
  .b1-shell .b1-header {
    position: static;
  }
}

@media (display-mode: standalone) {
  .landing-header,
  .exam-header,
  .b1-shell .b1-header {
    padding-top: calc(8px + env(safe-area-inset-top));
  }
}
