/* Phones and small tablets: one column, one paper at a time, a shelf along the top to pick it.
   Loaded last so it can override the desktop layout. */

#shelf { display: none; }

@media (max-width: 900px) {
  #desk {
    min-height: 100dvh;
    padding: 6px;
    place-items: stretch;
  }

  #pad {
    width: 100%;
    height: calc(100dvh - 12px);
    min-height: 0;
    padding: 12px 10px 10px;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    gap: 10px;
    border-radius: 12px;
  }
  #pad::before { inset: 5px; border-radius: 8px; }
  #pad > * { grid-column: 1; }

  /* Papers lie flat on a phone: a rotated sheet wastes the little width there is. */
  .paper, #walkman { transform: none; }
  #side, #ledger, #dashboard, #folder { overflow-x: hidden; }

  /* One paper at a time */
  #dashboard, #folder, #ledger { grid-row: 2; display: none; overflow-y: auto; }
  #side { grid-row: 2; display: none; grid-template-rows: none; align-content: start; gap: 12px; overflow-y: auto; }
  #calendar, #walkman, #newspaper { display: none; }
  #pad[data-view="tray"] #folder,
  #pad[data-view="brief"] #dashboard { display: block; }
  #pad[data-view="clock"] #side,
  #pad[data-view="news"] #side { display: grid; }
  #pad[data-view="clock"] #calendar,
  #pad[data-view="clock"] #walkman,
  #pad[data-view="news"] #newspaper { display: block; }

  /* The ledger is a view of its own while a review is open; the tabs still reach the other papers */
  #pad.is-ledger #folder { display: none; }
  #pad[data-view="ledger"] #ledger:not([hidden]) { display: block; }
  #ledger { grid-column: 1; }

  /* Menu and end screens cover the shelf too */
  #menu, #endgame { grid-row: 1 / -1; }

  /* ---- The shelf ---- */
  #shelf {
    display: grid;
    grid-row: 1;
    gap: 6px;
    z-index: 5;
    padding-top: 2px;
  }
  .shelf__time {
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
    padding: 5px 8px;
    background-color: var(--paper);
    background-image: var(--paper-grain);
    border-radius: 3px;
    box-shadow: inset 0 0 14px rgba(120, 90, 40, 0.22), 0 4px 8px rgba(0, 0, 0, 0.4);
  }
  .shelf__dial { width: 40px; height: 40px; }
  .shelf__date b { display: block; font-family: var(--font-head); font-weight: 400; font-size: 17px; line-height: 1.1; text-transform: capitalize; }
  .shelf__date span { font-size: 12px; opacity: 0.7; }
  .shelf__speed { min-width: 56px; min-height: 40px; font-size: 16px; }
  .shelf__tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
  .shelf__tabs::-webkit-scrollbar { display: none; }
  .shelf__tab {
    position: relative;
    flex: 1 0 auto;
    min-height: 44px;
    padding: 4px 11px;
    font-family: var(--font-type);
    font-size: 13px;
    color: var(--text);
    background: #c6a566;
    border: 1px solid rgba(90, 60, 20, 0.55);
    border-radius: 6px 6px 0 0;
    cursor: pointer;
  }
  .shelf__tab[aria-pressed="true"] {
    background-color: var(--paper);
    box-shadow: inset 0 4px 0 var(--ink-red);
  }
  .shelf__tab--ledger { background: #cfe0c8; }
  .shelf__tab--menu { flex: 0 0 auto; background: linear-gradient(#e7c872, #b98e32); font-weight: 700; }
  .shelf__tab:focus-visible { outline: 2px solid var(--ink); outline-offset: -3px; }
  .shelf__badge {
    position: absolute;
    top: -5px;
    right: -3px;
    min-width: 19px;
    padding: 0 5px;
    border-radius: 10px;
    background: var(--ink);
    color: #f6ead0;
    font: 700 12px/19px var(--font-num);
    font-style: normal;
    text-align: center;
  }
  .shelf__badge[hidden] { display: none; }
  .shelf__badge.is-warn { background: var(--ink-red); }

  /* ---- Papers, sized for a narrow screen ---- */
  .paper { padding: 12px 12px; }
  .paper--folder { padding-top: 38px; }
  .gauge { grid-template-columns: 104px minmax(40px, 1fr) 28px 62px; gap: 6px; }
  .gauge__spark { width: 62px; }
  .dash__head h2 { font-size: 19px; }
  .card { padding: 14px 14px 10px; }
  .card__title { font-size: 22px; }
  .card__choices { grid-template-columns: 1fr; gap: 8px; }
  .stamp-btn { min-height: 62px; flex-direction: row; justify-content: space-between; text-align: left; }
  .card__keys { display: none; }
  .card__stamp { font-size: 34px; }
  .cal__day { font-size: 46px; }

  .ledger__book { height: auto; min-height: 100%; grid-template-columns: 1fr; overflow-y: visible; }
  .ledger__page { overflow: visible; padding: 12px 12px 12px 24px; }
  .ledger__page--left, .ledger__page--right { border-radius: 4px; box-shadow: none; }
  .ledger__page--right { margin-top: 8px; }

  .menu__folder { width: 100%; padding: 40px 14px 16px; }
  .rules { max-height: calc(100dvh - 250px); }
  .alerts { top: 8px; width: calc(100% - 16px); }
}

@media (max-width: 420px) {
  .gauge { grid-template-columns: 92px minmax(30px, 1fr) 26px; }
  .gauge__spark { display: none; }
  .gauge__label { font-size: 12px; }
}

/* Landscape phones: the shelf shrinks to one row so the paper keeps its height */
@media (max-width: 900px) and (max-height: 480px) {
  #pad { grid-template-rows: auto minmax(0, 1fr); padding: 8px; }
  .shelf__time { display: none; }
}
