/* TreyOS: a 1-bit desktop. Black ink, white paper, dither for grey. */

:root {
  --ink: #000;
  --paper: #fff;
  --dim: #555;
  --wgi: #0a8f63;
  --pm: #74291e;
  --ui: 'IBM Plex Mono', ui-monospace, Menlo, monospace;
  --display: 'VT323', 'IBM Plex Mono', monospace;
  --dither: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='4' height='4' shape-rendering='crispEdges'%3E%3Crect width='4' height='4' fill='%23fff'/%3E%3Crect width='1' height='1'/%3E%3Crect x='2' y='2' width='1' height='1'/%3E%3C/svg%3E");
  --dots: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='6' height='6' shape-rendering='crispEdges'%3E%3Crect width='6' height='6' fill='%23fff'/%3E%3Crect x='2' y='2' width='1' height='1'/%3E%3C/svg%3E");
  --grid: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' shape-rendering='crispEdges'%3E%3Crect width='16' height='16' fill='%23fff'/%3E%3Crect width='16' height='1' fill='%23bbb'/%3E%3Crect width='1' height='16' fill='%23bbb'/%3E%3C/svg%3E");
  --desk: var(--dither);
  --step: steps(6);
}

* { box-sizing: border-box; }

html, body { margin: 0; height: 100%; }

body {
  background: var(--paper);
  color: var(--ink);
  font: 14px/1.5 var(--ui);
  -webkit-font-smoothing: none;
}

a { color: inherit; }

:focus-visible { outline: 2px dashed var(--ink); outline-offset: 2px; }

/* ---------- Fallback (no JS) ---------- */
#fallback { max-width: 68ch; margin: 0 auto; padding: 32px 16px 64px; }
#fallback h1 { font: 400 44px/1 var(--display); }
html.js #fallback { display: none; }
html:not(.js) #desktop, html:not(.js) #boot { display: none; }

/* ---------- Boot ---------- */
#boot { display: none; }
#boot.is-on {
  position: fixed; inset: 0; z-index: 1000;
  display: grid; place-items: center;
  background: var(--paper);
}
.boot-box { text-align: center; }
.boot-mark {
  width: 64px; height: 64px; margin: 0 auto 12px;
  border: 4px solid var(--ink);
  background: var(--dither);
  animation: boot-mark 1.4s steps(2) infinite;
}
@keyframes boot-mark { 50% { background: var(--ink); } }
.boot-name { margin: 0 0 16px; font: 400 40px/1 var(--display); }
.boot-bar { width: 200px; height: 14px; border: 2px solid var(--ink); padding: 2px; }
.boot-bar span { display: block; height: 100%; width: 0; background: var(--ink); animation: boot-fill 1.3s steps(12) 0.2s forwards; }
@keyframes boot-fill { to { width: 100%; } }

/* ---------- Desktop ---------- */
#desktop {
  position: fixed; inset: 0;
  background: var(--desk);
  overflow: hidden;
  opacity: 0;
}
#desktop.is-ready { opacity: 1; }
html[data-pattern="dots"] { --desk: var(--dots); }
html[data-pattern="grid"] { --desk: var(--grid); }
html[data-pattern="plain"] { --desk: var(--paper); }

.menubar {
  position: absolute; inset: 0 0 auto 0; z-index: 900;
  height: 28px; padding: 0 8px;
  display: flex; align-items: center; justify-content: space-between;
  background: var(--paper);
  border-bottom: 2px solid var(--ink);
  font-weight: 600;
}
.menus { display: flex; height: 100%; }
.menu { position: relative; }
.menu-title {
  height: 26px; padding: 0 10px;
  border: 0; background: none; color: inherit;
  font: inherit; cursor: pointer;
}
.menu-title[aria-expanded="true"] { background: var(--ink); color: var(--paper); }
.menu-items {
  position: absolute; top: 26px; left: 0; min-width: 190px;
  display: flex; flex-direction: column;
  background: var(--paper);
  border: 2px solid var(--ink);
  box-shadow: 3px 3px 0 var(--ink);
  padding: 2px 0;
}
.menu-items[hidden] { display: none; }
.menu-items button {
  text-align: left; padding: 3px 14px;
  border: 0; background: none; color: inherit;
  font: inherit; font-weight: 400; cursor: pointer;
}
.menu-items button:hover, .menu-items button:focus-visible { background: var(--ink); color: var(--paper); outline: 0; }
.status { display: flex; gap: 14px; align-items: center; font-weight: 400; }
.hits {
  font-variant-numeric: tabular-nums; letter-spacing: 1px;
  padding: 0 4px; background: var(--ink); color: var(--paper);
}

