/* The viewer's chrome, drawn as the Mac app draws its own: paper, ink and sticker cards in IBM
   Plex Mono, with the same palette, line weight, radii, offset shadows and metrics, which
   Docs/design/chrome-spec.md lists. A card's border is inside its box, as on the Mac, so a padding
   here is the Mac's inset less the 1.5px line. Tools/compare_chrome.py checks the two agree. */

@font-face {
  font-family: "Plex Mono";
  src: url("fonts/IBMPlexMono-Regular.ttf") format("truetype");
  font-weight: 400;
}
@font-face {
  font-family: "Plex Mono";
  src: url("fonts/IBMPlexMono-Medium.ttf") format("truetype");
  font-weight: 500;
}
@font-face {
  font-family: "Plex Mono";
  src: url("fonts/IBMPlexMono-SemiBold.ttf") format("truetype");
  font-weight: 600;
}

:root {
  --paper: #f2efe7;
  --sheet: #f7f5ee;
  --sheet-sunk: #ece8dd;
  --ink: #231e16;
  --ink-soft: #3a342a;
  --muted: #6f685c;
  --faint: #9a9284;
  --rule: #ddd6c8;
  --cream: #fff4d6;
  --cream-wash: #fbf5e2;
  --cobalt: #76a0e2;
  --cobalt-mid: #5a82c6;
  --cobalt-wash: #dde6f4;
  --mustard: #f4b829;
  --tomato-wash: #f8ddd3;
  --ink-on-dark: #eef4ff;
  --muted-on-dark: #a9bedf;
  --line: 1.5px;
  --radius-card: 12px;
  --radius-chip: 8px;
  --shadow-card: 3px;
  --shadow-chip: 2px;
  --pill: 30px;
  --ease: cubic-bezier(0.3, 0.7, 0.2, 1);
  --text-xs: 10.5px;
  --text-s: 11.5px;
  --text-m: 12.5px;
  --text-l: 13.5px;
  --text-heading: 15px;
  color-scheme: light;
}

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

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  font: 400 var(--text-m)/1.3 "Plex Mono", Menlo, monospace;
  -webkit-font-smoothing: antialiased;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#viewport {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  outline: none;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ---- Cards ------------------------------------------------------------------------------ */

.card {
  position: fixed;
  background: var(--sheet);
  border: var(--line) solid var(--ink);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card) var(--shadow-card) 0 var(--ink);
  z-index: 2;
}

.card h2 {
  margin: 0 0 2px;
  font-size: var(--text-xs);
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--muted);
}

/* ---- Controls --------------------------------------------------------------------------- */

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: var(--pill);
  min-width: var(--pill);
  padding: 0 10.5px;
  border: var(--line) solid var(--ink);
  border-radius: calc(var(--pill) / 2);
  background: var(--sheet);
  font-size: var(--text-s);
  font-weight: 500;
  white-space: nowrap;
  transition: background 0.16s var(--ease);
}
.pill.icon { padding: 0; width: var(--pill); }
.pill:hover:not(:disabled) { background: var(--cream); }
.pill:active:not(:disabled) { transform: translate(1px, 1px); }
.pill.on { background: var(--ink); color: var(--paper); }
.pill:disabled { opacity: 0.4; }
.pill.ghostly { border-color: transparent; background: transparent; }
.pill.ghostly:hover { border-color: var(--ink); }

.segmented {
  position: relative;
  display: inline-flex;
  height: var(--pill);
  border-radius: calc(var(--pill) / 2);
  overflow: hidden;
  background: var(--sheet);
  flex: none;
}
.segmented::after {
  content: "";
  position: absolute;
  inset: 0;
  border: var(--line) solid var(--ink);
  border-radius: inherit;
  pointer-events: none;
}
.segmented button {
  border: none;
  box-shadow: inset var(--line) 0 0 var(--ink);
  background: transparent;
  padding: 0 11px;
  font-size: var(--text-s);
  font-weight: 500;
  white-space: nowrap;
  transition: background 0.16s var(--ease);
}
.segmented button:first-child { box-shadow: none; }
.segmented button:hover { background: var(--cream-wash); }
.segmented button.on {
  font-weight: 600;
  background: linear-gradient(to top, transparent var(--line), var(--ink) var(--line),
                              var(--ink) calc(var(--line) + 2px), var(--cream) calc(var(--line) + 2px));
}
.segmented.disabled { opacity: 0.4; pointer-events: none; }

