/* pico-mac -- the page's layout: the screen (the PicoCalc's 320x320 panel, or the PC at its own resolution
   in a 4:3 box), a toolbar, the touchpad's two buttons, a PC keyboard and the menus as touch screens.
   Portrait stacks them; landscape puts the screen at the left and the rest beside it, or (no room)
   lays the keyboard over the screen. */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
input, textarea { user-select: text; -webkit-user-select: text; }
html, body { margin: 0; height: 100%; background: #000; color: #ddd; overflow: hidden;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: none; overscroll-behavior: none; }
button { font: inherit; color: inherit; }

/* iOS 26's Safari blurs a band just under the status bar (its edge effect, which a page can't turn
   off), so the screen starts a little lower than the safe area alone; no notch, no extra space. */
#app { position: fixed; inset: 0; display: flex;
  padding: calc(env(safe-area-inset-top) + min(env(safe-area-inset-top), 20px)) env(safe-area-inset-right)
    env(safe-area-inset-bottom) env(safe-area-inset-left); }

#screen-wrap { position: relative; overflow: hidden; display: flex; align-items: center; justify-content: center; background: #000; }
#screen { width: 100%; height: 100%; object-fit: contain; image-rendering: pixelated; display: block; touch-action: none; }
#screen.locked { cursor: none; }

#toolbar { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
#toolbar button { width: 44px; height: 36px; border-radius: 10px; border: 1px solid #333; background: #1c1c22; font-size: 18px; }
#toolbar button.on { background: #2e4f8a; border-color: #4a73c0; }

/* ---------- touchpad buttons ---------- */
#mbtns { display: flex; gap: 6px; padding: 0 4px 4px; }
#mbtns[hidden] { display: none; }
.mb { flex: 1; height: 34px; border: none; border-radius: 8px; background: #2b2b33; font-size: 12px; color: #aab; touch-action: none; }
.mb.on { background: #6a8fd8; color: #fff; }

/* ---------- the trackpad (🖱): in the keyboard's place ---------- */
#pad { flex: 1; min-height: 120px; margin: 0 4px 6px; border-radius: 16px; touch-action: none;
  background: radial-gradient(circle at 50% 40%, #23232c, #18181e); border: 1px solid #2e2e38;
  display: flex; align-items: flex-end; justify-content: center; padding: 10px 14px; }
#pad span { font-size: 11.5px; color: #667; text-align: center; pointer-events: none; }
#pad.touch { border-color: #4a73c0; }
#pad[hidden] { display: none; }
#app.padmode #mbtns .mb { height: 48px; font-size: 13px; }

/* ---------- keyboard ---------- */
#kbd { display: flex; flex-direction: column; gap: 4px; padding: 4px; background: #15151a; }
#kbd .krow { display: flex; gap: 4px; }
#kbd .k { flex: 1 1 0; min-width: 0; height: var(--kh, 38px); border: none; border-radius: 6px; background: #2b2b33;
  font-size: 14px; padding: 0; touch-action: none; display: flex; flex-direction: column; align-items: center;
  justify-content: center; line-height: 1.05; overflow: hidden; }
#kbd .k span { white-space: nowrap; }
#kbd .k small { font-size: 9px; opacity: .65; white-space: nowrap; }
#kbd .k.mod { background: #3a3a46; font-size: 11px; }
#kbd .k.fkey { background: #33384a; font-size: 11px; }
#kbd .k.latch { background: #2e4f8a !important; }
#kbd .k.down { background: #6a8fd8 !important; }
/* the game keyboard (🎮): a 14-column grid of big keys, its rows sharing the keyboard's height */
#kbd.game { display: grid; grid-template-columns: repeat(14, 1fr);
  grid-template-rows: repeat(4, minmax(calc(var(--kh, 38px) * 1.3), 1fr)); gap: 6px; padding: 6px; }
#kbd.game[hidden] { display: none; }
#kbd.game .k { height: auto; border-radius: 12px; font-size: 20px; font-weight: 600; }
#kbd.game .k.mod { font-size: 15px; font-weight: 500; }
#kbd.game .k.diag { background: #25252c; color: #aab; }
#kbd.game .gl, #kbd.game .gr { display: contents; }
#kbd.game .k { grid-column: var(--pc); grid-row: var(--pr); }
#kbd.game .k.split { display: none; }

/* ---------- landscape game keys: screen in the middle, the keys split to both sides ---------- */
#app.gsplit { display: grid; grid-template-columns: 1fr var(--scrw) 1fr; grid-template-rows: auto 1fr; }
#app.gsplit #screen-wrap { grid-column: 2; grid-row: 1 / span 2; height: 100%; }
#app.gsplit #toolbar { grid-column: 1; grid-row: 1; padding: 6px 4px 0; gap: 4px; }
#app.gsplit #toolbar button { width: 38px; height: 32px; font-size: 15px; }
#app.gsplit #mbtns { grid-column: 3; grid-row: 1; padding: 6px 6px 0; align-self: start; }
#app.gsplit #kbd { display: contents; }
#app.gsplit #kbd .gl, #app.gsplit #kbd .gr { display: grid; grid-row: 2; gap: 5px; padding: 6px; min-height: 0; background: #15151a; }
#app.gsplit #kbd .gl { grid-column: 1; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(4, 1fr); }
#app.gsplit #kbd .gr { grid-column: 3; grid-template-columns: repeat(6, 1fr); grid-template-rows: repeat(5, 1fr); }
#app.gsplit #kbd .k { grid-column: var(--sc); grid-row: var(--sr); font-size: 18px; }
#app.gsplit #kbd .k.mod { font-size: 13px; }
#app.gsplit #kbd .k.split { display: flex; }