.icons {
  position: absolute; top: 44px; bottom: 16px; left: 12px; right: 12px;
  display: grid;
  grid-auto-flow: column;
  grid-template-rows: repeat(auto-fill, 92px);
  grid-auto-columns: 96px;
  gap: 4px 8px;
  align-content: start;
  direction: rtl; /* icons live on the right edge; windows open on the left */
  pointer-events: none;
}
.icon {
  pointer-events: auto;
  width: 96px; padding: 4px 2px;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  background: none; border: 0; color: inherit;
  font: inherit; font-size: 12px; cursor: default;
  direction: ltr;
}
.icon-art {
  width: 44px; height: 44px;
  display: grid; place-items: center;
  background: var(--paper);
  border: 2px solid var(--ink);
  box-shadow: 2px 2px 0 var(--ink);
}
.icon-art img { width: 40px; height: 40px; image-rendering: pixelated; filter: grayscale(1) contrast(4); }
html[data-color="true"] .icon-art img { filter: none; }
.icon-label { background: var(--paper); padding: 0 4px; line-height: 1.35; text-align: center; }
.icon.is-selected .icon-label, .icon:focus-visible .icon-label { background: var(--ink); color: var(--paper); }
.icon.is-selected .icon-art { background: var(--ink); color: var(--paper); }
.icon:focus-visible { outline: 0; }

/* ---------- Windows ---------- */
.windows { position: absolute; inset: 0; pointer-events: none; }
.win {
  position: absolute;
  pointer-events: auto;
  display: flex; flex-direction: column;
  min-width: 260px;
  background: var(--paper);
  border: 2px solid var(--ink);
  box-shadow: 4px 4px 0 var(--ink);
  animation: win-open 0.2s steps(4);
}
@keyframes win-open { from { transform: scale(0.3); opacity: 0.4; } }
.win:focus { outline: 0; }
.tbar {
  flex: none; position: relative;
  height: 24px; display: flex; align-items: center; justify-content: center;
  border-bottom: 2px solid var(--ink);
  cursor: grab; user-select: none; touch-action: none;
}
.win.is-focused .tbar { background: repeating-linear-gradient(0deg, var(--ink) 0 1px, var(--paper) 1px 3px); }
.tbar-title { margin: 0; padding: 0 10px; background: var(--paper); font: 600 13px/1 var(--ui); }
.tbar-close {
  position: absolute; left: 8px; top: 4px;
  width: 14px; height: 14px; padding: 0;
  background: var(--paper); border: 2px solid var(--ink); cursor: pointer;
}
.tbar-close:hover, .tbar-close:focus-visible { background: var(--ink); outline: 0; }
.wbody { flex: 1; overflow: auto; overscroll-behavior: contain; }
.pad { padding: 16px; margin: 0; }

/* ---------- Phone ---------- */
@media (max-width: 699px) {
  .menus .menu:nth-child(3) { display: none; }
  .status .city { display: none; }
  .icons {
    grid-auto-flow: row;
    grid-template-rows: none;
    grid-template-columns: repeat(4, 1fr);
    grid-auto-rows: 92px;
    overflow-y: auto; pointer-events: auto;
    bottom: 72px; direction: ltr;
  }
  .icon { width: auto; }
  .win.is-full {
    left: 0 !important; top: 28px !important; right: 0; bottom: 0;
    width: auto !important; height: auto !important;
    border-width: 2px 0 0; box-shadow: none;
  }
  .tbar { height: 40px; cursor: default; }
  .tbar-close { width: 24px; height: 24px; left: 10px; top: 6px; }
}

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

/* ---------- App content ---------- */
.wbody h1 { font-size: 20px; line-height: 1.2; margin: 0 0 8px; }
.wbody h2 { font-size: 14px; margin: 20px 0 6px; }
.wbody p { margin: 0 0 10px; max-width: 62ch; }
.display { font: 400 40px/1 var(--display) !important; }
.meta { color: var(--dim); }
.hint { color: var(--dim); font-size: 12px; }

.btn {
  display: inline-block; margin: 0 8px 8px 0; padding: 4px 14px;
  border: 2px solid var(--ink); border-radius: 10px;
  box-shadow: 2px 2px 0 var(--ink);
  background: var(--paper); color: var(--ink);
  text-decoration: none; font-weight: 600;
}
.btn:hover { background: var(--ink); color: var(--paper); }
.btn:active { transform: translate(2px, 2px); box-shadow: none; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 0; margin: 12px 0; list-style: none; }
.chips li { border: 1px solid var(--ink); padding: 0 8px; font-size: 12px; }