.slider {
  -webkit-appearance: none;
  appearance: none;
  width: 120px;
  height: 16px;
  background: transparent;
  flex: 1;
}
.slider::-webkit-slider-runnable-track { height: 3px; border-radius: 1.5px; background: var(--rule); }
.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px; margin-top: -6.5px;
  border-radius: 8px; border: var(--line) solid var(--ink); background: var(--cream);
}
.slider::-moz-range-track { height: 3px; border-radius: 1.5px; background: var(--rule); }
.slider::-moz-range-thumb { width: 13px; height: 13px; border-radius: 8px; border: var(--line) solid var(--ink); background: var(--cream); }
.slider:disabled { opacity: 0.35; }

kbd.cap {
  display: inline-block;
  min-width: 20px;
  height: 20px;
  padding: 0 3.75px;
  border: 1.25px solid var(--ink);
  border-radius: 5px;
  background: var(--paper);
  box-shadow: 1px 1px 0 var(--ink);
  font: 600 var(--text-xs)/17.5px "Plex Mono", Menlo, monospace;
  text-align: center;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 3.5px 8.5px;
  background: var(--sheet);
  border: var(--line) solid var(--ink);
  border-radius: var(--radius-chip);
  box-shadow: var(--shadow-chip) var(--shadow-chip) 0 var(--ink);
  font-size: var(--text-s);
  white-space: nowrap;
}

/* ---- The masthead ----------------------------------------------------------------------- */

.masthead {
  position: fixed;
  left: 24px;
  top: 10px;
  max-width: 50%;
  z-index: 1;
  pointer-events: none;
}
.masthead .title, .masthead .subtitle { text-shadow: 0 0 3px var(--paper); }
/* The masthead lets clicks through to the view, but for its close button. */
.masthead .title-row { display: flex; align-items: center; gap: 4px; }
.masthead .title-row .pill { pointer-events: auto; flex: none; }
.masthead .title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.masthead .title { font-size: var(--text-l); font-weight: 600; }
.masthead .subtitle { margin-top: 2px; font-size: var(--text-s); color: var(--muted); }
.masthead .progress {
  position: relative;
  margin-top: 10px;
  width: 240px;
  height: 6px;
  border: var(--line) solid var(--ink);
  border-radius: 3px;
  background: var(--sheet);
  overflow: hidden;
}
/* Slid in from the left rather than widened, so it moves without layout. */
.masthead .progress .fill {
  position: absolute;
  inset: 0;
  background: var(--mustard);
  border-right: var(--line) solid var(--ink);
  transform: translateX(-100%);
  transition: transform 0.22s var(--ease);
}
.masthead.on-dark .title { color: var(--ink-on-dark); }
.masthead.on-dark .subtitle { color: var(--muted-on-dark); }

/* ---- The structure and library cards ---------------------------------------------------- */

.structure {
  left: 18px;
  top: 72px;
  bottom: 96px;
  width: 300px;
  display: flex;
  flex-direction: column;
  padding: 10.5px 14.5px 6.5px;
  gap: 10px;
}
.structure > .segmented { align-self: flex-start; }

.searchbox {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 10px;
  border: var(--line) solid var(--rule);
  border-radius: 14px;
  background: #fff;
  color: var(--muted);
}
.searchbox:focus-within { border-color: var(--ink); }
.searchbox .glyph { display: inline-flex; }
.searchbox input {
  flex: 1;
  min-width: 0;
  border: none;
  outline: none;
  background: transparent;
  font-size: var(--text-m);
  color: var(--ink);
  -webkit-user-select: text;
  user-select: text;
}
.searchbox input::-webkit-search-cancel-button { display: none; }
.searchbox input::placeholder { color: var(--muted); opacity: 1; }
.searchbox .match { font-size: var(--text-xs); color: var(--muted); white-space: nowrap; }

.tree {
  position: relative;
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  margin: 0 -10px;
  overscroll-behavior: contain;
}
.tree .spacer { width: 1px; }
.tree .rows { position: absolute; left: 0; right: 0; top: 0; will-change: transform; }

/* A row: its chevron at 8 + 14 a level (the padding, set per row), a 16-wide slot for the glyph or
   swatch 3 after it, the name 7 after that, and at the end the count 14 from the edge. */
.tree .row {
  position: relative;
  isolation: isolate;
  display: flex;
  align-items: center;
  height: 28px;
  padding-right: 8px;
  font-size: var(--text-m);
  cursor: default;
}
body.phone .tree .row { height: 30px; }
/* The plate behind a row, inset from it: cream under the pointer, and while selected the cobalt
   wash with a bar down its left edge, clipped to its corners. */
.tree .row::after {
  content: "";
  position: absolute;
  inset: 1px 6px;
  border-radius: 6px;
  z-index: -1;
}
.tree .row:hover::after, .tree .row.highlighted::after { background: var(--cream); }
.tree .row.selected::after { background: linear-gradient(to right, var(--cobalt-mid) 3px, var(--cobalt-wash) 3px); }
.tree .chevron {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--ink);
}
.tree .chevron.open { transform: rotate(90deg); }
.tree .glyph { flex: none; display: inline-flex; justify-content: center; width: 16px; margin-left: 3px; color: var(--ink); }
/* A part's colour as a printed chip: the colour, and below a diagonal across 55% of the way, a
   shade of it 16% toward ink, both set as one gradient over the whole tile, under its line. */
