/* ────────────────────────────────────────────────────────────────────
   Niels Stroober — Home Card
   1-bit HyperCard aesthetic. 1 logical pixel = 2 css px.
   ──────────────────────────────────────────────────────────────────── */

@font-face {
  font-family: "Chicago";
  src: url("../assets/fonts/ChicagoFLF.ttf") format("truetype");
  font-display: swap;
}

:root {
  --px: 2px;                 /* one 1-bit pixel */
  --black: #000;
  --white: #fff;
  --font-ui: "Chicago", "Helvetica Neue", sans-serif;
  --font-body: Geneva, Verdana, sans-serif;
  --cursor-hand: url("../assets/icons/cursor-hand.png") 6 0, pointer;
  --menubar-h: 40px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

button { color: inherit; }

html, body { height: 100%; }

body {
  font-family: var(--font-body);
  color: var(--black);
  overflow: hidden;
  /* light dot grid desktop (patterns can change it via the control panel) */
  background-color: var(--white);
  background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="8" height="8"><rect width="8" height="8" fill="white"/><rect width="2" height="2" fill="rgb(185,185,185)"/></svg>');
  background-size: 8px 8px;
  -webkit-font-smoothing: none;
}

img { image-rendering: pixelated; }

::selection { background: var(--black); color: var(--white); }

/* ─────────────────────────── menu bar ────────────────────────────── */

.menubar {
  position: relative;
  z-index: 500;
  height: var(--menubar-h);
  background: var(--black);
  color: var(--white);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  font-family: var(--font-ui);
  font-size: 22px;
  user-select: none;
  border-bottom: var(--px) solid var(--white);
}

.menubar-left, .menubar-right {
  display: flex;
  align-items: center;
  gap: 22px;
}

.menubar-logo {
  width: 24px;
  height: 24px;
  filter: invert(1);
}

.menubar-name { font-weight: bold; letter-spacing: 0.5px; }

.menu-item {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 4px 6px;
  cursor: var(--cursor-hand);
}

.menu-item.open,
.menu-item:hover {
  background: var(--white);
  color: var(--black);
}

.menubar-link {
  color: inherit;
  text-decoration: none;
  padding: 4px 6px;
  cursor: var(--cursor-hand);
}
.menubar-link:hover { background: var(--white); color: var(--black); }

.menu-dropdown {
  position: absolute;
  top: var(--menubar-h);
  background: var(--white);
  color: var(--black);
  border: var(--px) solid var(--black);
  box-shadow: 4px 4px 0 0 var(--black);
  min-width: 220px;
  padding: 4px 0;
  font-family: var(--font-ui);
  font-size: 20px;
}

.menu-dropdown button {
  display: block;
  width: 100%;
  text-align: left;
  font: inherit;
  background: none;
  border: 0;
  padding: 6px 18px;
  cursor: var(--cursor-hand);
  white-space: nowrap;
}
.menu-dropdown button:hover:not(:disabled) { background: var(--black); color: var(--white); }
.menu-dropdown button:disabled { color: #888; cursor: default; }
.menu-dropdown hr {
  border: 0;
  border-top: var(--px) dotted var(--black);
  margin: 4px 0;
}

/* ─────────────────────────── desktop ─────────────────────────────── */

.desktop {
  position: relative;
  height: calc(100% - var(--menubar-h));
  overflow: hidden;
}

.portrait {
  position: absolute;
  width: auto;    /* natural size — pixels stay 1:1 on the grid */
  height: auto;
  pointer-events: none;
  /* app.js snaps position onto the 8px background grid */
}

/* ─────────────────────────── card windows ────────────────────────── */

.card {
  position: absolute;
  background: var(--white);
  border: var(--px) solid var(--black);
  /* plain hard shadow — authentic for regular windows */
  box-shadow: 4px 4px 0 0 var(--black);
}

/* only the home card is a stack of cards */
.home-card {
  box-shadow:
    6px 6px 0 -2px var(--white),
    6px 6px 0 0 var(--black),
    12px 12px 0 -2px var(--white),
    12px 12px 0 0 var(--black);
}

/* home card */

.home-card {
  left: 50%;
  top: 44%;
  transform: translate(-50%, -50%);
  width: min(760px, calc(100vw - 48px));
  padding: 20px 24px 12px;
}

.home-title {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  font-family: var(--font-ui);
  font-size: 30px;
  font-weight: normal;
  margin-bottom: 22px;
  user-select: none;
}
.home-title img { width: 36px; height: 36px; }

.icon-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 26px 10px;
  justify-items: center;
  padding: 0 8px;
}

/* desktop icons */

.desk-icon {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  background: none;
  border: 0;
  font-family: var(--font-ui);
  font-size: 21px;
  cursor: var(--cursor-hand);
  padding: 6px;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.desk-icon img { width: 64px; height: 64px; }

.desk-icon-label {
  padding: 1px 6px 2px;
  background: var(--white);
  color: var(--black);
  line-height: 1.1;
}

.desk-icon:hover .desk-icon-label { text-decoration: underline; }
.desk-icon.selected img { filter: invert(1); background: var(--black); }
.desk-icon.selected .desk-icon-label { background: var(--black); color: var(--white); }

.desk-icon.small { flex-direction: row; font-size: 19px; gap: 10px; padding: 2px; }
.desk-icon.small img { width: 40px; height: 40px; }

/* home card footer: release notes / pager / clock */

.home-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 26px;
  font-family: var(--font-ui);
}

.pager { display: flex; gap: 18px; }

.pager-btn {
  background: none;
  border: 0;
  cursor: var(--cursor-hand);
  padding: 4px;
}
.pager-btn img { width: 48px; height: 32px; }
.pager-btn:active img { filter: invert(1); background: var(--black); }

.clock { font-size: 24px; user-select: none; min-width: 110px; text-align: right; }

/* ─────────────────────────── topic windows ───────────────────────── */

.window {
  min-width: 320px;
  width: min(480px, calc(100vw - 56px));
  z-index: 10;
}

.window.active { z-index: 100; }
.window:focus { outline: none; }

/* inactive windows lose their stripes and close box, like the real one */
.window:not(.active) .titlebar { background-image: none; }
.window:not(.active) .close-box { visibility: hidden; }

.titlebar {
  position: relative;
  height: 28px;
  border-bottom: var(--px) solid var(--black);
  /* classic racing stripes */
  background-image: repeating-linear-gradient(
    to bottom,
    var(--white) 0, var(--white) 2px,
    var(--black) 2px, var(--black) 4px
  );
  background-clip: content-box;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: move;
  user-select: none;
}

.titlebar-title {
  font-family: var(--font-ui);
  font-size: 21px;
  line-height: 1;
  background: var(--white);
  padding: 2px 14px 3px;
}

.close-box {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 20px;
  height: 20px;
  background-color: var(--white);
  /* pixel X (the real System 6 close box was empty — modern eyes want an X) */
  background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 8 8" shape-rendering="crispEdges" fill="black"><rect x="0" y="0" width="1" height="1"/><rect x="7" y="0" width="1" height="1"/><rect x="1" y="1" width="1" height="1"/><rect x="6" y="1" width="1" height="1"/><rect x="2" y="2" width="1" height="1"/><rect x="5" y="2" width="1" height="1"/><rect x="3" y="3" width="2" height="2"/><rect x="2" y="5" width="1" height="1"/><rect x="5" y="5" width="1" height="1"/><rect x="1" y="6" width="1" height="1"/><rect x="6" y="6" width="1" height="1"/><rect x="0" y="7" width="1" height="1"/><rect x="7" y="7" width="1" height="1"/></svg>');
  background-repeat: no-repeat;
  background-position: center;
  background-size: 12px 12px;
  border: var(--px) solid var(--black);
  box-shadow: 0 0 0 3px var(--white);
  cursor: var(--cursor-hand);
  padding: 0;
}
.close-box:active { background-color: var(--black); background-image: none; }

.window-body {
  padding: 20px 22px 24px;
  font-size: 15px;
  line-height: 1.55;
  max-height: min(480px, 60vh);
  overflow-y: auto;
}

.window-body h2 {
  font-family: var(--font-ui);
  font-size: 24px;
  font-weight: normal;
  margin-bottom: 12px;
}

.window-body p + p, .window-body ul + p, .window-body p + ul { margin-top: 12px; }

.window-body ul { padding-left: 24px; }
.window-body li { margin: 4px 0; }

.window-body a { color: var(--black); }
.window-body a:hover { background: var(--black); color: var(--white); text-decoration: none; }

.window-body blockquote {
  font-family: var(--font-ui);
  font-size: 26px;
  text-align: center;
  margin: 18px 0;
}
.window-body blockquote footer { font-size: 16px; margin-top: 10px; font-family: var(--font-body); }

/* ─────────────────────────── zoom rects ──────────────────────────── */

.zoom-rect {
  position: absolute;
  /* XOR outline, like the original ZoomRects: inverts whatever is under it */
  border: var(--px) solid var(--white);
  mix-blend-mode: difference;
  pointer-events: none;
  z-index: 400;
}

/* ─────────────────────────── desktop layout ──────────────────────── */

.layout-desktop .home-card { display: none; }

.desktop-icons {
  position: absolute;
  left: 48px;
  top: 44px;
  display: grid;
  grid-template-rows: repeat(4, auto);
  grid-auto-flow: column;
  gap: 24px 38px;
  justify-items: center;
}

.layout-desktop .desk-icon { width: 128px; }
.layout-desktop .desk-icon img { width: 96px; height: 96px; }  /* 3x, stays crisp */
.layout-desktop .desk-icon .desk-icon-label { text-align: center; }

.menubar-clock { display: none; }
.layout-desktop .menubar-clock {
  display: inline;
  font-size: inherit;
  min-width: 0;
  text-align: left;
  padding: 4px 0 4px 6px;
}

/* ─────────────────────────── desk accessories ────────────────────── */

/* menubar house menu */
.menubar-logo-btn { display: flex; align-items: center; }
.menubar-logo-btn:hover img, .menubar-logo-btn.open img { filter: none; }

/* dithered gray chrome used by several accessories */
.dither-gray, .calc-body, .cp-cell, .scrap-track {
  background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="4" height="4"><rect width="4" height="4" fill="white"/><rect x="2" width="2" height="2" fill="black"/><rect y="2" width="2" height="2" fill="black"/></svg>');
  background-size: 4px 4px;
}

/* ── Scrapbook ── */

.da-scrapbook { width: min(680px, calc(100vw - 56px)); }
.scrapbook-body.window-body { padding: 16px 18px 14px; }

.scrap-frame {
  border: var(--px) solid var(--black);
  box-shadow: 0 0 0 4px var(--white), 0 0 0 6px var(--black) inset;
  outline: 6px solid var(--black);
  outline-offset: -8px;
  padding: 8px;
}
.scrap-canvas {
  display: block;
  width: 100%;
  image-rendering: pixelated;
  border: var(--px) solid var(--black);
}

.scrap-scrollbar {
  display: flex;
  align-items: stretch;
  margin-top: 12px;
  height: 32px;
}
.scrap-arrow {
  width: 44px;
  background: var(--white);
  border: var(--px) solid var(--black);
  cursor: var(--cursor-hand);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.scrap-arrow img { width: 28px; height: 20px; }
.scrap-arrow:active { filter: invert(1); }
.scrap-track {
  position: relative;
  flex: 1;
  border: var(--px) solid var(--black);
  border-left: 0;
  border-right: 0;
}
.scrap-thumb {
  position: absolute;
  top: 2px;
  bottom: 2px;
  width: 28px;
  background: var(--white);
  border: var(--px) solid var(--black);
  transition: left .12s steps(3);
}

.scrap-status {
  display: flex;
  justify-content: space-between;
  margin-top: 10px;
  font-family: var(--font-ui);
  font-size: 19px;
}

/* ── Calculator ── */

.da-calculator { width: 264px; min-width: 264px; }
.calc-body.window-body { padding: 14px; }

.calc-display {
  background: var(--white);
  border: var(--px) solid var(--black);
  font-family: var(--font-ui);
  font-size: 24px;
  text-align: right;
  padding: 6px 10px;
  margin-bottom: 12px;
  overflow: hidden;
  white-space: nowrap;
}

.calc-keys {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.calc-key {
  height: 40px;
  background: var(--white);
  border: var(--px) solid var(--black);
  box-shadow: 2px 2px 0 0 var(--black);
  font-family: var(--font-ui);
  font-size: 21px;
  cursor: var(--cursor-hand);
  padding: 0;
}
.calc-key:active, .calc-key.pressed {
  background: var(--black);
  color: var(--white);
  box-shadow: none;
  transform: translate(2px, 2px);
}
.calc-key.k-plus { grid-row: span 2; height: auto; }
.calc-key.k-0 { grid-column: span 2; }

/* ── Note Pad ── */

.da-notepad { width: min(440px, calc(100vw - 56px)); }
.notepad-body.window-body { padding: 0; }

.notepad-text {
  display: block;
  width: 100%;
  height: 220px;
  border: 0;
  resize: none;
  outline: none;
  padding: 14px 16px;
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  background: var(--white);
}

.notepad-footer {
  position: relative;
  height: 40px;
  border-top: var(--px) solid var(--black);
}

/* folded page corner, bottom-left — left half flips back, right half forward */
.notepad-curl {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 56px;
  height: 40px;
  cursor: var(--cursor-hand);
}
.curl-under {
  position: absolute;
  inset: 0;
  background: var(--white);
  border-right: var(--px) solid var(--black);
  clip-path: polygon(0 0, 100% 100%, 0 100%);
  background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="4" height="4"><rect width="4" height="4" fill="white"/><rect x="2" width="2" height="2" fill="black"/><rect y="2" width="2" height="2" fill="black"/></svg>');
  background-size: 4px 4px;
}
.curl-over {
  position: absolute;
  inset: 0;
  background: var(--white);
  clip-path: polygon(0 0, 100% 0, 100% 100%);
  border-bottom: var(--px) solid var(--black);
}
.notepad-curl::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom right,
    transparent calc(50% - 1px), var(--black) calc(50% - 1px),
    var(--black) calc(50% + 1px), transparent calc(50% + 1px));
}
.notepad-pageno {
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  font-family: var(--font-ui);
  font-size: 20px;
}

/* ── Mail ── */

.da-mail { width: min(640px, calc(100vw - 56px)); }
.mail-body.window-body { padding: 0; max-height: none; }

.mail-toolbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 14px;
  border-bottom: var(--px) solid var(--black);
  background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="4" height="4"><rect width="4" height="4" fill="white"/><rect x="2" width="2" height="2" fill="black"/><rect y="2" width="2" height="2" fill="black"/></svg>');
  background-size: 4px 4px;
}
.mail-new {
  font-family: var(--font-ui);
  font-size: 18px;
  background: var(--white);
  border: var(--px) solid var(--black);
  box-shadow: 2px 2px 0 0 var(--black);
  padding: 4px 14px;
  cursor: var(--cursor-hand);
}
.mail-new:active { background: var(--black); color: var(--white); box-shadow: none; transform: translate(2px, 2px); }
.mail-count {
  font-family: var(--font-ui);
  font-size: 16px;
  background: var(--white);
  border: var(--px) solid var(--black);
  padding: 2px 8px;
}
.mail-links { margin-left: auto; font-size: 14px; background: var(--white); padding: 2px 8px; border: var(--px) solid var(--black); }
.mail-links a { color: var(--black); }
.mail-links a:hover { background: var(--black); color: var(--white); text-decoration: none; }

