/* =================================================================================================
   Aniseikonia – the look of the Thomson apps (Eye Dynamix / LogMAR Scorer / Stimulus Generator):
   navigation rail with the Thomson logo, top bar, dark blue title band, near-white cards.
   Three colour sets: White (light), Black (dark) and Blue.
   Test page: the target fills the main area, options on the right; Full screen gives the target the
   whole screen with fading buttons. On a phone the options become a bottom sheet.
   ================================================================================================= */
:root, html[data-theme="light"] {
  --canvas: #eef2f6; --surface: #ffffff; --surface-alt: #f6f8fa; --input: #ffffff;
  --ink: #1b2733; --muted: #5b6b7b; --border: #d5dde5; --grid: #e8edf2;
  --primary: #095595; --primary-hover: #0e67b2; --primary-soft: #dce9f6; --on-primary: #fff;
  --nav: #0c2e52; --nav-fore: #ffffff; --nav-muted: #a5bdd6; --nav-selected: #095595;
  --header: #ffffff; --header-fore: #1b2733; --header-muted: #5b6b7b;
  --danger: #b42318; --danger-soft: #fdeceb; --success: #16803d; --success-soft: #e1f5e8;
  --warning: #b06a00; --warning-soft: #fff3dc; --band: #1b4884; --select: #dce9f6;
  --cell: #ffffff; --cell-ink: #111820; --cross: #d12a1f; --near: #c0261b;
  color-scheme: light;
}
html[data-theme="dark"] {
  --canvas: #17191c; --surface: #212428; --surface-alt: #2a2e33; --input: #1c1f23;
  --ink: #e8eaed; --muted: #9aa3ad; --border: #3a3f46; --grid: #30343a;
  --primary: #3d8bda; --primary-hover: #569ee6; --primary-soft: #1e3a56; --on-primary: #fff;
  --nav: #111316; --nav-fore: #e8eaed; --nav-muted: #828c96; --nav-selected: #284668;
  --header: #1c1f23; --header-fore: #e8eaed; --header-muted: #9aa3ad;
  --danger: #ef6155; --danger-soft: #46201e; --success: #57c878; --success-soft: #1c3c28;
  --warning: #f0b446; --warning-soft: #463719; --band: #1b3a63; --select: #284668;
  --cell: #f4f5f7; --cell-ink: #111820; --cross: #e0362b; --near: #ff7a70;
  color-scheme: dark;
}
html[data-theme="blue"] {
  --canvas: #bfcddb; --surface: #fbfcfe; --surface-alt: #ecf2f8; --input: #f4f8fc;
  --ink: #102136; --muted: #364e69; --border: #96aeca; --grid: #c9d6e4;
  --primary: #1f4e79; --primary-hover: #2a6194; --primary-soft: #b0c7e0; --on-primary: #fff;
  --nav: #1f4e79; --nav-fore: #ffffff; --nav-muted: #bed2e6; --nav-selected: #5b80a8;
  --header: #99b4d1; --header-fore: #102136; --header-muted: #364e69;
  --danger: #aa1e14; --danger-soft: #f6dedc; --success: #147337; --success-soft: #d6eede;
  --warning: #a05f00; --warning-soft: #f6e9cd; --band: #1b4884; --select: #b0c7e0;
  --cell: #ffffff; --cell-ink: #102136; --cross: #c8231a; --near: #b3170e;
  color-scheme: light;
}


* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--canvas); color: var(--ink); font: 14px/1.4 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif; -webkit-tap-highlight-color: transparent; }
button, select, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
.hidden { display: none !important; }
[hidden] { display: none !important; }
svg.i { width: 18px; height: 18px; flex: none; }
.muted { color: var(--muted); font-size: 12.5px; margin: 0 0 4px; }

.app { display: flex; height: 100vh; height: 100dvh; }

