/* ---------- Tokens ---------- */
:root {
  --ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Menlo, monospace;
  --accent: #3b5bff;
  --win-bg: rgba(255, 255, 255, .92);
  --win-bar: rgba(246, 246, 248, .9);
  --win-text: #1d1d1f;
  --win-muted: #6e6e73;
  --win-line: rgba(0, 0, 0, .1);
  --chip: #f2f2f5;
  --shadow: 0 24px 60px -12px rgba(0, 0, 0, .45), 0 0 0 .5px rgba(0, 0, 0, .25);
  --menubar-h: 30px;
  --dock-h: 76px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --win-bg: rgba(30, 30, 34, .94);
    --win-bar: rgba(42, 42, 48, .92);
    --win-text: #f2f2f5;
    --win-muted: #a1a1aa;
    --win-line: rgba(255, 255, 255, .1);
    --chip: #34343b;
    --accent: #7d93ff;
  }
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; overflow: hidden; font: 14px/1.5 var(--ui); color: #fff;
  -webkit-font-smoothing: antialiased; background: #1e1e1e;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
button.btn { border: 0; cursor: pointer; font-family: var(--ui); }
a { color: inherit; }
img { display: block; max-width: 100%; }

/* ---------- Wallpaper ---------- */
.desktop {
  position: fixed; inset: 0; padding: calc(var(--menubar-h) + 16px) 16px calc(var(--dock-h) + 16px);
  background: #1e1e1e url("../img/wallpaper.png") center / cover no-repeat;
}
.desktop__tag {
  position: absolute; right: 24px; bottom: calc(var(--dock-h) + 20px); margin: 0;
  font: 12px var(--mono); color: rgba(255, 255, 255, .45); pointer-events: none;
}