.mail-list { border-bottom: var(--px) solid var(--black); }
.mail-rows { max-height: 172px; overflow-y: auto; }

.mail-row {
  display: grid;
  grid-template-columns: 150px 1fr 78px;
  gap: 10px;
  width: 100%;
  text-align: left;
  font-family: var(--font-body);
  font-size: 15px;
  background: var(--white);
  border: 0;
  border-bottom: 1px solid var(--black);
  padding: 6px 14px;
  cursor: var(--cursor-hand);
}
.mail-row span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-row span:last-child { text-align: right; }
.mail-row.unread { font-weight: bold; }
.mail-row.unread span:first-child::before { content: "•"; margin-right: 5px; }
.mail-row:hover:not(.mail-head), .mail-row.open { background: var(--black); color: var(--white); }
.mail-head {
  font-family: var(--font-ui);
  font-size: 16px;
  cursor: default;
  border-bottom: var(--px) solid var(--black);
}

.mail-pane { min-height: 190px; padding: 14px 16px; font-size: 15px; line-height: 1.5; }
.mail-meta { border-bottom: 1px solid var(--black); padding-bottom: 8px; margin-bottom: 10px; }
.mail-meta p { margin: 0; }
.mail-text { white-space: normal; }

.mail-compose-line { display: flex; gap: 8px; align-items: baseline; margin-bottom: 8px; }
.mail-compose-line input {
  flex: 1;
  font: inherit;
  border: 0;
  border-bottom: 1px solid var(--black);
  outline: none;
  background: var(--white);
  padding: 1px 2px;
}
.mc-text {
  width: 100%;
  height: 110px;
  font: inherit;
  border: var(--px) solid var(--black);
  padding: 8px 10px;
  resize: none;
  outline: none;
  margin: 4px 0 10px;
}
.mail-compose-actions { display: flex; align-items: center; gap: 12px; }
.mc-send, .mc-cancel {
  font-family: var(--font-ui);
  font-size: 18px;
  background: var(--white);
  border: var(--px) solid var(--black);
  box-shadow: 2px 2px 0 0 var(--black);
  padding: 4px 16px;
  cursor: var(--cursor-hand);
}
.mc-send { border-radius: 10px; }  /* the default button, System-style */
.mc-send:active, .mc-cancel:active { background: var(--black); color: var(--white); box-shadow: none; transform: translate(2px, 2px); }
.mc-send:disabled { opacity: 0.5; }
.mc-status { font-size: 14px; font-style: italic; }
.mc-status a { color: var(--black); }
.mail-sent { padding: 30px 10px; text-align: center; }

