@font-face {
  font-family: "Pixelated MS Sans Serif";
  src: url("assets/fonts/ms-sans-serif/regular/font.woff2") format("woff2");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

@font-face {
  font-family: "Pixelated MS Sans Serif";
  src: url("assets/fonts/ms-sans-serif/bold/font.woff2") format("woff2");
  font-style: normal;
  font-weight: 700;
  font-display: swap;
}

:root {
  --ui: "Pixelated MS Sans Serif", "MS Sans Serif", Tahoma, sans-serif;
  --mono: var(--ui);
  --ui-face: #ffccf1;
  --ui-title: #800064;
  --ui-title-end: #ffc7f0;
  --ui-title-text: #ffffff;
  --ui-text: #35112d;
  --ui-highlight: #ffffff;
  --ui-edge-light: #fff0fa;
  --ui-shadow: #d69abc;
  --ui-edge-dark: #800064;
  --ui-desktop: #edddea;
  --panel-bg: var(--ui-face);
  --panel-line: var(--ui-edge-dark);
  --panel-fg: var(--ui-text);
  --panel-dim: var(--ui-text);
  --rail-spine: 36px;
  --rail-width: min(328px, calc(100vw - 32px));
  --raised:
    inset -1px -1px 0 var(--ui-edge-dark),
    inset 1px 1px 0 var(--ui-highlight),
    inset -2px -2px 0 var(--ui-shadow),
    inset 2px 2px 0 var(--ui-edge-light);
  --sunken:
    inset -1px -1px 0 var(--ui-highlight),
    inset 1px 1px 0 var(--ui-edge-dark),
    inset -2px -2px 0 var(--ui-edge-light),
    inset 2px 2px 0 var(--ui-shadow);
}

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

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--ui-desktop);
}

body { padding: 8px; font-family: var(--ui); color: var(--ui-text); }

.app-window {
  height: 100%;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 4px;
  border: 1px solid var(--ui-edge-dark);
  background: var(--ui-face);
  box-shadow: var(--raised);
}

.title-bar {
  display: flex;
  align-items: center;
  flex: none;
  gap: 8px;
  min-height: 28px;
  padding: 3px 7px;
  background: linear-gradient(90deg, var(--ui-title), var(--ui-title-end));
  color: var(--ui-title-text);
  border: 0;
}

.title-bar h1 { margin: 0; font-size: 11px; font-weight: bold; }
.document-name { margin-left: auto; color: var(--ui-text); font-size: 11px; }
.app-icon { width: 15px; height: 15px; background: var(--ui-highlight); border: 2px solid var(--ui-shadow); box-shadow: inset 0 -5px var(--ui-title); }
.menu-bar { display: flex; flex: none; gap: 2px; padding: 3px 0; flex-wrap: wrap; }
.menu-bar button { border: 1px solid transparent; background: transparent; color: var(--ui-text); padding: 4px 8px; font: 11px var(--ui); cursor: pointer; }
.menu-bar button:hover { border-color: var(--ui-highlight) var(--ui-edge-dark) var(--ui-edge-dark) var(--ui-highlight); box-shadow: var(--raised); }
.menu-bar button:active { box-shadow: var(--sunken); }
.app-workspace { flex: 1; display: flex; min-width: 0; min-height: 0; border-top: 1px solid var(--ui-shadow); }

#stageWorkspace { flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; padding: 12px; background: var(--ui-desktop); }
.stage-heading { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 0 2px 8px; font: 11px var(--ui); }
.stage-heading > span:last-child { margin-left: auto; font-size: 11px; }
#recordingStatus { font-weight: bold; }
#canvasViewport { flex: 1; min-width: 0; min-height: 0; display: grid; place-items: center; overflow: hidden; }
#recordingFrame { padding: 5px; border: 2px solid; border-color: var(--ui-edge-dark) var(--ui-highlight) var(--ui-highlight) var(--ui-edge-dark); background: var(--ui-face); box-shadow: var(--sunken); }
#stage { display: block; touch-action: none; cursor: crosshair; background: #c5dc4d; }
.is-recording #recordingFrame { outline: 2px solid #bd284c; outline-offset: -1px; }

