@import url("icons.css");
@import url("code.css");

/* Shared chrome for ClackOS applications — self-contained pages under
   content/<menu>/ that run standalone or inside a ClackOS window (iframe). */
:root {
  color-scheme: only light;
  --ink: #09140d;
  --heading: #09140d;
  --ink-soft: #14231a;
  --control-text: var(--ink-soft);
  --strong-text: var(--ink-soft);
  --shadow: var(--ink);
  --shadow-distance: 8px;
  --shadow-alpha: 40%;
  --paper: #f8f2dd;
  --paper-deep: #f3ecd1;
  --paper-line: #d8cfa9;
  --sage: #66755a;
  --leaf: #4fae7d;
  --leaf-deep: #276b47;
  --menu-text: #f5efdb;
  --menu-dim: #8fcaa8;
  --desktop: #e3ddc6;
  --titlebar: var(--ink);
  --window-border: var(--ink);
  --window-inactive: #2a3b2f;
  --window-border-inactive: var(--window-inactive);
  --title-text: #c8e3d2;
  --title-text-inactive: var(--title-text);
  --accent-hover: #6fcf9a;
  --button-text: #f2ecd6;
  --disabled-text: #b3ab8d;
  /* Status, scrim and series roles — see clackos.css for what each is for.
     Repeated here because a standalone app page never loads clackos.css and
     would otherwise have no fallback before the desktop injects a theme. */
  --danger: #a04a3a;
  --warning: #b58b3a;
  --ok: var(--leaf-deep);
  --info: #3f66ad;
  --overlay: color-mix(in srgb, var(--shadow) 42%, transparent);
  --overlay-strong: color-mix(in srgb, var(--shadow) 82%, transparent);
  --series-1: var(--leaf-deep);
  --series-2: var(--danger);
  --series-3: var(--info);
  --series-4: var(--warning);
  --series-5: var(--sage);
  --series-6: var(--leaf);
  --media-grayscale: 0%;
  --media-sepia: 0%;
  --media-saturate: 100%;
  --media-hue: 0deg;
  --media-brightness: 100%;
  --media-contrast: 100%;
  --media-filter: none;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12.5px;
  color: var(--ink-soft);
  background: var(--paper);
}
:where(img, video, canvas):not([data-media-treatment="none"]) {
  filter: var(--media-filter);
}
.app { display: flex; flex-direction: column; min-height: 100%; }
.app-main { padding: 20px 26px; display: flex; flex-direction: column; gap: 16px; flex: 1; }

/* ---- buttons ---- */
.btn {
  all: unset; cursor: pointer; font: inherit; font-size: 12.5px; font-weight: 500;
  padding: 9px 20px; border-radius: 6px; border: 1px solid var(--ink);
  background: var(--paper); color: var(--control-text);
}
.btn:focus-visible { outline: 2px solid var(--leaf); outline-offset: 2px; }
.btn.primary { background: var(--ink); color: var(--button-text); }
.btn.primary:hover { background: var(--leaf-deep); border-color: var(--leaf-deep); }
.btn.ghost:hover { background: var(--paper-deep); }

/* ---- inputs ---- */
input[type="text"], select {
  font: inherit; font-size: 12.5px; color: var(--control-text); background: var(--paper-deep);
  border: 1px solid var(--ink); border-radius: 6px; padding: 6px 10px;
}
input[type="text"]:focus-visible, select:focus-visible {
  outline: 2px solid var(--leaf); outline-offset: 1px;
}
input[type="range"] { accent-color: var(--leaf-deep); }

/* ---- in-app menu bar ---- */
/* The bar wraps rather than running off the side. A phone-width window is
   narrower than most apps' bars — ClackPaint loses Image and Effects, Pure Data
   loses everything past Put — and a flex row that does not wrap gives no way
   back to those menus: they are not scrolled off, they are simply gone. Wrapping
   costs a second row only when there was no room for one, so nothing about the
   bar changes on a desktop. */
.rm-bar {
  display: flex; flex-wrap: wrap; gap: 2px; padding: 0 8px;
  background: var(--paper-deep); border-bottom: 1px solid var(--paper-line);
}
.rm { position: relative; }
.rm > button {
  all: unset; cursor: pointer; padding: 8px 12px; font: inherit; font-size: 12px; color: var(--control-text);
}
.rm > button:hover, .rm.open > button { background: var(--ink); color: var(--menu-text); }
.rm > button:focus-visible { outline: 2px solid var(--leaf); outline-offset: -2px; }
/* A dropdown opens under its own button, so a menu far along the bar would hang
   off the right of a phone screen — assets/js/app-menu.js shifts an open one
   back inside the bar. The max-width is the floor under that: a dropdown wider
   than the screen cannot be shifted anywhere useful, so it is narrowed instead. */
