:root {
  color-scheme: light;
  --page: #efeaf6;
  --chrome: rgba(252, 250, 255, 0.92);
  --chrome-2: rgba(228, 220, 244, 0.92);
  --ink: #1a1531;
  --muted: #665f80;
  --line: #20183a;
  --shadow: rgba(32, 24, 58, 0.72);
  --phase-accent: #ff46bb;
  --wall-bg: #f4efff;
  --wall-fg: #1a1531;
  --control-size: 38px;
  --zoom: 1;
  --texture-x: 0px;
  --texture-y: 0px;
  --texture-x-soft: 0px;
  --texture-y-soft: 0px;
  --trail-core: rgba(255, 70, 187, 0.94);
  --trail-glow: rgba(72, 233, 255, 0.28);
  --trail-radius: 999px;
  --hint-bg: rgba(252, 250, 255, 0.96);
  --hint-text: #1a1531;
  --ui-font: "Space Grotesk", sans-serif;
  --mono-font: "IBM Plex Mono", monospace;
  --display-font: "Orbitron", sans-serif;
  --serif-font: "Cormorant Garamond", serif;
  --pixel-font: "Press Start 2P", monospace;
  --cursor-ui: cell;
  --cursor-wall: crosshair;
  --cursor-drag: grabbing;
}

body[data-phase="paper"] {
  --page: #f2eddb;
  --chrome: rgba(255, 253, 245, 0.94);
  --chrome-2: rgba(243, 236, 217, 0.94);
  --ink: #23325c;
  --muted: #6f7697;
  --line: #2a3f77;
  --shadow: rgba(42, 63, 119, 0.28);
  --phase-accent: #29448d;
  --wall-bg: #fffdf7;
  --wall-fg: #23325c;
  --cursor-ui: crosshair;
  --cursor-wall: crosshair;
  --trail-core: rgba(41, 68, 141, 0.92);
  --trail-glow: rgba(190, 207, 255, 0.28);
  --trail-radius: 999px;
  --hint-bg: rgba(255, 253, 245, 0.97);
  --hint-text: #23325c;
}

body[data-phase="moes-school-wall"] {
  --page: #ddd2c7;
  --chrome: rgba(251, 245, 238, 0.92);
  --chrome-2: rgba(230, 218, 207, 0.94);
  --ink: #1d1714;
  --muted: #7f6a5c;
  --line: #2b211c;
  --shadow: rgba(43, 33, 28, 0.34);
  --phase-accent: #8f2427;
  --wall-bg: #eadccf;
  --wall-fg: #1d1714;
  --cursor-ui: crosshair;
  --cursor-wall: grab;
  --trail-core: rgba(43, 33, 28, 0.92);
  --trail-glow: rgba(143, 36, 39, 0.22);
  --trail-radius: 999px;
  --hint-bg: rgba(251, 245, 238, 0.96);
  --hint-text: #1d1714;
}

body[data-phase="static"] {
  --page: #dfdfd9;
  --chrome: rgba(246, 246, 241, 0.92);
  --chrome-2: rgba(218, 218, 211, 0.92);
  --ink: #111111;
  --muted: #676767;
  --line: #111111;
  --shadow: rgba(17, 17, 17, 0.55);
  --phase-accent: #111111;
  --wall-bg: #ebebe5;
  --wall-fg: #111111;
  --cursor-ui: crosshair;
  --cursor-wall: crosshair;
  --trail-core: rgba(17, 17, 17, 0.9);
  --trail-glow: rgba(255, 255, 255, 0.2);
  --trail-radius: 3px;
  --hint-bg: rgba(246, 246, 241, 0.96);
  --hint-text: #111111;
}

body[data-phase="pixel"] {
  --page: #eadfc1;
  --chrome: rgba(255, 248, 221, 0.96);
  --chrome-2: rgba(236, 224, 171, 0.96);
  --ink: #2b2414;
  --muted: #736543;
  --line: #2b2414;
  --shadow: rgba(43, 36, 20, 0.78);
  --phase-accent: #6df70d;
  --wall-bg: #fff3c6;
  --wall-fg: #2b2414;
  --cursor-ui: cell;
  --cursor-wall: cell;
  --trail-core: rgba(109, 247, 13, 0.96);
  --trail-glow: rgba(255, 241, 169, 0.24);
  --trail-radius: 2px;
  --hint-bg: rgba(255, 248, 221, 0.96);
  --hint-text: #2b2414;
}