/* ── corner icons: guestbook top-right, trash bottom-right ── */

.desk-corner { position: absolute; }
.corner-top-right { top: 44px; right: 48px; }
.corner-bottom-right { bottom: 32px; right: 48px; }
.desk-corner .desk-icon { width: 128px; }
.desk-corner .desk-icon img { width: 96px; height: 96px; }
.desk-corner .desk-icon .desk-icon-label { text-align: center; }

/* ── Guestbook ── */

.da-guestbook { width: min(520px, calc(100vw - 56px)); }
.gb-body.window-body { padding: 16px 20px 18px; }

.gb-lead {
  font-family: var(--font-ui);
  font-size: 19px;
  text-align: center;
  margin-bottom: 12px;
}

.gb-form {
  border: var(--px) solid var(--black);
  padding: 12px 14px;
  margin-bottom: 14px;
}
.gb-form label {
  display: flex;
  gap: 10px;
  align-items: baseline;
  margin-bottom: 8px;
}
.gb-form label b { min-width: 52px; font-family: var(--font-ui); font-weight: normal; font-size: 17px; }
.gb-form input {
  flex: 1;
  font: inherit;
  border: 0;
  border-bottom: 1px solid var(--black);
  outline: none;
  background: var(--white);
  padding: 1px 2px;
}
.gb-actions { display: flex; align-items: center; gap: 12px; margin-top: 10px; }
.gb-sign {
  font-family: var(--font-ui);
  font-size: 18px;
  background: var(--white);
  border: var(--px) solid var(--black);
  border-radius: 10px;
  box-shadow: 2px 2px 0 0 var(--black);
  padding: 4px 22px;
  cursor: var(--cursor-hand);
}
.gb-sign:active { background: var(--black); color: var(--white); box-shadow: none; transform: translate(2px, 2px); }
.gb-status { font-size: 14px; font-style: italic; }

