/* Phone mode (spec 11.8): a monochrome phone from 2000. The page is the green LCD.
   Only html[data-mode="phone"] shows it, and only a phone gets that mode (mode.js).
   Ink #1d2b14 on #bcd193 to #a6bd79: 9.0:1 and 7.2:1. VT323 is self-hosted
   (logbook.css). Dynamic values (battery, scroll bar) come from JS through CSSOM.
   One scroll container: the page itself. The status row and the post title stick to
   the top, and the softkeys stick to the bottom. No box inside scrolls up and down,
   so a swipe anywhere on the screen scrolls the post. */

/* Switches to phone mode render on phones only. */
:root:not([data-device="phone"]) .phone-only { display: none !important; }

phone-shell { display: none; }
:root[data-mode="phone"] {
  --ph-ink: #1d2b14; --ph-lcd: #bcd193; --ph-lcd-lo: #a6bd79; --ph-inv: #b4c98a;
  /* The height of the status row. The post title sticks under it. */
  --ph-top: calc(46px + env(safe-area-inset-top, 0px));
  --ph-grid: linear-gradient(rgba(29,43,20,.03) 1px, transparent 1px), linear-gradient(90deg, rgba(29,43,20,.03) 1px, transparent 1px);
}
[data-mode="phone"] body { background: var(--ph-lcd-lo); }
[data-mode="phone"] .taskbar { display: none; }
[data-mode="phone"] blog-app:not([data-current="write"], [data-current="setup"]) .desktop { display: none; }
[data-mode="phone"] blog-app:not([data-current="write"], [data-current="setup"]) phone-shell {
  display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh;
  padding: 0 env(safe-area-inset-right, 0px) 0 env(safe-area-inset-left, 0px);
  color: var(--ph-ink); font: 400 26px/1.1 var(--f-lcd); -webkit-tap-highlight-color: transparent;
}
/* The LCD: a gradient with a faint 3 px pixel grid, fixed to the screen behind the
   page. The sticky bars use the colors at the top and the bottom of it. */
phone-shell::before {
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background: var(--ph-grid), linear-gradient(var(--ph-lcd), var(--ph-lcd-lo));
  background-size: 3px 3px, 3px 3px, auto;
}
phone-shell [hidden] { display: none !important; }
phone-shell button { font: inherit; color: inherit; }
phone-shell :focus-visible { outline: 3px dashed var(--ph-ink); outline-offset: -6px; }
/* The reading area takes focus when a post opens. It is a scroll box, not a control: no outline. */
phone-shell .ph-read:focus, phone-shell .ph-read:focus-visible { outline: none; }
phone-shell .on:focus-visible { outline-color: var(--ph-inv); }
.pix { shape-rendering: crispEdges; fill: currentColor; }

/* Status row: signal bars, the time, the GitHub and X links, and the battery (reading progress).
   Three columns: the two side columns have the same width, so the time stays in the center. */
.ph-status {
  position: sticky; top: 0; z-index: 3; display: grid; grid-template-columns: 1fr auto 1fr; align-items: end;
  height: var(--ph-top); padding: calc(2px + env(safe-area-inset-top, 0px)) 14px 0;
  background: var(--ph-grid), var(--ph-lcd); background-size: 3px 3px, 3px 3px, auto;
}
.ph-signal { display: flex; align-items: flex-end; gap: 3px; }
.ph-signal svg { width: 14px; height: 18px; }
.ph-signal i { width: 5px; background: var(--ph-ink); }
.ph-signal i:nth-of-type(1) { height: 6px; }
.ph-signal i:nth-of-type(2) { height: 10px; }
.ph-signal i:nth-of-type(3) { height: 14px; }
.ph-signal i:nth-of-type(4) { height: 18px; }
.ph-signal i:nth-of-type(5) { height: 22px; }
.ph-signal { justify-self: start; }
.ph-time { font-size: 24px; }
.ph-right { justify-self: end; display: flex; align-items: flex-end; }
/* Each link is a 44 x 44 px tap area, as tall as the row. The icon sits at the bottom,
   on the same line as the battery. */