/* ---------- portrait: screen on top, then the toolbar, the buttons and the keyboard ---------- */
#app.portrait { flex-direction: column; }
#app.portrait #screen-wrap { width: 100%; aspect-ratio: var(--ar, 1); flex: 0 1 auto; min-height: 0; max-height: var(--scrh, 60vh); }
#app.portrait #toolbar { padding: 6px 0; }
#app.portrait #kbd { flex: 1; justify-content: flex-end; }

/* ---------- landscape (side): the square screen at the left, the rest in a column beside it ---------- */
#app.side { display: grid; grid-template-columns: var(--scrw) 1fr; grid-template-rows: auto auto 1fr; }
#app.side #screen-wrap { grid-row: 1 / span 3; grid-column: 1; height: 100%; }
#app.side #toolbar { grid-column: 2; padding: 6px 0; }
#app.side #mbtns { grid-column: 2; }
#app.side.padmode { grid-template-rows: auto 1fr auto; }
#app.side #pad { grid-column: 2; }
#app.side #kbd { grid-column: 2; justify-content: flex-end; }

/* ---------- landscape (overlay): the screen fills the height, the keyboard lies over its bottom ---------- */
#app.overlay #screen-wrap { position: absolute; inset: 0; }
#app.overlay #toolbar { position: absolute; top: 6px; right: 6px; flex-direction: column; opacity: .6; z-index: 5; }
#app.overlay #toolbar button { width: 38px; height: 30px; font-size: 15px; }
#app.overlay #mbtns { position: absolute; left: 6px; top: 6px; flex-direction: column; width: 70px; opacity: .6; z-index: 5; }
#app.overlay #kbd { position: absolute; left: 0; right: 0; bottom: 0; z-index: 4; opacity: .9; }

/* ---------- dialogs ---------- */
.dialog { position: fixed; inset: 0; background: rgba(0,0,0,.75); display: flex; align-items: center; justify-content: center; z-index: 20; }
.dialog[hidden], #kbd[hidden] { display: none !important; }
.dlg-body { background: #1b1b21; border: 1px solid #333; border-radius: 14px; padding: 14px; width: min(560px, 94vw);
  max-height: 90vh; overflow: auto; touch-action: auto; }
