@font-face {
  font-family: 'Pixel';
  src: local('Press Start 2P');
}

:root {
  --accent: #33ff33;
  --accent-dim: #1a8a1a;
  --accent-glow: rgba(51, 255, 51, 0.15);
  --bg-dark: #0a0a12;
  --bg-panel: #14142a;
  --bg-panel-light: #1e1e3a;
  --border: #2a2a4a;
  --border-light: #3a3a5a;
  --text: #cccccc;
  --text-dim: #666688;
  --text-bright: #ffffff;
  --danger: #ff4444;
  --warning: #ffaa00;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-font-smoothing: none;
  image-rendering: pixelated;
}

body {
  background: var(--bg-dark);
  color: var(--text);
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  line-height: 1.6;
  overflow: hidden;
  height: 100vh;
  user-select: none;
  cursor: default;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* Menu Bar */
#menu-bar {
  display: flex;
  align-items: center;
  height: 28px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  padding: 0 4px;
  gap: 2px;
  flex-shrink: 0;
}

.menu-item {
  padding: 4px 10px;
  cursor: pointer;
  color: var(--text);
  font-size: 8px;
  border: 1px solid transparent;
  transition: background 0.1s;
}

.menu-item:hover, .menu-item.active {
  background: var(--bg-panel-light);
  border-color: var(--border-light);
  color: var(--accent);
}

#app-title {
  margin-left: auto;
  color: var(--accent);
  font-size: 8px;
  text-shadow: 0 0 10px var(--accent-glow);
  letter-spacing: 1px;
}

#theme-toggle {
  padding: 4px 8px;
  cursor: pointer;
  color: var(--accent);
  font-size: 10px;
}
#theme-toggle:hover {
  text-shadow: 0 0 8px var(--accent);
}

/* Menu Dropdown */
#menu-dropdown {
  position: absolute;
  top: 28px;
  left: 0;
  background: var(--bg-panel);
  border: 1px solid var(--border-light);
  z-index: 1000;
  min-width: 180px;
  box-shadow: 4px 4px 0 rgba(0,0,0,0.5);
}

#menu-dropdown.hidden {
  display: none;
}

.menu-dropdown-item {
  padding: 6px 12px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 8px;
}

.menu-dropdown-item:hover {
  background: var(--accent-dim);
  color: var(--text-bright);
}

.menu-dropdown-item .shortcut {
  color: var(--text-dim);
  font-size: 7px;
}

.menu-separator {
  height: 1px;
  background: var(--border);
  margin: 2px 4px;
}

/* Tab Bar */
#tab-bar {
  display: flex;
  align-items: stretch;
  height: 24px;
  background: var(--bg-dark);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  overflow-x: auto;
  overflow-y: hidden;
}

#tab-bar::-webkit-scrollbar {
  height: 2px;
}
#tab-bar::-webkit-scrollbar-thumb {
  background: var(--accent-dim);
}

#tabs-container {
  display: flex;
  align-items: stretch;
  min-width: 0;
}

.tab {
  display: flex;
  align-items: center;
  padding: 0 8px;
  gap: 6px;
  cursor: pointer;
  border-right: 1px solid var(--border);
  background: var(--bg-panel);
  color: var(--text-dim);
  font-size: 7px;
  white-space: nowrap;
  min-width: 80px;
  max-width: 160px;
  position: relative;
}

.tab:hover {
  background: var(--bg-panel-light);
  color: var(--text);
}

.tab.active {
  background: var(--bg-panel-light);
  color: var(--accent);
  border-bottom: 2px solid var(--accent);
}

.tab .unsaved-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--warning);
  display: none;
}

.tab.unsaved .unsaved-dot {
  display: block;
}

.tab .tab-close {
  font-size: 8px;
  color: var(--text-dim);
  padding: 0 2px;
  cursor: pointer;
}

.tab .tab-close:hover {
  color: var(--danger);
}

.tab .tab-name {
  overflow: hidden;
  text-overflow: ellipsis;
}

