/* Touch / phone layout of the question screen. Desktop keeps the program look. */
.pw-m { display: none; }

@media (max-width: 760px), (pointer: coarse) and (max-width: 1024px) {
  .pw-d { display: none !important; }
  .pw-m { display: flex; }
  .pw-gear { display: none !important; }
  body[data-screen=quiz] { background: #ececec; }
  .pw-quiz {
    min-height: 100dvh;
    background: #ececec;
    padding-bottom: calc(76px + env(safe-area-inset-bottom));
    -webkit-tap-highlight-color: transparent;
  }

  /* Header: back arrow + ticket title; then sticky strip with clock and question cells. */
  .pw-mtop { flex-direction: column; position: sticky; top: 0; z-index: 20; }
  .pw-mhead {
    display: flex;
    align-items: center;
    gap: 4px;
    min-height: 52px;
    padding: env(safe-area-inset-top) 12px 0 4px;
    background: #6b6f73;
    color: #fff;
  }
  .pw-mback {
    width: 44px;
    height: 44px;
    flex: none;
    display: grid;
    place-items: center;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: #fff;
    cursor: pointer;
  }
  .pw-mback:active { background: rgba(255, 255, 255, 0.2); }
  .pw-mtitle { min-width: 0; display: flex; flex-direction: column; line-height: 1.2; }
  .pw-mtitle b { font-size: 18px; font-weight: 500; }
  .pw-mtitle small { font-size: 13px; opacity: 0.85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .pw-mleft {
    margin-left: auto;
    flex: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 4px 10px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.15);
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
  }
  .pw-mleft b { font-size: 18px; font-weight: 600; }
  .pw-mleft small { font-size: 11px; opacity: 0.85; }

  .pw-mstrip {
    display: flex;
    align-items: stretch;
    background: #fff;
    height: 44px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
  }
  .pw-mclock {
    flex: none;
    display: grid;
    place-items: center;
    padding: 0 12px;
    font-size: 17px;
    color: #555;
    font-variant-numeric: tabular-nums;
    border-right: 1px solid #e3e3e3;
  }
  .pw-mcells {
    flex: 1;
    display: flex;
    overflow-x: auto;
    scrollbar-width: none;
    scroll-snap-type: x proximity;
  }
  .pw-mcells::-webkit-scrollbar { display: none; }
  .pw-mcells button {
    flex: 1 0 40px;
    min-width: 40px;
    border: 0;
    background: #fff;
    color: var(--pw-ink);
    font: inherit;
    font-size: 18px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    scroll-snap-align: center;
    cursor: pointer;
    position: relative;
  }
  .pw-mcells button.ok { background: #4caf50; color: #fff; }
  .pw-mcells button.bad { background: #e53935; color: #fff; }
  .pw-mcells button.done { background: #3f7fc4; color: #fff; }
  .pw-mcells button.now { box-shadow: inset 0 -4px 0 #2c2c2c; background-color: #e9e9e9; }
  .pw-mcells button.now.ok { background: #388e3c; }
  .pw-mcells button.now.bad { background: #c62828; }
  .pw-mcells button.now.done { background: #2f6aa8; }
  .pw-mcells button:disabled { cursor: default; }

  /* Question text, full-width picture, answer cards with a number badge on the left. */
  .pw-qtext {
    padding: 16px 16px 14px;
    font-size: 18px;
    line-height: 1.35;
    font-weight: 500;
    background: #ececec;
  }
  /* Question text stays visible under the sticky header while answers/picture scroll. */
  .pw-quiz > .pw-qtext {
    position: sticky;
    top: var(--pw-mtop-h, 96px);
    z-index: 15;
    padding: 12px 16px 10px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
  }
  .pw-qmain, .pw-qmain.has-img {
    flex: none;
    flex-direction: column;
    gap: 12px;
    padding: 0 0 16px;
  }
  .pw-qimg { width: 100%; max-width: none; background: #fff; }
  .pw-qimg img { width: 100%; max-height: 52vh; object-fit: contain; }
  .pw-opts, .pw-qmain.has-img .pw-opts { gap: 10px; padding: 0 12px; width: 100%; }
  .pw-opt {
    display: flex;
    align-items: stretch;
    min-height: 60px;
    background: #fff;
    border-radius: 6px;
    overflow: hidden;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
    font-size: 17px;
    line-height: 1.35;
    touch-action: manipulation;
    transition: transform 0.08s, background-color 0.15s;
  }
  .pw-opt:active { transform: scale(0.985); background: #f3f3f3; }
  .pw-on {
    flex: none;
    width: 36px;
    display: flex;
    justify-content: center;
    padding-top: 13px;
    background: #8a8d90;
    color: #fff;
    font-size: 17px;
    font-weight: 600;
  }
  .pw-on::after { content: none; }
  .pw-ot { flex: 1; padding: 12px 14px; }
  .pw-opt.right { background: #c8ebc9; color: var(--pw-ink); }
  .pw-opt.right .pw-on { background: #43a047; }
  .pw-opt.wrong { background: #f7c4c2; color: var(--pw-ink); }
  .pw-opt.wrong .pw-on { background: #e53935; }
  .pw-mtip {
    margin: 0 12px 16px;
    padding: 12px 14px;
    background: #fff4d6;
    border-left: 4px solid #f4b84f;
    border-radius: 6px;
    font-size: 15px;
    line-height: 1.4;
  }

  /* Fixed bottom bar in thumb reach: ПДД / Пояснение + one main action that shows the verdict. */
  .pw-mbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    gap: 8px;
    padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
    background: rgba(236, 236, 236, 0.96);
    border-top: 1px solid #d4d4d4;
  }
  .pw-mbar button {
    min-height: 56px;
    border: 0;
    border-radius: 8px;
    font: inherit;
    cursor: pointer;
    touch-action: manipulation;
  }
  .pw-mbar button:active { filter: brightness(0.9); }
  .pw-mtool {
    flex: none;
    padding: 0 12px;
    background: #fff;
    color: var(--pw-ink);
    font-size: 15px;
    font-weight: 600;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
  }
  .pw-mmain {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #fff;
    line-height: 1.15;
  }
  .pw-mmain b { font-size: 18px; letter-spacing: 0.03em; }
  .pw-mmain small { font-size: 13px; opacity: 0.9; margin-top: 2px; }
  .pw-mmain.skip { background: #fff; color: #555; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12); }
  .pw-mmain.skip b { font-weight: 500; letter-spacing: 0; }
  .pw-mmain.ok { background: #43a047; animation: pw-pop 0.25s ease-out; }
  .pw-mmain.bad { background: #e53935; animation: pw-pop 0.25s ease-out; }
  .pw-mmain.taken { background: #3f7fc4; }
  .pw-mmain.rules { background: var(--pw-rules); }
  .pw-mmain.explain { background: var(--pw-explain); }

  /* ПДД / Пояснение overlay: readable text column, icon hidden. */
  .pw-over { margin-top: 0; }
  .pw-over-bar { height: 44px; font-size: 17px; font-weight: 600; }
  .pw-over-body { display: block; padding: 16px; }
  .pw-over-icon { display: none; }
  .pw-over-text { font-size: 16px; line-height: 1.5; }
  .pw-over-text img { max-width: 100%; height: auto; }
}

/* Menu, pick and result screens on phones. */
@media (max-width: 760px), (pointer: coarse) and (max-width: 1024px) {
  body[data-screen=menu], body[data-screen=pick], body[data-screen=result], body[data-screen=first] { background: #ececec; }
  .pw-shell { min-height: 100dvh; background: #ececec; -webkit-tap-highlight-color: transparent; }
  .pw-head, .pw-foot, .pw-shell > .pw-hint { display: none !important; }
  .pw-shell > .pw-mhead { position: sticky; top: 0; z-index: 20; }
  .pw-mhead.root { padding-left: 16px; }
  .pw-stage {
    display: block;
    padding: 12px 12px calc(24px + env(safe-area-inset-bottom));
  }
  body[data-screen=result] .pw-stage { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }

  .pw-mlist, .pw-mtickets { flex-direction: column; gap: 8px; }
  .pw-mgroup {
    margin: 12px 4px 2px;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #6b6f73;
  }
  .pw-mgroup:first-child { margin-top: 4px; }
  .pw-mcard {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    min-height: 64px;
    padding: 10px 8px 10px 12px;
    border: 0;
    border-radius: 8px;
    background: #fff;
    color: var(--pw-ink);
    font: inherit;
    text-align: left;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
    cursor: pointer;
    touch-action: manipulation;
    transition: transform 0.08s, background-color 0.15s;
  }
  .pw-mcard:active { transform: scale(0.985); background: #f3f3f3; }
  .pw-mic {
    flex: none;
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    border-radius: 10px;
    background: #e3eef9;
    color: var(--pw-blue);
    font-size: 20px;
    font-weight: 700;
  }
  .pw-mcard.exam .pw-mic { background: #fbe4e2; color: var(--pw-red); }
  .pw-msettings { margin-top: 16px; }
  .pw-msettings .pw-mic { background: #eee; color: #555; }
  .pw-mct { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
  .pw-mct b { font-size: 16px; font-weight: 600; line-height: 1.3; }
  .pw-mct small { font-size: 13px; color: #6b6f73; line-height: 1.3; }
  .pw-mchev { flex: none; font-size: 28px; line-height: 1; color: #b0b3b6; padding: 0 4px; }

  /* Ticket grid: 5 per row, square-ish tap targets. */
  .pw-mrandom .pw-mic { background: #e2f1e1; color: var(--pw-green); }
  .pw-mgrid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(56px, 1fr));
    gap: 8px;
  }
  .pw-mtk {
    height: 56px;
    border: 0;
    border-radius: 8px;
    background: #fff;
    color: var(--pw-ink);
    font: inherit;
    font-size: 19px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
    cursor: pointer;
    touch-action: manipulation;
  }
  .pw-mtk:active { background: var(--pw-blue); color: #fff; }

  /* Result: score card, mistakes list, bottom bar. */
  .pw-mscore {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 20px 12px;
    border-radius: 10px;
    color: #fff;
    text-align: center;
  }
  .pw-mscore.ok { background: #43a047; }
  .pw-mscore.bad { background: #e53935; }
  .pw-mscore b { font-size: 40px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; }
  .pw-mscore span { font-size: 18px; font-weight: 500; }
  .pw-mscore small { font-size: 14px; opacity: 0.9; }
  .pw-mmiss .pw-mic { background: #fbe4e2; color: #c62828; font-size: 17px; }
  .pw-mmiss .pw-mct b {
    font-weight: 500;
    font-size: 15px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
  .pw-mmiss em { font-style: normal; font-weight: 700; }
  .pw-mmiss em.bad { color: #c62828; }
  .pw-mmiss em.ok { color: #2e7d32; }

  /* Category / options popup. */
  .pw-options-layer { padding: 16px; gap: 16px; overflow-y: auto; justify-content: flex-start; padding-top: calc(16px + env(safe-area-inset-top)); }
  .pw-offline-body { padding: 14px; }
  .pw-offline-btn { min-height: 48px; }
  .pw-options-layer .pw-hint { display: none; }
  .pw-options { width: 100%; max-width: 420px; border-radius: 10px; overflow: hidden; }
  .pw-options .pw-row { padding: 14px 20px; line-height: 1.3; min-height: 56px; }
  .pw-options .pw-cap { padding: 10px 12px; }
}

@keyframes pw-pop {
  from { transform: scale(0.96); }
  to { transform: scale(1); }
}