body[data-phase="heaven"] {
  --page: #edf5ff;
  --chrome: rgba(248, 252, 255, 0.94);
  --chrome-2: rgba(219, 234, 255, 0.94);
  --ink: #2f4776;
  --muted: #6d85b2;
  --line: #86a4d9;
  --shadow: rgba(90, 122, 182, 0.4);
  --phase-accent: #ffd46e;
  --wall-bg: #eef6ff;
  --wall-fg: #35507f;
  --cursor-ui: copy;
  --cursor-wall: grab;
  --trail-core: rgba(138, 182, 255, 0.94);
  --trail-glow: rgba(255, 212, 110, 0.24);
  --trail-radius: 999px;
  --hint-bg: rgba(248, 252, 255, 0.96);
  --hint-text: #2f4776;
}

body[data-phase="terminal"] {
  color-scheme: dark;
  --page: #050806;
  --chrome: rgba(7, 13, 10, 0.92);
  --chrome-2: rgba(13, 24, 17, 0.92);
  --ink: #d9ffd6;
  --muted: #78a873;
  --line: #27ff68;
  --shadow: rgba(39, 255, 104, 0.28);
  --phase-accent: #27ff68;
  --wall-bg: #050806;
  --wall-fg: #caffc4;
  --cursor-ui: text;
  --cursor-wall: cell;
  --trail-core: rgba(39, 255, 104, 0.96);
  --trail-glow: rgba(39, 255, 104, 0.22);
  --trail-radius: 3px;
  --hint-bg: rgba(7, 13, 10, 0.96);
  --hint-text: #d9ffd6;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  background:
    radial-gradient(circle at 14% 10%, rgba(255, 255, 255, 0.55), transparent 28%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.2), transparent 28%),
    var(--page);
  font-family: var(--ui-font);
  cursor: var(--cursor-ui);
}

body::before,
body::after {
  position: fixed;
  inset: 0;
  z-index: 12;
  content: "";
  pointer-events: none;
}

body[data-phase="static"]::before {
  opacity: 0.18;
  background-image:
    radial-gradient(circle at 20% 30%, rgba(255, 255, 255, 0.75) 0 1px, transparent 1px),
    radial-gradient(circle at 70% 60%, rgba(0, 0, 0, 0.55) 0 1px, transparent 1px),
    radial-gradient(circle at 42% 12%, rgba(255, 255, 255, 0.4) 0 1px, transparent 1px);
  background-size: 7px 7px, 9px 9px, 5px 5px;
  mix-blend-mode: overlay;
  animation: static-jitter 180ms steps(2, end) infinite;
}

body[data-phase="static"]::after {
  opacity: 0.18;
  background:
    repeating-linear-gradient(0deg, rgba(17, 17, 17, 0.16) 0 1px, transparent 1px 4px),
    radial-gradient(circle at 50% 50%, transparent 0 62%, rgba(0, 0, 0, 0.18) 100%);
}

button,
input,
a,
label {
  cursor: var(--cursor-ui);
  font: inherit;
}

button {
  border: 0;
}

.app-shell {
  display: grid;
  grid-template-rows: auto 1fr;
  height: 100dvh;
  min-height: 520px;
  background: transparent;
}

.topbar {
  position: relative;
  z-index: 10;
  display: grid;
  grid-template-rows: 30px 58px;
  border-bottom: 2px solid var(--line);
  color: var(--ink);
  background: var(--chrome);
  backdrop-filter: blur(12px);
  box-shadow: 0 1px 0 var(--line);
  overflow: visible;
}

.system-strip {
  display: grid;
  grid-template-columns: max-content minmax(120px, 1fr) max-content max-content;
  min-width: 0;
  border-bottom: 2px solid var(--line);
  color: var(--chrome);
  background: var(--ink);
  font-family: var(--mono-font);
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  text-transform: uppercase;
}

