/* ---------- wersja web: logowanie, ładowanie, telefon/iPad ---------- */
#logowanie, #ladowanie { position: fixed; inset: 0; z-index: 200; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
  background: radial-gradient(80% 60% at 50% 0%, #1d1d22, #0f0f10); padding: 24px; }
.log-okno { width: min(380px, 100%); display: flex; flex-direction: column; gap: 12px; padding: 28px 24px !important; }
.log-logo { text-align: center; margin-bottom: 6px; } .log-logo b { display: block; font-size: 30px; letter-spacing: 3px; font-weight: 600; color: #ededed; }
.log-logo span { font: 13px var(--w-mono, monospace); color: #85858b; letter-spacing: 6px; }
.log-in { width: 100%; height: 46px; border: 0; border-radius: 12px; padding: 0 14px; font: inherit; font-size: 16px; color: #ededed;
  background: rgba(255, 255, 255, .07); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .1); outline: none; }
.log-in:focus { box-shadow: inset 0 0 0 1.5px var(--akcent, #8e5cff); }
.log-in::-webkit-caps-lock-indicator { display: none; }   /* własna strzałka Safari stała krzywo w polu */
.log-caps { margin-top: -4px; padding-left: 14px; display: flex; align-items: center; gap: 6px; font-size: 12.5px; line-height: 18px; color: var(--akcent, #a78bfa); }
.log-caps[hidden] { display: none; }
.log-caps b { display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 5px; font-size: 12px; background: rgba(142, 92, 255, .18); }
#log-tryb { align-self: center; }
.lad-pasek { width: 180px; height: 3px; border-radius: 3px; background: rgba(255, 255, 255, .08); overflow: hidden; }
.lad-pasek i { display: block; height: 100%; width: 40%; border-radius: 3px; background: var(--akcent, #8e5cff); animation: lad 1.1s ease-in-out infinite; }
@keyframes lad { 0% { transform: translateX(-100%); } 100% { transform: translateX(260%); } }
/* (przywrócone – ChatGPT usunął style ekranu logowania i ładowania; bez nich na iPadzie/PC logowanie było rozwalone) */

/*
 * MATURA27 — wersja mobilna
 * Autor: ChatGPT
 * Zakres: telefony, małe tablety, Safari iOS oraz Android.
 * Zasada: nie zmieniamy logiki aplikacji ani desktopowego układu.
 */

/* ---------- wspólne poprawki dotykowe ---------- */
html, body {
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
body { padding-top: env(safe-area-inset-top); }
button, input, select, textarea { touch-action: manipulation; }
button, .chip, .seg button, .check, .sw { -webkit-touch-callout: none; }
input, textarea { user-select: text; -webkit-user-select: text; }
#logowanie, #ladowanie {
  min-height: 100vh;
  min-height: 100dvh;
  padding: max(24px, env(safe-area-inset-top)) 20px max(24px, env(safe-area-inset-bottom));
}
.log-okno { width: min(420px, 100%); }

/* ---------- telefony i tablety w pionie ---------- */
@media (max-width: 900px) {
  html, body {
    width: 100%;
    height: 100%;
    min-height: 100%;
    overflow: hidden;
  }

  #app {
    position: fixed;
    inset: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 0 !important;
    padding: 0 !important;
    min-width: 0;
    min-height: 0;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
  }

  /* Nawigacja jako wysuwana szuflada */
  #boczny {
    position: fixed !important;
    z-index: 120;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(320px, 88vw);
    max-width: 360px;
    padding: max(22px, env(safe-area-inset-top)) 14px max(18px, env(safe-area-inset-bottom)) !important;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    transform: translate3d(-105%, 0, 0);
    transition: transform .26s cubic-bezier(.2, .8, .2, 1);
    border-radius: 0 !important;
    box-shadow: none;
    will-change: transform;
  }
  body.menu-otwarte #boczny {
    transform: translate3d(0, 0, 0);
    box-shadow: 18px 0 55px rgba(0, 0, 0, .48);
  }
  body.menu-otwarte::after {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 110;
    background: rgba(0, 0, 0, .56);
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
  }
  #menu-btn {
    display: inline-flex !important;
    flex: 0 0 40px;
    width: 40px !important;
    height: 40px !important;
    min-width: 40px;
    padding: 0 !important;
    align-items: center;
    justify-content: center;
    border-radius: 11px !important;
  }
  .logo { margin-bottom: 14px; }

  /* Główna część ekranu */
  #main {
    display: flex;
    flex-direction: column;
    gap: 12px !important;
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    padding: max(12px, env(safe-area-inset-top)) 13px max(12px, env(safe-area-inset-bottom)) !important;
  }
  #gorny {
    flex: 0 0 auto;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 9px;
    min-width: 0;
    padding: 0 1px 2px;
  }
  #tytul {
    flex: 1 1 0;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: clamp(21px, 6vw, 27px) !important;
    line-height: 1.15;
    padding: 0 !important;
    letter-spacing: -.5px;
  }
  #gra-pill {
    order: 3;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    margin: 0 !important;
    padding: 8px 11px !important;
    gap: 12px !important;
    border-radius: 10px !important;
    overflow-x: auto;
    overflow-y: hidden;
    white-space: nowrap;
    scrollbar-width: none;
  }
  #gra-pill::-webkit-scrollbar { display: none; }
  #gra-pill .p { flex: 0 0 auto; }
  .xpbar { width: 82px; }

  #tresc {
    flex: 1 1 auto;
    width: 100%;
    min-width: 0;
    min-height: 0;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
    padding: 1px 0 max(18px, env(safe-area-inset-bottom)) !important;
  }
  #tresc > * { min-width: 0; max-width: 100%; }

  /* Karty, kafelki i siatki */
  .siatka, .siatka.s2, .siatka.s3, .siatka.s4, .siatka.s32 {
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 10px !important;
  }
  .karta { padding: 16px !important; border-radius: 14px !important; }
  .karta h2 { font-size: 17px; line-height: 1.3; flex-wrap: wrap; }
  .karta h3 { margin-top: 13px; }
  .kafel { min-width: 0; padding: 14px 15px !important; border-radius: 12px !important; }
  .kafel .w { font-size: 27px; }
  .duzy { font-size: clamp(32px, 10vw, 42px) !important; }
  .wiersz { min-width: 0; gap: 8px; }
  .wiersz > * { min-width: 0; }
  .wiersz > .lg-btn { flex: 0 0 auto; }
  .lg { min-width: 0; }
  .scroll { max-width: 100%; }
  .szary, .slaby { overflow-wrap: anywhere; }

  /* Przyciski i pola: wygodne cele dotykowe */
  .lg-btn { min-height: 38px; }
  .lg-btn.maly { min-height: 34px; padding: 0 10px !important; }
  .lg-btn.ikona { min-width: 36px; min-height: 36px; }
  .chip { min-height: 34px; padding: 7px 11px; }
  .seg { max-width: 100%; flex-wrap: wrap; }
  .seg button { min-height: 34px; }
  input.lg-in, select.lg-sel, .log-in, textarea {
    min-height: 42px;
    max-width: 100%;
    font-size: 16px !important; /* zapobiega auto-zoomowi Safari */
  }
  input[type="range"] { min-height: 28px; }
  .abcd { display: flex; flex-wrap: wrap; gap: 8px; }
  .abcd .lg-btn { min-width: 48px; min-height: 46px; }

  /* Plan, historia, ranking i listy */
  .blok { align-items: flex-start; gap: 9px; padding: 11px 10px; border-radius: 11px; }
  .blok .t { overflow-wrap: anywhere; }
  .blok .lg-btn { flex: 0 0 auto; }
  .rank-r {
    grid-template-columns: 28px minmax(0, 1fr) auto !important;
    gap: 8px;
    padding: 10px 8px;
    min-width: 0;
  }
  .rank-r .rank-p, .rank-r > .w-meta:last-child { display: none !important; }
  .rank-n { min-width: 0; overflow-wrap: anywhere; }
  .rank-l { white-space: nowrap; }

  /* Zadania: treść nad tablicą, bez poziomego ścisku */
  #widok-zad {
    display: flex !important;
    flex-direction: column;
    gap: 10px;
    width: 100%;
    height: auto !important;
    min-height: 100%;
    overflow: visible !important;
  }
  #widok-zad > .panel-zad,
  #widok-zad > .lg.panel-zad {
    width: 100%;
    min-width: 0;
    min-height: 0;
    flex: 0 0 auto;
    padding: 11px !important;
    overflow: visible;
  }
  #widok-zad .splitter { display: none !important; }
  #widok-zad .meta { flex-wrap: wrap; gap: 7px; }
  #z-meta { flex: 1 1 100%; white-space: normal; }
  #z-papier {
    width: 100%;
    min-height: 260px;
    max-height: 58vh;
    max-height: 58dvh;
    flex: 0 1 auto;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    padding: 9px;
  }
  #z-papier img { max-width: 100%; height: auto; }
  .cke-kartka {
    padding: 12px 13px 18px;
    font-size: 15px;
    line-height: 1.5;
    overflow-wrap: anywhere;
  }
  .cke-kartka .cke-nag { flex-wrap: wrap; font-size: 15px; }
  .cke-kartka .cke-dz { margin-left: auto; }
  .cke-kartka .cke-pole { height: 125px; }
  .odp { min-width: 0; }
  .odp input, .odp select, .odp textarea { max-width: 100%; }
  .panel-tab { min-width: 0; padding: 10px !important; }
  .pasek-tab {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 7px;
  }
  #t-kol { flex: 1 1 100%; flex-wrap: wrap; margin-left: 0 !important; }
  #t-w { width: min(120px, 35vw) !important; }
  .tab-wrap {
    width: 100%;
    min-height: 220px;
    height: 34vh;
    max-height: 420px;
    overflow: hidden;
    touch-action: none;
  }

  /* Tabele: przewijanie zamiast rozjeżdżania layoutu */
  .tab-scroll, .tabela-wrap, .lg-tab-wrap {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  table, .lg-tab { max-width: 100%; }
  .lg-tab { font-size: 12px; }
  .lg-tab td, .lg-tab th { padding: 8px 9px; }
  pre, code { max-width: 100%; overflow-x: auto; }

  /* Okna modalne i komunikaty */
  .modal {
    position: fixed;
    z-index: 180;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: max(12px, env(safe-area-inset-top)) 10px max(12px, env(safe-area-inset-bottom));
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .modal > .lg, .modal > .karta {
    width: min(620px, 100%) !important;
    max-width: 100% !important;
    max-height: 100% !important;
    min-width: 0 !important;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 14px !important;
    padding: 15px !important;
  }
  #toasty {
    left: 10px;
    right: 10px;
    bottom: max(12px, env(safe-area-inset-bottom));
    width: auto;
  }
  .toast { max-width: 100%; }

  /* Nie pozwalamy pojedynczym elementom rozszerzać ekranu */
  img, video, canvas, svg { max-width: 100%; }
  .mini, .odz { min-width: 0; }
}