.status-bar { display: flex; flex: none; align-items: center; flex-wrap: wrap; gap: 4px; padding-top: 4px; font: 11px var(--ui); }
.status-bar > * { min-width: 0; padding: 4px 7px; box-shadow: var(--sunken); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status-bar .status-actions { padding: 0; box-shadow: none; min-width: 170px; }
.status-actions button { min-height: 30px; padding: 5px 8px; white-space: nowrap; }
.status-bar .page-size-form { padding: 2px 4px; flex: 1; overflow: visible; }
.page-size-form fieldset { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; min-width: 0; margin: 0; padding: 0; border: 0; }
.page-size-form select { width: 90px; min-height: 26px; padding: 3px; font-size: 11px; }
.page-size-form input { width: 58px; height: 26px; padding: 3px; border: 1px solid var(--ui-shadow); background: var(--ui-highlight); color: var(--ui-text); font: 11px var(--ui); box-shadow: var(--sunken); }
.page-size-form button { height: 26px; padding: 3px 8px; border: 1px solid var(--ui-shadow); background: var(--ui-face); color: var(--ui-text); font: 11px var(--ui); box-shadow: var(--raised); cursor: pointer; }
.page-size-form button:active { box-shadow: var(--sunken); }
.page-size-form fieldset:disabled { opacity: 0.55; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
#canvasDimensions { min-width: 120px; font-variant-numeric: tabular-nums; }
#captureStatus { min-width: 72px; text-align: center; }

/* The slim spine remains accessible when the controls are collapsed. */
#controlRail {
  position: relative;
  width: var(--rail-width);
  flex: none;
  display: flex;
  overflow: hidden;
  border-right: 1px solid var(--panel-line);
  background: var(--panel-bg);
  color: var(--panel-fg);
  color-scheme: light;
  font: 11px/1.5 var(--ui);
  z-index: 10;
}

#controlRail.collapsed { width: var(--rail-spine); }

.rail-spine {
  width: var(--rail-spine);
  flex: none;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 8px 0 16px;
  border-right: 1px solid var(--panel-line);
  box-shadow: var(--raised);
}

.rail-spine, #panel { flex-direction: column; }

#panelToggle {
  display: grid;
  place-items: center;
  flex: none;
  width: 28px;
  height: 28px;
  border: 1px solid var(--ui-edge-dark);
  border-radius: 0;
  background: var(--ui-face);
  box-shadow: var(--raised);
  color: var(--panel-fg);
  cursor: pointer;
}

#panelToggle:hover { background: var(--ui-highlight); }
#panelToggle:active { box-shadow: var(--sunken); }
#panelToggle svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; }
.collapsed #panelToggle svg { transform: rotate(180deg); }

.rail-brand {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font: 11px var(--mono);
  letter-spacing: 0.2em;
  color: var(--panel-dim);
}

.rail-spine kbd {
  margin-top: auto;
  border: 1px solid var(--panel-line);
  border-radius: 0;
  box-shadow: var(--sunken);
  padding: 1px 5px;
  font: 11px var(--mono);
  color: var(--panel-dim);
}

#panel {
  display: flex;
  flex: none;
  width: calc(var(--rail-width) - var(--rail-spine));
  min-height: 0;
}

.panel-head { flex: none; padding: 12px 16px; border-bottom: 1px solid var(--panel-line); box-shadow: var(--raised); }
.panel-head h2 { margin: 0; font-size: 11px; font-weight: bold; }
.panel-head p { margin: 4px 0 0; color: var(--panel-dim); font-size: 11px; }

.panel-body {
  min-height: 0;
  flex: 1;
  padding: 6px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--ui-shadow) var(--ui-face);
}

.control-group { margin-bottom: 6px; box-shadow: var(--sunken); }
.control-group summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  list-style: none;
  padding: 12px;
  font-size: 11px;
  font-weight: bold;
  cursor: pointer;
  user-select: none;
  box-shadow: var(--raised);
}

.control-group summary::-webkit-details-marker { display: none; }
.control-group summary::after { content: "+"; font: 16px var(--mono); color: var(--panel-dim); }
.control-group[open] > summary::after { content: "\2212"; }
.control-group summary:hover { background: var(--ui-highlight); }
.group-body { padding: 12px; }
.field { margin-bottom: 16px; }
.field label, .field-label { display: block; margin-bottom: 7px; color: var(--panel-dim); font-size: 11px; }

