/**
 * The dashboard adapted to a phone screen.
 *
 * Loaded only in the web build, after `dashboard.css`. The point is to avoid a
 * second interface: same screens, with the sidebar becoming a bottom bar and
 * the dial following the width available.
 *
 * The `safe-area-inset` margins handle the notch and Android's gesture bar.
 */

/* ------------------------------------------------- general web tweaks --- */

body.web {
  /* Avoids double-tap zoom and Android's blue tap highlight on buttons. */
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

body.web button,
body.web .nav-item,
body.web .chip {
  touch-action: manipulation;
}

/* In the PWA scrolling is by touch; the desktop's 10px bar only takes room. */
body.web ::-webkit-scrollbar {
  width: 0;
  height: 0;
}

/* --------------------------------------------------------- phone layout - */

@media (max-width: 720px) {
  body {
    font-size: 15px;
  }

  .app {
    flex-direction: column;
  }

  /* The sidebar moves down into bottom navigation, within thumb reach. */
  .sidebar {
    order: 2;
    width: auto;
    flex: 0 0 auto;
    flex-direction: row;
    border-right: 0;
    border-top: 1px solid var(--line);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    gap: 0;
    /* No `backdrop-filter` on purpose: it would create a containing block and
       the fixed top strip (`.side-foot`, a child of this) would position
       itself inside the bar instead of inside the window. */
    background: var(--bg-2);
  }

  .brand {
    display: none;
  }

  nav {
    flex: 1;
    flex-direction: row;
    gap: 2px;
  }

  .nav-item {
    flex: 1;
    flex-direction: column;
    gap: 3px;
    padding: 7px 2px 5px;
    font-size: 10.5px;
    font-weight: 600;
    text-align: center;
    letter-spacing: -0.2px;
    border-radius: 12px;
  }

  .nav-item svg {
    width: 21px;
    height: 21px;
  }

  .nav-item.active {
    background: transparent;
    box-shadow: none;
    color: var(--accent);
  }

  /* The timer always in sight: the sidebar's mini countdown becomes a fixed
     strip at the top, so the time stays visible on the other tabs. */
  .side-foot {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 20;
    margin: 0;
    padding: calc(env(safe-area-inset-top) + 6px) 14px 6px;
    background: rgba(14, 16, 22, 0.94);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--line);
  }

  .mini-timer {
    background: transparent;
    border: 0;
    border-radius: 0;
    padding: 0;
  }

  .mini-timer span {
    font-size: 17px;
  }

  .content {
    order: 1;
    /* In a column flex, without `min-height: 0` the content pushes the bottom
       bar off screen instead of scrolling. */
    min-height: 0;
    padding: calc(env(safe-area-inset-top) + 52px) 14px 22px;
  }

  .view-head {
    margin-bottom: 14px;
  }

  .view-head h1 {
    font-size: 20px;
  }

  .card {
    padding: 15px;
    margin-bottom: 12px;
  }

  /* -------------------------------------------------------------- timer -- */

  .timer-card {
    padding: 18px 14px 16px;
    gap: 14px;
  }

  .mode-tabs button {
    padding: 7px 12px;
    font-size: 12.5px;
  }

  /* The SVG has a viewBox, so shrinking the box is enough. */
  .dial-big {
    width: min(320px, 76vw);
    height: min(320px, 76vw);
  }

  .dial-face span {
    font-size: clamp(38px, 13vw, 54px);
    letter-spacing: -1.5px;
  }

  /* Four buttons do not fit side by side. Instead of leaving one stranded on
     a second row, Start takes the whole first row - it is the primary action -
     and the three secondary ones share the row below. */
  .timer-actions {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    width: 100%;
  }

  .timer-actions .primary {
    grid-column: 1 / -1;
    grid-row: 1;
    min-width: 0;
    padding: 13px 18px;
  }

  .timer-actions .ghost {
    grid-row: 2;
    padding: 10px 6px;
    font-size: 13.5px;
  }

  .task-pick {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
  }

  /* ---------------------------------------------------------------- forms */

  .form-row,
  .form-grid {
    grid-template-columns: 1fr;
  }

  /* Stacked, the date and count fields have to introduce themselves. */
  .form-row label span {
    display: block;
    color: var(--muted);
    font-size: 12px;
    margin-bottom: 5px;
  }

  .form-grid .wide,
  .form-grid button {
    grid-column: 1;
  }

  .form-grid button {
    justify-self: stretch;
  }

  /* Under 16px in a text field makes iOS zoom in on focus. */
  input,
  select {
    font-size: 16px;
    padding: 11px 12px;
  }

  .days {
    gap: 5px;
  }

  .days button {
    flex: 1;
    min-width: 40px;
    padding: 9px 4px;
  }

  /* --------------------------------------------------------------- lists */

  .row {
    padding: 12px 13px;
    gap: 10px;
  }

  /* Decent touch targets: a 32px button is small for a finger. */
  .icon-btn {
    width: 38px;
    height: 38px;
  }

  .check {
    width: 26px;
    height: 26px;
  }

  .check svg {
    width: 15px;
    height: 15px;
  }

  /* ---------------------------------------------------------------- stats */

  .stat-cards {
    grid-template-columns: 1fr 1fr;
  }

  .card.stat strong {
    font-size: 21px;
  }

  .chart {
    height: 150px;
    gap: 4px;
  }

  .chart .col b {
    font-size: 9.5px;
  }

  .subject-row {
    grid-template-columns: 88px 1fr 54px;
    gap: 8px;
    font-size: 12.5px;
  }

  .toast {
    bottom: calc(env(safe-area-inset-bottom) + 78px);
    left: 14px;
    right: 14px;
    transform: translateY(14px);
    text-align: center;
  }

  .toast.show {
    transform: translateY(0);
  }
}

/* Phone in landscape: the top strip eats too much of a short screen. */
@media (max-width: 900px) and (max-height: 460px) {
  .side-foot {
    display: none;
  }

  .content {
    padding-top: calc(env(safe-area-inset-top) + 12px);
  }

  .dial-big {
    width: min(240px, 42vh);
    height: min(240px, 42vh);
  }
}

/* --------------------------------------------------------------- ads ---- */

/**
 * The AdMob banner is drawn by the system on top of the webview, so nothing in
 * the layout knows it is there. `ads.js` publishes the height the banner
 * settled on and the bottom of the interface moves up by exactly that much.
 *
 * With no banner - the browser, or an ad that never loaded - the variable
 * stays at 0 and none of these rules change anything.
 */
:root {
  --ad-height: 0px;
}

@media (max-width: 720px) {
  .sidebar {
    padding-bottom: calc(6px + env(safe-area-inset-bottom) + var(--ad-height));
  }

  .toast {
    bottom: calc(env(safe-area-inset-bottom) + 78px + var(--ad-height));
  }
}