.sys-cell {
  display: flex;
  align-items: center;
  min-width: 0;
  padding: 0 10px;
  border-right: 1px solid color-mix(in srgb, var(--chrome) 34%, transparent);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sys-cell:last-child {
  border-right: 0;
}

#phaseLabel {
  color: var(--phase-accent);
}

.command-row {
  display: grid;
  grid-template-columns: 1fr;
  align-items: stretch;
  min-width: 0;
}

.brand {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  min-width: 0;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  place-items: center;
  border-right: 2px solid var(--line);
  color: var(--chrome);
  background: var(--ink);
  font-family: var(--mono-font);
  font-size: 13px;
  font-weight: 700;
}

.brand-name {
  display: flex;
  align-items: center;
  min-width: 0;
  padding: 0 16px;
  border-right: 2px solid var(--line);
  font-family: var(--display-font);
  font-size: 31px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  white-space: nowrap;
}

body[data-phase="pixel"] .brand-name {
  font-family: var(--pixel-font);
  font-size: 18px;
  letter-spacing: 0;
}

body[data-phase="paper"] .brand-name {
  font-family: var(--mono-font);
  font-size: 29px;
  letter-spacing: 0.05em;
}

body[data-phase="moes-school-wall"] .brand-name {
  font-family: var(--mono-font);
  font-size: 27px;
  letter-spacing: 0.04em;
}

body[data-phase="heaven"] .brand-name {
  font-family: var(--serif-font);
  font-size: 36px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: none;
}

body[data-phase="terminal"] .brand-name,
body[data-phase="static"] .brand-name {
  font-family: var(--mono-font);
  font-size: 28px;
  letter-spacing: 0.04em;
}

.tools-button,
.dock-button,
.plain-button,
.style-button,
.zoom-button,
.zoom-value {
  min-height: 38px;
  transition:
    transform 120ms ease,
    box-shadow 120ms ease,
    background-color 160ms ease,
    color 160ms ease,
    border-color 160ms ease;
}

.tools-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  color: var(--ink);
  background: var(--chrome);
  font-family: var(--mono-font);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.tools-button:hover,
.dock-button:hover,
.plain-button:hover,
.style-button:hover,
.zoom-button:hover,
.zoom-value:hover {
  transform: translate(-1px, -1px);
  box-shadow: 3px 3px 0 var(--shadow);
}

.control-dock {
  position: absolute;
  right: 18px;
  bottom: 18px;
  z-index: 8;
  display: flex;
  align-items: center;
  justify-content: center;
}

.dock-button {
  display: inline-flex;
  width: 58px;
  height: 58px;
  min-height: 58px;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 2px solid var(--line);
  border-radius: 999px;
  color: var(--ink);
  background: var(--chrome);
  box-shadow: 5px 5px 0 var(--shadow);
  font-family: var(--mono-font);
  font-size: 24px;
  font-weight: 700;
  line-height: 1;
}

.tools-button[aria-expanded="true"] {
  color: var(--chrome);
  background: var(--ink);
  transform: rotate(45deg);
}

.toolbar {
  position: absolute;
  right: 18px;
  bottom: 92px;
  z-index: 7;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  width: min(560px, calc(100vw - 32px));
  padding: 12px;
  border: 2px solid var(--line);
  background: var(--chrome-2);
  box-shadow: 6px 6px 0 var(--shadow);
  backdrop-filter: blur(12px);
}

.toolbar[hidden] {
  display: none !important;
}

.cursor-hint {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 60;
  padding: 8px 10px;
  border: 2px solid var(--line);
  color: var(--hint-text);
  background: var(--hint-bg);
  box-shadow: 4px 4px 0 var(--shadow);
  font-family: var(--mono-font);
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  text-transform: uppercase;
  pointer-events: none;
  opacity: 0;
  transform: translate(-999px, -999px);
  transition: opacity 120ms ease;
}

.cursor-hint.is-visible {
  opacity: 1;
}

.cursor-trail {
  position: fixed;
  inset: 0;
  z-index: 55;
  pointer-events: none;
}