.tree .swatch {
  flex: none;
  width: 12px;
  height: 12px;
  margin: 0 2px 0 5px;
  border: 1.25px solid var(--ink);
  border-radius: 3px;
  background-color: var(--sheet-sunk);
  background-origin: border-box;
}
.tree .swatch.small { width: 9px; height: 9px; margin: 0 3.5px 0 6.5px; border-radius: 2px; }
.tree .name { flex: 1; min-width: 0; margin-left: 7px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree .count, .tree .mark { flex: none; margin: 0 6px 0 8px; font-size: var(--text-s); color: var(--muted); display: inline-flex; }
.tree .actions { display: none; flex: none; gap: 1px; margin-left: 4px; }
.tree .row:hover .actions { display: inline-flex; }
.tree .row:hover .actions ~ .count, .tree .row:hover .actions ~ .mark, .tree .row:hover .actions ~ .pill { display: none; }
.tree .rowbutton {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 1.25px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  transition: background 0.16s var(--ease), border-color 0.16s var(--ease);
}
.tree .rowbutton:hover { border-color: var(--ink); background: var(--sheet); }
.tree .rowbutton.on { border-color: var(--ink); background: var(--sheet-sunk); }
.tree .row.hidden-node .name { color: var(--faint); text-decoration: line-through; text-decoration-color: var(--faint); }
.tree .row.ghosted-node .name { color: var(--muted); }

.structure .footer {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 10px;
  border-top: var(--line) solid var(--rule);
}
.structure .footer .counts { display: flex; flex-direction: column; gap: 2px; font-size: var(--text-s); font-weight: 500; }
.structure .footer .buttons { display: flex; gap: 8px; }

.structure .nothing { margin: 0; color: var(--muted); font-size: var(--text-s); }

/* The Library: the switcher and the two ways in, then folders and recent files as tree rows. */
.library .header { display: flex; align-items: center; gap: 8px; }
.library .header .grow { flex: 1; }
.library .row.heading .name { font-weight: 600; }
.library .row.message { color: var(--muted); font-size: var(--text-s); }
.library .row.missing .name { color: var(--faint); }
.library .row .pill.small { height: 22px; padding: 0 8px; margin: 0 4px 0 8px; font-size: var(--text-xs); }
body.phone .library .actions { display: inline-flex; }
body.phone .library .actions ~ .count { display: none; }

/* ---- The selection card ----------------------------------------------------------------- */

.selection {
  right: 18px;
  top: 172px;
  width: 286px;
  padding: 10.5px 12.5px 12.5px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.selection .kind { font-size: var(--text-xs); font-weight: 500; color: var(--muted); letter-spacing: 0.04em; }
.selection .name { margin-top: 3px; font-size: var(--text-l); font-weight: 600; overflow-wrap: anywhere; }
.selection .path { margin-top: 3px; font-size: var(--text-xs); color: var(--muted); overflow-wrap: anywhere; }
.selection hr { width: 100%; margin: 0; border: none; border-top: var(--line) solid var(--ink); }
.selection .stats { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.selection .number { font-size: 26px; font-weight: 600; line-height: 1.1; }
.selection .unit { font-size: var(--text-s); font-weight: 500; color: var(--ink-soft); }
.selection .actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.selection .pill { width: 100%; justify-content: flex-start; }

/* ---- The toolbar and its cards ---------------------------------------------------------- */

.toolbar {
  left: calc(318px + (100% - 318px) / 2);
  bottom: 22px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6.5px 8.5px;
  max-width: calc(100% - 336px);
  overflow: hidden;
}
/* Tools keep their size; those that don't fit fold into More (toolbar-fold.js). */
.toolbar > * { flex: none; }
.toolbar > .folded { display: none !important; }
.toolbar .rule { flex: none; width: var(--line); height: 22px; background: var(--rule); }

.menu {
  position: fixed;
  display: flex;
  flex-direction: column;
  padding: 6px;
  background: var(--sheet);
  border: var(--line) solid var(--ink);
  border-radius: var(--radius-chip);
  box-shadow: var(--shadow-chip) var(--shadow-chip) 0 var(--ink);
  z-index: 5;
}
.menu button { display: flex; align-items: center; gap: 8px; border: none; background: transparent; padding: 6px 12px; border-radius: 6px; text-align: left; font-size: var(--text-s); }
.menu button:hover:not(:disabled) { background: var(--cream); }
.menu button:disabled { opacity: 0.4; }
.menu .icon, .menu .check { display: inline-flex; flex: none; width: 15px; justify-content: center; }
.menu.views .icon, .menu.views .check { display: none; }
.menu button > span:nth-child(2) { flex: 1; padding-right: 12px; }
.menu .heading { padding: 8px 12px 4px; font-size: var(--text-xs); font-weight: 500; color: var(--muted); letter-spacing: 0.04em; }

.popover {
  left: calc(318px + (100% - 318px) / 2);
  bottom: 80px;
  transform: translateX(-50%);
  padding: 12.5px 14.5px 14.5px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: calc(100% - 24px);
}
.popover .row { display: flex; align-items: center; gap: 8px; }
.look .label { width: 92px; flex: none; font-size: var(--text-s); font-weight: 500; }
.look .label.disabled { color: var(--faint); }
.look .note { margin: -4px 0 0 100px; font-size: var(--text-xs); color: var(--muted); }
.section .row { gap: 10px; }
.section .axis { width: 14px; font-size: var(--text-s); font-weight: 600; }
.popover.section { width: 340px; }
.section .slider { width: 160px; }

/* ---- Overlays --------------------------------------------------------------------------- */

.status {
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 360px;
  max-width: calc(100% - 32px);
  padding: 18.5px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
}
.status h2 { margin: 0; font-size: var(--text-heading); font-weight: 600; color: var(--ink); letter-spacing: 0; }
.status p { margin: 0; color: var(--muted); font-size: var(--text-m); overflow-wrap: anywhere; }
.status .buttons { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.status .samples { align-self: stretch; display: flex; flex-direction: column; margin-top: 10px; padding-top: 12px; border-top: var(--line) solid var(--rule); }
.status .samples .heading { margin: 0 0 4px; font-size: var(--text-xs); font-weight: 500; color: var(--muted); letter-spacing: 0.04em; }
.status .sample { display: flex; align-items: baseline; gap: 12px; margin: 0 -8px; padding: 6px 8px; border: none; border-radius: 6px; background: transparent; text-align: left; font-size: var(--text-s); color: var(--ink); }
.status .sample:hover { background: var(--cream); }
.status .sample .name { flex: 1; }
.status .sample .size { font-size: var(--text-xs); color: var(--muted); }

.hint.hiding { background: var(--tomato-wash); }
.hint {
  position: fixed;
  left: calc(318px + (100% - 318px) / 2);
  bottom: 86px;
  transform: translateX(-50%);
  z-index: 3;
}
.hover {
  position: fixed;
  z-index: 4;
  pointer-events: none;
}
.hover .name { font-weight: 500; }
.hover .face { color: var(--muted); }

.dropzone {
  position: fixed;
  inset: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 18px;
  background: rgba(255, 244, 214, 0.7) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg'%3E%3Crect x='1' y='1' rx='17' style='width:calc(100%25 - 2px);height:calc(100%25 - 2px)' fill='none' stroke='%23231e16' stroke-width='2' stroke-dasharray='8 6'/%3E%3C/svg%3E");
  z-index: 6;
  pointer-events: none;
}
.dropzone .words { font-size: var(--text-l); font-weight: 600; }

.sheet {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(242, 239, 231, 0.55);
  z-index: 7;
}
.sheet .card { position: relative; padding: 16.5px 18.5px; }
.sheet h2 { font-size: var(--text-l); font-weight: 600; color: var(--ink); margin-bottom: 12px; letter-spacing: 0; }
.sheet .grid { display: grid; grid-template-columns: auto auto; gap: 8px 12px; align-items: center; font-size: var(--text-s); }
.sheet .keys { display: flex; gap: 4px; justify-content: flex-end; }

/* ---- Phones: the tree and cards give way to the view ------------------------------------ */

.phone-only { display: none !important; }
body.phone .phone-only { display: inline-flex !important; }
body.phone .desktop-only { display: none !important; }

body.phone .structure { left: 8px; right: 8px; top: auto; bottom: calc(76px + env(safe-area-inset-bottom)); width: auto; height: 45%; }
body.phone .selection { right: 8px; left: 8px; top: calc(56px + env(safe-area-inset-top)); width: auto; }
body.phone .toolbar { left: 50%; bottom: calc(10px + env(safe-area-inset-bottom)); max-width: calc(100% - 16px); }
body.phone .popover, body.phone .hint { left: 50%; bottom: calc(70px + env(safe-area-inset-bottom)); }
body.phone .masthead { top: calc(10px + env(safe-area-inset-top)); left: 16px; max-width: 70%; }
body.phone .look .label { width: 70px; }
body.phone .look .note { margin-left: 78px; }

@media (max-width: 900px) {
  .toolbar, .popover, .hint { left: 50%; max-width: calc(100% - 16px); }
}