textarea, select {
  display: block;
  width: 100%;
  border: 1px solid var(--panel-line);
  border-radius: 0;
  box-shadow: var(--sunken);
  background: var(--ui-highlight);
  color: var(--panel-fg);
  font: 11px/1.5 var(--ui);
  padding: 9px 10px;
}

textarea { min-height: 80px; max-height: 240px; resize: vertical; }
select { min-height: 36px; cursor: pointer; }
.hint { margin: 10px 0 0; color: var(--panel-dim); font-size: 11px; line-height: 1.6; }
#fontStatus:empty { display: none; }

/* Native range inputs retain keyboard/touch behavior; only their tracks are styled. */
.sliders { display: flex; flex-direction: column; gap: 16px; }
.grain-control, .text-blur-control { margin-top: 18px; }

.slider {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.slider label { grid-area: 1 / 1; font-size: 11px; color: var(--panel-fg); }
.slider output {
  grid-area: 1 / 2;
  color: var(--panel-dim);
  font: 11px var(--mono);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

input[type="range"] {
  appearance: none;
  -webkit-appearance: none;
  grid-area: 2 / 1 / 3 / -1;
  display: block;
  width: 100%;
  height: 28px;
  margin: 0;
  background: repeating-linear-gradient(90deg, var(--ui-shadow) 0 1px, transparent 1px 10%) 7px bottom / calc(100% - 14px) 4px no-repeat;
  cursor: ew-resize;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 0;
  border: 1px solid var(--ui-edge-dark);
  box-shadow: var(--sunken);
  background: var(--ui-highlight);
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 13px;
  height: 22px;
  margin-top: -10px;
  border: 1px solid var(--ui-edge-dark);
  border-radius: 0;
  box-shadow: var(--raised);
  background: var(--ui-face);
}

input[type="range"]::-moz-range-track {
  height: 4px;
  border-radius: 0;
  border: 1px solid var(--ui-edge-dark);
  box-shadow: var(--sunken);
  background: var(--ui-highlight);
}

input[type="range"]::-moz-range-thumb { width: 13px; height: 22px; border: 1px solid var(--ui-edge-dark); border-radius: 0; background: var(--ui-face); box-shadow: var(--raised); }
input[type="range"]:active::-webkit-slider-thumb { box-shadow: var(--sunken); }
input[type="range"]:active::-moz-range-thumb { box-shadow: var(--sunken); }
.slider.is-disabled { opacity: 0.4; }
input[type="range"]:disabled { cursor: not-allowed; }
.slider:focus-within output { color: var(--panel-fg); }

.check { display: flex; align-items: center; gap: 8px; margin-top: 20px; font-size: 11px; cursor: pointer; }
.check input { width: 15px; height: 15px; margin: 0; accent-color: var(--panel-fg); }

.colours { display: flex; gap: 8px; margin-top: 18px; }
.swatch {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px;
  border: 1px solid var(--panel-line);
  border-radius: 0;
  box-shadow: var(--raised);
  font-size: 11px;
  color: var(--panel-dim);
  cursor: pointer;
}

input[type="color"] { width: 24px; height: 22px; padding: 0; border: 0; background: transparent; cursor: pointer; }
input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
input[type="color"]::-webkit-color-swatch { border: 1px solid var(--ui-shadow); border-radius: 0; }
input[type="color"]::-moz-color-swatch { border: 1px solid var(--ui-shadow); border-radius: 0; }
.ui-palette { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin-top: 12px; }
.ui-palette .swatch { font-size: 11px; padding: 6px; }
.palette-hint { margin-top: 0; }
.theme-reset { width: 100%; min-height: 32px; margin-top: 12px; border: 1px solid var(--ui-shadow); border-radius: 0; background: var(--ui-face); color: var(--ui-text); box-shadow: var(--raised); cursor: pointer; font: 11px var(--ui); }
.theme-reset:active { box-shadow: var(--sunken); }

.rail-footer { flex: none; padding: 14px 16px 12px; border-top: 1px solid var(--panel-line); }
.buttons { display: flex; gap: 6px; }
.export-buttons { margin-top: 7px; }
.buttons button {
  flex: 1;
  min-width: 0;
  min-height: 36px;
  padding: 7px 5px;
  border: 1px solid var(--panel-line);
  border-radius: 0;
  box-shadow: var(--raised);
  background: var(--ui-face);
  color: var(--panel-fg);
  font: 11px var(--ui);
  cursor: pointer;
}

.buttons button:hover { background: var(--ui-highlight); }
.buttons .primary { background: var(--ui-title-end); color: var(--ui-text); font-weight: bold; }
.buttons .primary:hover { background: var(--ui-highlight); }
.buttons button.active, .buttons button:active { box-shadow: var(--sunken); }
#btnRec.active { background: #a52828; border-color: #db6666; color: white; }

#appWindow :is(button, summary, input, textarea, select):focus-visible,
.welcome-dialog :is(button, a):focus-visible {
  outline: 1px dotted var(--ui-text);
  outline-offset: -3px;
}

#recDot {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0;
  color: var(--panel-fg);
  font: 11px var(--mono);
  z-index: 12;
}

#recDot span { width: 7px; height: 7px; border-radius: 50%; background: #ef5656; animation: pulse 1s infinite; }
#recDot em { font-style: normal; color: var(--panel-dim); }
@keyframes pulse { 50% { opacity: 0.3; } }

.welcome-dialog {
  width: min(520px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  max-height: calc(100dvh - 24px);
  padding: 4px;
  overflow: auto;
  border: 1px solid var(--ui-edge-dark);
  border-radius: 0;
  background: var(--ui-face);
  color: var(--ui-text);
  box-shadow: var(--raised), 4px 4px 0 var(--ui-edge-dark);
  font: 11px/1.6 var(--ui);
}

.welcome-dialog::backdrop { background: rgba(40, 13, 34, 0.2); }
.welcome-title-bar { justify-content: space-between; padding: 3px 4px 3px 7px; font-weight: 700; }
.window-close { display: grid; place-items: center; width: 24px; height: 22px; padding: 4px; border: 0; background: var(--ui-face); color: var(--ui-text); box-shadow: var(--raised); cursor: pointer; }
.window-close svg { width: 12px; height: 12px; stroke: currentColor; stroke-width: 2; }
.window-close:active { box-shadow: var(--sunken); }
.welcome-body { padding: 24px; }
.welcome-intro { display: flex; align-items: center; gap: 20px; margin-bottom: 20px; }
.welcome-icon { width: 48px; height: 60px; flex: none; }
.icon-shadow { fill: var(--ui-shadow); }
.icon-ink { fill: var(--ui-edge-dark); }
.icon-light { fill: var(--ui-highlight); }
.welcome-eyebrow { margin: 0 0 4px; font-weight: 700; }
.welcome-intro h2 { margin: 0; font: 400 22px/1.3 var(--ui); }
.welcome-tagline { margin: 8px 0 0; }
.welcome-instructions { padding: 12px; box-shadow: var(--sunken); }
#welcomeDescription { margin: 0; }
.welcome-note { margin: 10px 0 0; }
.welcome-actions { display: flex; justify-content: center; margin: 18px 0 14px; }
.welcome-actions button { min-width: 100px; min-height: 32px; padding: 6px 18px; border: 0; border-radius: 0; color: var(--ui-text); background: var(--ui-face); box-shadow: var(--raised); cursor: pointer; font: 400 11px var(--ui); }
.welcome-actions button:active { box-shadow: var(--sunken); }
.welcome-byline { margin: 0; text-align: center; font-size: 11px; }

@media (max-width: 600px) {
  body { padding: 3px; }
  #stageWorkspace { padding: 6px; }
  .stage-heading > span:last-child { display: none; }
  .title-bar h1 { font-size: 11px; }
  .document-name { display: none; }
  .menu-bar button { font-size: 11px; padding: 4px 5px; }
  .app-workspace { position: relative; }
  #controlRail { position: absolute; inset: 0 auto 0 0; max-width: calc(100% - 24px); z-index: 10; }
  #stageWorkspace { margin-left: var(--rail-spine); }
  .status-bar .page-size-form { flex-basis: 100%; order: 2; }
  #canvasDimensions { flex: 1; }
  .panel-head { padding-top: 14px; padding-bottom: 12px; }
  .rail-footer { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
  .welcome-body { padding: 16px; }
  .welcome-intro { gap: 12px; }
  .welcome-icon { width: 32px; height: 40px; }
}

@media (prefers-reduced-motion: reduce) {
  #controlRail { transition: none; }
  #recDot span { animation: none; }
}
