:root {
  --bg: #e6e6d7;
  --panel: #f5f3e6;
  --line: #111;
  --ink: #111;
  --screen: #fcfbf3;
  --toolbar: #ebe7d4;
}

* { box-sizing: border-box; margin: 0; }

html, body {
  height: 100%;
  background: repeating-linear-gradient(0deg, #d9d7c9 0px, #d9d7c9 4px, #d3d1c4 4px, #d3d1c4 8px);
  color: var(--ink);
  font-family: "Chicago", "Geneva", "Verdana", system-ui, sans-serif;
  image-rendering: pixelated;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

.desktop {
  height: 100%;
  display: grid;
  grid-template-rows: 28px 1fr 26px;
}

.menu-bar, .status-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 10px;
  background: #f2efdf;
  border-bottom: 2px solid #000;
  font-size: 13px;
  user-select: none;
}

.status-bar {
  border-top: 2px solid #000;
  border-bottom: none;
  justify-content: space-between;
  font-size: 12px;
}

.workspace {
  padding: 18px;
  position: relative;
  overflow: hidden;
}

.desktop-icon {
  position: absolute;
  top: 16px;
  left: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  cursor: pointer;
  user-select: none;
  z-index: 0;
}

.desktop-icon-img {
  font-size: 32px;
  line-height: 1;
  filter: drop-shadow(1px 1px 0 rgba(0,0,0,0.3));
}

.desktop-icon-label {
  font-size: 11px;
  color: #000;
  background: rgba(255,255,255,0.6);
  padding: 1px 4px;
  text-align: center;
}

.desktop-icon:active .desktop-icon-label {
  background: #316ac5;
  color: #fff;
}

.desktop-icon-donut {
  top: 6px;
  right: 16px;
  left: auto;
}

.desktop-icon-donut.dragging {
  position: fixed;
  z-index: 200;
  pointer-events: none;
  opacity: 0.85;
}

.window {
  position: absolute;
  z-index: 1;
  width: min(1180px, 96vw);
  height: min(760px, 88vh);
  background: var(--panel);
  border: 2px solid #000;
  box-shadow: 6px 6px 0 #000;
  display: grid;
  grid-template-rows: 30px 1fr;
  overflow: hidden;
}

.title-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
  background: linear-gradient(90deg, #d7d2bf 0%, #f4f0df 100%);
  border-bottom: 2px solid #000;
  font-size: 13px;
  user-select: none;
  cursor: grab;
}

.title-bar:active {
  cursor: grabbing;
}

.title-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.traffic {
  width: 12px;
  height: 12px;
  border: 2px solid #000;
  background: #fff9d9;
}

.window-body {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: 0;
}

.sidebar {
  border-right: 2px solid #000;
  background: var(--toolbar);
  padding: 10px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.canvas-wrap {
  display: grid;
  grid-template-rows: 44px 1fr;
  min-width: 0;
  min-height: 0;
  background: #d8d3c1;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 8px;
  border-bottom: 2px solid #000;
  background: #f3efde;
}

.toolbar-group {
  display: flex;
  gap: 4px;
  align-items: center;
}

.panel {
  background: var(--panel);
  border: 2px solid #000;
  padding: 8px;
}

.panel h3 {
  margin: 0 0 6px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.tool-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 4px;
}

button {
  font: inherit;
  border: 2px solid #000;
  background: #fffceb;
  color: #000;
  padding: 4px 8px;
  cursor: pointer;
  box-shadow: 2px 2px 0 #000;
  font-size: 11px;
  min-height: 28px;
}

button:active, button.active {
  transform: translate(2px, 2px);
  box-shadow: none;
  background: #ddd7c2;
}

.tool-btn {
  width: 100%;
  text-align: left;
}

.fx-grid {
  grid-template-columns: repeat(3, 1fr);
}

.fx-grid .tool-btn {
  font-size: 10px;
  padding: 3px 5px;
  min-height: 24px;
}

.layer-stack {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.layer-btn {
  width: 100%;
  text-align: left;
  font-size: 11px;
  display: flex;
  align-items: center;
  gap: 6px;
  border-bottom-width: 0;
}

.layer-btn:last-child {
  border-bottom-width: 2px;
}

.layer-btn.active {
  background: #d6ecd8;
}

.layer-btn.active:active {
  background: #a5d6a7;
}

.layer-eye {
  cursor: pointer;
  font-size: 13px;
  flex-shrink: 0;
}

.layer-eye.hidden {
  opacity: 0.3;
}

.layer-label {
  flex: 1;
}

.layer-pos {
  font-size: 9px;
  color: #888;
  margin-left: auto;
}

.palette-row {
  display: flex;
  gap: 4px;
  margin-bottom: 6px;
}

.palette-row .swatch {
  flex: 1;
  height: 28px;
  border: 2px solid #000;
  cursor: pointer;
  box-shadow: 2px 2px 0 #000;
}

.palette-row .swatch.active {
  outline: 3px solid #f00;
  outline-offset: 0px;
}

.palette-select {
  width: 100%;
  font: inherit;
  font-size: 11px;
  border: 2px solid #000;
  background: #fffceb;
  padding: 3px;
}

.row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  margin-bottom: 4px;
}

/* Retro range slider */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  background: #d8d3c1;
  border: 2px solid #000;
  border-radius: 0;
  outline: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 20px;
  background: #fffceb;
  border: 2px solid #000;
  border-radius: 0;
  box-shadow: 1px 1px 0 #000;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb:active {
  background: #ddd7c2;
  box-shadow: none;
  transform: translateY(1px);
}

input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 20px;
  background: #fffceb;
  border: 2px solid #000;
  border-radius: 0;
  box-shadow: 1px 1px 0 #000;
  cursor: pointer;
}