/* Project windows carry their brand color. */
.project-head {
  display: flex; gap: 14px; align-items: center;
  padding: 16px; background: var(--brand); color: #fff;
  border-bottom: 2px solid var(--ink);
}
.project-head h1 { margin: 0; font-size: 24px; }
.project-role { margin: 0 !important; opacity: 0.85; }
.project-icon { border: 2px solid var(--ink); border-radius: 12px; background: #fff; }
.project-pitch { font-size: 16px; }
.project-how { padding-left: 22px; }
.project-how li { margin-bottom: 6px; }
.project .btn { border-color: var(--brand); box-shadow: 2px 2px 0 var(--brand); color: var(--brand); }
.project .btn:hover { background: var(--brand); color: #fff; }

.shots { display: flex; gap: 12px; overflow-x: auto; padding: 4px 2px 14px; }
.shot { flex: none; width: 150px; padding: 0; border: 2px solid var(--ink); background: var(--paper); cursor: pointer; }
.shot img { display: block; width: 100%; }

/* The develop effect: 1-bit until hovered, focused or tapped. */
.develop { position: relative; overflow: hidden; }
.develop img { filter: grayscale(1) contrast(3) brightness(1.1); transition: filter 1.2s var(--step); }
.develop::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: var(--dots); mix-blend-mode: multiply; opacity: 0.9;
  transition: opacity 1.2s var(--step);
}
.develop:hover img, .develop:focus-visible img, .develop.is-developed img { filter: none; }
.develop:hover::after, .develop:focus-visible::after, .develop.is-developed::after { opacity: 0; }
html[data-color="true"] .develop img { filter: none; }
html[data-color="true"] .develop::after { opacity: 0; }

.folder { display: grid; grid-template-columns: repeat(auto-fill, 96px); gap: 8px; }
.folder-item { display: flex; flex-direction: column; align-items: center; gap: 4px; background: none; border: 0; font: inherit; font-size: 12px; cursor: pointer; color: inherit; }
.folder-item:hover .icon-label, .folder-item:focus-visible .icon-label { background: var(--ink); color: var(--paper); }
.folder-item:focus-visible { outline: 0; }

.trash-item { border-top: 2px dotted var(--ink); padding-top: 8px; margin-top: 12px; }
.trash-item h2 { margin-top: 0; }

.shelf { display: flex; gap: 20px; align-items: center; }
.book-spine {
  width: 44px; height: 170px; flex: none;
  border: 2px solid var(--ink); background: var(--ink); color: var(--paper);
  display: grid; place-items: center; box-shadow: 3px 3px 0 var(--dim);
}
.book-spine span { writing-mode: vertical-rl; transform: rotate(180deg); font-size: 12px; }

.garage-art svg { width: 96px; height: 96px; }

/* Darkroom */
.contact-sheet { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; }
.print { padding: 4px 4px 14px; background: var(--paper); border: 2px solid var(--ink); box-shadow: 2px 2px 0 var(--ink); cursor: pointer; }
.print img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; }
.viewer { margin: 0; height: 100%; display: flex; flex-direction: column; }
.viewer-frame { flex: 1; min-height: 0; background: var(--ink); display: grid; place-items: center; }
.viewer-frame { position: relative; overflow: hidden; }
.viewer-frame img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.viewer-frame.develop img { transition-duration: 2s; }
.viewer-frame.develop::after { transition-duration: 2s; }
.viewer figcaption { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px 2px; border-top: 2px solid var(--ink); }

/* Cellar */
.rack { display: flex; gap: 6px; align-items: flex-end; padding: 12px 8px 0; border-bottom: 6px solid var(--ink); overflow-x: auto; }
.bottle { padding: 0; background: none; border: 0; cursor: pointer; transition: transform 0.2s steps(2); }
.bottle svg { display: block; width: 48px; height: 144px; }
.bottle.is-picked, .bottle:focus-visible { transform: translateY(-10px); outline: 0; }
.cellar-detail { min-height: 3em; margin-top: 12px !important; }