/* ---------- telefony poziomo ---------- */
@media (max-width: 900px) and (orientation: landscape) {
  #main { gap: 8px !important; padding: 8px 12px !important; }
  #gorny { flex-wrap: nowrap; }
  #gra-pill { order: initial; width: auto; margin-left: auto !important; }
  #widok-zad {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) !important;
    grid-template-rows: minmax(0, 1fr);
    height: 100% !important;
    min-height: 0;
    overflow: hidden !important;
  }
  #widok-zad > .panel-zad { min-height: 0; overflow-y: auto; }
  #z-papier { max-height: none; min-height: 220px; }
  .tab-wrap { height: 45vh; }
}

/* ---------- bardzo małe ekrany ---------- */
@media (max-width: 380px) {
  #main { padding-left: 10px !important; padding-right: 10px !important; }
  .karta { padding: 13px !important; }
  .kafel { padding: 12px !important; }
  #gra-pill { gap: 8px !important; }
  .rank-r { grid-template-columns: 24px minmax(0, 1fr) auto !important; }
}

/* ---------- tablety w poziomie ---------- */
@media (min-width: 700px) and (max-width: 900px) {
  .siatka.s2, .siatka.s32 { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
  .siatka.s3, .siatka.s4 { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
}

/* Szanuj ustawienie ograniczenia animacji systemu. */
@media (prefers-reduced-motion: reduce) {
  #boczny { transition: none !important; }
}



/* ==========================================================
   MOBILE V2 — ChatGPT
   Real mobile dashboard, compact stats and bottom navigation.
   ========================================================== */
@media (max-width: 900px) {
  html, body {
    background: transparent !important;
    min-height: 100%;
    min-height: 100dvh;
  }
  #tlo { position: fixed; inset: 0; z-index: -1; }
  #app { bottom: 0; min-height: 0; }
  #main {
    padding-bottom: 76px !important;
  }
  #gra-pill {
    display: grid !important;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    align-items: center;
    gap: 8px 12px !important;
    overflow: visible !important;
    white-space: normal !important;
    padding: 10px 12px !important;
    border-radius: 15px !important;
  }
  #gra-pill .p { min-width: 0; overflow: hidden; }
  #gra-pill .p b, #gra-pill .p small {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  #gra-pill .xpbar { width: 100%; max-width: 90px; }

  /* Dashboard hero: countdown first, exam dates below it. */
  #tresc > .wejscie > .siatka.s32:first-child {
    display: block !important;
  }
  #tresc > .wejscie > .siatka.s32:first-child > .karta:first-child {
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 16px !important;
    padding: 19px !important;
  }
  #tresc > .wejscie > .siatka.s32:first-child > .karta:first-child > div:first-child {
    flex: none !important;
    min-width: 0;
  }
  #tresc > .wejscie > .siatka.s32:first-child > .karta:first-child > div:first-child > div:first-child {
    font-size: clamp(22px, 6vw, 29px) !important;
    line-height: 1.2;
  }
  #odl-cel { font-size: 14px; line-height: 1.4; }
  #odl {
    font-size: clamp(35px, 10vw, 49px) !important;
    line-height: 1.08;
    overflow-wrap: anywhere;
  }
  #tresc > .wejscie > .siatka.s32:first-child > .karta:first-child > div:last-child {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 9px 12px;
    text-align: left !important;
    border-top: 1px solid rgba(255,255,255,.12);
    padding-top: 13px;
    font-size: 12px;
    line-height: 1.35;
  }
  #tresc > .wejscie > .siatka.s32:first-child > .karta:first-child > div:last-child > div {
    min-width: 0;
    margin: 0 !important;
    overflow-wrap: anywhere;
  }
  #tresc > .wejscie > .siatka.s32:nth-child(2) {
    display: grid !important;
    grid-template-columns: minmax(0,1fr) !important;
  }
  #tresc > .wejscie > .siatka.s32:nth-child(2) > .karta {
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    text-align: center;
    gap: 13px !important;
  }
  #tresc > .wejscie > .siatka.s32:nth-child(2) .ring {
    width: 112px;
    height: 112px;
  }
  #tresc > .wejscie > .siatka.s32:nth-child(2) > .karta > div:last-child {
    width: 100%;
    text-align: left;
  }
  #tresc .siatka.s4 {
    grid-template-columns: repeat(2, minmax(0,1fr)) !important;
  }
  #tresc .siatka.s4 .kafel { padding: 13px !important; }
  #tresc .siatka.s4 .kafel .w { font-size: clamp(20px, 6vw, 26px); }

  /* Persistent native-app-like tab bar. */
  #mobile-tabs {
    position: fixed;
    z-index: 105;
    left: 10px;
    right: 10px;
    bottom: max(8px, env(safe-area-inset-bottom));
    display: grid;
    grid-template-columns: repeat(5, minmax(0,1fr));
    gap: 3px;
    padding: 7px 5px;
    border: 1px solid rgba(255,255,255,.16);
    border-radius: 20px;
    background: rgba(25, 17, 43, .88);
    -webkit-backdrop-filter: blur(24px) saturate(150%);
    backdrop-filter: blur(24px) saturate(150%);
    box-shadow: 0 8px 30px rgba(0,0,0,.32), inset 0 1px rgba(255,255,255,.12);
  }
  #mobile-tabs button {
    appearance: none;
    border: 0;
    min-width: 0;
    min-height: 48px;
    padding: 5px 2px;
    border-radius: 13px;
    color: rgba(255,255,255,.68);
    background: transparent;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    font: inherit;
    font-size: 10px;
    font-weight: 600;
  }
  #mobile-tabs button .ik { width: 20px; height: 20px; }
  #mobile-tabs button.akt {
    color: #fff;
    background: rgba(167,139,250,.24);
  }
}
@media (max-width: 380px) {
  #gra-pill { grid-template-columns: repeat(2, minmax(0,1fr)); }
  #tresc > .wejscie > .siatka.s32:first-child > .karta:first-child > div:last-child {
    grid-template-columns: minmax(0,1fr);
  }
}