.gb-entries { max-height: 260px; overflow-y: auto; }
.gb-entry {
  padding: 8px 2px 9px;
  border-bottom: 1px solid var(--black);
}
.gb-entry:last-child { border-bottom: 0; }
.gb-entry-msg { font-style: italic; }
.gb-entry-meta { font-size: 13px; margin-top: 2px; }

/* ── Trash: anti-portfolio ── */

.da-anti { width: min(560px, calc(100vw - 56px)); }
.anti-body.window-body { padding: 14px 18px 16px; }

.anti-lead { font-size: 14px; font-style: italic; margin-bottom: 10px; }

.anti-list {
  border: var(--px) solid var(--black);
  margin-bottom: 12px;
  max-height: 200px;
  overflow-y: auto;
}
.anti-item {
  display: grid;
  grid-template-columns: 26px 1fr auto;
  gap: 10px;
  align-items: center;
  width: 100%;
  text-align: left;
  font-family: var(--font-body);
  font-size: 15px;
  background: var(--white);
  border: 0;
  border-bottom: 1px solid var(--black);
  padding: 7px 12px;
  cursor: var(--cursor-hand);
}
.anti-item:last-child { border-bottom: 0; }
.anti-item:hover, .anti-item.open { background: var(--black); color: var(--white); }
.anti-doc {
  width: 18px;
  height: 22px;
  border: var(--px) solid currentColor;
  /* dog-eared document */
  clip-path: polygon(0 0, 70% 0, 100% 30%, 100% 100%, 0 100%);
}
.anti-period { font-size: 13px; opacity: 0.8; }