.ph-right a { display: flex; align-items: flex-end; justify-content: center; width: 44px; height: 44px; color: var(--ph-ink); }
.ph-ico { display: block; padding: 2px; margin: -2px; }
.ph-ico svg { display: block; width: 20px; height: 20px; }
.ph-right a:active .ph-ico { background: var(--ph-ink); color: var(--ph-inv); }
.ph-batt { display: flex; align-items: center; margin-left: 4px; }
.ph-batt-box { display: flex; width: 38px; height: 18px; padding: 2px; border: 3px solid var(--ph-ink); }
.ph-batt-box span { width: 75%; background: var(--ph-ink); }
.ph-batt-tip { width: 4px; height: 8px; background: var(--ph-ink); }

.ph-main { flex: 1; display: flex; padding: 10px 14px 0; outline: none; }
.ph-col { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.ph-col > section { flex: 1; display: flex; flex-direction: column; }
.ph-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 10px; padding-bottom: 4px; border-bottom: 3px solid var(--ph-ink); font-size: 34px; }
/* The post title and the page number stay on screen under the status row. */
[data-screen="text"] .ph-head { position: sticky; top: var(--ph-top); z-index: 2; margin-bottom: 0; padding-bottom: 4px; box-shadow: 0 10px 0 var(--ph-lcd); background: var(--ph-grid), var(--ph-lcd); background-size: 3px 3px, 3px 3px, auto; }
[data-screen="text"] .ph-head + * { margin-top: 10px; }
.ph-head h1 { min-width: 0; margin: 0; overflow: hidden; font: inherit; white-space: nowrap; text-overflow: ellipsis; }
.ph-head span { flex: none; font-size: 24px; }

/* Standby. */
.ph-standby { align-items: center; text-align: center; }
.ph-standby h1 { margin: 24px 0 0; font: inherit; font-size: 34px; letter-spacing: .04em; }
/* The post links from the server (spec 6.16). They are visually hidden (.sr-only).
   When the keyboard focus moves into them, they show as a box above the softkeys. */
.ph-index ul { margin: 0; padding: 0; list-style: none; }
/* Each link is a 44 px touch target, as on the other screens. */
.ph-index a { display: inline-block; min-width: 44px; min-height: 44px; line-height: 44px; color: var(--ph-ink); }
.ph-index span { display: none; }
.ph-index:focus-within {
  position: fixed; inset: auto 8px 72px; z-index: 4; width: auto; height: auto; margin: 0; padding: 6px 10px;
  overflow: visible; clip-path: none; white-space: normal; text-align: left; font-size: 22px;
  background: var(--ph-lcd); border: 2px solid var(--ph-ink);
}
.ph-logo { width: 112px; height: 112px; margin-top: 14px; }
.ph-logo .far { opacity: .45; }
.ph-clock { margin: 12px 0 0; font-size: 96px; line-height: .9; }
.ph-date { margin: 6px 0 0; }
.ph-new { min-height: 48px; margin-top: 22px; padding: 6px 14px; border: 3px solid var(--ph-ink); background: transparent; cursor: pointer; }
.ph-new:active { background: var(--ph-ink); color: var(--ph-inv); }

/* Menu: one item per screen. */
.ph-menu { flex: 1; display: flex; align-items: center; }
.ph-arrow { display: grid; place-items: center; width: 44px; min-height: 88px; padding: 0; border: 0; background: transparent; cursor: pointer; }
.ph-arrow svg { width: 20px; height: 28px; }
.ph-item { flex: 1; align-self: stretch; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; min-width: 0; border: 0; background: transparent; font-size: 48px; cursor: pointer; touch-action: pan-y; }
.ph-item svg { width: 176px; max-width: 100%; height: auto; aspect-ratio: 16 / 12; }