/* ==========================================================
   MOBILE V3 — fixes from iPhone testing feedback
   Author: ChatGPT
   ========================================================== */
@media (max-width: 900px) {
  /* iOS WebViews can over-blur the entire composited page when
     backdrop-filter is applied to a full-screen pseudo-element. */
  body.menu-otwarte::after {
    -webkit-backdrop-filter: none !important;
    backdrop-filter: none !important;
    background: rgba(8, 6, 16, .42) !important;
  }
  body.menu-otwarte #boczny {
    z-index: 121 !important;
    background: rgba(25, 17, 43, .98) !important;
    -webkit-backdrop-filter: none !important;
    backdrop-filter: none !important;
    filter: none !important;
  }
  #mobile-tabs {
    padding: 5px 4px !important;
    gap: 2px !important;
    border-radius: 18px !important;
  }
  #mobile-tabs button {
    min-height: 54px !important;
    padding: 4px 1px !important;
    gap: 2px !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    font-size: 9px !important;
    letter-spacing: -.2px;
  }
  #mobile-tabs button > span:first-child {
    display: block !important;
    font-size: 25px !important;
    line-height: 1.05 !important;
    height: 27px;
  }
  #mobile-tabs button > span:last-child {
    display: block !important;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1.1;
  }
  #mobile-tabs button.akt {
    background: rgba(167,139,250,.27) !important;
  }
}