.anti-story {
  border: var(--px) solid var(--black);
  box-shadow: 3px 3px 0 0 var(--black);
  padding: 12px 16px;
  min-height: 84px;
  font-size: 15px;
  line-height: 1.5;
}
.anti-hint { color: #666; font-style: italic; }
.anti-story-name { font-family: var(--font-ui); font-size: 19px; margin-bottom: 6px; }

/* ── Catalog of favorite things ── */

.da-catalog { width: min(600px, calc(100vw - 56px)); }
.cat-body.window-body { padding: 16px 18px 18px; }

.cat-lead {
  font-family: var(--font-ui);
  font-size: 18px;
  text-align: center;
  margin-bottom: 14px;
}

.cat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  max-height: 340px;
  overflow-y: auto;
}
.cat-card {
  border: var(--px) dashed var(--black);
  padding: 10px 12px 12px;
}
.cat-no {
  font-size: 12px;
  letter-spacing: 1px;
  border-bottom: 1px solid var(--black);
  display: inline-block;
  padding-bottom: 1px;
  margin-bottom: 6px;
}
.cat-name { font-family: var(--font-ui); font-size: 18px; margin-bottom: 4px; }
.cat-note { font-size: 14px; font-style: italic; }

/* ── Book Shelf ── */

.da-bookshelf { width: min(620px, calc(100vw - 56px)); }
.shelf-body.window-body { padding: 18px; }