#tab-add {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  cursor: pointer;
  color: var(--accent-dim);
  font-size: 14px;
  flex-shrink: 0;
}

#tab-add:hover {
  color: var(--accent);
  background: var(--bg-panel-light);
}

/* Main Content */
#main-content {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* Left Toolbar */
#toolbar {
  width: 52px;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 4px 2px;
  gap: 2px;
  flex-shrink: 0;
  overflow-y: auto;
}

.tool-btn {
  width: 44px;
  height: 36px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--bg-panel-light);
  border-radius: 2px;
  padding: 2px;
}

.tool-btn:hover {
  border-color: var(--accent-dim);
  background: #22224a;
}

.tool-btn.active {
  border-color: var(--accent);
  background: rgba(51, 255, 51, 0.1);
  box-shadow: 0 0 6px var(--accent-glow);
}

.tool-icon {
  width: 16px;
  height: 16px;
  image-rendering: pixelated;
}

.tool-label {
  font-size: 6px;
  color: var(--text-dim);
  letter-spacing: 0.5px;
}

.tool-btn.active .tool-label {
  color: var(--accent);
}

.tool-separator {
  width: 36px;
  height: 1px;
  background: var(--border);
  margin: 3px 0;
}

.tool-option {
  width: 44px;
  padding: 3px;
  text-align: center;
  cursor: pointer;
  font-size: 10px;
  color: var(--accent);
  border: 1px solid var(--border);
  background: var(--bg-panel-light);
  border-radius: 2px;
}

.tool-option:hover {
  border-color: var(--accent-dim);
}

.tool-option.hidden {
  display: none;
}

.option-label {
  font-size: 6px;
  color: var(--text-dim);
}

.size-btns {
  display: flex;
  gap: 1px;
  justify-content: center;
}

.size-btn {
  width: 12px;
  height: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 7px;
  color: var(--text-dim);
  border: 1px solid var(--border);
  cursor: pointer;
}

.size-btn.active {
  color: var(--accent);
  border-color: var(--accent);
}

/* Color Palette */
#color-palette {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding-top: 2px;
}

#fg-bg-display {
  position: relative;
  width: 36px;
  height: 36px;
}

#fg-color {
  position: absolute;
  top: 0;
  left: 0;
  width: 24px;
  height: 24px;
  border: 2px solid var(--accent);
  z-index: 2;
}

#bg-color {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 24px;
  height: 24px;
  border: 2px solid var(--text-dim);
  z-index: 1;
}

#swap-colors {
  position: absolute;
  top: -2px;
  right: -2px;
  font-size: 8px;
  cursor: pointer;
  color: var(--text-dim);
  z-index: 3;
}

#swap-colors:hover {
  color: var(--accent);
}

#color-swatches {
  display: grid;
  grid-template-columns: repeat(2, 18px);
  gap: 2px;
}

.color-swatch {
  width: 18px;
  height: 18px;
  border: 1px solid var(--border-light);
  cursor: pointer;
}

.color-swatch:hover {
  border-color: var(--text-bright);
  transform: scale(1.1);
}

.color-swatch.fg-selected {
  border: 2px solid var(--accent);
  box-shadow: 0 0 4px var(--accent);
}

.color-swatch.bg-selected {
  outline: 2px dashed var(--text-dim);
  outline-offset: 1px;
}

/* Canvas Area */
#canvas-area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-dark);
  overflow: hidden;
  position: relative;
  cursor: crosshair;
}

#crt-frame {
  position: relative;
  border: 3px solid #222244;
  border-radius: 8px;
  box-shadow:
    inset 0 0 30px rgba(0,0,0,0.5),
    0 0 20px rgba(0,0,0,0.8),
    0 0 40px var(--accent-glow);
  overflow: hidden;
  background: #000;
}

#canvas {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

#scanline-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 1px,
    rgba(0,0,0,0.15) 1px,
    rgba(0,0,0,0.15) 2px
  );
  z-index: 5;
}

#grid-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  z-index: 4;
  display: none;
}