/* Maps */
.maps { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); height: 100%; }
.map { position: relative; border-right: 2px solid var(--ink); align-self: start; }
.map img { display: block; width: 100%; }
.pin {
  position: absolute; width: 14px; height: 14px; margin: -14px 0 0 -7px; padding: 0;
  background: var(--paper); border: 2px solid var(--ink); border-radius: 50% 50% 50% 0; transform: rotate(-45deg);
  cursor: pointer;
}
.pin.is-picked, .pin:hover { background: var(--ink); }
.spots { padding-left: 20px; }
.spots button { padding: 0; background: none; border: 0; font: inherit; text-align: left; cursor: pointer; color: inherit; }
.spots button.is-picked { background: var(--ink); color: var(--paper); }
@media (max-width: 699px) {
  .maps { grid-template-columns: 1fr; }
  .map { border-right: 0; border-bottom: 2px solid var(--ink); }
}
.spots li { margin-bottom: 6px; }
.spots .meta { display: block; font-size: 12px; }

/* Terminal */
.wbody.term { background: var(--ink); color: var(--paper); font: 20px/1.1 var(--display); padding: 10px 12px; }
.term-out div { white-space: pre-wrap; }
.term-line { display: flex; gap: 8px; }
.term-line input { flex: 1; background: none; border: 0; color: inherit; font: inherit; caret-color: var(--paper); outline: 0; }

/* Control Panel */
.control fieldset { border: 2px solid var(--ink); margin: 0 0 12px; padding: 8px 12px 10px; }
.control legend { font-weight: 600; padding: 0 6px; }
.control label { display: block; margin: 4px 0; cursor: pointer; }
.control input { accent-color: var(--ink); }

/* Newton */
.newton-app { display: flex; flex-direction: column; }
.newton-photo { display: block; padding: 0; border: 0; border-bottom: 2px solid var(--ink); background: var(--ink); cursor: pointer; }
.newton-photo img { display: block; width: 100%; max-height: 320px; object-fit: cover; object-position: 50% 60%; }
.pet-layer { position: absolute; left: 0; right: 0; bottom: 6px; height: 46px; pointer-events: none; z-index: 5; }
.pet { position: absolute; left: 0; bottom: 0; padding: 0; border: 0; background: none; cursor: pointer; pointer-events: auto; }
.pet svg { display: block; }

/* CRT mode */
html[data-crt="true"] body::after {
  content: ""; position: fixed; inset: 0; z-index: 2000; pointer-events: none;
  background: repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.12) 0 1px, transparent 1px 3px);
  box-shadow: inset 0 0 120px rgba(0, 0, 0, 0.35);
  animation: crt-flicker 0.15s steps(2) infinite;
}
@keyframes crt-flicker { 50% { opacity: 0.85; } }

/* Notes */
.notes-list { list-style: none; margin: 0; padding: 0; }
.notes-list button { display: block; width: 100%; text-align: left; padding: 12px 16px; background: none; border: 0; border-bottom: 1px solid var(--ink); font: inherit; color: inherit; cursor: pointer; }
.notes-list button:hover, .notes-list button:focus-visible { background: var(--ink); color: var(--paper); outline: 0; }
.notes-list button:hover .meta, .notes-list button:focus-visible .meta { color: var(--paper); }
.notes-list .meta { display: block; font-size: 12px; }
.notes-bar { padding: 12px 16px 0; margin: 0 !important; }
.note h1 { font: 400 36px/1 var(--display); }
.note .post-date { color: var(--dim); }

/* Guestbook */
.gb-form label { display: block; margin-bottom: 8px; font-weight: 600; }
.gb-form input, .gb-form textarea { display: block; width: 100%; margin-top: 2px; padding: 4px 6px; border: 2px solid var(--ink); background: var(--paper); font: 400 14px/1.4 var(--ui); color: var(--ink); }
.gb-form .gb-hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
.gb-status { min-height: 1.5em; }
.gb-entries { list-style: none; padding: 0; margin: 0; }
.gb-entries li { border-top: 2px dotted var(--ink); padding-top: 8px; margin-top: 8px; }
.gb-msg { white-space: pre-wrap; overflow-wrap: anywhere; }
.hits[hidden] { display: none; }

/* Desktop label: the owner's name, printed on the desk like a volume label. */
.desk-label {
  position: absolute; left: 16px; bottom: 64px; z-index: 1;
  padding: 8px 12px; background: var(--paper);
  border: 2px solid var(--ink); box-shadow: 3px 3px 0 var(--ink);
}
.desk-label h1 { margin: 0; font: 400 34px/1 var(--display); }
.desk-label p { margin: 2px 0 0; font-size: 12px; }
@media (max-width: 699px) {
  .desk-label { left: 12px; right: 12px; bottom: 56px; padding: 6px 10px; }
  .desk-label h1 { font-size: 26px; }
  .icons { bottom: 136px; }
}