/* MOBILE TOP SAFE AREA — match the iOS status-bar strip to the app canvas.
   Author: ChatGPT */
@media (max-width: 900px) {
  html, body {
    background-color: transparent !important;
  }
  body {
    padding-top: env(safe-area-inset-top) !important;
  }
}


/* MOBILE SIDEBAR TAP FIX — ChatGPT
   Keep the drawer and its actual navigation controls above the scrim
   and make the decorative glass pill non-interactive. */
@media (max-width: 900px) {
  body.menu-otwarte #boczny {
    z-index: 130 !important;
    pointer-events: auto !important;
    isolation: isolate;
  }
  body.menu-otwarte #boczny::before,
  body.menu-otwarte #boczny::after,
  body.menu-otwarte #nav::before,
  body.menu-otwarte #nav::after,
  body.menu-otwarte #nav .nav-pill {
    pointer-events: none !important;
  }
  body.menu-otwarte #nav {
    position: relative !important;
    z-index: 2 !important;
    pointer-events: auto !important;
    touch-action: pan-y;
  }
  body.menu-otwarte #nav button[data-k] {
    position: relative !important;
    z-index: 3 !important;
    display: flex !important;
    pointer-events: auto !important;
    touch-action: manipulation !important;
    -webkit-tap-highlight-color: transparent;
    cursor: pointer;
  }
  /* The old body pseudo-element sat above #app's fixed stacking
     context, so it intercepted every tap on the drawer. Put the scrim
     inside #main instead, below the sibling sidebar. */
  body.menu-otwarte::after {
    content: none !important;
    display: none !important;
    pointer-events: none !important;
  }
  body.menu-otwarte #main {
    position: relative !important;
    z-index: 110 !important;
  }
  body.menu-otwarte #main::after {
    content: "" !important;
    display: block !important;
    position: absolute !important;
    inset: 0 !important;
    z-index: 20 !important;
    background: rgba(8, 6, 16, .42) !important;
    pointer-events: auto !important;
  }
  body.menu-otwarte #boczny {
    z-index: 130 !important;
  }
}