.shelf-case {
  border: 4px solid var(--black);
  padding: 12px 10px 0;
}

.shelf-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 6px;
  padding: 0 4px;
  /* every wrapped row stands on its own board */
  border-bottom: 6px solid var(--black);
}
.shelf-row::after { content: ""; flex: 0 0 0; }

.book {
  position: relative;
  background: var(--white);
  border: var(--px) solid var(--black);
  border-bottom: 0;
  cursor: var(--cursor-hand);
  padding: 20px 2px 8px;   /* top room for the band/dot decorations */
  display: flex;
  align-items: flex-start;  /* titles read from the top, like real spines */
  justify-content: center;
  overflow: hidden;
}

.book-title {
  writing-mode: vertical-rl;
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1;
  max-height: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  background: var(--white);
  padding: 3px 1px;
}

/* a bookend so a half-empty shelf still looks furnished */
.bookend {
  align-self: flex-end;
  width: 12px;
  height: 56px;
  background: var(--black);
  margin-left: 4px;
}
.bookend::before {
  content: "";
  display: block;
  position: relative;
  left: -14px;
  top: 44px;
  width: 14px;
  height: 12px;
  background: var(--black);
}

/* spine decorations */
.spine-bands::before, .spine-bands::after {
  content: "";
  position: absolute;
  left: 2px; right: 2px;
  height: 4px;
  background: var(--black);
}
.spine-bands::before { top: 4px; }
.spine-bands::after { top: 12px; }