/* ---------- Navigation rail ---------- */
.rail { width: 208px; flex: none; background: var(--nav); color: var(--nav-fore); display: flex; flex-direction: column; padding: 0 0 10px; overflow-y: auto; }
.rail .logo { display: flex; align-items: center; gap: 10px; min-height: 74px; padding: 12px 16px; font-size: 15px; font-weight: 600; line-height: 1.15; }
.rail .logo img { width: 36px; height: 36px; flex: none; }
.rail .logo .sub { display: block; font-size: 11.5px; font-weight: 400; color: var(--nav-muted); margin-top: 2px; }
.rail .item { position: relative; display: flex; align-items: center; gap: 14px; height: 42px; margin: 2px 8px; padding: 0 12px; border: 0; border-radius: 8px; background: transparent; color: var(--nav-muted); font-weight: 600; font-size: 13.5px; cursor: pointer; text-align: left; text-decoration: none; }
.rail .item:hover { background: rgba(255,255,255,.11); color: var(--nav-fore); }
.rail .item.on { background: var(--nav-selected); color: var(--nav-fore); }
.rail .item.on::before { content: ""; position: absolute; left: 0; top: 10px; bottom: 10px; width: 3px; border-radius: 2px; background: var(--nav-fore); }
.rail .grow { flex: 1; }
.rail .thomson { display: block; margin: 10px 8px 0; background: #fff; border-radius: 8px; padding: 10px 12px; }
.rail .thomson img { display: block; width: 100%; }

/* ---------- Top bar ---------- */
.body { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { position: relative; display: flex; align-items: center; gap: 10px; height: 60px; flex: none; padding: 0 22px; background: var(--header); color: var(--header-fore); border-bottom: 1px solid var(--border); }
.topbar .mlogo { display: none; width: 30px; height: 30px; }
.topbar .ttl b { display: block; font-size: 15px; }
.topbar .ttl small { display: block; font-size: 12px; color: var(--header-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 52vw; }
.spacer { flex: 1; }
.chip { display: inline-flex; align-items: center; gap: 8px; height: 28px; padding: 0 12px; border-radius: 14px; background: var(--surface-alt); color: var(--ink); font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.chip.warn { background: var(--warning-soft); } .chip.warn .dot { background: var(--warning); }
.iconbtn { width: 38px; height: 38px; display: grid; place-items: center; border: 0; border-radius: 8px; background: transparent; color: inherit; }
.iconbtn:hover { background: var(--surface-alt); }
.iconbtn svg.i { width: 20px; height: 20px; }
.monly { display: none; }
.menu { position: absolute; right: 14px; top: 54px; z-index: 60; background: var(--surface); color: var(--ink); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.18); padding: 6px; min-width: 210px; }
.menu button, .menu a { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border: 0; border-radius: 6px; background: transparent; cursor: pointer; text-align: left; text-decoration: none; font-size: 14px; }
.menu button:hover, .menu a:hover { background: var(--surface-alt); }
.menu button.on { font-weight: 700; color: var(--primary); }
.menu .sep { height: 1px; background: var(--border); margin: 6px 4px; }
.menu .note { padding: 4px 10px 2px; font-size: 11.5px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.swatch { width: 14px; height: 14px; border-radius: 3px; border: 1px solid var(--border); }

/* ---------- Main area and title band ---------- */
main { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 18px 22px 20px; gap: 14px; }
.band { flex: none; display: flex; align-items: center; gap: 8px; background: var(--band); color: #fff; border-radius: 4px; padding: 12px 14px 11px 20px; }
.band h1 { font-size: 21px; margin: 0; font-weight: 600; line-height: 1.2; }
.band p { margin: 3px 0 0; font-size: 12.5px; opacity: .85; }
.band .grow { flex: 1; min-width: 0; }
.bandtools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.bandbtn { display: inline-flex; align-items: center; gap: 7px; padding: 7px 12px; border: 1px solid rgba(255,255,255,.45); border-radius: 6px; background: transparent; color: #fff; font-size: 13px; font-weight: 600; white-space: nowrap; }
.bandbtn:hover { background: rgba(255,255,255,.15); }
.bandbtn:disabled { opacity: .4; cursor: default; background: transparent; }
.bandbtn.solid { background: #fff; color: var(--band); border-color: #fff; }
.bandbtn.solid:hover { background: #e8eef6; }
.bandchk { display: inline-flex; align-items: center; gap: 7px; padding: 6px 10px; border: 1px solid rgba(255,255,255,.45); border-radius: 6px; color: #fff; font-size: 13px; font-weight: 600; cursor: pointer; user-select: none; white-space: nowrap; }
.bandchk input { width: 16px; height: 16px; margin: 0; accent-color: #f5a623; cursor: pointer; }
.bandchk:has(input:checked) { background: rgba(245,166,35,.22); border-color: #f5a623; }
.band .help { flex: none; width: 32px; height: 32px; border: 0; border-radius: 50%; background: transparent; color: #fff; font-size: 16px; font-weight: 600; opacity: .8; }
.band .help:hover { background: rgba(255,255,255,.15); opacity: 1; }

.content { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 14px; }
.chartcol { min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; align-items: center; padding-bottom: 4px; }
.side { min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; padding-right: 2px; }
.sheethead { display: none; }

/* ---------- Cards and controls ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 14px 16px; }
.card h2 { position: relative; font-size: 15px; margin: 0 0 12px; padding-left: 12px; color: var(--primary); font-weight: 600; }
.card h2::before { content: ""; position: absolute; left: 0; top: 2px; bottom: 2px; width: 3px; border-radius: 2px; background: var(--primary); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 8px 14px; font-weight: 600; font-size: 13px; }
.btn:hover { border-color: var(--primary); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn.primary:hover { background: var(--primary-hover); }
.btn.flat { border-color: transparent; background: transparent; }
.btn.flat:hover { background: var(--surface-alt); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn:disabled { opacity: .45; cursor: default; }
.buttons { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; align-items: center; }
select, input[type=text] { width: 100%; background: var(--input); border: 1px solid var(--border); border-radius: 4px; padding: 7px 9px; min-height: 36px; }
select:focus, input:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
.row { display: grid; grid-template-columns: 60px 1fr; align-items: center; gap: 8px; margin: 6px 0; }
.row > span { font-size: 13px; color: var(--muted); font-weight: 600; }
.switch { display: flex; align-items: center; gap: 10px; padding: 7px 0; cursor: pointer; user-select: none; }
.switch input { width: 18px; height: 18px; margin: 0; accent-color: var(--primary); flex: none; }
.switch small { color: var(--muted); }
.tag { display: inline-block; padding: 2px 9px; border-radius: 10px; font-size: 11.5px; font-weight: 600; background: var(--surface-alt); color: var(--muted); white-space: nowrap; }
.tag.good { background: var(--success-soft); color: var(--success); }


/* ---------- Dialog and toast ---------- */
dialog { border: 1px solid var(--border); border-radius: 10px; padding: 0; background: var(--surface); color: var(--ink); width: min(460px, calc(100vw - 28px)); box-shadow: 0 18px 50px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(10,20,35,.45); }
dialog .dh { background: var(--band); color: #fff; padding: 13px 18px; font-size: 17px; font-weight: 600; }
dialog .db { padding: 16px 18px; max-height: 64vh; overflow-y: auto; }
dialog .db p { margin: 0 0 10px; }
dialog .db h3 { font-size: 14px; color: var(--primary); margin: 14px 0 6px; }
dialog .db ul { margin: 0 0 8px; padding-left: 20px; } dialog .db li { margin: 4px 0; }
dialog .df { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px 16px; }
dialog .err { color: var(--danger); font-size: 12.5px; min-height: 18px; margin-top: 6px; }
dialog .radio { display: flex; gap: 8px; align-items: center; padding: 6px 0; }
.ic { display: inline-grid; place-items: center; width: 26px; height: 26px; border: 1px solid var(--border); border-radius: 5px; vertical-align: middle; color: var(--primary); background: var(--surface-alt); }
.ic svg.i { width: 18px; height: 18px; }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--success); color: #fff; padding: 9px 18px; border-radius: 6px; z-index: 90; font-weight: 600; box-shadow: 0 6px 18px rgba(0,0,0,.2); white-space: nowrap; }
.backdrop { position: fixed; inset: 0; background: rgba(10,20,35,.45); z-index: 70; }



/* ---------- Layout ---------- */
.content { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 14px; }
.stagecol { min-height: 0; display: flex; }
.side { min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; padding-right: 2px; }
.sheethead { display: none; }
.lbl { font-size: 12.5px; font-weight: 600; color: var(--muted); margin: 12px 0 6px; }
.card h2 + .lbl { margin-top: 0; }
.off { opacity: .35; pointer-events: none; }
.note { margin-top: 10px; padding: 8px 10px; border-radius: 6px; background: var(--warning-soft); font-size: 12.5px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.note .btn { padding: 5px 10px; }

/* the meridian / method choices in the band */
.segs { display: inline-flex; border: 1px solid rgba(255,255,255,.45); border-radius: 6px; overflow: hidden; }
.segs button { border: 0; background: transparent; color: #fff; padding: 7px 14px; font-weight: 600; font-size: 13px; }
.segs button + button { border-left: 1px solid rgba(255,255,255,.3); }
.segs button.on { background: rgba(255,255,255,.22); }
.segs button:hover:not(.on) { background: rgba(255,255,255,.1); }
.bandbtn svg.i { width: 16px; height: 16px; }


/* ---------- The stimulus ---------- */
.stage { position: relative; flex: 1; min-height: 240px; border-radius: 8px; overflow: hidden; border: 1px solid var(--border); background: #000; touch-action: manipulation; }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.stagechips { position: absolute; left: 10px; bottom: 10px; display: flex; gap: 6px; pointer-events: none; }
.pchip { background: rgba(20,30,45,.72); color: #fff; font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 10px; font-variant-numeric: tabular-nums; white-space: pre; }
.presentbar { display: none; position: absolute; top: max(12px, env(safe-area-inset-top)); right: max(12px, env(safe-area-inset-right)); gap: 6px; z-index: 5; transition: opacity .4s; }
.pbtn { width: 44px; height: 44px; display: grid; place-items: center; border: 1px solid rgba(255,255,255,.35); border-radius: 10px; background: rgba(20,30,45,.72); color: #fff; }
.pbtn:hover { background: rgba(20,30,45,.9); }
.pbtn svg.i { width: 20px; height: 20px; }

/* full screen */
body.present .stage { position: fixed; inset: 0; z-index: 60; border: 0; border-radius: 0; }
body.present .presentbar { display: flex; }
body.present .stagechips { display: none; }
body.present.idle .presentbar { opacity: 0; pointer-events: none; }
body.present.idle { cursor: none; }
body.present .side { display: none; }
body.present.popts .side { display: flex; position: fixed; z-index: 65; top: 68px; right: 14px; width: 340px; max-height: calc(100vh - 82px); background: var(--canvas); padding: 10px; border-radius: 10px; box-shadow: 0 12px 40px rgba(0,0,0,.35); }

/* ---------- Two- or three-way choices in the cards ---------- */
.segs2 { display: flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.segs2 button { flex: 1; border: 0; background: var(--surface); padding: 8px 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
.segs2 button + button { border-left: 1px solid var(--border); }
.segs2 button.on { background: var(--primary); color: var(--on-primary); }

/* ---------- Sliders with a number box ---------- */
.slider { margin-top: 14px; }
.shead { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.shead label { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.num { display: inline-flex; align-items: center; border: 1px solid var(--border); border-radius: 6px; background: var(--input); overflow: hidden; }
.num input { width: 58px; border: 0; background: transparent; text-align: right; padding: 5px 2px; font-weight: 600; font-variant-numeric: tabular-nums; -moz-appearance: textfield; }
.num input::-webkit-inner-spin-button, .num input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.num input:focus { outline: none; }
.num .unit { font-size: 12px; color: var(--muted); padding: 0 6px 0 2px; min-width: 8px; }
.num .step { width: 30px; height: 30px; border: 0; background: var(--surface-alt); font-size: 16px; font-weight: 600; color: var(--primary); touch-action: manipulation; }
.num .step:first-child { border-right: 1px solid var(--border); } .num .step:last-child { border-left: 1px solid var(--border); }
.slider input[type=range] { width: 100%; margin: 10px 0 2px; accent-color: var(--primary); height: 22px; }
.sends { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); }

/* =================================================================================================
   Aniseikonia
   ================================================================================================= */
.rail .item .count { margin-left: auto; min-width: 22px; height: 20px; padding: 0 6px; border-radius: 10px; background: rgba(255,255,255,.18); color: var(--nav-fore); font-size: 11.5px; display: grid; place-items: center; }
.rail .item .count:empty { display: none; }
.chip[role=button] { cursor: pointer; }
.menu .monlyb { display: none; }

/* pages */
.page { display: none !important; }
body[data-page="test"] #page-test { display: grid !important; }
body[data-page="results"] #page-results, body[data-page="rx"] #page-rx, body[data-page="setup"] #page-setup { display: block !important; }
.bandtools[class*="pg-"] { display: none; }
body[data-page="test"] .bandtools.pg-test, body[data-page="results"] .bandtools.pg-results { display: flex; }
body:not([data-page="test"]) #optsBtn { display: none; }
.pagewrap { flex: 1; min-height: 0; overflow-y: auto; }
.cols { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 14px; align-items: start; }
.col { display: flex; flex-direction: column; gap: 14px; min-width: 0; }

/* method */
body[data-mode="manual"] .m-guided, body[data-mode="guided"] .m-manual { display: none; }
body[data-mode="guided"] .monly-manual { display: none; }

/* stage extras */
.warnchip { background: rgba(176,106,0,.9); }
.pbtn { font-size: 24px; font-weight: 600; line-height: 1; }
.guidedbar { display: none; position: absolute; left: 50%; bottom: max(14px, env(safe-area-inset-bottom)); transform: translateX(-50%); gap: 8px; z-index: 4; }
body[data-mode="guided"].grun .guidedbar { display: flex; }
.gbtn { display: inline-flex; align-items: center; gap: 8px; min-height: 46px; padding: 0 16px; border: 1px solid rgba(255,255,255,.3); border-radius: 10px; background: rgba(40,48,60,.75); color: #e6e9ee; font-weight: 600; font-size: 14px; white-space: nowrap; touch-action: manipulation; }
.gbtn:hover { background: rgba(60,70,85,.9); }
.gbtn.same { background: rgba(40,48,60,.5); }
.gbtn .arr { font-size: 12px; opacity: .8; }
.gbtn.flash { background: #095595; }
.guidedstart { position: absolute; left: 50%; bottom: max(14px, env(safe-area-inset-bottom)); transform: translateX(-50%); display: flex; align-items: center; gap: 14px; padding: 10px 12px 10px 16px; border-radius: 10px; background: rgba(20,30,45,.85); color: #fff; z-index: 4; max-width: calc(100% - 24px); }
.guidedstart b { display: block; font-size: 14px; } .guidedstart span { display: block; font-size: 12px; opacity: .8; }
body:not([data-mode="guided"]) .guidedstart, body.grun .guidedstart { display: none !important; }
body.present.idle .guidedbar { opacity: .55; }
body[data-mode="guided"] .stagechips { top: 10px; bottom: auto; }

/* guided progress */
.progress { height: 8px; border-radius: 4px; background: var(--surface-alt); border: 1px solid var(--border); overflow: hidden; margin: 10px 0 6px; }
.progress .bar { height: 100%; width: 0; background: var(--primary); transition: width .2s; }
.gstat { font-size: 12.5px; color: var(--muted); font-weight: 600; margin-bottom: 4px; font-variant-numeric: tabular-nums; }

/* result now */
.resnow { display: flex; align-items: center; gap: 12px; }
.resnow .big { font-size: 30px; font-weight: 700; color: var(--primary); line-height: 1.1; font-variant-numeric: tabular-nums; }
.restext { margin: 8px 0 4px; font-weight: 600; }
.tag.none { background: var(--success-soft); color: var(--success); }
.tag.small { background: var(--primary-soft); color: var(--primary); }
.tag.moderate { background: var(--warning-soft); color: var(--warning); }
.tag.large { background: var(--danger-soft); color: var(--danger); }
.sizeinfo { margin-top: 8px; font-size: 12.5px; color: var(--muted); }
.sizeinfo b { color: var(--ink); }
.sizeinfo a { color: var(--primary); font-weight: 600; }
.segs2.small button { font-size: 12px; padding: 8px 3px; }
.colours { display: none; gap: 14px; margin-top: 10px; }
.colours.on { display: flex; }
.colours label { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: var(--muted); }
.colours input[type=color] { width: 44px; height: 32px; padding: 2px; border: 1px solid var(--border); border-radius: 6px; background: var(--input); }
.switch span { font-size: 13.5px; }

/* summary tiles */
.summary { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 14px 16px; }
.tile .k { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.tile .v { font-size: 34px; font-weight: 700; color: var(--primary); line-height: 1.15; margin-top: 6px; font-variant-numeric: tabular-nums; }
.tile .v small { font-size: 15px; font-weight: 600; color: var(--muted); margin-left: 6px; }
.tile .t { margin-top: 6px; font-size: 13px; }
.tile .m { margin-top: 6px; font-size: 12px; color: var(--muted); }
.tile.empty .v { color: var(--muted); }
.tile .btn { margin-top: 10px; padding: 5px 10px; }

/* tables */
.tablewrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
.tbl th { text-align: left; font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 6px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.tbl td { padding: 8px; border-bottom: 1px solid var(--grid); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl td.n { text-align: right; font-weight: 700; }
.tbl .x { width: 30px; height: 30px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); font-size: 18px; line-height: 1; }
.tbl .x:hover { background: var(--danger-soft); color: var(--danger); }
.tbl tr.latest td:first-child { box-shadow: inset 3px 0 var(--primary); }

/* form fields */
.field { display: block; margin: 0 0 10px; }
.field > span { display: block; font-size: 12.5px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
textarea, input[type=number] { width: 100%; background: var(--input); border: 1px solid var(--border); border-radius: 4px; padding: 7px 9px; min-height: 36px; resize: vertical; }
textarea:focus, input[type=number]:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
.row2 { display: flex; align-items: flex-end; gap: 12px; margin-top: 12px; }
.row2 .field { width: 180px; margin: 0; }
.row2 .buttons { margin: 0 0 2px; }
.rxin { width: 100%; border-collapse: separate; border-spacing: 8px 6px; margin: 0 -8px; }
.rxin th { font-size: 12.5px; font-weight: 600; color: var(--muted); text-align: left; }
.rxin thead th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; }
.rxin input { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.rxwarn { color: var(--warning); font-weight: 600; }

/* calibration */
.calbox { display: grid; place-items: center; padding: 18px 0; overflow: hidden; }
.card-shape { width: var(--cw, 324px); aspect-ratio: 85.6 / 53.98; border-radius: calc(var(--cw, 324px) * .037); border: 2px solid var(--primary); background: repeating-linear-gradient(45deg, var(--primary-soft) 0 10px, transparent 10px 20px); display: grid; place-items: center; }
.card-shape span { background: var(--surface); padding: 2px 8px; border-radius: 4px; font-size: 12px; font-weight: 600; color: var(--muted); }
.calstat { font-size: 13px; margin: 12px 0 0; }
.calstat.ok { color: var(--success); } .calstat.warn { color: var(--warning); font-weight: 600; }
.tips, .bands { margin: 0; padding-left: 18px; font-size: 13px; }
.tips li, .bands li { margin: 6px 0; }
.bands li b { display: inline-block; min-width: 84px; }

/* the guided test chart in the dialog */
.gchart { width: 100%; height: auto; display: block; margin: 8px 0 4px; background: var(--surface-alt); border: 1px solid var(--border); border-radius: 6px; }
dialog.wide { width: min(620px, calc(100vw - 28px)); }
.bigres { font-size: 30px; font-weight: 700; color: var(--primary); }
.kbd { display: inline-block; min-width: 22px; padding: 0 5px; border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 4px; background: var(--surface-alt); font-size: 12px; font-weight: 600; text-align: center; }
table.keys { border-collapse: collapse; font-size: 13px; } table.keys td { padding: 3px 10px 3px 0; vertical-align: top; }

/* printing */
.printout { display: none; }
@media print {
  @page { margin: 16mm; }
  body { background: #fff; color: #000; font-size: 11pt; }
  .app, dialog, .toast, .backdrop { display: none !important; }
  .printout { display: block; }
  .printout header { display: flex; align-items: center; justify-content: space-between; border-bottom: 2px solid #1b4884; padding-bottom: 8px; margin-bottom: 14px; }
  .printout header img { height: 44px; }
  .printout h1 { font-size: 18pt; margin: 0; color: #1b4884; }
  .printout .meta { margin: 0 0 14px; } .printout .meta td { padding: 2px 16px 2px 0; }
  .printout table.r { width: 100%; border-collapse: collapse; margin: 6px 0 14px; }
  .printout table.r th, .printout table.r td { border: 1px solid #999; padding: 5px 7px; text-align: left; vertical-align: top; }
  .printout table.r th { background: #e8eef6; }
  .printout h2 { font-size: 12pt; color: #1b4884; margin: 14px 0 4px; }
  .printout .small { font-size: 9pt; color: #444; }
}

/* =================================================================================================
   Tablet: narrower rail
   ================================================================================================= */
@media (max-width: 1100px) {
  .rail { width: 64px; }
  .rail .logo { padding: 14px; justify-content: center; }
  .rail .logo > span { display: none; }
  .rail .item { font-size: 0; gap: 0; justify-content: center; padding: 0; }
  .rail .item svg.i { width: 22px; height: 22px; }
  .rail .thomson { padding: 6px; }
  .content { grid-template-columns: minmax(0, 1fr) 310px; }
}

/* =================================================================================================
   Phone (and a phone on its side)
   ================================================================================================= */
@media (max-width: 760px), (max-height: 520px) {
  .rail { display: none; }
  .topbar { height: calc(54px + env(safe-area-inset-top)); padding: env(safe-area-inset-top) 6px 0 12px; gap: 6px; background: var(--nav); color: var(--nav-fore); border-bottom: 0; }
  .topbar .mlogo { display: block; }
  .topbar .ttl small { color: var(--nav-muted); }
  .iconbtn:hover { background: rgba(255,255,255,.12); }
  .monly { display: grid; }
  main { padding: 0; gap: 0; }
  .band { border-radius: 0; padding: 8px 6px 8px 10px; }
  .band .grow { display: none; }
  .bandtools { flex: 1; justify-content: flex-start; flex-wrap: nowrap; }
  .bandbtn { padding: 7px 10px; }
  .content { display: flex; padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); }
  .stagecol { flex: 1; }
  .stage { min-height: 0; }

  .side { position: fixed; left: 0; right: 0; bottom: 0; z-index: 80; max-height: 78vh; max-height: 78dvh; padding: 0 12px calc(16px + env(safe-area-inset-bottom)); background: var(--canvas); border-radius: 16px 16px 0 0; box-shadow: 0 -10px 40px rgba(0,0,0,.25); transform: translateY(105%); transition: transform .22s ease; gap: 10px; }
  body.sheet .side { transform: none; }
  body.present.sheet .side { display: flex; }
  .sheethead { display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 1; background: var(--canvas); padding: 12px 2px 6px; font-size: 16px; }
  .sheethead::before { content: ""; position: absolute; left: 50%; top: 5px; width: 40px; height: 4px; margin-left: -20px; border-radius: 2px; background: var(--border); }
  .backdrop { z-index: 75; }
  .swatches { gap: 8px; }
  .sw { aspect-ratio: auto; height: 36px; min-height: 0; }
  .toast { bottom: calc(24px + env(safe-area-inset-bottom)); }
  .menu { top: calc(50px + env(safe-area-inset-top)); right: 8px; }
}
@media (max-width: 400px) {
  .bandbtn span { display: none; }
  .bandbtn { padding: 7px 9px; }
}
@media (max-height: 520px) {
  .topbar { height: calc(44px + env(safe-area-inset-top)); }
  .topbar .ttl small { display: none; }
  .band { padding: 5px 8px; }
  .side { max-height: 92vh; max-height: 92dvh; }
}

/* Aniseikonia: phone */
@media (max-width: 1100px) {
  .cols { grid-template-columns: minmax(0, 1fr) 300px; }
}
@media (max-width: 900px) {
  .cols { grid-template-columns: 1fr; }
}
@media (max-width: 760px), (max-height: 520px) {
  .menu .monlyb { display: flex; }
  .menu div.note.monlyb { display: block; }
  .menu .sep.monlyb { display: block; }
  .pagewrap { padding: 10px 10px calc(14px + env(safe-area-inset-bottom)); }
  .bandtools .segs button { padding: 7px 9px; }
  body[data-page="test"] #page-test { display: flex !important; }
  body:not([data-page="test"]) .band .grow { display: block; }
  body:not([data-page="test"]) .band p { display: none; }
  body:not([data-page="test"]) .band { padding: 8px 6px 8px 14px; }
  .band h1 { font-size: 18px; }
  .gbtn { min-height: 44px; padding: 0 10px; font-size: 13px; }
  .guidedbar { width: calc(100% - 16px); justify-content: center; }
  .chip#calChip { display: none !important; }
  .summary { grid-template-columns: 1fr 1fr; gap: 10px; }
  .tile .v { font-size: 26px; }
  .row2 { flex-wrap: wrap; }
}
@media (max-width: 480px) {
  .gbtn .arr { display: none; }
  .gbtn { white-space: normal; line-height: 1.15; text-align: center; justify-content: center; flex: 1; }
  .bandtools .bandbtn.solid span { display: none; }
}