/* MOBILE SAFE-AREA RESET — ChatGPT
   The body-level top inset was being applied in addition to #main's own
   safe-area padding. Keep fixed UI anchored to the actual viewport. */
@media (max-width: 900px) {
  body {
    padding-top: 0 !important;
  }
  #mobile-tabs {
    bottom: 4px !important;
  }
  /* Avoid a blur layer bleeding into the top edge in iOS WebViews. */
  body.menu-otwarte::after {
    -webkit-backdrop-filter: none !important;
    backdrop-filter: none !important;
  }
}


/* MOBILE DRAWER SWIPE — disable transition only while the finger controls the drawer. */
@media (max-width: 900px) {
  #boczny.is-dragging {
    transition: none !important;
    will-change: transform;
  }
}


/* MOBILE TEXT DENSITY — ChatGPT
   Reduce visual noise without shrinking exam/task content or removing information. */
@media (max-width: 900px) {
  /* Secondary copy should support the main point, not dominate every card. */
  #tresc .karta > p,
  #tresc .karta > .szary,
  #tresc .karta > .slaby {
    font-size: 12.5px !important;
    line-height: 1.4 !important;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    overflow: hidden;
  }
  #tresc .karta h2 { margin-bottom: 8px !important; }
  #tresc .karta h3 { margin-top: 10px !important; margin-bottom: 5px !important; }
  #tresc .karta .szary,
  #tresc .karta .slaby,
  #tresc .kafel small,
  #tresc .blok .t small {
    font-size: 11.5px !important;
    line-height: 1.35 !important;
  }
  #tresc .kafel small,
  #tresc .blok .t small {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  #tresc .karta,
  #tresc .kafel { gap: 9px; }
  #tresc .karta { padding: 14px !important; }
  #tresc .kafel { padding: 11px 12px !important; }

  /* Keep actual learning material and feedback readable and complete. */
  #widok-zad, #widok-zad *,
  .cke-kartka, .papier, .ziomek,
  .modal, .modal *,
  input, textarea, select,
  #mobile-tabs, #mobile-tabs * {
    -webkit-line-clamp: unset;
  }
}