/* ---------- Menu bar ---------- */
.menubar {
  position: fixed; inset: 0 0 auto; height: var(--menubar-h); z-index: 9000;
  display: flex; align-items: center; justify-content: space-between; padding: 0 14px;
  background: rgba(20, 20, 20, .55); backdrop-filter: blur(20px) saturate(1.6); -webkit-backdrop-filter: blur(20px) saturate(1.6);
  font-size: 13px; border-bottom: .5px solid rgba(255, 255, 255, .08);
}
.menubar__left, .menubar__right { display: flex; align-items: center; gap: 18px; min-width: 0; }
.menubar__logo { display: grid; place-items: center; width: 22px; height: 22px; }
.menubar__logo svg { width: 16px; height: 16px; fill: none; stroke: #fff; stroke-width: 1.8; stroke-linecap: round; }
.menubar__logo circle { fill: #fff; stroke: none; }
.menubar__app { color: rgba(255, 255, 255, .75); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.menubar__right a { text-decoration: none; color: rgba(255, 255, 255, .85); }
.menubar__right a:hover { color: #fff; }
.menubar time { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- Desktop icons ---------- */
.icons {
  position: relative; z-index: 1; list-style: none; margin: 0; padding: 0;
  display: grid; grid-auto-flow: column; grid-template-rows: repeat(auto-fill, 104px); grid-auto-columns: 96px;
  gap: 4px 8px; height: 100%; width: max-content;
}
.icon {
  text-decoration: none; color: inherit;
  width: 96px; padding: 8px 4px 6px; border-radius: 8px;
  display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center;
}
.icon:hover { background: rgba(255, 255, 255, .1); }
.icon:focus-visible { outline: 2px solid var(--accent); outline-offset: 0; background: rgba(255, 255, 255, .14); }
.icon__art { width: 56px; height: 56px; display: grid; place-items: center; }
.icon__art svg { width: 100%; height: 100%; filter: drop-shadow(0 4px 8px rgba(0, 0, 0, .3)); }
.icon__art img {
  width: 52px; height: 52px; object-fit: cover; border-radius: 4px;
  border: 3px solid #fff; box-shadow: 0 4px 10px rgba(0, 0, 0, .35);
}
.icon__label {
  font-size: 12px; line-height: 1.25; color: #fff; text-shadow: 0 1px 3px rgba(0, 0, 0, .7);
  max-width: 100%; overflow-wrap: break-word;
}

/* ---------- Windows ---------- */
.win {
  position: absolute; display: flex; flex-direction: column; min-width: 300px; min-height: 200px;
  max-width: calc(100vw - 16px); max-height: calc(100vh - var(--menubar-h) - var(--dock-h) - 16px);
  background: var(--win-bg); color: var(--win-text); border-radius: 12px; box-shadow: var(--shadow);
  backdrop-filter: blur(30px); -webkit-backdrop-filter: blur(30px);
  overflow: hidden; resize: both; animation: win-open .18s ease-out;
}
.win[hidden] { display: none; }
.win.is-inactive { --shadow: 0 16px 40px -12px rgba(0, 0, 0, .35), 0 0 0 .5px rgba(0, 0, 0, .2); }
.win.is-inactive .win__title { opacity: .55; }
.win.is-max {
  left: 0 !important; top: var(--menubar-h) !important; width: 100vw !important;
  height: calc(100vh - var(--menubar-h) - var(--dock-h)) !important; max-height: none; border-radius: 0; resize: none;
}
@keyframes win-open { from { opacity: 0; transform: scale(.96); } }

.win__bar {
  position: relative; flex: none; height: 40px; display: flex; align-items: center; justify-content: center;
  background: var(--win-bar); border-bottom: .5px solid var(--win-line); cursor: grab; user-select: none; touch-action: none;
}
.win__bar:active { cursor: grabbing; }
.win__btns { position: absolute; left: 14px; display: flex; gap: 8px; }
.win__btn { width: 12px; height: 12px; border-radius: 50%; position: relative; }
.win__btn--close { background: #ff5f57; }
.win__btn--min { background: #febc2e; }
.win__btn--max { background: #28c840; }
.win.is-inactive .win__btn { background: var(--chip); }
.win__btn::after {
  content: ""; position: absolute; inset: 0; border-radius: 50%; opacity: 0;
  background: center / 8px no-repeat; transition: opacity .1s;
}
.win__btns:hover .win__btn::after { opacity: 1; }
.win__btn--close::after { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8'%3E%3Cpath d='M1.5 1.5l5 5M6.5 1.5l-5 5' stroke='%234d0000' stroke-width='1.3'/%3E%3C/svg%3E"); }
.win__btn--min::after { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8'%3E%3Cpath d='M1 4h6' stroke='%23995700' stroke-width='1.3'/%3E%3C/svg%3E"); }
.win__btn--max::after { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8'%3E%3Cpath d='M1.5 4h5M4 1.5v5' stroke='%23006500' stroke-width='1.3'/%3E%3C/svg%3E"); }
.win__title { font-size: 13px; font-weight: 600; display: flex; align-items: center; gap: 6px; max-width: 60%; }
.win__title span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.win__title svg, .win__title img { width: 16px; height: 16px; flex: none; border-radius: 2px; object-fit: cover; }
.win__body { flex: 1; overflow: auto; overscroll-behavior: contain; }

/* Folder view */
.win__body:has(> .folder) { display: flex; flex-direction: column; }
.folder { flex: 1; display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 4px; padding: 16px; align-content: start; }
.folder .icon:hover { background: var(--chip); }
.folder .icon__label { color: var(--win-text); text-shadow: none; }
.folder__status {
  position: sticky; bottom: 0; padding: 6px 16px; font-size: 12px; color: var(--win-muted);
  border-top: .5px solid var(--win-line); background: var(--win-bar);
}

/* Document view */
.doc { padding: 28px 32px 36px; max-width: 680px; font-size: 15px; line-height: 1.65; }
.doc h1 { font-size: 26px; line-height: 1.2; margin: 0 0 10px; letter-spacing: -.01em; }
.doc h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--win-muted); margin: 28px 0 8px; }
.doc p { margin: 0 0 14px; }
.doc ul, .doc ol { margin: 0 0 14px; padding-left: 20px; }
.doc li { margin-bottom: 8px; }
.doc .lead { font-size: 17px; color: var(--win-muted); }
.doc .kicker { font: 12px var(--mono); color: var(--accent); margin-bottom: 8px; }
.doc .hint, .doc .note { font-size: 13px; color: var(--win-muted); }
.doc .note { padding: 10px 14px; border-radius: 8px; background: var(--chip); }
.doc code { font: 13px var(--mono); padding: 1px 6px; border-radius: 4px; background: var(--chip); }
.doc blockquote { margin: 20px 0; padding-left: 16px; border-left: 3px solid var(--accent); font-size: 17px; font-style: italic; }
.doc a { color: var(--accent); }
.inline-link { color: var(--accent); text-decoration: underline; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 20px; margin: 20px 0; padding: 16px; border-radius: 10px; background: var(--chip); }
.facts dt { color: var(--win-muted); font-size: 13px; }
.facts dd { margin: 0; font-size: 14px; }
.timeline { list-style: none; padding: 0 !important; }
.timeline li { display: grid; grid-template-columns: 140px 1fr; gap: 16px; padding: 12px 0; margin: 0; border-bottom: .5px solid var(--win-line); }
.timeline span { font: 12px/1.8 var(--mono); color: var(--win-muted); }
.timeline strong, .timeline em { display: block; }
.timeline em { font-style: normal; color: var(--win-muted); font-size: 13px; margin-bottom: 2px; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tags span { padding: 3px 10px; border-radius: 999px; font-size: 13px; background: var(--chip); }
.contact { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 20px; }
.btn {
  display: inline-block; padding: 9px 16px; border-radius: 8px; font-size: 14px; font-weight: 500;
  text-decoration: none; color: var(--win-text) !important; background: var(--chip);
}
.btn--primary { background: var(--accent); color: #fff !important; }
.btn:hover { filter: brightness(1.08); }

/* Image viewer */
.viewer { margin: 0; display: flex; flex-direction: column; height: 100%; background: #111; }
.viewer img { flex: 1; min-height: 0; width: 100%; object-fit: contain; }
.viewer p { margin: 0; padding: 10px 16px; font-size: 13px; color: #ddd; background: #1a1a1a; }

/* Photos app */
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; padding: 6px; }
.photos button { aspect-ratio: 1; overflow: hidden; border-radius: 4px; }
.photos img { width: 100%; height: 100%; object-fit: cover; transition: transform .3s; }
.photos button:hover img { transform: scale(1.05); }

/* PDF */
.win__body--pdf { display: flex; flex-direction: column; overflow: hidden; }
.pdfbar {
  display: flex; align-items: center; gap: 16px; padding: 8px 14px; font-size: 13px;
  background: var(--win-bar); border-bottom: .5px solid var(--win-line);
}
.pdfbar span { margin-right: auto; color: var(--win-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pdfbar a { color: var(--accent); text-decoration: none; white-space: nowrap; }
.pdf { flex: 1; width: 100%; border: 0; display: block; background: #525659; }

/* Compose */
.compose { position: relative; display: flex; flex-direction: column; height: 100%; }
.compose__row {
  display: flex; align-items: center; gap: 10px; padding: 10px 16px;
  border-bottom: .5px solid var(--win-line); font-size: 14px;
}
.compose__row span { width: 56px; color: var(--win-muted); flex: none; }
.compose input, .compose textarea {
  flex: 1; min-width: 0; font: 15px/1.5 var(--ui); color: var(--win-text); background: none; border: 0; outline: 0;
}
.compose textarea { padding: 14px 16px; resize: none; min-height: 140px; }
.compose__copy { flex: none; padding: 4px 10px; border-radius: 6px; font-size: 13px; color: var(--accent); background: var(--chip); }
.compose__copy:hover { filter: brightness(1.08); }
.compose__trap { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }
.compose__status { flex: 1; margin: 0; font-size: 13px; color: var(--win-muted); }
.compose__status[data-kind="error"] { color: #e5484d; }
.compose button.btn { padding: 9px 22px; }
.compose button.btn:disabled { opacity: .6; cursor: default; }
.compose__send {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px;
  border-top: .5px solid var(--win-line); background: var(--win-bar);
}

.muted { color: var(--win-muted); }

/* Notifications */
#toasts {
  position: fixed; top: calc(var(--menubar-h) + 10px); right: 12px; z-index: 100000;
  display: flex; flex-direction: column; gap: 10px; width: min(360px, calc(100vw - 24px));
}
.toast {
  display: flex; align-items: flex-start; gap: 12px; padding: 12px 14px; border-radius: 14px;
  background: var(--win-bg); color: var(--win-text); box-shadow: var(--shadow);
  backdrop-filter: blur(30px); -webkit-backdrop-filter: blur(30px);
  animation: toast-in .25s ease-out;
}
.toast.is-leaving { animation: toast-out .2s ease-in forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateX(24px); } }
@keyframes toast-out { to { opacity: 0; transform: translateX(24px); } }
.toast__icon { flex: none; width: 22px; height: 22px; margin-top: 1px; border-radius: 50%; background: #28c840 center / 12px no-repeat; }
.toast[data-kind="ok"] .toast__icon { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 6.2l2.3 2.3 4.7-5' fill='none' stroke='%23fff' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); }
.toast[data-kind="error"] .toast__icon { background-color: #e5484d; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M6 2.5v4.2M6 9.2v.1' fill='none' stroke='%23fff' stroke-width='1.8' stroke-linecap='round'/%3E%3C/svg%3E"); }
.toast[data-kind="sending"] .toast__icon { background: none; border: 2.5px solid var(--chip); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast__text { flex: 1; min-width: 0; font-size: 13px; line-height: 1.4; }
.toast__text strong { display: block; font-size: 14px; margin-bottom: 2px; }
.toast__text p { margin: 0; color: var(--win-muted); overflow-wrap: anywhere; }
.toast__actions { display: flex; gap: 8px; margin-top: 10px; }
.toast__actions button { padding: 5px 12px; border-radius: 7px; font-size: 13px; color: var(--accent); background: var(--chip); }
.toast__actions button:hover { filter: brightness(1.08); }
.toast__close { flex: none; width: 20px; height: 20px; border-radius: 50%; font-size: 15px; line-height: 1; color: var(--win-muted); }
.toast__close:hover { background: var(--chip); }

/* Terminal */
.term {
  min-height: 100%; padding: 14px 16px; background: #0d1117; color: #c9d1d9;
  font: 13px/1.6 var(--mono); cursor: text;
}
.term__out { white-space: pre-wrap; word-break: break-word; margin: 0; font: inherit; }
.term__line { display: flex; gap: 8px; }
.term__prompt { color: #3fb950; flex: none; }
.term__prompt b { color: #79c0ff; font-weight: 400; }
.term input { flex: 1; min-width: 0; font: inherit; color: inherit; background: none; border: 0; outline: 0; caret-color: #3fb950; }
.term .t-accent { color: #79c0ff; }
.term .t-dim { color: #8b949e; }
.term .t-err { color: #ff7b72; }
.term .t-ok { color: #3fb950; }
.term .t-banner { display: block; margin: 4px 0 14px; color: #79c0ff; font: 12px/1.05 var(--mono); white-space: pre; overflow: hidden; }
.term .t-banner--agent { color: #3fb950; margin-bottom: 6px; }
.term strong { color: #fff; }
.t-cmd {
  font: inherit; color: #79c0ff; text-decoration: underline; text-decoration-color: rgba(121, 192, 255, .35);
  text-underline-offset: 3px; cursor: pointer;
}
.t-cmd:hover { color: #a5d6ff; text-decoration-color: currentColor; }
.t-cmd.t-file { color: #c9d1d9; text-decoration-color: #484f58; }
.t-cmd.t-file:hover { color: #fff; }
.t-src { font: inherit; color: #c9d1d9; text-decoration: underline; text-decoration-color: #484f58; text-underline-offset: 3px; cursor: pointer; }
.t-src:hover { color: #fff; }
@media (max-width: 700px) { .term .t-banner { font-size: 7px; } .term { font-size: 12px; } }
.term a { color: #79c0ff; }

/* Arm controller: the UR7e viewer (its terminal is a normal .term window) */
.win__body--armview { overflow: hidden; }
.armview { position: relative; height: 100%; background: radial-gradient(120% 90% at 50% 25%, #353c46, #15181d 75%); }
.armview canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: grab; }
.armview canvas:active { cursor: grabbing; }
.armview__status { position: absolute; inset: 0; display: grid; place-items: center; margin: 0; padding: 24px; text-align: center; font: 13px var(--mono); color: #8b949e; }
.armview__status[hidden] { display: none; }
.armview__joints, .armview__hint { position: absolute; margin: 0; pointer-events: none; font: 11px/1.5 var(--mono); color: #8b949e; }
.armview__joints { left: 12px; bottom: 10px; color: #c9d1d9; white-space: pre; text-shadow: 0 1px 2px #000; }
.armview__hint { right: 12px; bottom: 10px; text-align: right; }
.term__line[hidden] { display: none; }
@media (max-width: 700px) {
  .win.win--stack-top { height: 42% !important; }
  .win.win--stack-bottom { top: calc(var(--menubar-h) + 42%) !important; height: calc(58% - var(--menubar-h) - var(--dock-h)) !important; }
  .armview__hint { display: none; }
  .armview__joints { font-size: 10px; }
}

/* ---------- Dock ---------- */
.dock {
  position: fixed; left: 50%; bottom: 10px; transform: translateX(-50%); z-index: 9000;
  display: flex; align-items: flex-end; gap: 6px; padding: 6px 8px;
  background: rgba(255, 255, 255, .14); border: .5px solid rgba(255, 255, 255, .2); border-radius: 18px;
  backdrop-filter: blur(24px) saturate(1.6); -webkit-backdrop-filter: blur(24px) saturate(1.6);
}
.dock__item { position: relative; width: 52px; height: 52px; transition: transform .15s ease; }
.dock__item:hover { transform: translateY(-6px) scale(1.12); }
.dock__item svg, .dock__item img { width: 100%; height: 100%; }
.dock__item.is-open::after {
  content: ""; position: absolute; left: 50%; bottom: -5px; width: 4px; height: 4px; margin-left: -2px;
  border-radius: 50%; background: rgba(255, 255, 255, .85);
}
.dock__tip {
  position: absolute; bottom: calc(100% + 12px); left: 50%; transform: translateX(-50%);
  padding: 4px 10px; border-radius: 6px; font-size: 12px; white-space: nowrap; pointer-events: none;
  background: rgba(30, 30, 34, .9); color: #fff; opacity: 0; transition: opacity .12s;
}
.dock__item:hover .dock__tip, .dock__item:focus-visible .dock__tip { opacity: 1; }
/* icons for open windows that aren't kept in the dock grow in, and shrink away when closed */
.dock__item--running { animation: dock-in .22s ease-out; }
.dock__item--running.is-leaving { animation: dock-out .22s ease-in forwards; pointer-events: none; }
@keyframes dock-in { from { width: 0; margin: 0 -3px; transform: scale(.2); opacity: 0; } }
@keyframes dock-out { to { width: 0; margin: 0 -3px; transform: scale(.2); opacity: 0; } }
.dock__sep { width: 1px; align-self: stretch; margin: 4px 4px; background: rgba(255, 255, 255, .25); }

/* ---------- Boot ---------- */
.boot {
  position: fixed; inset: 0; z-index: 10000; background: #000; color: #d4d4d4;
  padding: 20px 24px; font: 14px/1.7 var(--mono); cursor: pointer; transition: opacity .4s;
}
.boot.is-done { opacity: 0; pointer-events: none; }
.boot__log { margin: 0; font: inherit; white-space: pre-wrap; }
.boot__log .ok { color: #3fb950; }
.boot__log .wait { color: #d29922; }
.boot__hint { position: absolute; bottom: 20px; left: 24px; margin: 0; color: #555; font-size: 12px; }

.noscript { position: fixed; inset: 0; z-index: 20000; padding: 40px 24px; background: #0b1020; font-size: 16px; }

/* ---------- Mobile: phone-style home screen, full-screen windows ---------- */
@media (max-width: 700px) {
  :root { --dock-h: 84px; }
  .menubar__name, .menubar__right a { display: none; }
  .icons {
    grid-auto-flow: row; grid-template-rows: none; grid-template-columns: repeat(4, 1fr);
    grid-auto-columns: auto; width: 100%; height: auto; gap: 10px 4px;
  }
  .icon { width: auto; }
  .icon__label { font-size: 11px; }
  .desktop__tag { display: none; }
  .win, .win.is-max {
    left: 0 !important; top: var(--menubar-h) !important; width: 100vw !important;
    height: calc(100% - var(--menubar-h) - var(--dock-h)) !important; max-height: none;
    border-radius: 0; resize: none; min-width: 0;
  }
  .win__bar { cursor: default; }
  .win__btn { width: 14px; height: 14px; }
  .win__btn--min, .win__btn--max { display: none; }
  .doc { padding: 22px 18px 32px; }
  .timeline li { grid-template-columns: 1fr; gap: 2px; }
  .dock { width: calc(100% - 16px); justify-content: space-around; bottom: 8px; }
  .dock__item { width: 48px; height: 48px; }
  .dock__sep, .dock__item--extra, .dock__item--running { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .win { animation: none; }
  .dock__item, .photos img { transition: none; }
  .dock__item--running, .dock__item--running.is-leaving { animation-duration: 1ms; }
}