.cursor-trail-dot {
  position: fixed;
  left: 0;
  top: 0;
  width: var(--trail-size, 12px);
  height: var(--trail-size, 12px);
  margin-left: calc(var(--trail-size, 12px) / -2);
  margin-top: calc(var(--trail-size, 12px) / -2);
  border-radius: var(--trail-radius);
  background: var(--trail-core);
  box-shadow: 0 0 18px var(--trail-glow);
  opacity: var(--trail-opacity, 0.4);
  transform: translate(-999px, -999px);
}

.toolbar {
  overflow: hidden;
}

.panel-group {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 2px solid var(--line);
  background: var(--chrome);
}

.tool-label {
  font-family: var(--mono-font);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--muted);
}

.ink-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0;
}

.ink-button {
  position: relative;
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  padding: 0;
  border: 0;
  background: transparent;
}

.ink-button::after {
  position: absolute;
  inset: 0;
  border: 2px solid var(--line);
  content: "";
  opacity: 0;
}

.ink-button span {
  display: block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--line);
  background: var(--ink);
}

.ink-button.is-active::after {
  opacity: 1;
}

.tool-group,
.size-control,
.font-control {
  display: inline-flex;
  align-items: center;
  min-height: 42px;
  border: 0;
  background: transparent;
}

.style-group {
  align-items: stretch;
  border: 2px solid var(--line);
}

.style-button,
.plain-button,
.zoom-button,
.zoom-value {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: max-content;
  padding: 0 14px;
  border-right: 2px solid var(--line);
  color: var(--ink);
  background: var(--chrome);
  font-family: var(--mono-font);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.style-button.is-active {
  color: var(--chrome);
  background: var(--ink);
}

.style-button:disabled {
  opacity: 0.42;
  box-shadow: none;
  transform: none;
}

.style-group .style-button:last-child,
.zoom-group .zoom-button:last-child {
  border-right: 0;
}

.size-control {
  padding: 2px 0 0;
}

.size-control input {
  width: 100%;
  accent-color: var(--phase-accent);
}

.font-control {
  width: 100%;
}

.font-control select {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border: 2px solid var(--line);
  color: var(--ink);
  background: var(--chrome);
  font-family: var(--mono-font);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  outline: 0;
}

.font-control select:disabled {
  opacity: 0.42;
}

.zoom-group {
  align-items: stretch;
  border: 2px solid var(--line);
}

.zoom-button {
  width: 40px;
  font-size: 18px;
  line-height: 1;
}

.zoom-value {
  min-width: 68px;
}

.panel-actions {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.panel-actions .plain-button {
  min-width: 0;
  border: 2px solid var(--line);
  color: var(--ink);
  background: var(--chrome);
}

.wall {
  position: relative;
  overflow: hidden;
  isolation: isolate;
  touch-action: none;
  user-select: none;
  color: var(--wall-fg);
  background: var(--wall-bg);
  cursor: var(--cursor-wall);
}

.wall[data-tool="brush"],
.wall[data-tool="spray"] {
  cursor: crosshair;
}

.wall.is-dragging {
  cursor: var(--cursor-drag);
}

.wall::after {
  position: absolute;
  inset: 0;
  z-index: 4;
  content: "";
  pointer-events: none;
  opacity: 0.08;
  background:
    linear-gradient(90deg, rgba(17, 17, 15, 0.24), transparent 13%, transparent 87%, rgba(17, 17, 15, 0.18)),
    linear-gradient(180deg, rgba(17, 17, 15, 0.12), transparent 18%, transparent 83%, rgba(17, 17, 15, 0.16));
}

body[data-phase="heaven"] .wall::after {
  opacity: 0.18;
  background:
    radial-gradient(circle at 50% 0%, rgba(255, 255, 255, 0.82), transparent 44%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.35), transparent 22%, transparent 80%, rgba(126, 169, 235, 0.18));
}

body[data-phase="paper"] .wall::after {
  opacity: 0.16;
  background:
    radial-gradient(circle at 14% 14%, rgba(255, 244, 204, 0.42), transparent 16%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.34), transparent 26%, transparent 82%, rgba(95, 120, 199, 0.08));
}