.dlg-body.center { text-align: center; }
.dlg-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.dlg-head button, .dialog button, .btn { background: #2b2b33; border: 1px solid #444; border-radius: 8px; padding: 8px 14px; cursor: pointer; }
.dialog select { background: #2b2b33; color: #ddd; border: 1px solid #444; border-radius: 8px; padding: 7px; font: inherit; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 10px 0; }
.hint { font-size: 13px; color: #999; }
#boot h1 { margin: 4px 0 8px; letter-spacing: 3px; }

/* the Files screen (#files): #ui's cards, plus section titles, a note and the receive card */
.ui-sec { margin: 10px 4px 0; font-size: 12.5px; color: #99a; text-transform: uppercase; letter-spacing: .08em; }
.ui-note { margin: 8px 4px 0; font-size: 12.5px; color: #99a; line-height: 1.45; }
.ui-txt small.wrap { white-space: normal; }
.ui-adj button.wide { width: auto; padding: 0 14px; font-size: 14px; }
.recv-card { align-items: flex-start; }
.recv-url { font: 13px ui-monospace, monospace; color: #9cf; word-break: break-all; user-select: all; -webkit-user-select: all; margin-top: 6px; }
.recv-code { font: 700 32px/1.2 ui-monospace, monospace; letter-spacing: .2em; margin: 4px 0; user-select: all; -webkit-user-select: all; }

/* ---------- the PC at its own resolution: a 4:3 picture in device pixels, scaled by app.js (fitPc, drawPc) ---------- */
#pc { display: block; touch-action: none; image-rendering: auto; }
#pc[hidden], #screen[hidden] { display: none; }
#screen-wrap.locked { cursor: none; }
#status { position: absolute; left: 6px; right: 6px; top: 6px; display: flex; justify-content: space-between;
  gap: 8px; pointer-events: none; z-index: 3; }
#status span { font: 12px/1.3 ui-monospace, monospace; color: #fff; background: rgba(0,0,0,.6); padding: 3px 7px;
  border-radius: 8px; transition: opacity .3s; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#status span:empty, #status span.off { opacity: 0; }
#st-fps { margin-left: auto; }

/* ---------- the menus as touch screens (#ui) ---------- */
#ui, #files { position: fixed; inset: 0; z-index: 10; display: flex; flex-direction: column; color: #eef;
  background: rgba(20,22,40,.94);
  -webkit-backdrop-filter: blur(14px) saturate(1.2); backdrop-filter: blur(14px) saturate(1.2);
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
#ui[hidden], #files[hidden] { display: none; }
#files { z-index: 20; }   /* over the home menu that opened it */
.ui-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px; min-height: 60px; }
.ui-btn { width: 44px; height: 44px; flex: none; border: none; border-radius: 14px; background: rgba(255,255,255,.08);
  font-size: 20px; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.ui-btn:active { background: rgba(255,255,255,.22); }
.ui-btn[hidden] { display: none; }
#ui-back, #files-back { font-size: 30px; line-height: 1; padding-bottom: 4px; }
#ui-back.hide { visibility: hidden; }
.ui-titles { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.ui-titles b { font-size: 19px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ui-titles small { font-size: 12.5px; color: #aab; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ui-titles small:empty { display: none; }
.ui-body { flex: 1; overflow-y: auto; touch-action: pan-y; -webkit-overflow-scrolling: touch; padding: 4px 12px 24px;
  overscroll-behavior: contain; }
.ui-wrap { max-width: 640px; margin: 0 auto; display: flex; flex-direction: column; gap: 8px; }
.ui-hero { text-align: center; padding: 18px 0 14px; }
.ui-hero h1 { margin: 0; font-size: 44px; letter-spacing: 2px; font-weight: 800;
  background: linear-gradient(90deg, #7fd4ff, #b48cff 55%, #ff8fd0); -webkit-background-clip: text; background-clip: text; color: transparent; }
.ui-hero p { margin: 4px 0 0; color: #aab; font-size: 13px; }

.ui-row { display: flex; align-items: center; gap: 12px; min-height: 58px; padding: 8px 12px; border-radius: 16px;
  background: rgba(255,255,255,.07); border: 1px solid rgba(255,255,255,.06); cursor: pointer; text-align: left; width: 100%;
  transition: background .12s, transform .08s; }
.ui-row:active { background: rgba(255,255,255,.18); transform: scale(.985); }
.ui-row.sel { border-color: rgba(150,170,255,.7); background: rgba(120,140,255,.16); }
.ui-row.static { cursor: default; }
.ui-ico { width: 38px; height: 38px; flex: none; border-radius: 12px; display: flex; align-items: center; justify-content: center;
  font-size: 21px; background: rgba(255,255,255,.08); }
.ui-pic { flex: none; border-radius: 8px; image-rendering: pixelated; background: #000; }
.ui-txt { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.ui-txt b { font-weight: 560; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ui-txt small { font-size: 12.5px; color: #aab; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ui-val { flex: none; max-width: 45%; font-size: 13.5px; color: #cfd6ff; background: rgba(120,140,255,.18); padding: 5px 10px;
  border-radius: 999px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ui-chev { flex: none; color: #889; font-size: 22px; }
.ui-adj { flex: none; display: flex; align-items: center; gap: 6px; }
.ui-adj button { width: 40px; height: 40px; border: none; border-radius: 12px; background: rgba(255,255,255,.12); font-size: 16px; cursor: pointer; }
.ui-adj button:active { background: rgba(255,255,255,.3); }
.ui-meter { display: flex; gap: 3px; }
.ui-meter i { width: 7px; height: 18px; border-radius: 3px; background: rgba(255,255,255,.15); }
.ui-meter i.on { background: linear-gradient(#9fd0ff, #8a7dff); }

.ui-card { margin: 12vh auto 0; max-width: 460px; padding: 22px; border-radius: 20px; background: rgba(255,255,255,.08);
  text-align: center; border: 1px solid rgba(255,255,255,.08); }
.ui-card h2 { margin: 0 0 8px; font-size: 20px; }
.ui-card p { margin: 0; color: #ccd; font-size: 15px; white-space: pre-wrap; }
.ui-card input { width: 100%; margin: 14px 0; padding: 12px 14px; font: 17px system-ui, sans-serif; color: #fff;
  background: rgba(0,0,0,.35); border: 1px solid rgba(255,255,255,.2); border-radius: 12px; outline: none; user-select: text; }
.ui-card input:focus { border-color: #8a9bff; }
.ui-actions { display: flex; gap: 10px; }
.ui-actions button { flex: 1; height: 48px; border: none; border-radius: 14px; font-size: 16px; cursor: pointer; background: rgba(255,255,255,.12); }
.ui-actions button.primary { background: linear-gradient(90deg, #5d7bff, #9a5cff); font-weight: 600; }
.spin { width: 28px; height: 28px; margin: 14px auto 0; border: 3px solid rgba(255,255,255,.2); border-top-color: #9fb0ff;
  border-radius: 50%; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#screen-wrap.abs #pc { cursor: none; }   /* touch-screen mode: the Mac draws its own pointer */
