/* Photon handheld: a TI-Nspire CX II style screen and keypad in Photon colours.
   Computer view keeps the wide workspace in styles.css; everything handheld-only is scoped to body[data-layout="handheld"]. */

.device-key-console, .device-entry, .screen-bar, .device-brand, .coach, .screen-prompt { display: none; }

.layout-select {
  appearance: none;
  border: 1px solid #ccd9e9;
  border-radius: 8px;
  min-height: 35px;
  padding: 7px 26px 7px 10px;
  background: #eef4fb url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='m3 4.5 3 3 3-3' fill='none' stroke='%231b3a6b' stroke-width='1.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") right 8px center no-repeat;
  color: var(--accent);
  font-size: .87rem;
  font-weight: 650;
  white-space: nowrap;
}
.layout-select:hover { background-color: #e1ecfa; }

.workspace-controls, .desktop-controls { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.workspace-controls { flex: 0 0 auto; justify-content: flex-end; }
.desktop-controls .icon { width: 17px; height: 17px; }
.desktop-controls button:is([aria-pressed="true"], [aria-expanded="true"]) { background: #fff2d3; border-color: #dcb560; color: #634000; }

/* Computer view: the menu opens as a drop-down panel under the Menu button. */
body:not([data-layout="handheld"]) .device-screen { position: relative; }
body:not([data-layout="handheld"]) .device-screen .device-menu {
  position: absolute; z-index: 4; inset: 44px 0 auto auto; width: min(360px, 100%); max-height: min(560px, 72dvh);
  display: flex; flex-direction: column; overflow: hidden;
  border: 1px solid #c5d4e6; border-radius: 12px; background: #f4f7fb; box-shadow: 0 12px 34px #102e572c;
}
body:not([data-layout="handheld"]) .device-menu-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 12px; border-bottom: 1px solid #d8e1ec; background: #fff; }
body:not([data-layout="handheld"]) .device-menu-head h2 { font-size: .94rem; }
body:not([data-layout="handheld"]) .device-menu-head button { min-height: 30px; padding: 3px 8px; border: 1px solid #cedbed; border-radius: 6px; background: #fff; color: var(--accent); font-size: .79rem; font-weight: 650; }
body:not([data-layout="handheld"]) .device-menu-items { display: grid; gap: 4px; padding: 8px; overflow: auto; }
body:not([data-layout="handheld"]) .device-menu-column { display: grid; gap: 4px; }
body:not([data-layout="handheld"]) .device-menu-column:not(:last-child) { display: none; }
body:not([data-layout="handheld"]) .device-menu-column-title { display: none; }
body:not([data-layout="handheld"]) .device-menu-item { display: flex; align-items: center; gap: 8px; width: 100%; min-height: 36px; padding: 6px 9px; border: 1px solid #d6e0ee; border-radius: 7px; background: #fff; color: var(--ink); text-align: left; font-size: .87rem; font-weight: 620; }
body:not([data-layout="handheld"]) .device-menu-item:is(:hover, :focus-visible, [data-active]) { border-color: #8ca9cc; background: #e4eefb; }
body:not([data-layout="handheld"]) .device-home-hero { display: none; }
body:not([data-layout="handheld"]) .device-menu.device-home .device-menu-column { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.toolbox-keypad { min-width: 0; padding: 9px; border: 1px solid #d4ddeb; border-top: 3px solid #d29a36; border-radius: 12px; background: #eaf0f8; }
.toolbox-keypad-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; padding: 0 0 8px 2px; }
.toolbox-keypad-head h2 { font-size: .875rem; font-weight: 700; }
.toolbox-keypad-head .icon-button { width: 28px; min-height: 28px; padding: 5px; }
.toolbox-keypad-head .icon { width: 16px; height: 16px; }
.toolbox-keypad .handheld-key[data-kind="enter"] { background: #f0a500; }
body[data-layout="keypad"] .calc-handheld { display: none; }
@media (min-width: 781px) {
  body[data-layout="keypad"] .shell { grid-template-columns: minmax(286px, 22%) minmax(0, 1fr); }
  body[data-layout="keypad"] .sidebar { gap: 14px; }
  body[data-layout="keypad"] .sidebar nav { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px; }
  body[data-layout="keypad"] .nav-label { grid-column: 1 / -1; margin-bottom: 7px; }
  body[data-layout="keypad"] .sidebar a { margin: 0; padding: 7px 6px; gap: 6px; white-space: normal; }
  body[data-layout="keypad"] .sidebar .icon { width: 17px; height: 17px; }
  body[data-layout="keypad"] .owl-guide { display: none; }
}
@media (max-width: 780px) {
  .toolbox-keypad { width: min(100%, 420px); margin: 6px auto; }
  .workspace-head:has(.desktop-controls) { align-items: start; }
  .workspace-controls { max-width: 49%; }
}

/* ───────────────────────── Handheld view ───────────────────────── */

body[data-layout="handheld"] {
  --navy-1: #23477d;
  --navy-2: #12305c;
  --navy-3: #0b1f3f;
  --gold: #f0a500;
  --screen-ink: #0f1d35;
  --screen-line: #d9e0ea;
  --screen-select: #1b4f9c;
  background: radial-gradient(120% 90% at 50% 0%, #f5f8fc 0%, #e6ecf4 55%, #dbe3ee 100%);
}
body[data-layout="handheld"] .shell { display: block; min-height: auto; }
body[data-layout="handheld"] .sidebar { display: none; }
body[data-layout="handheld"] .workspace {
  --console-pad: clamp(10px, 1.6vw, 20px);
  --keys-w: clamp(300px, 26vw, 352px);
  --coach-room: 0px;
  --screen-h: clamp(280px, min(calc(100dvh - 72px - 2 * var(--console-pad) - 40px), calc((100vw - var(--keys-w) - var(--coach-room) - 4 * var(--console-pad) - 48px) * 0.75)), 640px);
  --screen-w: calc(var(--screen-h) * 4 / 3);
  max-width: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(16px, 2vw, 30px);
  padding: 18px 14px 26px;
}
@media (min-width: 1680px) {
  body[data-layout="handheld"] .workspace { --coach-room: 330px; flex-direction: row; align-items: flex-start; }
}

/* The device body. Landscape on wide screens: screen on the left, keypad on the right. */
body[data-layout="handheld"] .device-frame {
  position: relative;
  display: grid;
  grid-template-columns: var(--screen-w) var(--keys-w);
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas: "screen keys" "brand keys";
  gap: 10px var(--console-pad);
  padding: var(--console-pad);
  border-radius: 30px;
  background:
    linear-gradient(160deg, #ffffff22, transparent 28%),
    linear-gradient(155deg, var(--navy-1), var(--navy-2) 48%, var(--navy-3));
  box-shadow: inset 0 1px 0 #ffffff40, inset 0 -2px 0 #00000040, 0 2px 0 #0b1f3f, 0 22px 50px #0d1f3c47;
}
body[data-layout="handheld"] .device-frame::after {
  content: ""; position: absolute; left: 50%; bottom: 7px; width: 46px; height: 4px; translate: -50% 0;
  border-radius: 4px; background: #f0a50066;
}

body[data-layout="handheld"] .device-screen {
  grid-area: screen;
  width: var(--screen-w);
  height: var(--screen-h);
  container-type: size;
  position: relative;
  isolation: isolate;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: 10px;
  background: #fff;
  color: var(--screen-ink);
  font-size: clamp(11.5px, 3.05cqh, 18px);
  box-shadow: 0 0 0 6px #08162d, 0 0 0 7px #2c4f82, inset 0 0 0 1px #0000001f;
  -webkit-text-size-adjust: 100%;
}

body[data-layout="handheld"] .device-brand {
  grid-area: brand;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 34px;
  padding: 4px 4px 0;
  color: #fff;
}
body[data-layout="handheld"] .device-brand img { width: 26px; height: 26px; border-radius: 50%; box-shadow: 0 0 0 2px #ffffff30; }
body[data-layout="handheld"] .device-wordmark { font: 800 .98rem/1 "Photon Inter", Inter, system-ui, sans-serif; letter-spacing: .3em; }
body[data-layout="handheld"] .device-model { font-size: .7rem; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: #f0c76a; }
body[data-layout="handheld"] .device-model::before { content: "·"; margin-right: 10px; color: #ffffff55; }

body[data-layout="handheld"] .device-key-console { grid-area: keys; display: block; min-width: 0; align-self: center; }

/* Portrait handheld: screen on top, keypad underneath (tablets in portrait and phones). */
@media (max-width: 1099px), (max-height: 620px) and (max-width: 1399px) {
  body[data-layout="handheld"] .workspace {
    --screen-w: min(calc(100vw - 2 * var(--console-pad) - 28px), 470px);
    --screen-h: calc(var(--screen-w) * 3 / 4);
    flex-direction: column;
    align-items: center;
    padding: 12px 10px 22px;
  }
  body[data-layout="handheld"] .device-frame {
    grid-template-columns: var(--screen-w);
    grid-template-rows: auto auto auto;
    grid-template-areas: "screen" "brand" "keys";
  }
  body[data-layout="handheld"] .device-brand { justify-content: flex-start; min-height: 0; }
  body[data-layout="handheld"] .device-model { margin-left: auto; }
  body[data-layout="handheld"] .device-model::before { content: none; }
  body[data-layout="handheld"] .device-frame {
    border-radius: 30px 30px 40px 40px;
    padding-bottom: calc(var(--console-pad) + 8px);
  }
}
@media (max-width: 520px) {
  body[data-layout="handheld"] .workspace { --console-pad: 9px; padding: 8px 6px 18px; }
  body[data-layout="handheld"] .device-frame { border-radius: 22px 22px 30px 30px; }
  body[data-layout="handheld"] .device-screen { box-shadow: 0 0 0 4px #08162d, 0 0 0 5px #2c4f82; border-radius: 7px; }
}

/* Keypad, Photon colours */
body[data-layout="handheld"] .device-key-console .handheld { --key-h: clamp(30px, 4.6dvh, 40px); }
body[data-layout="handheld"] .device-key-console .handheld-key {
  border: 0;
  border-radius: 8px;
  background: linear-gradient(#f4f7fb, #dfe6f0);
  color: #10264a;
  box-shadow: 0 2px 0 #0a1a33, inset 0 1px 0 #fff;
}
body[data-layout="handheld"] .device-key-console .handheld-key[data-kind="number"] { background: linear-gradient(#ffffff, #eef2f7); font-size: 1.08rem; }
body[data-layout="handheld"] .device-key-console .handheld-key[data-kind="operator"] { background: linear-gradient(#e8eef7, #d2dceb); }
body[data-layout="handheld"] .device-key-console .handheld-key:is([data-kind="function"], [data-kind="command"]) { background: linear-gradient(#3a5f96, #284a7c); color: #fff; box-shadow: 0 2px 0 #08162d, inset 0 1px 0 #ffffff33; }
body[data-layout="handheld"] .device-key-console .handheld-key[data-kind="letter"] { background: linear-gradient(#2e5184, #213f6d); color: #e9f0fb; box-shadow: 0 2px 0 #08162d, inset 0 1px 0 #ffffff26; }
body[data-layout="handheld"] .device-key-console .handheld-key[data-kind="symbol"] { background: linear-gradient(#24426f, #1a345b); color: #d8e3f3; box-shadow: 0 2px 0 #08162d, inset 0 1px 0 #ffffff1f; }
body[data-layout="handheld"] .device-key-console .handheld-key[data-kind="nav"] { background: linear-gradient(#18355f, #10284b); color: #fff; box-shadow: 0 2px 0 #050f20, inset 0 1px 0 #ffffff22; font-size: .82rem; }
body[data-layout="handheld"] .device-key-console .handheld-key[data-kind="enter"] { background: linear-gradient(#ffc04a, #e69d00); color: #10264a; box-shadow: 0 2px 0 #7a5200, inset 0 1px 0 #fff6; }
body[data-layout="handheld"] .device-key-console .handheld-key[data-modifier="ctrl"] { background: linear-gradient(#ffd879, #f0a500); color: #10264a; box-shadow: 0 2px 0 #7a5200, inset 0 1px 0 #fff6; }
body[data-layout="handheld"] .device-key-console .handheld-key[data-modifier="ctrl"][aria-pressed="true"] { background: #fff1c4; box-shadow: 0 0 0 2px #fff, 0 2px 0 #7a5200; }
body[data-layout="handheld"] .device-key-console .handheld-key[data-modifier="shift"] { background: linear-gradient(#f4f7fb, #dfe6f0); color: #10264a; box-shadow: 0 2px 0 #0a1a33; }
body[data-layout="handheld"] .device-key-console .handheld-key[data-modifier="shift"][aria-pressed="true"] { background: #cfe0f8; box-shadow: 0 0 0 2px #fff, 0 2px 0 #0a1a33; }
body[data-layout="handheld"] .device-key-console .handheld-alt { color: #f5c35a; top: 1px; font-size: .58rem; }
body[data-layout="handheld"] .device-key-console .handheld-key[data-kind="number"] .handheld-alt,
body[data-layout="handheld"] .device-key-console .handheld-key[data-kind="operator"] .handheld-alt,
body[data-layout="handheld"] .device-key-console .handheld-key[data-modifier="shift"] .handheld-alt { color: #9a6200; }
body[data-layout="handheld"] .device-key-console .handheld[data-ctrl] .handheld-key:has(.handheld-alt) { box-shadow: 0 0 0 2px #f0a500, 0 2px 0 #08162d; }
body[data-layout="handheld"] .device-key-console .handheld-pad {
  background: radial-gradient(circle at 50% 45%, #2d5189, #142e57 70%);
  border-radius: 22px;
  box-shadow: inset 0 1px 0 #ffffff30, 0 2px 0 #050f20;
  padding: 5px;
}
body[data-layout="handheld"] .device-key-console .handheld-pad .handheld-key { background: transparent; box-shadow: none; color: #cfe0f8; font-size: .9rem; }
body[data-layout="handheld"] .device-key-console .handheld-pad .handheld-key:hover { background: #ffffff14; }
body[data-layout="handheld"] .device-key-console .handheld-pad .handheld-key[data-action="submit"] { background: radial-gradient(circle at 40% 35%, #ffd36d, #e69d00); box-shadow: 0 2px 0 #7a5200, inset 0 1px 0 #fff8; }
body[data-layout="handheld"] .device-key-console .handheld-letters { border-top-color: #ffffff1f; }
body[data-layout="handheld"] .device-key-console .handheld-key:focus-visible { outline-color: #ffd36d; }

/* ───── Screen chrome ───── */
body[data-layout="handheld"] .screen-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: stretch;
  gap: .4em;
  height: max(1.85em, 7.4cqh);
  padding: 0 .35em 0 0;
  background: linear-gradient(#f3f6fa, #dfe6ef);
  border-bottom: 1px solid #b8c5d6;
  font-size: .82em;
}
body[data-layout="handheld"] .screen-tabs { display: flex; align-items: end; gap: 1px; min-width: 0; overflow: hidden; padding-left: .25em; }
body[data-layout="handheld"] .screen-tabs button {
  flex: 0 0 auto;
  height: 82%;
  padding: 0 .62em;
  border: 1px solid transparent;
  border-bottom: 0;
  border-radius: .45em .45em 0 0;
  background: transparent;
  color: #4b5b75;
  font: 650 1em/1 "Photon Inter", Inter, system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
}
body[data-layout="handheld"] .screen-tabs button:hover { background: #ffffff8c; color: var(--screen-ink); }
body[data-layout="handheld"] .screen-tabs button[aria-selected="true"] { background: #fff; border-color: #b8c5d6; color: #0b2a57; box-shadow: inset 0 2px 0 var(--gold); }
body[data-layout="handheld"] .screen-doc { align-self: center; margin-left: auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #4b5b75; font-weight: 600; }
body[data-layout="handheld"] .screen-angle {
  align-self: center; padding: .12em .45em; border: 1px solid #9fb2ca; border-radius: .35em; background: #fff;
  color: #0b2a57; font: 750 .86em/1.2 "Photon Inter", Inter, system-ui, sans-serif; letter-spacing: .04em;
}
body[data-layout="handheld"] .screen-angle:hover { border-color: var(--gold); }
body[data-layout="handheld"] .screen-owl { align-self: center; display: grid; place-items: center; width: 1.6em; height: 1.6em; padding: 0; border: 0; border-radius: 50%; background: transparent; }
body[data-layout="handheld"] .screen-owl img { width: 100%; height: 100%; }
body[data-layout="handheld"] .screen-owl:hover img { transform: rotate(-8deg) scale(1.08); transition: transform .2s ease; }

body[data-layout="handheld"] .device-screen .workspace-head { display: none; }
body[data-layout="handheld"] .device-view {
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
  overflow: hidden;
}
body[data-layout="handheld"] .device-view > section { height: 100%; min-height: 0; overflow: hidden; }
body[data-layout="handheld"] .device-view > section[hidden] { display: none; }
body[data-layout="handheld"] .view-enter { animation: none; }

/* Prompts ("graph?", "lower bound?") sit in a small grey box at the bottom-left of the graph, as on the handheld. */
body[data-layout="handheld"] .screen-prompt {
  position: absolute;
  z-index: 6;
  left: .6em;
  bottom: 2.9em;
  display: block;
  max-width: 80%;
  margin: 0;
  padding: .2em .6em;
  border: 1px solid #8e9bb0;
  border-radius: .35em;
  background: #eceff4;
  color: #1c2940;
  font-size: .9em;
  font-weight: 600;
  box-shadow: 0 2px 8px #0b1f3f26;
  pointer-events: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
body[data-layout="handheld"] .screen-prompt[hidden] { display: none; }
body[data-layout="handheld"] .screen-prompt[data-tone="error"] { border-color: #c4677c; background: #fbecef; color: #8a1c35; }
body[data-layout="handheld"] .screen-prompt[data-tone="result"] { border-color: #6aa58d; background: #eaf6f0; color: #0d5a3f; }

/* ───── TI-style popup menus (cascading) ───── */
body[data-layout="handheld"] .device-screen .device-menu {
  position: absolute;
  z-index: 8;
  inset: max(1.85em, 7.4cqh) 0 0 0;
  display: block;
  background: transparent;
  pointer-events: none;
}
body[data-layout="handheld"] .device-menu-head { display: none; }
body[data-layout="handheld"] .device-menu-items { position: absolute; inset: 0; pointer-events: none; }
body[data-layout="handheld"] .device-menu-column {
  --level: 0;
  position: absolute;
  top: calc(1.5% + var(--level) * 7%);
  left: calc(1.2% + min(var(--level), 3) * 19%);
  width: min(60%, 26em);
  max-height: calc(97% - var(--level) * 7%);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid #7d91ad;
  border-radius: .5em;
  background: #f7f9fc;
  box-shadow: 0 .45em 1.4em #0b1f3f52;
  pointer-events: auto;
  animation: menu-pop .12s ease-out both;
}
body[data-layout="handheld"] .device-menu-column:not(:last-child) { filter: saturate(.6) brightness(.97); }
body[data-layout="handheld"] .device-menu-column-title {
  margin: 0;
  padding: .32em .7em;
  background: linear-gradient(var(--navy-1), var(--navy-2));
  color: #fff;
  font-size: .86em;
  font-weight: 700;
  letter-spacing: .01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
body[data-layout="handheld"] .device-menu-list { overflow: auto; overscroll-behavior: contain; scrollbar-width: thin; padding: .2em; }
body[data-layout="handheld"] .device-menu-item {
  display: flex;
  align-items: center;
  gap: .5em;
  width: 100%;
  min-height: 1.85em;
  padding: .18em .45em;
  border: 0;
  border-radius: .3em;
  background: transparent;
  color: var(--screen-ink);
  text-align: left;
  font: 560 1em/1.2 "Photon Inter", Inter, system-ui, sans-serif;
}
body[data-layout="handheld"] .device-menu-item:is(:hover, :focus-visible, [data-active]) { outline: none; background: var(--screen-select); color: #fff; }
body[data-layout="handheld"] .device-menu-item:is(:hover, :focus-visible, [data-active]) .device-menu-slot { background: #ffffff2b; color: #fff; }
body[data-layout="handheld"] .device-menu-slot {
  display: inline-grid; place-items: center; flex: 0 0 auto; min-width: 1.45em; height: 1.35em; padding: 0 .2em;
  border-radius: .25em; background: #e3e9f2; color: #1b3a6b; font: 700 .82em/1 "Photon Inter", Inter, system-ui, sans-serif;
}
body[data-layout="handheld"] .device-menu-slot[hidden] { visibility: hidden; display: inline-grid; }
body[data-layout="handheld"] .device-menu-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
body[data-layout="handheld"] .device-menu-group::after { content: "▸"; margin-left: auto; padding-left: .4em; font-size: .9em; opacity: .7; }
body[data-layout="handheld"] .device-menu-notation { display: none; }
body[data-layout="handheld"] .device-menu-empty { padding: .6em .8em; color: #5b6880; }
@keyframes menu-pop { from { opacity: 0; transform: translateY(-.3em); } to { opacity: 1; transform: none; } }

/* Home screen: the owl welcomes, the pages are tiles. */
body[data-layout="handheld"] .device-menu.device-home { pointer-events: auto; background: linear-gradient(160deg, #f8fafd, #e9eef6); }
body[data-layout="handheld"] .device-menu.device-home .device-menu-items { inset: 0 0 0 34%; display: grid; align-content: center; padding: 3% 4% 3% 0; }
body[data-layout="handheld"] .device-menu.device-home .device-menu-column { position: static; width: auto; max-height: none; border: 0; background: transparent; box-shadow: none; animation: none; filter: none; }
body[data-layout="handheld"] .device-menu.device-home .device-menu-column-title { background: none; color: #0b2a57; padding: 0 0 .5em; font-size: 1em; }
body[data-layout="handheld"] .device-menu.device-home .device-menu-list { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .5em; padding: 0; overflow: visible; }
body[data-layout="handheld"] .device-menu.device-home .device-menu-item {
  position: relative; flex-direction: column; justify-content: center; gap: .25em; min-height: 4.6em; padding: .5em .3em;
  border: 1px solid #d3dceb; border-radius: .6em; background: #fff; box-shadow: 0 1px 0 #c5d1e2; text-align: center; font-weight: 650; font-size: .9em;
}
body[data-layout="handheld"] .device-menu.device-home .device-menu-item .device-menu-label { white-space: normal; line-height: 1.15; }
body[data-layout="handheld"] .device-menu.device-home .device-menu-item svg { width: 1.7em; height: 1.7em; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
body[data-layout="handheld"] .device-menu.device-home .device-menu-slot { position: absolute; top: .3em; left: .3em; background: var(--gold); color: #10264a; }
body[data-layout="handheld"] .device-menu.device-home .device-menu-item:is(:hover, :focus-visible, [data-active]) { border-color: var(--screen-select); background: var(--screen-select); color: #fff; }
body[data-layout="handheld"] .device-home-hero { display: none; }
body[data-layout="handheld"] .device-menu.device-home .device-home-hero {
  position: absolute; inset: 0 66% 0 0; display: grid; place-content: center; justify-items: center; gap: .5em; padding: .6em;
  background: radial-gradient(ellipse at 50% 38%, #2d5189, #13305d 70%); color: #fff; text-align: center;
}
body[data-layout="handheld"] .device-home-hero .owl-art { width: min(62%, 7.6em); }
body[data-layout="handheld"] .device-home-hero p { margin: 0; font-size: .86em; line-height: 1.3; color: #e8eef8; }
body[data-layout="handheld"] .device-home-hero strong { display: block; color: #ffd27a; font-size: 1.08em; }

/* ───── Dialog boxes inside the screen ───── */
body[data-layout="handheld"] .device-screen .tool-dialog {
  position: absolute;
  z-index: 9;
  inset: auto;
  left: 50%;
  top: calc(50% + max(1.85em, 7.4cqh) / 2);
  translate: -50% -50%;
  width: min(92%, 34em);
  max-height: calc(100% - max(1.85em, 7.4cqh) - 1em);
  display: flex;
  flex-direction: column;
  margin: 0;
  padding: 0;
  overflow: hidden;
  border: 1px solid #6f84a3;
  border-radius: .55em;
  background: #f7f9fc;
  color: var(--screen-ink);
  font-size: 1em;
  box-shadow: 0 .6em 2em #0b1f3f66;
}
body[data-layout="handheld"] .device-screen .tool-dialog:not([open]) { display: none; }
body[data-layout="handheld"] .device-screen .tool-dialog-head { flex: 0 0 auto; padding: .32em .5em .32em .75em; background: linear-gradient(var(--navy-1), var(--navy-2)); border: 0; }
body[data-layout="handheld"] .device-screen .tool-dialog-head h2 { color: #fff; font: 700 .95em/1.2 "Photon Inter", Inter, system-ui, sans-serif; letter-spacing: 0; }
body[data-layout="handheld"] .device-screen .tool-dialog-head .icon-button { min-height: 0; padding: .15em; border: 0; background: transparent; color: #fff; }
body[data-layout="handheld"] .device-screen .tool-dialog-head .icon { width: 1.1em; height: 1.1em; }
body[data-layout="handheld"] .device-screen .tool-dialog-form { min-height: 0; overflow: auto; gap: .5em; padding: .6em .75em .6em; scrollbar-width: thin; }
body[data-layout="handheld"] .device-screen .tool-dialog-fields { gap: .3em; }
body[data-layout="handheld"] .device-screen .tool-dialog-field { grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); gap: .1em .6em; }
body[data-layout="handheld"] .device-screen .tool-dialog-field label { font-size: .92em; font-weight: 600; text-align: right; }
body[data-layout="handheld"] .device-screen .tool-dialog-field :is(input:not([type="checkbox"]), select, textarea) {
  min-height: 1.75em; padding: .12em .4em; border: 1px solid #94a6bf; border-radius: .22em; background: #fff;
  font-size: .95em; color: var(--screen-ink);
}
body[data-layout="handheld"] .device-screen .tool-dialog-field :is(input, select, textarea):focus { outline: 2px solid var(--gold); outline-offset: 0; border-color: #b77d00; }
body[data-layout="handheld"] .device-screen .tool-dialog-field small { font-size: .78em; }
body[data-layout="handheld"] .device-screen .tool-dialog-actions { gap: .4em; padding-top: .1em; }
body[data-layout="handheld"] .device-screen .tool-dialog-actions [data-keypad] { display: none; }
body[data-layout="handheld"] .device-screen .tool-dialog-actions button {
  min-height: 1.8em; padding: .1em 1.1em; border: 1px solid #7d91ad; border-radius: .35em; background: linear-gradient(#fff, #e7edf5);
  color: var(--screen-ink); font-size: .92em; font-weight: 650;
}
body[data-layout="handheld"] .device-screen .tool-dialog-actions [data-submit] { border: 2px solid var(--screen-select); }
body[data-layout="handheld"] .device-screen .tool-dialog-actions button:focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; }
body[data-layout="handheld"] .device-screen .tool-dialog-error { font-size: .88em; padding: .35em .5em; }
body[data-layout="handheld"] .device-screen .tool-dialog-result { padding: .4em .55em; font-size: .9em; }
body[data-layout="handheld"] .device-screen .tool-dialog-keypad { display: none; }
body[data-layout="handheld"] .screen-scrim { position: absolute; z-index: 7; inset: max(1.85em, 7.4cqh) 0 0; background: #0b1f3f26; }
body[data-layout="handheld"] .screen-scrim[hidden] { display: none; }

/* Palettes from the trig, template and symbol keys open on the screen, as on the handheld. */
body[data-layout="handheld"] .device-screen > .handheld-palette {
  position: absolute; z-index: 8; left: 50%; bottom: 3%; translate: -50% 0; width: min(88%, 30em); margin: 0;
  grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .35em; padding: .5em;
  border: 1px solid #7d91ad; border-radius: .5em; background: #f7f9fc; box-shadow: 0 .45em 1.4em #0b1f3f52; font-size: 1em;
}
body[data-layout="handheld"] .device-screen > .handheld-palette .handheld-key { min-height: 2.1em; font-size: .92em; border-radius: .3em; }
body[data-layout="handheld"] .device-screen > .handheld-palette[data-panel="templates"] { grid-template-columns: repeat(6, minmax(0, 1fr)); }
body[data-layout="handheld"] .device-screen > .handheld-palette[data-panel="templates"] .handheld-key { min-height: 3.1em; font-size: .62em; }
body[data-layout="handheld"] .device-screen > .handheld-palette .handheld-palette-title { font-size: .85em; }

/* ───── Pages inside the screen ───── */

/* 1.1 Calculator: history with the entry line underneath, answers on the right */
body[data-layout="handheld"] .device-view .calc-workspace { display: block; height: 100%; }
body[data-layout="handheld"] .device-view .calc-device { display: flex; height: 100%; padding: 0; border: 0; border-radius: 0; background: #fff; box-shadow: none; }
body[data-layout="handheld"] .device-view .calc-screen { display: flex; flex-direction: column; justify-content: flex-start; width: 100%; height: 100%; border: 0; border-radius: 0; }
body[data-layout="handheld"] .device-view .calc-screen > .panel-head,
body[data-layout="handheld"] .device-view .calc-reference,
body[data-layout="handheld"] .device-view .calc-handheld { display: none; }
body[data-layout="handheld"] .device-view .calc-history { flex: 0 1 auto; height: auto; min-height: 0; padding: 0; gap: 0; overflow-y: auto; scrollbar-width: thin; }
body[data-layout="handheld"] .device-view .calc-history > p { padding: .5em .6em; font-size: .9em; }
body[data-layout="handheld"] .device-view .calc-entry {
  display: grid; grid-template-columns: minmax(0, auto) minmax(0, 1fr); align-items: center; gap: .1em .8em;
  padding: .25em .55em; border: 0; border-bottom: 1px solid var(--screen-line); border-radius: 0; background: #fff;
}
body[data-layout="handheld"] .device-view .calc-entry:hover { background: #f2f6fb; }
body[data-layout="handheld"] .device-view .calc-entry:focus-visible { outline: none; background: #dfe9f7; }
body[data-layout="handheld"] .device-view .calc-entry code { font: 500 1em "Photon Inter", Inter, system-ui, sans-serif; color: var(--screen-ink); }
body[data-layout="handheld"] .device-view .calc-entry code math { font-size: 1.08em; }
body[data-layout="handheld"] .device-view .calc-entry strong { justify-self: end; font: 600 1.02em "Photon Inter", Inter, system-ui, sans-serif; color: #0b2a57; text-align: right; }
body[data-layout="handheld"] .device-view .calc-entry strong math { font-size: 1.08em; }
body[data-layout="handheld"] .device-view .calc-entry.error strong { grid-column: 1 / -1; justify-self: start; font-size: .86em; color: #a3213f; }
body[data-layout="handheld"] .device-view .calc-entry.has-table strong { grid-column: 1 / -1; justify-self: stretch; }
body[data-layout="handheld"] .device-view .calc-form { flex: 0 0 auto; display: grid; grid-template-columns: minmax(0, 1fr); gap: .15em; padding: .3em .45em; border-top: 0; background: #fff; }
body[data-layout="handheld"] .device-view .calc-form > button { display: none; }
body[data-layout="handheld"] .device-view .calc-form input {
  min-height: 1.9em; padding: .15em .45em; border: 1px solid #7d91ad; border-radius: .25em; background: #fff;
  font: 500 1em ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--screen-ink);
}
body[data-layout="handheld"] .device-view .calc-form input:focus { outline: 2px solid #b8cbe6; border-color: var(--screen-select); }
body[data-layout="handheld"] .device-view .math-draft { grid-row: auto; padding: .1em .45em; border: 0; border-left: 2px solid var(--gold); border-radius: 0; background: #f6f8fb; }
body[data-layout="handheld"] .device-view .math-draft math { font-size: 1.05em; }

/* Result tables (stat tests, One-Variable Statistics…) in the history */
.calc-table { width: 100%; border-collapse: collapse; margin: .1em 0 .2em; font: 500 .95em "Photon Inter", Inter, system-ui, sans-serif; text-align: left; }
.calc-table th, .calc-table td { padding: .12em .5em; border: 1px solid #d5dde8; }
.calc-table th { width: 45%; font-weight: 600; color: #22385c; background: #f5f8fc; white-space: nowrap; }
.calc-table td { font-variant-numeric: tabular-nums; color: #0b2a57; overflow-wrap: anywhere; }
.calc-entry .calc-table { font-size: .92rem; }
body[data-layout="handheld"] .calc-entry .calc-table { font-size: .9em; }

/* 1.2 Graphs: the graph fills the page, the entry line sits underneath */
body[data-layout="handheld"] .device-view .graph-work, body[data-layout="handheld"] .device-view .graph-work > div:not([hidden]) { height: 100%; }
body[data-layout="handheld"] .device-view .graph-module { height: 100%; }
body[data-layout="handheld"] .device-view .graph-grid { display: flex; align-items: stretch; height: 100%; gap: 0; }
body[data-layout="handheld"] .device-view .graph-card { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; border: 0; border-radius: 0; box-shadow: none; }
body[data-layout="handheld"] .device-view .graph-card.graph-expressions,
body[data-layout="handheld"] .device-view .graph-toolbar,
body[data-layout="handheld"] .device-view .graph-zoom,
body[data-layout="handheld"] .device-view .graph-analysis,
body[data-layout="handheld"] .device-view .graph-window { display: none !important; }
body[data-layout="handheld"] .device-view .graph-plot-view { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; position: relative; }
body[data-layout="handheld"] .device-view .graph-chart-shell { flex: 1 1 auto; height: auto; min-height: 0; border: 0; border-radius: 0; }
body[data-layout="handheld"] .device-view .graph-readout { position: absolute; right: .4em; bottom: .3em; margin: 0; padding: .1em .45em; border-radius: .3em; background: #ffffffd9; font-size: .78em; color: #37486a; pointer-events: none; max-width: 70%; }
body[data-layout="handheld"] .device-view .graph-table-view:not([hidden]) { flex: 0 0 46%; border-left: 1px solid #9fb0c7; }
body[data-layout="handheld"] .device-view .graph-table-header { padding: .2em .4em; }
body[data-layout="handheld"] .device-view .graph-table-header h2 { font-size: .9em; }
body[data-layout="handheld"] .device-view .graph-table-view .graph-controls { display: none; }
body[data-layout="handheld"] .device-view .graph-table-wrap { flex: 1 1 auto; min-height: 0; max-height: none; font-size: .9em; }
body[data-layout="handheld"] .device-view .surface-grid { display: flex; height: 100%; }
body[data-layout="handheld"] .device-view .surface-frame { flex: 1 1 auto; height: auto; }

body[data-layout="handheld"] .device-entry {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: .3em;
  padding: .22em .35em;
  border-top: 1px solid #b8c5d6;
  background: linear-gradient(#eef2f8, #e3e9f2);
}
body[data-layout="handheld"] .device-entry[hidden] { display: none; }
body[data-layout="handheld"] .device-entry :is(select, input, button) { min-width: 0; min-height: 1.75em; border: 1px solid #94a6bf; border-radius: .25em; background: #fff; color: var(--screen-ink); font: 500 .95em ui-monospace, SFMono-Regular, Menlo, monospace; }
body[data-layout="handheld"] .device-entry select { padding: 0 .2em; border-color: transparent; background: transparent; font-weight: 700; color: #0b2a57; }
body[data-layout="handheld"] .device-entry input { padding: .1em .4em; }
body[data-layout="handheld"] .device-entry input:focus { outline: 2px solid #b8cbe6; border-color: var(--screen-select); }
body[data-layout="handheld"] .device-entry button { width: 1.9em; font-weight: 700; color: #0b2a57; }
body[data-layout="handheld"] .device-entry .math-draft { display: none; }

/* 1.3 Geometry */
body[data-layout="handheld"] .device-view .geometry-layout { display: block; height: 100%; }
body[data-layout="handheld"] .device-view .geometry-layout > .panel { height: 100%; display: flex; flex-direction: column; border: 0; border-radius: 0; box-shadow: none; }
body[data-layout="handheld"] .device-view .geometry-layout > .panel + .panel,
body[data-layout="handheld"] .device-view .geometry-toolbar { display: none; }
body[data-layout="handheld"] .device-view .geometry-canvas { flex: 1 1 auto; min-height: 0; padding: 0; }
body[data-layout="handheld"] .device-view .geometry-canvas svg { width: 100%; height: 100%; max-height: none; border: 0; border-radius: 0; }
body[data-layout="handheld"] .device-view .geometry-footer { padding: .2em .5em; font-size: .8em; border-top: 1px solid var(--screen-line); }

/* 1.4 Lists & Spreadsheet */
body[data-layout="handheld"] .device-view .data-workspace { display: flex; flex-direction: column; height: 100%; gap: 0; padding: 0; }
body[data-layout="handheld"] .device-view .data-workspace > .data-toolbar,
body[data-layout="handheld"] .device-view .data-workspace > .data-caption { display: none; }
body[data-layout="handheld"] .device-view .data-paste { margin: .3em; font-size: .9em; }
body[data-layout="handheld"] .device-view .data-grid-scroll { flex: 1 1 auto; min-height: 0; max-height: none; border: 0; border-radius: 0; font-size: .92em; }
body[data-layout="handheld"] .device-view .data-status { margin: 0; padding: .15em .5em; font-size: .8em; border-top: 1px solid var(--screen-line); }
body[data-layout="handheld"] .device-view .data-status:empty { display: none; }

/* 1.5 Data & Statistics */
body[data-layout="handheld"] .device-view .data-stat-modes { display: none; }
body[data-layout="handheld"] .device-view #view-statistics .data-workspace { overflow: auto; scrollbar-width: thin; }
body[data-layout="handheld"] .device-view #view-statistics :is(.data-summary, .data-plot-card) { border-radius: .4em; font-size: .9em; }
body[data-layout="handheld"] .device-view #view-statistics .data-controls { padding: .3em .45em; gap: .3em .6em; font-size: .85em; }
body[data-layout="handheld"] .device-view #view-statistics .data-stat-grid,
body[data-layout="handheld"] .device-view #view-statistics .data-command-grid { grid-template-columns: minmax(0, 1fr); gap: .4em; padding: 0 .4em .4em; }

/* 1.6 Notes */
body[data-layout="handheld"] .device-view #view-notes .split { display: block; height: 100%; }
body[data-layout="handheld"] .device-view #view-notes .panel { height: 100%; display: flex; flex-direction: column; border: 0; border-radius: 0; box-shadow: none; }
body[data-layout="handheld"] .device-view #view-notes .panel + .panel,
body[data-layout="handheld"] .device-view #view-notes .panel-head { display: none; }
body[data-layout="handheld"] .device-view #view-notes .notes-body { flex: 1 1 auto; display: flex; flex-direction: column; gap: .3em; padding: .4em; }
body[data-layout="handheld"] .device-view #view-notes .notes-title { padding: .2em .4em; font-size: 1em; border-radius: .25em; }
body[data-layout="handheld"] .device-view #view-notes .notes-content { flex: 1 1 auto; min-height: 0; resize: none; padding: .35em .45em; font-size: .95em; border-radius: .25em; }

/* ───── Owl coach beside the device ───── */
body[data-layout="handheld"] .coach {
  position: static;
  display: grid;
  justify-items: center;
  gap: 12px;
  width: 300px;
  padding: 18px 16px 16px;
  border: 1px solid #d5deea;
  border-radius: 20px;
  background: #fff;
  box-shadow: 0 10px 30px #0d1f3c14;
}
body[data-layout="handheld"] .coach-owl { width: 104px; }
body[data-layout="handheld"] .coach-bubble {
  position: relative;
  width: 100%;
  padding: 12px 13px;
  border-radius: 14px;
  background: #f2f6fb;
  border: 1px solid #dbe4f0;
}
body[data-layout="handheld"] .coach-bubble::before {
  content: ""; position: absolute; top: -8px; left: 50%; width: 14px; height: 14px; translate: -50% 0; rotate: 45deg;
  background: #f2f6fb; border-left: 1px solid #dbe4f0; border-top: 1px solid #dbe4f0;
}
body[data-layout="handheld"] .coach-kicker { margin: 0 0 4px; font-size: .7rem; font-weight: 750; letter-spacing: .12em; text-transform: uppercase; color: #9a6400; }
body[data-layout="handheld"] .coach-text { margin: 0; font-size: .9rem; line-height: 1.45; color: #22314d; }
body[data-layout="handheld"] .coach-keys { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; margin: 10px 0 0; padding: 0; list-style: none; }
body[data-layout="handheld"] .coach-keys:empty { display: none; }
body[data-layout="handheld"] .coach-keys li { display: inline-flex; align-items: center; gap: 4px; font-size: .78rem; color: #4b5b75; }
body[data-layout="handheld"] .coach-keys li + li::before { content: "▸"; color: #9fb0c7; }
.coach kbd, .about kbd, .guide-content kbd {
  display: inline-block; min-width: 1.6em; padding: .05em .4em; border-radius: 5px; background: #12305c; color: #fff;
  font: 650 .8em/1.5 "Photon Inter", Inter, system-ui, sans-serif; text-align: center; box-shadow: 0 2px 0 #050f20;
}
body[data-layout="handheld"] .coach-actions { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 8px 14px; }
body[data-layout="handheld"] .coach-button { min-height: 34px; padding: 6px 14px; border: 1px solid #d59200; border-radius: 999px; background: var(--gold); color: #10264a; font-size: .84rem; font-weight: 700; }
body[data-layout="handheld"] .coach-button:hover { background: #ffbd35; }
body[data-layout="handheld"] .coach-link { font-size: .84rem; font-weight: 650; color: #1b3a6b; }

@media (max-width: 1679px) {
  body[data-layout="handheld"] .coach { width: min(100%, 640px); grid-template-columns: auto minmax(0, 1fr); align-items: center; justify-items: start; padding: 12px 14px; }
  body[data-layout="handheld"] .coach-owl { width: 64px; grid-row: span 2; }
  body[data-layout="handheld"] .coach-bubble::before { top: 18px; left: -8px; rotate: -45deg; translate: 0 0; }
  body[data-layout="handheld"] .coach-actions { justify-content: flex-start; }
}

@media (prefers-reduced-motion: reduce) {
  body[data-layout="handheld"] .device-menu-column { animation: none; }
}

@container (max-width: 430px) {
  body[data-layout="handheld"] .screen-doc { display: none; }
  body[data-layout="handheld"] .screen-tabs button { padding: 0 .45em; }
}

body.hide-entry-line[data-layout="handheld"] .device-entry { display: none; }

/* Narrow phones: the top bar wraps so it never makes the page wider than the screen. */
@media (max-width: 560px) {
  .topbar:has(.layout-select) { flex-wrap: wrap; height: auto; min-height: 60px; padding: 7px 10px 8px; gap: 6px 8px; }
  .topbar:has(.layout-select) .top-actions { width: 100%; margin-left: 0; gap: 6px; }
  .topbar:has(.layout-select) .layout-select { margin-right: auto; max-width: 150px; }
  .topbar:has(.layout-select) .angle-select { max-width: 112px; }
  .topbar:has(.layout-select) .guide-button span { display: none; }
}
@media (max-width: 520px) {
  body[data-layout="handheld"] .device-key-console .handheld { --key-h: clamp(29px, 3.9dvh, 34px); }
  body[data-layout="handheld"] .device-key-console .handheld-letter-row .handheld-key { min-height: 26px; }
  body[data-layout="handheld"] .device-key-console .handheld-letters { margin-top: 7px; padding-top: 7px; }
  body[data-layout="handheld"] .device-key-console .handheld-pad { aspect-ratio: 1.6; }
  body[data-layout="handheld"] .device-brand { min-height: 26px; }
}