body[data-phase="moes-school-wall"] .wall::after {
  opacity: 0.12;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.16), transparent 18%, transparent 82%, rgba(78, 61, 48, 0.18)),
    radial-gradient(circle at 50% 110%, rgba(115, 92, 74, 0.24), transparent 52%);
}

body[data-phase="terminal"] .wall::after {
  opacity: 0.16;
  background:
    radial-gradient(circle at 50% 50%, transparent 0 58%, rgba(39, 255, 104, 0.18) 100%),
    linear-gradient(180deg, rgba(39, 255, 104, 0.12), transparent 22%, transparent 78%, rgba(39, 255, 104, 0.1));
}

.surface-layer {
  position: absolute;
  inset: 0;
  z-index: 0;
  opacity: 0;
  overflow: hidden;
  pointer-events: none;
  transition: opacity 180ms linear;
  background-position:
    var(--texture-x) var(--texture-y),
    var(--texture-x-soft) var(--texture-y-soft),
    0 0;
}

.surface-layer::before {
  position: absolute;
  inset: -8%;
  content: "";
  pointer-events: none;
  background-repeat: repeat;
  will-change: transform, opacity;
}

.surface-layer.is-active {
  opacity: 1;
}

.surface-paper {
  background:
    radial-gradient(circle at 14% 18%, rgba(255, 243, 204, 0.34), transparent 14%),
    radial-gradient(circle at 82% 20%, rgba(188, 207, 255, 0.22), transparent 18%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.74), rgba(244, 239, 224, 0.92)),
    #f4efe0;
  animation: paper-shift 18s ease-in-out infinite alternate;
}

.surface-paper::before {
  opacity: 0.96;
  background-image:
    linear-gradient(180deg, rgba(0, 0, 0, 0.08), transparent 18%, transparent 82%, rgba(72, 61, 41, 0.08)),
    linear-gradient(90deg, rgba(229, 108, 123, 0.9), rgba(229, 108, 123, 0.9)),
    repeating-linear-gradient(180deg, transparent 0 31px, rgba(103, 140, 219, 0.64) 31px 33px, transparent 33px 62px),
    linear-gradient(180deg, rgba(255, 255, 255, 0.985), rgba(252, 248, 239, 0.99));
  background-size:
    100% 100%,
    3px 100%,
    100% 100%,
    100% 100%;
  background-position:
    0 0,
    112px 0,
    0 0,
    0 0;
  background-repeat: no-repeat, no-repeat, repeat, no-repeat;
  animation: paper-grain 10s ease-in-out infinite alternate;
}

.surface-y2k {
  background:
    radial-gradient(circle at 16% 20%, rgba(255, 255, 255, 0.76), transparent 18%),
    linear-gradient(130deg, rgba(255, 62, 181, 0.16), transparent 28%, rgba(72, 233, 255, 0.14) 58%, transparent 78%),
    repeating-linear-gradient(90deg, rgba(32, 24, 58, 0.07) 0 1px, transparent 1px calc(34px * var(--zoom))),
    linear-gradient(180deg, rgba(255, 255, 255, 0.42), transparent 34%, rgba(75, 52, 128, 0.08)),
    #f4efff;
  animation: y2k-sheen 14s linear infinite;
}

.surface-y2k::before {
  opacity: 0.48;
  background-image: url("assets/y2k-sparkle.gif");
  background-size: calc(240px * var(--zoom)) calc(240px * var(--zoom));
  background-position: var(--texture-x-soft) var(--texture-y-soft);
  animation: ambient-float 11s ease-in-out infinite alternate;
  mix-blend-mode: screen;
}

.surface-static {
  background:
    radial-gradient(circle at 50% 50%, rgba(255, 255, 255, 0.08), transparent 56%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(0, 0, 0, 0.05)),
    repeating-linear-gradient(0deg, rgba(17, 17, 17, 0.06) 0 1px, transparent 1px calc(4px * var(--zoom))),
    #eae8e1;
}

.surface-static::before {
  opacity: 0.3;
  background-image: url("assets/static-noise.gif");
  background-size: calc(150px * var(--zoom)) calc(150px * var(--zoom));
  background-position: var(--texture-x) var(--texture-y);
  animation: static-flicker 420ms steps(2, end) infinite;
  mix-blend-mode: multiply;
}

