@import url("/css/tools.css");

/* Pixel Purgatory - Retro Debugger */
:root {
  --accent: #ff4444;
  --breakpoint: #ff00ff;
}

[data-theme="ayu-mirage"] {
  --accent: #ff6666;
  --breakpoint: #ff66ff;
}

body {
  display: grid;
  grid-template-areas: "header header header" "left center right" "footer footer footer";
  grid-template-columns: 320px 1fr 380px;
  grid-template-rows: 48px 1fr 24px;
  gap: 1px;
  font-family: var(--font-sans);
  font-size: 13px;
}

body.advanced-mode {
  grid-template-areas: "header header header" "toolbar toolbar toolbar" "left center right" "footer footer footer";
  grid-template-rows: 48px auto 1fr 24px;
}

header {
  grid-area: header;
  display: flex;
  align-items: center;
  padding: 0 16px;
  height: 48px;
  background: linear-gradient(135deg, var(--bg-elevated) 0%, var(--bg-base) 100%);
  gap: 16px;
}

footer {
  grid-area: footer;
  display: flex;
  align-items: center;
  padding: 0 16px;
  height: 24px;
  font-size: 10px;
  color: var(--text-muted);
  gap: 24px;
}

#left-panel { grid-area: left; }
#center-panel {
  grid-area: center;
  display: grid;
  place-items: center;
  min-width: 0;
  overflow: hidden;
  background: radial-gradient(circle at center, var(--bg-elevated) 0%, var(--bg-base) 100%);
}
#right-panel { grid-area: right; }

.panel {
  background: var(--bg-elevated);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex: none;
}

/* Tabs */
.tabs {
  display: flex;
  height: 32px;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-base);
}

.tab {
  padding: 0 16px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 11px;
  cursor: pointer;
  position: relative;
  transition: all 0.2s;
  text-transform: none;
  letter-spacing: normal;
  height: auto;
}

.tab:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.03);
}

.tab.active {
  color: var(--text-primary);
  background: var(--bg-elevated);
}

.tab.active::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--accent);
}

.tab-content {
  display: none;
  flex: 1;
  overflow: hidden;
  flex-direction: column;
}

.tab-content.active { display: flex; }

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  height: auto;
  font-size: 11px;
}

.panel-content {
  flex: 1;
  padding: 12px;
  overflow-y: auto;
  font-family: var(--font-mono);
}

/* Buttons */
button {
  height: 30px;
  padding: 0 12px;
  font-size: 11px;
}

button.primary {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

button.active {
  background: #4ade80;
  color: white;
  border-color: #4ade80;
}

#advanced-btn.active {
  background: #60a5fa;
  color: white;
  border-color: #60a5fa;
}

/* Field */
.field {
  display: flex;
  justify-content: space-between;
  padding: 6px 8px;
  background: var(--bg-base);
  border-radius: 4px;
  margin-bottom: 8px;
}

.field-label {
  color: var(--text-muted);
  font-size: 10px;
  text-transform: uppercase;
}

.field-value {
  color: var(--text-primary);
  font-weight: 600;
}