/* MOBILE DASHBOARD CLEANUP + TAB BAR ANCHOR — ChatGPT */
@media (max-width: 900px) {
  /* Keep the bottom navigation pinned to the viewport, independent of
     content height and iOS safe-area padding. */
  body > #mobile-tabs {
    position: fixed !important;
    left: 10px !important;
    right: 10px !important;
    bottom: 4px !important;
    top: auto !important;
    margin: 0 !important;
    transform: none !important;
    z-index: 999 !important;
    box-sizing: border-box !important;
  }
  body > #mobile-tabs button {
    min-height: 48px !important;
  }

  /* Dashboard: retain the headline figures, remove repeated explanatory copy. */
  #tresc > .wejscie > .siatka.s4 .kafel small {
    font-size: 10px !important;
    line-height: 1.25 !important;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  #tresc > .wejscie > .siatka.s4 .kafel small:last-child {
    display: none !important;
  }
  #tresc > .wejscie > .siatka.s32:nth-child(2) > .karta .slaby {
    display: none !important;
  }
  #tresc > .wejscie #dzis-plan .blok .t small {
    display: none !important;
  }
  #tresc > .wejscie #dzis-plan .blok:nth-child(n+4) {
    display: none !important;
  }
  #tresc > .wejscie #start-akt .w-meta {
    font-size: 11px !important;
    line-height: 1.25 !important;
  }
  #tresc > .wejscie #start-akt .mini .w-meta {
    display: none !important;
  }
  #tresc > .wejscie #start-akt .siatka.s4 {
    margin: 8px 0 12px !important;
    gap: 7px !important;
  }
}