.surface-pixel {
  background:
    radial-gradient(circle at 70% 22%, rgba(255, 241, 169, 0.36), transparent 18%),
    repeating-linear-gradient(90deg, rgba(43, 36, 20, 0.09) 0 1px, transparent 1px calc(20px * var(--zoom))),
    repeating-linear-gradient(0deg, rgba(43, 36, 20, 0.09) 0 1px, transparent 1px calc(20px * var(--zoom))),
    linear-gradient(180deg, rgba(255, 255, 255, 0.28), transparent 28%, rgba(122, 99, 28, 0.08)),
    #fff3c6;
}

.surface-pixel::before {
  opacity: 0.78;
  background-image: url("assets/pixel-stars.gif");
  background-size: calc(170px * var(--zoom)) calc(170px * var(--zoom));
  background-position: var(--texture-x-soft) var(--texture-y-soft);
  animation: pixel-drift 7s steps(5, end) infinite alternate;
  image-rendering: pixelated;
}

.surface-heaven {
  background:
    radial-gradient(circle at 18% 20%, rgba(255, 255, 255, 0.92), transparent 18%),
    radial-gradient(circle at 82% 15%, rgba(255, 248, 206, 0.9), transparent 14%),
    radial-gradient(circle at 58% 56%, rgba(255, 255, 255, 0.44), transparent 22%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.88), rgba(229, 241, 255, 0.86) 46%, rgba(215, 232, 255, 0.96)),
    #eef6ff;
  animation: cloud-drift 18s ease-in-out infinite alternate;
}

.surface-heaven::before {
  opacity: 0.68;
  background-image: url("assets/heaven-twinkle.gif");
  background-size: calc(250px * var(--zoom)) calc(250px * var(--zoom));
  background-position: var(--texture-x-soft) var(--texture-y-soft);
  animation: heaven-float 13s ease-in-out infinite alternate;
  mix-blend-mode: screen;
}

.surface-moes-school-wall {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.16), transparent 26%, rgba(61, 45, 35, 0.08) 92%),
    #eadccf;
}

.surface-moes-school-wall::before {
  opacity: 0.96;
  background-image: url("assets/moes-school-wall.png");
  background-size: calc(900px * var(--zoom)) auto;
  background-position: var(--texture-x) var(--texture-y-soft);
  mix-blend-mode: multiply;
}

.surface-terminal {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.02), rgba(0, 0, 0, 0.1)),
    repeating-linear-gradient(0deg, rgba(39, 255, 104, 0.14) 0 1px, transparent 1px calc(11px * var(--zoom))),
    repeating-linear-gradient(90deg, rgba(39, 255, 104, 0.04) 0 1px, transparent 1px calc(58px * var(--zoom))),
    linear-gradient(135deg, rgba(39, 255, 104, 0.05), transparent 36%, rgba(39, 255, 104, 0.04) 68%, transparent 88%),
    radial-gradient(circle at 50% 18%, rgba(39, 255, 104, 0.08), transparent 22%),
    #050806;
}

.surface-terminal::before {
  opacity: 0.24;
  background-image: url("assets/terminal-pulse.gif");
  background-size: calc(92px * var(--zoom)) calc(92px * var(--zoom));
  background-position: var(--texture-x-soft) var(--texture-y-soft);
  animation: terminal-sweep 8s linear infinite;
  mix-blend-mode: screen;
}

.drawing-layer {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  overflow: visible;
  mix-blend-mode: multiply;
}

body[data-phase="terminal"] .drawing-layer {
  mix-blend-mode: screen;
}

.drawing-brush {
  filter: drop-shadow(0 0 1px color-mix(in srgb, currentColor 28%, transparent));
}

.drawing-spray {
  filter: blur(0.2px);
}

.writing-layer {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}

.writing {
  position: absolute;
  left: 0;
  top: 0;
  max-width: min(520px, 78vw);
  min-width: 24px;
  color: var(--writing-color);
  font-size: var(--writing-size);
  pointer-events: auto;
  cursor: var(--cursor-ui);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family: var(--writing-font), var(--ui-font);
  line-height: 0.94;
  transform-origin: center;
}

