/* Layout: a studio bench. Slim tool rail, large canvas pit, one tabbed dock for brushes, layers, color and type. */
:root {
  color-scheme: dark;
  --bg: #14181c;
  --stage: #0e1114;
  --panel: #1b2025;
  --panel2: #232a31;
  --field: #12161a;
  --line: #313a43;
  --fg: #e7ebee;
  --mute: #8b97a3;
  --accent: #56c4b4;
  --accent-fg: #06201c;
  --danger: #ef7b6b;
  --shadow: rgba(0, 0, 0, 0.55);
  --font-display: "Bricolage Grotesque", system-ui, sans-serif;
  --font-ui: "Figtree", system-ui, sans-serif;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #e6eaee; --stage: #cfd6dc; --panel: #f5f7f8; --panel2: #ffffff; --field: #ffffff;
    --line: #cbd2d8; --fg: #1b2126; --mute: #5b6670; --accent: #0f8f80; --accent-fg: #ffffff;
    --danger: #c2402f; --shadow: rgba(30, 40, 50, 0.3); color-scheme: light;
  }
}
:root[data-theme="light"] {
  --bg: #e6eaee; --stage: #cfd6dc; --panel: #f5f7f8; --panel2: #ffffff; --field: #ffffff;
  --line: #cbd2d8; --fg: #1b2126; --mute: #5b6670; --accent: #0f8f80; --accent-fg: #ffffff;
  --danger: #c2402f; --shadow: rgba(30, 40, 50, 0.3); color-scheme: light;
}
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 14px/1.4 var(--font-ui); overflow: hidden; }
* { box-sizing: border-box; }
[hidden] { display: none !important; }
.app { height: 100%; display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }

.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 6px 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.doctitle { font-family: var(--font-display); font-weight: 700; font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; max-width: 34vw; }
.mark { width: 26px; height: 26px; flex: none; fill: none; stroke: var(--accent); stroke-width: 6; stroke-linecap: round; stroke-linejoin: round; }
.logo { font-family: var(--font-display); font-weight: 700; font-size: 19px; letter-spacing: -0.01em; }
/* The way back to the SleepyScythe Works hub, before the Sketchroom name on the homepage (icon only on phones). */
.hublink { display: inline-flex; align-items: center; gap: 6px; flex: none; color: var(--mute); text-decoration: none; font-size: 13px; font-weight: 600; padding: 5px 10px 5px 7px; border: 1px solid var(--line); border-radius: 999px; }
.hublink:hover { color: var(--fg); background: var(--panel2); }
.hublink:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.hubmark { width: 18px; height: 18px; flex: none; fill: currentColor; }
.hubmark .hubdot { fill: #d9a21b; }
.hubsep { color: var(--mute); margin: 0 -2px; }
@media (max-width: 560px) {
  .hubname { display: none; }
  .hublink { padding: 6px; }
}
.savestate { color: var(--mute); font-size: 12px; white-space: nowrap; }
.top-actions { display: flex; align-items: center; gap: 4px; flex: none; }
.sep { width: 1px; height: 22px; background: var(--line); margin: 0 6px; }
.zoomval { font: inherit; font-variant-numeric: tabular-nums; color: var(--fg); background: none; border: 0; min-width: 52px; cursor: pointer; padding: 6px; border-radius: 8px; }
.zoomval:hover { background: var(--panel2); }

.btn { font: inherit; color: var(--fg); background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 7px 12px; cursor: pointer; min-height: 34px; }
.btn:hover:not(:disabled) { border-color: var(--mute); }
.btn.primary { background: var(--accent); color: var(--accent-fg); border-color: transparent; font-weight: 600; }
.btn.warn { border-color: var(--danger); color: var(--danger); }
.btn:disabled { opacity: 0.45; cursor: default; }
.ibtn { width: 36px; height: 36px; display: grid; place-items: center; background: transparent; border: 1px solid transparent; border-radius: 8px; color: var(--fg); cursor: pointer; padding: 0; flex: none; }
.ibtn:hover:not(:disabled) { background: var(--panel2); }
.ibtn:disabled { opacity: 0.35; cursor: default; }
.ibtn[aria-pressed="true"] { background: var(--accent); color: var(--accent-fg); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.menu-wrap { position: relative; }
.menu { position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; min-width: 220px; background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 6px; box-shadow: 0 10px 30px var(--shadow); display: flex; flex-direction: column; gap: 2px; }
.menu button { font: inherit; color: var(--fg); background: none; border: 0; text-align: left; padding: 9px 10px; border-radius: 7px; cursor: pointer; }
.menu button:hover { background: var(--panel); }
.menu button.armed { color: var(--danger); }
.menu-note { color: var(--mute); font-size: 12px; padding: 6px 10px 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn.account { max-width: 140px; margin-left: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* The editor: a slim rail and the canvas. Everything else floats over the canvas (.pop, .toolstrip), so opening or
   closing a panel never resizes the canvas area and the zoom stays where it was. */
.work { --rail: 60px; position: relative; display: grid; min-height: 0; grid-template-columns: var(--rail) minmax(0, 1fr); grid-template-areas: "tools vp"; }
.tools { grid-area: tools; display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 10px 0; background: var(--panel); border-right: 1px solid var(--line); overflow-y: auto; overflow-x: hidden; scrollbar-width: none; }
.tools > * { flex: none; }
.tools .chip { margin: 2px 0; }
.tools .vhost { flex: 1 1 150px; min-height: 96px; max-height: 190px; display: flex; }
/* The tall size and opacity sliders on the rail */
.vslider { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 4px 0; cursor: ns-resize; touch-action: none; user-select: none; -webkit-user-select: none; border-radius: 10px; outline: none; }
.vslider:focus-visible { box-shadow: 0 0 0 2px var(--accent); }
.vtrack { position: relative; flex: 1; width: 26px; border-radius: 13px; background: var(--panel2); border: 1px solid var(--line); overflow: hidden; }
.vfill { position: absolute; left: 0; right: 0; bottom: 0; background: rgba(86, 196, 180, 0.35); background: color-mix(in srgb, var(--accent) 35%, transparent); }
.vthumb { position: absolute; left: 3px; right: 3px; height: 6px; margin-bottom: -3px; border-radius: 3px; background: var(--fg); }
.vslider.active .vtrack { border-color: var(--accent); }
.vname { font-size: 10px; color: var(--mute); line-height: 1; }
.vbubble { position: fixed; z-index: 45; transform: translateY(-50%); background: var(--panel2); color: var(--fg); border: 1px solid var(--line); border-radius: 8px; padding: 5px 9px; font-size: 13px; font-variant-numeric: tabular-nums; box-shadow: 0 6px 18px var(--shadow); pointer-events: none; white-space: nowrap; }
/* Floating popouts */
.pop { position: absolute; z-index: 35; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 16px 40px var(--shadow); }
.pophead { display: flex; align-items: center; gap: 6px; padding: 4px 6px 0 14px; border-bottom: 1px solid var(--line); }
.pophead h2 { flex: 1; margin: 8px 0; font-family: var(--font-display); font-size: 16px; }
.pophead .tabs { flex: 1; border-bottom: 0; }
.toolspop { left: calc(var(--rail) + 8px); display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px; padding: 8px; width: 260px; }
.toolspop button { display: flex; align-items: center; gap: 8px; font: inherit; color: var(--fg); background: none; border: 0; border-radius: 9px; padding: 9px 10px; cursor: pointer; text-align: left; }
.toolspop button:hover { background: var(--panel2); }
.toolspop button[aria-pressed="true"] { background: var(--accent); color: var(--accent-fg); }
.toolspop button svg { width: 20px; height: 20px; flex: none; }
.layerspop { left: calc(var(--rail) + 8px); width: min(320px, calc(100% - var(--rail) - 16px)); max-height: calc(100% - 16px); display: flex; flex-direction: column; }
.panelpop { right: 10px; top: 10px; width: min(360px, calc(100% - var(--rail) - 20px)); max-height: calc(100% - 20px); display: flex; flex-direction: column; }
.layerspop .pane, .panelpop .pane { flex: 1 1 auto; }
.panelbtn { display: inline-flex; align-items: center; gap: 6px; }
.panelbtn svg { width: 18px; height: 18px; }
.panelbtn[aria-expanded="true"] { border-color: var(--accent); }
.ibtn[aria-expanded="true"] { background: var(--panel2); box-shadow: inset 0 0 0 1px var(--accent); }
/* The pen or finger switch at the bottom of the rail */
.modebtn { display: flex; flex-direction: column; align-items: center; gap: 3px; width: 46px; padding: 6px 0 5px; margin-top: auto; font: inherit; color: var(--fg); background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; cursor: pointer; }
.modebtn svg { width: 20px; height: 20px; }
.modebtn[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
/* Drawing together */
.livebadge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; color: var(--accent-fg); background: var(--accent); margin-right: 4px; white-space: nowrap; }
.livebadge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.livebadge.offline { background: var(--panel2); color: var(--mute); border: 1px solid var(--line); }
.sharedsection { display: flex; flex-direction: column; gap: 12px; }
.sectiontitle { margin: 4px 0 0; font-family: var(--font-display); font-size: 16px; font-weight: 600; color: var(--mute); }
.movelist input[type="checkbox"] { accent-color: var(--accent); }
/* Settings for the tools behind "…", at the top of the canvas. Moves out of the panel's way when it's open. */
.toolstrip { position: absolute; z-index: 30; top: 10px; left: calc(var(--rail) + 10px); right: 10px; margin: 0 auto; width: max-content; max-width: min(560px, calc(100% - var(--rail) - 20px)); display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; padding: 8px 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 8px 24px var(--shadow); }
.work.panelopen .toolstrip { right: calc(min(360px, 100% - var(--rail) - 20px) + 20px); max-width: calc(100% - var(--rail) - min(360px, 100% - var(--rail) - 20px) - 40px); }
.toolstrip .who { font-family: var(--font-display); font-weight: 600; font-size: 14px; }
.toolstrip .qgroup { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.toolstrip .qgroup .row { min-width: 150px; }
.toolstrip .hint { flex-basis: 100%; }
.chip { width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--fg); cursor: pointer; padding: 0; background: #222831; }

.viewport { grid-area: vp; position: relative; overflow: hidden; background: var(--stage); touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; min-width: 0; min-height: 0; }
#stage { position: absolute; left: 0; top: 0; width: 1600px; height: 1200px; transform-origin: 0 0; background: #ffffff; box-shadow: 0 10px 50px var(--shadow); }
#stage canvas { position: absolute; left: 0; top: 0; width: 100%; height: 100%; pointer-events: none; }
/* Pixel art: hard pixel edges when zoomed, and a checkerboard where the image is transparent. */
#stage.pixel { background-color: #ffffff; background-image: linear-gradient(45deg, #e4e4e4 25%, transparent 25%, transparent 75%, #e4e4e4 75%), linear-gradient(45deg, #e4e4e4 25%, transparent 25%, transparent 75%, #e4e4e4 75%); background-size: 8px 8px; background-position: 0 0, 4px 4px; }
#stage.pixel canvas { image-rendering: crisp-edges; image-rendering: pixelated; }
#grid { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 3; }
.loading { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0, 0, 0, 0.35); color: #fff; font-weight: 600; z-index: 8; }
.pixelonly { display: none; }
.pixeldoc .pixelonly { display: block; }
.pixeldoc [data-tool="smudge"] { display: none; }
#ring { position: absolute; border-radius: 50%; border: 1.5px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,0.7); pointer-events: none; transform: translate(-50%, -50%); z-index: 5; }
#toast { position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); max-width: calc(100% - 32px); background: var(--panel2); color: var(--fg); border: 1px solid var(--line); border-radius: 10px; padding: 9px 14px; box-shadow: 0 8px 24px var(--shadow); z-index: 10; opacity: 0; pointer-events: none; transition: opacity 0.18s; text-align: center; }
#toast.show { opacity: 1; }

.tabs { display: flex; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.tab { flex: 1; background: none; border: 0; border-bottom: 2px solid transparent; color: var(--mute); padding: 10px 8px; font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap; }
.tab[aria-selected="true"] { color: var(--fg); border-bottom-color: var(--accent); }
.pane { flex: 1; min-height: 0; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 14px; }
.pane[hidden] { display: none; }
.pane h3 { margin: 0; font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--mute); font-weight: 600; }
.hint { color: var(--mute); font-size: 12px; margin: 0; }

.row { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; align-items: center; }
.row label { color: var(--mute); font-size: 12px; }
.row output { font-variant-numeric: tabular-nums; font-size: 12px; }
.row input[type="range"] { grid-column: 1 / -1; width: 100%; accent-color: var(--accent); margin: 2px 0; min-width: 0; }

input[type="text"], textarea, select { font: inherit; color: var(--fg); background: var(--field); border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; width: 100%; min-width: 0; }
textarea { resize: vertical; min-height: 64px; }
.inline { display: flex; gap: 8px; }
.inline > input { flex: 1; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button { font: inherit; color: var(--fg); background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-fg); border-color: transparent; font-weight: 600; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; }

.bgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 8px; }
.bcard { position: relative; background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 8px 4px; cursor: pointer; min-width: 0; }
.bcard[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.bcard canvas { display: block; width: 100%; height: 38px; }
.bcard .nm { display: block; font-size: 12px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-right: 22px; }
.bcard .by { display: block; font-size: 11px; color: var(--mute); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bcard .del { position: absolute; top: 4px; right: 4px; width: 26px; height: 26px; }
.bcard .del.armed { color: var(--danger); }
.reqrow { display: flex; gap: 6px; margin: 4px 0; }
.btn.sm { min-height: 28px; padding: 4px 10px; font-size: 12px; }
.qgroup { display: flex; flex-direction: column; gap: 8px; }
.section { display: flex; flex-direction: column; gap: 14px; }
.lrow .lockbtn { width: 30px; height: 30px; color: var(--mute); }
.lrow .lockbtn[aria-pressed="true"] { color: var(--accent); background: transparent; }
.fontlist { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.fontlist:empty { display: none; }
.fontrow { display: flex; align-items: center; gap: 6px; padding: 2px 2px 2px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel2); }
.fontrow span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 17px; }
.empty { border: 1px dashed var(--line); border-radius: 10px; padding: 14px; color: var(--mute); font-size: 13px; }
#editPreview { width: 100%; height: 90px; background: var(--field); border: 1px solid var(--line); border-radius: 10px; display: block; }
.padwrap { position: relative; }
#testPad { position: absolute; left: 0; top: 0; width: 100%; height: 90px; border-radius: 10px; touch-action: none; cursor: crosshair; }
#penPad { width: 100%; height: 120px; display: block; background: var(--field); border: 1px solid var(--line); border-radius: 10px; touch-action: none; cursor: crosshair; }
.padbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.padbar .hint { flex: 1; min-width: 0; }

.layers { display: flex; flex-direction: column; gap: 6px; }
.lrow { display: flex; align-items: center; gap: 4px; padding: 3px 8px 3px 3px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel2); cursor: pointer; min-width: 0; }
.lrow[aria-current="true"] { border-color: var(--accent); }
.lrow .ln { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lrow.hidden-layer .ln { color: var(--mute); text-decoration: line-through; }
.tools-row { display: flex; flex-wrap: wrap; gap: 4px; }

.palette { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.sw { width: 100%; aspect-ratio: 1; border-radius: 7px; border: 1px solid var(--line); cursor: pointer; padding: 0; min-width: 0; }
.sw[aria-pressed="true"] { outline: 2px solid var(--accent); outline-offset: 1px; }
.palette .empty { grid-column: 1 / -1; }
.palette.mini { grid-template-columns: repeat(8, 1fr); gap: 5px; }
.palette.editing .sw { position: relative; }
.palette.editing .sw::after { content: "\00d7"; position: absolute; inset: 0; display: grid; place-items: center; color: #fff; font-size: 17px; font-weight: 700; text-shadow: 0 0 3px #000, 0 0 2px #000; }
.palhead { display: flex; align-items: center; gap: 2px; }
.palhead h3 { flex: 1; }
.ibtn.sm { width: 30px; height: 30px; }
.wheel { display: block; width: 100%; max-width: 260px; aspect-ratio: 1 / 1; margin: 0 auto; touch-action: none; cursor: crosshair; }
.wheel.mini { max-width: 196px; }
.nowchip { flex: none; width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--line); background: #222831; }
.chip[aria-expanded="true"] { box-shadow: 0 0 0 3px var(--accent); }
.colorpop { position: fixed; z-index: 40; width: min(300px, calc(100vw - 16px)); max-height: calc(100vh - 16px); overflow-y: auto; background: var(--panel2); border: 1px solid var(--line); border-radius: 14px; padding: 14px; box-shadow: 0 14px 40px var(--shadow); display: flex; flex-direction: column; gap: 10px; }
.colorpop h3 { margin: 0; font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--mute); font-weight: 600; }
.popnow { display: flex; align-items: center; gap: 10px; }
.pophex { flex: 1; font-family: ui-monospace, "Space Mono", monospace; color: var(--mute); }
.fontprev { font-size: 26px; line-height: 1.2; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--field); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- homepage library ---------- */
.home { height: 100%; display: grid; grid-template-rows: auto minmax(0, 1fr); }
.homebody { overflow-y: auto; padding: 20px 16px 48px; }
/* The art behind the signed-in pages (js/background.js), faded by a layer of the page color. The header and content are
   positioned so they paint above it; the header sits higher so its account menu can hang over the content. */
.libbg, .libshade { position: fixed; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; z-index: 0; }
.libbg { display: block; }
.libshade { background: var(--bg); }
.home > .top { position: relative; z-index: 2; }
.home > .homebody { position: relative; z-index: 1; }
.library { max-width: 1100px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
/* ---------- signed-out landing: a sample sheet you can draw on, then what the app holds ---------- */
.signedout { max-width: 1100px; margin: 0 auto; padding-top: clamp(4px, 4vh, 40px); display: flex; flex-direction: column; gap: clamp(56px, 9vh, 96px); }
.hero { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.12fr); gap: clamp(28px, 5vw, 64px); align-items: center; }
.herotext { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.herotext p { margin: 0; }
.signedout h1 { margin: 0; font-family: var(--font-display); font-weight: 700; font-size: clamp(34px, 5.4vw, 60px); line-height: 1.02; letter-spacing: -0.025em; font-variation-settings: "wdth" 84; max-width: 11em; text-wrap: balance; }
.lede { font-size: 18px; line-height: 1.5; max-width: 34em; }
.signintext { color: var(--mute); max-width: 34em; }
.heroactions { gap: 8px; margin-top: 4px; }
.heroactions .btn { min-height: 44px; padding: 10px 20px; font-size: 15px; }
.sheetfig { margin: 0; min-width: 0; }
.sheet { position: relative; aspect-ratio: 1000 / 720; background-color: #fbfcfb; background-image: radial-gradient(circle, #d3dad8 1px, transparent 1.2px); background-size: 24px 24px; border-radius: 3px; box-shadow: 0 1px 0 rgba(0, 0, 0, 0.08), 0 22px 44px var(--shadow); transform: rotate(-1.2deg); animation: settle 0.7s cubic-bezier(0.2, 0.7, 0.2, 1) both; }
@keyframes settle { from { transform: rotate(2.2deg) translateY(14px); opacity: 0; } to { transform: rotate(-1.2deg); opacity: 1; } }
.sheet canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: crosshair; }
@supports not (aspect-ratio: 1) { .sheet { height: 0; padding-top: 72%; } }
.sheethint { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); font-family: var(--font-display); font-size: clamp(22px, 3vw, 32px); font-weight: 600; color: #a9b4b1; pointer-events: none; transition: opacity 0.25s; }
.sheethint.gone { opacity: 0; }
.tray { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; margin-top: 22px; }
.pens { display: flex; gap: 4px; padding: 3px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; }
.pens button { font: inherit; color: var(--mute); background: none; border: 0; border-radius: 7px; padding: 6px 12px; cursor: pointer; }
.pens button:hover { color: var(--fg); }
.pens button[aria-pressed="true"] { background: var(--accent); color: var(--accent-fg); font-weight: 600; }
.inks { display: flex; gap: 8px; }
.ink { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--bg); padding: 0; cursor: pointer; }
.ink[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--fg); }
.sheetfig figcaption { margin-top: 10px; }
.room h2 { margin: 0 0 8px; font-family: var(--font-display); font-weight: 700; font-size: 26px; letter-spacing: -0.01em; }
.roomlist { margin: 0; }
.roomlist > div { display: grid; grid-template-columns: minmax(120px, 11rem) minmax(0, 1fr); gap: 8px 32px; padding: 18px 0; border-top: 1px solid var(--line); }
.roomlist dt { font-family: var(--font-display); font-weight: 600; font-size: 18px; }
.roomlist dd { margin: 0; max-width: 60ch; line-height: 1.55; }
@media (max-width: 860px) {
  .hero { grid-template-columns: minmax(0, 1fr); }
  .roomlist > div { grid-template-columns: minmax(0, 1fr); }
}
@media (prefers-reduced-motion: reduce) { .sheet { animation: none; } .sheethint { transition: none; } }

.homebar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.crumbs { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-family: var(--font-display); font-size: 21px; font-weight: 600; min-width: 0; }
.crumbs a { color: var(--mute); text-decoration: none; }
.crumbs a:hover { color: var(--fg); }
.crumbsep { color: var(--mute); font-weight: 400; }
.hgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; }
.hcard { position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; cursor: pointer; display: flex; flex-direction: column; min-width: 0; }
.hcard:hover { border-color: var(--mute); }
/* A 4:3 box from padding (not aspect-ratio), with its contents absolutely positioned, so a thumbnail can never stretch
   the card. iPad Safari stretched image cards down the screen with the aspect-ratio version (2026-10-12). */
.hthumb { position: relative; flex: none; height: 0; padding-top: 75%; background: var(--panel2); color: var(--accent); overflow: hidden; }
.hthumb > * { position: absolute; top: 0; right: 0; bottom: 0; left: 0; margin: auto; }
.hcard.image .hthumb { background: #ffffff; }
.hthumb img, .hthumb canvas { width: 100%; height: 100%; object-fit: contain; display: block; }
.hthumb img.pixelated { image-rendering: pixelated; }
.checker, .hcard.image .hthumb.checker { background-color: #ffffff; background-image: linear-gradient(45deg, #e4e4e4 25%, transparent 25%, transparent 75%, #e4e4e4 75%), linear-gradient(45deg, #e4e4e4 25%, transparent 25%, transparent 75%, #e4e4e4 75%); background-size: 16px 16px; background-position: 0 0, 8px 8px; }
.hmeta { padding: 8px 42px 10px 12px; display: flex; flex-direction: column; min-width: 0; }
.hname { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hsub { color: var(--mute); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hmore { position: absolute; right: 6px; bottom: 8px; }
.homeempty { color: var(--mute); text-align: center; padding: 40px 16px; border: 1px dashed var(--line); border-radius: 12px; margin: 0 auto; max-width: 1100px; }
.sketchbanner { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); }
.sketchbanner span { flex: 1; min-width: 200px; }
.menu.cardmenu { position: fixed; right: auto; top: auto; min-width: 180px; }

.freegroups { display: flex; flex-direction: column; gap: 8px; }
.bcat { margin: 6px 0 0; font-size: 12px; font-weight: 600; color: var(--fg); }
.homefoot { max-width: 1100px; margin: 32px auto 0; display: flex; flex-wrap: wrap; gap: 6px 18px; justify-content: center; font-size: 12px; }
.homefoot a { color: var(--mute); text-decoration: none; }
.homefoot a:hover { color: var(--fg); text-decoration: underline; }

/* ---------- profile ---------- */
.profilepage { max-width: 720px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.ptop { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.ptitle { font-family: var(--font-display); font-size: 21px; font-weight: 600; }
.backbtn { display: inline-flex; align-items: center; gap: 6px; }
.backbtn svg { width: 18px; height: 18px; }
.pcard { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; padding-bottom: 16px; }
.pbanner { height: 90px; }
.phead { display: flex; align-items: flex-end; gap: 14px; padding: 0 18px; margin-top: -40px; flex-wrap: wrap; }
.pnames { flex: 1; min-width: 160px; display: flex; flex-direction: column; padding-bottom: 4px; }
.pnames h1 { margin: 0; font-family: var(--font-display); font-size: 24px; line-height: 1.2; overflow-wrap: anywhere; }
.pnames span { color: var(--mute); }
.pmeta, .pbio { margin: 10px 18px 0; }
.pmeta { color: var(--mute); font-size: 13px; }
.pbio { white-space: pre-wrap; overflow-wrap: anywhere; }
.plinks { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 10px 18px 0; }
.plinks:empty { display: none; }
.plinks a { color: var(--accent); overflow-wrap: anywhere; }
.pstats { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: 8px; margin: 16px 18px 0; }
.pstats div { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; display: flex; flex-direction: column; }
.pstats strong { font-size: 20px; font-family: var(--font-display); }
.pstats span { color: var(--mute); font-size: 12px; }
.pbox { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 14px 18px; display: flex; flex-direction: column; gap: 10px; }
.pbox h3 { margin: 0; font-size: 15px; }
.pbox a.btn { text-decoration: none; display: inline-flex; align-items: center; }
.avatar { flex: none; display: grid; place-items: center; border-radius: 50%; overflow: hidden; color: #fff; font-family: var(--font-display); font-weight: 700; width: 40px; height: 40px; font-size: 18px; border: 3px solid var(--panel); }
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar.big { width: 96px; height: 96px; font-size: 40px; }
.avatar.mid { width: 72px; height: 72px; font-size: 30px; }
.peavatar { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.field textarea { font: inherit; font-size: 14px; color: var(--fg); background: var(--field); border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; width: 100%; resize: vertical; }
.field input + input { margin-top: 6px; }
.count { float: right; }
.formerror { color: var(--danger); margin: 0; font-size: 13px; min-height: 0; }
.formerror:empty { display: none; }
.inbox { display: flex; flex-direction: column; gap: 10px; }
.msg { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: var(--panel2); display: flex; flex-direction: column; gap: 6px; }
.msg.unread { border-color: var(--accent); }

/* ---------- friends ---------- */
.homebtns { display: flex; align-items: center; gap: 8px; }
.badge { display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 5px; margin-left: 6px; border-radius: 9px; background: var(--accent); color: var(--accent-fg); font-size: 11px; font-weight: 700; line-height: 1; }
.hlock { position: absolute; top: 8px; left: 8px; width: 26px; height: 26px; display: grid; place-items: center; border-radius: 50%; background: rgba(20, 24, 28, 0.72); color: #fff; pointer-events: none; }
.addfriend { display: flex; flex-wrap: wrap; gap: 8px; }
.addfriend input { flex: 1; min-width: 160px; font: inherit; font-size: 14px; color: var(--fg); background: var(--field); border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; }
.people { display: flex; flex-direction: column; gap: 8px; }
.people:empty { display: none; }
.person { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel2); }
.person .avatar { border-color: var(--panel2); }
.person .who { flex: 1; min-width: 120px; display: flex; flex-direction: column; color: var(--fg); text-decoration: none; }
.person a.who:hover strong { text-decoration: underline; }
.person .who strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person .who span { color: var(--mute); font-size: 12px; }
.person .who span:empty { display: none; }
#ufHead:empty { display: none; }
.viewer { display: flex; flex-direction: column; gap: 10px; }
.viewbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.viewtitle { display: flex; flex-direction: column; min-width: 0; }
.viewtitle strong { font-family: var(--font-display); font-size: 18px; overflow-wrap: anywhere; }
/* margin: auto centers the image but still lets it scroll when zoomed in */
.viewbox { display: flex; overflow: auto; max-height: 78vh; padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel2); }
.viewbox canvas { margin: auto; flex: none; display: block; cursor: zoom-in; box-shadow: 0 4px 18px var(--shadow); }
.viewbox canvas.pixelated { image-rendering: pixelated; }
.msghead { font-size: 12px; color: var(--mute); }
.msgbody { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.dlg { max-height: calc(100vh - 32px); overflow-y: auto; }

/* ---------- dialogs ---------- */
.dlg { border: 1px solid var(--line); border-radius: 14px; background: var(--panel2); color: var(--fg); padding: 20px; width: min(420px, calc(100vw - 32px)); box-shadow: 0 20px 60px var(--shadow); }
.dlg::backdrop { background: rgba(0, 0, 0, 0.5); }
/* "What's new" (news.js) */
.dlg.news { width: min(520px, calc(100vw - 32px)); }
.newshead { display: flex; flex-direction: column; gap: 2px; }
.newswhen { color: var(--accent); font-size: 12px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; }
.newslist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.newslist li { display: flex; flex-direction: column; gap: 2px; padding-left: 14px; border-left: 2px solid var(--accent); }
.newslist strong { font-weight: 600; }
.newslist span { color: var(--mute); line-height: 1.45; }
.dlg form { display: flex; flex-direction: column; gap: 12px; }
.dlg h2 { margin: 0; font-family: var(--font-display); font-size: 20px; }
.field { display: flex; flex-direction: column; gap: 4px; color: var(--mute); font-size: 12px; flex: 1; min-width: 0; }
.field input, .field select { font: inherit; font-size: 14px; color: var(--fg); background: var(--field); border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; width: 100%; min-width: 0; }
.dlgbtns { justify-content: flex-end; gap: 8px; }
.movelist { display: flex; flex-direction: column; gap: 4px; max-height: 50vh; overflow-y: auto; }
.movelist label { display: flex; gap: 8px; align-items: center; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line); cursor: pointer; }
.movelist input { accent-color: var(--accent); }

@media (max-width: 860px) {
  .work { --rail: 54px; }
  .zoomgroup, .savestate { display: none; }
  .panelbtn .lbl { display: none; }
  .panelbtn { padding: 7px 9px; }
  #editor .top { padding: 6px 8px; gap: 6px; }
  #editor .top-actions .sep { display: none; }
  /* On narrow screens the open panel covers much of the canvas, so the tool strip waits until it closes. */
  .work.panelopen .toolstrip { display: none; }
  .hgrid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
}
@media (prefers-reduced-motion: reduce) { #toast { transition: none; } }