/* Lists: real links, inverse video for the selected row. */
.ph-list { margin: 0; padding: 0; list-style: none; }
/* The sticky bars never cover the selected row. */
.ph-list a, .ph-list button { scroll-margin: calc(var(--ph-top) + 8px) 0 72px; display: block; width: 100%; min-height: 48px; padding: 6px 10px; border: 0; background: transparent; color: var(--ph-ink); font-size: 28px; text-align: left; text-decoration: none; cursor: pointer; }
.ph-list .on { background: var(--ph-ink); color: var(--ph-inv); }
.ph-list small { display: block; font-size: 20px; }
/* The marks are decoration: aria-pressed gives the state. */
.ph-list button::before { content: "○ " / ""; }
.ph-list button[aria-pressed="true"]::before { content: "● " / ""; }
.ph-empty { margin: 0; }

/* Reading: the post body. The page scrolls, not this box. Sizes: Small 20, Normal 24, Large 30 px. */
.ph-read {
  --ph-size: 24px;
  flex: 1; padding: 0 10px 12px 0;
  font-size: var(--ph-size); line-height: 1.15; overflow-wrap: anywhere; outline: none;
}
.ph-read[data-size="s"] { --ph-size: 20px; }
.ph-read[data-size="l"] { --ph-size: 30px; }
.ph-read[data-clean] { font-family: ui-monospace, "SF Mono", Menlo, Consolas, "Courier New", monospace; font-size: calc(var(--ph-size) * .72); line-height: 1.45; }
.ph-read:focus-visible { outline-offset: 2px; }
.ph-read h1, .ph-read h2, .ph-read h3, .ph-read h4 { margin: 14px 0 6px; font: inherit; font-size: 1.25em; scroll-margin-top: calc(var(--ph-top) + 64px); }
.ph-read .ph-title { margin-top: 0; }
.ph-read p { margin: 0 0 12px; }
.ph-read .ph-meta { margin-bottom: 12px; padding-bottom: 6px; border-bottom: 2px dashed var(--ph-ink); font-size: .9em; }
.ph-read ul, .ph-read ol { margin: 0 0 12px; padding-left: 1.2em; }
.ph-read li { margin-bottom: 6px; }
.ph-read a { color: var(--ph-ink); }
.ph-read blockquote { margin: 4px 0 14px; padding-left: 10px; border-left: 4px solid var(--ph-ink); }
.ph-read code { font: inherit; }
/* Code scrolls sideways. One ink color: the LCD has no other colors. */
.ph-read pre { margin: 4px 0 14px; padding: 6px 8px; overflow-x: auto; overscroll-behavior-x: contain; border: 2px solid var(--ph-ink); font-size: .85em; line-height: 1.1; white-space: pre; overflow-wrap: normal; }
.ph-read pre, .ph-read pre * { background: transparent !important; color: var(--ph-ink) !important; }
.ph-read pre .hl-ln { display: inline-block; margin-right: 1ch; padding-right: 1ch; border-right: 1px solid var(--ph-ink); text-align: right; opacity: .6; user-select: none; -webkit-user-select: none; }
.ph-read table { display: block; overflow-x: auto; overscroll-behavior-x: contain; border-collapse: collapse; }
.ph-read th, .ph-read td { padding: 2px 6px; border: 2px solid var(--ph-ink); text-align: left; }
.ph-read hr { border: 0; border-top: 2px dashed var(--ph-ink); }
/* Images: grayscale, tinted green by the LCD under them. */
.ph-read img { display: block; max-width: 100%; height: auto; filter: grayscale(1) contrast(1.1); mix-blend-mode: multiply; }

/* The thin scroll bar: fixed on the right, between the post title and the softkeys. */
.ph-thumb { position: fixed; z-index: 1; top: calc(var(--ph-top) + 52px); bottom: calc(76px + env(safe-area-inset-bottom, 0px)); right: calc(14px + env(safe-area-inset-right, 0px)); width: 6px; background: rgba(29,43,20,.3); }
.ph-thumb span { position: absolute; left: 0; top: 0; width: 6px; height: 28px; background: var(--ph-ink); }