input[type="range"]::-moz-range-thumb:active {
  background: #ddd7c2;
  box-shadow: none;
}

input[type="range"]::-moz-range-track {
  height: 6px;
  background: #d8d3c1;
  border: 2px solid #000;
  border-radius: 0;
}

.canvas-stage {
  position: relative;
  display: grid;
  place-items: center;
  padding: 16px;
  overflow: auto;
}

.canvas-shell {
  position: relative;
  width: min(100%, 900px);
  aspect-ratio: 4 / 3;
  background: var(--screen);
  border: 2px solid #000;
  box-shadow: 6px 6px 0 #000;
  overflow: hidden;
}

canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  image-rendering: auto;
}

.mono {
  font-family: "Monaco", "Courier New", monospace;
  font-size: 11px;
}

/* About Modal */
.about-overlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
}

.about-overlay[hidden] {
  display: none;
}

.about-window {
  width: 380px;
  max-width: 90vw;
  background: var(--panel);
  border: 2px solid #000;
  box-shadow: 6px 6px 0 #000;
  display: flex;
  flex-direction: column;
}

.about-title-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
  height: 30px;
  background: linear-gradient(90deg, #d7d2bf 0%, #f4f0df 100%);
  border-bottom: 2px solid #000;
  font-size: 13px;
  user-select: none;
}

.about-close {
  min-height: 20px;
  padding: 0 6px;
  font-size: 14px;
  line-height: 1;
  box-shadow: 1px 1px 0 #000;
}

.about-body {
  padding: 16px;
  font-size: 12px;
  line-height: 1.7;
}

.about-header {
  text-align: center;
  margin-bottom: 12px;
}

.about-text, .about-license {
  color: #333;
}

.about-links {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 11px;
}

.about-links a {
  color: #2255aa;
  text-decoration: none;
}

.about-links a:hover {
  text-decoration: underline;
}

.about-divider {
  height: 2px;
  background: #000;
  margin: 10px 0;
}

.about-license {
  font-size: 10px;
  color: #666;
}

/* Sub Window (Animation) */
.sub-window {
  position: fixed;
  z-index: 2;
  width: 240px;
  background: var(--panel);
  border: 2px solid #000;
  box-shadow: 4px 4px 0 #000;
  bottom: 44px;
  left: 16px;
}

.sub-title-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px;
  height: 24px;
  background: linear-gradient(90deg, #d7d2bf 0%, #f4f0df 100%);
  border-bottom: 2px solid #000;
  font-size: 12px;
  user-select: none;
  cursor: grab;
}

.sub-title-bar:active {
  cursor: grabbing;
}

.sub-body {
  padding: 10px;
  font-size: 11px;
}

.frame-strip {
  display: flex;
  gap: 3px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.frame-cell {
  width: 40px;
  height: 30px;
  border: 2px solid #000;
  background: var(--screen);
  cursor: pointer;
  flex-shrink: 0;
  position: relative;
  image-rendering: pixelated;
}

.frame-cell.active {
  border-color: #f00;
  box-shadow: 0 0 0 1px #f00;
}

.frame-cell canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.frame-cell-label {
  position: absolute;
  bottom: 0;
  right: 1px;
  font-size: 7px;
  color: #999;
  pointer-events: none;
}

.frame-add {
  width: 40px;
  height: 30px;
  border: 2px dashed #999;
  background: transparent;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: #999;
  box-shadow: none;
  min-height: 0;
  padding: 0;
}

.frame-add:hover {
  border-color: #000;
  color: #000;
}

.frame-add:active {
  transform: none;
}

.slot-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.slot-empty {
  border: 2px dashed #999;
  padding: 8px;
  text-align: center;
  font-size: 11px;
  color: #999;
  cursor: pointer;
  background: transparent;
  box-shadow: none;
  min-height: 0;
}

.slot-empty:hover {
  border-color: #000;
  color: #000;
}

.slot-empty:active {
  transform: none;
}

.slot-filled {
  border: 2px solid #000;
  padding: 6px 8px;
  background: #fffceb;
}

.slot-filled-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.slot-filled-header strong {
  font-size: 11px;
}

.slot-date {
  font-size: 9px;
  color: #888;
  font-family: "Monaco", "Courier New", monospace;
}

.slot-actions {
  display: flex;
  gap: 4px;
}

.slot-actions .tool-btn {
  font-size: 10px;
  padding: 2px 6px;
  min-height: 20px;
  flex: 1;
}

/* Ghost Mascot */
.ghost-container {
  position: fixed;
  bottom: 30px;
  right: 16px;
  z-index: 2;
  display: flex;
  align-items: flex-start;
  pointer-events: none;
}

.ghost-bubble {
  position: relative;
  background: #ffffcc;
  border: 2px solid #000;
  box-shadow: 2px 2px 0 #000;
  padding: 8px 12px;
  font-size: 12px;
  max-width: 180px;
  margin-top: 30px;
  margin-right: -8px;
  white-space: pre-wrap;
  pointer-events: auto;
}

.ghost-bubble[hidden] {
  display: none;
}

.ghost-bubble-tail {
  position: absolute;
  right: -8px;
  bottom: 14px;
  width: 0;
  height: 0;
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
  border-left: 8px solid #ffffcc;
}

.ghost-img {
  height: 200px;
  cursor: pointer;
  pointer-events: auto;
  filter: drop-shadow(1px 2px 2px rgba(0,0,0,0.3));
  user-select: none;
  image-rendering: auto;
}

@media (max-width: 900px) {
  .window-body { grid-template-columns: 1fr; }
  .sidebar {
    border-right: none;
    border-bottom: 2px solid #000;
    max-height: 35vh;
    flex-direction: row;
    flex-wrap: wrap;
  }
  .sidebar .panel { flex: 1; min-width: 140px; }
}
