* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

:root {
  --bg: #1e2228;
  --panel: #262b33;
  --panel2: #2e3440;
  --border: #3b4252;
  --text: #e5e9f0;
  --muted: #9aa5b5;
  --accent: #4f9cf9;
  --accent-dark: #3b7dd8;
  --danger: #e53935;
}

html, body { height: 100%; }
body {
  font-family: "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

#app { display: flex; flex-direction: column; height: 100vh; }

/* ---------- home: projects & plans ---------- */
#home { display: flex; flex-direction: column; height: 100vh; }
#homeBar {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
#homeBar .spacer { flex: 1; }
#crumbs { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.crumb { color: var(--muted); cursor: pointer; }
.crumb:hover { color: var(--text); }
.crumb.active { color: var(--text); font-weight: 600; cursor: default; }
#crumbs .sep { color: var(--muted); }

#homeBody { flex: 1; overflow-y: auto; padding: 22px 26px 60px; }
.viewhead { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.viewhead h1 { font-size: 21px; font-weight: 650; }
.headbtns { display: flex; gap: 8px; flex-wrap: wrap; }
.empty { color: var(--muted); font-size: 13.5px; line-height: 1.6; max-width: 520px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; }
.card {
  position: relative;
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  cursor: pointer;
  transition: border-color .12s, transform .12s;
}
.card:hover { border-color: var(--accent); transform: translateY(-1px); }
.cardicon { font-size: 26px; margin-bottom: 8px; }
.cardname {
  font-size: 14px; font-weight: 600; margin-bottom: 5px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.cardsub { font-size: 11.5px; color: var(--muted); line-height: 1.55; }
.cardsub b { color: var(--accent); }
.carddetails { font-size: 11.5px; color: var(--accent); margin-bottom: 4px; }
.carddetails[hidden] { display: none; }
.cardx, .cardedit {
  position: absolute; top: 8px;
  background: transparent; border: none; color: var(--muted);
  font-size: 13px; cursor: pointer; padding: 2px 5px; border-radius: 4px;
}
.cardx { right: 8px; }
.cardedit { right: 30px; }
.cardx:hover { background: var(--danger); color: #fff; }
.cardedit:hover { background: var(--panel2); color: var(--text); }

.planlabel { font-size: 13px; font-weight: 600; }
.savestate { font-size: 11.5px; color: var(--muted); min-width: 56px; }

/* ---------- top bar ---------- */
#topbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 8px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 16px; margin-right: 6px; white-space: nowrap; }
.plustag { background: #2b6cff; color: #fff; border-radius: 5px; padding: 1px 6px; font-size: 12px; vertical-align: 2px; }

.btn {
  background: var(--panel2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.btn:hover { background: #38404e; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--accent-dark); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.wide { width: 100%; margin-top: 6px; }
.btn.mode.active { background: var(--accent); border-color: var(--accent); color: #fff; }
#modeZone.mode.active { background: #6b7280; border-color: #6b7280; }
#modeCountZone.mode.active { background: #7cb342; border-color: #7cb342; }

.group { display: flex; align-items: center; gap: 6px; }
#pageLabel { font-size: 13px; color: var(--muted); min-width: 90px; text-align: center; }

.opt { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.opt input[type=range] { width: 90px; }
.opt select {
  background: var(--panel2); color: var(--text);
  border: 1px solid var(--border); border-radius: 4px; padding: 3px 6px; font-size: 12px;
}
#sensVal { min-width: 32px; }

/* ---------- sign in / sign up ---------- */
#authScreen {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg, #14161a);
}
.auth-box {
  width: min(360px, 92vw);
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 28px 26px; display: flex; flex-direction: column; gap: 4px;
}
.auth-box .brand { margin-bottom: 14px; }
.auth-box h2 { font-size: 17px; margin-bottom: 2px; }
.authfield {
  display: flex; flex-direction: column; gap: 4px;
  font-size: 12px; color: var(--muted); margin-top: 12px;
}
.authfield input {
  background: var(--panel2); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 8px 10px; font-size: 14px;
}
.authfield input:focus { outline: none; border-color: var(--accent); }
.autherror { color: var(--danger); font-size: 12.5px; margin-top: 10px; }
.autherror[hidden] { display: none; }
.authmsg { color: var(--accent); font-size: 12.5px; margin-top: 10px; }
.authmsg[hidden] { display: none; }
.author {
  display: flex; align-items: center; gap: 10px;
  margin: 14px 0 10px; color: var(--muted); font-size: 11.5px;
}
.author::before, .author::after {
  content: ""; flex: 1; height: 1px; background: var(--border);
}
.oauthbtn {
  display: flex; align-items: center; justify-content: center; gap: 9px;
  margin-top: 8px;
}
.authlinks {
  display: flex; justify-content: space-between;
  margin-top: 14px; font-size: 12px;
}
.authlinks a { color: var(--muted); text-decoration: none; }
.authlinks a:hover { color: var(--accent); }
.authlegal { margin-top: 16px; font-size: 11px; color: var(--muted); text-align: center; line-height: 1.5; }
.authlegal a { color: var(--muted); text-decoration: underline; }
.authlegal a:hover { color: var(--accent); }

/* ---------- isolate bar ---------- */
#isoBar {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 12px;
  background: #313845;
  border-bottom: 1px solid var(--border);
}
#isoLabel { font-size: 13px; font-weight: 600; margin-right: 6px; }

/* ---------- layout ---------- */
#main { display: flex; flex: 1; min-height: 0; position: relative; }

#sidebar {
  width: var(--sidebar-w, 300px);
  min-width: var(--sidebar-w, 300px);
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 12px;
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 10px;
}

/* drag the edge of the sidebar to make it wider or narrower (desktop) */
#sidebarResizer {
  flex: 0 0 6px; margin-left: -3px; margin-right: -3px;
  cursor: col-resize; z-index: 5;
  background: transparent; transition: background .12s;
}
#sidebarResizer:hover, #sidebarResizer.dragging { background: var(--accent); }

/* backdrop behind the sidebar when it slides over on a small screen */
#sidebarBackdrop {
  position: absolute; inset: 0; z-index: 8;
  background: rgba(10, 12, 16, .55);
}
#sidebarToggle { display: none; }
.sidehead { display: flex; align-items: baseline; justify-content: space-between; }
.sidetools { display: flex; gap: 5px; }
.btn.tiny { flex: 1; font-size: 11px; padding: 4px 6px; }
#sidebar h2 { font-size: 14px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); }
#grandTotal { font-size: 12px; color: var(--muted); }
#sidebarHint { font-size: 12.5px; color: var(--muted); line-height: 1.5; }
.small { font-size: 12px; }
.muted { color: var(--muted); }

/* ---------- item rows ---------- */
.symrow {
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 7px;
  cursor: pointer;
  margin-bottom: 6px;
}
.symrow.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.symrow.isolated { border-color: #ffb74d; box-shadow: 0 0 0 1px #ffb74d; }
.symrow.hiddenitem { opacity: 0.55; }
.symrow.droptarget { border-color: #7cb342; box-shadow: 0 0 0 2px #7cb342; }
.symrow .top { display: flex; align-items: center; gap: 8px; }
.symrow .swatch {
  width: 16px; height: 20px; padding: 0; flex-shrink: 0; cursor: pointer;
  border: 1px solid var(--border); border-radius: 3px; background: none;
}
.symrow .swatch::-webkit-color-swatch-wrapper { padding: 2px; }
.symrow .swatch::-webkit-color-swatch { border: none; border-radius: 2px; }

/* background: xref groups */
.xgroup {
  border: 1px solid var(--border); border-radius: 6px;
  padding: 6px; margin-bottom: 6px; background: var(--panel2);
}
.xgroup.isbg { border-color: #7cb342; }
.xhead { align-items: flex-start; gap: 7px; }
.xhead b { color: var(--text); }
.xhead i { font-size: 10.5px; color: #7cb342; font-style: normal; }
.xsub { font-size: 10.5px; color: var(--muted); line-height: 1.45; }
.xgroup details { margin-top: 6px; }
.xgroup summary { font-size: 10.5px; color: var(--muted); cursor: pointer; }
.xgroup summary:hover { color: var(--text); }
.xlayer { margin: 3px 0 0 12px; font-size: 10.5px; }
.symrow input.name {
  flex: 1; min-width: 0;
  background: transparent; border: none; color: var(--text);
  font-size: 13px; font-weight: 600; outline: none;
  border-bottom: 1px dashed transparent;
}
.symrow input.name:focus { border-bottom-color: var(--accent); }
.symrow .count { font-size: 15px; font-weight: 700; min-width: 20px; text-align: right; }

/* variant thumbnails */
.variants { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.variant {
  position: relative;
  width: 38px; height: 38px;
  background: #fff; border: 1px solid var(--border); border-radius: 5px;
  cursor: pointer; overflow: hidden; flex-shrink: 0;
}
.variant.sel { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.variant:hover { border-color: var(--accent); }
.variant img { width: 100%; height: 100%; object-fit: contain; display: block; }
.vdel {
  position: absolute; left: 0; top: 0;
  width: 15px; height: 15px; padding: 0;
  display: none; align-items: center; justify-content: center;
  background: var(--danger); color: #fff;
  border: none; border-bottom-right-radius: 5px;
  font-size: 9px; line-height: 1; cursor: pointer;
}
.variant:hover .vdel { display: flex; }
.variant span {
  position: absolute; right: 0; bottom: 0;
  background: rgba(30,34,40,.85); color: #fff;
  font-size: 10px; line-height: 1; padding: 2px 3px; border-top-left-radius: 4px;
}

.symrow .pages { font-size: 10.5px; color: var(--muted); margin-top: 5px; line-height: 1.4; }

/* compact icon tools on the title line */
.symrow .tools { display: flex; gap: 2px; flex-shrink: 0; }
.symrow .tools button {
  width: 22px; height: 22px; padding: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 11.5px; line-height: 1;
  background: transparent; color: var(--muted);
  border: 1px solid transparent; border-radius: 4px; cursor: pointer;
}
.symrow .tools button:hover { color: var(--text); background: #38404e; border-color: var(--border); }
.symrow .tools button.on { color: #fff; background: var(--accent); border-color: var(--accent); }

.splitzone {
  border: 1px dashed var(--border); border-radius: 6px;
  padding: 8px; text-align: center;
  font-size: 11px; color: var(--muted);
}
.splitzone.droptarget { border-color: #7cb342; color: var(--text); }

/* zones */
#zoneList { display: flex; flex-direction: column; gap: 4px; }
.zonerow {
  display: flex; align-items: center; gap: 6px;
  font-size: 11.5px; color: var(--muted);
  background: var(--panel2); border: 1px solid var(--border);
  border-radius: 5px; padding: 4px 6px;
}
.zonerow span { flex: 1; }
.zonerow button {
  background: var(--panel); color: var(--muted);
  border: 1px solid var(--border); border-radius: 4px;
  font-size: 11px; padding: 2px 6px; cursor: pointer;
}
.zonerow button:hover { color: var(--text); }

/* saved symbol library (drop-down panel) */
#libPanel {
  position: absolute; top: 82px; right: 12px; z-index: 40;
  width: 460px; max-height: 68vh;
  display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: 0 12px 40px rgba(0,0,0,.55);
}
.libhead, .libfoot {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px;
}
.libhead { border-bottom: 1px solid var(--border); }
.libfoot { border-top: 1px solid var(--border); flex-wrap: wrap; }
.libhead h3 { font-size: 14px; }
.libhead .spacer, .libfoot .spacer { flex: 1; }
.libhead .btn, .libfoot .btn { padding: 4px 9px; font-size: 12px; }
#libSearch {
  background: var(--panel2); border: 1px solid var(--border); border-radius: 5px;
  color: var(--text); font-size: 12px; padding: 4px 8px; width: 150px;
}
#libEmpty { padding: 14px 12px; }
#libGroups { overflow-y: auto; padding: 6px; }

.enggroup { margin-bottom: 4px; }
.enghead {
  display: flex; align-items: center; gap: 7px;
  padding: 6px 8px; cursor: pointer; border-radius: 6px;
  font-size: 12.5px; color: var(--text); background: var(--panel2);
}
.enghead:hover { background: #38404e; }
.engarrow { color: var(--muted); font-size: 10px; transition: transform .12s; display: inline-block; }
.enghead.open .engarrow { transform: rotate(90deg); }
.engname { flex: 1; font-weight: 600; }
.engcount { font-size: 11px; color: var(--muted); }
.engbody { padding: 4px 0 6px 14px; display: flex; flex-direction: column; gap: 4px; }

.librow {
  display: flex; align-items: center; gap: 7px;
  background: var(--panel2); border: 1px solid var(--border);
  border-radius: 6px; padding: 5px 6px;
}
.libthumb {
  width: 30px; height: 30px; object-fit: contain;
  background: #fff; border-radius: 3px; flex-shrink: 0;
}
.libtext { flex: 1; min-width: 0; }
.libname { font-size: 12px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.libsub { font-size: 10.5px; color: var(--muted); }
.librow button {
  background: var(--panel); color: var(--muted);
  border: 1px solid var(--border); border-radius: 4px;
  font-size: 11px; padding: 2px 6px; cursor: pointer; flex-shrink: 0;
}
.librow button:hover { color: var(--text); background: #38404e; }
#dbStats { line-height: 1.5; }

/* background panel */
#bgPanel { border-top: 1px solid var(--border); padding-top: 10px; }
.bglist { list-style: none; font-size: 11.5px; color: var(--muted); line-height: 1.55; margin: 6px 0; }
.bglist li { margin-bottom: 5px; }
.bglist b { color: var(--text); }
#bgControls { margin-top: 8px; display: flex; flex-direction: column; gap: 6px; }
#bgGroupList { display: flex; flex-direction: column; gap: 4px; max-height: 160px; overflow-y: auto; }

/* ---------- viewer ---------- */
#viewer { flex: 1; overflow: auto; position: relative; background: #14161a; }
#viewer.mode-pan    { cursor: grab; }
#viewer.mode-pan.panning { cursor: grabbing; }
#viewer.mode-select { cursor: crosshair; }
#viewer.mode-edit   { cursor: pointer; }
#viewer.mode-zone   { cursor: crosshair; }
#viewer.mode-countzone { cursor: crosshair; }

#spacer { position: absolute; left: 0; top: 0; width: 0; height: 0; }
#view, #overlay { position: absolute; left: 0; top: 0; will-change: transform; }
/* the app does its own panning and pinch-zooming, so the browser must keep its
   hands off touch gestures here — otherwise it scrolls and zooms underneath us */
#overlay {
  z-index: 2;
  touch-action: none;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}

#dropHint { position: absolute; inset: 0; z-index: 3; display: flex; align-items: center; justify-content: center; }
.drop-inner {
  text-align: center; color: var(--muted);
  border: 2px dashed var(--border); border-radius: 14px;
  padding: 48px 64px; line-height: 2;
}
.drop-icon { font-size: 42px; }
#dropHint.dragover .drop-inner { border-color: var(--accent); color: var(--text); }

/* ---------- status bar ---------- */
#statusbar {
  display: flex; align-items: center; gap: 12px;
  padding: 5px 12px;
  background: var(--panel);
  border-top: 1px solid var(--border);
  font-size: 12px; color: var(--muted);
  min-height: 28px;
}
#progressWrap { flex: 1; max-width: 320px; height: 8px; background: var(--panel2); border-radius: 4px; overflow: hidden; }
#progressBar { height: 100%; width: 0%; background: var(--accent); transition: width .15s; }

/* ---------- "preparing plans" screen ---------- */
#prepScreen {
  position: fixed; inset: 0; z-index: 80;
  background: rgba(10, 12, 16, 0.82);
  display: flex; align-items: center; justify-content: center;
}
.prep-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 26px 28px;
  width: min(560px, 92vw);
  display: flex; flex-direction: column; gap: 12px;
  box-shadow: 0 14px 56px rgba(0,0,0,.65);
  text-align: center;
}
.prep-icon { font-size: 30px; animation: prepspin 2.4s linear infinite; }
@keyframes prepspin { to { transform: rotate(360deg); } }
.prep-box h2 { font-size: 18px; }
.prep-hint { font-size: 12.5px; color: var(--muted); line-height: 1.6; }
.prep-what {
  font-size: 13px; padding: 8px 10px;
  background: var(--panel2); border-radius: 8px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.prep-bar { height: 10px; background: var(--panel2); border-radius: 5px; overflow: hidden; }
#prepBar { height: 100%; width: 0%; background: var(--accent); transition: width .2s; }
.prep-foot { display: flex; align-items: center; gap: 10px; }

/* prepared / not prepared tag on a plan card */
.prepline { display: flex; align-items: center; gap: 6px; margin-top: 6px; }
.prepline .btn.tiny { flex: 0 0 auto; }
.tag {
  font-size: 10.5px; padding: 2px 7px; border-radius: 10px;
  background: var(--panel2); color: var(--muted); white-space: nowrap;
}
.tag.ok { background: rgba(46, 160, 87, .18); color: #66d68b; }

/* storage bar in the home header */
#storageBarWrap {
  width: 90px; height: 8px; border-radius: 4px;
  background: var(--panel2); overflow: hidden; flex: 0 0 auto;
}
#storageBar { height: 100%; width: 0%; background: var(--accent); transition: width .2s; }
#storageBarWrap.warn #storageBar { background: #e2a33d; }
#storageBarWrap.hot #storageBar { background: #e0554f; }

/* "free up space" modal — project checklist */
.clearlist { display: flex; flex-direction: column; gap: 6px; max-height: 340px; overflow-y: auto; }
.clearrow {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 8px; background: var(--panel2);
}
.clearrow .name { font-weight: 600; flex: 1; }
.clearrow .size { font-size: 12px; color: var(--muted); white-space: nowrap; }
.clearrow.none { opacity: .5; }

/* in-app alert/confirm/prompt replacement */
#appDialog {
  position: fixed; inset: 0; z-index: 120;
  background: rgba(10, 12, 16, 0.65);
  display: flex; align-items: center; justify-content: center;
}
.dialog-box { width: min(420px, 92vw); white-space: pre-line; }
.dialog-box h3 { font-size: 16px; }
#dlgMsg { max-width: none; }
#dlgInput {
  background: var(--panel2); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 8px 10px; font-size: 14px; width: 100%; margin-top: 4px;
}
#dlgInput:focus { outline: none; border-color: var(--accent); }

/* ---------- clean-up modal ---------- */
#editorModal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(10, 12, 16, 0.65);
  display: flex; align-items: center; justify-content: center;
}
.modal-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  max-width: min(720px, 94vw); max-height: 90vh;
  display: flex; flex-direction: column; gap: 10px;
  box-shadow: 0 12px 48px rgba(0,0,0,.6);
}
.modal-box h3 { font-size: 16px; }
.modal-hint { font-size: 12.5px; color: var(--muted); line-height: 1.5; max-width: 640px; }
.modal-hint b { color: var(--text); }
.modal-canvas-wrap {
  overflow: auto; align-self: center;
  border: 1px solid var(--border); border-radius: 8px;
  background: #fff;
  max-width: min(660px, 84vw); max-height: min(460px, 52vh);
}
#editCanvas { display: block; cursor: crosshair; user-select: none; }
.modal-footer { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.modal-footer .spacer { flex: 1; }
#editCount { font-size: 12px; color: var(--muted); }
#editHover { font-size: 12px; color: #ff8f00; }

.imgopt { margin-top: 6px; font-size: 11px; line-height: 1.35; }

/* picture clean-up window */
#pixelModal {
  position: fixed; inset: 0; z-index: 55;
  background: rgba(10, 12, 16, 0.65);
  display: flex; align-items: center; justify-content: center;
}
#pixCanvas {
  display: block; cursor: crosshair; user-select: none;
  image-rendering: pixelated;
}
#pixInfo { font-size: 12px; color: var(--muted); }
#pixelModal .opt input[type=range] { width: 70px; }

/* ==========================================================================
   Phone & tablet
   Two breakpoints:
     <= 1024px  tablet — sidebar slides over instead of taking permanent space
     <=  640px  phone  — tighter spacing, smaller type, single-row scrolling bars
   ========================================================================== */

/* fingers need bigger targets than a mouse pointer does */
@media (pointer: coarse) {
  .btn { padding: 9px 12px; }
  .btn.tiny { padding: 7px 8px; font-size: 12px; }
  .symrow { padding: 9px 8px; }
  select, input[type="search"], input[type="text"] { min-height: 36px; }
}

@media (max-width: 1024px) {
  /* the sidebar becomes a drawer that slides in over the drawing */
  #sidebar {
    position: absolute; left: 0; top: 0; bottom: 0; z-index: 10;
    width: min(320px, 86vw); min-width: 0;
    transform: translateX(-100%);
    transition: transform .22s ease;
    box-shadow: 0 0 40px rgba(0,0,0,.5);
  }
  #main.drawer-open #sidebar { transform: translateX(0); }
  #sidebarResizer { display: none; }
  #main:not(.drawer-open) #sidebarBackdrop { display: none; }

  #sidebarToggle { display: inline-flex; }

  /* one scrolling row instead of stacking into a wall of buttons */
  #topbar {
    flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden;
    scrollbar-width: thin; gap: 8px; padding: 8px 10px;
  }
  #topbar > * { flex: 0 0 auto; }

  #libPanel { width: min(460px, 94vw); right: 3vw; max-height: 60vh; }
}

@media (max-width: 640px) {
  #topbar { padding: 6px 8px; gap: 6px; }
  #topbar .btn { padding: 7px 9px; font-size: 12px; }
  .planlabel { max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  /* home screen */
  #homeBar { flex-wrap: wrap; gap: 8px 10px; padding: 8px 12px; }
  #homeBody { padding: 14px 14px 48px; }
  .viewhead { flex-direction: column; align-items: stretch; gap: 10px; }
  .viewhead h1 { font-size: 18px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
  .card { padding: 12px; }

  /* the scan options row is long — let it scroll rather than squash */
  #scanOpts { gap: 8px; }

  #libPanel { top: auto; bottom: 0; left: 0; right: 0; width: 100%;
              max-height: 72vh; border-radius: 12px 12px 0 0; }

  .modal-box { padding: 12px; border-radius: 10px; }
  .modal-hint { font-size: 12px; }
  #statusbar { font-size: 11px; padding: 4px 8px; }
  .auth-box { width: min(400px, 92vw); }
}

/* ---------- settings ---------- */
#settingsModal {
  position: fixed; inset: 0; z-index: 115;
  background: rgba(10, 12, 16, 0.65);
  display: flex; align-items: center; justify-content: center;
}
.settings-box { width: min(520px, 94vw); gap: 4px; overflow-y: auto; }
.setgroup { padding: 14px 0; border-top: 1px solid var(--border); }
.setgroup:first-of-type { border-top: none; padding-top: 6px; }
.setlabel {
  font-size: 12px; text-transform: uppercase; letter-spacing: 1px;
  color: var(--muted); margin-bottom: 6px;
}
.setrow {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 9px 10px; margin-top: 6px;
  background: var(--panel2); border: 1px solid var(--border); border-radius: 8px;
  font-size: 13px; line-height: 1.45; cursor: pointer;
}
.setrow:hover { border-color: var(--accent); }
.setrow input { margin-top: 3px; flex: 0 0 auto; }
#penSeenNote { margin-top: 8px; }
#langSelect {
  background: var(--panel2); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 7px 10px; font-size: 13px; width: 100%;
}