/* Logo */
.logo {
  font-size: 14px;
  font-weight: 600;
  background: linear-gradient(135deg, var(--accent), #ff6b2b);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-transform: uppercase;
  letter-spacing: 1px;
}

/* Controls */
.controls {
  display: flex;
  gap: 8px;
  margin-left: auto;
}

.control-group {
  display: flex;
  gap: 4px;
  padding: 0 8px;
  border-left: 1px solid var(--border-subtle);
}

.control-group:first-child {
  border-left: none;
  padding-left: 0;
}

/* Screen */
.screen-container {
  border: 16px solid;
  border-image: linear-gradient(135deg, #2a2a2a, #1a1a1a) 1;
  border-radius: 12px;
  background: #000;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.9), inset 0 0 30px rgba(0, 0, 0, 0.8);
}

canvas {
  display: block;
  max-width: 100%;
  min-width: 0;
  image-rendering: pixelated;
  border-radius: 2px;
}

/* Status */
.status-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
}

.dot.running {
  background: #4ade80;
  animation: pulse 0.5s infinite;
}

.dot.paused { background: #fbbf24; }
.dot.error { background: var(--accent); }

@keyframes pulse { 50% { opacity: 0.3; } }

/* Registers */
.registers {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.reg {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.reg-name {
  color: var(--text-muted);
  font-size: 9px;
  text-transform: uppercase;
}

.reg-value {
  color: #ff6b2b;
  font-size: 13px;
  font-weight: 600;
}

.reg-flags {
  display: flex;
  gap: 4px;
  margin-top: 4px;
}

.flag {
  padding: 2px 4px;
  border-radius: 2px;
  font-size: 9px;
  background: var(--bg-base);
  color: var(--text-muted);
}

.flag.set {
  background: var(--accent);
  color: white;
}

/* Console */
.console {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 11px;
}

.console-line {
  padding: 4px 8px;
  border-left: 2px solid transparent;
  display: flex;
  gap: 8px;
}

.console-line.error {
  background: rgba(239, 68, 68, 0.1);
  border-left-color: #ef4444;
  color: #fca5a5;
}

.console-line.warn {
  background: rgba(245, 158, 11, 0.1);
  border-left-color: #fbbf24;
  color: #fcd34d;
}

.console-line.info {
  background: rgba(59, 130, 246, 0.1);
  border-left-color: #60a5fa;
  color: #93bbfc;
}

.console-line.debug {
  background: rgba(255, 0, 255, 0.05);
  border-left-color: var(--breakpoint);
  color: #ff99ff;
}

.console-line.success {
  background: rgba(16, 185, 129, 0.1);
  border-left-color: #4ade80;
  color: #6ee7b7;
}

.console-time {
  color: var(--text-muted);
  font-size: 10px;
}

/* Disassembly */
.disasm-line {
  display: grid;
  grid-template-columns: 50px 70px 1fr 60px;
  gap: 8px;
  padding: 3px 8px;
  font-size: 10px;
  cursor: pointer;
  border-radius: 2px;
}

.disasm-line:hover { background: rgba(255, 255, 255, 0.03); }

.disasm-line.current {
  background: rgba(255, 68, 68, 0.15);
  border-left: 2px solid var(--accent);
}

.disasm-line.breakpoint {
  background: rgba(255, 0, 255, 0.1);
}

.disasm-addr { color: var(--text-muted); }
.disasm-bytes { color: var(--text-secondary); }
.disasm-instr { color: var(--text-primary); }
.disasm-comment { color: var(--text-muted); font-style: italic; }

/* Memory view */
.memory-line {
  display: grid;
  grid-template-columns: 60px repeat(8, 24px) 1fr;
  gap: 4px;
  font-size: 10px;
  padding: 2px 8px;
}

.memory-addr { color: var(--text-muted); }
.memory-byte { color: var(--text-secondary); text-align: center; }
.memory-byte.changed { color: var(--accent); font-weight: 600; }
.memory-ascii { color: #60a5fa; }

/* Stack */
.stack-entry {
  display: grid;
  grid-template-columns: 60px 80px 1fr;
  gap: 8px;
  padding: 4px 8px;
  font-size: 10px;
}

.stack-addr { color: var(--text-muted); }
.stack-value { color: var(--accent); font-weight: 600; }
.stack-label { color: var(--text-secondary); }

/* Breakpoints */
.breakpoint-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 4px;
  cursor: pointer;
}

.breakpoint-item:hover { background: var(--bg-hover); }

.breakpoint-addr {
  color: var(--breakpoint);
  font-weight: 600;
}

.breakpoint-delete {
  margin-left: auto;
  color: var(--text-muted);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
}

.breakpoint-item:hover .breakpoint-delete { opacity: 1; }
.breakpoint-delete:hover { color: var(--accent); }

/* Responsive */
@media (max-width: 1200px) {
  body {
    grid-template-columns: 280px 1fr 320px;
  }
}

@media (max-width: 900px) {
  body {
    grid-template-areas: "header" "center" "footer";
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: 48px 1fr 24px;
  }
  #left-panel, #right-panel { display: none; }
}

/* === Utilities, overlays & modal the markup/JS depend on ===
   These were absent, so the file inputs, advanced toolbar and state modal
   rendered inline in the page flow. Chrome stays sans; code stays mono. */
.hidden { display: none !important; }
input[type="file"] { display: none; }

.file-label {
  display: inline-flex;
  align-items: center;
  height: 30px;
  padding: 0 12px;
  font-size: 11px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  transition: background var(--dur), color var(--dur), border-color var(--dur);
}
.file-label:hover { background: var(--bg-hover); color: var(--text-secondary); border-color: var(--border-default); }

/* Drop zone: a full-window overlay, shown only while dragging (JS adds .active) */
.drop-zone {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: none;
  place-items: center;
  font-size: 16px;
  color: var(--accent);
  background: color-mix(in oklch, var(--accent) 6%, rgba(0, 0, 0, 0.6));
  border: 2px dashed var(--accent);
  backdrop-filter: blur(4px);
}
.drop-zone.active { display: grid; }

/* Advanced toolbar: hidden until body.advanced-mode maps its grid row */
.advanced-toolbar { display: none; }
body.advanced-mode .advanced-toolbar {
  grid-area: toolbar;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
  padding: 8px 16px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border-subtle);
}
.toolbar-section { display: flex; align-items: center; gap: 8px; }
.toolbar-section + .toolbar-section { padding-left: 16px; border-left: 1px solid var(--border-subtle); }
.toolbar-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); }
.toolbar-button { height: 30px; }
.toolbar-button.success { color: var(--success); border-color: var(--success); }
.toolbar-button.danger { color: var(--error); border-color: var(--error); }

/* State modal (JS toggles .visible) */
.modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
}
.modal.visible { display: flex; }
.modal-content {
  width: 560px;
  max-width: 100%;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-subtle);
}
.modal-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
}
.modal-close {
  width: 28px;
  height: 28px;
  padding: 0;
  justify-content: center;
  font-size: 18px;
  line-height: 1;
}
.state-viewer {
  flex: 1;
  overflow: auto;
  padding: 12px 16px;
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text-secondary);
}
.state-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border-subtle);
}