.rm-dd {
  position: absolute; top: 100%; left: 0; min-width: 240px; z-index: 20;
  max-width: calc(100vw - 16px);
  background: var(--paper); border: 2px solid var(--ink); border-radius: 0 0 8px 8px;
  display: none; padding: 6px 2px;
}
/* a child selector, so a nested .rm-dd submenu is not dragged open along
 * with the menu that contains it */
.rm.open > .rm-dd { display: block; }
/* menu items are buttons, except the "Open app in new tab" link ClackOS adds
 * to an app running in a window — a real link, so it can be middle-clicked or
 * copied like any other */
.rm-dd button, .rm-dd a {
  all: unset; box-sizing: border-box; display: flex; align-items: center; width: 100%; cursor: pointer;
  gap: 8px; padding: 7px 14px; font: inherit; font-size: 12px; color: var(--control-text); white-space: nowrap;
}
.rm-dd .pixel-icon { width: 16px; height: 16px; }
.rm-dd button:hover:not(:disabled), .rm-dd a:hover { background: var(--ink); color: var(--menu-text); }
.rm-dd button:disabled { color: var(--disabled-text); cursor: default; }
.rm-dd a:focus-visible { outline: 2px solid var(--leaf); outline-offset: -2px; }
.rm-dd .sep { height: 1px; background: var(--paper-line); margin: 6px 0; }

.app-lbl {
  font-size: 11px; font-weight: 600; letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--leaf-deep);
}
.app-status { font-size: 11.5px; color: var(--sage); line-height: 1.7; }
.app-panel {
  border: 1px solid var(--ink); border-radius: 6px; background: var(--paper-deep);
  padding: 12px 14px; font-size: 11.5px; line-height: 1.8; color: var(--ink-soft);
}