/* Paint a dark fallback immediately, before app.js finishes loading user settings.
   The selected .tlo-* class still overrides #tlo with its own full background. */
@media (max-width: 900px) {
  html, body { background: #140e24 !important; }
  #tlo {
    background-color: #1d1240;
    background-repeat: no-repeat;
  }
}


/* ChatGPT: remove the iOS top-edge blur completely on mobile.
   Keep the configurator's solid panel, but do not blur the viewport behind it. */
@media (max-width: 900px) {
  #kw.modal,
  #kw.modal::before,
  #kw.modal::after {
    -webkit-backdrop-filter: none !important;
    backdrop-filter: none !important;
  }
  html, body, #app, #main, #tlo {
    -webkit-backdrop-filter: none !important;
    backdrop-filter: none !important;
  }
  html::before, html::after,
  body::before, body::after,
  #app::before, #app::after,
  #main::before, #main::after,
  #tlo::before, #tlo::after {
    -webkit-backdrop-filter: none !important;
    backdrop-filter: none !important;
  }
  body {
    padding-top: 0 !important;
    margin-top: 0 !important;
  }
}


/* ==========================================================
   MOBILE UX REDESIGN V1 — readable, touch-first layout
   Author: ChatGPT
   This is a single final mobile layer; desktop styles stay intact.
   ========================================================== */