.writing-marker {
  font-weight: 700;
  line-height: 1;
}

.writing-mono {
  padding: 7px 9px;
  border: 1px solid currentColor;
  background: color-mix(in srgb, var(--wall-bg) 80%, transparent);
  font-weight: 700;
  line-height: 1.05;
  text-transform: uppercase;
}

.writing-pixel {
  padding: 8px 10px;
  border: 3px solid currentColor;
  background: var(--wall-bg);
  font-weight: 400;
  line-height: 1.35;
  image-rendering: pixelated;
  box-shadow: 5px 5px 0 color-mix(in srgb, currentColor 48%, transparent);
}

body[data-phase="terminal"] .writing {
  text-shadow: 0 0 10px color-mix(in srgb, currentColor 48%, transparent);
}

body[data-phase="paper"] .writing-marker {
  line-height: 1.04;
}

body[data-phase="heaven"] .writing-marker {
  font-weight: 700;
  text-transform: none;
}

body[data-phase="static"] .writing {
  filter: grayscale(1);
}

.editor-popover,
.wall-stats {
  position: absolute;
  z-index: 6;
}

.editor-popover {
  left: 0;
  top: 0;
  min-width: min(360px, calc(100vw - 48px));
  max-width: min(560px, calc(100vw - 48px));
  border: 2px solid var(--line);
  color: var(--ink);
  background: var(--chrome);
  box-shadow: 5px 5px 0 var(--shadow);
  transform-origin: center;
}

.editor-popover input {
  width: 100%;
  min-width: 0;
  padding: 12px 14px;
  border: 0;
  outline: 0;
  color: var(--editor-color, var(--ink));
  background: transparent;
  font-family: var(--editor-font, var(--ui-font));
  font-size: var(--editor-size, 32px);
  line-height: 1;
}

.editor-popover[data-style="marker"] input {
  font-weight: 700;
}

.editor-popover[data-style="mono"] input {
  font-weight: 700;
  text-transform: uppercase;
}

.editor-popover[data-style="pixel"] input {
  font-weight: 400;
  line-height: 1.3;
}

body[data-phase="heaven"] .editor-popover[data-style="marker"] input {
  font-weight: 700;
  text-transform: none;
}

body[data-phase="terminal"] .editor-popover input {
  text-shadow: 0 0 10px color-mix(in srgb, currentColor 48%, transparent);
}

body[data-phase="static"] .editor-popover input {
  filter: grayscale(1);
}

.editor-popover input::placeholder {
  color: color-mix(in srgb, var(--muted) 74%, transparent);
  opacity: 1;
}