/* Right Panel */
#right-panel {
  width: 160px;
  background: var(--bg-panel);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0;
  flex-shrink: 0;
  overflow-y: auto;
}

.panel-section {
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
}

.panel-title {
  color: var(--accent);
  font-size: 7px;
  margin-bottom: 4px;
  letter-spacing: 1px;
}

#file-info div, #cursor-info {
  font-size: 7px;
  margin-bottom: 2px;
}

.info-label {
  color: var(--accent-dim);
}

#cursor-info {
  display: flex;
  gap: 8px;
}

#minimap {
  width: 140px;
  height: 96px;
  border: 1px solid var(--border);
  background: #000;
  image-rendering: pixelated;
  cursor: pointer;
}

#shortcuts-info {
  font-size: 6px;
  color: var(--text-dim);
  line-height: 1.8;
}

/* Status Bar */
#status-bar {
  height: 22px;
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 8px;
  gap: 12px;
  font-size: 7px;
  flex-shrink: 0;
}

#status-tool {
  color: var(--accent);
  min-width: 50px;
}

#status-pos {
  color: var(--text-dim);
  min-width: 80px;
}

#status-zoom {
  color: var(--text-dim);
}

#status-colors {
  display: flex;
  gap: 3px;
  align-items: center;
}

#status-fg, #status-bg {
  width: 10px;
  height: 10px;
  border: 1px solid var(--border-light);
}

#status-memory {
  color: var(--accent-dim);
  margin-left: auto;
}

#status-file {
  color: var(--text-dim);
}

#remix-link {
  color: var(--accent-dim);
  text-decoration: none;
  font-size: 6px;
  margin-left: 8px;
}

#remix-link:hover {
  color: var(--accent);
}

/* Dialog */
#dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

#dialog-overlay.hidden {
  display: none;
}

#dialog-box {
  background: var(--bg-panel);
  border: 2px solid var(--accent);
  box-shadow: 0 0 30px var(--accent-glow), 8px 8px 0 rgba(0,0,0,0.5);
  padding: 16px;
  min-width: 280px;
  max-width: 90vw;
  max-height: 80vh;
  overflow-y: auto;
}

#dialog-title {
  color: var(--accent);
  font-size: 10px;
  margin-bottom: 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

#dialog-content {
  font-size: 8px;
  margin-bottom: 12px;
  line-height: 2;
  color: var(--text);
}

#dialog-content input[type="text"] {
  background: var(--bg-dark);
  border: 1px solid var(--border-light);
  color: var(--accent);
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  padding: 4px 6px;
  width: 100%;
  outline: none;
}

#dialog-content input[type="text"]:focus {
  border-color: var(--accent);
}

#dialog-buttons {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.dialog-btn {
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  padding: 6px 12px;
  cursor: pointer;
  border: 1px solid var(--border-light);
  background: var(--bg-panel-light);
  color: var(--text);
}

.dialog-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.dialog-btn.primary {
  border-color: var(--accent-dim);
  color: var(--accent);
}

/* File browser */
.file-list {
  max-height: 200px;
  overflow-y: auto;
}

.file-list-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px;
  cursor: pointer;
  border: 1px solid transparent;
}

.file-list-item:hover {
  border-color: var(--accent-dim);
  background: var(--bg-dark);
}

.file-list-item canvas {
  width: 35px;
  height: 24px;
  border: 1px solid var(--border);
  image-rendering: pixelated;
}

/* Amber theme overrides */
body.amber {
  --accent: #ffaa00;
  --accent-dim: #8a5a00;
  --accent-glow: rgba(255, 170, 0, 0.15);
}

/* Utility */
.hidden {
  display: none !important;
}

/* Scrollbar styling */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: var(--bg-dark);
}

::-webkit-scrollbar-thumb {
  background: var(--border-light);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--accent-dim);
}

/* Boot animation */
@keyframes bootFlicker {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.8; }
}

.booting #crt-frame {
  animation: bootFlicker 0.1s ease-in-out 3;
}