/* Options: a menu over the bottom of the screen, above the softkeys. */
.ph-options { position: fixed; left: 10px; right: 10px; bottom: calc(70px + env(safe-area-inset-bottom, 0px)); z-index: 4; max-height: 60vh; max-height: 60dvh; overscroll-behavior: contain; overflow-y: auto; border: 3px solid var(--ph-ink); background: var(--ph-inv); box-shadow: 6px 6px 0 rgba(29,43,20,.5); }
.ph-options p { margin: 0; padding: 6px 12px; border-bottom: 3px solid var(--ph-ink); font-size: 30px; }
.ph-options button { display: block; width: 100%; min-height: 48px; padding: 6px 12px; border: 0; background: transparent; font-size: 28px; text-align: left; cursor: pointer; }
.ph-options button.on { background: var(--ph-ink); color: var(--ph-inv); }
.ph-toast { position: fixed; left: 14px; right: 14px; bottom: calc(70px + env(safe-area-inset-bottom, 0px)); z-index: 5; margin: 0; padding: 4px 8px; border: 3px solid var(--ph-ink); background: var(--ph-inv); text-align: center; pointer-events: none; }
.ph-toast:empty { display: none; }

/* Snake: a 20 x 16 board and a 3 x 3 key pad. */
.ph-board { position: relative; width: 100%; aspect-ratio: 20 / 16; border: 3px solid var(--ph-ink); touch-action: none; }
.ph-board svg { display: block; width: 100%; height: 100%; }
.ph-board rect { fill: none; stroke: var(--ph-ink); stroke-width: .25; }
.ph-banner { position: absolute; inset: 0; display: grid; place-items: center; margin: 0; background: rgba(180,201,138,.85); font-size: 34px; text-align: center; }
.ph-pad { display: grid; grid-template-columns: repeat(3, 64px); grid-template-rows: repeat(3, 52px); gap: 6px; justify-content: center; margin-top: 12px; }
.ph-pad button { border: 3px solid var(--ph-ink); background: transparent; font-size: 28px; cursor: pointer; }
.ph-pad button:active { background: var(--ph-ink); color: var(--ph-inv); }
.ph-pad [data-dir="2"] { grid-area: 1 / 2; }
.ph-pad [data-dir="4"] { grid-area: 2 / 1; }
.ph-pad [data-dir="5"] { grid-area: 2 / 2; }
.ph-pad [data-dir="6"] { grid-area: 2 / 3; }
.ph-pad [data-dir="8"] { grid-area: 3 / 2; }
.ph-sr { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* Softkeys: two plain words. Each half is a 64 px tap area. A tap shows the word in inverse. */
.ph-soft {
  position: sticky; bottom: 0; z-index: 3; display: flex; padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--ph-grid), var(--ph-lcd-lo); background-size: 3px 3px, 3px 3px, auto;
}
.ph-soft button { flex: 1; display: flex; align-items: center; min-height: 64px; padding: 0 18px; border: 0; background: transparent; font-size: 30px; cursor: pointer; }
.ph-soft [data-soft="right"] { justify-content: flex-end; }
.ph-soft span { padding: 0 4px; }
.ph-soft button:active span { background: var(--ph-ink); color: var(--ph-inv); }

@media (max-height: 640px) {
  .ph-standby h1 { margin-top: 8px; }
  .ph-logo { width: 80px; height: 80px; }
  .ph-clock { font-size: 72px; }
  .ph-pad { grid-template-rows: repeat(3, 44px); }
}
@media (prefers-contrast: more) {
  :root[data-mode="phone"] { --ph-grid: linear-gradient(transparent, transparent); }
}
@media print {
  [data-mode="phone"] blog-app:not([data-current="write"], [data-current="setup"]) phone-shell { display: block; min-height: 0; background: #fff; }
  .ph-status, .ph-soft, .ph-thumb, .ph-options, .ph-standby, phone-shell::before { display: none !important; }
  [data-screen="text"] .ph-head { position: static; box-shadow: none; background: none; }
}