/* ---- sound recorder ---- */
.rec-top { display: flex; gap: 14px; align-items: stretch; }
.rec-counter { display: flex; flex-direction: column; gap: 6px; min-width: 92px; }
.rec-pos, .rec-len {
  font-size: 13px; color: var(--control-text); background: var(--paper-deep);
  border: 1px solid var(--ink); border-radius: 6px; padding: 8px 10px;
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.rec-scope { flex: 1; min-width: 120px; border: 1px solid var(--ink); border-radius: 6px; background: var(--ink); }
.rec-seek { width: 100%; }
.rec-btns { display: flex; flex-wrap: wrap; gap: 10px; }
.rec-btns .pixel-icon { width: 17px; height: 17px; }
.rec-record { color: var(--danger); }

/* ---- paint ---- */
.paint-app { height: 100%; min-height: 0; }
.paint-main { display: flex; gap: 14px; padding: 14px; flex: 1; min-height: 0; }
.paint-tools {
  display: grid; grid-template-columns: repeat(2, 36px); grid-auto-rows: minmax(36px, auto); gap: 6px;
  align-content: start; flex: none; max-height: 100%; overflow-x: hidden; overflow-y: auto;
  scrollbar-width: thin;
}
.paint-tool {
  all: unset; cursor: pointer; display: flex; align-items: center; justify-content: center;
  font-size: 15px; border: 1px solid var(--ink); border-radius: 6px;
  background: var(--paper); color: var(--control-text);
}
.paint-tool:hover { background: var(--paper-deep); }
.paint-tool.active { background: var(--ink); color: var(--menu-text); }
.paint-tool:focus-visible { outline: 2px solid var(--leaf); outline-offset: 1px; }
.paint-tool .pixel-icon { width: 21px; height: 21px; }
.paint-zoom-icon {
  position: relative; display: block; width: 13px; height: 13px;
  border: 2px solid currentColor; border-radius: 50%; box-sizing: border-box;
}
.paint-zoom-icon::after {
  content: ""; position: absolute; width: 8px; height: 2px; right: -7px; bottom: -4px;
  background: currentColor; transform: rotate(45deg); transform-origin: left center;
}
.paint-size { grid-column: span 2; display: flex; flex-direction: column; gap: 4px; margin-top: 6px; }
.paint-size input { width: 100%; }
.paint-canvas-wrap {
  flex: 1; overflow: auto; min-width: 0; min-height: 0; padding: 8px;
  background-color: var(--paper-deep);
  background-image: linear-gradient(45deg, var(--paper-line) 25%, transparent 25%), linear-gradient(-45deg, var(--paper-line) 25%, transparent 25%), linear-gradient(45deg, transparent 75%, var(--paper-line) 75%), linear-gradient(-45deg, transparent 75%, var(--paper-line) 75%);
  background-position: 0 0, 0 4px, 4px -4px, -4px 0; background-size: 8px 8px;
}
.paint-stack {
  position: relative; width: 640px; height: 400px;
  box-sizing: content-box; border: 1px solid var(--ink); background: #fff; cursor: crosshair; touch-action: none;
}
.paint-stack canvas { position: absolute; inset: 0; width: 100%; height: 100%; image-rendering: pixelated; }
.paint-stack .overlay, .paint-stack .seam-animation { pointer-events: none; }
.paint-stack.checking-seams { cursor: crosshair; }
.paint-stack.zoom-tool { cursor: zoom-in; }
.paint-brush-cursor {
  position: absolute; z-index: 4; box-sizing: border-box; border: 1px solid #fff;
  border-radius: 50%; box-shadow: 0 0 0 1px #000; pointer-events: none;
}
.paint-brush-cursor.mirrored { opacity: .7; }
.paint-bottom { display: flex; align-items: center; gap: 9px; padding: 3px 12px 5px; flex-wrap: nowrap; overflow-x: auto; }
.paint-current { position: relative; width: 30px; height: 30px; flex: none; }
.paint-current .fg, .paint-current .bg {
  position: absolute; width: 19px; height: 19px; border: 1px solid var(--ink); border-radius: 3px;
}
.paint-current .bg { right: 0; bottom: 0; }
.paint-current .fg { left: 0; top: 0; z-index: 1; }
.paint-palette { display: grid; grid-template-columns: repeat(28, 16px); grid-auto-rows: 16px; gap: 2px; flex: none; }
.paint-swatch {
  all: unset; cursor: pointer; border: 1px solid var(--ink); border-radius: 3px;
}
.paint-swatch:focus-visible { outline: 2px solid var(--leaf); outline-offset: 1px; }
.paint-status { padding: 0 12px 5px; font-size: 11px; color: var(--sage); }

.paint-modal {
  position: fixed; inset: 0; z-index: 50; display: none; align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--ink) 38%, transparent);
}
.paint-modal.open { display: flex; }
.paint-modal-box {
  width: min(520px, 92vw); max-height: 82vh; display: flex; flex-direction: column;
  border: 2px solid var(--window-border); border-radius: 9px; background: var(--paper);
  box-shadow: var(--shadow-distance) var(--shadow-distance) 0 color-mix(in srgb, var(--shadow) var(--shadow-alpha), transparent);
}
.paint-modal-box > header {
  display: flex; justify-content: space-between; padding: 9px 13px;
  border-radius: 6px 6px 0 0; background: var(--titlebar); color: var(--menu-text);
}
.paint-modal-box > header button { all: unset; cursor: pointer; padding: 0 3px; }
.paint-site-list { overflow: auto; padding: 8px; color: var(--sage); }
.paint-site-list button {
  all: unset; box-sizing: border-box; width: 100%; display: flex; flex-direction: column; gap: 3px;
  padding: 9px 11px; border-radius: 6px; color: var(--control-text); cursor: pointer;
}
.paint-site-list button span { color: var(--sage); font-size: 10.5px; }
.paint-site-list button:hover { background: var(--ink); color: var(--menu-text); }
.paint-site-list button:hover span { color: var(--menu-dim); }
.paint-dialog { width: min(410px, 92vw); }
.paint-dialog-body { display: flex; flex-direction: column; gap: 12px; padding: 16px; }
.paint-dialog-body > label:not(.paint-check) { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.paint-dialog-body input[type="number"] {
  width: 112px; padding: 6px 8px; border: 1px solid var(--ink); border-radius: 6px;
  background: var(--paper-deep); color: var(--control-text); font: inherit;
}
.paint-check { display: flex; align-items: center; gap: 8px; }
.paint-dialog-actions { display: flex; justify-content: flex-end; gap: 10px; }
.paint-anchor {
  align-self: center; display: grid; grid-template-columns: repeat(3, 26px); gap: 4px;
  padding: 8px; border: 1px solid var(--paper-line); border-radius: 6px;
}
.paint-anchor legend { padding: 0 5px; color: var(--sage); font-size: 11px; }
.paint-anchor label { width: 26px; height: 26px; cursor: pointer; }
.paint-anchor input { position: absolute; opacity: 0; }
.paint-anchor span { display: block; width: 100%; height: 100%; border: 1px solid var(--ink); border-radius: 3px; background: var(--paper); }
.paint-anchor input:checked + span { background: var(--leaf-deep); box-shadow: inset 0 0 0 7px var(--paper); }
.paint-anchor input:focus-visible + span { outline: 2px solid var(--leaf); outline-offset: 1px; }

@media (max-width: 560px) {
  .paint-main { gap: 8px; padding: 8px; }
  .paint-tools { grid-template-columns: repeat(2, 32px); grid-auto-rows: minmax(32px, auto); gap: 4px; }
  .paint-palette { grid-template-columns: repeat(14, 16px); }
}