.spine-dots::before {
  content: "";
  position: absolute;
  left: 4px; right: 4px;
  top: 4px;
  height: 10px;
  background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="4" height="4"><rect width="4" height="4" fill="white"/><rect x="2" width="2" height="2" fill="black"/><rect y="2" width="2" height="2" fill="black"/></svg>');
  background-size: 4px 4px;
  border: var(--px) solid var(--black);
}

.book.open, .book:active { background: var(--black); }
.book.open .book-title, .book:active .book-title { background: var(--black); color: var(--white); }
.book.open.spine-dots::before, .book.open.spine-bands::before, .book.open.spine-bands::after { filter: invert(1); }

/* index card under the shelf */
.book-card {
  margin-top: 14px;
  border: var(--px) solid var(--black);
  box-shadow: 3px 3px 0 0 var(--black);
  padding: 10px 16px 12px;
  min-height: 84px;
}
.book-card p {
  margin: 0 0 6px;
  padding-bottom: 3px;
  border-bottom: 1px solid var(--black);  /* ruled index-card lines */
}
.book-card p:last-child { margin-bottom: 0; }
.book-card-hint { color: #666; font-style: italic; }
.book-card-title { font-family: var(--font-ui); font-size: 20px; }
.book-card-author { font-style: italic; }

/* ── Control Panel ── */

.da-controlpanel { width: min(560px, calc(100vw - 56px)); }
.cp-body.window-body { padding: 12px; }

.cp-grid {
  display: grid;
  grid-template-columns: 88px 1fr 96px;
  grid-template-areas:
    "vol datetime music"
    "vol tempo    tempo"
    "vol keyclick pattern";
  gap: 10px;
}

.cp-cell {
  border: var(--px) solid var(--black);
  padding: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.cp-volume {
  grid-area: vol;
  flex-direction: column;
  justify-content: space-between;
}
.cp-spk { width: 32px; height: 32px; }
.cp-vol-scale {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background: var(--white);
  border: var(--px) solid var(--black);
  padding: 6px 8px;
  margin: 6px 0;
}
.cp-vol-tick {
  display: flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: 0;
  font-family: var(--font-ui);
  font-size: 16px;
  cursor: var(--cursor-hand);
  padding: 1px 2px;
}
.cp-vol-tick i {
  width: 14px;
  height: 6px;
  border: var(--px) solid var(--black);
  background: var(--white);
}
.cp-vol-tick.sel i { background: var(--black); }
.cp-vol-tick.sel { background: var(--white); }

.cp-datetime {
  grid-area: datetime;
  background-image: none;
  background-color: var(--white);
  font-family: var(--font-ui);
  font-size: 22px;
  justify-content: space-around;
}

.cp-music-cell { grid-area: music; }
.cp-music {
  width: 56px;
  height: 56px;
  background: var(--white);
  border: var(--px) solid var(--black);
  box-shadow: 2px 2px 0 0 var(--black);
  cursor: var(--cursor-hand);
  display: flex;
  align-items: center;
  justify-content: center;
}
.cp-music img { width: 32px; height: 32px; }
.cp-music.on { background: var(--black); }
.cp-music.on img { filter: invert(1); }
.cp-music.on { animation: bop 0.6s steps(2) infinite; }
@keyframes bop { 50% { transform: translateY(-2px); } }

.cp-tempo { grid-area: tempo; }
.cp-tempo img { width: 32px; height: 24px; }
.cp-num, .cp-radio {
  width: 32px;
  height: 32px;
  background: var(--white);
  border: var(--px) solid var(--black);
  font-family: var(--font-ui);
  font-size: 18px;
  cursor: var(--cursor-hand);
  padding: 0;
}
.cp-num.sel, .cp-radio.sel { background: var(--black); color: var(--white); }

.cp-pattern { grid-area: pattern; }
.cp-pat-arrow {
  background: none;
  border: 0;
  cursor: var(--cursor-hand);
  padding: 2px;
}
.cp-pat-arrow img { width: 24px; height: 16px; }
.cp-pattern-sample {
  width: 40px;
  height: 40px;
  border: var(--px) solid var(--black);
  background-color: var(--white);
}

.cp-keyclick { grid-area: keyclick; }
.cp-label-mini {
  font-family: var(--font-ui);
  font-size: 15px;
  background: var(--white);
  padding: 2px 6px;
  border: var(--px) solid var(--black);
}

/* ─────────────────────────── small screens ───────────────────────── */

@media (max-width: 720px) {
  body { overflow: auto; }
  .desktop { overflow: visible; height: auto; min-height: calc(100% - var(--menubar-h)); padding-bottom: 40px; }
  .menubar { font-size: 16px; padding: 0 8px; }
  .menubar-left, .menubar-right { gap: 4px; }
  .menubar-logo { display: none; }
  .menu-item { display: none; }           /* menus are desktop sugar */
  .desktop { padding-bottom: 360px; overflow-x: hidden; }  /* room for the backdrop */
  .portrait { width: auto; }

  .home-card {
    position: relative;
    left: auto; top: auto;
    transform: none;
    margin: 20px auto;
    padding: 16px 10px 10px;
  }
  .home-title { font-size: 20px; gap: 8px; margin-bottom: 16px; }
  .home-title img { width: 24px; height: 24px; }
  .home-footer { flex-wrap: wrap; gap: 10px; margin-top: 18px; }
  .desk-icon.small { font-size: 16px; }
  .desk-icon.small img { width: 32px; height: 32px; }
  .pager-btn img { width: 36px; height: 24px; }
  .icon-grid { grid-template-columns: repeat(2, 1fr); }

  /* desktop layout on small screens: icons flow as a normal grid */
  .desktop-icons {
    position: static;
    margin: 20px auto 0;
    grid-auto-flow: row;
    grid-template-rows: none;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px 4px;
    width: fit-content;
    padding: 0 8px;
  }
  .layout-desktop .desk-icon { width: 110px; font-size: 17px; }
  .layout-desktop .menubar-clock { display: none; }

  .cat-grid { grid-template-columns: 1fr; }

  .window {
    position: fixed !important;
    left: 50% !important;
    top: 50% !important;
    transform: translate(-50%, -50%);
    width: calc(100vw - 32px);
  }
  .da-calculator { width: 264px; min-width: 264px; }

  /* control panel restacks into two columns on small screens */
  .cp-grid {
    grid-template-columns: 72px 1fr;
    grid-template-areas:
      "vol datetime"
      "vol music"
      "vol tempo"
      "vol keyclick"
      "vol pattern";
  }
  .cp-datetime { font-size: 16px; gap: 8px; flex-wrap: wrap; padding: 6px; }
  .cp-tempo { flex-wrap: wrap; }
  .cp-tempo img { width: 24px; height: 18px; }
  .cp-num, .cp-radio { width: 28px; height: 28px; font-size: 16px; }
  .cp-spk { width: 24px; height: 24px; }
  .cp-music { width: 44px; height: 44px; }
  .clock { display: none; }
}