@media (max-width: 900px) {
  html, body { font-size: 15px; }

  #main {
    gap: 14px !important;
    padding: max(14px, env(safe-area-inset-top)) 15px max(14px, env(safe-area-inset-bottom)) !important;
  }
  #gorny { gap: 11px; }
  #menu-btn {
    width: 44px !important;
    height: 44px !important;
    min-width: 44px;
    border-radius: 14px !important;
  }
  #tytul {
    font-size: clamp(22px, 6vw, 28px) !important;
    font-weight: 760;
  }

  /* Keep useful progress visible without turning the header into a dashboard. */
  #gra-pill {
    display: grid !important;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 9px 12px !important;
    padding: 11px 13px !important;
    border-radius: 16px !important;
    overflow: visible !important;
    white-space: normal !important;
  }
  #gra-pill .p { min-width: 0; overflow: hidden; }
  #gra-pill .p small { font-size: 12px !important; }
  #gra-pill .p b { font-size: 14px; overflow-wrap: anywhere; white-space: normal; }
  #gra-pill .xpbar { width: 100%; max-width: 100%; }

  #tresc {
    padding: 2px 0 112px !important;
    scroll-padding-bottom: 112px;
  }

  /* Cards: readable type and real breathing room. No blanket line-clamping. */
  #tresc .karta {
    padding: 18px !important;
    border-radius: 18px !important;
    gap: 13px;
  }
  #tresc .karta h2 { font-size: 19px !important; line-height: 1.3; }
  #tresc .karta h3 { font-size: 15px !important; margin: 14px 0 7px !important; }
  #tresc .karta p,
  #tresc .karta > .szary,
  #tresc .karta > .slaby {
    display: block !important;
    font-size: 14px !important;
    line-height: 1.5 !important;
    overflow: visible !important;
    -webkit-line-clamp: unset !important;
    line-clamp: unset !important;
  }
  #tresc .kafel {
    padding: 15px !important;
    border-radius: 16px !important;
  }
  #tresc .kafel .w { font-size: clamp(23px, 6.5vw, 29px) !important; }
  #tresc .kafel small,
  #tresc .blok .t small {
    font-size: 12.5px !important;
    line-height: 1.4 !important;
  }

  /* Dashboard: balanced two-column stats, one clear column for content. */
  #tresc .siatka.s4 {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 10px !important;
  }
  #tresc > .wejscie > .siatka.s32:first-child > .karta:first-child {
    padding: 20px !important;
    gap: 15px !important;
  }
  #odl { font-size: clamp(34px, 9vw, 46px) !important; line-height: 1.12; }
  #tresc > .wejscie > .siatka.s32:first-child > .karta:first-child > div:last-child {
    font-size: 13px;
    line-height: 1.45;
  }

  /* All interactive controls should be comfortable to tap. */
  #tresc button,
  #tresc .chip,
  #tresc .seg button,
  #tresc .check {
    min-height: 44px;
  }
  #tresc input.lg-in,
  #tresc select.lg-sel,
  #tresc textarea,
  #tresc input:not([type="checkbox"]):not([type="radio"]):not([type="range"]) {
    min-height: 46px;
    font-size: 16px !important;
  }

  /* Drawer is a proper navigation surface, not a narrow desktop list. */
  #boczny {
    width: min(340px, 88vw) !important;
    padding: max(24px, env(safe-area-inset-top)) 16px max(20px, env(safe-area-inset-bottom)) !important;
  }
  #boczny .logo { margin-bottom: 20px; }
  #boczny .nav { gap: 5px; }
  #boczny .nav button {
    min-height: 48px;
    padding: 12px 15px;
    border-radius: 14px;
    font-size: 15px;
  }

  /* Bottom navigation: four destinations plus an explicit More menu. */
  body > #mobile-tabs {
    left: 12px !important;
    right: 12px !important;
    bottom: 5px !important;
    padding: 7px 6px !important;
    gap: 4px !important;
    border-radius: 20px !important;
    background: rgba(22, 16, 38, .96) !important;
    -webkit-backdrop-filter: none !important;
    backdrop-filter: none !important;
  }
  #mobile-tabs button {
    min-height: 58px !important;
    gap: 4px !important;
    padding: 5px 2px !important;
    border-radius: 14px !important;
    font-size: 12px !important;
    font-weight: 650;
    letter-spacing: 0 !important;
  }
  #mobile-tabs button > span:first-child {
    height: 25px !important;
    font-size: 23px !important;
    line-height: 1.1 !important;
  }
  #mobile-tabs button > span:last-child {
    font-size: 11.5px !important;
    line-height: 1.15;
  }
  #mobile-tabs button.akt { background: rgba(167,139,250,.32) !important; }

  /* Keep learning material readable and preserve the existing task layout. */
  .cke-kartka { font-size: 16px !important; line-height: 1.55 !important; }
  .cke-kartka .cke-pole { min-height: 125px; }
  .blok { padding: 13px 12px !important; border-radius: 14px !important; }
}
@media (max-width: 380px) {
  #main { padding-left: 12px !important; padding-right: 12px !important; }
  #gra-pill { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #mobile-tabs button > span:last-child { font-size: 10.5px !important; }
}

body:has(#logowanie) .m2-tabs, body:has(#ladowanie) .m2-tabs { display: none !important; }
