/* Shared window boundaries; every app's own layout starts at these edges. */
.window {
  --preview-terminal: #352542;
  --preview-code: #e4efdf;
  --preview-image: #faeac0;
  --app-paper: #e4edf7;
  --app-chrome: #d3dfed;
  --app-pane: #c8d8e9;
  --app-divider: #9bafc6;
  --app-edge: #92a8c2;
  --app-ink: #2f4967;
  --app-mark: #6d89a8;
  position: absolute;
  container: tile / size;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--app-edge);
  background: var(--app-paper);
  color: var(--app-ink);
  text-align: left;
}
:where(button).window:hover { border-color: var(--accent); }
.window.is-focused { border-color: #2e4868; z-index: 1; }
.window::after { content: ""; position: absolute; inset: 0; pointer-events: none; }
:where(button).window:hover::after { box-shadow: inset 0 0 0 1px var(--accent); }
.window.is-focused::after { box-shadow: inset 0 0 0 2px #2e4868; }
.window:focus-visible::after { outline: 2px dashed #2e4868; outline-offset: -5px; }
.window.pointer-focused:focus-visible,
.window.pointer-focused:focus-visible::after { outline: none; }
.screen .divider { z-index: 2; }

.app-ui, .app-compact { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.app-ui {
  --app-pad: clamp(5px, 4cqw, 13px);
  --app-row: clamp(16px, 14cqh, 25px);
  display: flex;
  flex-direction: column;
  font-size: clamp(8px, 5.5cqw, 11px);
  line-height: 1.35;
}
.app-compact { display: none; }
.app-bar, .app-rail {
  display: flex;
  gap: 5px;
  background: var(--app-chrome);
  white-space: nowrap;
  overflow: hidden;
}
.app-bar { flex: none; height: var(--app-row); align-items: center; padding-inline: 6px; border-bottom: 1px solid var(--app-divider); }
.app-tab {
  align-self: stretch;
  display: grid;
  align-items: center;
  padding-inline: 6px;
  background: var(--app-paper);
  border-inline: 1px solid var(--app-divider);
  font-weight: 650;
}
.app-rail { flex: none; flex-direction: column; border-right: 1px solid var(--app-divider); }
.app-rail > span { overflow: hidden; text-overflow: ellipsis; }
.app-current { background: #a9c0d9; font-weight: 650; }
.app-main { display: flex; flex: 1; min-width: 0; flex-direction: column; }
.app-line { display: block; height: 2px; flex-shrink: 0; background: var(--app-mark); opacity: .7; }

/* Terminal and editor: text runs in the primary pane, not in an inset drawing. */
.window[data-app="terminal"] {
  --app-paper: var(--preview-terminal);
  --app-edge: #735681;
  --app-ink: #f1dff7;
  --prompt: #d9b5ea;
}
.window[data-app="terminal"].is-focused::after { box-shadow: inset 0 0 0 2px var(--prompt); }
.window[data-app="terminal"]:focus-visible::after { outline-color: var(--app-ink); }
.terminal-log, .code-source { display: grid; align-content: start; font-family: ui-monospace, monospace; white-space: nowrap; }
.terminal-log { gap: .25em; padding: var(--app-pad); }
.terminal-log b { color: var(--prompt); }
.app-caret { display: inline-block; visibility: hidden; height: 1em; vertical-align: text-bottom; }
.window.is-focused .app-caret { visibility: visible; }
.terminal-cursor { width: .65em; background: var(--prompt); }
.code-cursor { width: max(1px, .12em); margin-left: 1px; background: currentColor; }
.window[data-app="code"] {
  --app-paper: var(--preview-code);
  --app-chrome: #c9ddc8;
  --app-divider: #9bb79d;
  --app-edge: var(--app-divider);
  --app-ink: #284438;
  --muted: #4a6352;
}
[data-app="code"] .app-ui, [data-app="image"] .app-ui { flex-direction: row; }
.code-tree, .files-tree {
  gap: 1px;
  width: clamp(40px, 28cqw, 124px);
  padding-block: 4px;
}
.code-tree > *, .files-tree > * { padding: 2px 5px; }
.code-tree .app-current { background: #b2d0b0; }
.code-source { gap: .25em; padding: var(--app-pad) 5px; }
.code-source b { color: #285f43; }
.code-source i { margin-right: .65em; color: var(--muted); font-style: normal; }

/* The selected Chrome tab joins the toolbar; inactive tabs sit in the recessed strip. */
.window[data-app="browser"] { --browser-toolbar: #dbe7f3; }
.browser-tabs {
  display: flex;
  flex: none;
  height: var(--app-row);
  align-items: stretch;
  gap: 4px;
  padding: 3px 6px 0;
  background: var(--app-pane);
  font-size: clamp(8px, 4.2cqw, 11px);
  white-space: nowrap;
}
.browser-tab {
  position: relative;
  display: flex;
  flex: 0 1 128px;
  min-width: 0;
  align-items: center;
  gap: 4px;
  padding-inline: 5px;
  color: var(--muted);
}
.browser-tab-active {
  flex-basis: 86px;
  min-width: 68px;
  border-radius: 6px 6px 0 0;
  background: var(--browser-toolbar);
  color: var(--app-ink);
  font-weight: 650;
}
.browser-tab-active::before, .browser-tab-active::after {
  --tab-corner: 3px;
  content: "";
  position: absolute;
  bottom: 0;
  width: var(--tab-corner);
  height: var(--tab-corner);
  background: radial-gradient(circle var(--tab-corner) at var(--tab-corner-origin) 0,
    transparent calc(100% - .5px), var(--browser-toolbar) 100%);
}
.browser-tab-active::before { right: 100%; --tab-corner-origin: 0%; }
.browser-tab-active::after { left: 100%; --tab-corner-origin: 100%; }
.browser-tab:not(.browser-tab-active) + .browser-tab::before {
  content: "";
  position: absolute;
  inset: 25% auto 25% -2px;
  border-left: 1px solid var(--app-divider);
}
.browser-tab-label {
  overflow: hidden;
  text-overflow: ellipsis;
}
.browser-tab-context { display: none; }
.browser-tab-icon, .browser-tab-close, .browser-tab-add { flex: none; width: 10px; }
.browser-tab-close { margin-left: auto; }
.browser-tab-add { align-self: center; width: 12px; }
.browser-toolbar { background: var(--browser-toolbar); }
.browser-address {
  min-width: 0;
  flex: 1;
  padding-inline: 5px;
  border: 1px solid var(--app-divider);
  border-radius: 999px;
  background: var(--app-paper);
  font-size: clamp(7px, 6.5cqw, 11px);
  overflow: hidden;
  text-overflow: ellipsis;
}
.browser-page { flex: 1; overflow: hidden; background: var(--paper); color: var(--ink); }
.browser-home {
  --home-gutter: clamp(5px, 4cqw, 16px);
  display: block;
  padding-inline: var(--home-gutter);
  line-height: 1.2;
}
.browser-home-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  padding-block: clamp(4px, 2.5cqw, 9px);
  border-bottom: 1px solid var(--rule);
}
.browser-home-header img { width: clamp(26px, 17cqw, 58px); }
.browser-home-nav {
  display: flex;
  gap: clamp(3px, 2cqw, 8px);
  font-size: clamp(6px, 2.5cqw, 9px);
  font-weight: 600;
}
.browser-home-nav b { color: var(--action); text-decoration: underline; }
.browser-home-hero {
  display: grid;
  grid-template-columns: minmax(0, 4fr) minmax(0, 5fr);
  align-items: center;
  gap: var(--home-gutter);
  padding-block: clamp(5px, 4cqw, 16px);
}
.browser-home-copy { display: grid; justify-items: start; gap: clamp(3px, 2cqw, 8px); }
.browser-home-title {
  max-inline-size: 15ch;
  font-size: clamp(8px, 5.4cqw, 19px);
  font-weight: 750;
  line-height: 1.1;
  letter-spacing: -.035em;
}
.browser-home-tagline { font-size: clamp(7px, 3cqw, 11px); font-weight: 650; }
.browser-home-install {
  padding: 2px clamp(3px, 1.5cqw, 6px);
  border-radius: 2px;
  background: var(--action);
  color: var(--paper);
  font-size: clamp(6px, 2.5cqw, 9px);
  white-space: nowrap;
}
.browser-home-monitors {
  justify-self: center;
  width: min(100%, max(18px, calc(100cqh - 2 * var(--app-row) - 76px)));
  background: radial-gradient(circle, #6a8fbd66 .5px, transparent .75px) center / 5px 5px;
}

.files-path { background: #dbe7f3; }
.files-body { display: flex; flex: 1; min-height: 0; }
.file-grid {
  display: grid;
  flex: 1;
  min-width: 0;
  grid-template-columns: repeat(auto-fit, minmax(min(32px, 100%), 1fr));
  align-content: start;
  gap: 8px 4px;
  padding: var(--app-pad) 4px;
  text-align: center;
}
.file-grid > span { overflow: hidden; text-overflow: ellipsis; }
.file-grid svg {
  display: block;
  width: min(100%, 28px);
  margin-inline: auto;
  fill: var(--app-pane);
  stroke: currentColor;
  stroke-width: .8;
}

/* The worksheet grid repeats at a fixed cell height even in a tall tile. */
.sheet-formula i { padding-inline: 4px; border-inline: 1px solid var(--app-divider); }
.sheet-grid {
  --cell-height: clamp(15px, 12cqh, 25px);
  --data-columns: 4;
  --column-pitch: calc(100% / var(--data-columns));
  flex: 1;
  overflow: hidden;
  background: repeating-linear-gradient(to bottom, transparent 0 calc(var(--cell-height) - 1px),
    var(--app-divider) calc(var(--cell-height) - 1px) var(--cell-height));
  position: relative;
}
.sheet-grid::after {
  content: "";
  position: absolute;
  inset: var(--cell-height) 0 0 16%;
  background: repeating-linear-gradient(to right, var(--app-divider) 0 1px,
    transparent 1px var(--column-pitch));
  pointer-events: none;
}
.sheet-row { display: grid; grid-template-columns: 16% repeat(var(--data-columns), minmax(0, 1fr)); height: var(--cell-height); }
.sheet-row > span { display: grid; align-items: center; padding-inline: 3px; white-space: nowrap; overflow: hidden; }
.sheet-row > :first-child, .sheet-head > span { background: var(--app-chrome); box-shadow: inset -1px -1px var(--app-divider); }
.sheet-row > :first-child, .sheet-head { text-align: center; }
.sheet-row:nth-child(3) > :nth-child(3) { background: #b8cde3; outline: 1px solid var(--accent); outline-offset: -2px; }

.window[data-app="image"] {
  --app-paper: var(--preview-image);
  --app-chrome: #ead19a;
  --app-divider: #b79762;
  --app-edge: var(--app-divider);
  --app-ink: #503619;
  --ridge-line: #8a5b25;
  --ridge-light: #fff3d1;
}
.image-tools { width: clamp(16px, 16cqw, 30px); align-items: center; padding-block: 4px; }
.image-canvas { position: relative; flex: 1; overflow: hidden; background: var(--app-chrome); }
.image-canvas svg { position: absolute; inset: 0; width: 100%; height: 100%; stroke: var(--ridge-line); }
.image-canvas :is(path, rect, circle) { vector-effect: non-scaling-stroke; }
.image-artboard { fill: var(--app-paper); stroke: none; }
.image-ridge { fill: #cf984c; }
.image-highlight { fill: var(--ridge-light); }
.image-guides path { stroke: #8a5b254a; }
.image-guides rect { stroke-dasharray: 3 2; }

[data-app="solitaire"] { background: #bacee3; }
[data-app="solitaire"] .app-ui { gap: var(--app-pad); padding: var(--app-pad); }
.card-row { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: clamp(2px, 2cqw, 8px); }
.playing-card, .card-slot {
  height: clamp(16px, 36cqh, 112px);
  padding: 2px;
  border: 1px solid #829dbc;
  border-radius: 3px;
  overflow: hidden;
  white-space: nowrap;
}
.playing-card { background: var(--app-paper); }
.card-back { background: #93b0d0; }
.card-slot { border-style: dashed; }

.notes-page { display: grid; align-content: start; gap: 7px; padding: var(--app-pad); flex: 1; }
.notes-page b { font-size: clamp(10px, 12cqh, 17px); }
.music-track { display: flex; align-items: center; flex: 1; min-height: 0; gap: var(--app-pad); padding-inline: var(--app-pad); overflow: hidden; }
.music-turntable {
  position: relative;
  flex: none;
  width: clamp(18px, min(39cqw, 42cqh), 126px);
  max-width: 100%;
  aspect-ratio: 100 / 78;
  border: 1px solid var(--app-divider);
  border-radius: 4px;
  background: var(--app-chrome);
}
.music-record {
  position: absolute;
  inset: 10% auto auto 7%;
  display: grid;
  place-items: center;
  width: 62%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: repeating-radial-gradient(circle closest-side, #27394e 0 8%, #394f68 8% 11%);
}
.music-record img {
  display: block;
  width: 40%;
  border: 1px solid #9ab1ca;
  border-radius: 50%;
  filter: grayscale(1) sepia(.35) hue-rotate(170deg) saturate(1.4);
}
.music-tonearm { position: absolute; inset: 0; width: 100%; height: 100%; }
.music-name { display: grid; white-space: nowrap; }
.music-wave { display: flex; flex: 1; height: 52%; align-items: end; justify-content: end; gap: 3px; }
.music-wave > span { width: clamp(1px, 1cqw, 6px); background: var(--app-mark); transform-origin: bottom; }
.music-controls { border-top: 1px solid var(--app-divider); border-bottom: 0; gap: var(--app-pad); }
.music-progress {
  position: relative;
  height: 10px;
  flex: 1;
  overflow: hidden;
  background: linear-gradient(var(--app-divider), var(--app-divider)) center / 100% 2px no-repeat;
}
.music-playhead {
  position: absolute;
  inset: 4px 0;
  background: var(--accent);
  transform: translateX(-65%);
}
.music-playhead::after {
  content: "";
  position: absolute;
  top: 50%;
  right: 0;
  width: 6px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--accent);
  transform: translate(50%, -50%);
}

@media (prefers-reduced-motion: no-preference) {
  .window.is-focused .app-caret { animation: caret-blink 1.1s step-end infinite; }
  .music-record { animation: record-spin 2.8s linear var(--music-delay) infinite; }
  .music-playhead { animation: track-progress 24s linear var(--music-delay) infinite; }
  .music-wave > span { animation: equalizer var(--beat) ease-in-out calc(var(--music-delay) - var(--beat-phase)) infinite alternate; }
}
@keyframes caret-blink {
  0%, 100% { opacity: 1; }
  52% { opacity: 0; }
}
@keyframes record-spin { to { transform: rotate(1turn); } }
@keyframes track-progress { from { transform: translateX(-100%); } to { transform: translateX(0); } }
@keyframes equalizer {
  0%, 100% { transform: scaleY(.28); }
  36% { transform: scaleY(1); }
  72% { transform: scaleY(.52); }
}

.calendar-bar { justify-content: space-between; }
.calendar-days { display: grid; flex: 1; min-height: 0; grid-template-columns: repeat(7, minmax(0, 1fr)); grid-auto-rows: minmax(12px, 1fr); overflow: hidden; }
.calendar-days > span { display: grid; place-items: center; box-shadow: inset -1px -1px var(--app-divider); }
.calendar-days > :nth-child(-n + 7) { background: #dbe7f3; font-weight: 650; }

/* Compact panes keep the recognizable parts and drop secondary controls. */
@container tile (width >= 380px) {
  .browser-tab-active { flex: 0 0 165px; }
  .browser-tab-context { display: inline; }
}
@container tile (width < 180px) {
  .browser-tab:nth-child(3) { display: none; }
}
@container tile (width < 140px) {
  .browser-tab:not(.browser-tab-active) { flex: 0 0 20px; justify-content: center; }
  .browser-tab:not(.browser-tab-active) .browser-tab-label { display: none; }
}
@container tile (width < 122px) {
  .browser-tab-close, .browser-tab-add, .browser-toolbar > span { display: none; }
  .browser-tab-active { min-width: 0; }
  .browser-toolbar { padding-inline: 2px; }
  .browser-address { padding-inline: 3px; }
}
@container tile (width < 86px) {
  .browser-tab:not(.browser-tab-active) { display: none; }
  .browser-tabs { padding-inline: 4px; }
  .browser-tab-active { gap: 3px; padding-inline: 3px; }
}
@container tile (width < 190px) or (height < 160px) or (aspect-ratio > 2) {
  .browser-home-nav, .browser-home-tagline { display: none; }
  .browser-home-header { padding-block: 3px; }
  .browser-home-header img { max-width: 42px; }
  .browser-home-hero { padding-block: 4px; }
  .browser-home-title { font-size: clamp(7px, min(5.4cqw, 8.5cqh), 15px); }
  .browser-home-monitors {
    width: min(100%, max(18px, calc(100cqh - 2 * var(--app-row) - 32px)));
  }
}
@container tile (height < 77px) {
  .browser-home-header { padding-block: 2px; }
  .browser-home-header img { max-width: 26px; }
  .browser-home-hero { grid-template-columns: minmax(0, 1fr) auto; padding-block: 2px; }
  .browser-home-title { max-inline-size: none; font-size: 7px; }
  .browser-home-install { display: none; }
  .browser-home-monitors { width: 20px; }
}
@container tile (width < 100px) {
  .browser-home-copy { display: none; }
  .browser-home-hero { grid-template-columns: minmax(0, 1fr); }
}
@container tile (height < 54px) {
  .browser-home-hero, .browser-tabs { display: none; }
}
@container tile (aspect-ratio < 1) and (height >= 104px) {
  .music-track { flex-direction: column; justify-content: center; text-align: center; }
  .music-turntable { width: clamp(26px, min(86cqw, 42cqh), 126px); }
  .music-name { white-space: normal; }
  .music-wave { flex: none; width: 100%; height: clamp(12px, 17cqh, 44px); justify-content: center; gap: 2px; }
}
@container tile (width < 93px) {
  .code-tree, .files-tree { display: none; }
  .sheet-grid { --data-columns: 2; }
  .sheet-row > :nth-child(n + 4) { display: none; }
  .file-grid svg { width: min(100%, 18px); }
  .files-path > :last-child { overflow: hidden; text-overflow: ellipsis; }
}
@container tile (height < 72px) {
  .card-deal, .music-controls, .sheet-formula { display: none; }
}
@container tile (height < 38px) {
  .notes-page { gap: 3px; padding-block: 2px; }
  .calendar-days { grid-auto-rows: minmax(9px, 1fr); font-size: 7px; }
}
@container tile (width < 46px) or (height < 18px) {
  .app-ui { display: none; }
  .app-compact { display: flex; justify-content: center; align-items: center; gap: 4px; }
  .app-compact svg { flex: none; width: min(15px, 50cqw, 76cqh); }
  .app-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 9px; }
}
@container tile (width < 82px) or (height < 13px) {
  .app-name { display: none; }
}