.wall-stats {
  border: 2px solid var(--line);
  color: var(--ink);
  background: var(--chrome);
  box-shadow: 5px 5px 0 var(--shadow);
  font-family: var(--mono-font);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.wall-stats {
  left: 18px;
  bottom: 18px;
  min-height: 38px;
  padding: 10px 12px;
}

@keyframes paper-shift {
  0% {
    background-position:
      0 0,
      0 0,
      0 0,
      0 0;
  }
  100% {
    background-position:
      0 0,
      0 6px,
      0 0,
      0 0;
  }
}

@keyframes paper-grain {
  0% {
    opacity: 0.42;
    transform: translate3d(-6px, 2px, 0);
  }
  100% {
    opacity: 0.58;
    transform: translate3d(8px, -4px, 0);
  }
}

@keyframes static-jitter {
  0% {
    transform: translate(0, 0);
  }
  25% {
    transform: translate(-0.4%, 0.2%);
  }
  50% {
    transform: translate(0.35%, -0.15%);
  }
  75% {
    transform: translate(-0.2%, 0.35%);
  }
  100% {
    transform: translate(0, 0);
  }
}

@keyframes y2k-sheen {
  0% {
    background-position:
      var(--texture-x) var(--texture-y),
      0 0,
      var(--texture-x-soft) var(--texture-y-soft),
      0 0,
      0 0;
  }
  100% {
    background-position:
      var(--texture-x) var(--texture-y),
      120% 0,
      var(--texture-x-soft) var(--texture-y-soft),
      0 0,
      0 0;
  }
}

@keyframes cloud-drift {
  0% {
    background-position:
      18% 20%,
      82% 15%,
      58% 56%,
      0 0,
      0 0;
  }
  100% {
    background-position:
      24% 18%,
      78% 18%,
      52% 52%,
      0 0,
      0 0;
  }
}

@keyframes ambient-float {
  0% {
    opacity: 0.34;
    transform: translate3d(-10px, 6px, 0) scale(1);
  }
  100% {
    opacity: 0.54;
    transform: translate3d(14px, -12px, 0) scale(1.03);
  }
}

@keyframes static-flicker {
  0% {
    opacity: 0.22;
    transform: translate3d(-4px, 1px, 0);
  }
  50% {
    opacity: 0.34;
    transform: translate3d(3px, -2px, 0);
  }
  100% {
    opacity: 0.26;
    transform: translate3d(-2px, 3px, 0);
  }
}

@keyframes pixel-drift {
  0% {
    opacity: 0.58;
    transform: translate3d(-6px, -4px, 0);
  }
  100% {
    opacity: 0.82;
    transform: translate3d(10px, 8px, 0);
  }
}

@keyframes heaven-float {
  0% {
    opacity: 0.52;
    transform: translate3d(-12px, 8px, 0) scale(1);
  }
  100% {
    opacity: 0.74;
    transform: translate3d(16px, -8px, 0) scale(1.04);
  }
}

@keyframes terminal-sweep {
  0% {
    opacity: 0.28;
    transform: translate3d(0, -10px, 0);
  }
  50% {
    opacity: 0.56;
    transform: translate3d(0, 10px, 0);
  }
  100% {
    opacity: 0.32;
    transform: translate3d(0, -10px, 0);
  }
}

@media (max-width: 980px) {
  .topbar {
    grid-template-rows: 28px auto;
  }

  .system-strip {
    grid-template-columns: max-content minmax(80px, 1fr) max-content;
  }

  #coordLabel {
    display: none;
  }

  .command-row {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .brand {
    grid-template-columns: 48px minmax(0, 1fr);
  }

  .brand-name {
    font-size: 28px;
  }

  body[data-phase="pixel"] .brand-name {
    font-size: 16px;
  }

  body[data-phase="paper"] .brand-name {
    font-size: 26px;
  }

  .toolbar {
    width: min(500px, calc(100vw - 24px));
  }
}

@media (max-width: 640px) {
  .app-shell {
    min-height: 100dvh;
  }

  .topbar {
    grid-template-rows: 28px auto;
  }

  .system-strip {
    grid-template-columns: 1fr 1fr;
  }

  .path-cell {
    display: none;
  }

  .sys-cell {
    padding: 0 8px;
    font-size: 10px;
  }

  .brand-name {
    padding: 0 10px;
    font-size: 24px;
  }

  body[data-phase="pixel"] .brand-name {
    font-size: 14px;
  }

  body[data-phase="paper"] .brand-name {
    font-size: 22px;
  }

  .control-dock {
    right: 12px;
    bottom: 12px;
  }

  .dock-button {
    width: 52px;
    height: 52px;
    min-height: 52px;
    font-size: 22px;
  }

  .toolbar {
    right: 8px;
    bottom: 76px;
    width: calc(100vw - 16px);
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 10px;
  }

  .style-button,
  .plain-button,
  .zoom-button,
  .zoom-value {
    padding: 0 10px;
    font-size: 11px;
  }

  .ink-group {
    gap: 6px;
  }

  .tool-group,
  .size-control,
  .font-control {
    min-height: 42px;
  }

  .panel-group {
    padding: 9px;
  }

  .panel-actions {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .editor-popover {
    min-width: min(280px, calc(100vw - 24px));
    max-width: min(360px, calc(100vw - 24px));
  }

  .editor-popover input {
    padding: 10px 12px;
  }

  .cursor-hint {
    display: none;
  }

  .cursor-trail {
    display: none;
  }

  .wall-stats {
    left: 12px;
    bottom: 12px;
    max-width: calc(100vw - 88px);
  }
}
