/* Phone layout for the public site (prod/ only; build_prod.py links it).
   Everything is inside the media query, so desktop looks exactly like index.html. */

/* Floating calculator button and image viewer: never shown on desktop. */
#calcToggle, #calcClose, #imgViewer { display: none; }

@media (max-width: 760px) {
  html { -webkit-text-size-adjust: 100%; }
  body { font-size: 15px; }
  button, .btn, .choice-btn { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }

  /* ---------- header ---------- */
  .topbar {
    position: sticky; top: 0; z-index: 40;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 10px 12px calc(10px);
    padding-top: max(10px, env(safe-area-inset-top));
  }
  .topbar h1 { grid-column: 1 / -1; font-size: 17px; margin: 0; display: flex; align-items: center; min-height: 34px; padding-right: 150px; }
  .topbar #themeBtn, .topbar #resetBtn {
    position: absolute; top: max(10px, env(safe-area-inset-top));
    padding: 7px 10px; font-size: 13px;
  }
  .topbar #resetBtn { right: 12px; }
  .topbar #themeBtn { right: 82px; }
  .topbar #resetBtn { font-size: 0; }
  .topbar #resetBtn::after { content: "Reset"; font-size: 13px; }
  .btn.session-math, .btn.session-rw {
    white-space: normal; line-height: 1.25; padding: 10px 8px; min-height: 46px; font-size: 14px;
  }
  .topbar #browseBtn { padding: 8px 10px; }
  .stats { margin: 0; gap: 8px; }
  .stat-tile { flex: 1; min-width: 0; padding: 4px 6px; display: flex; flex-direction: column; justify-content: center; }
  .stat-tile .val { font-size: 15px; line-height: 1.2; }
  .stat-tile .lbl { font-size: 9.5px; }

  /* In a question, keep the header to the title plus the two session buttons. */
  body:has(#questionView:not([hidden])) .topbar #browseBtn,
  body:has(#questionView:not([hidden])) .topbar .stats { display: none; }

  /* ---------- list ---------- */
  .content { padding: 12px; }
  .list-toolbar { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .list-toolbar select, .list-toolbar input[type=text] { width: 100%; padding: 9px 10px; font-size: 16px; /* 16px stops iOS zoom on focus */ }
  .list-toolbar input[type=text] { grid-column: 1 / -1; }
  .list-toolbar .caption { grid-column: 1 / -1; margin: 0; }

  table.qlist, table.qlist tbody { display: block; }
  table.qlist thead { display: none; }
  table.qlist tbody tr {
    display: grid;
    grid-template-columns: 18px auto 1fr auto;
    grid-template-areas: "dot badge domain type" ". skill skill skill";
    align-items: center;
    column-gap: 8px; row-gap: 3px;
    padding: 11px 4px;
    border-bottom: 1px solid var(--gridline);
  }
  table.qlist td { padding: 0; border: 0; min-width: 0; }
  table.qlist td:nth-child(1) { grid-area: dot; }
  table.qlist td:nth-child(2) { grid-area: badge; }
  table.qlist td:nth-child(3) { grid-area: domain; font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  table.qlist td:nth-child(4) { grid-area: skill; color: var(--text-secondary); font-size: 13.5px; line-height: 1.35; }
  table.qlist td:nth-child(5) { grid-area: type; }
  table.qlist td:nth-child(6) { display: none; }
  table.qlist tbody tr:active { background: var(--chip-bg); }

  /* ---------- question ---------- */
  .qHeader { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; margin-bottom: 10px; }
  .qHeader .spacer { display: none; }
  .qHeader #backBtn { grid-column: 1; justify-self: start; }
  .qHeader .meta { grid-row: 2; grid-column: 1 / -1; font-size: 12px; line-height: 1.4; }
  .qHeader #prevBtn, .qHeader #nextBtn { padding: 8px 14px; }

  .qBody { display: block; overflow: visible; }
  .qPane { min-width: 0; }
  .qPane.split { display: block; font-size: 16px; }
  .qPane.split .card { margin-bottom: 12px; }
  .card { padding: 14px; border-radius: 12px; margin-bottom: 12px; }
  .qPane.split .choice-btn, .choice-btn { padding: 13px 14px; line-height: 1.5; min-height: 48px; }
  .choices { gap: 10px; }
  .stemImg, .rationale-img { width: 100%; height: auto; cursor: zoom-in; }
  #stemCard:has(.stemImg)::after, #answerCard:has(.rationale-img)::after {
    content: "Tap the image to zoom"; display: block; margin-top: 8px;
    font-size: 12px; color: var(--text-muted); text-align: center;
  }
  /* session buttons: name on top, "N left" underneath (mobile.js adds the spans) */
  .btn .sess-name { display: block; font-size: 15px; }
  .btn .sess-p { display: none; }
  .btn .sess-left { display: block; font-size: 12px; font-weight: 500; opacity: .8; margin-top: 1px; }
  .spr-row { flex-wrap: wrap; }
  .spr-row input { flex: 1 1 140px; width: auto; font-size: 16px; padding: 11px 12px; }
  .spr-row .btn { padding: 11px 16px; }
  .result-banner { position: relative; }
  table.data-table { font-size: 13px; }
  table.data-table th, table.data-table td { padding: 6px 7px; }
  .data-table-wrap { margin-left: -2px; margin-right: -2px; }
  .chart-figure svg text { font-size: 15px; }

  /* Calculator: hidden behind a floating button; opens full screen. */
  .calcPane { display: none; }
  body.calc-open .calcPane:not([hidden]) {
    display: block;
    position: fixed; inset: 0; z-index: 200;
    height: auto; border: 0; border-radius: 0;
    padding-top: calc(52px + env(safe-area-inset-top));
    background: var(--surface-1);
  }
  body:has(#questionView:not([hidden])):has(#calcPane:not([hidden])) #calcToggle { display: inline-flex; }
  #calcToggle {
    position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 150;
    align-items: center; gap: 6px;
    padding: 12px 16px; border-radius: 999px; border: 0;
    background: var(--series-blue); color: #fff; font-weight: 600; font-size: 15px;
    box-shadow: 0 6px 18px rgba(0,0,0,.25);
  }
  body.calc-open #calcToggle { display: none !important; }
  body.calc-open #calcClose {
    display: block;
    position: fixed; top: calc(8px + env(safe-area-inset-top)); right: 12px; z-index: 210;
    padding: 9px 16px; font-weight: 600;
  }
  body.calc-open { overflow: hidden; }
  /* leave room so the floating button never covers the last choice */
  body:has(#calcPane:not([hidden])) #answerCard { margin-bottom: 76px; }

  /* Tap a question/rationale image to see it full size. */
  #imgViewer.open {
    display: block; position: fixed; inset: 0; z-index: 300;
    background: #111; overflow: auto; -webkit-overflow-scrolling: touch;
  }
  #imgViewer img { display: block; width: auto; min-width: 100%; max-width: none; height: auto; background: #fff; margin: 70px 0 30px; }
  #imgViewer .close {
    position: fixed; top: calc(10px + env(safe-area-inset-top)); right: 12px; z-index: 301;
    padding: 9px 16px; font-weight: 600;
  }
  #imgViewer .hint { position: fixed; top: calc(18px + env(safe-area-inset-top)); left: 14px; color: #ddd; font-size: 13px; }
}
